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] Remove deprecated ResolverSettings fields #10173

Merged
Merged
Show file tree
Hide file tree
Changes from all 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/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)
Copy link
Member

Choose a reason for hiding this comment

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

Separate PR/issue. It would be great to have all public APIs like Create always accept context.Context as the first argument.

}

// 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
Loading