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

[receiver/receivercreator] Make receivercreator expose its required interface #34234

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 12 additions & 1 deletion receiver/receivercreator/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,27 @@ func newReceiverCreator(params receiver.Settings, cfg *Config) receiver.Metrics
}
}

// Host is an interface that the component.Host passed to receivercreator's Start function must implement
type Host interface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it need to be exported?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's good to have the interface so that the component explicitly says what it needs from the component.Host. If it's controversial though, maybe we can make it private for now, enshrine it on some documentation on how to deal with this case, and make it public then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can hide it for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am asking if it can be unexported because in general we are trying to keep the public API of any component down to its config struct if possible.

Do we see any code import this module and use this host interface?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we see any code import this module and use this host interface?

No, it doesn't need to be public at this time.

component.Host
GetFactory(component.Kind, component.Type) component.Factory
}

// Start receiver_creator.
func (rc *receiverCreator) Start(_ context.Context, host component.Host) error {
rcHost, ok := host.(Host)
if !ok {
return fmt.Errorf("the receivercreator is not compatible with the provided component.Host")
}

rc.observerHandler = &observerHandler{
config: rc.cfg,
params: rc.params,
receiversByEndpointID: receiverMap{},
nextLogsConsumer: rc.nextLogsConsumer,
nextMetricsConsumer: rc.nextMetricsConsumer,
nextTracesConsumer: rc.nextTracesConsumer,
runner: newReceiverRunner(rc.params, host),
runner: newReceiverRunner(rc.params, rcHost),
}

observers := map[component.ID]observer.Observable{}
Expand Down
4 changes: 2 additions & 2 deletions receiver/receivercreator/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ type receiverRunner struct {
logger *zap.Logger
params rcvr.Settings
idNamespace component.ID
host component.Host
host Host
receivers map[string]*wrappedReceiver
lock *sync.Mutex
}

func newReceiverRunner(params rcvr.Settings, host component.Host) *receiverRunner {
func newReceiverRunner(params rcvr.Settings, host Host) *receiverRunner {
return &receiverRunner{
logger: params.Logger,
params: params,
Expand Down
Loading