Search in sources :

Example 1 with SpanEventView

use of org.hypertrace.viewgenerator.api.SpanEventView in project hypertrace-ingester by hypertrace.

the class SpanEventViewGeneratorTest method testApiTraceErrorSpanCount.

@Test
public void testApiTraceErrorSpanCount() {
    StructuredTrace.Builder traceBuilder = StructuredTrace.newBuilder();
    traceBuilder.setCustomerId("customer1").setTraceId(ByteBuffer.wrap("sample-trace-id".getBytes())).setEntityList(Collections.singletonList(Entity.newBuilder().setCustomerId("customer1").setEntityId("sample-entity-id").setEntityName("sample-entity-name").setEntityType("SERVICE").build())).setEventList(Collections.singletonList(Event.newBuilder().setCustomerId("customer1").setEventId(ByteBuffer.wrap("sample-span-id".getBytes())).setEventName("sample-span-name").setEntityIdList(Collections.singletonList("sample-entity-id")).setStartTimeMillis(System.currentTimeMillis()).setEndTimeMillis(System.currentTimeMillis()).setMetrics(Metrics.newBuilder().setMetricMap(new HashMap<>()).build()).setAttributesBuilder(Attributes.newBuilder().setAttributeMap(new HashMap<>())).setEnrichedAttributesBuilder(Attributes.newBuilder().setAttributeMap(Maps.newHashMap())).build())).setMetrics(Metrics.newBuilder().setMetricMap(new HashMap<>()).build()).setEntityEdgeList(new ArrayList<>()).setEventEdgeList(new ArrayList<>()).setEntityEventEdgeList(new ArrayList<>()).setStartTimeMillis(System.currentTimeMillis()).setEndTimeMillis(System.currentTimeMillis());
    StructuredTrace trace = traceBuilder.build();
    SpanEventViewGenerator spanEventViewGenerator = new SpanEventViewGenerator();
    List<SpanEventView> list = spanEventViewGenerator.process(trace);
    assertEquals(0, list.get(0).getApiTraceErrorSpanCount());
    Map<String, AttributeValue> spanAttributes = new HashMap<>();
    spanAttributes.put(EnrichedSpanConstants.API_TRACE_ERROR_SPAN_COUNT_ATTRIBUTE, AttributeValue.newBuilder().setValue("5").build());
    traceBuilder.setEventList(Collections.singletonList(Event.newBuilder().setCustomerId("customer1").setEventId(ByteBuffer.wrap("sample-span-id".getBytes())).setEventName("sample-span-name").setEntityIdList(Collections.singletonList("sample-entity-id")).setStartTimeMillis(System.currentTimeMillis()).setEndTimeMillis(System.currentTimeMillis()).setMetrics(Metrics.newBuilder().setMetricMap(new HashMap<>()).build()).setAttributesBuilder(Attributes.newBuilder().setAttributeMap(new HashMap<>())).setEnrichedAttributesBuilder(Attributes.newBuilder().setAttributeMap(spanAttributes)).build())).build();
    trace = traceBuilder.build();
    spanEventViewGenerator = new SpanEventViewGenerator();
    list = spanEventViewGenerator.process(trace);
    assertEquals(5, list.get(0).getApiTraceErrorSpanCount());
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SpanEventView(org.hypertrace.viewgenerator.api.SpanEventView) Test(org.junit.jupiter.api.Test)

Example 2 with SpanEventView

use of org.hypertrace.viewgenerator.api.SpanEventView in project hypertrace-ingester by hypertrace.

the class SpanEventViewGeneratorTest method testSpanEventViewGen_HotrodTrace.

@Test
public void testSpanEventViewGen_HotrodTrace() throws IOException {
    URL resource = Thread.currentThread().getContextClassLoader().getResource("StructuredTrace-Hotrod.avro");
    SpecificDatumReader<StructuredTrace> datumReader = new SpecificDatumReader<>(StructuredTrace.getClassSchema());
    DataFileReader<StructuredTrace> dfrStructuredTrace = new DataFileReader<>(new File(resource.getPath()), datumReader);
    StructuredTrace trace = dfrStructuredTrace.next();
    dfrStructuredTrace.close();
    TraceState traceState = new TraceState(trace);
    verifyGetExitSpanToApiEntrySpan_HotrodTrace(trace, traceState);
    SpanEventViewGenerator spanEventViewGenerator = new SpanEventViewGenerator();
    List<SpanEventView> spanEventViews = spanEventViewGenerator.process(trace);
    assertEquals(50, spanEventViews.size());
}
Also used : TraceState(org.hypertrace.viewgenerator.generators.ViewGeneratorState.TraceState) DataFileReader(org.apache.avro.file.DataFileReader) StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) SpanEventView(org.hypertrace.viewgenerator.api.SpanEventView) SpecificDatumReader(org.apache.avro.specific.SpecificDatumReader) File(java.io.File) URL(java.net.URL) HTTP_URL(org.hypertrace.core.span.constants.v1.Http.HTTP_URL) Test(org.junit.jupiter.api.Test)

