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

[config] Deprecate component.UnmarshalConfig #9750

Merged
merged 6 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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/embedded_struct_unmarshaler.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
atoulme marked this conversation as resolved.
Show resolved Hide resolved

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Deprecate `component.UnmarshalConfig`, use `conf.Unmarshal(&intoCfg)` instead.
atoulme marked this conversation as resolved.
Show resolved Hide resolved

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

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

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

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

10 changes: 5 additions & 5 deletions cmd/mdatagen/templates/component_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestComponentLifecycle(t *testing.T) {
cfg := factory.CreateDefaultConfig()
sub, err := cm.Sub("tests::config")
require.NoError(t, err)
require.NoError(t, component.UnmarshalConfig(sub, cfg))
require.NoError(t, sub.Unmarshal(&cfg))
atoulme marked this conversation as resolved.
Show resolved Hide resolved

for _, test := range tests {
{{- if not .Tests.SkipShutdown }}
Expand Down Expand Up @@ -199,7 +199,7 @@ func TestComponentLifecycle(t *testing.T) {
cfg := factory.CreateDefaultConfig()
sub, err := cm.Sub("tests::config")
require.NoError(t, err)
require.NoError(t, component.UnmarshalConfig(sub, cfg))
require.NoError(t, sub.Unmarshal(&cfg))

for _, test := range tests {
{{- if not .Tests.SkipShutdown }}
Expand Down Expand Up @@ -294,7 +294,7 @@ func TestComponentLifecycle(t *testing.T) {
cfg := factory.CreateDefaultConfig()
sub, err := cm.Sub("tests::config")
require.NoError(t, err)
require.NoError(t, component.UnmarshalConfig(sub, cfg))
require.NoError(t, sub.Unmarshal(&cfg))

for _, test := range tests {
{{- if not .Tests.SkipShutdown }}
Expand Down Expand Up @@ -333,7 +333,7 @@ func TestComponentLifecycle(t *testing.T) {
cfg := factory.CreateDefaultConfig()
sub, err := cm.Sub("tests::config")
require.NoError(t, err)
require.NoError(t, component.UnmarshalConfig(sub, cfg))
require.NoError(t, sub.Unmarshal(&cfg))

{{- if not .Tests.SkipShutdown }}
t.Run("shutdown", func(t *testing.T) {
Expand Down Expand Up @@ -456,7 +456,7 @@ func TestComponentLifecycle(t *testing.T) {
cfg := factory.CreateDefaultConfig()
sub, err := cm.Sub("tests::config")
require.NoError(t, err)
require.NoError(t, component.UnmarshalConfig(sub, cfg))
require.NoError(t, sub.Unmarshal(&cfg))

for _, test := range tests {
{{- if not .Tests.SkipShutdown }}
Expand Down
5 changes: 2 additions & 3 deletions cmd/mdatagen/templates/config_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap/confmaptest"
)

Expand Down Expand Up @@ -75,7 +74,7 @@ func loadMetricsBuilderConfig(t *testing.T, name string) MetricsBuilderConfig {
sub, err := cm.Sub(name)
require.NoError(t, err)
cfg := DefaultMetricsBuilderConfig()
require.NoError(t, component.UnmarshalConfig(sub, &cfg))
require.NoError(t, sub.Unmarshal(&cfg))
return cfg
}
{{- end }}
Expand Down Expand Up @@ -125,7 +124,7 @@ func loadResourceAttributesConfig(t *testing.T, name string) ResourceAttributesC
sub, err = sub.Sub("resource_attributes")
require.NoError(t, err)
cfg := DefaultResourceAttributesConfig()
require.NoError(t, component.UnmarshalConfig(sub, &cfg))
require.NoError(t, sub.Unmarshal(&cfg))
return cfg
}
{{- end }}
7 changes: 1 addition & 6 deletions component/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,8 @@ type Config any
var configValidatorType = reflect.TypeOf((*ConfigValidator)(nil)).Elem()

// UnmarshalConfig helper function to UnmarshalConfig a Config.
// It checks if the config implements confmap.Unmarshaler and uses that if available,
// otherwise uses Map.UnmarshalExact, erroring if a field is nonexistent.
// Deprecated: [v0.101.0] Use conf.Unmarshal(&intoCfg)
func UnmarshalConfig(conf *confmap.Conf, intoCfg Config) error {
atoulme marked this conversation as resolved.
Show resolved Hide resolved
if cu, ok := intoCfg.(confmap.Unmarshaler); ok {
return cu.Unmarshal(conf)
}

return conf.Unmarshal(intoCfg)
}

Expand Down
2 changes: 1 addition & 1 deletion connector/forwardconnector/generated_component_test.go

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

7 changes: 3 additions & 4 deletions exporter/debugexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/confmap/confmaptest"
Expand All @@ -19,7 +18,7 @@ import (
func TestUnmarshalDefaultConfig(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
assert.NoError(t, component.UnmarshalConfig(confmap.New(), cfg))
assert.NoError(t, confmap.New().Unmarshal(&cfg))
assert.Equal(t, factory.CreateDefaultConfig(), cfg)
}

Expand Down Expand Up @@ -49,7 +48,7 @@ func TestUnmarshalConfig(t *testing.T) {
require.NoError(t, err)
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
err = component.UnmarshalConfig(cm, cfg)
err = cm.Unmarshal(&cfg)
if tt.expectedErr != "" {
assert.EqualError(t, err, tt.expectedErr)
} else {
Expand Down Expand Up @@ -91,7 +90,7 @@ func Test_UnmarshalMarshalled(t *testing.T) {

outCfg := &Config{}

err = component.UnmarshalConfig(conf, outCfg)
err = conf.Unmarshal(outCfg)

if tc.expectedErr == "" {
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion exporter/debugexporter/generated_component_test.go

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

7 changes: 3 additions & 4 deletions exporter/loggingexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/confmap/confmaptest"
Expand All @@ -20,7 +19,7 @@ import (
func TestUnmarshalDefaultConfig(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
assert.NoError(t, component.UnmarshalConfig(confmap.New(), cfg))
assert.NoError(t, confmap.New().Unmarshal(&cfg))
assert.Equal(t, factory.CreateDefaultConfig(), cfg)
}

Expand Down Expand Up @@ -75,7 +74,7 @@ func TestUnmarshalConfig(t *testing.T) {
require.NoError(t, err)
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
err = component.UnmarshalConfig(cm, cfg)
err = cm.Unmarshal(&cfg)
if tt.expectedErr != "" {
assert.EqualError(t, err, tt.expectedErr)
} else {
Expand Down Expand Up @@ -135,7 +134,7 @@ func Test_UnmarshalMarshalled(t *testing.T) {

outCfg := &Config{}

err = component.UnmarshalConfig(conf, outCfg)
err = conf.Unmarshal(outCfg)

if tc.expectedErr == "" {
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion exporter/loggingexporter/generated_component_test.go

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

2 changes: 1 addition & 1 deletion exporter/nopexporter/generated_component_test.go

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

6 changes: 3 additions & 3 deletions exporter/otlpexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
func TestUnmarshalDefaultConfig(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
assert.NoError(t, component.UnmarshalConfig(confmap.New(), cfg))
assert.NoError(t, confmap.New().Unmarshal(&cfg))
assert.Equal(t, factory.CreateDefaultConfig(), cfg)
}

Expand All @@ -34,7 +34,7 @@ func TestUnmarshalConfig(t *testing.T) {
require.NoError(t, err)
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
assert.NoError(t, component.UnmarshalConfig(cm, cfg))
assert.NoError(t, cm.Unmarshal(&cfg))
assert.Equal(t,
&Config{
TimeoutSettings: exporterhelper.TimeoutSettings{
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestUnmarshalInvalidConfig(t *testing.T) {
cfg := factory.CreateDefaultConfig()
sub, err := cm.Sub(test.name)
require.NoError(t, err)
assert.NoError(t, component.UnmarshalConfig(sub, cfg))
assert.NoError(t, sub.Unmarshal(&cfg))
assert.ErrorContains(t, component.ValidateConfig(cfg), test.errorMsg)
})
}
Expand Down
2 changes: 1 addition & 1 deletion exporter/otlpexporter/generated_component_test.go

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

6 changes: 3 additions & 3 deletions exporter/otlphttpexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
func TestUnmarshalDefaultConfig(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
assert.NoError(t, component.UnmarshalConfig(confmap.New(), cfg))
assert.NoError(t, confmap.New().Unmarshal(&cfg))
assert.Equal(t, factory.CreateDefaultConfig(), cfg)
// Default/Empty config is invalid.
assert.Error(t, component.ValidateConfig(cfg))
Expand All @@ -35,7 +35,7 @@ func TestUnmarshalConfig(t *testing.T) {
require.NoError(t, err)
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
assert.NoError(t, component.UnmarshalConfig(cm, cfg))
assert.NoError(t, cm.Unmarshal(&cfg))
assert.Equal(t,
&Config{
RetryConfig: configretry.BackOffConfig{
Expand Down Expand Up @@ -80,7 +80,7 @@ func TestUnmarshalConfigInvalidEncoding(t *testing.T) {
require.NoError(t, err)
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
assert.Error(t, component.UnmarshalConfig(cm, cfg))
assert.Error(t, cm.Unmarshal(&cfg))
}

func TestUnmarshalEncoding(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion exporter/otlphttpexporter/generated_component_test.go

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

5 changes: 2 additions & 3 deletions extension/ballastextension/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/confmap/confmaptest"
)

func TestUnmarshalDefaultConfig(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
assert.NoError(t, component.UnmarshalConfig(confmap.New(), cfg))
assert.NoError(t, confmap.New().Unmarshal(&cfg))
assert.Equal(t, factory.CreateDefaultConfig(), cfg)
}

Expand All @@ -27,7 +26,7 @@ func TestUnmarshalConfig(t *testing.T) {
require.NoError(t, err)
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
assert.NoError(t, component.UnmarshalConfig(cm, cfg))
assert.NoError(t, cm.Unmarshal(&cfg))
assert.Equal(t,
&Config{
SizeMiB: 123,
Expand Down
3 changes: 1 addition & 2 deletions extension/ballastextension/generated_component_test.go

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

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

Loading
Loading