Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/otelcol/receiver/otlp/otlp.go
4096 views
1
// Package otlp provides an otelcol.receiver.otlp component.
2
package otlp
3
4
import (
5
"github.com/alecthomas/units"
6
"github.com/grafana/agent/component"
7
"github.com/grafana/agent/component/otelcol"
8
"github.com/grafana/agent/component/otelcol/receiver"
9
"github.com/grafana/agent/pkg/river"
10
otelcomponent "go.opentelemetry.io/collector/component"
11
otelconfig "go.opentelemetry.io/collector/config"
12
"go.opentelemetry.io/collector/receiver/otlpreceiver"
13
)
14
15
func init() {
16
component.Register(component.Registration{
17
Name: "otelcol.receiver.otlp",
18
Args: Arguments{},
19
20
Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
21
fact := otlpreceiver.NewFactory()
22
return receiver.New(opts, fact, args.(Arguments))
23
},
24
})
25
}
26
27
// Arguments configures the otelcol.receiver.otlp component.
28
type Arguments struct {
29
GRPC *GRPCServerArguments `river:"grpc,block,optional"`
30
HTTP *HTTPServerArguments `river:"http,block,optional"`
31
32
// Output configures where to send received data. Required.
33
Output *otelcol.ConsumerArguments `river:"output,block"`
34
}
35
36
var _ receiver.Arguments = Arguments{}
37
38
// Convert implements receiver.Arguments.
39
func (args Arguments) Convert() (otelconfig.Receiver, error) {
40
return &otlpreceiver.Config{
41
ReceiverSettings: otelconfig.NewReceiverSettings(otelconfig.NewComponentID("otlp")),
42
Protocols: otlpreceiver.Protocols{
43
GRPC: (*otelcol.GRPCServerArguments)(args.GRPC).Convert(),
44
HTTP: (*otelcol.HTTPServerArguments)(args.HTTP).Convert(),
45
},
46
}, nil
47
}
48
49
// Extensions implements receiver.Arguments.
50
func (args Arguments) Extensions() map[otelconfig.ComponentID]otelcomponent.Extension {
51
return nil
52
}
53
54
// Exporters implements receiver.Arguments.
55
func (args Arguments) Exporters() map[otelconfig.DataType]map[otelconfig.ComponentID]otelcomponent.Exporter {
56
return nil
57
}
58
59
// NextConsumers implements receiver.Arguments.
60
func (args Arguments) NextConsumers() *otelcol.ConsumerArguments {
61
return args.Output
62
}
63
64
type (
65
// GRPCServerArguments is used to configure otelcol.receiver.otlp with
66
// component-specific defaults.
67
GRPCServerArguments otelcol.GRPCServerArguments
68
69
// HTTPServerArguments is used to configure otelcol.receiver.otlp with
70
// component-specific defaults.
71
HTTPServerArguments otelcol.HTTPServerArguments
72
)
73
74
var (
75
_ river.Unmarshaler = (*GRPCServerArguments)(nil)
76
_ river.Unmarshaler = (*HTTPServerArguments)(nil)
77
)
78
79
// Default server settings.
80
var (
81
DefaultGRPCServerArguments = GRPCServerArguments{
82
Endpoint: "0.0.0.0:4317",
83
Transport: "tcp",
84
85
ReadBufferSize: 512 * units.Kibibyte,
86
// We almost write 0 bytes, so no need to tune WriteBufferSize.
87
}
88
89
DefaultHTTPServerArguments = HTTPServerArguments{
90
Endpoint: "0.0.0.0:4318",
91
}
92
)
93
94
// UnmarshalRiver implements river.Unmarshaler and supplies defaults.
95
func (args *GRPCServerArguments) UnmarshalRiver(f func(interface{}) error) error {
96
*args = DefaultGRPCServerArguments
97
type arguments GRPCServerArguments
98
return f((*arguments)(args))
99
}
100
101
// UnmarshalRiver implements river.Unmarshaler and supplies defaults.
102
func (args *HTTPServerArguments) UnmarshalRiver(f func(interface{}) error) error {
103
*args = DefaultHTTPServerArguments
104
type arguments HTTPServerArguments
105
return f((*arguments)(args))
106
}
107
108