Search in sources :

Example 21 with StructuredTrace

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));
}
Also used : StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 22 with StructuredTrace

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);
}
Also used : StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) HashMap(java.util.HashMap) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 23 with StructuredTrace

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());
}
Also used : StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) Event(org.hypertrace.core.datamodel.Event) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Example 24 with StructuredTrace

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));
}
Also used : StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test) AbstractAttributeEnricherTest(org.hypertrace.traceenricher.enrichment.enrichers.AbstractAttributeEnricherTest)

Example 25 with StructuredTrace

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));
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test) AbstractAttributeEnricherTest(org.hypertrace.traceenricher.enrichment.enrichers.AbstractAttributeEnricherTest)

Aggregations

StructuredTrace (org.hypertrace.core.datamodel.StructuredTrace)79 Test (org.junit.jupiter.api.Test)66 Event (org.hypertrace.core.datamodel.Event)47 HashMap (java.util.HashMap)15 AbstractAttributeEnricherTest (org.hypertrace.traceenricher.enrichment.enrichers.AbstractAttributeEnricherTest)15 Config (com.typesafe.config.Config)7 ByteBuffer (java.nio.ByteBuffer)7 Map (java.util.Map)7 Edge (org.hypertrace.core.datamodel.Edge)7 File (java.io.File)6 List (java.util.List)6 Entity (org.hypertrace.entity.data.service.v1.Entity)6 URL (java.net.URL)5 ArrayList (java.util.ArrayList)5 SpecificDatumReader (org.apache.avro.specific.SpecificDatumReader)5 RawSpan (org.hypertrace.core.datamodel.RawSpan)5 HexUtils (org.hypertrace.core.datamodel.shared.HexUtils)5 Counter (io.micrometer.core.instrument.Counter)4 Duration (java.time.Duration)4 Instant (java.time.Instant)4