Search in sources :

Example 11 with StructuredTraceGraph

use of org.hypertrace.core.datamodel.shared.StructuredTraceGraph in project hypertrace-ingester by hypertrace.

the class DefaultServiceEntityEnricherTest method test_case1_findServiceNameOfFirstAncestorThatIsNotAnExitSpanAndBelongsToADifferentService.

@Test
public void test_case1_findServiceNameOfFirstAncestorThatIsNotAnExitSpanAndBelongsToADifferentService() {
    // Case 1:  sampleapp (entry) -> redis (exit)
    Event parent = createEvent(TENANT_ID, "parent", Map.of("span.kind", "server"), Map.of("SPAN_TYPE", "ENTRY", "SERVICE_NAME", "sampleapp"), null, "sampleapp");
    Event current = createEvent(TENANT_ID, "current", Map.of("span.kind", "client"), Map.of("SPAN_TYPE", "EXIT"), ByteBuffer.wrap("parent".getBytes()), "redis");
    StructuredTraceGraph graph = mock(StructuredTraceGraph.class);
    when(graph.getParentEvent(current)).thenReturn(parent);
    String actual = enricher.findServiceNameOfFirstAncestorThatIsNotAnExitSpanAndBelongsToADifferentService(current, "redis", graph).orElse(null);
    String expected = "sampleapp";
    assertEquals(expected, actual);
}
Also used : Event(org.hypertrace.core.datamodel.Event) StructuredTraceGraph(org.hypertrace.core.datamodel.shared.StructuredTraceGraph) Test(org.junit.jupiter.api.Test)

Example 12 with StructuredTraceGraph

use of org.hypertrace.core.datamodel.shared.StructuredTraceGraph in project hypertrace-ingester by hypertrace.

the class DefaultServiceEntityEnricherTest method test_case2_findServiceNameOfFirstAncestorThatIsNotAnExitSpanAndBelongsToADifferentService.

@Test
public void test_case2_findServiceNameOfFirstAncestorThatIsNotAnExitSpanAndBelongsToADifferentService() {
    // Case 2:  sampleapp (entry) -> sampleapp (exit)
    Event parent = createEvent(TENANT_ID, "parent", Map.of("span.kind", "server"), Map.of("SPAN_TYPE", "ENTRY", "SERVICE_NAME", "sampleapp"), null, "sampleapp");
    Event current = createEvent(TENANT_ID, "current", Map.of("span.kind", "client"), Map.of("SPAN_TYPE", "EXIT"), ByteBuffer.wrap("parent".getBytes()), "sampleapp");
    StructuredTraceGraph graph = mock(StructuredTraceGraph.class);
    when(graph.getParentEvent(current)).thenReturn(parent);
    String actual = enricher.findServiceNameOfFirstAncestorThatIsNotAnExitSpanAndBelongsToADifferentService(current, "sampleapp", graph).orElse(null);
    String expected = null;
    assertEquals(expected, actual);
}
Also used : Event(org.hypertrace.core.datamodel.Event) StructuredTraceGraph(org.hypertrace.core.datamodel.shared.StructuredTraceGraph) Test(org.junit.jupiter.api.Test)

Example 13 with StructuredTraceGraph

use of org.hypertrace.core.datamodel.shared.StructuredTraceGraph in project hypertrace-ingester by hypertrace.

the class DefaultServiceEntityEnricherTest method test_case3_findServiceNameOfFirstAncestorThatIsNotAnExitSpanAndBelongsToADifferentService.

@Test
public void test_case3_findServiceNameOfFirstAncestorThatIsNotAnExitSpanAndBelongsToADifferentService() {
    // Case 3:  sampleapp (entry) -> sampleapp (exit) -> redis (exit)
    Event parent1 = createEvent(TENANT_ID, "parent1", Map.of("span.kind", "server"), Map.of(API_BOUNDARY_TYPE_ATTR, "ENTRY", "SERVICE_NAME", "sampleapp"), null, "sampleapp");
    Event parent2 = createEvent(TENANT_ID, "parent2", Map.of("span.kind", "client"), Map.of(API_BOUNDARY_TYPE_ATTR, "EXIT", "SERVICE_NAME", "sampleapp"), ByteBuffer.wrap("parent1".getBytes()), "sampleapp");
    Event current = createEvent(TENANT_ID, "current", Map.of("span.kind", "client"), Map.of(API_BOUNDARY_TYPE_ATTR, "EXIT"), ByteBuffer.wrap("parent2".getBytes()), "redis");
    StructuredTraceGraph graph = mock(StructuredTraceGraph.class);
    when(graph.getParentEvent(current)).thenReturn(parent2);
    when(graph.getParentEvent(parent2)).thenReturn(parent1);
    String actual = enricher.findServiceNameOfFirstAncestorThatIsNotAnExitSpanAndBelongsToADifferentService(current, "redis", graph).orElse(null);
    String expected = "sampleapp";
    assertEquals(expected, actual);
}
Also used : Event(org.hypertrace.core.datamodel.Event) StructuredTraceGraph(org.hypertrace.core.datamodel.shared.StructuredTraceGraph) Test(org.junit.jupiter.api.Test)

Example 14 with StructuredTraceGraph

