Skip to content

Commit

Permalink
[exporter/signalfxexporter] Use configopaque for access_token field
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed Dec 29, 2022
1 parent 0df569d commit cfe513a
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 13 deletions.
16 changes: 16 additions & 0 deletions .chloggen/adopt-opaque-signalfx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Use configopaque for access_token field

# One or more tracking issues related to the change
issues: [17294]

# (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:
3 changes: 2 additions & 1 deletion exporter/signalfxexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net/url"
"time"

"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/exporter/exporterhelper"
Expand All @@ -43,7 +44,7 @@ type Config struct {
exporterhelper.RetrySettings `mapstructure:"retry_on_failure"`

// AccessToken is the authentication token provided by SignalFx.
AccessToken string `mapstructure:"access_token"`
AccessToken configopaque.String `mapstructure:"access_token"`

// Realm is the SignalFx realm where data is going to be sent to.
Realm string `mapstructure:"realm"`
Expand Down
3 changes: 2 additions & 1 deletion exporter/signalfxexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/confmap/confmaptest"
"go.opentelemetry.io/collector/exporter/exporterhelper"

Expand Down Expand Up @@ -202,7 +203,7 @@ func TestConfig_getOptionsFromConfig(t *testing.T) {
return translator
}
type fields struct {
AccessToken string
AccessToken configopaque.String
Realm string
IngestURL string
APIURL string
Expand Down
2 changes: 1 addition & 1 deletion exporter/signalfxexporter/dpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func buildHeaders(config *Config) map[string]string {
}

if config.AccessToken != "" {
headers[splunk.SFxAccessTokenHeader] = config.AccessToken
headers[splunk.SFxAccessTokenHeader] = string(config.AccessToken)
}

// Add any custom headers from the config. They will override the pre-defined
Expand Down
3 changes: 2 additions & 1 deletion exporter/signalfxexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"time"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/exporter"
Expand Down Expand Up @@ -72,7 +73,7 @@ type exporterOptions struct {
apiURL *url.URL
apiTLSSettings configtls.TLSClientSetting
httpTimeout time.Duration
token string
token configopaque.String
logDataPoints bool
logDimUpdate bool
metricTranslator *translation.MetricTranslator
Expand Down
5 changes: 3 additions & 2 deletions exporter/signalfxexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/consumer/consumererror"
"go.opentelemetry.io/collector/exporter/exporterhelper"
Expand Down Expand Up @@ -418,7 +419,7 @@ func TestConsumeMetricsWithAccessTokenPassthrough(t *testing.T) {
cfg.Headers[k] = v
}
cfg.Headers["test_header_"] = tt.name
cfg.AccessToken = fromHeaders
cfg.AccessToken = configopaque.String(fromHeaders)
cfg.AccessTokenPassthrough = tt.accessTokenPassthrough
sfxExp, err := NewFactory().CreateMetricsExporter(context.Background(), exportertest.NewNopCreateSettings(), cfg)
require.NoError(t, err)
Expand Down Expand Up @@ -667,7 +668,7 @@ func TestConsumeLogsDataWithAccessTokenPassthrough(t *testing.T) {
cfg.APIURL = server.URL
cfg.Headers = make(map[string]string)
cfg.Headers["test_header_"] = tt.name
cfg.AccessToken = fromHeaders
cfg.AccessToken = configopaque.String(fromHeaders)
cfg.AccessTokenPassthrough = tt.accessTokenPassthrough
sfxExp, err := NewFactory().CreateLogsExporter(context.Background(), exportertest.NewNopCreateSettings(), cfg)
require.NoError(t, err)
Expand Down
9 changes: 5 additions & 4 deletions exporter/signalfxexporter/internal/correlation/correlation.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/signalfx/signalfx-agent/pkg/apm/correlations"
"github.com/signalfx/signalfx-agent/pkg/apm/tracetracker"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.uber.org/zap"
Expand All @@ -40,7 +41,7 @@ type Tracker struct {
traceTracker *tracetracker.ActiveServiceTracker
pTicker timeutils.TTicker
correlation *correlationContext
accessToken string
accessToken configopaque.String
}

type correlationContext struct {
Expand All @@ -49,7 +50,7 @@ type correlationContext struct {
}

// NewTracker creates a new tracker instance for correlation.
func NewTracker(cfg *Config, accessToken string, params exporter.CreateSettings) *Tracker {
func NewTracker(cfg *Config, accessToken configopaque.String, params exporter.CreateSettings) *Tracker {
return &Tracker{
log: params.Logger,
cfg: cfg,
Expand All @@ -58,7 +59,7 @@ func NewTracker(cfg *Config, accessToken string, params exporter.CreateSettings)
}
}

func newCorrelationClient(cfg *Config, accessToken string, params exporter.CreateSettings, host component.Host) (
func newCorrelationClient(cfg *Config, accessToken configopaque.String, params exporter.CreateSettings, host component.Host) (
*correlationContext, error,
) {
corrURL, err := url.Parse(cfg.Endpoint)
Expand All @@ -75,7 +76,7 @@ func newCorrelationClient(cfg *Config, accessToken string, params exporter.Creat

client, err := correlations.NewCorrelationClient(newZapShim(params.Logger), ctx, httpClient, correlations.ClientConfig{
Config: cfg.Config,
AccessToken: accessToken,
AccessToken: string(accessToken),
URL: corrURL,
})

Expand Down
7 changes: 4 additions & 3 deletions exporter/signalfxexporter/internal/dimensions/dimclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"sync"
"time"

"go.opentelemetry.io/collector/config/configopaque"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter/internal/translation"
Expand All @@ -42,7 +43,7 @@ import (
type DimensionClient struct {
sync.RWMutex
ctx context.Context
Token string
Token configopaque.String
APIURL *url.URL
client *http.Client
requestSender *ReqSender
Expand Down Expand Up @@ -72,7 +73,7 @@ type queuedDimension struct {
}

type DimensionClientOptions struct {
Token string
Token configopaque.String
APIURL *url.URL
APITLSConfig *tls.Config
LogUpdates bool
Expand Down Expand Up @@ -320,7 +321,7 @@ func (dc *DimensionClient) makePatchRequest(dim *DimensionUpdate) (*http.Request
}

req.Header.Add("Content-Type", "application/json")
req.Header.Add("X-SF-TOKEN", dc.Token)
req.Header.Add("X-SF-TOKEN", string(dc.Token))

return req, nil
}

0 comments on commit cfe513a

Please sign in to comment.