use of io.opentelemetry.proto.trace.v1.ResourceSpans in project data-prepper by opensearch-project.
the class PeerForwarderTest method testSingleRemoteIpBothLocalAndForwardedRequest.
@Test
public void testSingleRemoteIpBothLocalAndForwardedRequest() {
final List<String> testIps = generateTestIps(2);
final Channel channel = mock(Channel.class);
final String peerIp = testIps.get(1);
when(channel.authority()).thenReturn(String.format("%s:21890", peerIp));
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<ExportTraceServiceRequest>> exportedRecords = testPeerForwarder.doExecute(Arrays.asList(new Record<>(REQUEST_1), new Record<>(REQUEST_2)));
final List<ResourceSpans> expectedLocalResourceSpans = Arrays.asList(generateResourceSpans(SPAN_1, SPAN_2), generateResourceSpans(SPAN_3));
final List<ResourceSpans> expectedForwardedResourceSpans = Arrays.asList(generateResourceSpans(SPAN_5, SPAN_6), generateResourceSpans(SPAN_4));
Assert.assertEquals(1, exportedRecords.size());
final ExportTraceServiceRequest localRequest = exportedRecords.get(0).getData();
final List<ResourceSpans> localResourceSpans = localRequest.getResourceSpansList();
assertTrue(localResourceSpans.containsAll(expectedLocalResourceSpans));
assertTrue(expectedLocalResourceSpans.containsAll(localResourceSpans));
Assert.assertEquals(1, requestsByIp.get(peerIp).size());
final ExportTraceServiceRequest forwardedRequest = requestsByIp.get(peerIp).get(0);
final List<ResourceSpans> forwardedResourceSpans = forwardedRequest.getResourceSpansList();
assertTrue(forwardedResourceSpans.containsAll(expectedForwardedResourceSpans));
assertTrue(expectedForwardedResourceSpans.containsAll(forwardedResourceSpans));
}
use of io.opentelemetry.proto.trace.v1.ResourceSpans in project data-prepper by opensearch-project.
the class PeerForwarderTest method testSingleRemoteIpForwardedRequestOnly.
@Test
public void testSingleRemoteIpForwardedRequestOnly() 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<ExportTraceServiceRequest>> exportedRecords = testPeerForwarder.doExecute(Collections.singletonList(new Record<>(REQUEST_4)));
final List<ResourceSpans> expectedForwardedResourceSpans = Collections.singletonList(generateResourceSpans(SPAN_4, SPAN_5, SPAN_6));
Assert.assertEquals(1, requestsByIp.get(peerIp).size());
final ExportTraceServiceRequest forwardedRequest = requestsByIp.get(peerIp).get(0);
final List<ResourceSpans> forwardedResourceSpans = forwardedRequest.getResourceSpansList();
assertTrue(forwardedResourceSpans.containsAll(expectedForwardedResourceSpans));
assertTrue(expectedForwardedResourceSpans.containsAll(forwardedResourceSpans));
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);
}
Aggregations