From 254d9e246b299f4aa8b76e1c5d13fa7841f5b9ef Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Wed, 31 Jan 2024 11:05:25 -0800 Subject: [PATCH 1/2] [receiver/sapm] Use localhost gate for sapmreceiver --- .chloggen/mx-psi_internal-localhostgate.yaml | 1 + receiver/sapmreceiver/config_test.go | 4 ++-- receiver/sapmreceiver/factory.go | 7 ++++--- receiver/sapmreceiver/trace_receiver_test.go | 6 +++--- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.chloggen/mx-psi_internal-localhostgate.yaml b/.chloggen/mx-psi_internal-localhostgate.yaml index 0b92835d81d2..fb7e4cc4418f 100755 --- a/.chloggen/mx-psi_internal-localhostgate.yaml +++ b/.chloggen/mx-psi_internal-localhostgate.yaml @@ -27,6 +27,7 @@ subtext: | - receiver/influxdb - receiver/zookeeper - receiver/signalfx + - receiver/sapm # 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/receiver/sapmreceiver/config_test.go b/receiver/sapmreceiver/config_test.go index c55c4fdd8305..3d51a97bd41a 100644 --- a/receiver/sapmreceiver/config_test.go +++ b/receiver/sapmreceiver/config_test.go @@ -44,7 +44,7 @@ func TestLoadConfig(t *testing.T) { id: component.NewIDWithName(metadata.Type, "tls"), expected: &Config{ HTTPServerConfig: confighttp.HTTPServerConfig{ - Endpoint: ":7276", + Endpoint: "0.0.0.0:7276", TLSSetting: &configtls.TLSServerSetting{ TLSSetting: configtls.TLSSetting{ CertFile: "/test.crt", @@ -58,7 +58,7 @@ func TestLoadConfig(t *testing.T) { id: component.NewIDWithName(metadata.Type, "passthrough"), expected: &Config{ HTTPServerConfig: confighttp.HTTPServerConfig{ - Endpoint: ":7276", + Endpoint: "0.0.0.0:7276", }, AccessTokenPassthroughConfig: splunk.AccessTokenPassthroughConfig{ AccessTokenPassthrough: true, diff --git a/receiver/sapmreceiver/factory.go b/receiver/sapmreceiver/factory.go index 82f90c638ee1..508106cb5ea4 100644 --- a/receiver/sapmreceiver/factory.go +++ b/receiver/sapmreceiver/factory.go @@ -16,12 +16,13 @@ import ( "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/receiver" + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/localhostgate" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sapmreceiver/internal/metadata" ) const ( - // Default endpoints to bind to. - defaultEndpoint = ":7276" + // Default port to bind to. + defaultPort = 7276 ) // NewFactory creates a factory for SAPM receiver. @@ -35,7 +36,7 @@ func NewFactory() receiver.Factory { func createDefaultConfig() component.Config { return &Config{ HTTPServerConfig: confighttp.HTTPServerConfig{ - Endpoint: defaultEndpoint, + Endpoint: localhostgate.EndpointForPort(defaultPort), }, } } diff --git a/receiver/sapmreceiver/trace_receiver_test.go b/receiver/sapmreceiver/trace_receiver_test.go index 7b49a21ec2df..3bc3fbef90dd 100644 --- a/receiver/sapmreceiver/trace_receiver_test.go +++ b/receiver/sapmreceiver/trace_receiver_test.go @@ -279,7 +279,7 @@ func TestReception(t *testing.T) { // 1. Create the SAPM receiver aka "server" config: &Config{ HTTPServerConfig: confighttp.HTTPServerConfig{ - Endpoint: defaultEndpoint, + Endpoint: "0.0.0.0:7226", }, }, sapm: &splunksapm.PostSpansRequest{Batches: []*model.Batch{grpcFixture(now)}}, @@ -293,7 +293,7 @@ func TestReception(t *testing.T) { args: args{ config: &Config{ HTTPServerConfig: confighttp.HTTPServerConfig{ - Endpoint: defaultEndpoint, + Endpoint: "0.0.0.0:7226", }, }, sapm: &splunksapm.PostSpansRequest{Batches: []*model.Batch{grpcFixture(now)}}, @@ -382,7 +382,7 @@ func TestAccessTokenPassthrough(t *testing.T) { t.Run(tt.name, func(t *testing.T) { config := &Config{ HTTPServerConfig: confighttp.HTTPServerConfig{ - Endpoint: defaultEndpoint, + Endpoint: "0.0.0.0:7226", }, AccessTokenPassthroughConfig: splunk.AccessTokenPassthroughConfig{ AccessTokenPassthrough: tt.accessTokenPassthrough, From 7259a15fa01fdac1e3002ebe58ba8c2c5f68bf4d Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Wed, 31 Jan 2024 20:24:15 -0800 Subject: [PATCH 2/2] add missing doc update --- receiver/sapmreceiver/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/receiver/sapmreceiver/README.md b/receiver/sapmreceiver/README.md index 54b9023c635a..b19f34404b48 100644 --- a/receiver/sapmreceiver/README.md +++ b/receiver/sapmreceiver/README.md @@ -26,6 +26,7 @@ The following settings are required: - `endpoint` (default = `0.0.0.0:7276`): Address and port that the SAPM receiver should bind to. + The `component.UseLocalHostAsDefaultHost` feature gate changes this to localhost:7276. This will become the default in a future release. The following setting are optional: