Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[confmap] Start deprecation processor for env var expand syntax ($ENV) #10144

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .chloggen/confmap-expandconverter-featuregate.yaml
Original file line number Diff line number Diff line change
@@ -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: []
11 changes: 8 additions & 3 deletions cmd/builder/internal/builder/templates/main.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -35,9 +42,7 @@ func main() {
{{.Name}}.NewFactory(),
{{- end}}
},
ConverterFactories: []confmap.ConverterFactory{
expandconverter.NewFactory(),
},
ConverterFactories: converterFactories,
},
},
{{- end}}
Expand Down
11 changes: 8 additions & 3 deletions cmd/otelcorecol/main.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions confmap/converter/expandconverter/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion otelcol/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
18 changes: 17 additions & 1 deletion otelcol/configprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

// PreventEnvVarExpansionFeatureGate is the feature gate that controls whether the collector
// supports configuring the OpenTelemetry SDK via configuration
Comment on lines +20 to +21
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// PreventEnvVarExpansionFeatureGate is the feature gate that controls whether the collector
// supports configuring the OpenTelemetry SDK via configuration
// PreventEnvVarExpansionFeatureGate disables the ability to use environment variables
// without wrapping the variable in braces.

I don't think we need to explicitly call out SDK configuration here; I also don't think this has to do with the Collector's SDK instance.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like I had a bad copy-paste

var PreventEnvVarExpansionFeatureGate = featuregate.GlobalRegistry().MustRegister(
"confmap.preventEnvVarExpansion",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"confmap.preventEnvVarExpansion",
"confmap.NoBracelessEnvVars",

I think we should refine the name a bit, since we will still allow env var expansion even after the deprecation process. We could also say NoNakedEnvVars, but I think "braceless" is a bit clearer to someone who isn't familiar with our terminology.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a single feature gate for all changes related to the environment variable revamp? Or should we have one for each change? I am inclined to say we should have one (easier to figure out how to revert back to the old behavior without having to understand its intricacies)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is another change? I thought $ENV was the only thing we were deprecating

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making types stricter and unified between ${ENV} and ${env:ENV} is the other part

featuregate.StageAlpha,
featuregate.WithRegisterDescription("controls whether the collector supports expanding $ENV in configuration"),
featuregate.WithRegisterFromVersion("v0.101.0"),
)

// ConfigProvider provides the service configuration.
Expand Down Expand Up @@ -132,6 +142,12 @@ func (cm *configProvider) GetConfmap(ctx context.Context) (*confmap.Conf, error)
}

func newDefaultConfigProviderSettings(uris []string) ConfigProviderSettings {
var converterFactories []confmap.ConverterFactory
if !PreventEnvVarExpansionFeatureGate.IsEnabled() {
converterFactories = []confmap.ConverterFactory{
expandconverter.NewFactory(),
}
}
return ConfigProviderSettings{
ResolverSettings: confmap.ResolverSettings{
URIs: uris,
Expand All @@ -142,7 +158,7 @@ func newDefaultConfigProviderSettings(uris []string) ConfigProviderSettings {
httpprovider.NewFactory(),
httpsprovider.NewFactory(),
},
ConverterFactories: []confmap.ConverterFactory{expandconverter.NewFactory()},
ConverterFactories: converterFactories,
},
}
}
Loading