diff --git a/.chloggen/better-effective-config.yaml b/.chloggen/better-effective-config.yaml new file mode 100644 index 00000000000..917f727bd9c --- /dev/null +++ b/.chloggen/better-effective-config.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: Obtain the Collector's effective config from otelcol.Config + +# One or more tracking issues or pull requests related to the change +issues: [10139] + +# (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: "`otelcol.Collector` will now marshal `confmap.Conf` objects from `otelcol.Config` itself." + +# 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/.chloggen/deprecate-confmapprovider.yaml b/.chloggen/deprecate-confmapprovider.yaml new file mode 100644 index 00000000000..b5f2bf1805a --- /dev/null +++ b/.chloggen/deprecate-confmapprovider.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: deprecation + +# 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: Deprecate `otelcol.ConfmapProvider` + +# One or more tracking issues or pull requests related to the change +issues: [10139] + +# (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: "`otelcol.Collector` will now marshal `confmap.Conf` objects from `otelcol.Config` itself." + +# 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/.chloggen/deprecate-getconfmap.yaml b/.chloggen/deprecate-getconfmap.yaml new file mode 100644 index 00000000000..016481095e2 --- /dev/null +++ b/.chloggen/deprecate-getconfmap.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: deprecation + +# 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: Deprecate `(*otelcol.ConfigProvider).GetConfmap` + +# One or more tracking issues or pull requests related to the change +issues: [10139] + +# (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: Call `(*confmap.Conf).Marshal(*otelcol.Config)` to get the Collector's configuration. + +# 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 8f9839af6c8..b1d4705649c 100644 --- a/otelcol/collector.go +++ b/otelcol/collector.go @@ -163,17 +163,6 @@ func (col *Collector) Shutdown() { func (col *Collector) setupConfigurationComponents(ctx context.Context) error { col.setCollectorState(StateStarting) - var conf *confmap.Conf - - if cp, ok := col.configProvider.(ConfmapProvider); ok { - var err error - conf, err = cp.GetConfmap(ctx) - - if err != nil { - return fmt.Errorf("failed to resolve config: %w", err) - } - } - factories, err := col.set.Factories() if err != nil { return fmt.Errorf("failed to initialize factories: %w", err) @@ -189,6 +178,12 @@ func (col *Collector) setupConfigurationComponents(ctx context.Context) error { col.serviceConfig = &cfg.Service + conf := confmap.New() + + if err = conf.Marshal(cfg); err != nil { + return fmt.Errorf("could not marshal configuration: %w", err) + } + col.service, err = service.New(ctx, service.Settings{ BuildInfo: col.set.BuildInfo, CollectorConf: conf, diff --git a/otelcol/collector_test.go b/otelcol/collector_test.go index e1a2356a553..a2dc4083f5f 100644 --- a/otelcol/collector_test.go +++ b/otelcol/collector_test.go @@ -450,24 +450,6 @@ func TestCollectorDryRun(t *testing.T) { } } -func TestPassConfmapToServiceFailure(t *testing.T) { - set := CollectorSettings{ - BuildInfo: component.NewDefaultBuildInfo(), - Factories: nopFactories, - ConfigProviderSettings: ConfigProviderSettings{ - ResolverSettings: confmap.ResolverSettings{ - URIs: []string{filepath.Join("testdata", "otelcol-invalid.yaml")}, - ProviderFactories: []confmap.ProviderFactory{confmap.NewProviderFactory(newFailureProvider)}, - }, - }, - } - col, err := NewCollector(set) - require.NoError(t, err) - - err = col.Run(context.Background()) - require.Error(t, err) -} - func startCollector(ctx context.Context, t *testing.T, col *Collector) *sync.WaitGroup { wg := &sync.WaitGroup{} wg.Add(1) diff --git a/otelcol/configprovider.go b/otelcol/configprovider.go index 4b003a6fa39..344d86fb86a 100644 --- a/otelcol/configprovider.go +++ b/otelcol/configprovider.go @@ -58,6 +58,9 @@ type ConfigProvider interface { // // The purpose of this interface is that otelcol.ConfigProvider structs do not // necessarily need to use confmap.Conf as their underlying config structure. +// +// Deprecated: [v0.105.0] This interface is deprecated. otelcol.Collector will now obtain +// a confmap.Conf object from the unmarshaled config itself. type ConfmapProvider interface { // GetConfmap resolves the Collector's configuration and provides it as a confmap.Conf object. // @@ -70,7 +73,6 @@ type configProvider struct { } var _ ConfigProvider = (*configProvider)(nil) -var _ ConfmapProvider = (*configProvider)(nil) // ConfigProviderSettings are the settings to configure the behavior of the ConfigProvider. type ConfigProviderSettings struct { @@ -143,8 +145,11 @@ func (cm *configProvider) Shutdown(ctx context.Context) error { return cm.mapResolver.Shutdown(ctx) } +// Deprecated: [v0.105.0] Call `(*confmap.Conf).Marshal(*otelcol.Config)` to get +// the Collector's configuration instead. func (cm *configProvider) GetConfmap(ctx context.Context) (*confmap.Conf, error) { conf, err := cm.mapResolver.Resolve(ctx) + if err != nil { return nil, fmt.Errorf("cannot resolve the configuration: %w", err) }