Skip to content

Commit

Permalink
Draft minimum changes to component.Host
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu committed Nov 17, 2022
1 parent a8d6280 commit efa0d4d
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 60 deletions.
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 {
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
}
11 changes: 3 additions & 8 deletions component/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,21 @@ 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
}

// 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: 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
}
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
12 changes: 6 additions & 6 deletions exporter/exporterhelper/queued_retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func TestGetRetrySettings(t *testing.T) {
t.Run(tC.desc, func(t *testing.T) {
storageID := component.NewIDWithName("file_storage", strconv.Itoa(tC.storageIndex))

var extensions = map[component.ID]component.Extension{}
var extensions = map[component.ID]component.Component{}
for i := 0; i < tC.numStorages; i++ {
extensions[component.NewIDWithName("file_storage", strconv.Itoa(i))] = &mockStorageExtension{GetClientError: tC.getClientError}
}
Expand Down Expand Up @@ -466,7 +466,7 @@ func TestInvalidStorageExtensionType(t *testing.T) {
settings := componenttest.NewNopExtensionCreateSettings()
extension, err := factory.CreateExtension(context.Background(), settings, extConfig)
assert.NoError(t, err)
var extensions = map[component.ID]component.Extension{
var extensions = map[component.ID]component.Component{
storageID: extension,
}
host := &mockHost{ext: extensions}
Expand Down Expand Up @@ -545,7 +545,7 @@ func TestQueuedRetryPersistenceEnabled(t *testing.T) {
be, err := newBaseExporter(&defaultExporterCfg, tt.ToExporterCreateSettings(), fromOptions(WithRetry(rCfg), WithQueue(qCfg)), "", nopRequestUnmarshaler())
require.NoError(t, err)

var extensions = map[component.ID]component.Extension{
var extensions = map[component.ID]component.Component{
storageID: &mockStorageExtension{},
}
host := &mockHost{ext: extensions}
Expand All @@ -568,7 +568,7 @@ func TestQueuedRetryPersistenceEnabledStorageError(t *testing.T) {
be, err := newBaseExporter(&defaultExporterCfg, tt.ToExporterCreateSettings(), fromOptions(WithRetry(rCfg), WithQueue(qCfg)), "", nopRequestUnmarshaler())
require.NoError(t, err)

var extensions = map[component.ID]component.Extension{
var extensions = map[component.ID]component.Component{
storageID: &mockStorageExtension{GetClientError: storageError},
}
host := &mockHost{ext: extensions}
Expand Down Expand Up @@ -746,10 +746,10 @@ func tagsMatchLabelKeys(tags []tag.Tag, keys []metricdata.LabelKey, labels []met

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
4 changes: 2 additions & 2 deletions processor/memorylimiterprocessor/memorylimiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ type host struct {
component.Host
}

func (h *host) GetExtensions() map[component.ID]component.Extension {
ret := make(map[component.ID]component.Extension)
func (h *host) GetExtensions() map[component.ID]component.Component {
ret := make(map[component.ID]component.Component)
ret[component.NewID("ballast")] = &ballastExtension{ballastSize: h.ballastSize}
return ret
}
Expand Down
4 changes: 2 additions & 2 deletions service/extensions/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func (bes *Extensions) NotifyPipelineNotReady() error {
return errs
}

func (bes *Extensions) GetExtensions() map[component.ID]component.Extension {
result := make(map[component.ID]component.Extension, len(bes.extMap))
func (bes *Extensions) GetExtensions() map[component.ID]component.Component {
result := make(map[component.ID]component.Component, len(bes.extMap))
for extID, v := range bes.extMap {
result[extID] = v
}
Expand Down
4 changes: 2 additions & 2 deletions service/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ func (host *serviceHost) GetFactory(kind component.Kind, componentType component
return nil
}

func (host *serviceHost) GetExtensions() map[component.ID]component.Extension {
func (host *serviceHost) GetExtensions() map[component.ID]component.Component {
return host.extensions.GetExtensions()
}

func (host *serviceHost) GetExporters() map[component.DataType]map[component.ID]component.Exporter {
func (host *serviceHost) GetExporters() map[component.DataType]map[component.ID]component.Component {
return host.pipelines.GetExporters()
}
Loading

0 comments on commit efa0d4d

Please sign in to comment.