-
Notifications
You must be signed in to change notification settings - Fork 486
/
otlp.go
102 lines (85 loc) · 3.25 KB
/
otlp.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Package otlp provides an otelcol.exporter.otlp component.
package otlp
import (
"time"
"github.com/grafana/agent/component"
"github.com/grafana/agent/component/otelcol"
"github.com/grafana/agent/component/otelcol/exporter"
"github.com/grafana/agent/pkg/river"
otelcomponent "go.opentelemetry.io/collector/component"
otelconfig "go.opentelemetry.io/collector/config"
otelpexporterhelper "go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/exporter/otlpexporter"
)
func init() {
component.Register(component.Registration{
Name: "otelcol.exporter.otlp",
Args: Arguments{},
Exports: otelcol.ConsumerExports{},
Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
fact := otlpexporter.NewFactory()
return exporter.New(opts, fact, args.(Arguments))
},
})
}
// Arguments configures the otelcol.exporter.otlp component.
type Arguments struct {
Timeout time.Duration `river:"timeout,attr,optional"`
Queue otelcol.QueueArguments `river:"sending_queue,block,optional"`
Retry otelcol.RetryArguments `river:"retry_on_failure,block,optional"`
Client GRPCClientArguments `river:"client,block"`
}
var (
_ river.Unmarshaler = (*Arguments)(nil)
_ exporter.Arguments = Arguments{}
)
// DefaultArguments holds default values for Arguments.
var DefaultArguments = Arguments{
Timeout: otelcol.DefaultTimeout,
Queue: otelcol.DefaultQueueArguments,
Retry: otelcol.DefaultRetryArguments,
Client: DefaultGRPCClientArguments,
}
// UnmarshalRiver implements river.Unmarshaler.
func (args *Arguments) UnmarshalRiver(f func(interface{}) error) error {
*args = DefaultArguments
type arguments Arguments
return f((*arguments)(args))
}
// Convert implements exporter.Arguments.
func (args Arguments) Convert() otelconfig.Exporter {
return &otlpexporter.Config{
ExporterSettings: otelconfig.NewExporterSettings(otelconfig.NewComponentID("otlp")),
TimeoutSettings: otelpexporterhelper.TimeoutSettings{
Timeout: args.Timeout,
},
QueueSettings: *args.Queue.Convert(),
RetrySettings: *args.Retry.Convert(),
GRPCClientSettings: *(*otelcol.GRPCClientArguments)(&args.Client).Convert(),
}
}
// Extensions implements exporter.Arguments.
func (args Arguments) Extensions() map[otelconfig.ComponentID]otelcomponent.Extension {
return (*otelcol.GRPCClientArguments)(&args.Client).Extensions()
}
// Exporters implements exporter.Arguments.
func (args Arguments) Exporters() map[otelconfig.DataType]map[otelconfig.ComponentID]otelcomponent.Exporter {
return nil
}
// GRPCClientArguments is used to configure otelcol.exporter.otlp with
// component-specific defaults.
type GRPCClientArguments otelcol.GRPCClientArguments
var _ river.Unmarshaler = (*GRPCClientArguments)(nil)
// DefaultGRPCClientArguments holds component-specific default settings for
// GRPCClientArguments.
var DefaultGRPCClientArguments = GRPCClientArguments{
Headers: map[string]string{},
Compression: otelcol.CompressionTypeGzip,
WriteBufferSize: 512 * 1024,
}
// UnmarshalRiver implements river.Unmarshaler and supplies defaults.
func (args *GRPCClientArguments) UnmarshalRiver(f func(interface{}) error) error {
*args = DefaultGRPCClientArguments
type arguments GRPCClientArguments
return f((*arguments)(args))
}