Search in sources :

Example 21 with ResourceSpans

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));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) Mock(org.mockito.Mock) MetricsTestUtil(com.amazon.dataprepper.metrics.MetricsTestUtil) RunWith(org.junit.runner.RunWith) InstrumentationLibrarySpans(io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans) HashMap(java.util.HashMap) MetricNames(com.amazon.dataprepper.metrics.MetricNames) Channel(io.grpc.Channel) ArrayList(java.util.ArrayList) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) After(org.junit.After) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Resource(io.opentelemetry.proto.resource.v1.Resource) Record(com.amazon.dataprepper.model.record.Record) Before(org.junit.Before) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) TraceServiceGrpc(io.opentelemetry.proto.collector.trace.v1.TraceServiceGrpc) Collectors(java.util.stream.Collectors) Measurement(io.micrometer.core.instrument.Measurement) Span(io.opentelemetry.proto.trace.v1.Span) ByteString(com.google.protobuf.ByteString) Mockito(org.mockito.Mockito) MockedStatic(org.mockito.MockedStatic) List(java.util.List) InstrumentationLibrary(io.opentelemetry.proto.common.v1.InstrumentationLibrary) StringJoiner(java.util.StringJoiner) ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) Assert(org.junit.Assert) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) Channel(io.grpc.Channel) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) ArrayList(java.util.ArrayList) List(java.util.List) Record(com.amazon.dataprepper.model.record.Record) Test(org.junit.Test)

Example 22 with ResourceSpans

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);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) Mock(org.mockito.Mock) MetricsTestUtil(com.amazon.dataprepper.metrics.MetricsTestUtil) RunWith(org.junit.runner.RunWith) InstrumentationLibrarySpans(io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans) HashMap(java.util.HashMap) MetricNames(com.amazon.dataprepper.metrics.MetricNames) Channel(io.grpc.Channel) ArrayList(java.util.ArrayList) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) After(org.junit.After) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Resource(io.opentelemetry.proto.resource.v1.Resource) Record(com.amazon.dataprepper.model.record.Record) Before(org.junit.Before) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) TraceServiceGrpc(io.opentelemetry.proto.collector.trace.v1.TraceServiceGrpc) Collectors(java.util.stream.Collectors) Measurement(io.micrometer.core.instrument.Measurement) Span(io.opentelemetry.proto.trace.v1.Span) ByteString(com.google.protobuf.ByteString) Mockito(org.mockito.Mockito) MockedStatic(org.mockito.MockedStatic) List(java.util.List) InstrumentationLibrary(io.opentelemetry.proto.common.v1.InstrumentationLibrary) StringJoiner(java.util.StringJoiner) ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) Assert(org.junit.Assert) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) Measurement(io.micrometer.core.instrument.Measurement) Channel(io.grpc.Channel) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) ArrayList(java.util.ArrayList) List(java.util.List) Record(com.amazon.dataprepper.model.record.Record) StringJoiner(java.util.StringJoiner) Test(org.junit.Test)

Aggregations

ResourceSpans (io.opentelemetry.proto.trace.v1.ResourceSpans)22 ExportTraceServiceRequest (io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest)13 InstrumentationLibrarySpans (io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans)11 Span (io.opentelemetry.proto.trace.v1.Span)10 ByteString (com.google.protobuf.ByteString)9 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 Record (com.amazon.dataprepper.model.record.Record)8 Measurement (io.micrometer.core.instrument.Measurement)5 StringJoiner (java.util.StringJoiner)5 InstrumentationLibrary (io.opentelemetry.proto.common.v1.InstrumentationLibrary)4 HashMap (java.util.HashMap)4 List (java.util.List)4 PluginSetting (com.amazon.dataprepper.model.configuration.PluginSetting)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)3 Channel (io.grpc.Channel)3 SpanContext (io.opentelemetry.api.trace.SpanContext)3 TraceServiceGrpc (io.opentelemetry.proto.collector.trace.v1.TraceServiceGrpc)3 Resource (io.opentelemetry.proto.resource.v1.Resource)3 Map (java.util.Map)3