Path: blob/main/component/otelcol/receiver/jaeger/jaeger.go
4096 views
// Package jaeger provides an otelcol.receiver.jaeger component.1package jaeger23import (4"fmt"5"time"67"github.com/alecthomas/units"8"github.com/grafana/agent/component"9"github.com/grafana/agent/component/otelcol"10"github.com/grafana/agent/component/otelcol/receiver"11"github.com/grafana/agent/pkg/river"12"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver"13otelcomponent "go.opentelemetry.io/collector/component"14otelconfig "go.opentelemetry.io/collector/config"15)1617func init() {18component.Register(component.Registration{19Name: "otelcol.receiver.jaeger",20Args: Arguments{},2122Build: func(opts component.Options, args component.Arguments) (component.Component, error) {23fact := jaegerreceiver.NewFactory()24return receiver.New(opts, fact, args.(Arguments))25},26})27}2829// Arguments configures the otelcol.receiver.jaeger component.30type Arguments struct {31Protocols ProtocolsArguments `river:"protocols,block"`32RemoteSampling *RemoteSamplingArguments `river:"remote_sampling,block,optional"`3334// Output configures where to send received data. Required.35Output *otelcol.ConsumerArguments `river:"output,block"`36}3738var (39_ river.Unmarshaler = (*Arguments)(nil)40_ receiver.Arguments = Arguments{}41)4243// DefaultArguments provides default settings for Arguments. All protocols are44// configured with defaults and then set to nil in UnmarshalRiver if they were45// not defined in the source config.46var DefaultArguments = Arguments{47Protocols: ProtocolsArguments{48GRPC: &otelcol.GRPCServerArguments{49Endpoint: "0.0.0.0:14250",50Transport: "tcp",51},52ThriftHTTP: &otelcol.HTTPServerArguments{53Endpoint: "0.0.0.0:14268",54},55ThriftBinary: &ProtocolUDP{56Endpoint: "0.0.0.0:6832",57QueueSize: 1_000,58MaxPacketSize: 65 * units.KiB,59Workers: 10,60},61ThriftCompact: &ProtocolUDP{62Endpoint: "0.0.0.0:6831",63QueueSize: 1_000,64MaxPacketSize: 65 * units.KiB,65Workers: 10,66},67},68}6970// UnmarshalRiver implements river.Unmarshaler.71func (args *Arguments) UnmarshalRiver(f func(interface{}) error) error {72*args = DefaultArguments7374type arguments Arguments7576// Unmarshal into a temporary struct so we can detect which protocols were77// actually enabled by the user.78var temp arguments79if err := f(&temp); err != nil {80return err81}8283// Remove protocols from args if they weren't provided by the user.84if temp.Protocols.GRPC == nil {85args.Protocols.GRPC = nil86}87if temp.Protocols.ThriftHTTP == nil {88args.Protocols.ThriftHTTP = nil89}90if temp.Protocols.ThriftBinary == nil {91args.Protocols.ThriftBinary = nil92}93if temp.Protocols.ThriftCompact == nil {94args.Protocols.ThriftCompact = nil95}9697// Finally, unmarshal into the real struct.98if err := f((*arguments)(args)); err != nil {99return err100}101return args.Validate()102}103104// Validate returns an error if args is invalid.105func (args *Arguments) Validate() error {106if args.Protocols.GRPC == nil &&107args.Protocols.ThriftHTTP == nil &&108args.Protocols.ThriftBinary == nil &&109args.Protocols.ThriftCompact == nil {110111return fmt.Errorf("at least one protocol must be enabled")112}113114return nil115}116117// Convert implements receiver.Arguments.118func (args Arguments) Convert() (otelconfig.Receiver, error) {119return &jaegerreceiver.Config{120ReceiverSettings: otelconfig.NewReceiverSettings(otelconfig.NewComponentID("jaeger")),121Protocols: jaegerreceiver.Protocols{122GRPC: args.Protocols.GRPC.Convert(),123ThriftHTTP: args.Protocols.ThriftHTTP.Convert(),124ThriftBinary: args.Protocols.ThriftBinary.Convert(),125ThriftCompact: args.Protocols.ThriftCompact.Convert(),126},127RemoteSampling: args.RemoteSampling.Convert(),128}, nil129}130131// Extensions implements receiver.Arguments.132func (args Arguments) Extensions() map[otelconfig.ComponentID]otelcomponent.Extension {133if args.RemoteSampling == nil {134return nil135}136return args.RemoteSampling.Client.Extensions()137}138139// Exporters implements receiver.Arguments.140func (args Arguments) Exporters() map[otelconfig.DataType]map[otelconfig.ComponentID]otelcomponent.Exporter {141return nil142}143144// NextConsumers implements receiver.Arguments.145func (args Arguments) NextConsumers() *otelcol.ConsumerArguments {146return args.Output147}148149// ProtocolsArguments configures protocols for otelcol.receiver.jaeger to150// listen on.151type ProtocolsArguments struct {152GRPC *otelcol.GRPCServerArguments `river:"grpc,block,optional"`153ThriftHTTP *otelcol.HTTPServerArguments `river:"thrift_http,block,optional"`154ThriftBinary *ProtocolUDP `river:"thrift_binary,block,optional"`155ThriftCompact *ProtocolUDP `river:"thrift_compact,block,optional"`156}157158// ProtocolUDP configures a UDP server.159type ProtocolUDP struct {160Endpoint string `river:"endpoint,attr,optional"`161QueueSize int `river:"queue_size,attr,optional"`162MaxPacketSize units.Base2Bytes `river:"max_packet_size,attr,optional"`163Workers int `river:"workers,attr,optional"`164SocketBufferSize units.Base2Bytes `river:"socket_buffer_size,attr,optional"`165}166167// Convert converts proto into the upstream type.168func (proto *ProtocolUDP) Convert() *jaegerreceiver.ProtocolUDP {169if proto == nil {170return nil171}172173return &jaegerreceiver.ProtocolUDP{174Endpoint: proto.Endpoint,175ServerConfigUDP: jaegerreceiver.ServerConfigUDP{176QueueSize: proto.QueueSize,177MaxPacketSize: int(proto.MaxPacketSize),178Workers: proto.Workers,179SocketBufferSize: int(proto.SocketBufferSize),180},181}182}183184// RemoteSamplingArguments configures remote sampling settings.185type RemoteSamplingArguments struct {186// TODO(rfratto): can we work with upstream to provide a hook to provide a187// custom strategy file and bypass the reload interval?188//189// That would let users connect a local.file to otelcol.receiver.jaeger for190// the remote sampling.191192HostEndpoint string `river:"host_endpoint,attr"`193StrategyFile string `river:"strategy_file,attr"`194StrategyFileReloadInterval time.Duration `river:"strategy_file_reload_interval,attr"`195Client otelcol.GRPCClientArguments `river:"client,block"`196}197198// Convert converts args into the upstream type.199func (args *RemoteSamplingArguments) Convert() *jaegerreceiver.RemoteSamplingConfig {200if args == nil {201return nil202}203204return &jaegerreceiver.RemoteSamplingConfig{205HostEndpoint: args.HostEndpoint,206StrategyFile: args.StrategyFile,207StrategyFileReloadInterval: args.StrategyFileReloadInterval,208GRPCClientSettings: *args.Client.Convert(),209}210}211212213