Search in sources :

Example 11 with PluginSetting

use of com.amazon.dataprepper.model.configuration.PluginSetting in project data-prepper by opensearch-project.

the class OpenSearchSinkIT method testInstantiateSinkCustomIndex_NoRollOver.

@Test
public void testInstantiateSinkCustomIndex_NoRollOver() throws IOException {
    final String testIndexAlias = "test-alias";
    final String testTemplateFile = Objects.requireNonNull(getClass().getClassLoader().getResource(TEST_TEMPLATE_V1_FILE)).getFile();
    final PluginSetting pluginSetting = generatePluginSetting(false, false, testIndexAlias, testTemplateFile);
    OpenSearchSink sink = new OpenSearchSink(pluginSetting);
    final Request request = new Request(HttpMethod.HEAD, testIndexAlias);
    final Response response = client.performRequest(request);
    MatcherAssert.assertThat(response.getStatusLine().getStatusCode(), equalTo(SC_OK));
    sink.shutdown();
    // Check restart for index already exists
    sink = new OpenSearchSink(pluginSetting);
    sink.shutdown();
}
Also used : Response(org.opensearch.client.Response) Request(org.opensearch.client.Request) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with PluginSetting

use of com.amazon.dataprepper.model.configuration.PluginSetting in project data-prepper by opensearch-project.

the class OpenSearchSinkIT method testOutputRawSpanDefault.

@ParameterizedTest
@ArgumentsSource(MultipleRecordTypeArgumentProvider.class)
public void testOutputRawSpanDefault(final Function<String, Record> stringToRecord) throws IOException, InterruptedException {
    final String testDoc1 = readDocFromFile(DEFAULT_RAW_SPAN_FILE_1);
    final String testDoc2 = readDocFromFile(DEFAULT_RAW_SPAN_FILE_2);
    final ObjectMapper mapper = new ObjectMapper();
    @SuppressWarnings("unchecked") final Map<String, Object> expData1 = mapper.readValue(testDoc1, Map.class);
    @SuppressWarnings("unchecked") final Map<String, Object> expData2 = mapper.readValue(testDoc2, Map.class);
    final List<Record<Object>> testRecords = Arrays.asList(stringToRecord.apply(testDoc1), stringToRecord.apply(testDoc2));
    final PluginSetting pluginSetting = generatePluginSetting(true, false, null, null);
    final OpenSearchSink sink = new OpenSearchSink(pluginSetting);
    sink.output(testRecords);
    final String expIndexAlias = IndexConstants.TYPE_TO_DEFAULT_ALIAS.get(IndexType.TRACE_ANALYTICS_RAW);
    final List<Map<String, Object>> retSources = getSearchResponseDocSources(expIndexAlias);
    MatcherAssert.assertThat(retSources.size(), equalTo(2));
    MatcherAssert.assertThat(retSources, hasItems(expData1, expData2));
    MatcherAssert.assertThat(getDocumentCount(expIndexAlias, "_id", (String) expData1.get("spanId")), equalTo(Integer.valueOf(1)));
    sink.shutdown();
    // Verify metrics
    final List<Measurement> bulkRequestErrors = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add(PIPELINE_NAME).add(PLUGIN_NAME).add(OpenSearchSink.BULKREQUEST_ERRORS).toString());
    MatcherAssert.assertThat(bulkRequestErrors.size(), equalTo(1));
    Assert.assertEquals(0.0, bulkRequestErrors.get(0).getValue(), 0);
    final List<Measurement> bulkRequestLatencies = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add(PIPELINE_NAME).add(PLUGIN_NAME).add(OpenSearchSink.BULKREQUEST_LATENCY).toString());
    MatcherAssert.assertThat(bulkRequestLatencies.size(), equalTo(3));
    // COUNT
    Assert.assertEquals(1.0, bulkRequestLatencies.get(0).getValue(), 0);
    // TOTAL_TIME
    Assert.assertTrue(bulkRequestLatencies.get(1).getValue() > 0.0);
    // MAX
    Assert.assertTrue(bulkRequestLatencies.get(2).getValue() > 0.0);
    final List<Measurement> documentsSuccessMeasurements = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add(PIPELINE_NAME).add(PLUGIN_NAME).add(BulkRetryStrategy.DOCUMENTS_SUCCESS).toString());
    MatcherAssert.assertThat(documentsSuccessMeasurements.size(), equalTo(1));
    MatcherAssert.assertThat(documentsSuccessMeasurements.get(0).getValue(), closeTo(2.0, 0));
    final List<Measurement> documentsSuccessFirstAttemptMeasurements = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add(PIPELINE_NAME).add(PLUGIN_NAME).add(BulkRetryStrategy.DOCUMENTS_SUCCESS_FIRST_ATTEMPT).toString());
    MatcherAssert.assertThat(documentsSuccessFirstAttemptMeasurements.size(), equalTo(1));
    MatcherAssert.assertThat(documentsSuccessFirstAttemptMeasurements.get(0).getValue(), closeTo(2.0, 0));
    final List<Measurement> documentErrorsMeasurements = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add(PIPELINE_NAME).add(PLUGIN_NAME).add(BulkRetryStrategy.DOCUMENT_ERRORS).toString());
    MatcherAssert.assertThat(documentErrorsMeasurements.size(), equalTo(1));
    MatcherAssert.assertThat(documentErrorsMeasurements.get(0).getValue(), closeTo(0.0, 0));
    /**
     * Metrics: Bulk Request Size in Bytes
     */
    final List<Measurement> bulkRequestSizeBytesMetrics = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add(PIPELINE_NAME).add(PLUGIN_NAME).add(OpenSearchSink.BULKREQUEST_SIZE_BYTES).toString());
    MatcherAssert.assertThat(bulkRequestSizeBytesMetrics.size(), equalTo(3));
    MatcherAssert.assertThat(bulkRequestSizeBytesMetrics.get(0).getValue(), closeTo(1.0, 0));
    MatcherAssert.assertThat(bulkRequestSizeBytesMetrics.get(1).getValue(), closeTo(2058.0, 0));
    MatcherAssert.assertThat(bulkRequestSizeBytesMetrics.get(2).getValue(), closeTo(2058.0, 0));
}
Also used : Measurement(io.micrometer.core.instrument.Measurement) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Record(com.amazon.dataprepper.model.record.Record) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Map(java.util.Map) HashMap(java.util.HashMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) StringJoiner(java.util.StringJoiner) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 13 with PluginSetting

