Skip to content

Commit

Permalink
Deprecate last funcs/structs in componenthelper (#5069)
Browse files Browse the repository at this point in the history
Fixes #4681

These funcs/structs are not used, and in case we need them in multiple places we can add them to `component` directly.

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu committed Mar 25, 2022
1 parent a13c2dd commit 6f4057b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- Deprecate `pdata.AttributeValueTypeArray` type in favor of `pdata.ValueTypeSlice`
- Deprecate `pdata.NewAttributeValueArray` func in favor of `pdata.NewValueSlice`
- Deprecate global flag in `featuregates` (#5060)
- Deprecate last funcs/structs in componenthelper (#5069)
- Change structs in otlpgrpc to follow standard go encoding interfaces (#5062)
- Deprecate UnmarshalJSON[Traces|Metrics|Logs][Reques|Response] in favor of `UnmarshalJSON`.
- Deprecate [Traces|Metrics|Logs][Reques|Response].Marshal in favor of `MarshalProto`.
Expand Down
10 changes: 4 additions & 6 deletions component/componenthelper/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,17 @@ import (
"go.opentelemetry.io/collector/component"
)

// Option represents the possible options for New.
// Deprecated: [v0.48.0] will be removed.
type Option func(*baseComponent)

// WithStart overrides the default `Start` function for a component.Component.
// The default always returns nil.
// Deprecated: [v0.48.0] embed component.StartFunc directly.
func WithStart(startFunc component.StartFunc) Option {
return func(o *baseComponent) {
o.StartFunc = startFunc
}
}

// WithShutdown overrides the default `Shutdown` function for a component.Component.
// The default always returns nil.
// Deprecated: [v0.48.0] embed component.ShutdownFunc directly.
func WithShutdown(shutdownFunc component.ShutdownFunc) Option {
return func(o *baseComponent) {
o.ShutdownFunc = shutdownFunc
Expand All @@ -42,7 +40,7 @@ type baseComponent struct {
component.ShutdownFunc
}

// New returns a component.Component configured with the provided options.
// Deprecated: [v0.48.0] embed component.StartFunc and component.ShutdownFunc directly.
func New(options ...Option) component.Component {
bc := &baseComponent{}

Expand Down
17 changes: 11 additions & 6 deletions internal/sharedcomponent/sharedcomponent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,24 @@ import (
"github.com/stretchr/testify/assert"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenthelper"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config"
)

var id = config.NewComponentID("test")

type baseComponent struct {
component.StartFunc
component.ShutdownFunc
}

func TestNewSharedComponents(t *testing.T) {
comps := NewSharedComponents()
assert.Len(t, comps.comps, 0)
}

func TestSharedComponents_GetOrAdd(t *testing.T) {
nop := componenthelper.New()
nop := &baseComponent{}
createNop := func() component.Component { return nop }

comps := NewSharedComponents()
Expand All @@ -54,14 +58,15 @@ func TestSharedComponent(t *testing.T) {
wantErr := errors.New("my error")
calledStart := 0
calledStop := 0
comp := componenthelper.New(
componenthelper.WithStart(func(ctx context.Context, host component.Host) error {
comp := &baseComponent{
StartFunc: func(ctx context.Context, host component.Host) error {
calledStart++
return wantErr
}), componenthelper.WithShutdown(func(ctx context.Context) error {
},
ShutdownFunc: func(ctx context.Context) error {
calledStop++
return wantErr
}))
}}
createComp := func() component.Component { return comp }

comps := NewSharedComponents()
Expand Down
18 changes: 11 additions & 7 deletions internal/testcomponents/example_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"context"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenthelper"
"go.opentelemetry.io/collector/config"
)

Expand All @@ -33,8 +32,18 @@ type ExampleExtensionCfg struct {

const extType = "exampleextension"

type extension struct {
component.StartFunc
component.ShutdownFunc
}

// ExampleExtensionFactory is factory for ExampleExtensionCfg.
var ExampleExtensionFactory = component.NewExtensionFactory(extType, createExtensionDefaultConfig, createExtension)
var ExampleExtensionFactory = component.NewExtensionFactory(
extType,
createExtensionDefaultConfig,
func(context.Context, component.ExtensionCreateSettings, config.Extension) (component.Extension, error) {
return &extension{}, nil
})

// CreateDefaultConfig creates the default configuration for the Extension.
func createExtensionDefaultConfig() config.Extension {
Expand All @@ -45,8 +54,3 @@ func createExtensionDefaultConfig() config.Extension {
ExtraListSetting: nil,
}
}

// CreateExtension creates an Extension based on this config.
func createExtension(context.Context, component.ExtensionCreateSettings, config.Extension) (component.Extension, error) {
return componenthelper.New(), nil
}

0 comments on commit 6f4057b

Please sign in to comment.