use of com.amazon.dataprepper.model.record.Record in project data-prepper by opensearch-project.
the class PeerForwarderTest method testSingleRemoteIpForwardedRequestOnlyWithExportTraceServiceRequestRecordData.
// TODO: remove in 2.0
@Test
public void testSingleRemoteIpForwardedRequestOnlyWithExportTraceServiceRequestRecordData() 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(Collections.singletonList(new Record<>(REQUEST_4)));
final List<ResourceSpans> expectedForwardedResourceSpans = Collections.singletonList(generateResourceSpans(OTLP_SPAN_4, OTLP_SPAN_5, OTLP_SPAN_6));
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));
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());
assertEquals(1, forwardRequestErrorMeasurements.size());
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());
assertEquals(1, forwardRequestSuccessMeasurements.size());
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());
assertEquals(3, forwardRequestLatencyMeasurements.size());
// COUNT
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.record.Record 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);
}
use of com.amazon.dataprepper.model.record.Record in project data-prepper by opensearch-project.
the class PeerForwarderTest method testSingleRemoteIpBothLocalAndForwardedRequestWithExportTraceServiceRequestRecordData.
// TODO: remove in 2.0
@Test
public void testSingleRemoteIpBothLocalAndForwardedRequestWithExportTraceServiceRequestRecordData() {
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<Object>> exportedRecords = testPeerForwarder.doExecute(Arrays.asList(new Record<>(REQUEST_1), new Record<>(REQUEST_2)));
final List<ResourceSpans> expectedLocalResourceSpans = Arrays.asList(generateResourceSpans(OTLP_SPAN_1, OTLP_SPAN_2), generateResourceSpans(OTLP_SPAN_3));
final List<ResourceSpans> expectedForwardedResourceSpans = Arrays.asList(generateResourceSpans(OTLP_SPAN_5, OTLP_SPAN_6), generateResourceSpans(OTLP_SPAN_4));
assertEquals(1, exportedRecords.size());
final ExportTraceServiceRequest localRequest = (ExportTraceServiceRequest) exportedRecords.get(0).getData();
final List<ResourceSpans> localResourceSpans = localRequest.getResourceSpansList();
assertTrue(localResourceSpans.containsAll(expectedLocalResourceSpans));
assertTrue(expectedLocalResourceSpans.containsAll(localResourceSpans));
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 com.amazon.dataprepper.model.record.Record in project data-prepper by opensearch-project.
the class PeerForwarderTest method testSingleRemoteIpForwardRequestClientErrorWithExportTraceServiceRequestRecordData.
// TODO: remove in 2.0
@Test
public void testSingleRemoteIpForwardRequestClientErrorWithExportTraceServiceRequestRecordData() {
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(Collections.singletonList(new Record<>(REQUEST_4)));
final List<ResourceSpans> expectedLocalResourceSpans = Collections.singletonList(generateResourceSpans(OTLP_SPAN_4, OTLP_SPAN_5, OTLP_SPAN_6));
assertEquals(1, exportedRecords.size());
final ExportTraceServiceRequest exportedRequest = (ExportTraceServiceRequest) exportedRecords.get(0).getData();
final List<ResourceSpans> forwardedResourceSpans = exportedRequest.getResourceSpansList();
assertTrue(forwardedResourceSpans.containsAll(expectedLocalResourceSpans));
assertTrue(expectedLocalResourceSpans.containsAll(forwardedResourceSpans));
// Verify metrics
final List<Measurement> forwardRequestErrorMeasurements = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add(TEST_PIPELINE_NAME).add("peer_forwarder").add(PeerForwarder.ERRORS).toString());
assertEquals(1, forwardRequestErrorMeasurements.size());
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());
assertEquals(1, forwardRequestSuccessMeasurements.size());
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());
assertEquals(3, forwardRequestLatencyMeasurements.size());
// COUNT
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.record.Record in project data-prepper by opensearch-project.
the class PeerForwarderTest method testSingleRemoteIpLocalRequestOnlyWithExportTraceServiceRequestRecordData.
// TODO: remove in 2.0
@Test
public void testSingleRemoteIpLocalRequestOnlyWithExportTraceServiceRequestRecordData() throws Exception {
final List<String> testIps = generateTestIps(2);
final PeerForwarder testPeerForwarder = generatePeerForwarder(testIps, 3);
final List<Record<Object>> exportedRecords = testPeerForwarder.doExecute(Collections.singletonList(new Record<>(REQUEST_3)));
final List<ResourceSpans> expectedLocalResourceSpans = Collections.singletonList(generateResourceSpans(OTLP_SPAN_1, OTLP_SPAN_2, OTLP_SPAN_3));
assertEquals(1, exportedRecords.size());
final ExportTraceServiceRequest localRequest = (ExportTraceServiceRequest) exportedRecords.get(0).getData();
final List<ResourceSpans> localResourceSpans = localRequest.getResourceSpansList();
assertTrue(localResourceSpans.containsAll(expectedLocalResourceSpans));
assertTrue(expectedLocalResourceSpans.containsAll(localResourceSpans));
}
Aggregations