Path: blob/main/component/otelcol/receiver/otlp/otlp.go
4096 views
// Package otlp provides an otelcol.receiver.otlp component.1package otlp23import (4"github.com/alecthomas/units"5"github.com/grafana/agent/component"6"github.com/grafana/agent/component/otelcol"7"github.com/grafana/agent/component/otelcol/receiver"8"github.com/grafana/agent/pkg/river"9otelcomponent "go.opentelemetry.io/collector/component"10otelconfig "go.opentelemetry.io/collector/config"11"go.opentelemetry.io/collector/receiver/otlpreceiver"12)1314func init() {15component.Register(component.Registration{16Name: "otelcol.receiver.otlp",17Args: Arguments{},1819Build: func(opts component.Options, args component.Arguments) (component.Component, error) {20fact := otlpreceiver.NewFactory()21return receiver.New(opts, fact, args.(Arguments))22},23})24}2526// Arguments configures the otelcol.receiver.otlp component.27type Arguments struct {28GRPC *GRPCServerArguments `river:"grpc,block,optional"`29HTTP *HTTPServerArguments `river:"http,block,optional"`3031// Output configures where to send received data. Required.32Output *otelcol.ConsumerArguments `river:"output,block"`33}3435var _ receiver.Arguments = Arguments{}3637// Convert implements receiver.Arguments.38func (args Arguments) Convert() (otelconfig.Receiver, error) {39return &otlpreceiver.Config{40ReceiverSettings: otelconfig.NewReceiverSettings(otelconfig.NewComponentID("otlp")),41Protocols: otlpreceiver.Protocols{42GRPC: (*otelcol.GRPCServerArguments)(args.GRPC).Convert(),43HTTP: (*otelcol.HTTPServerArguments)(args.HTTP).Convert(),44},45}, nil46}4748// Extensions implements receiver.Arguments.49func (args Arguments) Extensions() map[otelconfig.ComponentID]otelcomponent.Extension {50return nil51}5253// Exporters implements receiver.Arguments.54func (args Arguments) Exporters() map[otelconfig.DataType]map[otelconfig.ComponentID]otelcomponent.Exporter {55return nil56}5758// NextConsumers implements receiver.Arguments.59func (args Arguments) NextConsumers() *otelcol.ConsumerArguments {60return args.Output61}6263type (64// GRPCServerArguments is used to configure otelcol.receiver.otlp with65// component-specific defaults.66GRPCServerArguments otelcol.GRPCServerArguments6768// HTTPServerArguments is used to configure otelcol.receiver.otlp with69// component-specific defaults.70HTTPServerArguments otelcol.HTTPServerArguments71)7273var (74_ river.Unmarshaler = (*GRPCServerArguments)(nil)75_ river.Unmarshaler = (*HTTPServerArguments)(nil)76)7778// Default server settings.79var (80DefaultGRPCServerArguments = GRPCServerArguments{81Endpoint: "0.0.0.0:4317",82Transport: "tcp",8384ReadBufferSize: 512 * units.Kibibyte,85// We almost write 0 bytes, so no need to tune WriteBufferSize.86}8788DefaultHTTPServerArguments = HTTPServerArguments{89Endpoint: "0.0.0.0:4318",90}91)9293// UnmarshalRiver implements river.Unmarshaler and supplies defaults.94func (args *GRPCServerArguments) UnmarshalRiver(f func(interface{}) error) error {95*args = DefaultGRPCServerArguments96type arguments GRPCServerArguments97return f((*arguments)(args))98}99100// UnmarshalRiver implements river.Unmarshaler and supplies defaults.101func (args *HTTPServerArguments) UnmarshalRiver(f func(interface{}) error) error {102*args = DefaultHTTPServerArguments103type arguments HTTPServerArguments104return f((*arguments)(args))105}106107108