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

Deprecate duplicate settings in service.ConfigProvider, embed ResolverSettings #5843

Merged
merged 2 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

### 🚩 Deprecations 🚩

- Deprecate duplicate settings in service.ConfigProvider, embed ResolverSettings (#5843)
- Deprecate `featuregate.Registry.MustApply` in favor of `featuregate.Registry.Apply`.
- Deprecate the `component.Factory.StabilityLevel(config.DataType)` in favor of Stability per component (#5762):
- `component.ExporterFactory.TracesExporterStability`
Expand Down
4 changes: 2 additions & 2 deletions service/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,9 @@ func testCollectorStartHelper(t *testing.T, telemetry *telemetryInitializer, tc
}

cfgSet := newDefaultConfigProviderSettings([]string{filepath.Join("testdata", "otelcol-nop.yaml")})
cfgSet.MapConverters = append([]confmap.Converter{
cfgSet.ResolverSettings.Converters = append([]confmap.Converter{
mapConverter{extraCfgAsProps}},
cfgSet.MapConverters...,
cfgSet.ResolverSettings.Converters...,
)
cfgProvider, err := NewConfigProvider(cfgSet)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions service/collector_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ func newWithWindowsEventLogCore(set CollectorSettings, flags *flag.FlagSet, elog
var err error
cfgSet := newDefaultConfigProviderSettings(getConfigFlag(flags))
// Append the "overwrite properties converter" as the first converter.
cfgSet.MapConverters = append(
cfgSet.ResolverSettings.Converters = append(
[]confmap.Converter{overwritepropertiesconverter.New(getSetFlag(flags))},
cfgSet.MapConverters...)
cfgSet.ResolverSettings.Converters...)
set.ConfigProvider, err = NewConfigProvider(cfgSet)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions service/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func NewCommand(set CollectorSettings) *cobra.Command {
var err error
cfgSet := newDefaultConfigProviderSettings(getConfigFlag(flagSet))
// Append the "overwrite properties converter" as the first converter.
cfgSet.MapConverters = append(
cfgSet.ResolverSettings.Converters = append(
[]confmap.Converter{overwritepropertiesconverter.New(getSetFlag(flagSet))},
cfgSet.MapConverters...)
cfgSet.ResolverSettings.Converters...)
set.ConfigProvider, err = NewConfigProvider(cfgSet)
if err != nil {
return err
Expand Down
33 changes: 22 additions & 11 deletions service/config_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,27 @@ type configProvider struct {
}

// ConfigProviderSettings are the settings to configure the behavior of the ConfigProvider.
// TODO: embed confmap.ResolverSettings into this to avoid duplicates.
type ConfigProviderSettings struct {
// Locations from where the confmap.Conf is retrieved, and merged in the given order.
// It is required to have at least one location.
// ResolverSettings are the settings to configure the behavior of the confmap.Resolver.
ResolverSettings confmap.ResolverSettings

// Deprecated: [v0.58.0] use ConfigProviderSettings.ResolverSettings.URIs
Locations []string

// MapProviders is a map of pairs <scheme, confmap.Provider>.
// It is required to have at least one confmap.Provider.
// Deprecated: [v0.58.0] use ConfigProviderSettings.ResolverSettings.Providers
MapProviders map[string]confmap.Provider

// MapConverters is a slice of confmap.Converter.
// Deprecated: [v0.58.0] use ConfigProviderSettings.ResolverSettings.Converter
MapConverters []confmap.Converter
}

func newDefaultConfigProviderSettings(locations []string) ConfigProviderSettings {
func newDefaultConfigProviderSettings(uris []string) ConfigProviderSettings {
return ConfigProviderSettings{
Locations: locations,
MapProviders: makeMapProvidersMap(fileprovider.New(), envprovider.New(), yamlprovider.New()),
MapConverters: []confmap.Converter{expandconverter.New()},
ResolverSettings: confmap.ResolverSettings{
URIs: uris,
Providers: makeMapProvidersMap(fileprovider.New(), envprovider.New(), yamlprovider.New()),
Converters: []confmap.Converter{expandconverter.New()},
},
}
}

Expand All @@ -95,7 +97,16 @@ func newDefaultConfigProviderSettings(locations []string) ConfigProviderSettings
//
// * Then unmarshalls the confmap.Conf into the service Config.
func NewConfigProvider(set ConfigProviderSettings) (ConfigProvider, error) {
mr, err := confmap.NewResolver(confmap.ResolverSettings{URIs: set.Locations, Providers: set.MapProviders, Converters: set.MapConverters})
if len(set.Locations) != 0 {
set.ResolverSettings.URIs = set.Locations
}
if len(set.MapProviders) != 0 {
set.ResolverSettings.Providers = set.MapProviders
}
if len(set.MapConverters) != 0 {
set.ResolverSettings.Converters = set.MapConverters
}
mr, err := confmap.NewResolver(set.ResolverSettings)
if err != nil {
return nil, err
}
Expand Down