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();
}
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);
}
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());
}
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);
}
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);
});
}
Aggregations