Example 3 with SpanEventView

use of org.hypertrace.viewgenerator.api.SpanEventView in project hypertrace-ingester by hypertrace.

the class HypertraceIngesterTest method testIngestionPacketFlow.

@Test
@SetEnvironmentVariable(key = "SERVICE_NAME", value = "hypertrace-ingester")
public void testIngestionPacketFlow(@TempDir Path tempDir) {
    File file = tempDir.resolve("state").toFile();
    Map<String, Object> baseProps = underTest.getBaseStreamsConfig();
    Map<String, Object> streamsProps = underTest.getStreamsConfig(underTestConfig);
    streamsProps.forEach(baseProps::put);
    Map<String, Object> mergedProps = baseProps;
    mergedProps.put(underTest.getJobConfigKey(), underTestConfig);
    StreamsBuilder streamsBuilder = underTest.buildTopology(mergedProps, new StreamsBuilder(), new HashMap<>());
    Properties props = new Properties();
    mergedProps.forEach(props::put);
    mergedProps.put(StreamsConfig.STATE_DIR_CONFIG, file.getAbsolutePath());
    // create topology test driver for ingester
    TopologyTestDriver topologyTestDriver = new TopologyTestDriver(streamsBuilder.build(), props);
    Span span = Span.newBuilder().setSpanId(ByteString.copyFrom("1".getBytes())).setTraceId(ByteString.copyFrom("trace-1".getBytes())).build();
    TestInputTopic<byte[], Span> spanNormalizerInputTopic = topologyTestDriver.createInputTopic(spanNormalizerConfig.getString(org.hypertrace.core.spannormalizer.constants.SpanNormalizerConstants.INPUT_TOPIC_CONFIG_KEY), Serdes.ByteArray().serializer(), new JaegerSpanSerde().serializer());
    spanNormalizerInputTopic.pipeInput(span);
    // create output topic for span-normalizer topology
    TestOutputTopic spanNormalizerOutputTopic = topologyTestDriver.createOutputTopic(spanNormalizerConfig.getString(StructuredTraceEnricherConstants.OUTPUT_TOPIC_CONFIG_KEY), Serdes.String().deserializer(), new AvroSerde<>().deserializer());
    assertNotNull(spanNormalizerOutputTopic.readKeyValue());
    topologyTestDriver.advanceWallClockTime(Duration.ofSeconds(32));
    // create output topic for span-grouper topology
    TestOutputTopic spanGrouperOutputTopic = topologyTestDriver.createOutputTopic(rawSpansGrouperConfig.getString(StructuredTraceEnricherConstants.OUTPUT_TOPIC_CONFIG_KEY), Serdes.String().deserializer(), new AvroSerde<>().deserializer());
    assertNotNull(spanGrouperOutputTopic.readKeyValue());
    // create output topic for trace-enricher topology
    TestOutputTopic traceEnricherOutputTopic = topologyTestDriver.createOutputTopic(traceEnricherConfig.getString(StructuredTraceEnricherConstants.OUTPUT_TOPIC_CONFIG_KEY), Serdes.String().deserializer(), new AvroSerde<>().deserializer());
    assertNotNull(traceEnricherOutputTopic.readKeyValue());
    // create output topic for  topology
    TestOutputTopic spanEventViewOutputTopic = topologyTestDriver.createOutputTopic(spanEventViewGeneratorConfig.getString(StructuredTraceEnricherConstants.OUTPUT_TOPIC_CONFIG_KEY), Serdes.String().deserializer(), new AvroSerde<>().deserializer());
    SpanEventView spanEventView = (SpanEventView) spanEventViewOutputTopic.readValue();
    assertEquals(HexUtils.getHex(spanEventView.getSpanId()), HexUtils.getHex(span.getSpanId().toByteArray()));
    assertEquals(HexUtils.getHex(spanEventView.getTraceId()), HexUtils.getHex(span.getTraceId().toByteArray()));
}
Also used : JaegerSpanSerde(org.hypertrace.core.spannormalizer.jaeger.JaegerSpanSerde) TopologyTestDriver(org.apache.kafka.streams.TopologyTestDriver) SpanEventView(org.hypertrace.viewgenerator.api.SpanEventView) ByteString(com.google.protobuf.ByteString) Properties(java.util.Properties) Span(io.jaegertracing.api_v2.JaegerSpanInternalModel.Span) StreamsBuilder(org.apache.kafka.streams.StreamsBuilder) AvroSerde(org.hypertrace.core.kafkastreams.framework.serdes.AvroSerde) File(java.io.File) TestOutputTopic(org.apache.kafka.streams.TestOutputTopic) SetEnvironmentVariable(org.junitpioneer.jupiter.SetEnvironmentVariable) Test(org.junit.jupiter.api.Test)

Example 4 with SpanEventView

use of org.hypertrace.viewgenerator.api.SpanEventView in project hypertrace-ingester by hypertrace.

the class SpanEventViewGeneratorTest method testExitCallsInfo.

