Skip to content

Commit

Permalink
[confmap] Move confmap.unifyEnvVarExpansion to beta (#10435)
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
Moves confmap.unifyEnvVarExpansion to beta. This means the collector
will, by default, use the env var provider to expand `${FOO}` synatx and
will error if the expandconverter is used to expand `$FOO` syntax.

<!-- Issue number if applicable -->
#### Link to tracking issue
Related to
#10161
Related to
#8215
Related to
#7111

---------

Co-authored-by: Pablo Baeyens <[email protected]>
  • Loading branch information
TylerHelmuth and mx-psi committed Jun 28, 2024
1 parent 2a19d55 commit 9524644
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 4 deletions.
25 changes: 25 additions & 0 deletions .chloggen/confmap-unifyEnvVarExpansion-gate-beta-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: breaking

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: By default, `otelcol.NewCommand` and `otelcol.NewCommandMustSetProvider` will set the `DefaultScheme` to `env`.

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

# (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-unifyEnvVarExpansion-gate-beta.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: breaking

# 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: By default expandconverter will now error if it is about to expand `$FOO` syntax. Update configuration to use `${env:FOO}` instead or disable the feature gate.

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

# (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: []
3 changes: 1 addition & 2 deletions confmap/converter/expandconverter/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package expandconverter // import "go.opentelemetry.io/collector/confmap/convert

import (
"context"
"errors"
"fmt"
"os"
"regexp"
Expand Down Expand Up @@ -95,7 +94,7 @@ func (c converter) expandEnv(s string) (string, error) {
var regex = regexp.MustCompile(fmt.Sprintf(`\$%s`, regexp.QuoteMeta(str)))
if _, exists := c.loggedDeprecations[str]; !exists && regex.MatchString(s) {
if featuregates.UseUnifiedEnvVarExpansionRules.IsEnabled() {
err = errors.New("$VAR expansion is not supported when feature gate confmap.unifyEnvVarExpansion is enabled")
err = fmt.Errorf("variable substitution using $VAR has been deprecated in favor of ${VAR} and ${env:VAR} - please update $%s or temporarily disable the confmap.unifyEnvVarExpansion feature gate", str)
return ""
}
msg := fmt.Sprintf("Variable substitution using $VAR will be deprecated in favor of ${VAR} and ${env:VAR}, please update $%s", str)
Expand Down
7 changes: 6 additions & 1 deletion confmap/converter/expandconverter/expand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ func TestNewExpandConverter(t *testing.T) {

for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
require.NoError(t, featuregate.GlobalRegistry().Set(featuregates.UseUnifiedEnvVarExpansionRules.ID(), false))
t.Cleanup(func() {
require.NoError(t, featuregate.GlobalRegistry().Set(featuregates.UseUnifiedEnvVarExpansionRules.ID(), true))
})

conf, err := confmaptest.LoadConf(filepath.Join("testdata", test.name))
require.NoError(t, err, "Unable to get config")

Expand Down Expand Up @@ -80,7 +85,7 @@ func TestNewExpandConverter_UseUnifiedEnvVarExpansionRules(t *testing.T) {
require.NoError(t, err, "Unable to get config")

// Test that expanded configs are the same with the simple config with no env vars.
require.ErrorContains(t, createConverter().Convert(context.Background(), conf), "$VAR expansion is not supported when feature gate confmap.unifyEnvVarExpansion is enabled")
require.ErrorContains(t, createConverter().Convert(context.Background(), conf), "variable substitution using $VAR has been deprecated in favor of ${VAR} and ${env:VAR}")
}

func TestNewExpandConverter_EscapedMaps(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/featuregates/featuregates.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ package featuregates // import "go.opentelemetry.io/collector/internal/featurega
import "go.opentelemetry.io/collector/featuregate"

var UseUnifiedEnvVarExpansionRules = featuregate.GlobalRegistry().MustRegister("confmap.unifyEnvVarExpansion",
featuregate.StageAlpha,
featuregate.StageBeta,
featuregate.WithRegisterFromVersion("v0.103.0"),
featuregate.WithRegisterDescription("`${FOO}` will now be expanded as if it was `${env:FOO}` and no longer expands $ENV syntax. See https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/rfcs/env-vars.md for more details. When this feature gate is stable, expandconverter will be removed."))
1 change: 1 addition & 0 deletions otelcol/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestNewCommandProgrammaticallyPassedConfig(t *testing.T) {
cmd := NewCommandMustSetProvider(CollectorSettings{Factories: nopFactories, ConfigProviderSettings: ConfigProviderSettings{
ResolverSettings: confmap.ResolverSettings{
ProviderFactories: []confmap.ProviderFactory{confmap.NewProviderFactory(newFailureProvider)},
DefaultScheme: "file",
},
}})
otelRunE := cmd.RunE
Expand Down

0 comments on commit 9524644

Please sign in to comment.