Search in sources :

Example 36 with Record

use of com.amazon.dataprepper.model.record.Record in project data-prepper by opensearch-project.

the class ServiceMapStatefulPrepperTest method testPrepareForShutdownWithExportTraceServiceRequestRecordData.

// TODO: remove in 2.0
@Test
public void testPrepareForShutdownWithExportTraceServiceRequestRecordData() throws Exception {
    final File path = new File(ServiceMapPrepperConfig.DEFAULT_DB_PATH);
    final ServiceMapStatefulPrepper serviceMapStateful = new ServiceMapStatefulPrepper(100, path, Clock.systemUTC(), 1, PLUGIN_SETTING);
    final byte[] rootSpanId1 = ServiceMapTestUtils.getRandomBytes(8);
    final byte[] traceId1 = ServiceMapTestUtils.getRandomBytes(16);
    final String traceGroup1 = "reset_password";
    final ResourceSpans frontendSpans1 = ServiceMapTestUtils.getResourceSpans(FRONTEND_SERVICE, traceGroup1, rootSpanId1, null, traceId1, io.opentelemetry.proto.trace.v1.Span.SpanKind.SPAN_KIND_CLIENT);
    final ResourceSpans authenticationSpansServer = ServiceMapTestUtils.getResourceSpans(AUTHENTICATION_SERVICE, "reset", ServiceMapTestUtils.getRandomBytes(8), ServiceMapTestUtils.getSpanId(frontendSpans1), traceId1, io.opentelemetry.proto.trace.v1.Span.SpanKind.SPAN_KIND_SERVER);
    serviceMapStateful.execute(Collections.singletonList(new Record<>(ServiceMapTestUtils.getExportTraceServiceRequest(frontendSpans1, authenticationSpansServer))));
    assertFalse(serviceMapStateful.isReadyForShutdown());
    serviceMapStateful.prepareForShutdown();
    serviceMapStateful.execute(Collections.emptyList());
    assertTrue(serviceMapStateful.isReadyForShutdown());
    serviceMapStateful.shutdown();
}
Also used : Record(com.amazon.dataprepper.model.record.Record) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) File(java.io.File) Test(org.junit.Test)

Example 37 with Record

use of com.amazon.dataprepper.model.record.Record in project data-prepper by opensearch-project.

the class MetricsPluginSummaryTest method testSummaryProcessing.

@Test
public void testSummaryProcessing() throws JsonProcessingException {
    SummaryDataPoint dataPoint = SummaryDataPoint.newBuilder().addQuantileValues(SummaryDataPoint.ValueAtQuantile.newBuilder().setQuantile(0.5).setValue(100).build()).addQuantileValues(SummaryDataPoint.ValueAtQuantile.newBuilder().setQuantile(0.7).setValue(250).build()).build();
    Summary summary = Summary.newBuilder().addDataPoints(dataPoint).build();
    Metric metric = Metric.newBuilder().setSummary(summary).setUnit("seconds").setName("name").setDescription("description").build();
    InstrumentationLibraryMetrics instLib = InstrumentationLibraryMetrics.newBuilder().addMetrics(metric).build();
    Resource resource = Resource.newBuilder().addAttributes(KeyValue.newBuilder().setKey("service.name").setValue(AnyValue.newBuilder().setStringValue("service").build())).build();
    ResourceMetrics resourceMetrics = ResourceMetrics.newBuilder().setResource(resource).addInstrumentationLibraryMetrics(instLib).build();
    ExportMetricsServiceRequest exportMetricRequest = ExportMetricsServiceRequest.newBuilder().addResourceMetrics(resourceMetrics).build();
    Record record = new Record<>(exportMetricRequest);
    List<Record<Event>> rec = (List<Record<Event>>) rawProcessor.doExecute(Arrays.asList(record));
    Record<Event> firstRecord = rec.get(0);
    ObjectMapper objectMapper = new ObjectMapper();
    Map map = objectMapper.readValue(firstRecord.getData().toJsonString(), Map.class);
    assertSumProcessing(map);
}
Also used : Resource(io.opentelemetry.proto.resource.v1.Resource) InstrumentationLibraryMetrics(io.opentelemetry.proto.metrics.v1.InstrumentationLibraryMetrics) ResourceMetrics(io.opentelemetry.proto.metrics.v1.ResourceMetrics) Summary(io.opentelemetry.proto.metrics.v1.Summary) Event(com.amazon.dataprepper.model.event.Event) Metric(io.opentelemetry.proto.metrics.v1.Metric) Record(com.amazon.dataprepper.model.record.Record) List(java.util.List) SummaryDataPoint(io.opentelemetry.proto.metrics.v1.SummaryDataPoint) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ExportMetricsServiceRequest(io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest) Test(org.junit.Test)

Example 38 with Record

use of com.amazon.dataprepper.model.record.Record in project data-prepper by opensearch-project.

the class OTelMetricsGrpcServiceTest method export_Success_responseObserverOnCompleted.

