Skip to content

Commit

Permalink
Remove WithLogger option
Browse files Browse the repository at this point in the history
The capability is out of scope of the PR
  • Loading branch information
pmm-sumo committed Feb 15, 2021
1 parent a81cf71 commit caf9227
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 17 deletions.
14 changes: 1 addition & 13 deletions config/confighttp/confighttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"time"

"github.com/rs/cors"
"go.uber.org/zap"

"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/internal/middleware"
)
Expand Down Expand Up @@ -144,18 +142,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 {
Expand All @@ -172,10 +162,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,
Expand Down
4 changes: 1 addition & 3 deletions config/confighttp/confighttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

"go.opentelemetry.io/collector/config/configtls"
)

Expand Down Expand Up @@ -391,7 +389,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())
}
Expand Down
1 change: 0 additions & 1 deletion receiver/otlpreceiver/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit caf9227

Please sign in to comment.