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