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());
}
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());
}
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()));
}
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());
}
Aggregations