-
Notifications
You must be signed in to change notification settings - Fork 487
/
loki.go
77 lines (62 loc) · 1.95 KB
/
loki.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
68
69
70
71
72
73
74
75
76
77
// Package loki provides an otelcol.exporter.loki component.
package loki
import (
"context"
"github.com/go-kit/log"
"github.com/grafana/agent/component"
"github.com/grafana/agent/component/common/loki"
"github.com/grafana/agent/component/otelcol"
"github.com/grafana/agent/component/otelcol/exporter/loki/internal/convert"
"github.com/grafana/agent/component/otelcol/internal/lazyconsumer"
)
func init() {
component.Register(component.Registration{
Name: "otelcol.exporter.loki",
Args: Arguments{},
Exports: otelcol.ConsumerExports{},
Build: func(o component.Options, a component.Arguments) (component.Component, error) {
return New(o, a.(Arguments))
},
})
}
// Arguments configures the otelcol.exporter.loki component.
type Arguments struct {
ForwardTo []loki.LogsReceiver `river:"forward_to,attr"`
}
// Component is the otelcol.exporter.loki component.
type Component struct {
log log.Logger
opts component.Options
converter *convert.Converter
}
var _ component.Component = (*Component)(nil)
// New creates a new otelcol.exporter.loki component.
func New(o component.Options, c Arguments) (*Component, error) {
converter := convert.New(o.Logger, o.Registerer, c.ForwardTo)
res := &Component{
log: o.Logger,
opts: o,
converter: converter,
}
if err := res.Update(c); err != nil {
return nil, err
}
// Construct a consumer based on our converter and export it. This will
// remain the same throughout the component's lifetime, so we do this
// during component construction.
export := lazyconsumer.New(context.Background())
export.SetConsumers(nil, nil, converter)
o.OnStateChange(otelcol.ConsumerExports{Input: export})
return res, nil
}
// Run implements Component.
func (c *Component) Run(ctx context.Context) error {
<-ctx.Done()
return nil
}
// Update implements Component.
func (c *Component) Update(newConfig component.Arguments) error {
cfg := newConfig.(Arguments)
c.converter.UpdateFanout(cfg.ForwardTo)
return nil
}