Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/otelcol/config_http.go
4096 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
otelconfighttp "go.opentelemetry.io/collector/config/confighttp"
12
)
13
14
// HTTPServerArguments holds shared settings for components which launch HTTP
15
// servers.
16
type HTTPServerArguments struct {
17
Endpoint string `river:"endpoint,attr,optional"`
18
19
TLS *TLSServerArguments `river:"tls,block,optional"`
20
21
CORS *CORSArguments `river:"cors,block,optional"`
22
23
// TODO(rfratto): auth
24
//
25
// Figuring out how to do authentication isn't very straightforward here. The
26
// auth section links to an authenticator extension.
27
//
28
// We will need to generally figure out how we want to provide common
29
// authentication extensions to all of our components.
30
31
MaxRequestBodySize units.Base2Bytes `river:"max_request_body_size,attr,optional"`
32
IncludeMetadata bool `river:"include_metadata,attr,optional"`
33
}
34
35
// Convert converts args into the upstream type.
36
func (args *HTTPServerArguments) Convert() *otelconfighttp.HTTPServerSettings {
37
if args == nil {
38
return nil
39
}
40
41
return &otelconfighttp.HTTPServerSettings{
42
Endpoint: args.Endpoint,
43
TLSSetting: args.TLS.Convert(),
44
CORS: args.CORS.Convert(),
45
MaxRequestBodySize: int64(args.MaxRequestBodySize),
46
IncludeMetadata: args.IncludeMetadata,
47
}
48
}
49
50
// CORSArguments holds shared CORS settings for components which launch HTTP
51
// servers.
52
type CORSArguments struct {
53
AllowedOrigins []string `river:"allowed_origins,attr,optional"`
54
AllowedHeaders []string `river:"allowed_headers,attr,optional"`
55
56
MaxAge int `river:"max_age,attr,optional"`
57
}
58
59
// Convert converts args into the upstream type.
60
func (args *CORSArguments) Convert() *otelconfighttp.CORSSettings {
61
if args == nil {
62
return nil
63
}
64
65
return &otelconfighttp.CORSSettings{
66
AllowedOrigins: args.AllowedOrigins,
67
AllowedHeaders: args.AllowedHeaders,
68
69
MaxAge: args.MaxAge,
70
}
71
}
72
73
// HTTPClientArguments holds shared HTTP settings for components which launch
74
// HTTP clients.
75
type HTTPClientArguments struct {
76
Endpoint string `river:"endpoint,attr"`
77
78
Compression CompressionType `river:"compression,attr,optional"`
79
80
TLS TLSClientArguments `river:"tls,block,optional"`
81
82
ReadBufferSize units.Base2Bytes `river:"read_buffer_size,attr,optional"`
83
WriteBufferSize units.Base2Bytes `river:"write_buffer_size,attr,optional"`
84
Timeout time.Duration `river:"timeout,attr,optional"`
85
Headers map[string]string `river:"headers,attr,optional"`
86
// CustomRoundTripper func(next http.RoundTripper) (http.RoundTripper, error) TODO (@tpaschalis)
87
MaxIdleConns *int `river:"max_idle_conns,attr,optional"`
88
MaxIdleConnsPerHost *int `river:"max_idle_conns_per_host,attr,optional"`
89
MaxConnsPerHost *int `river:"max_conns_per_host,attr,optional"`
90
IdleConnTimeout *time.Duration `river:"idle_conn_timeout,attr,optional"`
91
92
// Auth is a binding to an otelcol.auth.* component extension which handles
93
// authentication.
94
Auth *auth.Handler `river:"auth,attr,optional"`
95
}
96
97
// Convert converts args into the upstream type.
98
func (args *HTTPClientArguments) Convert() *otelconfighttp.HTTPClientSettings {
99
if args == nil {
100
return nil
101
}
102
103
// Configure the authentication if args.Auth is set.
104
var auth *otelconfigauth.Authentication
105
if args.Auth != nil {
106
auth = &otelconfigauth.Authentication{AuthenticatorID: args.Auth.ID}
107
}
108
109
return &otelconfighttp.HTTPClientSettings{
110
Endpoint: args.Endpoint,
111
112
Compression: args.Compression.Convert(),
113
114
TLSSetting: *args.TLS.Convert(),
115
116
ReadBufferSize: int(args.ReadBufferSize),
117
WriteBufferSize: int(args.WriteBufferSize),
118
Timeout: args.Timeout,
119
Headers: args.Headers,
120
// CustomRoundTripper: func(http.RoundTripper) (http.RoundTripper, error) { panic("not implemented") }, TODO (@tpaschalis)
121
MaxIdleConns: args.MaxIdleConns,
122
MaxIdleConnsPerHost: args.MaxIdleConnsPerHost,
123
MaxConnsPerHost: args.MaxConnsPerHost,
124
IdleConnTimeout: args.IdleConnTimeout,
125
126
Auth: auth,
127
}
128
}
129
130
// Extensions exposes extensions used by args.
131
func (args *HTTPClientArguments) Extensions() map[otelconfig.ComponentID]otelcomponent.Extension {
132
m := make(map[otelconfig.ComponentID]otelcomponent.Extension)
133
if args.Auth != nil {
134
m[args.Auth.ID] = args.Auth.Extension
135
}
136
return m
137
}
138
139