Add the StartFunc/ShutdownFunc to component directly (#4803)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
This commit is contained in:
parent
d5656d6bb2
commit
c4134ba6f3
|
|
@ -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 💡
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
// Deprecated: use component.StartFunc.
|
||||
type StartFunc = component.StartFunc
|
||||
|
||||
// Start starts the component.
|
||||
func (f StartFunc) Start(ctx context.Context, host component.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)
|
||||
}
|
||||
// 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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue