From fd18481e8a3a236567f4d2bda6eb3be6ca785aa3 Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Wed, 31 Jan 2024 02:00:43 -0800 Subject: [PATCH] [processor/remotetap] remotetapprocessor adopts `component.UseLocalHostAsDefaultHost` feature gate (#30905) **Description:** remotetapprocessor adopts `component.UseLocalHostAsDefaultHost` feature gate **Link to tracking Issue:** https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/30702 **Documentation:** Updated docs. --- .chloggen/mx-psi_internal-localhostgate.yaml | 1 + processor/remotetapprocessor/README.md | 2 ++ processor/remotetapprocessor/config.go | 6 ++++-- processor/remotetapprocessor/config_test.go | 2 +- processor/remotetapprocessor/go.mod | 3 +++ 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.chloggen/mx-psi_internal-localhostgate.yaml b/.chloggen/mx-psi_internal-localhostgate.yaml index 709e091e920a..745c3efb0b32 100755 --- a/.chloggen/mx-psi_internal-localhostgate.yaml +++ b/.chloggen/mx-psi_internal-localhostgate.yaml @@ -21,6 +21,7 @@ subtext: | - receiver/opencensus - receiver/zipkin - receiver/awsfirehose + - processor/remotetap # If your change doesn't affect end users or the exported elements of any package, # you should instead start your pull request title with [chore] or use the "Skip Changelog" label. diff --git a/processor/remotetapprocessor/README.md b/processor/remotetapprocessor/README.md index 79277e0f09af..edfe77cbd237 100644 --- a/processor/remotetapprocessor/README.md +++ b/processor/remotetapprocessor/README.md @@ -25,6 +25,8 @@ The WebSocket processor has two configurable fields: `port` and `limit`: - `port`: The port on which the WebSocket processor listens. Optional. Defaults to `12001`. + The `component.UseLocalHostAsDefaultHost` feature gate changes this to localhost:12001. This will become the default in a future release. + - `limit`: The rate limit over the WebSocket in messages per second. Can be a float or an integer. Optional. Defaults to `1`. diff --git a/processor/remotetapprocessor/config.go b/processor/remotetapprocessor/config.go index a76754fb0470..df52f2bd1b70 100644 --- a/processor/remotetapprocessor/config.go +++ b/processor/remotetapprocessor/config.go @@ -7,9 +7,11 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/confighttp" "golang.org/x/time/rate" + + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/localhostgate" ) -const defaultEndpoint = ":12001" +const defaultPort = 12001 type Config struct { confighttp.HTTPServerConfig `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct @@ -22,7 +24,7 @@ type Config struct { func createDefaultConfig() component.Config { return &Config{ HTTPServerConfig: confighttp.HTTPServerConfig{ - Endpoint: defaultEndpoint, + Endpoint: localhostgate.EndpointForPort(defaultPort), }, Limit: 1, } diff --git a/processor/remotetapprocessor/config_test.go b/processor/remotetapprocessor/config_test.go index 7fdbaf9053ed..c941c9402636 100644 --- a/processor/remotetapprocessor/config_test.go +++ b/processor/remotetapprocessor/config_test.go @@ -11,6 +11,6 @@ import ( func TestCreateDefaultConfig(t *testing.T) { cfg := createDefaultConfig().(*Config) - assert.Equal(t, ":12001", cfg.Endpoint) + assert.Equal(t, "0.0.0.0:12001", cfg.Endpoint) assert.EqualValues(t, 1, cfg.Limit) } diff --git a/processor/remotetapprocessor/go.mod b/processor/remotetapprocessor/go.mod index 3e615a1885f4..cdccb0f189be 100644 --- a/processor/remotetapprocessor/go.mod +++ b/processor/remotetapprocessor/go.mod @@ -3,6 +3,7 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/processor/remot go 1.20 require ( + github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.93.0 github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.93.0 github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent v0.93.0 github.com/stretchr/testify v1.8.4 @@ -80,3 +81,5 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest => ../../pkg/pdatatest replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden => ../../pkg/golden + +replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/common => ../../internal/common