use of org.hypertrace.core.datamodel.StructuredTrace in project hypertrace-ingester by hypertrace.
the class TraceStatsEnricherTest method headSpanIndexInTraceNotAddedToTraceAttributeIfNoApiNodesInTrace.
@Test
void headSpanIndexInTraceNotAddedToTraceAttributeIfNoApiNodesInTrace() {
// 0
Event yEntryEvent = createUnspecifiedTypeEventWithName("yEvent");
// 1
Event zEntryEvent = createUnspecifiedTypeEventWithName("zEvent");
StructuredTrace trace = createTraceWithEventsAndEdges(new Event[] { yEntryEvent, zEntryEvent }, new HashMap<>() {
{
put(0, new int[] { 1 });
}
});
TraceStatsEnricher traceStatsEnricher = new TraceStatsEnricher();
traceStatsEnricher.enrichTrace(trace);
assertNull(trace.getAttributes().getAttributeMap().get(HEAD_EVENT_ID));
}
use of org.hypertrace.core.datamodel.StructuredTrace in project hypertrace-ingester by hypertrace.
the class TraceStatsEnricherTest method totalNumberOfUniqueApiNodeAttributeEqualsToOneIfAtLeastOneNodeExist.
@Test
void totalNumberOfUniqueApiNodeAttributeEqualsToOneIfAtLeastOneNodeExist() {
// 0
Event yEntryEvent = createUnspecifiedTypeEventWithName("yEvent");
// 1
Event zEntryEvent = createUnspecifiedTypeEventWithName("zEvent");
// 2
Event aEntryHeadSpanEvent = createEntryEventWithName("aEvent");
addApiIdAttr(aEntryHeadSpanEvent, "aApiId");
Event[] allEvents = new Event[] { yEntryEvent, zEntryEvent, aEntryHeadSpanEvent };
HashMap<Integer, int[]> eventEdges = new HashMap<>() {
{
put(0, new int[] { 1 });
put(1, new int[] { 2 });
}
};
StructuredTrace trace = createTraceWithEventsAndEdges(allEvents, eventEdges);
TraceStatsEnricher traceStatsEnricher = new TraceStatsEnricher();
traceStatsEnricher.enrichTrace(trace);
String actualTotalNumberOfCalls = trace.getAttributes().getAttributeMap().get(UNIQUE_API_NODES_COUNT).getValue();
assertEquals("1", actualTotalNumberOfCalls);
}
use of org.hypertrace.core.datamodel.StructuredTrace in project hypertrace-ingester by hypertrace.
the class TraceStatsEnricherTest method headSpanIdIsAddedToTraceAttribute.
@Test
void headSpanIdIsAddedToTraceAttribute() {
// 0
Event aEntryHeadSpanEvent = createEntryEventWithName("aEvent");
// 1
Event aExitEvent = createExitEventName("aExitEvent");
// 2
Event bEntryEvent = createEntryEventWithName("bEvent");
StructuredTrace trace = createTraceWithEventsAndEdges(new Event[] { aEntryHeadSpanEvent, aExitEvent, bEntryEvent }, new HashMap<>() {
{
put(0, new int[] { 1 });
put(1, new int[] { 2 });
}
});
TraceStatsEnricher traceStatsEnricher = new TraceStatsEnricher();
traceStatsEnricher.enrichTrace(trace);
ByteBuffer actualHeadSpanId = aEntryHeadSpanEvent.getEventId();
assertEquals(actualHeadSpanId, trace.getAttributes().getAttributeMap().get(HEAD_EVENT_ID).getBinaryValue());
}
use of org.hypertrace.core.datamodel.StructuredTrace in project hypertrace-ingester by hypertrace.
the class BackendEntityEnricherTest method test_EnrichTrace_apiEntryEvent.
@Test
public void test_EnrichTrace_apiEntryEvent() {
Event e = createApiEntryEvent(EVENT_ID).build();
StructuredTrace trace = createStructuredTrace(TENANT_ID, e);
enricher.enrichTrace(trace);
Assertions.assertEquals(ByteBuffer.wrap(EVENT_ID.getBytes()), e.getEventId());
Assertions.assertNull(EnrichedSpanUtils.getBackendId(e));
}
use of org.hypertrace.core.datamodel.StructuredTrace in project hypertrace-ingester by hypertrace.
the class BackendEntityEnricherTest method test_EnrichTrace_BackendResolvedForBrokenFacadeEvent.
@Test
public void test_EnrichTrace_BackendResolvedForBrokenFacadeEvent() {
String eventName = "broken facade event";
String backendName = "peer";
String serviceName = "peer";
String backendId = "peerId";
Map<String, String> identifyingAttributes = Map.of(BACKEND_PROTOCOL_ATTR_NAME, "UNKNOWN", BACKEND_HOST_ATTR_NAME, backendName, BACKEND_PORT_ATTR_NAME, "-1");
Map<String, String> attributes = Map.of("FROM_EVENT", eventName, "FROM_EVENT_ID", HexUtils.getHex(ByteBuffer.wrap(EVENT_ID.getBytes())));
Entity backendEntity = createEntity(EntityType.BACKEND, backendName, identifyingAttributes, attributes, TENANT_ID);
when(edsClient.upsert(eq(backendEntity))).thenReturn(Entity.newBuilder(backendEntity).setEntityId(backendId).putAllAttributes(createEdsAttributes(identifyingAttributes)).build());
// both service and peer service are same
Event e = createApiExitEvent(EVENT_ID, serviceName, backendName).setEventName(eventName).build();
StructuredTrace trace = createStructuredTrace(TENANT_ID, e);
enricher.enrichTrace(trace);
// assert that backend has been created for above event
Assertions.assertNotNull(EnrichedSpanUtils.getBackendId(e));
Assertions.assertNotNull(EnrichedSpanUtils.getBackendName(e));
}
Aggregations