From a285f0f4f803a5cff0bc2e31227f42c514b69146 Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Mon, 13 May 2024 16:14:53 -0600 Subject: [PATCH 1/3] Start deprecating env expand syntax --- cmd/otelcorecol/main.go | 11 ++++++++--- confmap/converter/expandconverter/expand.go | 4 ++++ otelcol/configprovider.go | 18 +++++++++++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/cmd/otelcorecol/main.go b/cmd/otelcorecol/main.go index beaeb912ee4..2e380da4b66 100644 --- a/cmd/otelcorecol/main.go +++ b/cmd/otelcorecol/main.go @@ -24,6 +24,13 @@ func main() { Version: "0.100.0-dev", } + var converterFactories []confmap.ConverterFactory + if otelcol.AllowEnvVarExpansionFeatureGate.IsEnabled() { + converterFactories = []confmap.ConverterFactory{ + expandconverter.NewFactory(), + } + } + set := otelcol.CollectorSettings{ BuildInfo: info, Factories: components, @@ -36,9 +43,7 @@ func main() { httpsprovider.NewFactory(), yamlprovider.NewFactory(), }, - ConverterFactories: []confmap.ConverterFactory{ - expandconverter.NewFactory(), - }, + ConverterFactories: converterFactories, }, }, } diff --git a/confmap/converter/expandconverter/expand.go b/confmap/converter/expandconverter/expand.go index 98bc455d907..3a22743ed05 100644 --- a/confmap/converter/expandconverter/expand.go +++ b/confmap/converter/expandconverter/expand.go @@ -23,6 +23,10 @@ type converter struct { // NewFactory returns a factory for a confmap.Converter, // which expands all environment variables for a given confmap.Conf. +// +// Deprecated: [v0.101.0] The expand converter is deprecated, the collector will no longer support this style environment +// variable substitution by default. Use ${...} or ${env:...} instead. +// See https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/rfcs/env-vars.md for more details. func NewFactory() confmap.ConverterFactory { return confmap.NewConverterFactory(newConverter) } diff --git a/otelcol/configprovider.go b/otelcol/configprovider.go index 477541fd4bd..a8ae8da1689 100644 --- a/otelcol/configprovider.go +++ b/otelcol/configprovider.go @@ -14,6 +14,16 @@ import ( "go.opentelemetry.io/collector/confmap/provider/httpprovider" "go.opentelemetry.io/collector/confmap/provider/httpsprovider" "go.opentelemetry.io/collector/confmap/provider/yamlprovider" + "go.opentelemetry.io/collector/featuregate" +) + +// AllowEnvVarExpansionFeatureGate is the feature gate that controls whether the collector +// supports configuring the OpenTelemetry SDK via configuration +var AllowEnvVarExpansionFeatureGate = featuregate.GlobalRegistry().MustRegister( + "confmap.allowEnvVarExpansion", + featuregate.StageAlpha, + featuregate.WithRegisterDescription("controls whether the collector supports expanding $ENV in configuration"), + featuregate.WithRegisterFromVersion("v0.101.0"), ) // ConfigProvider provides the service configuration. @@ -132,6 +142,12 @@ func (cm *configProvider) GetConfmap(ctx context.Context) (*confmap.Conf, error) } func newDefaultConfigProviderSettings(uris []string) ConfigProviderSettings { + var converterFactories []confmap.ConverterFactory + if AllowEnvVarExpansionFeatureGate.IsEnabled() { + converterFactories = []confmap.ConverterFactory{ + expandconverter.NewFactory(), + } + } return ConfigProviderSettings{ ResolverSettings: confmap.ResolverSettings{ URIs: uris, @@ -142,7 +158,7 @@ func newDefaultConfigProviderSettings(uris []string) ConfigProviderSettings { httpprovider.NewFactory(), httpsprovider.NewFactory(), }, - ConverterFactories: []confmap.ConverterFactory{expandconverter.NewFactory()}, + ConverterFactories: converterFactories, }, } } From 43b291d78e4dcda0ecef876907cd94d24c8999b6 Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Mon, 13 May 2024 16:20:04 -0600 Subject: [PATCH 2/3] changelog --- .../confmap-expandconverter-featuregate.yaml | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .chloggen/confmap-expandconverter-featuregate.yaml diff --git a/.chloggen/confmap-expandconverter-featuregate.yaml b/.chloggen/confmap-expandconverter-featuregate.yaml new file mode 100644 index 00000000000..19aac1af43e --- /dev/null +++ b/.chloggen/confmap-expandconverter-featuregate.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: deprecation + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: expandconverter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Adds `confmap.allowEnvVarExpansion` feature gate to control use of $ENV syntax. + +# One or more tracking issues or pull requests related to the change +issues: [10144] + +# (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: Deprecates expandconverter + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] From 8cbb16a97b08a69fa37a854c5623262f1bc012aa Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Tue, 14 May 2024 09:58:55 -0600 Subject: [PATCH 3/3] Fix tests --- cmd/builder/internal/builder/templates/main.go.tmpl | 11 ++++++++--- cmd/otelcorecol/main.go | 2 +- otelcol/command_test.go | 2 +- otelcol/configprovider.go | 8 ++++---- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/cmd/builder/internal/builder/templates/main.go.tmpl b/cmd/builder/internal/builder/templates/main.go.tmpl index f9964c5d5ec..e93843aa77b 100644 --- a/cmd/builder/internal/builder/templates/main.go.tmpl +++ b/cmd/builder/internal/builder/templates/main.go.tmpl @@ -24,6 +24,13 @@ func main() { Version: "{{ .Distribution.Version }}", } + var converterFactories []confmap.ConverterFactory + if otelcol.PreventEnvVarExpansionFeatureGate.IsEnabled() { + converterFactories = []confmap.ConverterFactory{ + expandconverter.NewFactory(), + } + } + set := otelcol.CollectorSettings{ BuildInfo: info, Factories: components, @@ -35,9 +42,7 @@ func main() { {{.Name}}.NewFactory(), {{- end}} }, - ConverterFactories: []confmap.ConverterFactory{ - expandconverter.NewFactory(), - }, + ConverterFactories: converterFactories, }, }, {{- end}} diff --git a/cmd/otelcorecol/main.go b/cmd/otelcorecol/main.go index 2e380da4b66..f95d460336a 100644 --- a/cmd/otelcorecol/main.go +++ b/cmd/otelcorecol/main.go @@ -25,7 +25,7 @@ func main() { } var converterFactories []confmap.ConverterFactory - if otelcol.AllowEnvVarExpansionFeatureGate.IsEnabled() { + if otelcol.PreventEnvVarExpansionFeatureGate.IsEnabled() { converterFactories = []confmap.ConverterFactory{ expandconverter.NewFactory(), } diff --git a/otelcol/command_test.go b/otelcol/command_test.go index 69e1a943d2b..c2429d3fae1 100644 --- a/otelcol/command_test.go +++ b/otelcol/command_test.go @@ -73,7 +73,7 @@ func TestAddDefaultConfmapModules(t *testing.T) { ResolverSettings: confmap.ResolverSettings{}, }, } - flgs := flags(featuregate.NewRegistry()) + flgs := flags(featuregate.GlobalRegistry()) err := flgs.Parse([]string{"--config=otelcol-nop.yaml"}) require.NoError(t, err) diff --git a/otelcol/configprovider.go b/otelcol/configprovider.go index a8ae8da1689..d1943647d9f 100644 --- a/otelcol/configprovider.go +++ b/otelcol/configprovider.go @@ -17,10 +17,10 @@ import ( "go.opentelemetry.io/collector/featuregate" ) -// AllowEnvVarExpansionFeatureGate is the feature gate that controls whether the collector +// PreventEnvVarExpansionFeatureGate is the feature gate that controls whether the collector // supports configuring the OpenTelemetry SDK via configuration -var AllowEnvVarExpansionFeatureGate = featuregate.GlobalRegistry().MustRegister( - "confmap.allowEnvVarExpansion", +var PreventEnvVarExpansionFeatureGate = featuregate.GlobalRegistry().MustRegister( + "confmap.preventEnvVarExpansion", featuregate.StageAlpha, featuregate.WithRegisterDescription("controls whether the collector supports expanding $ENV in configuration"), featuregate.WithRegisterFromVersion("v0.101.0"), @@ -143,7 +143,7 @@ func (cm *configProvider) GetConfmap(ctx context.Context) (*confmap.Conf, error) func newDefaultConfigProviderSettings(uris []string) ConfigProviderSettings { var converterFactories []confmap.ConverterFactory - if AllowEnvVarExpansionFeatureGate.IsEnabled() { + if !PreventEnvVarExpansionFeatureGate.IsEnabled() { converterFactories = []confmap.ConverterFactory{ expandconverter.NewFactory(), }