Skip to content

Commit 79c0bf1

Browse files
authored
[receiver/receivercreator] Make receivercreator expose its required interface (#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.
1 parent 8de1e8f commit 79c0bf1

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

receiver/receivercreator/receiver.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,34 @@ func newReceiverCreator(params receiver.Settings, cfg *Config) receiver.Metrics
3434
}
3535
}
3636

37+
// host is an interface that the component.Host passed to receivercreator's Start function must implement
38+
type host interface {
39+
component.Host
40+
GetFactory(component.Kind, component.Type) component.Factory
41+
}
42+
3743
// Start receiver_creator.
38-
func (rc *receiverCreator) Start(_ context.Context, host component.Host) error {
44+
func (rc *receiverCreator) Start(_ context.Context, h component.Host) error {
45+
rcHost, ok := h.(host)
46+
if !ok {
47+
return fmt.Errorf("the receivercreator is not compatible with the provided component.host")
48+
}
49+
3950
rc.observerHandler = &observerHandler{
4051
config: rc.cfg,
4152
params: rc.params,
4253
receiversByEndpointID: receiverMap{},
4354
nextLogsConsumer: rc.nextLogsConsumer,
4455
nextMetricsConsumer: rc.nextMetricsConsumer,
4556
nextTracesConsumer: rc.nextTracesConsumer,
46-
runner: newReceiverRunner(rc.params, host),
57+
runner: newReceiverRunner(rc.params, rcHost),
4758
}
4859

4960
observers := map[component.ID]observer.Observable{}
5061

5162
// Match all configured observables to the extensions that are running.
5263
for _, watchObserver := range rc.cfg.WatchObservers {
53-
for cid, ext := range host.GetExtensions() {
64+
for cid, ext := range rcHost.GetExtensions() {
5465
if cid != watchObserver {
5566
continue
5667
}

receiver/receivercreator/runner.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ type receiverRunner struct {
3131
logger *zap.Logger
3232
params rcvr.Settings
3333
idNamespace component.ID
34-
host component.Host
34+
host host
3535
receivers map[string]*wrappedReceiver
3636
lock *sync.Mutex
3737
}
3838

39-
func newReceiverRunner(params rcvr.Settings, host component.Host) *receiverRunner {
39+
func newReceiverRunner(params rcvr.Settings, host host) *receiverRunner {
4040
return &receiverRunner{
4141
logger: params.Logger,
4242
params: params,

0 commit comments

Comments
 (0)