Skip to content

Commit

Permalink
[confmap] Remove deprecated ResolverSettings fields (#10173)
Browse files Browse the repository at this point in the history
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### 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.
  • Loading branch information
evan-bradley authored May 20, 2024
1 parent e09b25f commit 91f13c3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 76 deletions.
25 changes: 25 additions & 0 deletions .chloggen/remove-confmap-instances.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: 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]
48 changes: 10 additions & 38 deletions confmap/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,13 @@ type ResolverSettings struct {
// if a Provider is not given.
ProviderFactories []ProviderFactory

// Providers is a map of pairs <scheme, Provider>.
// 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

// 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
Expand All @@ -83,11 +72,11 @@ type ResolverSettings struct {
// (see https://datatracker.ietf.org/doc/html/rfc3986). An empty "<scheme>" 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 {
Expand All @@ -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.
Expand Down
38 changes: 0 additions & 38 deletions confmap/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 91f13c3

Please sign in to comment.