Skip to content

Commit

Permalink
[receiver/receivercreator] Make receivercreator expose its required i…
Browse files Browse the repository at this point in the history
…nterface (#34234)

**Description:**
Updates receivercreator in preparation for `component.Host.GetFactory`
to be removed.

**Link to tracking Issue:** <Issue number if applicable>
Related to
open-telemetry/opentelemetry-collector#9511

**Testing:** <Describe what testing was performed and which tests were
added.>
Unit tests.

I cant add a unit test yet that fails the interface check since being
compliant with `component.Host` still requires the `GetFactory` method.
  • Loading branch information
TylerHelmuth authored Jul 26, 2024
1 parent 8de1e8f commit 79c0bf1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
17 changes: 14 additions & 3 deletions receiver/receivercreator/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,34 @@ 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 {
component.Host
GetFactory(component.Kind, component.Type) component.Factory
}

// Start receiver_creator.
func (rc *receiverCreator) Start(_ context.Context, host component.Host) error {
func (rc *receiverCreator) Start(_ context.Context, h component.Host) error {
rcHost, ok := h.(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{}

// Match all configured observables to the extensions that are running.
for _, watchObserver := range rc.cfg.WatchObservers {
for cid, ext := range host.GetExtensions() {
for cid, ext := range rcHost.GetExtensions() {
if cid != watchObserver {
continue
}
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

0 comments on commit 79c0bf1

Please sign in to comment.