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] Add featuregate to use stable expansion rules #10259

Closed
Show file tree
Hide file tree
Changes from 6 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-add-expand-featuregate-2.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: Expanding `$ENV` is no longer supported. Use `DefaultScheme="env"` or the `otelcol.useStableExpansionRules` feature gate to expand `${}`.
TylerHelmuth marked this conversation as resolved.
Show resolved Hide resolved

# One or more tracking issues or pull requests related to the change
issues: [10259]

# (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:

# 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: []
25 changes: 25 additions & 0 deletions .chloggen/confmap-add-expand-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: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: confmap

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add `otelcol.useStableExpansionRules` feature gate to allow enabling stable expansion rules.
mx-psi marked this conversation as resolved.
Show resolved Hide resolved

# One or more tracking issues or pull requests related to the change
issues: [10259]

# (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:

# 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: []
13 changes: 10 additions & 3 deletions cmd/builder/internal/builder/templates/main.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,21 @@ func main() {
{{.Name}}.NewFactory(),
{{- end}}
},
ConverterFactories: []confmap.ConverterFactory{
expandconverter.NewFactory(),
},
},
},
{{- end}}
}

{{ if .Distribution.SupportsConfmapFactories }}
if otelcol.UseStableExpansionRules.IsEnabled() {
set.ConfigProviderSettings.ResolverSettings.DefaultScheme = "env"
} else {
set.ConfigProviderSettings.ResolverSettings.ConverterFactories = []confmap.ConverterFactory{
expandconverter.NewFactory(),
}
}
{{- end}}

if err := run(set); err != nil {
log.Fatal(err)
}
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.

5 changes: 5 additions & 0 deletions confmap/converter/expandconverter/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ type converter struct {

// NewFactory returns a factory for a confmap.Converter,
// which expands all environment variables for a given confmap.Conf.
//
// Deprecated: [v0.102.0] Expanding $ENV is no longer supported.
// To expand ${} using env vars use DefaultScheme="env" or the otelcol.useStableExpansionRules feature gate.
func NewFactory() confmap.ConverterFactory {
return confmap.NewConverterFactory(newConverter)
}
Expand All @@ -35,6 +38,8 @@ func newConverter(set confmap.ConverterSettings) confmap.Converter {
}
}

// Deprecated: [v0.102.0] Expanding $ENV is no longer supported.
// To expand ${} using env vars use DefaultScheme="env" or the otelcol.useStableExpansionRules feature gate.
func (c converter) Convert(_ context.Context, conf *confmap.Conf) error {
var err error
out := make(map[string]any)
Expand Down
5 changes: 5 additions & 0 deletions otelcol/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import (
"go.opentelemetry.io/collector/featuregate"
)

var UseStableExpansionRules = featuregate.GlobalRegistry().MustRegister("otelcol.useStableExpansionRules",
featuregate.StageAlpha,
featuregate.WithRegisterFromVersion("v0.102.0"),
featuregate.WithRegisterDescription("Uses the env provider to expand `${}` instead of the expandconverter and no longer expands $ENV syntax"))

// NewCommand constructs a new cobra.Command using the given CollectorSettings.
// Any URIs specified in CollectorSettings.ConfigProviderSettings.ResolverSettings.URIs
// are considered defaults and will be overwritten by config flags passed as
Expand Down
11 changes: 9 additions & 2 deletions otelcol/configprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
}

func newDefaultConfigProviderSettings(uris []string) ConfigProviderSettings {
return ConfigProviderSettings{
set := ConfigProviderSettings{
ResolverSettings: confmap.ResolverSettings{
URIs: uris,
ProviderFactories: []confmap.ProviderFactory{
Expand All @@ -142,7 +142,14 @@
httpprovider.NewFactory(),
httpsprovider.NewFactory(),
},
ConverterFactories: []confmap.ConverterFactory{expandconverter.NewFactory()},
},
}

if UseStableExpansionRules.IsEnabled() {
set.ResolverSettings.DefaultScheme = "env"

Check warning on line 149 in otelcol/configprovider.go

View check run for this annotation

Codecov / codecov/patch

otelcol/configprovider.go#L149

Added line #L149 was not covered by tests
} else {
set.ResolverSettings.ConverterFactories = []confmap.ConverterFactory{expandconverter.NewFactory()}
}

return set
}
Loading