Skip to content

Commit

Permalink
[chore][confmap] Show that issue 10799 is fixed (#10809)
Browse files Browse the repository at this point in the history
<!--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
  • Loading branch information
mx-psi committed Aug 7, 2024
1 parent eb6bc6a commit 56908c3
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
13 changes: 13 additions & 0 deletions confmap/internal/e2e/testdata/indirect-slice-env-var-main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
receivers:
nop:
otlp:
protocols:
grpc:

exporters:
nop:
otlp:
endpoint: localhost:4317

service:
pipelines: ${file:${env:BASE_FOLDER}/indirect-slice-env-var-pipelines.yaml}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
logs:
receivers: ${env:OTEL_LOGS_RECEIVER}
exporters: ${env:OTEL_LOGS_EXPORTER}
51 changes: 51 additions & 0 deletions confmap/internal/e2e/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,3 +634,54 @@ logging:
cfgStr.Field,
)
}

func TestIndirectSliceEnvVar(t *testing.T) {
previousValue := globalgates.StrictlyTypedInputGate.IsEnabled()
err := featuregate.GlobalRegistry().Set(globalgates.StrictlyTypedInputID, true)
require.NoError(t, err)
defer func() {
seterr := featuregate.GlobalRegistry().Set(globalgates.StrictlyTypedInputID, previousValue)
require.NoError(t, seterr)
}()

// This replicates the situation in https://github.com/open-telemetry/opentelemetry-collector/issues/10799
// where a configuration file is loaded that contains a reference to a slice of strings in an environment variable.
t.Setenv("BASE_FOLDER", "testdata")
t.Setenv("OTEL_LOGS_RECEIVER", "[nop, otlp]")
t.Setenv("OTEL_LOGS_EXPORTER", "[otlp, nop]")
resolver := NewResolver(t, "indirect-slice-env-var-main.yaml")
conf, err := resolver.Resolve(context.Background())
require.NoError(t, err)

type CollectorConf struct {
Exporters struct {
OTLP struct {
Endpoint string `mapstructure:"endpoint"`
} `mapstructure:"otlp"`
Nop struct{} `mapstructure:"nop"`
} `mapstructure:"exporters"`
Receivers struct {
OTLP struct {
Protocols struct {
GRPC struct{} `mapstructure:"grpc"`
} `mapstructure:"protocols"`
} `mapstructure:"otlp"`
Nop struct{} `mapstructure:"nop"`
} `mapstructure:"receivers"`
Service struct {
Pipelines struct {
Logs struct {
Exporters []string `mapstructure:"exporters"`
Receivers []string `mapstructure:"receivers"`
} `mapstructure:"logs"`
} `mapstructure:"pipelines"`
} `mapstructure:"service"`
}

var collectorConf CollectorConf
err = conf.Unmarshal(&collectorConf)
require.NoError(t, err)
assert.Equal(t, collectorConf.Exporters.OTLP.Endpoint, "localhost:4317")
assert.Equal(t, collectorConf.Service.Pipelines.Logs.Receivers, []string{"nop", "otlp"})
assert.Equal(t, collectorConf.Service.Pipelines.Logs.Exporters, []string{"otlp", "nop"})
}

0 comments on commit 56908c3

Please sign in to comment.