use of com.amazon.dataprepper.model.configuration.PluginSetting in project data-prepper by opensearch-project.

the class OpenSearchSinkIT method testInstantiateSinkServiceMapDefault.

@Test
public void testInstantiateSinkServiceMapDefault() throws IOException {
    final PluginSetting pluginSetting = generatePluginSetting(false, true, null, null);
    final OpenSearchSink sink = new OpenSearchSink(pluginSetting);
    final String indexAlias = IndexConstants.TYPE_TO_DEFAULT_ALIAS.get(IndexType.TRACE_ANALYTICS_SERVICE_MAP);
    final Request request = new Request(HttpMethod.HEAD, indexAlias);
    final Response response = client.performRequest(request);
    MatcherAssert.assertThat(response.getStatusLine().getStatusCode(), equalTo(SC_OK));
    final Map<String, Object> mappings = getIndexMappings(indexAlias);
    MatcherAssert.assertThat(mappings, notNullValue());
    MatcherAssert.assertThat((boolean) mappings.get("date_detection"), equalTo(false));
    sink.shutdown();
    if (isOSBundle()) {
        // Check managed index
        MatcherAssert.assertThat(getIndexPolicyId(indexAlias), nullValue());
    }
}
Also used : Response(org.opensearch.client.Response) Request(org.opensearch.client.Request) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with PluginSetting

use of com.amazon.dataprepper.model.configuration.PluginSetting in project data-prepper by opensearch-project.

the class HTTPSourceTest method getBuffer.

private BlockingBuffer<Record<Log>> getBuffer() {
    final HashMap<String, Object> integerHashMap = new HashMap<>();
    integerHashMap.put("buffer_size", 1);
    integerHashMap.put("batch_size", 1);
    final PluginSetting pluginSetting = new PluginSetting("blocking_buffer", integerHashMap) {

        {
            setPipelineName(TEST_PIPELINE_NAME);
        }
    };
    return new BlockingBuffer<>(pluginSetting);
}
Also used : HashMap(java.util.HashMap) BlockingBuffer(com.amazon.dataprepper.plugins.buffer.blockingbuffer.BlockingBuffer) AsciiString(io.netty.util.AsciiString) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting)

Example 15 with PluginSetting

use of com.amazon.dataprepper.model.configuration.PluginSetting in project data-prepper by opensearch-project.

the class GrokPrepperConfigTests method testDefault.

@Test
public void testDefault() {
    final GrokPrepperConfig grokPrepperConfig = GrokPrepperConfig.buildConfig(new PluginSetting(PLUGIN_NAME, null));
    assertThat(grokPrepperConfig.isBreakOnMatch(), equalTo(DEFAULT_BREAK_ON_MATCH));
    assertThat(grokPrepperConfig.isKeepEmptyCaptures(), equalTo(DEFAULT_KEEP_EMPTY_CAPTURES));
    assertThat(grokPrepperConfig.getMatch(), equalTo(Collections.emptyMap()));
    assertThat(grokPrepperConfig.getkeysToOverwrite(), equalTo(Collections.emptyList()));
    assertThat(grokPrepperConfig.getPatternDefinitions(), equalTo(Collections.emptyMap()));
    assertThat(grokPrepperConfig.getPatternsDirectories(), equalTo(Collections.emptyList()));
    assertThat(grokPrepperConfig.getPatternsFilesGlob(), equalTo(DEFAULT_PATTERNS_FILES_GLOB));
    assertThat(grokPrepperConfig.getTargetKey(), equalTo(DEFAULT_TARGET_KEY));
    assertThat(grokPrepperConfig.isNamedCapturesOnly(), equalTo(DEFAULT_NAMED_CAPTURES_ONLY));
    assertThat(grokPrepperConfig.getTimeoutMillis(), equalTo(DEFAULT_TIMEOUT_MILLIS));
}
Also used : PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Test(org.junit.jupiter.api.Test)

Aggregations

PluginSetting (com.amazon.dataprepper.model.configuration.PluginSetting)150 Test (org.junit.jupiter.api.Test)58 HashMap (java.util.HashMap)55 Test (org.junit.Test)43 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 Record (com.amazon.dataprepper.model.record.Record)22 AsciiString (io.netty.util.AsciiString)16 Measurement (io.micrometer.core.instrument.Measurement)12 StringJoiner (java.util.StringJoiner)12 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)12 Map (java.util.Map)11 Path (java.nio.file.Path)9 Server (com.linecorp.armeria.server.Server)8 Before (org.junit.Before)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8 BlockingBuffer (com.amazon.dataprepper.plugins.buffer.blockingbuffer.BlockingBuffer)7 RestHighLevelClient (org.opensearch.client.RestHighLevelClient)7 PluginMetrics (com.amazon.dataprepper.metrics.PluginMetrics)6 CertificateProvider (com.amazon.dataprepper.plugins.certificate.CertificateProvider)6 ACMCertificateProvider (com.amazon.dataprepper.plugins.certificate.acm.ACMCertificateProvider)6