-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
statuswatcher_extension.go
47 lines (40 loc) · 1.66 KB
/
statuswatcher_extension.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package extensiontest // import "go.opentelemetry.io/collector/extension/extensiontest"
import (
"context"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/extension"
)
// NewStatusWatcherExtensionCreateSettings returns a new nop settings for Create*Extension functions.
func NewStatusWatcherExtensionCreateSettings() extension.CreateSettings {
return extension.CreateSettings{
TelemetrySettings: componenttest.NewNopTelemetrySettings(),
BuildInfo: component.NewDefaultBuildInfo(),
}
}
// NewStatusWatcherExtensionFactory returns a component.ExtensionFactory to construct a status watcher extension.
func NewStatusWatcherExtensionFactory(
onStatusChanged func(source *component.InstanceID, event *component.StatusEvent),
) extension.Factory {
return extension.NewFactory(
component.MustNewType("statuswatcher"),
func() component.Config {
return &struct{}{}
},
func(context.Context, extension.CreateSettings, component.Config) (component.Component, error) {
return &statusWatcherExtension{onStatusChanged: onStatusChanged}, nil
},
component.StabilityLevelStable)
}
// statusWatcherExtension receives status events reported via component status reporting for testing
// purposes.
type statusWatcherExtension struct {
component.StartFunc
component.ShutdownFunc
onStatusChanged func(source *component.InstanceID, event *component.StatusEvent)
}
func (e statusWatcherExtension) ComponentStatusChanged(source *component.InstanceID, event *component.StatusEvent) {
e.onStatusChanged(source, event)
}