Skip to content

Commit 04d48c4

Browse files
Update config validate to allow empty accessToken when in passthrough
1 parent 186038a commit 04d48c4

File tree

2 files changed

+179
-1
lines changed

2 files changed

+179
-1
lines changed

exporter/signalfxexporter/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func (cfg *Config) Unmarshal(componentParser *confmap.Conf) error {
215215

216216
// Validate checks if the exporter configuration is valid.
217217
func (cfg *Config) Validate() error {
218-
if cfg.AccessToken == "" {
218+
if cfg.AccessToken == "" && !cfg.AccessTokenPassthrough {
219219
return errors.New(`requires a non-empty "access_token"`)
220220
}
221221

exporter/signalfxexporter/config_test.go

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,182 @@ func TestLoadConfig(t *testing.T) {
284284
SendOTLPHistograms: true,
285285
},
286286
},
287+
{
288+
id: component.NewIDWithName(metadata.Type, ""),
289+
expected: &Config{
290+
AccessToken: "",
291+
Realm: "ap0",
292+
ClientConfig: confighttp.ClientConfig{
293+
Timeout: 10 * time.Second,
294+
Headers: map[string]configopaque.String{},
295+
MaxIdleConns: &hundred,
296+
MaxIdleConnsPerHost: &hundred,
297+
MaxConnsPerHost: &defaultMaxConnsPerHost,
298+
IdleConnTimeout: &idleConnTimeout,
299+
HTTP2ReadIdleTimeout: 10 * time.Second,
300+
HTTP2PingTimeout: 10 * time.Second,
301+
},
302+
BackOffConfig: configretry.BackOffConfig{
303+
Enabled: true,
304+
InitialInterval: 5 * time.Second,
305+
MaxInterval: 30 * time.Second,
306+
MaxElapsedTime: 5 * time.Minute,
307+
RandomizationFactor: backoff.DefaultRandomizationFactor,
308+
Multiplier: backoff.DefaultMultiplier,
309+
},
310+
QueueSettings: exporterhelper.NewDefaultQueueConfig(),
311+
AccessTokenPassthroughConfig: splunk.AccessTokenPassthroughConfig{
312+
AccessTokenPassthrough: true,
313+
},
314+
LogDimensionUpdates: false,
315+
DimensionClient: DimensionClientConfig{
316+
MaxBuffered: 10000,
317+
SendDelay: 10 * time.Second,
318+
MaxIdleConns: 20,
319+
MaxIdleConnsPerHost: 20,
320+
MaxConnsPerHost: 20,
321+
IdleConnTimeout: 30 * time.Second,
322+
Timeout: 10 * time.Second,
323+
},
324+
TranslationRules: nil,
325+
ExcludeMetrics: nil,
326+
IncludeMetrics: nil,
327+
DeltaTranslationTTL: 3600,
328+
ExcludeProperties: nil,
329+
Correlation: &correlation.Config{
330+
ClientConfig: confighttp.ClientConfig{
331+
Endpoint: "",
332+
Timeout: 5 * time.Second,
333+
Headers: map[string]configopaque.String{},
334+
MaxIdleConns: &defaultMaxIdleConns,
335+
MaxIdleConnsPerHost: &defaultMaxIdleConnsPerHost,
336+
MaxConnsPerHost: &defaultMaxConnsPerHost,
337+
IdleConnTimeout: &defaultIdleConnTimeout,
338+
},
339+
StaleServiceTimeout: 5 * time.Minute,
340+
SyncAttributes: map[string]string{
341+
"k8s.pod.uid": "k8s.pod.uid",
342+
"container.id": "container.id",
343+
},
344+
Config: apmcorrelation.Config{
345+
MaxRequests: 20,
346+
MaxBuffered: 10_000,
347+
MaxRetries: 2,
348+
LogUpdates: false,
349+
RetryDelay: 30 * time.Second,
350+
CleanupInterval: 1 * time.Minute,
351+
},
352+
},
353+
NonAlphanumericDimensionChars: "_-.",
354+
SendOTLPHistograms: false,
355+
},
356+
},
357+
}
358+
359+
for _, tt := range tests {
360+
t.Run(tt.id.String(), func(t *testing.T) {
361+
factory := NewFactory()
362+
cfg := factory.CreateDefaultConfig()
363+
364+
sub, err := cm.Sub(tt.id.String())
365+
require.NoError(t, err)
366+
require.NoError(t, sub.Unmarshal(cfg))
367+
368+
assert.NoError(t, component.ValidateConfig(cfg))
369+
// We need to add the default exclude rules.
370+
assert.NoError(t, setDefaultExcludes(tt.expected))
371+
assert.Equal(t, tt.expected, cfg)
372+
})
373+
}
374+
}
375+
376+
func TestEmptyAccessTokenPassValidate(t *testing.T) {
377+
t.Parallel()
378+
379+
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
380+
require.NoError(t, err)
381+
382+
hundred := 100
383+
idleConnTimeout := 30 * time.Second
384+
defaultMaxIdleConns := http.DefaultTransport.(*http.Transport).MaxIdleConns
385+
defaultMaxIdleConnsPerHost := http.DefaultTransport.(*http.Transport).MaxIdleConnsPerHost
386+
defaultMaxConnsPerHost := http.DefaultTransport.(*http.Transport).MaxConnsPerHost
387+
defaultIdleConnTimeout := http.DefaultTransport.(*http.Transport).IdleConnTimeout
388+
389+
tests := []struct {
390+
id component.ID
391+
expected *Config
392+
}{
393+
{
394+
id: component.NewIDWithName(metadata.Type, ""),
395+
expected: &Config{
396+
AccessToken: "",
397+
Realm: "ap0",
398+
ClientConfig: confighttp.ClientConfig{
399+
Timeout: 10 * time.Second,
400+
Headers: map[string]configopaque.String{},
401+
MaxIdleConns: &hundred,
402+
MaxIdleConnsPerHost: &hundred,
403+
MaxConnsPerHost: &defaultMaxConnsPerHost,
404+
IdleConnTimeout: &idleConnTimeout,
405+
HTTP2ReadIdleTimeout: 10 * time.Second,
406+
HTTP2PingTimeout: 10 * time.Second,
407+
},
408+
BackOffConfig: configretry.BackOffConfig{
409+
Enabled: true,
410+
InitialInterval: 5 * time.Second,
411+
MaxInterval: 30 * time.Second,
412+
MaxElapsedTime: 5 * time.Minute,
413+
RandomizationFactor: backoff.DefaultRandomizationFactor,
414+
Multiplier: backoff.DefaultMultiplier,
415+
},
416+
QueueSettings: exporterhelper.NewDefaultQueueConfig(),
417+
AccessTokenPassthroughConfig: splunk.AccessTokenPassthroughConfig{
418+
AccessTokenPassthrough: true,
419+
},
420+
LogDimensionUpdates: false,
421+
DimensionClient: DimensionClientConfig{
422+
MaxBuffered: 10000,
423+
SendDelay: 10 * time.Second,
424+
MaxIdleConns: 20,
425+
MaxIdleConnsPerHost: 20,
426+
MaxConnsPerHost: 20,
427+
IdleConnTimeout: 30 * time.Second,
428+
Timeout: 10 * time.Second,
429+
},
430+
TranslationRules: nil,
431+
ExcludeMetrics: nil,
432+
IncludeMetrics: nil,
433+
DeltaTranslationTTL: 3600,
434+
ExcludeProperties: nil,
435+
Correlation: &correlation.Config{
436+
ClientConfig: confighttp.ClientConfig{
437+
Endpoint: "",
438+
Timeout: 5 * time.Second,
439+
Headers: map[string]configopaque.String{},
440+
MaxIdleConns: &defaultMaxIdleConns,
441+
MaxIdleConnsPerHost: &defaultMaxIdleConnsPerHost,
442+
MaxConnsPerHost: &defaultMaxConnsPerHost,
443+
IdleConnTimeout: &defaultIdleConnTimeout,
444+
},
445+
StaleServiceTimeout: 5 * time.Minute,
446+
SyncAttributes: map[string]string{
447+
"k8s.pod.uid": "k8s.pod.uid",
448+
"container.id": "container.id",
449+
},
450+
Config: apmcorrelation.Config{
451+
MaxRequests: 20,
452+
MaxBuffered: 10_000,
453+
MaxRetries: 2,
454+
LogUpdates: false,
455+
RetryDelay: 30 * time.Second,
456+
CleanupInterval: 1 * time.Minute,
457+
},
458+
},
459+
NonAlphanumericDimensionChars: "_-.",
460+
SendOTLPHistograms: false,
461+
},
462+
},
287463
}
288464

289465
for _, tt := range tests {
@@ -295,6 +471,8 @@ func TestLoadConfig(t *testing.T) {
295471
require.NoError(t, err)
296472
require.NoError(t, sub.Unmarshal(cfg))
297473

474+
cfg.(*Config).AccessToken = ""
475+
298476
assert.NoError(t, component.ValidateConfig(cfg))
299477
// We need to add the default exclude rules.
300478
assert.NoError(t, setDefaultExcludes(tt.expected))

0 commit comments

Comments
 (0)