use of com.amazon.dataprepper.metrics.PluginMetrics in project data-prepper by opensearch-project.
the class StaticPeerListProvider_CreateTest method setup.
@BeforeEach
void setup() {
pluginSetting = new PluginSetting(PLUGIN_NAME, new HashMap<>());
pluginSetting.setPipelineName(PIPELINE_NAME);
pluginMetrics = mock(PluginMetrics.class);
}
use of com.amazon.dataprepper.metrics.PluginMetrics in project data-prepper by opensearch-project.
the class HTTPSourceTest method testHTTPJsonResponse429.
@Test
public void testHTTPJsonResponse429() throws InterruptedException {
// Prepare
final Map<String, Object> settings = new HashMap<>();
final int testMaxPendingRequests = 1;
final int testThreadCount = 1;
final int clientTimeoutInMillis = 100;
final int serverTimeoutInMillis = (testMaxPendingRequests + testThreadCount + 1) * clientTimeoutInMillis;
when(sourceConfig.getRequestTimeoutInMillis()).thenReturn(serverTimeoutInMillis);
when(sourceConfig.getMaxPendingRequests()).thenReturn(testMaxPendingRequests);
when(sourceConfig.getThreadCount()).thenReturn(testThreadCount);
HTTPSourceUnderTest = new HTTPSource(sourceConfig, pluginMetrics, pluginFactory);
// Start the source
HTTPSourceUnderTest.start(testBuffer);
refreshMeasurements();
final RequestHeaders testRequestHeaders = RequestHeaders.builder().scheme(SessionProtocol.HTTP).authority("127.0.0.1:2021").method(HttpMethod.POST).path("/log/ingest").contentType(MediaType.JSON_UTF_8).build();
final HttpData testHttpData = HttpData.ofUtf8("[{\"log\": \"somelog\"}]");
// Fill in the buffer
WebClient.of().execute(testRequestHeaders, testHttpData).aggregate().whenComplete((i, ex) -> assertSecureResponseWithStatusCode(i, HttpStatus.OK)).join();
// Send requests to throttle the server when buffer is full
// Set the client timeout to be less than source serverTimeoutInMillis / (testMaxPendingRequests + testThreadCount)
WebClient testWebClient = WebClient.builder().responseTimeoutMillis(clientTimeoutInMillis).build();
for (int i = 0; i < testMaxPendingRequests + testThreadCount; i++) {
CompletionException actualException = Assertions.assertThrows(CompletionException.class, () -> testWebClient.execute(testRequestHeaders, testHttpData).aggregate().join());
assertThat(actualException.getCause(), instanceOf(ResponseTimeoutException.class));
}
// When/Then
testWebClient.execute(testRequestHeaders, testHttpData).aggregate().whenComplete((i, ex) -> assertSecureResponseWithStatusCode(i, HttpStatus.TOO_MANY_REQUESTS)).join();
// Wait until source server timeout a request processing thread
Thread.sleep(serverTimeoutInMillis);
// New request should timeout instead of being rejected
CompletionException actualException = Assertions.assertThrows(CompletionException.class, () -> testWebClient.execute(testRequestHeaders, testHttpData).aggregate().join());
assertThat(actualException.getCause(), instanceOf(ResponseTimeoutException.class));
// verify metrics
final Measurement requestReceivedCount = MetricsTestUtil.getMeasurementFromList(requestsReceivedMeasurements, Statistic.COUNT);
Assertions.assertEquals(testMaxPendingRequests + testThreadCount + 2, requestReceivedCount.getValue());
final Measurement successRequestsCount = MetricsTestUtil.getMeasurementFromList(successRequestsMeasurements, Statistic.COUNT);
Assertions.assertEquals(1.0, successRequestsCount.getValue());
final Measurement rejectedRequestsCount = MetricsTestUtil.getMeasurementFromList(rejectedRequestsMeasurements, Statistic.COUNT);
Assertions.assertEquals(1.0, rejectedRequestsCount.getValue());
}
use of com.amazon.dataprepper.metrics.PluginMetrics in project data-prepper by opensearch-project.
the class PluginArgumentsContextTest method createArguments_with_PluginMetrics.
@Test
void createArguments_with_PluginMetrics() {
final PluginArgumentsContext objectUnderTest = new PluginArgumentsContext.Builder().withPluginSetting(pluginSetting).build();
final PluginMetrics pluginMetrics = mock(PluginMetrics.class);
final Object[] arguments;
try (final MockedStatic<PluginMetrics> pluginMetricsMockedStatic = mockStatic(PluginMetrics.class)) {
pluginMetricsMockedStatic.when(() -> PluginMetrics.fromPluginSetting(pluginSetting)).thenReturn(pluginMetrics);
arguments = objectUnderTest.createArguments(new Class[] { PluginSetting.class, PluginMetrics.class });
}
assertThat(arguments, equalTo(new Object[] { pluginSetting, pluginMetrics }));
}
use of com.amazon.dataprepper.metrics.PluginMetrics in project data-prepper by opensearch-project.
the class AbstractProcessorTest method testMetricsWithPluginMetricsConstructor.
@Test
public void testMetricsWithPluginMetricsConstructor() {
final String processorName = "testProcessor";
final String pipelineName = "testPipeline";
MetricsTestUtil.initMetrics();
PluginMetrics pluginMetrics = PluginMetrics.fromNames(processorName, pipelineName);
AbstractProcessor<Record<String>, Record<String>> processor = new ProcessorImpl(pluginMetrics);
processor.execute(Arrays.asList(new Record<>("Value1"), new Record<>("Value2"), new Record<>("Value3")));
final List<Measurement> recordsInMeasurements = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add(pipelineName).add(processorName).add(MetricNames.RECORDS_IN).toString());
final List<Measurement> recordsOutMeasurements = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add(pipelineName).add(processorName).add(MetricNames.RECORDS_OUT).toString());
final List<Measurement> elapsedTimeMeasurements = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add(pipelineName).add(processorName).add(MetricNames.TIME_ELAPSED).toString());
Assertions.assertEquals(1, recordsInMeasurements.size());
Assertions.assertEquals(3.0, recordsInMeasurements.get(0).getValue(), 0);
Assertions.assertEquals(1, recordsOutMeasurements.size());
Assertions.assertEquals(6.0, recordsOutMeasurements.get(0).getValue(), 0);
Assertions.assertEquals(3, elapsedTimeMeasurements.size());
Assertions.assertEquals(1.0, MetricsTestUtil.getMeasurementFromList(elapsedTimeMeasurements, Statistic.COUNT).getValue(), 0);
Assertions.assertTrue(MetricsTestUtil.isBetween(MetricsTestUtil.getMeasurementFromList(elapsedTimeMeasurements, Statistic.TOTAL_TIME).getValue(), 0.1, 0.2));
}
Aggregations