use of org.hypertrace.core.datamodel.shared.StructuredTraceGraph in project hypertrace-ingester by hypertrace.

the class DefaultServiceEntityEnricherTest method test_case4_findServiceNameOfFirstAncestorThatIsNotAnExitSpanAndBelongsToADifferentService.

@Test
public void test_case4_findServiceNameOfFirstAncestorThatIsNotAnExitSpanAndBelongsToADifferentService() {
    // Case 4:  sampleapp (entry) -> sampleapp (exit) -> sampleapp (exit)
    Event parent1 = createEvent(TENANT_ID, "parent1", Map.of("span.kind", "server"), Map.of(API_BOUNDARY_TYPE_ATTR, "ENTRY", "SERVICE_NAME", "sampleapp"), null, "sampleapp");
    Event parent2 = createEvent(TENANT_ID, "parent2", Map.of("span.kind", "client"), Map.of(API_BOUNDARY_TYPE_ATTR, "EXIT", "SERVICE_NAME", "sampleapp"), ByteBuffer.wrap("parent1".getBytes()), "sampleapp");
    Event current = createEvent(TENANT_ID, "current", Map.of("span.kind", "client"), Map.of(API_BOUNDARY_TYPE_ATTR, "EXIT"), ByteBuffer.wrap("parent2".getBytes()), "sampleapp");
    StructuredTraceGraph graph = mock(StructuredTraceGraph.class);
    when(graph.getParentEvent(current)).thenReturn(parent2);
    String actual = enricher.findServiceNameOfFirstAncestorThatIsNotAnExitSpanAndBelongsToADifferentService(current, "sampleapp", graph).orElse(null);
    String expected = null;
    assertEquals(expected, actual);
}
Also used : Event(org.hypertrace.core.datamodel.Event) StructuredTraceGraph(org.hypertrace.core.datamodel.shared.StructuredTraceGraph) Test(org.junit.jupiter.api.Test)

Example 15 with StructuredTraceGraph

use of org.hypertrace.core.datamodel.shared.StructuredTraceGraph in project hypertrace-ingester by hypertrace.

the class ApiBoundaryTypeAttributeEnricher method enrichEvent.

@Override
public void enrichEvent(StructuredTrace trace, Event event) {
    if (event.getEnrichedAttributes() == null) {
        return;
    }
    Map<String, AttributeValue> attributeMap = event.getEnrichedAttributes().getAttributeMap();
    if (attributeMap == null) {
        return;
    }
    boolean isEntrySpan = EnrichedSpanUtils.isEntrySpan(event);
    boolean isExitSpan = EnrichedSpanUtils.isExitSpan(event);
    // does not need to build the full traversal graph, just get the parents mapping
    StructuredTraceGraph graph = buildGraph(trace);
    if (isEntrySpan) {
        /*
      Determines if this is entry span is an entry to  api
      1. If the event is an ENTRY span, and
      2. If the direct parent span is either an EXIT Span or Null, or direct parent span service name differs from current span service name.
      */
        Event parentEvent = graph.getParentEvent(event);
        if (!EnrichedSpanUtils.isEntrySpan(parentEvent) || EnrichedSpanUtils.areBothSpansFromDifferentService(event, parentEvent)) {
            addEnrichedAttribute(event, API_BOUNDARY_TYPE_ATTR_NAME, AttributeValueCreator.create(ENTRY_BOUNDARY_TYPE));
            // For all API entry spans, try to enrich with host header.
            enrichHostHeader(event);
        }
    } else if (isExitSpan) {
        /*
      Determines if this is exit span is an exit to  api
      1. If the event is an EXIT span, and
      2. If the direct child span is either an ENTRY Span or Null, then this is the exit point.
      */
        List<Event> childrenEvents = graph.getChildrenEvents(event);
        if (childrenEvents == null || childrenEvents.isEmpty()) {
            addEnrichedAttribute(event, API_BOUNDARY_TYPE_ATTR_NAME, AttributeValueCreator.create(EXIT_BOUNDARY_TYPE));
        } else {
            for (Event childEvent : childrenEvents) {
                if (EnrichedSpanUtils.isEntrySpan(childEvent)) {
                    addEnrichedAttribute(event, API_BOUNDARY_TYPE_ATTR_NAME, AttributeValueCreator.create(EXIT_BOUNDARY_TYPE));
                    break;
                }
            }
        }
    }
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) StructuredTraceGraph(org.hypertrace.core.datamodel.shared.StructuredTraceGraph)

Aggregations

StructuredTraceGraph (org.hypertrace.core.datamodel.shared.StructuredTraceGraph)15 Event (org.hypertrace.core.datamodel.Event)11 Test (org.junit.jupiter.api.Test)7 List (java.util.List)4 StructuredTrace (org.hypertrace.core.datamodel.StructuredTrace)4 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 Optional (java.util.Optional)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Pair (org.apache.commons.lang3.tuple.Pair)2 Edge (org.hypertrace.core.datamodel.Edge)2 HexUtils (org.hypertrace.core.datamodel.shared.HexUtils)2 EnrichedSpanConstants (org.hypertrace.traceenricher.enrichedspan.constants.EnrichedSpanConstants)2 EnrichedSpanUtils (org.hypertrace.traceenricher.enrichedspan.constants.utils.EnrichedSpanUtils)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1