-
Notifications
You must be signed in to change notification settings - Fork 486
/
host.go
67 lines (54 loc) · 1.96 KB
/
host.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package scheduler
import (
"github.com/go-kit/log"
"github.com/go-kit/log/level"
otelcomponent "go.opentelemetry.io/collector/component"
otelconfig "go.opentelemetry.io/collector/config"
)
// Host implements otelcomponent.Host for Grafana Agent Flow.
type Host struct {
log log.Logger
extensions map[otelconfig.ComponentID]otelcomponent.Extension
exporters map[otelconfig.DataType]map[otelconfig.ComponentID]otelcomponent.Exporter
}
// NewHost creates a new Host.
func NewHost(l log.Logger, opts ...HostOption) *Host {
h := &Host{log: l}
for _, opt := range opts {
opt(h)
}
return h
}
// HostOption customizes behavior of the Host.
type HostOption func(*Host)
// WithHostExtensions provides a custom set of extensions to the Host.
func WithHostExtensions(extensions map[otelconfig.ComponentID]otelcomponent.Extension) HostOption {
return func(h *Host) {
h.extensions = extensions
}
}
// WithHostExporters provides a custom set of exporters to the Host.
func WithHostExporters(exporters map[otelconfig.DataType]map[otelconfig.ComponentID]otelcomponent.Exporter) HostOption {
return func(h *Host) {
h.exporters = exporters
}
}
var _ otelcomponent.Host = (*Host)(nil)
// ReportFatalError implements otelcomponent.Host.
func (h *Host) ReportFatalError(err error) {
level.Error(h.log).Log("msg", "fatal error running component", "err", err)
}
// GetFactory implements otelcomponent.Host.
func (h *Host) GetFactory(kind otelcomponent.Kind, componentType otelconfig.Type) otelcomponent.Factory {
// GetFactory is used for components to create other components. It's not
// clear if we want to allow this right now, so it's disabled.
return nil
}
// GetExtensions implements otelcomponent.Host.
func (h *Host) GetExtensions() map[otelconfig.ComponentID]otelcomponent.Extension {
return h.extensions
}
// GetExporters implements otelcomponent.Host.
func (h *Host) GetExporters() map[otelconfig.DataType]map[otelconfig.ComponentID]otelcomponent.Exporter {
return h.exporters
}