package otelcol
import (
"time"
"github.com/alecthomas/units"
"github.com/grafana/agent/component/otelcol/auth"
otelcomponent "go.opentelemetry.io/collector/component"
otelconfig "go.opentelemetry.io/collector/config"
otelconfigauth "go.opentelemetry.io/collector/config/configauth"
otelconfighttp "go.opentelemetry.io/collector/config/confighttp"
)
type HTTPServerArguments struct {
Endpoint string `river:"endpoint,attr,optional"`
TLS *TLSServerArguments `river:"tls,block,optional"`
CORS *CORSArguments `river:"cors,block,optional"`
MaxRequestBodySize units.Base2Bytes `river:"max_request_body_size,attr,optional"`
IncludeMetadata bool `river:"include_metadata,attr,optional"`
}
func (args *HTTPServerArguments) Convert() *otelconfighttp.HTTPServerSettings {
if args == nil {
return nil
}
return &otelconfighttp.HTTPServerSettings{
Endpoint: args.Endpoint,
TLSSetting: args.TLS.Convert(),
CORS: args.CORS.Convert(),
MaxRequestBodySize: int64(args.MaxRequestBodySize),
IncludeMetadata: args.IncludeMetadata,
}
}
type CORSArguments struct {
AllowedOrigins []string `river:"allowed_origins,attr,optional"`
AllowedHeaders []string `river:"allowed_headers,attr,optional"`
MaxAge int `river:"max_age,attr,optional"`
}
func (args *CORSArguments) Convert() *otelconfighttp.CORSSettings {
if args == nil {
return nil
}
return &otelconfighttp.CORSSettings{
AllowedOrigins: args.AllowedOrigins,
AllowedHeaders: args.AllowedHeaders,
MaxAge: args.MaxAge,
}
}
type HTTPClientArguments struct {
Endpoint string `river:"endpoint,attr"`
Compression CompressionType `river:"compression,attr,optional"`
TLS TLSClientArguments `river:"tls,block,optional"`
ReadBufferSize units.Base2Bytes `river:"read_buffer_size,attr,optional"`
WriteBufferSize units.Base2Bytes `river:"write_buffer_size,attr,optional"`
Timeout time.Duration `river:"timeout,attr,optional"`
Headers map[string]string `river:"headers,attr,optional"`
MaxIdleConns *int `river:"max_idle_conns,attr,optional"`
MaxIdleConnsPerHost *int `river:"max_idle_conns_per_host,attr,optional"`
MaxConnsPerHost *int `river:"max_conns_per_host,attr,optional"`
IdleConnTimeout *time.Duration `river:"idle_conn_timeout,attr,optional"`
Auth *auth.Handler `river:"auth,attr,optional"`
}
func (args *HTTPClientArguments) Convert() *otelconfighttp.HTTPClientSettings {
if args == nil {
return nil
}
var auth *otelconfigauth.Authentication
if args.Auth != nil {
auth = &otelconfigauth.Authentication{AuthenticatorID: args.Auth.ID}
}
return &otelconfighttp.HTTPClientSettings{
Endpoint: args.Endpoint,
Compression: args.Compression.Convert(),
TLSSetting: *args.TLS.Convert(),
ReadBufferSize: int(args.ReadBufferSize),
WriteBufferSize: int(args.WriteBufferSize),
Timeout: args.Timeout,
Headers: args.Headers,
MaxIdleConns: args.MaxIdleConns,
MaxIdleConnsPerHost: args.MaxIdleConnsPerHost,
MaxConnsPerHost: args.MaxConnsPerHost,
IdleConnTimeout: args.IdleConnTimeout,
Auth: auth,
}
}
func (args *HTTPClientArguments) Extensions() map[otelconfig.ComponentID]otelcomponent.Extension {
m := make(map[otelconfig.ComponentID]otelcomponent.Extension)
if args.Auth != nil {
m[args.Auth.ID] = args.Auth.Extension
}
return m
}