Skip to content

Commit af7ab05

Browse files
authored
[exporter/signalfxexporter] Use configopaque for access_token field (#17304)
Use configopaque for access_token field Link to tracking Issue: #17294
1 parent 4c860a2 commit af7ab05

File tree

7 files changed

+33
-13
lines changed

7 files changed

+33
-13
lines changed

.chloggen/adopt-opaque-signalfx.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: enhancement
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
5+
component: signalfxexporter
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: Use configopaque for access_token field
9+
10+
# One or more tracking issues related to the change
11+
issues: [17294]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext:

exporter/signalfxexporter/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"time"
2222

2323
"go.opentelemetry.io/collector/config/confighttp"
24+
"go.opentelemetry.io/collector/config/configopaque"
2425
"go.opentelemetry.io/collector/config/configtls"
2526
"go.opentelemetry.io/collector/confmap"
2627
"go.opentelemetry.io/collector/exporter/exporterhelper"
@@ -44,7 +45,7 @@ type Config struct {
4445
confighttp.HTTPClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
4546

4647
// AccessToken is the authentication token provided by SignalFx.
47-
AccessToken string `mapstructure:"access_token"`
48+
AccessToken configopaque.String `mapstructure:"access_token"`
4849

4950
// Realm is the SignalFx realm where data is going to be sent to.
5051
Realm string `mapstructure:"realm"`

exporter/signalfxexporter/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func TestConfig_getOptionsFromConfig(t *testing.T) {
202202
return translator
203203
}
204204
type fields struct {
205-
AccessToken string
205+
AccessToken configopaque.String
206206
Realm string
207207
IngestURL string
208208
APIURL string

exporter/signalfxexporter/exporter.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"time"
2626

2727
"go.opentelemetry.io/collector/component"
28+
"go.opentelemetry.io/collector/config/configopaque"
2829
"go.opentelemetry.io/collector/config/configtls"
2930
"go.opentelemetry.io/collector/consumer"
3031
"go.opentelemetry.io/collector/exporter"
@@ -77,7 +78,7 @@ type exporterOptions struct {
7778
apiURL *url.URL
7879
apiTLSSettings configtls.TLSClientSetting
7980
httpTimeout time.Duration
80-
token string
81+
token configopaque.String
8182
logDataPoints bool
8283
logDimUpdate bool
8384
metricTranslator *translation.MetricTranslator
@@ -264,7 +265,7 @@ func buildHeaders(config *Config) map[string]string {
264265
}
265266

266267
if config.AccessToken != "" {
267-
headers[splunk.SFxAccessTokenHeader] = config.AccessToken
268+
headers[splunk.SFxAccessTokenHeader] = string(config.AccessToken)
268269
}
269270

270271
// Add any custom headers from the config. They will override the pre-defined

exporter/signalfxexporter/exporter_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ func TestConsumeMetricsWithAccessTokenPassthrough(t *testing.T) {
425425
cfg.HTTPClientSettings.Headers[k] = configopaque.String(v)
426426
}
427427
cfg.HTTPClientSettings.Headers["test_header_"] = configopaque.String(tt.name)
428-
cfg.AccessToken = fromHeaders
428+
cfg.AccessToken = configopaque.String(fromHeaders)
429429
cfg.AccessTokenPassthrough = tt.accessTokenPassthrough
430430
sfxExp, err := NewFactory().CreateMetricsExporter(context.Background(), exportertest.NewNopCreateSettings(), cfg)
431431
require.NoError(t, err)
@@ -682,7 +682,7 @@ func TestConsumeLogsDataWithAccessTokenPassthrough(t *testing.T) {
682682
cfg.APIURL = server.URL
683683
cfg.Headers = make(map[string]configopaque.String)
684684
cfg.Headers["test_header_"] = configopaque.String(tt.name)
685-
cfg.AccessToken = fromHeaders
685+
cfg.AccessToken = configopaque.String(fromHeaders)
686686
cfg.AccessTokenPassthrough = tt.accessTokenPassthrough
687687
sfxExp, err := NewFactory().CreateLogsExporter(context.Background(), exportertest.NewNopCreateSettings(), cfg)
688688
require.NoError(t, err)

exporter/signalfxexporter/internal/correlation/correlation.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/signalfx/signalfx-agent/pkg/apm/correlations"
2424
"github.com/signalfx/signalfx-agent/pkg/apm/tracetracker"
2525
"go.opentelemetry.io/collector/component"
26+
"go.opentelemetry.io/collector/config/configopaque"
2627
"go.opentelemetry.io/collector/exporter"
2728
"go.opentelemetry.io/collector/pdata/ptrace"
2829
"go.uber.org/zap"
@@ -40,7 +41,7 @@ type Tracker struct {
4041
traceTracker *tracetracker.ActiveServiceTracker
4142
pTicker timeutils.TTicker
4243
correlation *correlationContext
43-
accessToken string
44+
accessToken configopaque.String
4445
}
4546

4647
type correlationContext struct {
@@ -49,7 +50,7 @@ type correlationContext struct {
4950
}
5051

5152
// NewTracker creates a new tracker instance for correlation.
52-
func NewTracker(cfg *Config, accessToken string, params exporter.CreateSettings) *Tracker {
53+
func NewTracker(cfg *Config, accessToken configopaque.String, params exporter.CreateSettings) *Tracker {
5354
return &Tracker{
5455
log: params.Logger,
5556
cfg: cfg,
@@ -58,7 +59,7 @@ func NewTracker(cfg *Config, accessToken string, params exporter.CreateSettings)
5859
}
5960
}
6061

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

7677
client, err := correlations.NewCorrelationClient(newZapShim(params.Logger), ctx, httpClient, correlations.ClientConfig{
7778
Config: cfg.Config,
78-
AccessToken: accessToken,
79+
AccessToken: string(accessToken),
7980
URL: corrURL,
8081
})
8182

exporter/signalfxexporter/internal/dimensions/dimclient.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"sync"
3030
"time"
3131

32+
"go.opentelemetry.io/collector/config/configopaque"
3233
"go.uber.org/zap"
3334

3435
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter/internal/translation"
@@ -42,7 +43,7 @@ import (
4243
type DimensionClient struct {
4344
sync.RWMutex
4445
ctx context.Context
45-
Token string
46+
Token configopaque.String
4647
APIURL *url.URL
4748
client *http.Client
4849
requestSender *ReqSender
@@ -72,7 +73,7 @@ type queuedDimension struct {
7273
}
7374

7475
type DimensionClientOptions struct {
75-
Token string
76+
Token configopaque.String
7677
APIURL *url.URL
7778
APITLSConfig *tls.Config
7879
LogUpdates bool
@@ -320,7 +321,7 @@ func (dc *DimensionClient) makePatchRequest(dim *DimensionUpdate) (*http.Request
320321
}
321322

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

325326
return req, nil
326327
}

0 commit comments

Comments
 (0)