From 4795a6be8bd46f0d291e34dea3eba38ca3f69013 Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Tue, 2 Jul 2024 10:05:14 -0600 Subject: [PATCH 01/13] Deprecate expandconverter --- cmd/builder/internal/builder/templates/main.go.tmpl | 4 ---- cmd/otelcorecol/go.mod | 1 - cmd/otelcorecol/main.go | 4 ---- confmap/converter/expandconverter/expand.go | 3 +++ confmap/converter/expandconverter/go.mod | 1 + otelcol/otelcoltest/config.go | 2 -- 6 files changed, 4 insertions(+), 11 deletions(-) diff --git a/cmd/builder/internal/builder/templates/main.go.tmpl b/cmd/builder/internal/builder/templates/main.go.tmpl index a1bb7b532dc..b167f1800e8 100644 --- a/cmd/builder/internal/builder/templates/main.go.tmpl +++ b/cmd/builder/internal/builder/templates/main.go.tmpl @@ -9,7 +9,6 @@ import ( "go.opentelemetry.io/collector/component" {{- if .Distribution.SupportsConfmapFactories}} "go.opentelemetry.io/collector/confmap" - "go.opentelemetry.io/collector/confmap/converter/expandconverter" {{- range .Providers}} {{.Name}} "{{.Import}}" {{- end}} @@ -38,9 +37,6 @@ func main() { {{- if .ConfResolver.DefaultURIScheme }} DefaultScheme: "{{ .ConfResolver.DefaultURIScheme }}", {{- end }} - ConverterFactories: []confmap.ConverterFactory{ - expandconverter.NewFactory(), - }, }, }, {{- end}} diff --git a/cmd/otelcorecol/go.mod b/cmd/otelcorecol/go.mod index ba5d483d339..d175223af25 100644 --- a/cmd/otelcorecol/go.mod +++ b/cmd/otelcorecol/go.mod @@ -9,7 +9,6 @@ toolchain go1.21.11 require ( go.opentelemetry.io/collector/component v0.104.0 go.opentelemetry.io/collector/confmap v0.104.0 - go.opentelemetry.io/collector/confmap/converter/expandconverter v0.104.0 go.opentelemetry.io/collector/confmap/provider/envprovider v0.104.0 go.opentelemetry.io/collector/confmap/provider/fileprovider v0.104.0 go.opentelemetry.io/collector/confmap/provider/httpprovider v0.104.0 diff --git a/cmd/otelcorecol/main.go b/cmd/otelcorecol/main.go index 45b25c6bb27..be9d3ae0478 100644 --- a/cmd/otelcorecol/main.go +++ b/cmd/otelcorecol/main.go @@ -8,7 +8,6 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/confmap" - "go.opentelemetry.io/collector/confmap/converter/expandconverter" envprovider "go.opentelemetry.io/collector/confmap/provider/envprovider" fileprovider "go.opentelemetry.io/collector/confmap/provider/fileprovider" httpprovider "go.opentelemetry.io/collector/confmap/provider/httpprovider" @@ -36,9 +35,6 @@ func main() { httpsprovider.NewFactory(), yamlprovider.NewFactory(), }, - ConverterFactories: []confmap.ConverterFactory{ - expandconverter.NewFactory(), - }, }, }, } diff --git a/confmap/converter/expandconverter/expand.go b/confmap/converter/expandconverter/expand.go index aa18d1a3817..1f076882bac 100644 --- a/confmap/converter/expandconverter/expand.go +++ b/confmap/converter/expandconverter/expand.go @@ -25,6 +25,8 @@ type converter struct { // NewFactory returns a factory for a confmap.Converter, // which expands all environment variables for a given confmap.Conf. +// +// Deprecated: [v0.105.0] BASH-style env var expansion is deprecated. Use `${FOO}` or `${env:FOO}` instead. func NewFactory() confmap.ConverterFactory { return confmap.NewConverterFactory(newConverter) } @@ -36,6 +38,7 @@ func newConverter(set confmap.ConverterSettings) confmap.Converter { } } +// Deprecated: [v0.105.0] BASH-style env var expansion is deprecated. Use `${FOO}` or `${env:FOO}` instead. func (c converter) Convert(_ context.Context, conf *confmap.Conf) error { var err error out := make(map[string]any) diff --git a/confmap/converter/expandconverter/go.mod b/confmap/converter/expandconverter/go.mod index f0d150834bb..9ae6f96e8cd 100644 --- a/confmap/converter/expandconverter/go.mod +++ b/confmap/converter/expandconverter/go.mod @@ -1,3 +1,4 @@ +// Deprecated: [v0.105.0] BASH-style env var expansion is deprecated. Use `${FOO}` or `${env:FOO}` instead. module go.opentelemetry.io/collector/confmap/converter/expandconverter go 1.21.0 diff --git a/otelcol/otelcoltest/config.go b/otelcol/otelcoltest/config.go index cbc0be024f4..4ae0d6fe539 100644 --- a/otelcol/otelcoltest/config.go +++ b/otelcol/otelcoltest/config.go @@ -7,7 +7,6 @@ import ( "context" "go.opentelemetry.io/collector/confmap" - "go.opentelemetry.io/collector/confmap/converter/expandconverter" "go.opentelemetry.io/collector/confmap/provider/envprovider" "go.opentelemetry.io/collector/confmap/provider/fileprovider" "go.opentelemetry.io/collector/confmap/provider/httpprovider" @@ -38,7 +37,6 @@ func LoadConfig(fileName string, factories otelcol.Factories) (*otelcol.Config, yamlprovider.NewFactory(), httpprovider.NewFactory(), }, - ConverterFactories: []confmap.ConverterFactory{expandconverter.NewFactory()}, }, }) if err != nil { From 8dd2dcacbba869e5635720de80baa0307b852194 Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Tue, 2 Jul 2024 10:11:26 -0600 Subject: [PATCH 02/13] add changelogs --- .chloggen/deprecate-expandconverter-2.yaml | 25 ++++++++++++++++++++++ .chloggen/deprecate-expandconverter-3.yaml | 25 ++++++++++++++++++++++ .chloggen/deprecate-expandconverter.yaml | 25 ++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 .chloggen/deprecate-expandconverter-2.yaml create mode 100644 .chloggen/deprecate-expandconverter-3.yaml create mode 100644 .chloggen/deprecate-expandconverter.yaml diff --git a/.chloggen/deprecate-expandconverter-2.yaml b/.chloggen/deprecate-expandconverter-2.yaml new file mode 100644 index 00000000000..4375a388747 --- /dev/null +++ b/.chloggen/deprecate-expandconverter-2.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: breaking + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: otelcoltest + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: The `otelcol.LoadConfig` method no longer sets the `expandconverter`. + +# One or more tracking issues or pull requests related to the change +issues: [10510] + +# (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: [api] diff --git a/.chloggen/deprecate-expandconverter-3.yaml b/.chloggen/deprecate-expandconverter-3.yaml new file mode 100644 index 00000000000..ee8001aa4f3 --- /dev/null +++ b/.chloggen/deprecate-expandconverter-3.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: breaking + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: ocb + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Collectors built with OCB will no longer include the `expandconverter` + +# One or more tracking issues or pull requests related to the change +issues: [10510] + +# (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: [api] diff --git a/.chloggen/deprecate-expandconverter.yaml b/.chloggen/deprecate-expandconverter.yaml new file mode 100644 index 00000000000..770ce3e0164 --- /dev/null +++ b/.chloggen/deprecate-expandconverter.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: Deprecate `expandconverter`. + +# One or more tracking issues or pull requests related to the change +issues: [10510] + +# (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: [api] From 7ec040794f6f52fbd768b0a746c09bea429e0c90 Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Tue, 2 Jul 2024 13:05:18 -0600 Subject: [PATCH 03/13] Cleanup builder --- cmd/builder/README.md | 2 -- cmd/builder/internal/builder/main_test.go | 1 - cmd/builder/internal/builder/templates/go.mod.tmpl | 1 - cmd/builder/test/core.builder.yaml | 1 - otelcol/otelcoltest/go.mod | 1 - 5 files changed, 6 deletions(-) diff --git a/cmd/builder/README.md b/cmd/builder/README.md index ec8d18c3808..003a7e93f6b 100644 --- a/cmd/builder/README.md +++ b/cmd/builder/README.md @@ -24,8 +24,6 @@ processors: providers: - gomod: go.opentelemetry.io/collector/confmap/provider/fileprovider v0.99.0 -converters: - - gomod: go.opentelemetry.io/collector/confmap/converter/expandconverter v0.99.0 EOF $ builder --config=otelcol-builder.yaml $ cat > /tmp/otelcol.yaml < ${WORKSPACE_DIR}/config/configtls - go.opentelemetry.io/collector/config/internal => ${WORKSPACE_DIR}/config/internal - go.opentelemetry.io/collector/confmap => ${WORKSPACE_DIR}/confmap - - go.opentelemetry.io/collector/confmap/converter/expandconverter => ${WORKSPACE_DIR}/confmap/converter/expandconverter - go.opentelemetry.io/collector/confmap/provider/envprovider => ${WORKSPACE_DIR}/confmap/provider/envprovider - go.opentelemetry.io/collector/confmap/provider/fileprovider => ${WORKSPACE_DIR}/confmap/provider/fileprovider - go.opentelemetry.io/collector/confmap/provider/httpprovider => ${WORKSPACE_DIR}/confmap/provider/httpprovider diff --git a/otelcol/otelcoltest/go.mod b/otelcol/otelcoltest/go.mod index 0259adae125..efb53c6a09d 100644 --- a/otelcol/otelcoltest/go.mod +++ b/otelcol/otelcoltest/go.mod @@ -6,7 +6,6 @@ require ( github.com/stretchr/testify v1.9.0 go.opentelemetry.io/collector/component v0.104.0 go.opentelemetry.io/collector/confmap v0.104.0 - go.opentelemetry.io/collector/confmap/converter/expandconverter v0.104.0 go.opentelemetry.io/collector/confmap/provider/envprovider v0.104.0 go.opentelemetry.io/collector/confmap/provider/fileprovider v0.104.0 go.opentelemetry.io/collector/confmap/provider/httpprovider v0.104.0 From 3bbd4682eb58636659b11d93e08fddca59bb9267 Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Tue, 2 Jul 2024 13:09:27 -0600 Subject: [PATCH 04/13] make crosslink --- cmd/otelcorecol/builder-config.yaml | 1 - cmd/otelcorecol/go.mod | 2 -- otelcol/otelcoltest/go.mod | 2 -- 3 files changed, 5 deletions(-) diff --git a/cmd/otelcorecol/builder-config.yaml b/cmd/otelcorecol/builder-config.yaml index be9be01815d..61d9e949b45 100644 --- a/cmd/otelcorecol/builder-config.yaml +++ b/cmd/otelcorecol/builder-config.yaml @@ -54,7 +54,6 @@ replaces: - go.opentelemetry.io/collector/config/configtls => ../../config/configtls - go.opentelemetry.io/collector/config/internal => ../../config/internal - go.opentelemetry.io/collector/confmap => ../../confmap - - go.opentelemetry.io/collector/confmap/converter/expandconverter => ../../confmap/converter/expandconverter - go.opentelemetry.io/collector/confmap/provider/envprovider => ../../confmap/provider/envprovider - go.opentelemetry.io/collector/confmap/provider/fileprovider => ../../confmap/provider/fileprovider - go.opentelemetry.io/collector/confmap/provider/httpprovider => ../../confmap/provider/httpprovider diff --git a/cmd/otelcorecol/go.mod b/cmd/otelcorecol/go.mod index d175223af25..1896c79289e 100644 --- a/cmd/otelcorecol/go.mod +++ b/cmd/otelcorecol/go.mod @@ -157,8 +157,6 @@ replace go.opentelemetry.io/collector/config/internal => ../../config/internal replace go.opentelemetry.io/collector/confmap => ../../confmap -replace go.opentelemetry.io/collector/confmap/converter/expandconverter => ../../confmap/converter/expandconverter - replace go.opentelemetry.io/collector/confmap/provider/envprovider => ../../confmap/provider/envprovider replace go.opentelemetry.io/collector/confmap/provider/fileprovider => ../../confmap/provider/fileprovider diff --git a/otelcol/otelcoltest/go.mod b/otelcol/otelcoltest/go.mod index efb53c6a09d..2f000fd2a81 100644 --- a/otelcol/otelcoltest/go.mod +++ b/otelcol/otelcoltest/go.mod @@ -114,8 +114,6 @@ replace go.opentelemetry.io/collector/otelcol => ../ replace go.opentelemetry.io/collector/confmap/provider/yamlprovider => ../../confmap/provider/yamlprovider -replace go.opentelemetry.io/collector/confmap/converter/expandconverter => ../../confmap/converter/expandconverter - replace go.opentelemetry.io/collector => ../.. replace go.opentelemetry.io/collector/service => ../../service From a8a451cec229e9b1cceb5eaa8068321a4cce8e6a Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Thu, 1 Aug 2024 15:47:59 -0600 Subject: [PATCH 05/13] Delete tests --- .../converter/expandconverter/expand_test.go | 367 ------------------ 1 file changed, 367 deletions(-) delete mode 100644 confmap/converter/expandconverter/expand_test.go diff --git a/confmap/converter/expandconverter/expand_test.go b/confmap/converter/expandconverter/expand_test.go deleted file mode 100644 index 4c7ff254e15..00000000000 --- a/confmap/converter/expandconverter/expand_test.go +++ /dev/null @@ -1,367 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package expandconverter - -import ( - "context" - "fmt" - "path/filepath" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" - "go.uber.org/zap/zaptest/observer" - - "go.opentelemetry.io/collector/confmap" - "go.opentelemetry.io/collector/confmap/confmaptest" - "go.opentelemetry.io/collector/confmap/internal/envvar" - "go.opentelemetry.io/collector/featuregate" - "go.opentelemetry.io/collector/internal/globalgates" -) - -func TestNewExpandConverter(t *testing.T) { - var testCases = []struct { - name string // test case name (also file name containing config yaml) - }{ - {name: "expand-with-no-env.yaml"}, - {name: "expand-with-partial-env.yaml"}, - {name: "expand-with-all-env.yaml"}, - } - - const valueExtra = "some string" - const valueExtraMapValue = "some map value" - const valueExtraListMapValue = "some list map value" - const valueExtraListElement = "some list value" - t.Setenv("EXTRA", valueExtra) - t.Setenv("EXTRA_MAP_VALUE_1", valueExtraMapValue+"_1") - t.Setenv("EXTRA_MAP_VALUE_2", valueExtraMapValue+"_2") - t.Setenv("EXTRA_LIST_MAP_VALUE_1", valueExtraListMapValue+"_1") - t.Setenv("EXTRA_LIST_MAP_VALUE_2", valueExtraListMapValue+"_2") - t.Setenv("EXTRA_LIST_VALUE_1", valueExtraListElement+"_1") - t.Setenv("EXTRA_LIST_VALUE_2", valueExtraListElement+"_2") - - expectedCfgMap, errExpected := confmaptest.LoadConf(filepath.Join("testdata", "expand-with-no-env.yaml")) - require.NoError(t, errExpected, "Unable to get expected config") - - for _, test := range testCases { - t.Run(test.name, func(t *testing.T) { - require.NoError(t, featuregate.GlobalRegistry().Set(globalgates.UseUnifiedEnvVarExpansionRules.ID(), false)) - t.Cleanup(func() { - require.NoError(t, featuregate.GlobalRegistry().Set(globalgates.UseUnifiedEnvVarExpansionRules.ID(), true)) - }) - - conf, err := confmaptest.LoadConf(filepath.Join("testdata", test.name)) - require.NoError(t, err, "Unable to get config") - - // Test that expanded configs are the same with the simple config with no env vars. - require.NoError(t, createConverter().Convert(context.Background(), conf)) - assert.Equal(t, expectedCfgMap.ToStringMap(), conf.ToStringMap()) - }) - } -} - -func TestNewExpandConverter_UseUnifiedEnvVarExpansionRules(t *testing.T) { - require.NoError(t, featuregate.GlobalRegistry().Set(globalgates.UseUnifiedEnvVarExpansionRules.ID(), true)) - t.Cleanup(func() { - require.NoError(t, featuregate.GlobalRegistry().Set(globalgates.UseUnifiedEnvVarExpansionRules.ID(), false)) - }) - - const valueExtra = "some string" - const valueExtraMapValue = "some map value" - const valueExtraListMapValue = "some list map value" - const valueExtraListElement = "some list value" - t.Setenv("EXTRA", valueExtra) - t.Setenv("EXTRA_MAP_VALUE_1", valueExtraMapValue+"_1") - t.Setenv("EXTRA_MAP_VALUE_2", valueExtraMapValue+"_2") - t.Setenv("EXTRA_LIST_MAP_VALUE_1", valueExtraListMapValue+"_1") - t.Setenv("EXTRA_LIST_MAP_VALUE_2", valueExtraListMapValue+"_2") - t.Setenv("EXTRA_LIST_VALUE_1", valueExtraListElement+"_1") - t.Setenv("EXTRA_LIST_VALUE_2", valueExtraListElement+"_2") - - conf, err := confmaptest.LoadConf(filepath.Join("testdata", "expand-with-all-env.yaml")) - 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), "variable substitution using $VAR has been deprecated in favor of ${VAR} and ${env:VAR}") -} - -func TestNewExpandConverter_EscapedMaps(t *testing.T) { - const receiverExtraMapValue = "some map value" - t.Setenv("MAP_VALUE", receiverExtraMapValue) - - conf := confmap.NewFromStringMap( - map[string]any{ - "test_string_map": map[string]any{ - "recv": "$MAP_VALUE", - }, - "test_interface_map": map[any]any{ - "recv": "$MAP_VALUE", - }}, - ) - require.NoError(t, createConverter().Convert(context.Background(), conf)) - - expectedMap := map[string]any{ - "test_string_map": map[string]any{ - "recv": receiverExtraMapValue, - }, - "test_interface_map": map[string]any{ - "recv": receiverExtraMapValue, - }} - assert.Equal(t, expectedMap, conf.ToStringMap()) -} - -func TestNewExpandConverter_EscapedEnvVars(t *testing.T) { - const receiverExtraMapValue = "some map value" - t.Setenv("MAP_VALUE_2", receiverExtraMapValue) - - // Retrieve the config - conf, err := confmaptest.LoadConf(filepath.Join("testdata", "expand-escaped-env.yaml")) - require.NoError(t, err, "Unable to get config") - - expectedMap := map[string]any{ - "test_map": map[string]any{ - // $$ -> escaped $ - "recv.1": "$MAP_VALUE_1", - // $$$ -> escaped $ + substituted env var - "recv.2": "$" + receiverExtraMapValue, - // $$$$ -> two escaped $ - "recv.3": "$$MAP_VALUE_3", - // escaped $ in the middle - "recv.4": "some${MAP_VALUE_4}text", - // $$$$ -> two escaped $ - "recv.5": "${ONE}${TWO}", - // trailing escaped $ - "recv.6": "text$", - // escaped $ alone - "recv.7": "$", - }} - require.NoError(t, createConverter().Convert(context.Background(), conf)) - assert.Equal(t, expectedMap, conf.ToStringMap()) -} - -func TestNewExpandConverterHostPort(t *testing.T) { - t.Setenv("HOST", "127.0.0.1") - t.Setenv("PORT", "4317") - - var testCases = []struct { - name string - input map[string]any - expected map[string]any - }{ - { - name: "brackets", - input: map[string]any{ - "test": "${HOST}:${PORT}", - }, - expected: map[string]any{ - "test": "127.0.0.1:4317", - }, - }, - { - name: "no brackets", - input: map[string]any{ - "test": "$HOST:$PORT", - }, - expected: map[string]any{ - "test": "127.0.0.1:4317", - }, - }, - { - name: "mix", - input: map[string]any{ - "test": "${HOST}:$PORT", - }, - expected: map[string]any{ - "test": "127.0.0.1:4317", - }, - }, - { - name: "reverse mix", - input: map[string]any{ - "test": "$HOST:${PORT}", - }, - expected: map[string]any{ - "test": "127.0.0.1:4317", - }, - }, - } - for _, tt := range testCases { - t.Run(tt.name, func(t *testing.T) { - conf := confmap.NewFromStringMap(tt.input) - require.NoError(t, createConverter().Convert(context.Background(), conf)) - assert.Equal(t, tt.expected, conf.ToStringMap()) - }) - } -} - -func NewTestConverter() (confmap.Converter, *observer.ObservedLogs) { - core, logs := observer.New(zapcore.InfoLevel) - conv := converter{loggedDeprecations: make(map[string]struct{}), logger: zap.New(core)} - return conv, logs -} - -func TestDeprecatedWarning(t *testing.T) { - msgTemplate := `Variable substitution using $VAR will be deprecated in favor of ${VAR} and ${env:VAR}, please update $%s` - t.Setenv("HOST", "127.0.0.1") - t.Setenv("PORT", "4317") - - t.Setenv("HOST_NAME", "127.0.0.2") - t.Setenv("HOSTNAME", "127.0.0.3") - - t.Setenv("BAD!HOST", "127.0.0.2") - - var testCases = []struct { - name string - input map[string]any - expectedOutput map[string]any - expectedWarnings []string - expectedError error - }{ - { - name: "no warning", - input: map[string]any{ - "test": "${HOST}:${PORT}", - }, - expectedOutput: map[string]any{ - "test": "127.0.0.1:4317", - }, - expectedWarnings: []string{}, - expectedError: nil, - }, - { - name: "one deprecated var", - input: map[string]any{ - "test": "${HOST}:$PORT", - }, - expectedOutput: map[string]any{ - "test": "127.0.0.1:4317", - }, - expectedWarnings: []string{"PORT"}, - expectedError: nil, - }, - { - name: "two deprecated vars", - input: map[string]any{ - "test": "$HOST:$PORT", - }, - expectedOutput: map[string]any{ - "test": "127.0.0.1:4317", - }, - expectedWarnings: []string{"HOST", "PORT"}, - expectedError: nil, - }, - { - name: "one depracated serveral times", - input: map[string]any{ - "test": "$HOST,$HOST", - "test2": "$HOST", - }, - expectedOutput: map[string]any{ - "test": "127.0.0.1,127.0.0.1", - "test2": "127.0.0.1", - }, - expectedWarnings: []string{"HOST"}, - expectedError: nil, - }, - { - name: "one warning", - input: map[string]any{ - "test": "$HOST_NAME,${HOSTNAME}", - }, - expectedOutput: map[string]any{ - "test": "127.0.0.2,127.0.0.3", - }, - expectedWarnings: []string{"HOST_NAME"}, - expectedError: nil, - }, - { - name: "malformed environment variable", - input: map[string]any{ - "test": "${BAD!HOST}", - }, - expectedOutput: map[string]any{ - "test": "blah", - }, - expectedWarnings: []string{}, - expectedError: fmt.Errorf("environment variable \"BAD!HOST\" has invalid name: must match regex %s", envvar.ValidationRegexp), - }, - { - name: "malformed environment variable number", - input: map[string]any{ - "test": "${2BADHOST}", - }, - expectedOutput: map[string]any{ - "test": "blah", - }, - expectedWarnings: []string{}, - expectedError: fmt.Errorf("environment variable \"2BADHOST\" has invalid name: must match regex %s", envvar.ValidationRegexp), - }, - { - name: "malformed environment variable unicode", - input: map[string]any{ - "test": "${😊BADHOST}", - }, - expectedOutput: map[string]any{ - "test": "blah", - }, - expectedWarnings: []string{}, - expectedError: fmt.Errorf("environment variable \"😊BADHOST\" has invalid name: must match regex %s", envvar.ValidationRegexp), - }, - } - - for _, tt := range testCases { - t.Run(tt.name, func(t *testing.T) { - conf := confmap.NewFromStringMap(tt.input) - conv, logs := NewTestConverter() - err := conv.Convert(context.Background(), conf) - assert.Equal(t, tt.expectedError, err) - if tt.expectedError == nil { - assert.Equal(t, tt.expectedOutput, conf.ToStringMap()) - } - assert.Equal(t, len(tt.expectedWarnings), len(logs.All())) - for i, variable := range tt.expectedWarnings { - errorMsg := fmt.Sprintf(msgTemplate, variable) - assert.Equal(t, errorMsg, logs.All()[i].Message) - } - }) - } -} - -func TestNewExpandConverterWithErrors(t *testing.T) { - var testCases = []struct { - name string // test case name (also file name containing config yaml) - expectedError error - }{ - { - name: "expand-list-error.yaml", - expectedError: fmt.Errorf("environment variable \"EXTRA_LIST_^VALUE_2\" has invalid name: must match regex %s", envvar.ValidationRegexp), - }, - { - name: "expand-list-map-error.yaml", - expectedError: fmt.Errorf("environment variable \"EXTRA_LIST_MAP_V#ALUE_2\" has invalid name: must match regex %s", envvar.ValidationRegexp), - }, - { - name: "expand-map-error.yaml", - expectedError: fmt.Errorf("environment variable \"EX#TRA\" has invalid name: must match regex %s", envvar.ValidationRegexp), - }, - } - - for _, test := range testCases { - t.Run(test.name, func(t *testing.T) { - conf, err := confmaptest.LoadConf(filepath.Join("testdata", "errors", test.name)) - require.NoError(t, err, "Unable to get config") - - // Test that expanded configs are the same with the simple config with no env vars. - err = createConverter().Convert(context.Background(), conf) - - assert.Equal(t, test.expectedError, err) - }) - } -} - -func createConverter() confmap.Converter { - return NewFactory().Create(confmap.ConverterSettings{Logger: zap.NewNop()}) -} From 2f90729ea832d738da47325c4fac8ba8e04f2c37 Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Thu, 1 Aug 2024 15:48:26 -0600 Subject: [PATCH 06/13] make gotidy --- confmap/converter/expandconverter/go.mod | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/confmap/converter/expandconverter/go.mod b/confmap/converter/expandconverter/go.mod index 20c6db4680e..9eff499a8e7 100644 --- a/confmap/converter/expandconverter/go.mod +++ b/confmap/converter/expandconverter/go.mod @@ -4,16 +4,13 @@ module go.opentelemetry.io/collector/confmap/converter/expandconverter go 1.21.0 require ( - github.com/stretchr/testify v1.9.0 go.opentelemetry.io/collector/confmap v0.106.1 - go.opentelemetry.io/collector/featuregate v1.12.0 go.opentelemetry.io/collector/internal/globalgates v0.106.1 go.uber.org/goleak v1.3.0 go.uber.org/zap v1.27.0 ) require ( - github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-viper/mapstructure/v2 v2.0.0 // indirect github.com/hashicorp/go-version v1.7.0 // indirect github.com/knadh/koanf/maps v0.1.1 // indirect @@ -21,7 +18,7 @@ require ( github.com/knadh/koanf/v2 v2.1.1 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect + go.opentelemetry.io/collector/featuregate v1.12.0 // indirect go.uber.org/multierr v1.11.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) From 787a7a795f52be4960aa0f9dd7503e2e32f95b18 Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Thu, 1 Aug 2024 15:55:52 -0600 Subject: [PATCH 07/13] nolint since these tests are fix in the other pr --- confmap/internal/e2e/expand_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/confmap/internal/e2e/expand_test.go b/confmap/internal/e2e/expand_test.go index 018725d30d5..a0eb3349ca7 100644 --- a/confmap/internal/e2e/expand_test.go +++ b/confmap/internal/e2e/expand_test.go @@ -20,6 +20,7 @@ import ( ) // Test_EscapedEnvVars tests that the resolver supports escaped env vars working together with expand converter. +// nolint func Test_EscapedEnvVars(t *testing.T) { tests := []struct { name string From 2614da9a03f8bff791a3c201f2e91835b628a09e Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Wed, 7 Aug 2024 11:47:57 -0600 Subject: [PATCH 08/13] Apply suggestions from code review Co-authored-by: Alex Boten <223565+codeboten@users.noreply.github.com> --- confmap/converter/expandconverter/expand.go | 4 ++-- confmap/converter/expandconverter/go.mod | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/confmap/converter/expandconverter/expand.go b/confmap/converter/expandconverter/expand.go index a04efbc6e54..263c5fc7eeb 100644 --- a/confmap/converter/expandconverter/expand.go +++ b/confmap/converter/expandconverter/expand.go @@ -26,7 +26,7 @@ type converter struct { // NewFactory returns a factory for a confmap.Converter, // which expands all environment variables for a given confmap.Conf. // -// Deprecated: [v0.105.0] BASH-style env var expansion is deprecated. Use `${FOO}` or `${env:FOO}` instead. +// Deprecated: [v0.107.0] BASH-style env var expansion is deprecated. Use `${FOO}` or `${env:FOO}` instead. func NewFactory() confmap.ConverterFactory { return confmap.NewConverterFactory(newConverter) } @@ -38,7 +38,7 @@ func newConverter(set confmap.ConverterSettings) confmap.Converter { } } -// Deprecated: [v0.105.0] BASH-style env var expansion is deprecated. Use `${FOO}` or `${env:FOO}` instead. +// Deprecated: [v0.107.0] BASH-style env var expansion is deprecated. Use `${FOO}` or `${env:FOO}` instead. func (c converter) Convert(_ context.Context, conf *confmap.Conf) error { var err error out := make(map[string]any) diff --git a/confmap/converter/expandconverter/go.mod b/confmap/converter/expandconverter/go.mod index 9eff499a8e7..d125d7dc0e3 100644 --- a/confmap/converter/expandconverter/go.mod +++ b/confmap/converter/expandconverter/go.mod @@ -1,4 +1,4 @@ -// Deprecated: [v0.105.0] BASH-style env var expansion is deprecated. Use `${FOO}` or `${env:FOO}` instead. +// Deprecated: [v0.107.0] BASH-style env var expansion is deprecated. Use `${FOO}` or `${env:FOO}` instead. module go.opentelemetry.io/collector/confmap/converter/expandconverter go 1.21.0 From e900c844c893690e424d1e71ebf423312b6486cb Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Wed, 7 Aug 2024 12:07:25 -0600 Subject: [PATCH 09/13] Add back tests, remove feature gate usage --- confmap/converter/expandconverter/expand.go | 15 - .../converter/expandconverter/expand_test.go | 290 ++++++++++++++++++ confmap/converter/expandconverter/go.mod | 5 +- 3 files changed, 294 insertions(+), 16 deletions(-) create mode 100644 confmap/converter/expandconverter/expand_test.go diff --git a/confmap/converter/expandconverter/expand.go b/confmap/converter/expandconverter/expand.go index a04efbc6e54..a7d4e9726b7 100644 --- a/confmap/converter/expandconverter/expand.go +++ b/confmap/converter/expandconverter/expand.go @@ -7,13 +7,11 @@ import ( "context" "fmt" "os" - "regexp" "go.uber.org/zap" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/confmap/internal/envvar" - "go.opentelemetry.io/collector/internal/globalgates" ) type converter struct { @@ -93,19 +91,6 @@ func (c converter) expandEnv(s string) (string, error) { return "$" } - // Matches on $VAR style environment variables - // in order to make sure we don't log a warning for ${VAR} - var regex = regexp.MustCompile(fmt.Sprintf(`\$%s`, regexp.QuoteMeta(str))) - if _, exists := c.loggedDeprecations[str]; !exists && regex.MatchString(s) { - if globalgates.UseUnifiedEnvVarExpansionRules.IsEnabled() { - 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) - c.logger.Warn(msg, zap.String("variable", str)) - c.loggedDeprecations[str] = struct{}{} - } - // For $ENV style environment variables os.Expand returns once it hits a character that isn't an underscore or // an alphanumeric character - so we cannot detect those malformed environment variables. // For ${ENV} style variables we can detect those kinds of env var names! diff --git a/confmap/converter/expandconverter/expand_test.go b/confmap/converter/expandconverter/expand_test.go new file mode 100644 index 00000000000..4934bb5a008 --- /dev/null +++ b/confmap/converter/expandconverter/expand_test.go @@ -0,0 +1,290 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package expandconverter + +import ( + "context" + "fmt" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "go.uber.org/zap" + "go.uber.org/zap/zapcore" + "go.uber.org/zap/zaptest/observer" + + "go.opentelemetry.io/collector/confmap" + "go.opentelemetry.io/collector/confmap/confmaptest" + "go.opentelemetry.io/collector/confmap/internal/envvar" +) + +func TestNewExpandConverter(t *testing.T) { + var testCases = []struct { + name string // test case name (also file name containing config yaml) + }{ + {name: "expand-with-no-env.yaml"}, + {name: "expand-with-partial-env.yaml"}, + {name: "expand-with-all-env.yaml"}, + } + + const valueExtra = "some string" + const valueExtraMapValue = "some map value" + const valueExtraListMapValue = "some list map value" + const valueExtraListElement = "some list value" + t.Setenv("EXTRA", valueExtra) + t.Setenv("EXTRA_MAP_VALUE_1", valueExtraMapValue+"_1") + t.Setenv("EXTRA_MAP_VALUE_2", valueExtraMapValue+"_2") + t.Setenv("EXTRA_LIST_MAP_VALUE_1", valueExtraListMapValue+"_1") + t.Setenv("EXTRA_LIST_MAP_VALUE_2", valueExtraListMapValue+"_2") + t.Setenv("EXTRA_LIST_VALUE_1", valueExtraListElement+"_1") + t.Setenv("EXTRA_LIST_VALUE_2", valueExtraListElement+"_2") + + expectedCfgMap, errExpected := confmaptest.LoadConf(filepath.Join("testdata", "expand-with-no-env.yaml")) + require.NoError(t, errExpected, "Unable to get expected config") + + for _, test := range testCases { + t.Run(test.name, func(t *testing.T) { + conf, err := confmaptest.LoadConf(filepath.Join("testdata", test.name)) + require.NoError(t, err, "Unable to get config") + + // Test that expanded configs are the same with the simple config with no env vars. + require.NoError(t, createConverter().Convert(context.Background(), conf)) + assert.Equal(t, expectedCfgMap.ToStringMap(), conf.ToStringMap()) + }) + } +} + +func TestNewExpandConverter_EscapedMaps(t *testing.T) { + const receiverExtraMapValue = "some map value" + t.Setenv("MAP_VALUE", receiverExtraMapValue) + + conf := confmap.NewFromStringMap( + map[string]any{ + "test_string_map": map[string]any{ + "recv": "$MAP_VALUE", + }, + "test_interface_map": map[any]any{ + "recv": "$MAP_VALUE", + }}, + ) + require.NoError(t, createConverter().Convert(context.Background(), conf)) + + expectedMap := map[string]any{ + "test_string_map": map[string]any{ + "recv": receiverExtraMapValue, + }, + "test_interface_map": map[string]any{ + "recv": receiverExtraMapValue, + }} + assert.Equal(t, expectedMap, conf.ToStringMap()) +} + +func TestNewExpandConverter_EscapedEnvVars(t *testing.T) { + const receiverExtraMapValue = "some map value" + t.Setenv("MAP_VALUE_2", receiverExtraMapValue) + + // Retrieve the config + conf, err := confmaptest.LoadConf(filepath.Join("testdata", "expand-escaped-env.yaml")) + require.NoError(t, err, "Unable to get config") + + expectedMap := map[string]any{ + "test_map": map[string]any{ + // $$ -> escaped $ + "recv.1": "$MAP_VALUE_1", + // $$$ -> escaped $ + substituted env var + "recv.2": "$" + receiverExtraMapValue, + // $$$$ -> two escaped $ + "recv.3": "$$MAP_VALUE_3", + // escaped $ in the middle + "recv.4": "some${MAP_VALUE_4}text", + // $$$$ -> two escaped $ + "recv.5": "${ONE}${TWO}", + // trailing escaped $ + "recv.6": "text$", + // escaped $ alone + "recv.7": "$", + }} + require.NoError(t, createConverter().Convert(context.Background(), conf)) + assert.Equal(t, expectedMap, conf.ToStringMap()) +} + +func TestNewExpandConverterHostPort(t *testing.T) { + t.Setenv("HOST", "127.0.0.1") + t.Setenv("PORT", "4317") + + var testCases = []struct { + name string + input map[string]any + expected map[string]any + }{ + { + name: "brackets", + input: map[string]any{ + "test": "${HOST}:${PORT}", + }, + expected: map[string]any{ + "test": "127.0.0.1:4317", + }, + }, + { + name: "no brackets", + input: map[string]any{ + "test": "$HOST:$PORT", + }, + expected: map[string]any{ + "test": "127.0.0.1:4317", + }, + }, + { + name: "mix", + input: map[string]any{ + "test": "${HOST}:$PORT", + }, + expected: map[string]any{ + "test": "127.0.0.1:4317", + }, + }, + { + name: "reverse mix", + input: map[string]any{ + "test": "$HOST:${PORT}", + }, + expected: map[string]any{ + "test": "127.0.0.1:4317", + }, + }, + } + for _, tt := range testCases { + t.Run(tt.name, func(t *testing.T) { + conf := confmap.NewFromStringMap(tt.input) + require.NoError(t, createConverter().Convert(context.Background(), conf)) + assert.Equal(t, tt.expected, conf.ToStringMap()) + }) + } +} + +func NewTestConverter() (confmap.Converter, *observer.ObservedLogs) { + core, logs := observer.New(zapcore.InfoLevel) + conv := converter{loggedDeprecations: make(map[string]struct{}), logger: zap.New(core)} + return conv, logs +} + +func TestDeprecatedWarning(t *testing.T) { + msgTemplate := `Variable substitution using $VAR will be deprecated in favor of ${VAR} and ${env:VAR}, please update $%s` + t.Setenv("HOST", "127.0.0.1") + t.Setenv("PORT", "4317") + + t.Setenv("HOST_NAME", "127.0.0.2") + t.Setenv("HOSTNAME", "127.0.0.3") + + t.Setenv("BAD!HOST", "127.0.0.2") + + var testCases = []struct { + name string + input map[string]any + expectedOutput map[string]any + expectedWarnings []string + expectedError error + }{ + { + name: "no warning", + input: map[string]any{ + "test": "${HOST}:${PORT}", + }, + expectedOutput: map[string]any{ + "test": "127.0.0.1:4317", + }, + expectedWarnings: []string{}, + expectedError: nil, + }, + { + name: "malformed environment variable", + input: map[string]any{ + "test": "${BAD!HOST}", + }, + expectedOutput: map[string]any{ + "test": "blah", + }, + expectedWarnings: []string{}, + expectedError: fmt.Errorf("environment variable \"BAD!HOST\" has invalid name: must match regex %s", envvar.ValidationRegexp), + }, + { + name: "malformed environment variable number", + input: map[string]any{ + "test": "${2BADHOST}", + }, + expectedOutput: map[string]any{ + "test": "blah", + }, + expectedWarnings: []string{}, + expectedError: fmt.Errorf("environment variable \"2BADHOST\" has invalid name: must match regex %s", envvar.ValidationRegexp), + }, + { + name: "malformed environment variable unicode", + input: map[string]any{ + "test": "${😊BADHOST}", + }, + expectedOutput: map[string]any{ + "test": "blah", + }, + expectedWarnings: []string{}, + expectedError: fmt.Errorf("environment variable \"😊BADHOST\" has invalid name: must match regex %s", envvar.ValidationRegexp), + }, + } + + for _, tt := range testCases { + t.Run(tt.name, func(t *testing.T) { + conf := confmap.NewFromStringMap(tt.input) + conv, logs := NewTestConverter() + err := conv.Convert(context.Background(), conf) + assert.Equal(t, tt.expectedError, err) + if tt.expectedError == nil { + assert.Equal(t, tt.expectedOutput, conf.ToStringMap()) + } + assert.Equal(t, len(tt.expectedWarnings), len(logs.All())) + for i, variable := range tt.expectedWarnings { + errorMsg := fmt.Sprintf(msgTemplate, variable) + assert.Equal(t, errorMsg, logs.All()[i].Message) + } + }) + } +} + +func TestNewExpandConverterWithErrors(t *testing.T) { + var testCases = []struct { + name string // test case name (also file name containing config yaml) + expectedError error + }{ + { + name: "expand-list-error.yaml", + expectedError: fmt.Errorf("environment variable \"EXTRA_LIST_^VALUE_2\" has invalid name: must match regex %s", envvar.ValidationRegexp), + }, + { + name: "expand-list-map-error.yaml", + expectedError: fmt.Errorf("environment variable \"EXTRA_LIST_MAP_V#ALUE_2\" has invalid name: must match regex %s", envvar.ValidationRegexp), + }, + { + name: "expand-map-error.yaml", + expectedError: fmt.Errorf("environment variable \"EX#TRA\" has invalid name: must match regex %s", envvar.ValidationRegexp), + }, + } + + for _, test := range testCases { + t.Run(test.name, func(t *testing.T) { + conf, err := confmaptest.LoadConf(filepath.Join("testdata", "errors", test.name)) + require.NoError(t, err, "Unable to get config") + + // Test that expanded configs are the same with the simple config with no env vars. + err = createConverter().Convert(context.Background(), conf) + + assert.Equal(t, test.expectedError, err) + }) + } +} + +func createConverter() confmap.Converter { + // nolint + return NewFactory().Create(confmap.ConverterSettings{Logger: zap.NewNop()}) +} diff --git a/confmap/converter/expandconverter/go.mod b/confmap/converter/expandconverter/go.mod index 9eff499a8e7..20c6db4680e 100644 --- a/confmap/converter/expandconverter/go.mod +++ b/confmap/converter/expandconverter/go.mod @@ -4,13 +4,16 @@ module go.opentelemetry.io/collector/confmap/converter/expandconverter go 1.21.0 require ( + github.com/stretchr/testify v1.9.0 go.opentelemetry.io/collector/confmap v0.106.1 + go.opentelemetry.io/collector/featuregate v1.12.0 go.opentelemetry.io/collector/internal/globalgates v0.106.1 go.uber.org/goleak v1.3.0 go.uber.org/zap v1.27.0 ) require ( + github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-viper/mapstructure/v2 v2.0.0 // indirect github.com/hashicorp/go-version v1.7.0 // indirect github.com/knadh/koanf/maps v0.1.1 // indirect @@ -18,7 +21,7 @@ require ( github.com/knadh/koanf/v2 v2.1.1 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect - go.opentelemetry.io/collector/featuregate v1.12.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect go.uber.org/multierr v1.11.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) From 82452beb642d57684438458569584cfda1acda7b Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Wed, 7 Aug 2024 12:09:51 -0600 Subject: [PATCH 10/13] make gotidy --- confmap/converter/expandconverter/go.mod | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/confmap/converter/expandconverter/go.mod b/confmap/converter/expandconverter/go.mod index 575008f5a96..fc66216a4f4 100644 --- a/confmap/converter/expandconverter/go.mod +++ b/confmap/converter/expandconverter/go.mod @@ -6,8 +6,6 @@ go 1.21.0 require ( github.com/stretchr/testify v1.9.0 go.opentelemetry.io/collector/confmap v0.106.1 - go.opentelemetry.io/collector/featuregate v1.12.0 - go.opentelemetry.io/collector/internal/globalgates v0.106.1 go.uber.org/goleak v1.3.0 go.uber.org/zap v1.27.0 ) @@ -22,6 +20,8 @@ require ( github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + go.opentelemetry.io/collector/featuregate v1.12.0 // indirect + go.opentelemetry.io/collector/internal/globalgates v0.106.1 // indirect go.uber.org/multierr v1.11.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) From b6aee54cea5eaa3ff69783410272257f9caea933 Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Wed, 7 Aug 2024 13:38:59 -0600 Subject: [PATCH 11/13] Update comments --- confmap/converter/expandconverter/expand.go | 6 ++++-- confmap/converter/expandconverter/go.mod | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/confmap/converter/expandconverter/expand.go b/confmap/converter/expandconverter/expand.go index b651ec6fda3..6d66498828a 100644 --- a/confmap/converter/expandconverter/expand.go +++ b/confmap/converter/expandconverter/expand.go @@ -24,7 +24,8 @@ type converter struct { // NewFactory returns a factory for a confmap.Converter, // which expands all environment variables for a given confmap.Conf. // -// Deprecated: [v0.107.0] BASH-style env var expansion is deprecated. Use `${FOO}` or `${env:FOO}` instead. +// Deprecated: [v0.107.0] BASH-style env var expansion is deprecated. Use the `envprovider` instead to expand `${FOO}` and `${env:FOO}`. +// Using the expandconverter will cause double escaping, so `$$$$` -> `$` instead of `$$`. func NewFactory() confmap.ConverterFactory { return confmap.NewConverterFactory(newConverter) } @@ -36,7 +37,8 @@ func newConverter(set confmap.ConverterSettings) confmap.Converter { } } -// Deprecated: [v0.107.0] BASH-style env var expansion is deprecated. Use `${FOO}` or `${env:FOO}` instead. +// Deprecated: [v0.107.0] BASH-style env var expansion is deprecated. Use the `envprovider` instead to expand `${FOO}` and `${env:FOO}`. +// Using the expandconverter will cause double escaping, so `$$$$` -> `$` instead of `$$`. func (c converter) Convert(_ context.Context, conf *confmap.Conf) error { var err error out := make(map[string]any) diff --git a/confmap/converter/expandconverter/go.mod b/confmap/converter/expandconverter/go.mod index fc66216a4f4..8b710e5663a 100644 --- a/confmap/converter/expandconverter/go.mod +++ b/confmap/converter/expandconverter/go.mod @@ -1,4 +1,5 @@ -// Deprecated: [v0.107.0] BASH-style env var expansion is deprecated. Use `${FOO}` or `${env:FOO}` instead. +// Deprecated: [v0.107.0] BASH-style env var expansion is deprecated. Use the `envprovider` instead to expand `${FOO}` and `${env:FOO}`. +// Using the expandconverter will cause double escaping, so `$$$$` -> `$` instead of `$$`. //// Using the expandconverter will cause double escaping, so `$$$$` -> `$` instead of `$$`. module go.opentelemetry.io/collector/confmap/converter/expandconverter go 1.21.0 From e6fef5a35b85836c891d289f76b06fa3c1ce98c7 Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Wed, 7 Aug 2024 13:58:55 -0600 Subject: [PATCH 12/13] Update confmap/converter/expandconverter/go.mod Co-authored-by: Dmitrii Anoshin --- confmap/converter/expandconverter/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/confmap/converter/expandconverter/go.mod b/confmap/converter/expandconverter/go.mod index 8b710e5663a..8701827566b 100644 --- a/confmap/converter/expandconverter/go.mod +++ b/confmap/converter/expandconverter/go.mod @@ -1,5 +1,5 @@ // Deprecated: [v0.107.0] BASH-style env var expansion is deprecated. Use the `envprovider` instead to expand `${FOO}` and `${env:FOO}`. -// Using the expandconverter will cause double escaping, so `$$$$` -> `$` instead of `$$`. //// Using the expandconverter will cause double escaping, so `$$$$` -> `$` instead of `$$`. +// Using the expandconverter will cause double escaping, so `$$$$` -> `$` instead of `$$`. module go.opentelemetry.io/collector/confmap/converter/expandconverter go 1.21.0 From 9aefa5ecfc04487df04f1276a5f48fff23c89160 Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Wed, 7 Aug 2024 14:01:25 -0600 Subject: [PATCH 13/13] Update comments --- confmap/converter/expandconverter/expand.go | 4 ++-- confmap/converter/expandconverter/go.mod | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/confmap/converter/expandconverter/expand.go b/confmap/converter/expandconverter/expand.go index 6d66498828a..83b8e4b9dd9 100644 --- a/confmap/converter/expandconverter/expand.go +++ b/confmap/converter/expandconverter/expand.go @@ -25,7 +25,7 @@ type converter struct { // which expands all environment variables for a given confmap.Conf. // // Deprecated: [v0.107.0] BASH-style env var expansion is deprecated. Use the `envprovider` instead to expand `${FOO}` and `${env:FOO}`. -// Using the expandconverter will cause double escaping, so `$$$$` -> `$` instead of `$$`. +// Using the expandconverter with `confmap.Resolver` will cause double escaping, so `$$$$` -> `$` instead of `$$`. func NewFactory() confmap.ConverterFactory { return confmap.NewConverterFactory(newConverter) } @@ -38,7 +38,7 @@ func newConverter(set confmap.ConverterSettings) confmap.Converter { } // Deprecated: [v0.107.0] BASH-style env var expansion is deprecated. Use the `envprovider` instead to expand `${FOO}` and `${env:FOO}`. -// Using the expandconverter will cause double escaping, so `$$$$` -> `$` instead of `$$`. +// Using the expandconverter with `confmap.Resolver` will cause double escaping, so `$$$$` -> `$` instead of `$$`. func (c converter) Convert(_ context.Context, conf *confmap.Conf) error { var err error out := make(map[string]any) diff --git a/confmap/converter/expandconverter/go.mod b/confmap/converter/expandconverter/go.mod index 8701827566b..60b4d680b5b 100644 --- a/confmap/converter/expandconverter/go.mod +++ b/confmap/converter/expandconverter/go.mod @@ -1,5 +1,5 @@ // Deprecated: [v0.107.0] BASH-style env var expansion is deprecated. Use the `envprovider` instead to expand `${FOO}` and `${env:FOO}`. -// Using the expandconverter will cause double escaping, so `$$$$` -> `$` instead of `$$`. +// Using the expandconverter with `confmap.Resolver` will cause double escaping, so `$$$$` -> `$` instead of `$$`. module go.opentelemetry.io/collector/confmap/converter/expandconverter go 1.21.0