From e90e4bfde2ce60b328abb50e4afb0ed2182a2717 Mon Sep 17 00:00:00 2001 From: Evan Bradley <11745660+evan-bradley@users.noreply.github.com> Date: Mon, 20 May 2024 09:10:16 -0400 Subject: [PATCH] [confmap] Remove deprecated ResolverSettings fields (#10173) #### Description These fields were deprecated in v0.99.0 and aren't used in any upstream repositories. These appear to still be used in downstream distributions. If we want to lengthen the deprecation period for these fields, I'll open a PR to instead set a timeline for their removal. --- .chloggen/remove-confmap-instances.yaml | 25 +++++++++++++ confmap/resolver.go | 48 ++++++------------------- confmap/resolver_test.go | 38 -------------------- 3 files changed, 35 insertions(+), 76 deletions(-) create mode 100644 .chloggen/remove-confmap-instances.yaml diff --git a/.chloggen/remove-confmap-instances.yaml b/.chloggen/remove-confmap-instances.yaml new file mode 100644 index 00000000000..5f2528d20cc --- /dev/null +++ b/.chloggen/remove-confmap-instances.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: confmap + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Remove deprecated `Providers` and `Converters` from `confmap.ResolverSettings` + +# One or more tracking issues or pull requests related to the change +issues: [10173] + +# (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: Use `ProviderSettings` and `ConverterSettings` instead. + +# 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/confmap/resolver.go b/confmap/resolver.go index c3de276e245..304dc3f71c3 100644 --- a/confmap/resolver.go +++ b/confmap/resolver.go @@ -39,12 +39,6 @@ type ResolverSettings struct { // if a Provider is not given. ProviderFactories []ProviderFactory - // Providers is a map of pairs . - // It is required to have at least one Provider. - // - // Deprecated: [v0.99.0] Use ProviderFactories instead - Providers map[string]Provider - // ProviderSettings contains settings that will be passed to Provider // factories when instantiating Providers. ProviderSettings ProviderSettings @@ -52,11 +46,6 @@ type ResolverSettings struct { // ConverterFactories is a slice of Converter creation functions. ConverterFactories []ConverterFactory - // Converters is a slice of Converters. - // - // Deprecated: [v0.99.0] Use ConverterFactories instead - Converters []Converter - // ConverterSettings contains settings that will be passed to Converter // factories when instantiating Converters. ConverterSettings ConverterSettings @@ -83,11 +72,11 @@ type ResolverSettings struct { // (see https://datatracker.ietf.org/doc/html/rfc3986). An empty "" defaults to "file" schema. func NewResolver(set ResolverSettings) (*Resolver, error) { if len(set.URIs) == 0 { - return nil, errors.New("invalid map resolver config: no URIs") + return nil, errors.New("invalid 'confmap.ResolverSettings' configuration: no URIs") } - if len(set.ProviderFactories) == 0 && len(set.Providers) == 0 { - return nil, errors.New("invalid map resolver config: no Providers") + if len(set.ProviderFactories) == 0 { + return nil, errors.New("invalid 'confmap.ResolverSettings' configuration: no Providers") } if set.ProviderSettings.Logger == nil { @@ -98,32 +87,15 @@ func NewResolver(set ResolverSettings) (*Resolver, error) { set.ConverterSettings.Logger = zap.NewNop() } - var providers map[string]Provider - var converters []Converter - - if len(set.Providers) != 0 { - if len(set.ProviderFactories) != 0 { - return nil, errors.New("only one of ResolverSettings.Providers and ResolverSettings.ProviderFactories can be used") - } - providers = set.Providers - } else { - providers = make(map[string]Provider, len(set.ProviderFactories)) - for _, factory := range set.ProviderFactories { - provider := factory.Create(set.ProviderSettings) - providers[provider.Scheme()] = provider - } + providers := make(map[string]Provider, len(set.ProviderFactories)) + for _, factory := range set.ProviderFactories { + provider := factory.Create(set.ProviderSettings) + providers[provider.Scheme()] = provider } - if len(set.Converters) != 0 { - if len(set.ConverterFactories) != 0 { - return nil, errors.New("only one of ResolverSettings.Converters and ResolverSettings.ConverterFactories can be used") - } - converters = set.Converters - } else { - converters = make([]Converter, len(set.ConverterFactories)) - for i, factory := range set.ConverterFactories { - converters[i] = factory.Create(set.ConverterSettings) - } + converters := make([]Converter, len(set.ConverterFactories)) + for i, factory := range set.ConverterFactories { + converters[i] = factory.Create(set.ConverterSettings) } // Safe copy, ensures the slices and maps cannot be changed from the caller. diff --git a/confmap/resolver_test.go b/confmap/resolver_test.go index d0218d01f3d..3a162c85247 100644 --- a/confmap/resolver_test.go +++ b/confmap/resolver_test.go @@ -382,44 +382,6 @@ func TestResolverShutdownClosesWatch(t *testing.T) { watcherWG.Wait() } -func TestCantConfigureTwoProviderSettings(t *testing.T) { - _, err := NewResolver(ResolverSettings{ - URIs: []string{filepath.Join("testdata", "config.yaml")}, - ProviderFactories: []ProviderFactory{newFileProvider(t)}, - Providers: map[string]Provider{"mock": &mockProvider{}}, - ConverterFactories: nil, - }) - require.Error(t, err) -} - -func TestCantConfigureTwoConverterSettings(t *testing.T) { - _, err := NewResolver(ResolverSettings{ - URIs: []string{filepath.Join("testdata", "config.yaml")}, - ProviderFactories: []ProviderFactory{newFileProvider(t)}, - ConverterFactories: []ConverterFactory{NewConverterFactory(func(_ ConverterSettings) Converter { return &mockConverter{} })}, - Converters: []Converter{&mockConverter{err: errors.New("converter_err")}}, - }) - require.Error(t, err) -} - -func TestTakesInstantiatedProviders(t *testing.T) { - _, err := NewResolver(ResolverSettings{ - URIs: []string{filepath.Join("testdata", "config.yaml")}, - Providers: map[string]Provider{"mock": &mockProvider{}}, - ConverterFactories: nil, - }) - require.NoError(t, err) -} - -func TestTakesInstantiatedConverters(t *testing.T) { - _, err := NewResolver(ResolverSettings{ - URIs: []string{filepath.Join("testdata", "config.yaml")}, - ProviderFactories: []ProviderFactory{newFileProvider(t)}, - Converters: []Converter{&mockConverter{err: errors.New("converter_err")}}, - }) - require.NoError(t, err) -} - func TestProvidesDefaultLogger(t *testing.T) { factory, provider := newObservableFileProvider(t) _, err := NewResolver(ResolverSettings{