From 60a436d7ac1abf30835f271732c2941bd96134b0 Mon Sep 17 00:00:00 2001 From: Ajay Sreehari Date: Wed, 23 Oct 2024 16:52:25 -0700 Subject: [PATCH] Remove accessTokenPassthrough from sapmreceiver --- receiver/sapmreceiver/config.go | 8 --- receiver/sapmreceiver/config_test.go | 4 -- receiver/sapmreceiver/trace_receiver.go | 22 +----- receiver/sapmreceiver/trace_receiver_test.go | 74 -------------------- 4 files changed, 1 insertion(+), 107 deletions(-) diff --git a/receiver/sapmreceiver/config.go b/receiver/sapmreceiver/config.go index 7f0085545fef..f9623c953bc8 100644 --- a/receiver/sapmreceiver/config.go +++ b/receiver/sapmreceiver/config.go @@ -5,17 +5,9 @@ package sapmreceiver // import "github.com/open-telemetry/opentelemetry-collecto import ( "go.opentelemetry.io/collector/config/confighttp" - - "github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk" ) // Config defines configuration for SAPM receiver. type Config struct { confighttp.ServerConfig `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct - - // Deprecated: `access_token_passthrough` is deprecated. - // Please enable include_metadata in the receiver and add the following config to the batch processor: - // batch: - // metadata_keys: [X-Sf-Token] - splunk.AccessTokenPassthroughConfig `mapstructure:",squash"` } diff --git a/receiver/sapmreceiver/config_test.go b/receiver/sapmreceiver/config_test.go index 42d1f562b5f0..c5a0eb95203c 100644 --- a/receiver/sapmreceiver/config_test.go +++ b/receiver/sapmreceiver/config_test.go @@ -14,7 +14,6 @@ import ( "go.opentelemetry.io/collector/config/configtls" "go.opentelemetry.io/collector/confmap/confmaptest" - "github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sapmreceiver/internal/metadata" ) @@ -60,9 +59,6 @@ func TestLoadConfig(t *testing.T) { ServerConfig: confighttp.ServerConfig{ Endpoint: "localhost:7276", }, - AccessTokenPassthroughConfig: splunk.AccessTokenPassthroughConfig{ - AccessTokenPassthrough: true, - }, }, }, } diff --git a/receiver/sapmreceiver/trace_receiver.go b/receiver/sapmreceiver/trace_receiver.go index 10d6d9949633..26d5243b5611 100644 --- a/receiver/sapmreceiver/trace_receiver.go +++ b/receiver/sapmreceiver/trace_receiver.go @@ -23,7 +23,6 @@ import ( "go.opentelemetry.io/collector/receiver/receiverhelper" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/errorutil" - "github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger" ) @@ -66,17 +65,6 @@ func (sr *sapmReceiver) handleRequest(req *http.Request) error { return err } - if sr.config.AccessTokenPassthrough { - if accessToken := req.Header.Get(splunk.SFxAccessTokenHeader); accessToken != "" { - rSpans := td.ResourceSpans() - for i := 0; i < rSpans.Len(); i++ { - rSpan := rSpans.At(i) - attrs := rSpan.Resource().Attributes() - attrs.PutStr(splunk.SFxAccessTokenLabel, accessToken) - } - } - } - // pass the trace data to the next consumer err = sr.nextConsumer.ConsumeTraces(ctx, td) if err != nil { @@ -104,7 +92,7 @@ func (sr *sapmReceiver) HTTPHandlerFunc(rw http.ResponseWriter, req *http.Reques // more than an empty struct, then the sapm.PostSpansResponse{} struct will need to be marshaled // and on error a http.StatusInternalServerError should be written to the http.ResponseWriter and // this function should immediately return. - var respBytes = sr.defaultResponse + respBytes := sr.defaultResponse rw.Header().Set(sapmprotocol.ContentTypeHeaderName, sapmprotocol.ContentTypeHeaderValue) // write the response if client does not accept gzip encoding @@ -209,14 +197,6 @@ func newReceiver( return nil, fmt.Errorf("failed to marshal default response body for %v receiver: %w", params.ID, err) } - if config.AccessTokenPassthrough { - params.Logger.Warn( - "access_token_passthrough is deprecated. " + - "Please enable include_metadata in the receiver and add " + - "`metadata_keys: [X-Sf-Token]` to the batch processor", - ) - } - transport := "http" if config.TLSSetting != nil { transport = "https" diff --git a/receiver/sapmreceiver/trace_receiver_test.go b/receiver/sapmreceiver/trace_receiver_test.go index 29d0d276571f..01aa4adeb910 100644 --- a/receiver/sapmreceiver/trace_receiver_test.go +++ b/receiver/sapmreceiver/trace_receiver_test.go @@ -34,7 +34,6 @@ import ( conventions "go.opentelemetry.io/collector/semconv/v1.27.0" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil" - "github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk" ) func expectedTraceData(t1, t2, t3 time.Time) ptrace.Traces { @@ -336,7 +335,6 @@ func TestReception(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - sink := new(consumertest.TracesSink) sr := setupReceiver(t, tt.args.config, sink) defer func() { @@ -362,78 +360,6 @@ func TestReception(t *testing.T) { } } -func TestAccessTokenPassthrough(t *testing.T) { - tests := []struct { - name string - accessTokenPassthrough bool - token string - }{ - { - name: "no passthrough and no token", - accessTokenPassthrough: false, - token: "", - }, - { - name: "no passthrough and token", - accessTokenPassthrough: false, - token: "MyAccessToken", - }, - { - name: "passthrough and no token", - accessTokenPassthrough: true, - token: "", - }, - { - name: "passthrough and token", - accessTokenPassthrough: true, - token: "MyAccessToken", - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - config := &Config{ - ServerConfig: confighttp.ServerConfig{ - Endpoint: "0.0.0.0:7226", - }, - AccessTokenPassthroughConfig: splunk.AccessTokenPassthroughConfig{ - AccessTokenPassthrough: tt.accessTokenPassthrough, - }, - } - - sapm := &splunksapm.PostSpansRequest{ - Batches: []*model.Batch{grpcFixture(time.Now().UTC())}, - } - - sink := new(consumertest.TracesSink) - sr := setupReceiver(t, config, sink) - defer func() { - require.NoError(t, sr.Shutdown(context.Background())) - }() - - var resp *http.Response - resp, err := sendSapm(config.Endpoint, sapm, "gzip", false, tt.token) - require.NoErrorf(t, err, "should not have failed when sending sapm %v", err) - assert.Equal(t, 200, resp.StatusCode) - assert.NoError(t, resp.Body.Close()) - - got := sink.AllTraces() - assert.Len(t, got, 1) - - received := got[0].ResourceSpans() - for i := 0; i < received.Len(); i++ { - rspan := received.At(i) - attrs := rspan.Resource().Attributes() - amap, contains := attrs.Get("com.splunk.signalfx.access_token") - if tt.accessTokenPassthrough && tt.token != "" { - assert.Equal(t, tt.token, amap.Str()) - } else { - assert.False(t, contains) - } - } - }) - } -} - func TestStatusCode(t *testing.T) { tlsAddress := testutil.GetAvailableLocalAddress(t)