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] Deprecate expandconverter #10510

Merged
merged 16 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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/deprecate-expandconverter-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: 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]
25 changes: 25 additions & 0 deletions .chloggen/deprecate-expandconverter-3.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: 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]
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
change_logs: [api]
change_logs: [user]

I'm tempted to say that we should include this in the user-facing changelog since we encourage users to build their own Collector binaries.

Copy link
Member Author

Choose a reason for hiding this comment

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

I disagree. The previous PR handled the user-facing changelog. This PR (which could have be in #10508 and was only separated for size), removes the expandconverter from the ocb's generated main.go, but end users don't need to worry about that.

Copy link
Member

Choose a reason for hiding this comment

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

We need to define the end user here :) I'm ok with any. We struggle on the same Q for madatagen "users".

Copy link
Member

@dmitryax dmitryax Aug 7, 2024

Choose a reason for hiding this comment

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

Potentially, we can have 2 more changelogs: ocb and mdatagen

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe user denotes those who run the collector and api denotes those who import libraries into their code.

Copy link
Member

Choose a reason for hiding this comment

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

I'm merging as is for now. Feel free to continue the discussion and we can change this line if needed

25 changes: 25 additions & 0 deletions .chloggen/deprecate-expandconverter.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: 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]
2 changes: 0 additions & 2 deletions cmd/builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF
Expand Down
1 change: 0 additions & 1 deletion cmd/builder/internal/builder/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ var (
"/config/configtls",
"/config/internal",
"/confmap",
"/confmap/converter/expandconverter",
"/confmap/provider/envprovider",
"/confmap/provider/fileprovider",
"/confmap/provider/httpprovider",
Expand Down
1 change: 0 additions & 1 deletion cmd/builder/internal/builder/templates/go.mod.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ go 1.21

require (
{{if .Distribution.SupportsConfmapFactories -}}
go.opentelemetry.io/collector/confmap/converter/expandconverter v{{.Distribution.OtelColVersion}}
{{- range .Providers}}
{{if .GoMod}}{{.GoMod}}{{end}}
{{- end}}
Expand Down
4 changes: 0 additions & 4 deletions cmd/builder/internal/builder/templates/main.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -38,9 +37,6 @@ func main() {
{{- if .ConfResolver.DefaultURIScheme }}
DefaultScheme: "{{ .ConfResolver.DefaultURIScheme }}",
{{- end }}
ConverterFactories: []confmap.ConverterFactory{
expandconverter.NewFactory(),
},
},
},
{{- end}}
Expand Down
1 change: 0 additions & 1 deletion cmd/builder/test/core.builder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ replaces:
- go.opentelemetry.io/collector/config/configtls => ${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
Expand Down
1 change: 0 additions & 1 deletion cmd/otelcorecol/builder-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,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
Expand Down
3 changes: 0 additions & 3 deletions cmd/otelcorecol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ toolchain go1.21.12
require (
go.opentelemetry.io/collector/component v0.106.1
go.opentelemetry.io/collector/confmap v0.106.1
go.opentelemetry.io/collector/confmap/converter/expandconverter v0.106.1
go.opentelemetry.io/collector/confmap/provider/envprovider v0.106.1
go.opentelemetry.io/collector/confmap/provider/fileprovider v0.106.1
go.opentelemetry.io/collector/confmap/provider/httpprovider v0.106.1
Expand Down Expand Up @@ -170,8 +169,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
Expand Down
4 changes: 0 additions & 4 deletions cmd/otelcorecol/main.go

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

18 changes: 3 additions & 15 deletions confmap/converter/expandconverter/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -25,6 +23,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.
dmitryax marked this conversation as resolved.
Show resolved Hide resolved
func NewFactory() confmap.ConverterFactory {
return confmap.NewConverterFactory(newConverter)
}
Expand All @@ -36,6 +36,7 @@ func newConverter(set confmap.ConverterSettings) confmap.Converter {
}
}

// 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)
Expand Down Expand Up @@ -90,19 +91,6 @@ func (c converter) expandEnv(s string) (string, error) {
return "$"
dmitryax marked this conversation as resolved.
Show resolved Hide resolved
}

// 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!
Expand Down
79 changes: 1 addition & 78 deletions confmap/converter/expandconverter/expand_test.go
dmitryax marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"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) {
Expand Down Expand Up @@ -48,11 +46,6 @@ func TestNewExpandConverter(t *testing.T) {

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")

Expand All @@ -63,31 +56,6 @@ func TestNewExpandConverter(t *testing.T) {
}
}

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)
Expand Down Expand Up @@ -231,52 +199,6 @@ func TestDeprecatedWarning(t *testing.T) {
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{
Expand Down Expand Up @@ -363,5 +285,6 @@ func TestNewExpandConverterWithErrors(t *testing.T) {
}

func createConverter() confmap.Converter {
// nolint
return NewFactory().Create(confmap.ConverterSettings{Logger: zap.NewNop()})
}
5 changes: 3 additions & 2 deletions confmap/converter/expandconverter/go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// 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

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
)
Expand All @@ -21,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
)
Expand Down
1 change: 1 addition & 0 deletions confmap/internal/e2e/expand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions otelcol/otelcoltest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -26,7 +25,6 @@ func LoadConfig(fileName string, factories otelcol.Factories) (*otelcol.Config,
yamlprovider.NewFactory(),
httpprovider.NewFactory(),
},
ConverterFactories: []confmap.ConverterFactory{expandconverter.NewFactory()},
},
})
if err != nil {
Expand Down
3 changes: 0 additions & 3 deletions otelcol/otelcoltest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/component v0.106.1
go.opentelemetry.io/collector/confmap v0.106.1
go.opentelemetry.io/collector/confmap/converter/expandconverter v0.106.1
go.opentelemetry.io/collector/confmap/provider/envprovider v0.106.1
go.opentelemetry.io/collector/confmap/provider/fileprovider v0.106.1
go.opentelemetry.io/collector/confmap/provider/httpprovider v0.106.1
Expand Down Expand Up @@ -119,8 +118,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
Expand Down
Loading