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

[otelcol] Add featuregate to use stable expansion rules #10361

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
26 changes: 26 additions & 0 deletions .chloggen/confmap-add-expand-featuregate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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.

# 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: |
- When enabled, this feature gate will disable the ability to expand `$ENV` syntax. Use `${env:ENV}` instead.

# 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 @@ -38,14 +38,21 @@ func main() {
{{- if .ConfResolver.DefaultURIScheme }}
DefaultScheme: "{{ .ConfResolver.DefaultURIScheme }}",
{{- end }}
ConverterFactories: []confmap.ConverterFactory{
expandconverter.NewFactory(),
},
},
},
{{- end}}
}

{{ if .Distribution.SupportsConfmapFactories }}
if otelcol.UseStableExpansionRules.IsEnabled() && set.ConfigProviderSettings.ResolverSettings.DefaultScheme == "" {
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.

9 changes: 6 additions & 3 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 Expand Up @@ -52,9 +57,7 @@ func updateSettingsUsingFlags(set *CollectorSettings, flags *flag.FlagSet) error
if len(resolverSet.URIs) == 0 {
return errors.New("at least one config flag must be provided")
}
// Provide a default set of providers and converters if none have been specified.
// TODO: Remove this after CollectorSettings.ConfigProvider is removed and instead
// do it in the builder.

if len(resolverSet.ProviderFactories) == 0 && len(resolverSet.ConverterFactories) == 0 {
set.ConfigProviderSettings = newDefaultConfigProviderSettings(resolverSet.URIs)
}
Expand Down
9 changes: 7 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,12 @@
httpprovider.NewFactory(),
httpsprovider.NewFactory(),
},
ConverterFactories: []confmap.ConverterFactory{expandconverter.NewFactory()},
},
}
if UseStableExpansionRules.IsEnabled() {
set.ResolverSettings.DefaultScheme = "env"

Check warning on line 148 in otelcol/configprovider.go

View check run for this annotation

Codecov / codecov/patch

otelcol/configprovider.go#L148

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