diff --git a/CHANGELOG.md b/CHANGELOG.md index c475f67fbc0..61054c853c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,10 @@ ### 🛑 Breaking changes 🛑 -- Deprecated methods `config.DefaultConfig`, `confighttp.DefaultHTTPSettings`, `exporterhelper.DefaultTimeoutSettings`, +- Deprecated funcs `config.DefaultConfig`, `confighttp.DefaultHTTPSettings`, `exporterhelper.DefaultTimeoutSettings`, `exporthelper.DefaultQueueSettings`, `exporterhelper.DefaultRetrySettings`, `testcomponents.DefaultFactories`, and `scraperhelper.DefaultScraperControllerSettings` in favour for their `NewDefault` method to adhere to contribution guidelines (#4865) +- Deprecated funcs `componenthelper.StartFunc`, `componenthelper.ShutdownFunc` in favour of `component.StartFunc` and `component.ShutdownFunc` (#4803) ### 💡 Enhancements 💡 diff --git a/component/component.go b/component/component.go index 4678f83f620..5548e1db34a 100644 --- a/component/component.go +++ b/component/component.go @@ -61,6 +61,28 @@ type Component interface { Shutdown(ctx context.Context) error } +// StartFunc specifies the function invoked when the component.Component is being started. +type StartFunc func(context.Context, Host) error + +// Start starts the component. +func (f StartFunc) Start(ctx context.Context, host Host) error { + if f == nil { + return nil + } + return f(ctx, host) +} + +// ShutdownFunc specifies the function invoked when the component.Component is being shutdown. +type ShutdownFunc func(context.Context) error + +// Shutdown shuts down the component. +func (f ShutdownFunc) Shutdown(ctx context.Context) error { + if f == nil { + return nil + } + return f(ctx) +} + // Kind represents component kinds. type Kind int diff --git a/component/componenthelper/component.go b/component/componenthelper/component.go index 6257654badd..f62905edf9d 100644 --- a/component/componenthelper/component.go +++ b/component/componenthelper/component.go @@ -15,39 +15,21 @@ package componenthelper // import "go.opentelemetry.io/collector/component/componenthelper" import ( - "context" - "go.opentelemetry.io/collector/component" ) -// StartFunc specifies the function invoked when the component.Component is being started. -type StartFunc func(context.Context, component.Host) error - -// Start starts the component. -func (f StartFunc) Start(ctx context.Context, host component.Host) error { - if f == nil { - return nil - } - return f(ctx, host) -} +// Deprecated: use component.StartFunc. +type StartFunc = component.StartFunc -// ShutdownFunc specifies the function invoked when the component.Component is being shutdown. -type ShutdownFunc func(context.Context) error - -// Shutdown shuts down the component. -func (f ShutdownFunc) Shutdown(ctx context.Context) error { - if f == nil { - return nil - } - return f(ctx) -} +// Deprecated: use component.ShutdownFunc. +type ShutdownFunc = component.ShutdownFunc // Option represents the possible options for New. type Option func(*baseComponent) // WithStart overrides the default `Start` function for a component.Component. // The default always returns nil. -func WithStart(startFunc StartFunc) Option { +func WithStart(startFunc component.StartFunc) Option { return func(o *baseComponent) { o.StartFunc = startFunc } @@ -55,15 +37,15 @@ func WithStart(startFunc StartFunc) Option { // WithShutdown overrides the default `Shutdown` function for a component.Component. // The default always returns nil. -func WithShutdown(shutdownFunc ShutdownFunc) Option { +func WithShutdown(shutdownFunc component.ShutdownFunc) Option { return func(o *baseComponent) { o.ShutdownFunc = shutdownFunc } } type baseComponent struct { - StartFunc - ShutdownFunc + component.StartFunc + component.ShutdownFunc } // New returns a component.Component configured with the provided options. diff --git a/component/componenttest/nop_component.go b/component/componenttest/nop_component.go index c8310d0bedb..ac56476e768 100644 --- a/component/componenttest/nop_component.go +++ b/component/componenttest/nop_component.go @@ -15,10 +15,10 @@ package componenttest // import "go.opentelemetry.io/collector/component/componenttest" import ( - "go.opentelemetry.io/collector/component/componenthelper" + "go.opentelemetry.io/collector/component" ) type nopComponent struct { - componenthelper.StartFunc - componenthelper.ShutdownFunc + component.StartFunc + component.ShutdownFunc } diff --git a/config/configauth/default_serverauthenticator.go b/config/configauth/default_serverauthenticator.go index c11bd7674a4..d4123388c0e 100644 --- a/config/configauth/default_serverauthenticator.go +++ b/config/configauth/default_serverauthenticator.go @@ -18,7 +18,6 @@ import ( "context" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/component/componenthelper" ) var _ ServerAuthenticator = (*defaultServerAuthenticator)(nil) @@ -28,8 +27,8 @@ type Option func(*defaultServerAuthenticator) type defaultServerAuthenticator struct { AuthenticateFunc - componenthelper.StartFunc - componenthelper.ShutdownFunc + component.StartFunc + component.ShutdownFunc } // WithAuthenticate specifies which function to use to perform the authentication. @@ -41,7 +40,7 @@ func WithAuthenticate(authenticateFunc AuthenticateFunc) Option { // WithStart overrides the default `Start` function for a component.Component. // The default always returns nil. -func WithStart(startFunc componenthelper.StartFunc) Option { +func WithStart(startFunc component.StartFunc) Option { return func(o *defaultServerAuthenticator) { o.StartFunc = startFunc } @@ -49,7 +48,7 @@ func WithStart(startFunc componenthelper.StartFunc) Option { // WithShutdown overrides the default `Shutdown` function for a component.Component. // The default always returns nil. -func WithShutdown(shutdownFunc componenthelper.ShutdownFunc) Option { +func WithShutdown(shutdownFunc component.ShutdownFunc) Option { return func(o *defaultServerAuthenticator) { o.ShutdownFunc = shutdownFunc } diff --git a/exporter/exporterhelper/common.go b/exporter/exporterhelper/common.go index 0bcc992f089..2096bc09090 100644 --- a/exporter/exporterhelper/common.go +++ b/exporter/exporterhelper/common.go @@ -19,7 +19,6 @@ import ( "time" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/component/componenthelper" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumerhelper" @@ -91,8 +90,8 @@ func (req *baseRequest) OnProcessingFinished() { // baseSettings represents all the options that users can configure. type baseSettings struct { - componenthelper.StartFunc - componenthelper.ShutdownFunc + component.StartFunc + component.ShutdownFunc consumerOptions []consumerhelper.Option TimeoutSettings QueueSettings @@ -122,7 +121,7 @@ type Option func(*baseSettings) // WithStart overrides the default Start function for an exporter. // The default start function does nothing and always returns nil. -func WithStart(start componenthelper.StartFunc) Option { +func WithStart(start component.StartFunc) Option { return func(o *baseSettings) { o.StartFunc = start } @@ -130,7 +129,7 @@ func WithStart(start componenthelper.StartFunc) Option { // WithShutdown overrides the default Shutdown function for an exporter. // The default shutdown function does nothing and always returns nil. -func WithShutdown(shutdown componenthelper.ShutdownFunc) Option { +func WithShutdown(shutdown component.ShutdownFunc) Option { return func(o *baseSettings) { o.ShutdownFunc = shutdown } @@ -171,8 +170,8 @@ func WithCapabilities(capabilities consumer.Capabilities) Option { // baseExporter contains common fields between different exporter types. type baseExporter struct { - componenthelper.StartFunc - componenthelper.ShutdownFunc + component.StartFunc + component.ShutdownFunc obsrep *obsExporter sender requestSender qrSender *queuedRetrySender diff --git a/processor/processorhelper/logs.go b/processor/processorhelper/logs.go index 290d0aaa3a1..8d049c1fc97 100644 --- a/processor/processorhelper/logs.go +++ b/processor/processorhelper/logs.go @@ -22,7 +22,6 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenterror" - "go.opentelemetry.io/collector/component/componenthelper" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumerhelper" @@ -34,8 +33,8 @@ import ( type ProcessLogsFunc func(context.Context, pdata.Logs) (pdata.Logs, error) type logProcessor struct { - componenthelper.StartFunc - componenthelper.ShutdownFunc + component.StartFunc + component.ShutdownFunc consumer.Logs } diff --git a/processor/processorhelper/metrics.go b/processor/processorhelper/metrics.go index a275797042a..e7c2d3eacd7 100644 --- a/processor/processorhelper/metrics.go +++ b/processor/processorhelper/metrics.go @@ -22,7 +22,6 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenterror" - "go.opentelemetry.io/collector/component/componenthelper" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumerhelper" @@ -34,8 +33,8 @@ import ( type ProcessMetricsFunc func(context.Context, pdata.Metrics) (pdata.Metrics, error) type metricsProcessor struct { - componenthelper.StartFunc - componenthelper.ShutdownFunc + component.StartFunc + component.ShutdownFunc consumer.Metrics } diff --git a/processor/processorhelper/processor.go b/processor/processorhelper/processor.go index 4dc76a52d37..ad60ef32a67 100644 --- a/processor/processorhelper/processor.go +++ b/processor/processorhelper/processor.go @@ -20,7 +20,7 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" - "go.opentelemetry.io/collector/component/componenthelper" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumerhelper" @@ -37,7 +37,7 @@ type Option func(*baseSettings) // WithStart overrides the default Start function for an processor. // The default shutdown function does nothing and always returns nil. -func WithStart(start componenthelper.StartFunc) Option { +func WithStart(start component.StartFunc) Option { return func(o *baseSettings) { o.StartFunc = start } @@ -45,7 +45,7 @@ func WithStart(start componenthelper.StartFunc) Option { // WithShutdown overrides the default Shutdown function for an processor. // The default shutdown function does nothing and always returns nil. -func WithShutdown(shutdown componenthelper.ShutdownFunc) Option { +func WithShutdown(shutdown component.ShutdownFunc) Option { return func(o *baseSettings) { o.ShutdownFunc = shutdown } @@ -60,8 +60,8 @@ func WithCapabilities(capabilities consumer.Capabilities) Option { } type baseSettings struct { - componenthelper.StartFunc - componenthelper.ShutdownFunc + component.StartFunc + component.ShutdownFunc consumerOptions []consumerhelper.Option } diff --git a/processor/processorhelper/traces.go b/processor/processorhelper/traces.go index 64781516657..e044f1af3ee 100644 --- a/processor/processorhelper/traces.go +++ b/processor/processorhelper/traces.go @@ -22,7 +22,6 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenterror" - "go.opentelemetry.io/collector/component/componenthelper" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumerhelper" @@ -34,8 +33,8 @@ import ( type ProcessTracesFunc func(context.Context, pdata.Traces) (pdata.Traces, error) type tracesProcessor struct { - componenthelper.StartFunc - componenthelper.ShutdownFunc + component.StartFunc + component.ShutdownFunc consumer.Traces } diff --git a/receiver/scraperhelper/scraper.go b/receiver/scraperhelper/scraper.go index 7bdd65e5a7b..2c6c75296c6 100644 --- a/receiver/scraperhelper/scraper.go +++ b/receiver/scraperhelper/scraper.go @@ -19,7 +19,6 @@ import ( "errors" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/component/componenthelper" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/model/pdata" ) @@ -46,14 +45,14 @@ type Scraper interface { type ScraperOption func(*baseScraper) // WithStart sets the function that will be called on startup. -func WithStart(start componenthelper.StartFunc) ScraperOption { +func WithStart(start component.StartFunc) ScraperOption { return func(o *baseScraper) { o.StartFunc = start } } // WithShutdown sets the function that will be called on shutdown. -func WithShutdown(shutdown componenthelper.ShutdownFunc) ScraperOption { +func WithShutdown(shutdown component.ShutdownFunc) ScraperOption { return func(o *baseScraper) { o.ShutdownFunc = shutdown } @@ -62,8 +61,8 @@ func WithShutdown(shutdown componenthelper.ShutdownFunc) ScraperOption { var _ Scraper = (*baseScraper)(nil) type baseScraper struct { - componenthelper.StartFunc - componenthelper.ShutdownFunc + component.StartFunc + component.ShutdownFunc ScrapeFunc id config.ComponentID }