From 1bdedf5762a3e3c867a16336208ee0a638c4fb7a Mon Sep 17 00:00:00 2001 From: Christopher van de Sande Date: Fri, 20 Sep 2024 13:06:15 +0100 Subject: [PATCH] address test comments --- internal/collector/otel_collector_plugin.go | 29 ++++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/internal/collector/otel_collector_plugin.go b/internal/collector/otel_collector_plugin.go index b0ae1a8240..7286c9ae3f 100644 --- a/internal/collector/otel_collector_plugin.go +++ b/internal/collector/otel_collector_plugin.go @@ -67,7 +67,6 @@ func New(conf *config.Config) (*Collector, error) { } // Init initializes and starts the plugin -// nolint: revive func (oc *Collector) Init(ctx context.Context, mp bus.MessagePipeInterface) error { slog.InfoContext(ctx, "Starting OTel Collector plugin") @@ -80,8 +79,23 @@ func (oc *Collector) Init(ctx context.Context, mp bus.MessagePipeInterface) erro } if oc.config.Collector.Receivers.OtlpReceivers != nil { - for _, receiver := range oc.config.Collector.Receivers.OtlpReceivers { - if receiver.OtlpTLSConfig != nil && receiver.OtlpTLSConfig.GenerateSelfSignedCert { + oc.processReceivers(ctx, oc.config.Collector.Receivers.OtlpReceivers) + } + + bootErr := oc.bootup(runCtx) + if bootErr != nil { + slog.ErrorContext(runCtx, "Unable to start OTel Collector", "error", bootErr) + } + + return nil +} + +// Process receivers and log warning for sub-optimal configurations +// nolint: revive +func (oc *Collector) processReceivers(ctx context.Context, receivers []config.OtlpReceiver) { + for _, receiver := range receivers { + if receiver.OtlpTLSConfig != nil { + if receiver.OtlpTLSConfig.GenerateSelfSignedCert { slog.WarnContext(ctx, "Self-signed certificate for OTEL receiver requested, "+ "this is not recommended for production environments.", @@ -93,15 +107,10 @@ func (oc *Collector) Init(ctx context.Context, mp bus.MessagePipeInterface) erro ) } } + } else { + slog.WarnContext(ctx, "OTEL receiver is configured without TLS. Connections are unencrypted.") } } - - bootErr := oc.bootup(runCtx) - if bootErr != nil { - slog.ErrorContext(runCtx, "Unable to start OTel Collector", "error", bootErr) - } - - return nil } func (oc *Collector) bootup(ctx context.Context) error {