Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimum changes to component.Host, to allow split of the component package #6553

Merged
merged 2 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .chloggen/deprecatecomp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 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: component

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Deprecate `component.Receiver`, `component.Processor`, and `component.Exporter`.

# One or more tracking issues or pull requests related to the change
issues: [6553]
11 changes: 11 additions & 0 deletions .chloggen/draftminhost.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: component

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "`component.Extension` is temporarily set to be an alias of `component.Component` which will be reverted once it's moved to the `extension` package. Change your `component.Host.GetExtensions()` implementation to return `map[ID]component.Component` instead of `map[ID]component.Extension`"

# One or more tracking issues or pull requests related to the change
issues: [6553]
4 changes: 2 additions & 2 deletions component/componenttest/nop_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ func (nh *nopHost) GetFactory(_ component.Kind, _ component.Type) component.Fact
return nil
}

func (nh *nopHost) GetExtensions() map[component.ID]component.Extension {
func (nh *nopHost) GetExtensions() map[component.ID]component.Component {
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved
return nil
}

func (nh *nopHost) GetExporters() map[component.DataType]map[component.ID]component.Exporter {
func (nh *nopHost) GetExporters() map[component.DataType]map[component.ID]component.Component {
return nil
}
12 changes: 5 additions & 7 deletions component/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,24 @@ func UnmarshalExporterConfig(conf *confmap.Conf, cfg ExporterConfig) error {
return unmarshal(conf, cfg)
}

// Exporter exports telemetry data from the collector to a destination.
type Exporter interface {
Component
}
// Deprecated: [v0.65.0] unnecessary interface, will be removed.
type Exporter = Component

// TracesExporter is an Exporter that can consume traces.
type TracesExporter interface {
Exporter
Component
consumer.Traces
}

// MetricsExporter is an Exporter that can consume metrics.
type MetricsExporter interface {
Exporter
Component
consumer.Metrics
}

// LogsExporter is an Exporter that can consume logs.
type LogsExporter interface {
Exporter
Component
consumer.Logs
}

Expand Down
4 changes: 1 addition & 3 deletions component/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ func UnmarshalExtensionConfig(conf *confmap.Conf, cfg ExtensionConfig) error {
// Extension is the interface for objects hosted by the OpenTelemetry Collector that
// don't participate directly on data pipelines but provide some functionality
// to the service, examples: health check endpoint, z-pages, etc.
type Extension interface {
Component
}
type Extension = Component
dmitryax marked this conversation as resolved.
Show resolved Hide resolved

// PipelineWatcher is an extra interface for Extension hosted by the OpenTelemetry
// Collector that is to be implemented by extensions interested in changes to pipeline
Expand Down
4 changes: 2 additions & 2 deletions component/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Host interface {
//
// GetExtensions can be called by the component anytime after Component.Start() begins and
// until Component.Shutdown() ends.
GetExtensions() map[ID]Extension
GetExtensions() map[ID]Component

// GetExporters returns the map of exporters. Only enabled and created exporters will be returned.
// Typically is used to find exporters by type or by full config name. Both cases
Expand All @@ -58,5 +58,5 @@ type Host interface {
//
// GetExporters can be called by the component anytime after Component.Start() begins and
// until Component.Shutdown() ends.
GetExporters() map[DataType]map[ID]Exporter
GetExporters() map[DataType]map[ID]Component
}
13 changes: 5 additions & 8 deletions component/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,24 @@ func UnmarshalProcessorConfig(conf *confmap.Conf, cfg ProcessorConfig) error {
return unmarshal(conf, cfg)
}

// Processor defines the common functions that must be implemented by TracesProcessor
// and MetricsProcessor.
type Processor interface {
Component
}
// Deprecated: [v0.65.0] unnecessary interface, will be removed.
type Processor = Component

// TracesProcessor is a processor that can consume traces.
type TracesProcessor interface {
Processor
Component
consumer.Traces
}

// MetricsProcessor is a processor that can consume metrics.
type MetricsProcessor interface {
Processor
Component
consumer.Metrics
}

// LogsProcessor is a processor that can consume logs.
type LogsProcessor interface {
Processor
Component
consumer.Logs
}

Expand Down
11 changes: 5 additions & 6 deletions component/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,16 @@ func UnmarshalReceiverConfig(conf *confmap.Conf, cfg ReceiverConfig) error {
//
// This ensures there are strong delivery guarantees once the data is acknowledged
// by the Collector.
type Receiver interface {
Component
}
// Deprecated: [v0.65.0] unnecessary interface, will be removed.
type Receiver = Component

// A TracesReceiver receives traces.
// Its purpose is to translate data from any format to the collector's internal trace format.
// TracesReceiver feeds a consumer.Traces with data.
//
// For example it could be Zipkin data source which translates Zipkin spans into ptrace.Traces.
type TracesReceiver interface {
Receiver
Component
}

// A MetricsReceiver receives metrics.
Expand All @@ -91,7 +90,7 @@ type TracesReceiver interface {
//
// For example it could be Prometheus data source which translates Prometheus metrics into pmetric.Metrics.
type MetricsReceiver interface {
Receiver
Component
}

// A LogsReceiver receives logs.
Expand All @@ -100,7 +99,7 @@ type MetricsReceiver interface {
//
// For example a LogsReceiver can read syslogs and convert them into plog.Logs.
type LogsReceiver interface {
Receiver
Component
}

// ReceiverCreateSettings configures Receiver creators.
Expand Down
4 changes: 2 additions & 2 deletions config/configauth/configauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Authentication struct {

// GetServerAuthenticator attempts to select the appropriate ServerAuthenticator from the list of extensions,
// based on the requested extension name. If an authenticator is not found, an error is returned.
func (a Authentication) GetServerAuthenticator(extensions map[component.ID]component.Extension) (ServerAuthenticator, error) {
func (a Authentication) GetServerAuthenticator(extensions map[component.ID]component.Component) (ServerAuthenticator, error) {
if ext, found := extensions[a.AuthenticatorID]; found {
if auth, ok := ext.(ServerAuthenticator); ok {
return auth, nil
Expand All @@ -49,7 +49,7 @@ func (a Authentication) GetServerAuthenticator(extensions map[component.ID]compo
// GetClientAuthenticator attempts to select the appropriate ClientAuthenticator from the list of extensions,
// based on the component id of the extension. If an authenticator is not found, an error is returned.
// This should be only used by HTTP clients.
func (a Authentication) GetClientAuthenticator(extensions map[component.ID]component.Extension) (ClientAuthenticator, error) {
func (a Authentication) GetClientAuthenticator(extensions map[component.ID]component.Component) (ClientAuthenticator, error) {
if ext, found := extensions[a.AuthenticatorID]; found {
if auth, ok := ext.(ClientAuthenticator); ok {
return auth, nil
Expand Down
8 changes: 4 additions & 4 deletions config/configauth/configauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestGetServerAuthenticator(t *testing.T) {
cfg := &Authentication{
AuthenticatorID: component.NewID("mock"),
}
ext := map[component.ID]component.Extension{
ext := map[component.ID]component.Component{
component.NewID("mock"): tC.authenticator,
}

Expand All @@ -68,7 +68,7 @@ func TestGetServerAuthenticatorFails(t *testing.T) {
AuthenticatorID: component.NewID("does-not-exist"),
}

authenticator, err := cfg.GetServerAuthenticator(map[component.ID]component.Extension{})
authenticator, err := cfg.GetServerAuthenticator(map[component.ID]component.Component{})
assert.ErrorIs(t, err, errAuthenticatorNotFound)
assert.Nil(t, authenticator)
}
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestGetClientAuthenticator(t *testing.T) {
cfg := &Authentication{
AuthenticatorID: component.NewID("mock"),
}
ext := map[component.ID]component.Extension{
ext := map[component.ID]component.Component{
component.NewID("mock"): tC.authenticator,
}

Expand All @@ -118,7 +118,7 @@ func TestGetClientAuthenticatorFails(t *testing.T) {
cfg := &Authentication{
AuthenticatorID: component.NewID("does-not-exist"),
}
authenticator, err := cfg.GetClientAuthenticator(map[component.ID]component.Extension{})
authenticator, err := cfg.GetClientAuthenticator(map[component.ID]component.Component{})
assert.ErrorIs(t, err, errAuthenticatorNotFound)
assert.Nil(t, authenticator)
}
14 changes: 7 additions & 7 deletions config/configgrpc/configgrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestAllGrpcClientSettings(t *testing.T) {
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("testauth")},
},
host: &mockHost{
ext: map[component.ID]component.Extension{
ext: map[component.ID]component.Component{
component.NewID("testauth"): &configauth.MockClientAuthenticator{},
},
},
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestAllGrpcClientSettings(t *testing.T) {
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("testauth")},
},
host: &mockHost{
ext: map[component.ID]component.Extension{
ext: map[component.ID]component.Component{
component.NewID("testauth"): &configauth.MockClientAuthenticator{},
},
},
Expand Down Expand Up @@ -147,7 +147,7 @@ func TestAllGrpcClientSettings(t *testing.T) {
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("testauth")},
},
host: &mockHost{
ext: map[component.ID]component.Extension{
ext: map[component.ID]component.Component{
component.NewID("testauth"): &configauth.MockClientAuthenticator{},
},
},
Expand Down Expand Up @@ -216,7 +216,7 @@ func TestGrpcServerAuthSettings(t *testing.T) {
AuthenticatorID: component.NewID("mock"),
}
host := &mockHost{
ext: map[component.ID]component.Extension{
ext: map[component.ID]component.Component{
component.NewID("mock"): configauth.NewServerAuthenticator(),
},
}
Expand Down Expand Up @@ -295,7 +295,7 @@ func TestGRPCClientSettingsError(t *testing.T) {
Endpoint: "localhost:1234",
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("doesntexist")},
},
host: &mockHost{ext: map[component.ID]component.Extension{}},
host: &mockHost{ext: map[component.ID]component.Component{}},
},
{
err: "no extensions configuration available",
Expand Down Expand Up @@ -1075,9 +1075,9 @@ func tempSocketName(t *testing.T) string {

type mockHost struct {
component.Host
ext map[component.ID]component.Extension
ext map[component.ID]component.Component
}

func (nh *mockHost) GetExtensions() map[component.ID]component.Extension {
func (nh *mockHost) GetExtensions() map[component.ID]component.Component {
return nh.ext
}
24 changes: 12 additions & 12 deletions config/confighttp/confighttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (c *customRoundTripper) RoundTrip(request *http.Request) (*http.Response, e

func TestAllHTTPClientSettings(t *testing.T) {
host := &mockHost{
ext: map[component.ID]component.Extension{
ext: map[component.ID]component.Component{
component.NewID("testauth"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}},
},
}
Expand Down Expand Up @@ -160,7 +160,7 @@ func TestAllHTTPClientSettings(t *testing.T) {

func TestPartialHTTPClientSettings(t *testing.T) {
host := &mockHost{
ext: map[component.ID]component.Extension{
ext: map[component.ID]component.Component{
component.NewID("testauth"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}},
},
}
Expand Down Expand Up @@ -211,7 +211,7 @@ func TestDefaultHTTPClientSettings(t *testing.T) {

func TestHTTPClientSettingsError(t *testing.T) {
host := &mockHost{
ext: map[component.ID]component.Extension{},
ext: map[component.ID]component.Component{},
}
tests := []struct {
settings HTTPClientSettings
Expand Down Expand Up @@ -274,7 +274,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
},
shouldErr: false,
host: &mockHost{
ext: map[component.ID]component.Extension{
ext: map[component.ID]component.Component{
component.NewID("mock"): &configauth.MockClientAuthenticator{
ResultRoundTripper: &customRoundTripper{},
},
Expand All @@ -289,7 +289,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
},
shouldErr: true,
host: &mockHost{
ext: map[component.ID]component.Extension{
ext: map[component.ID]component.Component{
component.NewID("mock"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}},
},
},
Expand All @@ -311,7 +311,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
},
shouldErr: false,
host: &mockHost{
ext: map[component.ID]component.Extension{
ext: map[component.ID]component.Component{
component.NewID("mock"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}},
},
},
Expand All @@ -324,7 +324,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
},
shouldErr: true,
host: &mockHost{
ext: map[component.ID]component.Extension{
ext: map[component.ID]component.Component{
component.NewID("mock"): &configauth.MockClientAuthenticator{
ResultRoundTripper: &customRoundTripper{}, MustError: true},
},
Expand Down Expand Up @@ -737,7 +737,7 @@ func TestHttpCorsWithAuthentication(t *testing.T) {
}

host := &mockHost{
ext: map[component.ID]component.Extension{
ext: map[component.ID]component.Component{
component.NewID("mock"): configauth.NewServerAuthenticator(
configauth.WithAuthenticate(func(ctx context.Context, headers map[string][]string) (context.Context, error) {
return ctx, errors.New("authentication failed")
Expand Down Expand Up @@ -932,7 +932,7 @@ func TestServerAuth(t *testing.T) {
}

host := &mockHost{
ext: map[component.ID]component.Extension{
ext: map[component.ID]component.Component{
component.NewID("mock"): configauth.NewServerAuthenticator(
configauth.WithAuthenticate(func(ctx context.Context, headers map[string][]string) (context.Context, error) {
authCalled = true
Expand Down Expand Up @@ -979,7 +979,7 @@ func TestFailedServerAuth(t *testing.T) {
},
}
host := &mockHost{
ext: map[component.ID]component.Extension{
ext: map[component.ID]component.Component{
component.NewID("mock"): configauth.NewServerAuthenticator(
configauth.WithAuthenticate(func(ctx context.Context, headers map[string][]string) (context.Context, error) {
return ctx, errors.New("authentication failed")
Expand All @@ -1002,10 +1002,10 @@ func TestFailedServerAuth(t *testing.T) {

type mockHost struct {
component.Host
ext map[component.ID]component.Extension
ext map[component.ID]component.Component
}

func (nh *mockHost) GetExtensions() map[component.ID]component.Extension {
func (nh *mockHost) GetExtensions() map[component.ID]component.Component {
return nh.ext
}

Expand Down
2 changes: 1 addition & 1 deletion exporter/exporterhelper/queued_retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func newQueuedRetrySender(id component.ID, signal component.DataType, qCfg Queue
return qrs
}

func getStorageExtension(extensions map[component.ID]component.Extension, storageID component.ID) (storage.Extension, error) {
func getStorageExtension(extensions map[component.ID]component.Component, storageID component.ID) (storage.Extension, error) {
if ext, found := extensions[storageID]; found {
if storageExt, ok := ext.(storage.Extension); ok {
return storageExt, nil
Expand Down
Loading