@@ -22,7 +22,7 @@ import (
22
22
"go.opentelemetry.io/collector/component"
23
23
"go.opentelemetry.io/collector/component/componentstatus"
24
24
"go.opentelemetry.io/collector/confmap"
25
- "go.opentelemetry.io/collector/extension/extensiontest "
25
+ "go.opentelemetry.io/collector/extension"
26
26
"go.opentelemetry.io/collector/processor/processortest"
27
27
)
28
28
@@ -136,6 +136,33 @@ func TestCollectorReportError(t *testing.T) {
136
136
assert .Equal (t , StateClosed , col .GetState ())
137
137
}
138
138
139
+ // NewStatusWatcherExtensionFactory returns a component.ExtensionFactory to construct a status watcher extension.
140
+ func NewStatusWatcherExtensionFactory (
141
+ onStatusChanged func (source * componentstatus.InstanceID , event * componentstatus.Event ),
142
+ ) extension.Factory {
143
+ return extension .NewFactory (
144
+ component .MustNewType ("statuswatcher" ),
145
+ func () component.Config {
146
+ return & struct {}{}
147
+ },
148
+ func (context.Context , extension.Settings , component.Config ) (component.Component , error ) {
149
+ return & statusWatcherExtension {onStatusChanged : onStatusChanged }, nil
150
+ },
151
+ component .StabilityLevelStable )
152
+ }
153
+
154
+ // statusWatcherExtension receives status events reported via component status reporting for testing
155
+ // purposes.
156
+ type statusWatcherExtension struct {
157
+ component.StartFunc
158
+ component.ShutdownFunc
159
+ onStatusChanged func (source * componentstatus.InstanceID , event * componentstatus.Event )
160
+ }
161
+
162
+ func (e statusWatcherExtension ) ComponentStatusChanged (source * componentstatus.InstanceID , event * componentstatus.Event ) {
163
+ e .onStatusChanged (source , event )
164
+ }
165
+
139
166
func TestComponentStatusWatcher (t * testing.T ) {
140
167
factories , err := nopFactories ()
141
168
assert .NoError (t , err )
@@ -159,7 +186,7 @@ func TestComponentStatusWatcher(t *testing.T) {
159
186
160
187
// Add a "statuswatcher" extension that will receive notifications when processor
161
188
// status changes.
162
- factory := extensiontest . NewStatusWatcherExtensionFactory (onStatusChanged )
189
+ factory := NewStatusWatcherExtensionFactory (onStatusChanged )
163
190
factories .Extensions [factory .Type ()] = factory
164
191
165
192
// Create a collector
0 commit comments