Search in sources :

Example 11 with CertificateProvider

use of com.amazon.dataprepper.plugins.certificate.CertificateProvider in project data-prepper by opensearch-project.

the class OTelTraceSource method start.

@Override
public void start(Buffer<Record<Object>> buffer) {
    if (buffer == null) {
        throw new IllegalStateException("Buffer provided is null");
    }
    if (server == null) {
        final OTelTraceGrpcService oTelTraceGrpcService = new OTelTraceGrpcService(oTelTraceSourceConfig.getRequestTimeoutInMillis(), oTelTraceSourceConfig.getRecordType(), new OTelProtoCodec.OTelProtoDecoder(), buffer, pluginMetrics);
        final List<ServerInterceptor> serverInterceptors = getAuthenticationInterceptor();
        final GrpcServiceBuilder grpcServiceBuilder = GrpcService.builder().addService(ServerInterceptors.intercept(oTelTraceGrpcService, serverInterceptors)).useClientTimeoutHeader(false).useBlockingTaskExecutor(true);
        if (oTelTraceSourceConfig.hasHealthCheck()) {
            LOG.info("Health check is enabled");
            grpcServiceBuilder.addService(new HealthGrpcService());
        }
        if (oTelTraceSourceConfig.hasProtoReflectionService()) {
            LOG.info("Proto reflection service is enabled");
            grpcServiceBuilder.addService(ProtoReflectionService.newInstance());
        }
        grpcServiceBuilder.enableUnframedRequests(oTelTraceSourceConfig.enableUnframedRequests());
        final ServerBuilder sb = Server.builder();
        sb.disableServerHeader();
        sb.service(grpcServiceBuilder.build());
        sb.requestTimeoutMillis(oTelTraceSourceConfig.getRequestTimeoutInMillis());
        // ACM Cert for SSL takes preference
        if (oTelTraceSourceConfig.isSsl() || oTelTraceSourceConfig.useAcmCertForSSL()) {
            LOG.info("SSL/TLS is enabled.");
            final CertificateProvider certificateProvider = certificateProviderFactory.getCertificateProvider();
            final Certificate certificate = certificateProvider.getCertificate();
            sb.https(oTelTraceSourceConfig.getPort()).tls(new ByteArrayInputStream(certificate.getCertificate().getBytes(StandardCharsets.UTF_8)), new ByteArrayInputStream(certificate.getPrivateKey().getBytes(StandardCharsets.UTF_8)));
        } else {
            LOG.warn("Creating otel_trace_source without SSL/TLS. This is not secure.");
            LOG.warn("In order to set up TLS for the otel_trace_source, go here: https://github.com/opensearch-project/data-prepper/tree/main/data-prepper-plugins/otel-trace-source#ssl");
            sb.http(oTelTraceSourceConfig.getPort());
        }
        sb.maxNumConnections(oTelTraceSourceConfig.getMaxConnectionCount());
        sb.blockingTaskExecutor(Executors.newScheduledThreadPool(oTelTraceSourceConfig.getThreadCount()), true);
        server = sb.build();
    }
    try {
        server.start().get();
    } catch (ExecutionException ex) {
        if (ex.getCause() != null && ex.getCause() instanceof RuntimeException) {
            throw (RuntimeException) ex.getCause();
        } else {
            throw new RuntimeException(ex);
        }
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
        throw new RuntimeException(ex);
    }
    LOG.info("Started otel_trace_source on port " + oTelTraceSourceConfig.getPort() + "...");
}
Also used : OTelProtoCodec(com.amazon.dataprepper.plugins.otel.codec.OTelProtoCodec) GrpcServiceBuilder(com.linecorp.armeria.server.grpc.GrpcServiceBuilder) HealthGrpcService(com.amazon.dataprepper.plugins.health.HealthGrpcService) CertificateProvider(com.amazon.dataprepper.plugins.certificate.CertificateProvider) ByteArrayInputStream(java.io.ByteArrayInputStream) ServerInterceptor(io.grpc.ServerInterceptor) ExecutionException(java.util.concurrent.ExecutionException) ServerBuilder(com.linecorp.armeria.server.ServerBuilder) Certificate(com.amazon.dataprepper.plugins.certificate.model.Certificate)

Aggregations

CertificateProvider (com.amazon.dataprepper.plugins.certificate.CertificateProvider)11 FileCertificateProvider (com.amazon.dataprepper.plugins.certificate.file.FileCertificateProvider)7 Test (org.junit.jupiter.api.Test)7 PluginSetting (com.amazon.dataprepper.model.configuration.PluginSetting)6 ACMCertificateProvider (com.amazon.dataprepper.plugins.certificate.acm.ACMCertificateProvider)6 S3CertificateProvider (com.amazon.dataprepper.plugins.certificate.s3.S3CertificateProvider)6 HashMap (java.util.HashMap)6 Certificate (com.amazon.dataprepper.plugins.certificate.model.Certificate)4 ServerBuilder (com.linecorp.armeria.server.ServerBuilder)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ExecutionException (java.util.concurrent.ExecutionException)4 HealthGrpcService (com.amazon.dataprepper.plugins.health.HealthGrpcService)3 OTelMetricsSourceConfig (com.amazon.dataprepper.plugins.source.otelmetrics.OTelMetricsSourceConfig)3 OTelTraceSourceConfig (com.amazon.dataprepper.plugins.source.oteltrace.OTelTraceSourceConfig)3 GrpcServiceBuilder (com.linecorp.armeria.server.grpc.GrpcServiceBuilder)3 ServerInterceptor (io.grpc.ServerInterceptor)3 OTelProtoCodec (com.amazon.dataprepper.plugins.otel.codec.OTelProtoCodec)1 HTTPSourceConfig (com.amazon.dataprepper.plugins.source.loghttp.HTTPSourceConfig)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1