Skip to content

Commit 56908c3

Browse files
authored
[chore][confmap] Show that issue 10799 is fixed (#10809)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description <!-- Issue number if applicable --> Shows that #10795 (as well as #10800) fixed this issue. #### Link to tracking issue Fixes #10799
1 parent eb6bc6a commit 56908c3

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
receivers:
2+
nop:
3+
otlp:
4+
protocols:
5+
grpc:
6+
7+
exporters:
8+
nop:
9+
otlp:
10+
endpoint: localhost:4317
11+
12+
service:
13+
pipelines: ${file:${env:BASE_FOLDER}/indirect-slice-env-var-pipelines.yaml}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
logs:
2+
receivers: ${env:OTEL_LOGS_RECEIVER}
3+
exporters: ${env:OTEL_LOGS_EXPORTER}

confmap/internal/e2e/types_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,3 +634,54 @@ logging:
634634
cfgStr.Field,
635635
)
636636
}
637+
638+
func TestIndirectSliceEnvVar(t *testing.T) {
639+
previousValue := globalgates.StrictlyTypedInputGate.IsEnabled()
640+
err := featuregate.GlobalRegistry().Set(globalgates.StrictlyTypedInputID, true)
641+
require.NoError(t, err)
642+
defer func() {
643+
seterr := featuregate.GlobalRegistry().Set(globalgates.StrictlyTypedInputID, previousValue)
644+
require.NoError(t, seterr)
645+
}()
646+
647+
// This replicates the situation in https://github.com/open-telemetry/opentelemetry-collector/issues/10799
648+
// where a configuration file is loaded that contains a reference to a slice of strings in an environment variable.
649+
t.Setenv("BASE_FOLDER", "testdata")
650+
t.Setenv("OTEL_LOGS_RECEIVER", "[nop, otlp]")
651+
t.Setenv("OTEL_LOGS_EXPORTER", "[otlp, nop]")
652+
resolver := NewResolver(t, "indirect-slice-env-var-main.yaml")
653+
conf, err := resolver.Resolve(context.Background())
654+
require.NoError(t, err)
655+
656+
type CollectorConf struct {
657+
Exporters struct {
658+
OTLP struct {
659+
Endpoint string `mapstructure:"endpoint"`
660+
} `mapstructure:"otlp"`
661+
Nop struct{} `mapstructure:"nop"`
662+
} `mapstructure:"exporters"`
663+
Receivers struct {
664+
OTLP struct {
665+
Protocols struct {
666+
GRPC struct{} `mapstructure:"grpc"`
667+
} `mapstructure:"protocols"`
668+
} `mapstructure:"otlp"`
669+
Nop struct{} `mapstructure:"nop"`
670+
} `mapstructure:"receivers"`
671+
Service struct {
672+
Pipelines struct {
673+
Logs struct {
674+
Exporters []string `mapstructure:"exporters"`
675+
Receivers []string `mapstructure:"receivers"`
676+
} `mapstructure:"logs"`
677+
} `mapstructure:"pipelines"`
678+
} `mapstructure:"service"`
679+
}
680+
681+
var collectorConf CollectorConf
682+
err = conf.Unmarshal(&collectorConf)
683+
require.NoError(t, err)
684+
assert.Equal(t, collectorConf.Exporters.OTLP.Endpoint, "localhost:4317")
685+
assert.Equal(t, collectorConf.Service.Pipelines.Logs.Receivers, []string{"nop", "otlp"})
686+
assert.Equal(t, collectorConf.Service.Pipelines.Logs.Exporters, []string{"otlp", "nop"})
687+
}

0 commit comments

Comments
 (0)