Search in sources :

Example 51 with PluginSetting

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

the class OTelMetricsSourceTest method testServerStartACMCertSuccess.

@Test
public void testServerStartACMCertSuccess() throws IOException {
    try (MockedStatic<Server> armeriaServerMock = Mockito.mockStatic(Server.class)) {
        armeriaServerMock.when(Server::builder).thenReturn(serverBuilder);
        when(server.stop()).thenReturn(completableFuture);
        final Path certFilePath = Path.of("data/certificate/test_cert.crt");
        final Path keyFilePath = Path.of("data/certificate/test_decrypted_key.key");
        final String certAsString = Files.readString(certFilePath);
        final String keyAsString = Files.readString(keyFilePath);
        when(certificate.getCertificate()).thenReturn(certAsString);
        when(certificate.getPrivateKey()).thenReturn(keyAsString);
        when(certificateProvider.getCertificate()).thenReturn(certificate);
        when(certificateProviderFactory.getCertificateProvider()).thenReturn(certificateProvider);
        final Map<String, Object> settingsMap = new HashMap<>();
        settingsMap.put(SSL, true);
        settingsMap.put("useAcmCertForSSL", true);
        settingsMap.put("awsRegion", "us-east-1");
        settingsMap.put("acmCertificateArn", "arn:aws:acm:us-east-1:account:certificate/1234-567-856456");
        settingsMap.put("sslKeyCertChainFile", "data/certificate/test_cert.crt");
        settingsMap.put("sslKeyFile", "data/certificate/test_decrypted_key.key");
        testPluginSetting = new PluginSetting(null, settingsMap);
        testPluginSetting.setPipelineName("pipeline");
        oTelMetricsSourceConfig = OBJECT_MAPPER.convertValue(testPluginSetting.getSettings(), OTelMetricsSourceConfig.class);
        final OTelMetricsSource source = new OTelMetricsSource(oTelMetricsSourceConfig, pluginMetrics, pluginFactory, certificateProviderFactory);
        source.start(buffer);
        source.stop();
        final ArgumentCaptor<InputStream> certificateIs = ArgumentCaptor.forClass(InputStream.class);
        final ArgumentCaptor<InputStream> privateKeyIs = ArgumentCaptor.forClass(InputStream.class);
        verify(serverBuilder).tls(certificateIs.capture(), privateKeyIs.capture());
        final String actualCertificate = IOUtils.toString(certificateIs.getValue(), StandardCharsets.UTF_8.name());
        final String actualPrivateKey = IOUtils.toString(privateKeyIs.getValue(), StandardCharsets.UTF_8.name());
        assertThat(actualCertificate, is(certAsString));
        assertThat(actualPrivateKey, is(keyAsString));
    }
}
Also used : Path(java.nio.file.Path) Server(com.linecorp.armeria.server.Server) HashMap(java.util.HashMap) InputStream(java.io.InputStream) AsciiString(io.netty.util.AsciiString) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Test(org.junit.jupiter.api.Test)

Example 52 with PluginSetting

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

the class OTelMetricsSourceTest method testHttpsFullJson.

@Test
void testHttpsFullJson() throws InvalidProtocolBufferException {
    final Map<String, Object> settingsMap = new HashMap<>();
    settingsMap.put("request_timeout", 5);
    settingsMap.put(SSL, true);
    settingsMap.put("useAcmCertForSSL", false);
    settingsMap.put("sslKeyCertChainFile", "data/certificate/test_cert.crt");
    settingsMap.put("sslKeyFile", "data/certificate/test_decrypted_key.key");
    pluginSetting = new PluginSetting("otel_metrics", settingsMap);
    pluginSetting.setPipelineName("pipeline");
    oTelMetricsSourceConfig = OBJECT_MAPPER.convertValue(pluginSetting.getSettings(), OTelMetricsSourceConfig.class);
    SOURCE = new OTelMetricsSource(oTelMetricsSourceConfig, pluginMetrics, pluginFactory);
    buffer = getBuffer();
    SOURCE.start(buffer);
    WebClient.builder().factory(ClientFactory.insecure()).build().execute(RequestHeaders.builder().scheme(SessionProtocol.HTTPS).authority("127.0.0.1:21891").method(HttpMethod.POST).path("/opentelemetry.proto.collector.metrics.v1.MetricsService/Export").contentType(MediaType.JSON_UTF_8).build(), HttpData.copyOf(JsonFormat.printer().print(METRICS_REQUEST).getBytes())).aggregate().whenComplete(OTelMetricsSourceTest::assertStatusCode415AndNoServerHeaders).join();
}
Also used : HashMap(java.util.HashMap) AsciiString(io.netty.util.AsciiString) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Test(org.junit.jupiter.api.Test)

