Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/otelcol/config_grpc.go
4095 views
1
package otelcol
2
3
import (
4
"time"
5
6
"github.com/alecthomas/units"
7
"github.com/grafana/agent/component/otelcol/auth"
8
otelcomponent "go.opentelemetry.io/collector/component"
9
otelconfig "go.opentelemetry.io/collector/config"
10
otelconfigauth "go.opentelemetry.io/collector/config/configauth"
11
otelconfiggrpc "go.opentelemetry.io/collector/config/configgrpc"
12
"go.opentelemetry.io/collector/config/confignet"
13
)
14
15
// GRPCServerArguments holds shared gRPC settings for components which launch
16
// gRPC servers.
17
type GRPCServerArguments struct {
18
Endpoint string `river:"endpoint,attr,optional"`
19
Transport string `river:"transport,attr,optional"`
20
21
TLS *TLSServerArguments `river:"tls,block,optional"`
22
23
MaxRecvMsgSize units.Base2Bytes `river:"max_recv_msg_size,attr,optional"`
24
MaxConcurrentStreams uint32 `river:"max_concurrent_streams,attr,optional"`
25
ReadBufferSize units.Base2Bytes `river:"read_buffer_size,attr,optional"`
26
WriteBufferSize units.Base2Bytes `river:"write_buffer_size,attr,optional"`
27
28
Keepalive *KeepaliveServerArguments `river:"keepalive,block,optional"`
29
30
// TODO(rfratto): auth
31
//
32
// Figuring out how to do authentication isn't very straightforward here. The
33
// auth section links to an authenticator extension.
34
//
35
// We will need to generally figure out how we want to provide common
36
// authentication extensions to all of our components.
37
38
IncludeMetadata bool `river:"include_metadata,attr,optional"`
39
}
40
41
// Convert converts args into the upstream type.
42
func (args *GRPCServerArguments) Convert() *otelconfiggrpc.GRPCServerSettings {
43
if args == nil {
44
return nil
45
}
46
47
return &otelconfiggrpc.GRPCServerSettings{
48
NetAddr: confignet.NetAddr{
49
Endpoint: args.Endpoint,
50
Transport: args.Transport,
51
},
52
53
TLSSetting: args.TLS.Convert(),
54
55
MaxRecvMsgSizeMiB: uint64(args.MaxRecvMsgSize / units.Mebibyte),
56
MaxConcurrentStreams: args.MaxConcurrentStreams,
57
ReadBufferSize: int(args.ReadBufferSize),
58
WriteBufferSize: int(args.WriteBufferSize),
59
60
Keepalive: args.Keepalive.Convert(),
61
62
IncludeMetadata: args.IncludeMetadata,
63
}
64
}
65
66
// KeepaliveServerArguments holds shared keepalive settings for components
67
// which launch servers.
68
type KeepaliveServerArguments struct {
69
ServerParameters *KeepaliveServerParamaters `river:"server_parameters,block,optional"`
70
EnforcementPolicy *KeepaliveEnforcementPolicy `river:"enforcement_policy,block,optional"`
71
}
72
73
// Convert converts args into the upstream type.
74
func (args *KeepaliveServerArguments) Convert() *otelconfiggrpc.KeepaliveServerConfig {
75
if args == nil {
76
return nil
77
}
78
79
return &otelconfiggrpc.KeepaliveServerConfig{
80
ServerParameters: args.ServerParameters.Convert(),
81
EnforcementPolicy: args.EnforcementPolicy.Convert(),
82
}
83
}
84
85
// KeepaliveServerParamaters holds shared keepalive settings for components
86
// which launch servers.
87
type KeepaliveServerParamaters struct {
88
MaxConnectionIdle time.Duration `river:"max_connection_idle,attr,optional"`
89
MaxConnectionAge time.Duration `river:"max_connection_age,attr,optional"`
90
MaxConnectionAgeGrace time.Duration `river:"max_connection_age_grace,attr,optional"`
91
Time time.Duration `river:"time,attr,optional"`
92
Timeout time.Duration `river:"timeout,attr,optional"`
93
}
94
95
// Convert converts args into the upstream type.
96
func (args *KeepaliveServerParamaters) Convert() *otelconfiggrpc.KeepaliveServerParameters {
97
if args == nil {
98
return nil
99
}
100
101
return &otelconfiggrpc.KeepaliveServerParameters{
102
MaxConnectionIdle: args.MaxConnectionIdle,
103
MaxConnectionAge: args.MaxConnectionAge,
104
MaxConnectionAgeGrace: args.MaxConnectionAgeGrace,
105
Time: args.Time,
106
Timeout: args.Timeout,
107
}
108
}
109
110
// KeepaliveEnforcementPolicy holds shared keepalive settings for components
111
// which launch servers.
112
type KeepaliveEnforcementPolicy struct {
113
MinTime time.Duration `river:"min_time,attr,optional"`
114
PermitWithoutStream bool `river:"permit_without_stream,attr,optional"`
115
}
116
117
// Convert converts args into the upstream type.
118
func (args *KeepaliveEnforcementPolicy) Convert() *otelconfiggrpc.KeepaliveEnforcementPolicy {
119
if args == nil {
120
return nil
121
}
122
123
return &otelconfiggrpc.KeepaliveEnforcementPolicy{
124
MinTime: args.MinTime,
125
PermitWithoutStream: args.PermitWithoutStream,
126
}
127
}
128
129
// GRPCClientArguments holds shared gRPC settings for components which launch
130
// gRPC clients.
131
type GRPCClientArguments struct {
132
Endpoint string `river:"endpoint,attr"`
133
134
Compression CompressionType `river:"compression,attr,optional"`
135
136
TLS TLSClientArguments `river:"tls,block,optional"`
137
Keepalive *KeepaliveClientArguments `river:"keepalive,block,optional"`
138
139
ReadBufferSize units.Base2Bytes `river:"read_buffer_size,attr,optional"`
140
WriteBufferSize units.Base2Bytes `river:"write_buffer_size,attr,optional"`
141
WaitForReady bool `river:"wait_for_ready,attr,optional"`
142
Headers map[string]string `river:"headers,attr,optional"`
143
BalancerName string `river:"balancer_name,attr,optional"`
144
145
// Auth is a binding to an otelcol.auth.* component extension which handles
146
// authentication.
147
Auth *auth.Handler `river:"auth,attr,optional"`
148
}
149
150
// Convert converts args into the upstream type.
151
func (args *GRPCClientArguments) Convert() *otelconfiggrpc.GRPCClientSettings {
152
if args == nil {
153
return nil
154
}
155
156
// Configure the authentication if args.Auth is set.
157
var auth *otelconfigauth.Authentication
158
if args.Auth != nil {
159
auth = &otelconfigauth.Authentication{AuthenticatorID: args.Auth.ID}
160
}
161
162
return &otelconfiggrpc.GRPCClientSettings{
163
Endpoint: args.Endpoint,
164
165
Compression: args.Compression.Convert(),
166
167
TLSSetting: *args.TLS.Convert(),
168
Keepalive: args.Keepalive.Convert(),
169
170
ReadBufferSize: int(args.ReadBufferSize),
171
WriteBufferSize: int(args.WriteBufferSize),
172
WaitForReady: args.WaitForReady,
173
Headers: args.Headers,
174
BalancerName: args.BalancerName,
175
176
Auth: auth,
177
}
178
}
179
180
// Extensions exposes extensions used by args.
181
func (args *GRPCClientArguments) Extensions() map[otelconfig.ComponentID]otelcomponent.Extension {
182
m := make(map[otelconfig.ComponentID]otelcomponent.Extension)
183
if args.Auth != nil {
184
m[args.Auth.ID] = args.Auth.Extension
185
}
186
return m
187
}
188
189
// KeepaliveClientArguments holds shared keepalive settings for components
190
// which launch clients.
191
type KeepaliveClientArguments struct {
192
PingWait time.Duration `river:"ping_wait,attr,optional"`
193
PingResponseTimeout time.Duration `river:"ping_response_timeout,attr,optional"`
194
PingWithoutStream bool `river:"ping_without_stream,attr,optional"`
195
}
196
197
// Convert converts args into the upstream type.
198
func (args *KeepaliveClientArguments) Convert() *otelconfiggrpc.KeepaliveClientConfig {
199
if args == nil {
200
return nil
201
}
202
203
return &otelconfiggrpc.KeepaliveClientConfig{
204
Time: args.PingWait,
205
Timeout: args.PingResponseTimeout,
206
PermitWithoutStream: args.PingWithoutStream,
207
}
208
}
209
210