Skip to content

Commit

Permalink
Remove accessTokenPassthrough from sapmreceiver
Browse files Browse the repository at this point in the history
  • Loading branch information
asreehari-splunk committed Oct 24, 2024
1 parent 468908c commit 8372ea4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 107 deletions.
27 changes: 27 additions & 0 deletions .chloggen/remove_access_token_passthrough_from_sapm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: deprecation

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: sapmreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Remove the deprecated access_token_passthrough from SAPM receiver."

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [35972]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# 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.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
8 changes: 0 additions & 8 deletions receiver/sapmreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
4 changes: 0 additions & 4 deletions receiver/sapmreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -60,9 +59,6 @@ func TestLoadConfig(t *testing.T) {
ServerConfig: confighttp.ServerConfig{
Endpoint: "localhost:7276",
},
AccessTokenPassthroughConfig: splunk.AccessTokenPassthroughConfig{
AccessTokenPassthrough: true,
},
},
},
}
Expand Down
22 changes: 1 addition & 21 deletions receiver/sapmreceiver/trace_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
74 changes: 0 additions & 74 deletions receiver/sapmreceiver/trace_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand All @@ -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)

Expand Down

0 comments on commit 8372ea4

Please sign in to comment.