use of com.amazon.dataprepper.model.trace.Span in project data-prepper by opensearch-project.
the class OTelProtoCodecTest method testOTelProtoCodecConsistency.
@Test
public void testOTelProtoCodecConsistency() throws IOException, DecoderException {
final ExportTraceServiceRequest request = buildExportTraceServiceRequestFromJsonFile(TEST_REQUEST_JSON_FILE);
final List<Span> spansFirstDec = decoderUnderTest.parseExportTraceServiceRequest(request);
final List<ResourceSpans> resourceSpansList = new ArrayList<>();
for (final Span span : spansFirstDec) {
resourceSpansList.add(encoderUnderTest.convertToResourceSpans(span));
}
final List<Span> spansSecondDec = resourceSpansList.stream().flatMap(rs -> decoderUnderTest.parseResourceSpans(rs).stream()).collect(Collectors.toList());
assertThat(spansFirstDec.size(), equalTo(spansSecondDec.size()));
for (int i = 0; i < spansFirstDec.size(); i++) {
assertThat(spansFirstDec.get(i).toJsonString(), equalTo(spansSecondDec.get(i).toJsonString()));
}
}
use of com.amazon.dataprepper.model.trace.Span in project data-prepper by opensearch-project.
the class OTelTraceGroupProcessor method doExecute.
@Override
public Collection<Record<Span>> doExecute(final Collection<Record<Span>> rawSpanRecords) {
final List<Record<Span>> recordsOut = new LinkedList<>();
final Set<Record<Span>> recordsMissingTraceGroupInfo = new HashSet<>();
final Set<String> traceIdsToLookUp = new HashSet<>();
for (Record<Span> record : rawSpanRecords) {
final Span span = record.getData();
final String traceGroup = span.getTraceGroup();
final String traceId = span.getTraceId();
if (Strings.isNullOrEmpty(traceGroup)) {
traceIdsToLookUp.add(traceId);
recordsMissingTraceGroupInfo.add(record);
recordsInMissingTraceGroupCounter.increment();
} else {
recordsOut.add(record);
}
}
final Map<String, TraceGroup> traceIdToTraceGroup = searchTraceGroupByTraceIds(traceIdsToLookUp);
for (final Record<Span> record : recordsMissingTraceGroupInfo) {
final Span span = record.getData();
final String traceId = span.getTraceId();
final TraceGroup traceGroup = traceIdToTraceGroup.get(traceId);
if (traceGroup != null) {
try {
fillInTraceGroupInfo(span, traceGroup);
recordsOut.add(record);
recordsOutFixedTraceGroupCounter.increment();
} catch (Exception e) {
recordsOut.add(record);
recordsOutMissingTraceGroupCounter.increment();
LOG.error("Failed to process the span: [{}]", record.getData(), e);
}
} else {
recordsOut.add(record);
recordsOutMissingTraceGroupCounter.increment();
final String spanId = span.getSpanId();
LOG.warn("Failed to find traceGroup for spanId: {} due to traceGroup missing for traceId: {}", spanId, traceId);
}
}
return recordsOut;
}
use of com.amazon.dataprepper.model.trace.Span in project data-prepper by opensearch-project.
the class OTelTraceGroupProcessorTests method testTraceGroupFillFailDueToFailedRequest.
@Test
public void testTraceGroupFillFailDueToFailedRequest() throws IOException {
// Arrange
Record<Span> testRecord = buildSpanRecordFromJsonFile(TEST_RAW_SPAN_MISSING_TRACE_GROUP_JSON_FILE_1);
List<Record<Span>> testRecords = Collections.singletonList(testRecord);
when(restHighLevelClient.search(any(SearchRequest.class), any(RequestOptions.class))).thenThrow(new OpenSearchException("Failure due to search request"));
// Act
List<Record<Span>> recordsOut = (List<Record<Span>>) otelTraceGroupProcessor.doExecute(testRecords);
// Assert
assertEquals(1, recordsOut.size());
Record<Span> recordOut = recordsOut.get(0);
assertEquals(testRecord, recordOut);
checkMeasurementValue(OTelTraceGroupProcessor.RECORDS_IN_MISSING_TRACE_GROUP, 1.0);
checkMeasurementValue(OTelTraceGroupProcessor.RECORDS_OUT_FIXED_TRACE_GROUP, 0.0);
checkMeasurementValue(OTelTraceGroupProcessor.RECORDS_OUT_MISSING_TRACE_GROUP, 1.0);
}
use of com.amazon.dataprepper.model.trace.Span in project data-prepper by opensearch-project.
the class PeerForwarderTest method testSingleRemoteIpForwardedRequestOnlyWithEventRecordData.
@Test
public void testSingleRemoteIpForwardedRequestOnlyWithEventRecordData() throws Exception {
final List<String> testIps = generateTestIps(2);
final Channel channel = mock(Channel.class);
final String peerIp = testIps.get(1);
final String fullPeerIp = String.format("%s:21890", peerIp);
when(channel.authority()).thenReturn(fullPeerIp);
when(peerClientPool.getClient(peerIp)).thenReturn(client);
when(client.getChannel()).thenReturn(channel);
final Map<String, List<ExportTraceServiceRequest>> requestsByIp = testIps.stream().collect(Collectors.toMap(ip -> ip, ip -> new ArrayList<>()));
doAnswer(invocation -> {
final ExportTraceServiceRequest exportTraceServiceRequest = invocation.getArgument(0);
requestsByIp.get(peerIp).add(exportTraceServiceRequest);
return null;
}).when(client).export(any(ExportTraceServiceRequest.class));
MetricsTestUtil.initMetrics();
final PeerForwarder testPeerForwarder = generatePeerForwarder(testIps, 3);
final List<Record<Object>> exportedRecords = testPeerForwarder.doExecute(TEST_SPANS_B.stream().map(span -> new Record<Object>(span)).collect(Collectors.toList()));
Assert.assertEquals(1, requestsByIp.get(peerIp).size());
final ExportTraceServiceRequest forwardedRequest = requestsByIp.get(peerIp).get(0);
final List<ResourceSpans> forwardedResourceSpans = forwardedRequest.getResourceSpansList();
assertEquals(3, forwardedResourceSpans.size());
forwardedResourceSpans.forEach(rs -> {
assertEquals(TEST_SERVICE_B, extractServiceName(rs));
assertEquals(1, rs.getInstrumentationLibrarySpansCount());
final InstrumentationLibrarySpans ils = rs.getInstrumentationLibrarySpans(0);
assertEquals(1, ils.getSpansCount());
final io.opentelemetry.proto.trace.v1.Span sp = ils.getSpans(0);
assertEquals(TEST_TRACE_ID_2, Hex.encodeHexString(sp.getTraceId().toByteArray()));
});
Assert.assertEquals(0, exportedRecords.size());
// Verify metrics
final List<Measurement> forwardRequestErrorMeasurements = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add(TEST_PIPELINE_NAME).add("peer_forwarder").add(PeerForwarder.ERRORS).toString());
Assert.assertEquals(1, forwardRequestErrorMeasurements.size());
Assert.assertEquals(0.0, forwardRequestErrorMeasurements.get(0).getValue(), 0);
final List<Measurement> forwardRequestSuccessMeasurements = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add(TEST_PIPELINE_NAME).add("peer_forwarder").add(PeerForwarder.REQUESTS).toString());
Assert.assertEquals(1, forwardRequestSuccessMeasurements.size());
Assert.assertEquals(1.0, forwardRequestSuccessMeasurements.get(0).getValue(), 0);
final List<Measurement> forwardRequestLatencyMeasurements = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add(TEST_PIPELINE_NAME).add("peer_forwarder").add(PeerForwarder.LATENCY).toString());
Assert.assertEquals(3, forwardRequestLatencyMeasurements.size());
// COUNT
Assert.assertEquals(1.0, forwardRequestLatencyMeasurements.get(0).getValue(), 0);
// TOTAL_TIME
assertTrue(forwardRequestLatencyMeasurements.get(1).getValue() > 0.0);
// MAX
assertTrue(forwardRequestLatencyMeasurements.get(2).getValue() > 0.0);
}
use of com.amazon.dataprepper.model.trace.Span in project data-prepper by opensearch-project.
the class PeerForwarderTest method testSingleRemoteIpForwardRequestClientErrorWithEventRecordData.
@Test
public void testSingleRemoteIpForwardRequestClientErrorWithEventRecordData() {
final List<String> testIps = generateTestIps(2);
final Channel channel = mock(Channel.class);
final String peerIp = testIps.get(1);
final String fullPeerIp = String.format("%s:21890", peerIp);
when(channel.authority()).thenReturn(fullPeerIp);
when(peerClientPool.getClient(peerIp)).thenReturn(client);
when(client.export(any(ExportTraceServiceRequest.class))).thenThrow(new RuntimeException());
when(client.getChannel()).thenReturn(channel);
MetricsTestUtil.initMetrics();
final PeerForwarder testPeerForwarder = generatePeerForwarder(testIps, 3);
final List<Record<Object>> exportedRecords = testPeerForwarder.doExecute(TEST_SPANS_B.stream().map(span -> new Record<Object>(span)).collect(Collectors.toList()));
Assert.assertEquals(3, exportedRecords.size());
final List<Span> exportedSpans = exportedRecords.stream().map(record -> (Span) record.getData()).collect(Collectors.toList());
assertTrue(exportedSpans.containsAll(TEST_SPANS_B));
assertTrue(TEST_SPANS_B.containsAll(exportedSpans));
// Verify metrics
final List<Measurement> forwardRequestErrorMeasurements = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add(TEST_PIPELINE_NAME).add("peer_forwarder").add(PeerForwarder.ERRORS).toString());
Assert.assertEquals(1, forwardRequestErrorMeasurements.size());
Assert.assertEquals(1.0, forwardRequestErrorMeasurements.get(0).getValue(), 0);
final List<Measurement> forwardRequestSuccessMeasurements = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add(TEST_PIPELINE_NAME).add("peer_forwarder").add(PeerForwarder.REQUESTS).toString());
Assert.assertEquals(1, forwardRequestSuccessMeasurements.size());
Assert.assertEquals(1.0, forwardRequestSuccessMeasurements.get(0).getValue(), 0);
final List<Measurement> forwardRequestLatencyMeasurements = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add(TEST_PIPELINE_NAME).add("peer_forwarder").add(PeerForwarder.LATENCY).toString());
Assert.assertEquals(3, forwardRequestLatencyMeasurements.size());
// COUNT
Assert.assertEquals(1.0, forwardRequestLatencyMeasurements.get(0).getValue(), 0);
// TOTAL_TIME
assertTrue(forwardRequestLatencyMeasurements.get(1).getValue() > 0.0);
// MAX
assertTrue(forwardRequestLatencyMeasurements.get(2).getValue() > 0.0);
}
Aggregations