From fc414ee67a79fcbd702b2a54deb13dd01d137058 Mon Sep 17 00:00:00 2001 From: Przemek Maciolek Date: Mon, 15 Feb 2021 10:43:07 +0100 Subject: [PATCH] Remove WithLogger option The capability is out of scope of the PR --- config/confighttp/confighttp.go | 13 +------------ config/confighttp/confighttp_test.go | 3 +-- receiver/otlpreceiver/otlp.go | 1 - 3 files changed, 2 insertions(+), 15 deletions(-) diff --git a/config/confighttp/confighttp.go b/config/confighttp/confighttp.go index d2e71d2fd1f..b1b49b5a587 100644 --- a/config/confighttp/confighttp.go +++ b/config/confighttp/confighttp.go @@ -21,7 +21,6 @@ import ( "time" "github.com/rs/cors" - "go.uber.org/zap" "go.opentelemetry.io/collector/config/configtls" "go.opentelemetry.io/collector/internal/middleware" @@ -144,18 +143,10 @@ func (hss *HTTPServerSettings) ToListener() (net.Listener, error) { // returned by HTTPServerSettings.ToServer(). type toServerOptions struct { errorHandler middleware.ErrorHandler - logger *zap.Logger } type ToServerOption func(opts *toServerOptions) -// WithLogger allows to specify optional logger used during initialization. -func WithLogger(logger *zap.Logger) ToServerOption { - return func(opts *toServerOptions) { - opts.logger = logger - } -} - // WithErrorHandler overrides the HTTP error handler that gets invoked // when there is a failure inside middleware.HTTPContentDecompressor. func WithErrorHandler(e middleware.ErrorHandler) ToServerOption { @@ -172,10 +163,8 @@ func (hss *HTTPServerSettings) ToServer(handler http.Handler, opts ...ToServerOp if len(hss.CorsOrigins) > 0 { co := cors.Options{AllowedOrigins: hss.CorsOrigins, AllowedHeaders: hss.CorsHeaders} handler = cors.New(co).Handler(handler) - } else if len(hss.CorsHeaders) > 0 && serverOpts.logger != nil { - serverOpts.logger.Warn( - "CORS needs to be enabled via `cors_allowed_origins` for `cors_allowed_headers` to have an effect") } + // TODO: emit a warning when non-empty CorsHeaders and empty CorsOrigins. handler = middleware.HTTPContentDecompressor( handler, diff --git a/config/confighttp/confighttp_test.go b/config/confighttp/confighttp_test.go index 652ffcc8bbd..581efeabb56 100644 --- a/config/confighttp/confighttp_test.go +++ b/config/confighttp/confighttp_test.go @@ -27,7 +27,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.uber.org/zap" "go.opentelemetry.io/collector/config/configtls" ) @@ -391,7 +390,7 @@ func TestHttpCorsInvalidSettings(t *testing.T) { } // This effectively does not enable CORS but should also not cause an error - s := hss.ToServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}), WithLogger(zap.NewNop())) + s := hss.ToServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) require.NotNil(t, s) require.NoError(t, s.Close()) } diff --git a/receiver/otlpreceiver/otlp.go b/receiver/otlpreceiver/otlp.go index c00a38601a7..875ea52b350 100644 --- a/receiver/otlpreceiver/otlp.go +++ b/receiver/otlpreceiver/otlp.go @@ -143,7 +143,6 @@ func (r *otlpReceiver) startProtocolServers(host component.Host) error { r.serverHTTP = r.cfg.HTTP.ToServer( r.gatewayMux, confighttp.WithErrorHandler(errorHandler), - confighttp.WithLogger(r.logger), ) err = r.startHTTPServer(r.cfg.HTTP, host) if err != nil {