From b6510d086dac849920eaccd43db5573883712bca Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Fri, 31 May 2024 14:32:22 -0600 Subject: [PATCH] [otelcol] Removed deprecated `ConfigProvider` field from settings (#10281) --- .chloggen/otelcol-remove-deprecations.yaml | 25 +++++++++++++++++++ otelcol/collector.go | 16 +++---------- otelcol/collector_test.go | 23 ++++++++---------- otelcol/command.go | 28 ++++++++++------------ otelcol/command_components_test.go | 9 +++---- 5 files changed, 54 insertions(+), 47 deletions(-) create mode 100644 .chloggen/otelcol-remove-deprecations.yaml diff --git a/.chloggen/otelcol-remove-deprecations.yaml b/.chloggen/otelcol-remove-deprecations.yaml new file mode 100644 index 00000000000..75dbd5313f9 --- /dev/null +++ b/.chloggen/otelcol-remove-deprecations.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: otelcol + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Remove deprecated `ConfigProvider` field from `CollectorSettings` + +# One or more tracking issues or pull requests related to the change +issues: [10281] + +# (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/otelcol/collector.go b/otelcol/collector.go index 64339a4040d..8f9839af6c8 100644 --- a/otelcol/collector.go +++ b/otelcol/collector.go @@ -68,11 +68,6 @@ type CollectorSettings struct { // and manually handle the signals to shutdown the collector. DisableGracefulShutdown bool - // Deprecated: [v0.95.0] Use ConfigProviderSettings instead. - // ConfigProvider provides the service configuration. - // If the provider watches for configuration change, collector may reload the new configuration upon changes. - ConfigProvider ConfigProvider - // ConfigProviderSettings allows configuring the way the Collector retrieves its configuration // The Collector will reload based on configuration changes from the ConfigProvider if any // confmap.Providers watch for configuration changes. @@ -118,9 +113,6 @@ type Collector struct { // NewCollector creates and returns a new instance of Collector. func NewCollector(set CollectorSettings) (*Collector, error) { - var err error - configProvider := set.ConfigProvider - bc := newBufferedCore(zapcore.DebugLevel) cc := &collectorCore{core: bc} options := append([]zap.Option{zap.WithCaller(true)}, set.LoggingOptions...) @@ -128,11 +120,9 @@ func NewCollector(set CollectorSettings) (*Collector, error) { set.ConfigProviderSettings.ResolverSettings.ProviderSettings = confmap.ProviderSettings{Logger: logger} set.ConfigProviderSettings.ResolverSettings.ConverterSettings = confmap.ConverterSettings{Logger: logger} - if configProvider == nil { - configProvider, err = NewConfigProvider(set.ConfigProviderSettings) - if err != nil { - return nil, err - } + configProvider, err := NewConfigProvider(set.ConfigProviderSettings) + if err != nil { + return nil, err } state := &atomic.Int32{} diff --git a/otelcol/collector_test.go b/otelcol/collector_test.go index b96a6fc15db..68eb3b54318 100644 --- a/otelcol/collector_test.go +++ b/otelcol/collector_test.go @@ -82,16 +82,17 @@ func (p mockCfgProvider) Watch() <-chan error { } func TestCollectorStateAfterConfigChange(t *testing.T) { - provider, err := NewConfigProvider(newDefaultConfigProviderSettings([]string{filepath.Join("testdata", "otelcol-nop.yaml")})) - require.NoError(t, err) - watcher := make(chan error, 1) col, err := NewCollector(CollectorSettings{ - BuildInfo: component.NewDefaultBuildInfo(), - Factories: nopFactories, - ConfigProvider: &mockCfgProvider{ConfigProvider: provider, watcher: watcher}, + BuildInfo: component.NewDefaultBuildInfo(), + Factories: nopFactories, + // this will be overwritten, but we need something to get past validation + ConfigProviderSettings: newDefaultConfigProviderSettings([]string{filepath.Join("testdata", "otelcol-nop.yaml")}), }) require.NoError(t, err) + provider, err := NewConfigProvider(newDefaultConfigProviderSettings([]string{filepath.Join("testdata", "otelcol-nop.yaml")})) + require.NoError(t, err) + col.configProvider = &mockCfgProvider{ConfigProvider: provider, watcher: watcher} wg := startCollector(context.Background(), t, col) @@ -157,15 +158,11 @@ func TestComponentStatusWatcher(t *testing.T) { factory := extensiontest.NewStatusWatcherExtensionFactory(onStatusChanged) factories.Extensions[factory.Type()] = factory - // Read config from file. This config uses 3 "unhealthy" processors. - validProvider, err := NewConfigProvider(newDefaultConfigProviderSettings([]string{filepath.Join("testdata", "otelcol-statuswatcher.yaml")})) - require.NoError(t, err) - // Create a collector col, err := NewCollector(CollectorSettings{ - BuildInfo: component.NewDefaultBuildInfo(), - Factories: func() (Factories, error) { return factories, nil }, - ConfigProvider: validProvider, + BuildInfo: component.NewDefaultBuildInfo(), + Factories: func() (Factories, error) { return factories, nil }, + ConfigProviderSettings: newDefaultConfigProviderSettings([]string{filepath.Join("testdata", "otelcol-statuswatcher.yaml")}), }) require.NoError(t, err) diff --git a/otelcol/command.go b/otelcol/command.go index 9db850bcc13..648b3a5ffda 100644 --- a/otelcol/command.go +++ b/otelcol/command.go @@ -43,22 +43,20 @@ func NewCommand(set CollectorSettings) *cobra.Command { // Puts command line flags from flags into the CollectorSettings, to be used during config resolution. func updateSettingsUsingFlags(set *CollectorSettings, flags *flag.FlagSet) error { - if set.ConfigProvider == nil { - resolverSet := &set.ConfigProviderSettings.ResolverSettings - configFlags := getConfigFlag(flags) + resolverSet := &set.ConfigProviderSettings.ResolverSettings + configFlags := getConfigFlag(flags) - if len(configFlags) > 0 { - resolverSet.URIs = configFlags - } - if len(resolverSet.URIs) == 0 { - return errors.New("at least one config flag must be provided") - } - // Provide a default set of providers and converters if none have been specified. - // TODO: Remove this after CollectorSettings.ConfigProvider is removed and instead - // do it in the builder. - if len(resolverSet.ProviderFactories) == 0 && len(resolverSet.ConverterFactories) == 0 { - set.ConfigProviderSettings = newDefaultConfigProviderSettings(resolverSet.URIs) - } + if len(configFlags) > 0 { + resolverSet.URIs = configFlags + } + if len(resolverSet.URIs) == 0 { + return errors.New("at least one config flag must be provided") + } + // Provide a default set of providers and converters if none have been specified. + // TODO: Remove this after CollectorSettings.ConfigProvider is removed and instead + // do it in the builder. + if len(resolverSet.ProviderFactories) == 0 && len(resolverSet.ConverterFactories) == 0 { + set.ConfigProviderSettings = newDefaultConfigProviderSettings(resolverSet.URIs) } return nil } diff --git a/otelcol/command_components_test.go b/otelcol/command_components_test.go index c4e3c7fbf29..d144d1dc32a 100644 --- a/otelcol/command_components_test.go +++ b/otelcol/command_components_test.go @@ -17,13 +17,10 @@ import ( ) func TestNewBuildSubCommand(t *testing.T) { - cfgProvider, err := NewConfigProvider(newDefaultConfigProviderSettings([]string{filepath.Join("testdata", "otelcol-nop.yaml")})) - require.NoError(t, err) - set := CollectorSettings{ - BuildInfo: component.NewDefaultBuildInfo(), - Factories: nopFactories, - ConfigProvider: cfgProvider, + BuildInfo: component.NewDefaultBuildInfo(), + Factories: nopFactories, + ConfigProviderSettings: newDefaultConfigProviderSettings([]string{filepath.Join("testdata", "otelcol-nop.yaml")}), } cmd := NewCommand(set) cmd.SetArgs([]string{"components"})