@Test
public void testExitCallsInfo() {
    StructuredTrace.Builder traceBuilder = StructuredTrace.newBuilder();
    traceBuilder.setCustomerId("customer1").setTraceId(ByteBuffer.wrap("sample-trace-id".getBytes())).setEntityList(Collections.singletonList(Entity.newBuilder().setCustomerId("customer1").setEntityId("sample-entity-id").setEntityName("sample-entity-name").setEntityType("SERVICE").build())).setEventList(Collections.singletonList(Event.newBuilder().setCustomerId("customer1").setEventId(ByteBuffer.wrap("sample-span-id".getBytes())).setEventName("sample-span-name").setEntityIdList(Collections.singletonList("sample-entity-id")).setStartTimeMillis(System.currentTimeMillis()).setEndTimeMillis(System.currentTimeMillis()).setMetrics(Metrics.newBuilder().setMetricMap(new HashMap<>()).build()).setAttributesBuilder(Attributes.newBuilder().setAttributeMap(new HashMap<>())).setEnrichedAttributesBuilder(Attributes.newBuilder().setAttributeMap(Maps.newHashMap())).build())).setMetrics(Metrics.newBuilder().setMetricMap(new HashMap<>()).build()).setEntityEdgeList(new ArrayList<>()).setEventEdgeList(new ArrayList<>()).setEntityEventEdgeList(new ArrayList<>()).setStartTimeMillis(System.currentTimeMillis()).setEndTimeMillis(System.currentTimeMillis());
    StructuredTrace trace = traceBuilder.build();
    SpanEventViewGenerator spanEventViewGenerator = new SpanEventViewGenerator();
    List<SpanEventView> list = spanEventViewGenerator.process(trace);
    assertEquals(Maps.newHashMap(), list.get(0).getApiCalleeNameCount());
    assertEquals(0, list.get(0).getApiExitCalls());
    Map<String, AttributeValue> spanAttributes = new HashMap<>();
    spanAttributes.put(EnrichedSpanConstants.API_EXIT_CALLS_ATTRIBUTE, AttributeValue.newBuilder().setValue("5").build());
    Map<String, String> calleeNameCount = Map.of("service1", "5", "backend1", "2");
    spanAttributes.put(EnrichedSpanConstants.API_CALLEE_NAME_COUNT_ATTRIBUTE, AttributeValue.newBuilder().setValueMap(calleeNameCount).build());
    spanAttributes.put(EnrichedSpanConstants.getValue(Api.API_BOUNDARY_TYPE), AttributeValueCreator.create(EnrichedSpanConstants.getValue(BoundaryTypeValue.BOUNDARY_TYPE_VALUE_ENTRY)));
    traceBuilder.setEventList(Collections.singletonList(Event.newBuilder().setCustomerId("customer1").setEventId(ByteBuffer.wrap("sample-span-id".getBytes())).setEventName("sample-span-name").setEntityIdList(Collections.singletonList("sample-entity-id")).setStartTimeMillis(System.currentTimeMillis()).setEndTimeMillis(System.currentTimeMillis()).setMetrics(Metrics.newBuilder().setMetricMap(new HashMap<>()).build()).setAttributesBuilder(Attributes.newBuilder().setAttributeMap(new HashMap<>())).setEnrichedAttributesBuilder(Attributes.newBuilder().setAttributeMap(spanAttributes)).build())).build();
    trace = traceBuilder.build();
    spanEventViewGenerator = new SpanEventViewGenerator();
    list = spanEventViewGenerator.process(trace);
    assertEquals(calleeNameCount, list.get(0).getApiCalleeNameCount());
    assertEquals(5, list.get(0).getApiExitCalls());
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SpanEventView(org.hypertrace.viewgenerator.api.SpanEventView) StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) Test(org.junit.jupiter.api.Test)

Aggregations

SpanEventView (org.hypertrace.viewgenerator.api.SpanEventView)4 Test (org.junit.jupiter.api.Test)4 StructuredTrace (org.hypertrace.core.datamodel.StructuredTrace)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AttributeValue (org.hypertrace.core.datamodel.AttributeValue)2 ByteString (com.google.protobuf.ByteString)1 Span (io.jaegertracing.api_v2.JaegerSpanInternalModel.Span)1 URL (java.net.URL)1 Properties (java.util.Properties)1 DataFileReader (org.apache.avro.file.DataFileReader)1 SpecificDatumReader (org.apache.avro.specific.SpecificDatumReader)1 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)1 TestOutputTopic (org.apache.kafka.streams.TestOutputTopic)1 TopologyTestDriver (org.apache.kafka.streams.TopologyTestDriver)1 AvroSerde (org.hypertrace.core.kafkastreams.framework.serdes.AvroSerde)1 HTTP_URL (org.hypertrace.core.span.constants.v1.Http.HTTP_URL)1 JaegerSpanSerde (org.hypertrace.core.spannormalizer.jaeger.JaegerSpanSerde)1 TraceState (org.hypertrace.viewgenerator.generators.ViewGeneratorState.TraceState)1