@Test
public void export_Success_responseObserverOnCompleted() throws Exception {
    sut.export(METRICS_REQUEST, responseObserver);
    verify(buffer, times(1)).write(recordCaptor.capture(), anyInt());
    verify(responseObserver, times(1)).onNext(ExportMetricsServiceResponse.newBuilder().build());
    verify(responseObserver, times(1)).onCompleted();
    verify(requestsReceivedCounter, times(1)).increment();
    verifyNoInteractions(timeoutCounter);
    Record capturedRecord = recordCaptor.getValue();
    assertEquals(METRICS_REQUEST, capturedRecord.getData());
}
Also used : Record(com.amazon.dataprepper.model.record.Record) Test(org.junit.jupiter.api.Test)

Example 39 with Record

use of com.amazon.dataprepper.model.record.Record in project data-prepper by opensearch-project.

the class OTelTraceRawPrepperTest method testResourceSpansProcessingErrorMetrics.

@Test
public void testResourceSpansProcessingErrorMetrics() {
    ExportTraceServiceRequest mockData = mock(ExportTraceServiceRequest.class);
    Record record = new Record(mockData);
    ResourceSpans mockResourceSpans = mock(ResourceSpans.class);
    List<ResourceSpans> mockResourceSpansList = Collections.singletonList(mockResourceSpans);
    when(mockData.getResourceSpansList()).thenReturn(mockResourceSpansList);
    when(mockResourceSpans.getResource()).thenThrow(new RuntimeException());
    oTelTraceRawPrepper.doExecute(Collections.singletonList(record));
    final List<Measurement> resourceSpansErrorsMeasurement = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add("pipelineOTelTrace").add("OTelTrace").add(OTelTraceRawPrepper.RESOURCE_SPANS_PROCESSING_ERRORS).toString());
    final List<Measurement> totalErrorsMeasurement = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add("pipelineOTelTrace").add("OTelTrace").add(OTelTraceRawPrepper.TOTAL_PROCESSING_ERRORS).toString());
    Assert.assertEquals(1, resourceSpansErrorsMeasurement.size());
    Assert.assertEquals(1.0, resourceSpansErrorsMeasurement.get(0).getValue(), 0);
    Assert.assertEquals(1, totalErrorsMeasurement.size());
    Assert.assertEquals(1.0, totalErrorsMeasurement.get(0).getValue(), 0);
}
Also used : ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) Measurement(io.micrometer.core.instrument.Measurement) Record(com.amazon.dataprepper.model.record.Record) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) StringJoiner(java.util.StringJoiner) Test(org.junit.Test)

Example 40 with Record

use of com.amazon.dataprepper.model.record.Record in project data-prepper by opensearch-project.

the class OTelTraceRawPrepperTest method testExportRequestFlushByParentSpanMultiThread.

@Test
public void testExportRequestFlushByParentSpanMultiThread() throws IOException, InterruptedException, ExecutionException {
    final ExportTraceServiceRequest exportTraceServiceRequest1 = buildExportTraceServiceRequestFromJsonFile(TEST_REQUEST_TWO_TRACE_GROUP_INTERLEAVED_JSON_FILE_1);
    final ExportTraceServiceRequest exportTraceServiceRequest2 = buildExportTraceServiceRequestFromJsonFile(TEST_REQUEST_TWO_TRACE_GROUP_INTERLEAVED_JSON_FILE_2);
    final List<Record<String>> processedRecords = new ArrayList<>();
    List<Future<Collection<Record<String>>>> futures = new ArrayList<>();
    futures.addAll(submitExportTraceServiceRequests(Collections.singletonList(exportTraceServiceRequest1)));
    futures.addAll(submitExportTraceServiceRequests(Collections.singletonList(exportTraceServiceRequest2)));
    for (Future<Collection<Record<String>>> future : futures) {
        processedRecords.addAll(future.get());
    }
    await().atMost(2 * TEST_TRACE_FLUSH_INTERVAL, TimeUnit.SECONDS).untilAsserted(() -> {
        List<Future<Collection<Record<String>>>> futureList = submitExportTraceServiceRequests(Collections.emptyList());
        for (Future<Collection<Record<String>>> future : futureList) {
            processedRecords.addAll(future.get());
        }
        Assertions.assertThat(processedRecords.size()).isEqualTo(6);
        Assertions.assertThat(getMissingTraceGroupFieldsSpanCount(processedRecords)).isEqualTo(0);
    });
}
Also used : ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Collection(java.util.Collection) Record(com.amazon.dataprepper.model.record.Record) Test(org.junit.Test)

Aggregations

Record (com.amazon.dataprepper.model.record.Record)103 Test (org.junit.Test)43 Measurement (io.micrometer.core.instrument.Measurement)35 StringJoiner (java.util.StringJoiner)35 PluginSetting (com.amazon.dataprepper.model.configuration.PluginSetting)33 ArrayList (java.util.ArrayList)31 Map (java.util.Map)30 Test (org.junit.jupiter.api.Test)30 HashMap (java.util.HashMap)29 List (java.util.List)28 Event (com.amazon.dataprepper.model.event.Event)23 ExportTraceServiceRequest (io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest)20 ResourceSpans (io.opentelemetry.proto.trace.v1.ResourceSpans)19 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)16 JacksonEvent (com.amazon.dataprepper.model.event.JacksonEvent)14 ByteString (com.google.protobuf.ByteString)13 ExecutorService (java.util.concurrent.ExecutorService)13 Resource (io.opentelemetry.proto.resource.v1.Resource)12 Channel (io.grpc.Channel)11 MetricNames (com.amazon.dataprepper.metrics.MetricNames)10