Example 53 with PluginSetting

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

the class OTelMetricsSourceTest method getBuffer.

private BlockingBuffer<Record<ExportMetricsServiceRequest>> getBuffer() {
    final HashMap<String, Object> integerHashMap = new HashMap<>();
    integerHashMap.put("buffer_size", 1);
    integerHashMap.put("batch_size", 1);
    return new BlockingBuffer<>(new PluginSetting("blocking_buffer", integerHashMap));
}
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 54 with PluginSetting

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

the class OTelMetricsSourceTest method start_with_Health_configured_includes_HealthCheck_service.

@Test
void start_with_Health_configured_includes_HealthCheck_service() throws IOException {
    try (MockedStatic<Server> armeriaServerMock = Mockito.mockStatic(Server.class);
        MockedStatic<GrpcService> grpcServerMock = Mockito.mockStatic(GrpcService.class)) {
        armeriaServerMock.when(Server::builder).thenReturn(serverBuilder);
        grpcServerMock.when(GrpcService::builder).thenReturn(grpcServiceBuilder);
        when(grpcServiceBuilder.addService(any(ServerServiceDefinition.class))).thenReturn(grpcServiceBuilder);
        when(grpcServiceBuilder.useClientTimeoutHeader(anyBoolean())).thenReturn(grpcServiceBuilder);
        when(server.stop()).thenReturn(completableFuture);
        final Path certFilePath = Path.of("data/certificate/test_cert.crt");
        final Path keyFilePath = Path.of("data/certificate/test_decrypted_key.key");
        final String certAsString = Files.readString(certFilePath);
        final String keyAsString = Files.readString(keyFilePath);
        when(certificate.getCertificate()).thenReturn(certAsString);
        when(certificate.getPrivateKey()).thenReturn(keyAsString);
        when(certificateProvider.getCertificate()).thenReturn(certificate);
        when(certificateProviderFactory.getCertificateProvider()).thenReturn(certificateProvider);
        final Map<String, Object> settingsMap = new HashMap<>();
        settingsMap.put(SSL, true);
        settingsMap.put("useAcmCertForSSL", true);
        settingsMap.put("awsRegion", "us-east-1");
        settingsMap.put("acmCertificateArn", "arn:aws:acm:us-east-1:account:certificate/1234-567-856456");
        settingsMap.put("sslKeyCertChainFile", "data/certificate/test_cert.crt");
        settingsMap.put("sslKeyFile", "data/certificate/test_decrypted_key.key");
        settingsMap.put("health_check_service", "true");
        testPluginSetting = new PluginSetting(null, settingsMap);
        testPluginSetting.setPipelineName("pipeline");
        oTelMetricsSourceConfig = OBJECT_MAPPER.convertValue(testPluginSetting.getSettings(), OTelMetricsSourceConfig.class);
        final OTelMetricsSource source = new OTelMetricsSource(oTelMetricsSourceConfig, pluginMetrics, pluginFactory, certificateProviderFactory);
        source.start(buffer);
        source.stop();
    }
    verify(grpcServiceBuilder, times(1)).useClientTimeoutHeader(false);
    verify(grpcServiceBuilder, times(1)).useBlockingTaskExecutor(true);
    verify(grpcServiceBuilder).addService(isA(HealthGrpcService.class));
}
Also used : Path(java.nio.file.Path) Server(com.linecorp.armeria.server.Server) HashMap(java.util.HashMap) AsciiString(io.netty.util.AsciiString) HealthGrpcService(com.amazon.dataprepper.plugins.health.HealthGrpcService) GrpcService(com.linecorp.armeria.server.grpc.GrpcService) HealthGrpcService(com.amazon.dataprepper.plugins.health.HealthGrpcService) ServerServiceDefinition(io.grpc.ServerServiceDefinition) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Test(org.junit.jupiter.api.Test)

Example 55 with PluginSetting

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

the class OTelMetricsSourceTest method testRunAnotherSourceWithSamePort.

@Test
public void testRunAnotherSourceWithSamePort() {
    // starting server
    SOURCE.start(buffer);
    testPluginSetting = new PluginSetting(null, Collections.singletonMap(SSL, false));
    testPluginSetting.setPipelineName("pipeline");
    oTelMetricsSourceConfig = OBJECT_MAPPER.convertValue(testPluginSetting.getSettings(), OTelMetricsSourceConfig.class);
    final OTelMetricsSource source = new OTelMetricsSource(oTelMetricsSourceConfig, pluginMetrics, pluginFactory);
    // Expect RuntimeException because when port is already in use, BindException is thrown which is not RuntimeException
    Assertions.assertThrows(RuntimeException.class, () -> source.start(buffer));
}
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