Skip to content

Commit

Permalink
Remove access_token_passthrough from sapmreceiver (#35972)
Browse files Browse the repository at this point in the history
#### Description
Remove the use access_token_passthrough from sapmreceiver after
deprecation

---------

Co-authored-by: Dmitrii Anoshin <[email protected]>
  • Loading branch information
asreehari-splunk and dmitryax authored Oct 28, 2024
1 parent 0d9a3f8 commit 025cae2
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 137 deletions.
30 changes: 30 additions & 0 deletions .chloggen/remove_access_token_passthrough_from_sapm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Use this changelog template to create an entry for release notes.

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

# 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: |
Please use `include_metadata` instead with the following config option applied to the batch processor:
batch:
metadata_keys: [X-Sf-Token]
# 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"`
}
12 changes: 0 additions & 12 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 @@ -54,17 +53,6 @@ func TestLoadConfig(t *testing.T) {
},
},
},
{
id: component.NewIDWithName(metadata.Type, "passthrough"),
expected: &Config{
ServerConfig: confighttp.ServerConfig{
Endpoint: "localhost:7276",
},
AccessTokenPassthroughConfig: splunk.AccessTokenPassthroughConfig{
AccessTokenPassthrough: true,
},
},
},
}

for _, tt := range tests {
Expand Down
7 changes: 0 additions & 7 deletions receiver/sapmreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/klauspost/compress v1.17.11
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.112.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.112.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk v0.112.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger v0.112.0
github.com/signalfx/sapm-proto v0.16.0
github.com/stretchr/testify v1.9.0
Expand All @@ -29,7 +28,6 @@ require (

require (
github.com/apache/thrift v0.21.0 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
Expand All @@ -56,14 +54,11 @@ require (
go.opentelemetry.io/collector/config/configauth v0.112.0 // indirect
go.opentelemetry.io/collector/config/configcompression v1.18.0 // indirect
go.opentelemetry.io/collector/config/configopaque v1.18.0 // indirect
go.opentelemetry.io/collector/config/configretry v1.18.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.112.0 // indirect
go.opentelemetry.io/collector/config/internal v0.112.0 // indirect
go.opentelemetry.io/collector/consumer/consumerprofiles v0.112.0 // indirect
go.opentelemetry.io/collector/exporter v0.112.0 // indirect
go.opentelemetry.io/collector/extension v0.112.0 // indirect
go.opentelemetry.io/collector/extension/auth v0.112.0 // indirect
go.opentelemetry.io/collector/extension/experimental/storage v0.112.0 // indirect
go.opentelemetry.io/collector/featuregate v1.18.0 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.112.0 // indirect
go.opentelemetry.io/collector/receiver/receiverprofiles v0.112.0 // indirect
Expand All @@ -84,8 +79,6 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk => ../../internal/splunk

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger => ../../pkg/translator/jaeger

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/common => ../../internal/common
Expand Down
12 changes: 0 additions & 12 deletions receiver/sapmreceiver/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
2 changes: 0 additions & 2 deletions testbed/datareceivers/sapm.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/receivertest"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sapmreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/testbed/testbed"
)
Expand All @@ -36,7 +35,6 @@ func (sr *SapmDataReceiver) Start(tc consumer.Traces, _ consumer.Metrics, _ cons
ServerConfig: confighttp.ServerConfig{
Endpoint: fmt.Sprintf("127.0.0.1:%d", sr.Port),
},
AccessTokenPassthroughConfig: splunk.AccessTokenPassthroughConfig{AccessTokenPassthrough: true},
}
var err error
params := receivertest.NewNopSettings()
Expand Down
2 changes: 1 addition & 1 deletion testbed/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/zipkinexporter v0.112.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.112.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.112.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk v0.112.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.112.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza v0.112.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger v0.112.0
Expand Down Expand Up @@ -215,6 +214,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/internal/exp/metrics v0.112.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/pdatautil v0.112.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent v0.112.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk v0.112.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/batchperresourceattr v0.112.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/experimentalmetricmetadata v0.112.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl v0.112.0 // indirect
Expand Down

0 comments on commit 025cae2

Please sign in to comment.