From 311078f6d4fbaef3ca28df1ad2bfebf9dd4ad1f7 Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Tue, 12 Mar 2024 18:27:07 -0700 Subject: [PATCH] [config] Deprecate config.UnmarshalConfig --- .chloggen/embedded_struct_unmarshaler.yaml | 25 +++++++ .../generated_component_test.go | 2 +- cmd/mdatagen/loader.go | 6 +- cmd/mdatagen/loader_test.go | 4 +- cmd/mdatagen/metricdata.go | 52 ++++--------- cmd/mdatagen/templates/component_test.go.tmpl | 10 +-- component/config.go | 7 +- component/config_test.go | 27 ------- confmap/confmap.go | 75 +++++++++++++------ confmap/confmap_test.go | 59 +++++++++++++-- .../generated_component_test.go | 2 +- .../debugexporter/generated_component_test.go | 2 +- .../generated_component_test.go | 2 +- .../nopexporter/generated_component_test.go | 2 +- .../otlpexporter/generated_component_test.go | 2 +- .../generated_component_test.go | 2 +- .../generated_component_test.go | 3 +- .../generated_component_test.go | 3 +- .../generated_component_test.go | 3 +- .../generated_component_test.go | 2 +- .../generated_component_test.go | 2 +- .../nopreceiver/generated_component_test.go | 2 +- .../otlpreceiver/generated_component_test.go | 2 +- 23 files changed, 168 insertions(+), 128 deletions(-) create mode 100644 .chloggen/embedded_struct_unmarshaler.yaml diff --git a/.chloggen/embedded_struct_unmarshaler.yaml b/.chloggen/embedded_struct_unmarshaler.yaml new file mode 100644 index 00000000000..d579630a03c --- /dev/null +++ b/.chloggen/embedded_struct_unmarshaler.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: 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. + +# 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] diff --git a/cmd/mdatagen/internal/samplereceiver/generated_component_test.go b/cmd/mdatagen/internal/samplereceiver/generated_component_test.go index 8eb4377792f..11bffede3bc 100644 --- a/cmd/mdatagen/internal/samplereceiver/generated_component_test.go +++ b/cmd/mdatagen/internal/samplereceiver/generated_component_test.go @@ -51,7 +51,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 { t.Run(test.name+"-shutdown", func(t *testing.T) { diff --git a/cmd/mdatagen/loader.go b/cmd/mdatagen/loader.go index aef532516a7..f28681cc737 100644 --- a/cmd/mdatagen/loader.go +++ b/cmd/mdatagen/loader.go @@ -124,11 +124,7 @@ func (m *metric) Unmarshal(parser *confmap.Conf) error { if !parser.IsSet("enabled") { return errors.New("missing required field: `enabled`") } - err := parser.Unmarshal(m) - if err != nil { - return err - } - return nil + return parser.Unmarshal(m) } func (m metric) Data() MetricData { if m.Sum != nil { diff --git a/cmd/mdatagen/loader_test.go b/cmd/mdatagen/loader_test.go index 677288258d2..b9040e23380 100644 --- a/cmd/mdatagen/loader_test.go +++ b/cmd/mdatagen/loader_test.go @@ -249,7 +249,7 @@ func TestLoadMetadata(t *testing.T) { }, { name: "testdata/unknown_value_type.yaml", - wantErr: "1 error(s) decoding:\n\n* error decoding 'metrics[system.cpu.time]': 1 error(s) decoding:\n\n* error decoding 'sum': 1 error(s) decoding:\n\n* error decoding 'value_type': invalid value_type: \"unknown\"", + wantErr: "1 error(s) decoding:\n\n* error decoding 'metrics[system.cpu.time]': 1 error(s) decoding:\n\n* error decoding 'sum': invalid value_type: \"unknown\"", }, { name: "testdata/no_aggregation.yaml", @@ -259,7 +259,7 @@ func TestLoadMetadata(t *testing.T) { { name: "testdata/invalid_aggregation.yaml", want: metadata{}, - wantErr: "1 error(s) decoding:\n\n* error decoding 'metrics[default.metric]': 1 error(s) decoding:\n\n* error decoding 'sum': 1 error(s) decoding:\n\n* error decoding 'aggregation_temporality': invalid aggregation: \"invalidaggregation\"", + wantErr: "1 error(s) decoding:\n\n* error decoding 'metrics[default.metric]': 1 error(s) decoding:\n\n* error decoding 'sum': invalid aggregation: \"invalidaggregation\"", }, { name: "testdata/invalid_type_attr.yaml", diff --git a/cmd/mdatagen/metricdata.go b/cmd/mdatagen/metricdata.go index 5bf77985cc9..d70e5324084 100644 --- a/cmd/mdatagen/metricdata.go +++ b/cmd/mdatagen/metricdata.go @@ -28,18 +28,20 @@ type MetricData interface { type AggregationTemporality struct { // Aggregation describes if the aggregator reports delta changes // since last report time, or cumulative changes since a fixed start time. - Aggregation pmetric.AggregationTemporality + Aggregation pmetric.AggregationTemporality `mapstructure:"aggregation_temporality"` } -// UnmarshalText implements the encoding.TextUnmarshaler interface. -func (agg *AggregationTemporality) UnmarshalText(text []byte) error { - switch vtStr := string(text); vtStr { +func (agg *AggregationTemporality) Unmarshal(parser *confmap.Conf) error { + if !parser.IsSet("aggregation_temporality") { + return errors.New("missing required field: `aggregation_temporality`") + } + switch vt := parser.Get("aggregation_temporality"); vt { case "cumulative": agg.Aggregation = pmetric.AggregationTemporalityCumulative case "delta": agg.Aggregation = pmetric.AggregationTemporalityDelta default: - return fmt.Errorf("invalid aggregation: %q", vtStr) + return fmt.Errorf("invalid aggregation: %q", vt) } return nil } @@ -73,36 +75,31 @@ func (mit MetricInputType) String() string { // MetricValueType defines the metric number type. type MetricValueType struct { // ValueType is type of the metric number, options are "double", "int". - ValueType pmetric.NumberDataPointValueType + ValueType pmetric.NumberDataPointValueType `mapstructure:"value_type"` } func (mvt *MetricValueType) Unmarshal(parser *confmap.Conf) error { if !parser.IsSet("value_type") { return errors.New("missing required field: `value_type`") } - return nil -} - -// UnmarshalText implements the encoding.TextUnmarshaler interface. -func (mvt *MetricValueType) UnmarshalText(text []byte) error { - switch vtStr := string(text); vtStr { + switch vt := parser.Get("value_type"); vt { case "int": mvt.ValueType = pmetric.NumberDataPointValueTypeInt case "double": mvt.ValueType = pmetric.NumberDataPointValueTypeDouble default: - return fmt.Errorf("invalid value_type: %q", vtStr) + return fmt.Errorf("invalid value_type: %q", vt) } return nil } // Type returns name of the datapoint type. -func (mvt MetricValueType) String() string { +func (mvt *MetricValueType) String() string { return mvt.ValueType.String() } // BasicType returns name of a golang basic type for the datapoint type. -func (mvt MetricValueType) BasicType() string { +func (mvt *MetricValueType) BasicType() string { switch mvt.ValueType { case pmetric.NumberDataPointValueTypeInt: return "int64" @@ -116,18 +113,10 @@ func (mvt MetricValueType) BasicType() string { } type gauge struct { - MetricValueType `mapstructure:"value_type"` + MetricValueType `mapstructure:",squash"` MetricInputType `mapstructure:",squash"` } -// Unmarshal is a custom unmarshaler for gauge. Needed mostly to avoid MetricValueType.Unmarshal inheritance. -func (d *gauge) Unmarshal(parser *confmap.Conf) error { - if err := d.MetricValueType.Unmarshal(parser); err != nil { - return err - } - return parser.Unmarshal(d, confmap.WithIgnoreUnused()) -} - func (d gauge) Type() string { return "Gauge" } @@ -141,23 +130,12 @@ func (d gauge) HasAggregated() bool { } type sum struct { - AggregationTemporality `mapstructure:"aggregation_temporality"` + AggregationTemporality `mapstructure:",squash"` Mono `mapstructure:",squash"` - MetricValueType `mapstructure:"value_type"` + MetricValueType `mapstructure:",squash"` MetricInputType `mapstructure:",squash"` } -// Unmarshal is a custom unmarshaler for sum. Needed mostly to avoid MetricValueType.Unmarshal inheritance. -func (d *sum) Unmarshal(parser *confmap.Conf) error { - if !parser.IsSet("aggregation_temporality") { - return errors.New("missing required field: `aggregation_temporality`") - } - if err := d.MetricValueType.Unmarshal(parser); err != nil { - return err - } - return parser.Unmarshal(d, confmap.WithIgnoreUnused()) -} - // TODO: Currently, this func will not be called because of https://github.com/open-telemetry/opentelemetry-collector/issues/6671. Uncomment function and // add a test case to Test_loadMetadata for file no_monotonic.yaml once the issue is solved. // diff --git a/cmd/mdatagen/templates/component_test.go.tmpl b/cmd/mdatagen/templates/component_test.go.tmpl index 0caf18e8c0f..57090bb5c68 100644 --- a/cmd/mdatagen/templates/component_test.go.tmpl +++ b/cmd/mdatagen/templates/component_test.go.tmpl @@ -88,7 +88,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 }} @@ -179,7 +179,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 }} @@ -268,7 +268,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 }} @@ -307,7 +307,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) { @@ -421,7 +421,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 }} diff --git a/component/config.go b/component/config.go index 03569aa166b..3c9a360bc79 100644 --- a/component/config.go +++ b/component/config.go @@ -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: Use conf.Unmarshal(&intoCfg) func UnmarshalConfig(conf *confmap.Conf, intoCfg Config) error { - if cu, ok := intoCfg.(confmap.Unmarshaler); ok { - return cu.Unmarshal(conf) - } - return conf.Unmarshal(intoCfg) } diff --git a/component/config_test.go b/component/config_test.go index f1c3c65b395..79651959108 100644 --- a/component/config_test.go +++ b/component/config_test.go @@ -11,8 +11,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "go.opentelemetry.io/collector/confmap" ) var _ fmt.Stringer = Type{} @@ -419,28 +417,3 @@ func TestNewType(t *testing.T) { }) } } - -type configWithEmbeddedStruct struct { - String string `mapstructure:"string"` - Num int `mapstructure:"num"` - embeddedUnmarshallingConfig -} - -type embeddedUnmarshallingConfig struct { -} - -func (euc *embeddedUnmarshallingConfig) Unmarshal(_ *confmap.Conf) error { - return nil // do nothing. -} -func TestStructWithEmbeddedUnmarshaling(t *testing.T) { - t.Skip("Skipping, to be fixed with https://github.com/open-telemetry/opentelemetry-collector/issues/7102") - cfgMap := confmap.NewFromStringMap(map[string]any{ - "string": "foo", - "num": 123, - }) - tc := &configWithEmbeddedStruct{} - err := UnmarshalConfig(cfgMap, tc) - require.NoError(t, err) - assert.Equal(t, "foo", tc.String) - assert.Equal(t, 123, tc.Num) -} diff --git a/confmap/confmap.go b/confmap/confmap.go index be8515a8faf..c59afa70244 100644 --- a/confmap/confmap.go +++ b/confmap/confmap.go @@ -5,8 +5,10 @@ package confmap // import "go.opentelemetry.io/collector/confmap" import ( "encoding" + "errors" "fmt" "reflect" + "strings" "github.com/go-viper/mapstructure/v2" "github.com/knadh/koanf/maps" @@ -37,7 +39,8 @@ func NewFromStringMap(data map[string]any) *Conf { // Conf represents the raw configuration map for the OpenTelemetry Collector. // The confmap.Conf can be unmarshalled into the Collector's config using the "service" package. type Conf struct { - k *koanf.Koanf + k *koanf.Koanf + self any } // AllKeys returns all keys holding a value, regardless of where they are set. @@ -76,7 +79,7 @@ func (l *Conf) Unmarshal(result any, opts ...UnmarshalOption) error { for _, opt := range opts { opt.apply(&set) } - return decodeConfig(l, result, !set.ignoreUnused) + return decodeConfig(l, result, !set.ignoreUnused, l.self != result) } type marshalOption struct{} @@ -143,7 +146,19 @@ func (l *Conf) ToStringMap() map[string]any { // uniqueness of component IDs (see mapKeyStringToMapKeyTextUnmarshalerHookFunc). // Decodes time.Duration from strings. Allows custom unmarshaling for structs implementing // encoding.TextUnmarshaler. Allows custom unmarshaling for structs implementing confmap.Unmarshaler. -func decodeConfig(m *Conf, result any, errorUnused bool) error { +func decodeConfig(m *Conf, result any, errorUnused bool, topLevelUnmarshaling bool) error { + hookFuncs := []mapstructure.DecodeHookFunc{ + expandNilStructPointersHookFunc(), + mapstructure.StringToSliceHookFunc(","), + mapKeyStringToMapKeyTextUnmarshalerHookFunc(), + mapstructure.StringToTimeDurationHookFunc(), + mapstructure.TextUnmarshallerHookFunc(), + unmarshalerHookFunc(result, topLevelUnmarshaling), + // after the main unmarshaler hook is called, + // we unmarshal the embedded structs if present to merge with the result: + unmarshalerEmbeddedStructsHookFunc(), + zeroSliceHookFunc(), + } dc := &mapstructure.DecoderConfig{ ErrorUnused: errorUnused, Result: result, @@ -151,23 +166,20 @@ func decodeConfig(m *Conf, result any, errorUnused bool) error { WeaklyTypedInput: true, MatchName: caseSensitiveMatchName, DecodeHook: mapstructure.ComposeDecodeHookFunc( - expandNilStructPointersHookFunc(), - mapstructure.StringToSliceHookFunc(","), - mapKeyStringToMapKeyTextUnmarshalerHookFunc(), - mapstructure.StringToTimeDurationHookFunc(), - mapstructure.TextUnmarshallerHookFunc(), - unmarshalerHookFunc(result), - // after the main unmarshaler hook is called, - // we unmarshal the embedded structs if present to merge with the result: - unmarshalerEmbeddedStructsHookFunc(), - zeroSliceHookFunc(), + hookFuncs..., ), } decoder, err := mapstructure.NewDecoder(dc) if err != nil { return err } - return decoder.Decode(m.ToStringMap()) + if err = decoder.Decode(m.ToStringMap()); err != nil { + if strings.HasPrefix(err.Error(), "error decoding ''") { + return errors.Unwrap(err) + } + return err + } + return nil } // encoderConfig returns a default encoder.EncoderConfig that includes @@ -277,9 +289,12 @@ func unmarshalerEmbeddedStructsHookFunc() mapstructure.DecodeHookFuncValue { } for i := 0; i < to.Type().NumField(); i++ { // embedded structs passed in via `squash` cannot be pointers. We just check if they are structs: - if to.Type().Field(i).IsExported() && to.Type().Field(i).Anonymous { + f := to.Type().Field(i) + if f.IsExported() && f.Anonymous && f.Tag.Get("mapstructure") == ",squash" { if unmarshaler, ok := to.Field(i).Addr().Interface().(Unmarshaler); ok { - if err := unmarshaler.Unmarshal(NewFromStringMap(fromAsMap)); err != nil { + c := NewFromStringMap(fromAsMap) + c.self = unmarshaler + if err := unmarshaler.Unmarshal(c); err != nil { return nil, err } // the struct we receive from this unmarshaling only contains fields related to the embedded struct. @@ -302,7 +317,7 @@ func unmarshalerEmbeddedStructsHookFunc() mapstructure.DecodeHookFuncValue { // Provides a mechanism for individual structs to define their own unmarshal logic, // by implementing the Unmarshaler interface. -func unmarshalerHookFunc(result any) mapstructure.DecodeHookFuncValue { +func unmarshalerHookFunc(result any, allowTopLevelUnmarshaler bool) mapstructure.DecodeHookFuncValue { return func(from reflect.Value, to reflect.Value) (any, error) { if !to.CanAddr() { return from.Interface(), nil @@ -310,7 +325,7 @@ func unmarshalerHookFunc(result any) mapstructure.DecodeHookFuncValue { toPtr := to.Addr().Interface() // Need to ignore the top structure to avoid circular dependency. - if toPtr == result { + if toPtr == result && !allowTopLevelUnmarshaler { return from.Interface(), nil } @@ -318,17 +333,31 @@ func unmarshalerHookFunc(result any) mapstructure.DecodeHookFuncValue { if !ok { return from.Interface(), nil } - - if _, ok = from.Interface().(map[string]any); !ok { - return from.Interface(), nil + unmarshalMethod := reflect.ValueOf(toPtr).MethodByName("Unmarshal") + // check that the Unmarshal method is not defined on one of the squash embedded structs defined. + // This allows us to have composition where the Unmarshaler may embed structs implementing Unmarshaler. + if to.Type().Kind() == reflect.Struct { + for i := 0; i < to.Type().NumField(); i++ { + // check embedded structs: + f := to.Type().Field(i) + if f.IsExported() && f.Anonymous && f.Tag.Get("mapstructure") == ",squash" { + if embedded, ok := to.Field(i).Addr().Interface().(Unmarshaler); ok { + embeddedUnmarshalMethod := reflect.ValueOf(embedded).MethodByName("Unmarshal") + if unmarshalMethod.Pointer() == embeddedUnmarshalMethod.Pointer() { + return from.Interface(), nil + } + } + } + } } // Use the current object if not nil (to preserve other configs in the object), otherwise zero initialize. if to.Addr().IsNil() { unmarshaler = reflect.New(to.Type()).Interface().(Unmarshaler) } - - if err := unmarshaler.Unmarshal(NewFromStringMap(from.Interface().(map[string]any))); err != nil { + c := NewFromStringMap(from.Interface().(map[string]any)) + c.self = unmarshaler + if err := unmarshaler.Unmarshal(c); err != nil { return nil, err } diff --git a/confmap/confmap_test.go b/confmap/confmap_test.go index 20659fd29f3..a48357bfc34 100644 --- a/confmap/confmap_test.go +++ b/confmap/confmap_test.go @@ -450,7 +450,7 @@ func TestEmbeddedUnmarshalerError(t *testing.T) { }) tc := &testConfigWithEmbeddedError{} - assert.EqualError(t, cfgMap.Unmarshal(tc), "error decoding '': embedded error") + assert.EqualError(t, cfgMap.Unmarshal(tc), "embedded error") } func TestEmbeddedMarshalerError(t *testing.T) { @@ -462,7 +462,7 @@ func TestEmbeddedMarshalerError(t *testing.T) { }) tc := &testConfigWithMarshalError{} - assert.EqualError(t, cfgMap.Unmarshal(tc), "error decoding '': error running encode hook: marshaling error") + assert.EqualError(t, cfgMap.Unmarshal(tc), "error running encode hook: marshaling error") } func TestUnmarshalerKeepAlreadyInitialized(t *testing.T) { @@ -503,10 +503,6 @@ type testErrConfig struct { Err errConfig `mapstructure:"err"` } -func (tc *testErrConfig) Unmarshal(component *Conf) error { - return component.Unmarshal(tc) -} - type errConfig struct { Foo string `mapstructure:"foo"` } @@ -613,3 +609,54 @@ func TestZeroSliceHookFunc(t *testing.T) { }) } } + +type configWithEmbeddedStruct struct { + String string `mapstructure:"string"` + Num int `mapstructure:"num"` + EmbeddedUnmarshallingConfig `mapstructure:",squash"` +} + +type EmbeddedUnmarshallingConfig struct { + Embedded string `mapstructure:"embedded"` +} + +func (euc *EmbeddedUnmarshallingConfig) Unmarshal(conf *Conf) error { + if err := conf.Unmarshal(euc, WithIgnoreUnused()); err != nil { + return err + } + euc.Embedded += " unmarshaled" + return nil +} +func TestStructWithEmbeddedUnmarshaling(t *testing.T) { + cfgMap := NewFromStringMap(map[string]any{ + "string": "foo", + "num": 123, + "embedded": "bar", + }) + tc := &configWithEmbeddedStruct{} + err := cfgMap.Unmarshal(tc) + require.NoError(t, err) + assert.Equal(t, "foo", tc.String) + assert.Equal(t, 123, tc.Num) + assert.Equal(t, "bar unmarshaled", tc.Embedded) +} + +type configWithEmbeddedUnmarshalMethod struct { + EmbeddedUnmarshallingMethodConfig +} + +type EmbeddedUnmarshallingMethodConfig struct { + MyValue string +} + +func (euc *EmbeddedUnmarshallingMethodConfig) Unmarshal(_ *Conf) error { + euc.MyValue = "my custom value" + return nil +} +func TestStructWithEmbeddedUnmarshalMethod(t *testing.T) { + cfgMap := NewFromStringMap(map[string]any{}) + tc := &configWithEmbeddedUnmarshalMethod{} + err := cfgMap.Unmarshal(tc, WithIgnoreUnused()) + require.NoError(t, err) + assert.Equal(t, "my custom value", tc.MyValue) +} diff --git a/connector/forwardconnector/generated_component_test.go b/connector/forwardconnector/generated_component_test.go index 27af252dad1..942fdb3d827 100644 --- a/connector/forwardconnector/generated_component_test.go +++ b/connector/forwardconnector/generated_component_test.go @@ -51,7 +51,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 { t.Run(test.name+"-shutdown", func(t *testing.T) { diff --git a/exporter/debugexporter/generated_component_test.go b/exporter/debugexporter/generated_component_test.go index 7efad327751..9d6a38cc2d1 100644 --- a/exporter/debugexporter/generated_component_test.go +++ b/exporter/debugexporter/generated_component_test.go @@ -55,7 +55,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 { t.Run(test.name+"-shutdown", func(t *testing.T) { diff --git a/exporter/loggingexporter/generated_component_test.go b/exporter/loggingexporter/generated_component_test.go index 9f8771a9da0..6fed85c8da4 100644 --- a/exporter/loggingexporter/generated_component_test.go +++ b/exporter/loggingexporter/generated_component_test.go @@ -55,7 +55,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 { t.Run(test.name+"-shutdown", func(t *testing.T) { diff --git a/exporter/nopexporter/generated_component_test.go b/exporter/nopexporter/generated_component_test.go index 45a556168e4..a02f6930d32 100644 --- a/exporter/nopexporter/generated_component_test.go +++ b/exporter/nopexporter/generated_component_test.go @@ -55,7 +55,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 { t.Run(test.name+"-shutdown", func(t *testing.T) { diff --git a/exporter/otlpexporter/generated_component_test.go b/exporter/otlpexporter/generated_component_test.go index 85ed788065a..cf08750e5a4 100644 --- a/exporter/otlpexporter/generated_component_test.go +++ b/exporter/otlpexporter/generated_component_test.go @@ -55,7 +55,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 { t.Run(test.name+"-shutdown", func(t *testing.T) { diff --git a/exporter/otlphttpexporter/generated_component_test.go b/exporter/otlphttpexporter/generated_component_test.go index c032505a050..5a32c41681d 100644 --- a/exporter/otlphttpexporter/generated_component_test.go +++ b/exporter/otlphttpexporter/generated_component_test.go @@ -55,7 +55,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 { t.Run(test.name+"-shutdown", func(t *testing.T) { diff --git a/extension/ballastextension/generated_component_test.go b/extension/ballastextension/generated_component_test.go index f43cef29af4..d820a5c51de 100644 --- a/extension/ballastextension/generated_component_test.go +++ b/extension/ballastextension/generated_component_test.go @@ -8,7 +8,6 @@ import ( "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/confmap/confmaptest" "go.opentelemetry.io/collector/extension/extensiontest" @@ -22,7 +21,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)) t.Run("shutdown", func(t *testing.T) { e, err := factory.CreateExtension(context.Background(), extensiontest.NewNopCreateSettings(), cfg) require.NoError(t, err) diff --git a/extension/memorylimiterextension/generated_component_test.go b/extension/memorylimiterextension/generated_component_test.go index ef808e120ac..04c872fbe3c 100644 --- a/extension/memorylimiterextension/generated_component_test.go +++ b/extension/memorylimiterextension/generated_component_test.go @@ -8,7 +8,6 @@ import ( "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/confmap/confmaptest" "go.opentelemetry.io/collector/extension/extensiontest" @@ -22,7 +21,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)) t.Run("lifecycle", func(t *testing.T) { firstExt, err := factory.CreateExtension(context.Background(), extensiontest.NewNopCreateSettings(), cfg) require.NoError(t, err) diff --git a/extension/zpagesextension/generated_component_test.go b/extension/zpagesextension/generated_component_test.go index f8c9f634b3c..d2bf96e9194 100644 --- a/extension/zpagesextension/generated_component_test.go +++ b/extension/zpagesextension/generated_component_test.go @@ -8,7 +8,6 @@ import ( "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/confmap/confmaptest" "go.opentelemetry.io/collector/extension/extensiontest" @@ -22,7 +21,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)) t.Run("shutdown", func(t *testing.T) { e, err := factory.CreateExtension(context.Background(), extensiontest.NewNopCreateSettings(), cfg) require.NoError(t, err) diff --git a/processor/batchprocessor/generated_component_test.go b/processor/batchprocessor/generated_component_test.go index 3c2313b4115..64ed9fc5bb8 100644 --- a/processor/batchprocessor/generated_component_test.go +++ b/processor/batchprocessor/generated_component_test.go @@ -55,7 +55,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 { t.Run(test.name+"-shutdown", func(t *testing.T) { diff --git a/processor/memorylimiterprocessor/generated_component_test.go b/processor/memorylimiterprocessor/generated_component_test.go index 5c13dde733c..0fd0ceb0b05 100644 --- a/processor/memorylimiterprocessor/generated_component_test.go +++ b/processor/memorylimiterprocessor/generated_component_test.go @@ -56,7 +56,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 { t.Run(test.name+"-lifecycle", func(t *testing.T) { diff --git a/receiver/nopreceiver/generated_component_test.go b/receiver/nopreceiver/generated_component_test.go index 7a5d702867d..5a86d22f37f 100644 --- a/receiver/nopreceiver/generated_component_test.go +++ b/receiver/nopreceiver/generated_component_test.go @@ -51,7 +51,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 { t.Run(test.name+"-shutdown", func(t *testing.T) { diff --git a/receiver/otlpreceiver/generated_component_test.go b/receiver/otlpreceiver/generated_component_test.go index 310eaa3d6b0..06fd87aa934 100644 --- a/receiver/otlpreceiver/generated_component_test.go +++ b/receiver/otlpreceiver/generated_component_test.go @@ -51,7 +51,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 { t.Run(test.name+"-shutdown", func(t *testing.T) {