diff --git a/receiver/jaegerreceiver/factory.go b/receiver/jaegerreceiver/factory.go index e8a4a266333e..81b522a4be88 100644 --- a/receiver/jaegerreceiver/factory.go +++ b/receiver/jaegerreceiver/factory.go @@ -36,14 +36,6 @@ const ( defaultThriftBinaryPort = 6832 ) -var disableJaegerReceiverRemoteSampling = featuregate.GlobalRegistry().MustRegister( - "receiver.jaeger.DisableRemoteSampling", - featuregate.StageBeta, - featuregate.WithRegisterDescription("When enabled, the Jaeger Receiver will fail to start when it is configured with remote_sampling config. When disabled, the receiver will start and the remote_sampling config will be no-op."), -) - -var once sync.Once - func logDeprecation(logger *zap.Logger) { once.Do(func() { logger.Warn("jaeger receiver will deprecate Thrift-gen and replace it with Proto-gen to be compatbible to jaeger 1.42.0 and higher. See https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/18485 for more details.") @@ -69,28 +61,10 @@ var disableJaegerReceiverRemoteSampling = featuregate.GlobalRegistry().MustRegis var once sync.Once -func logDeprecation(logger *zap.Logger) { - once.Do(func() { - logger.Warn("jaeger receiver will deprecate Thrift-gen and replace it with Proto-gen to be compatbible to jaeger 1.42.0 and higher. See https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/18485 for more details.") - - }) -} - const protoInsteadOfThrift = "receiver.jaegerreceiver.replaceThriftWithProto" -var protoGate = featuregate.GlobalRegistry().MustRegister( - protoInsteadOfThrift, - featuregate.StageBeta, - featuregate.WithRegisterDescription( - "When enabled, the jaegerreceiver will use Proto-gen over Thrift-gen.", - ), -) - // NewFactory creates a new Jaeger receiver factory. func NewFactory() receiver.Factory { - if !protoGate.IsEnabled() { - return jaegerreceiverdeprecated.NewFactory() - } return receiver.NewFactory( metadata.Type, createDefaultConfig, diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/README.md b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/README.md deleted file mode 100644 index 7dae0b40c1b9..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# DO NOT USE THIS PACKAGE - -This package is a workaround to bump the jaeger dependency and will be removed soon. - -For more details see: https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/18485 diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/config.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/config.go deleted file mode 100644 index 3ecfcde188c8..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/config.go +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package jaegerreceiverdeprecated // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated" - -import ( - "fmt" - "net" - "strconv" - "time" - - "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config/configgrpc" - "go.opentelemetry.io/collector/config/confighttp" - "go.opentelemetry.io/collector/confmap" -) - -const ( - // The config field id to load the protocol map from - protocolsFieldName = "protocols" - - // Default UDP server options - defaultQueueSize = 1_000 - defaultMaxPacketSize = 65_000 - defaultServerWorkers = 10 - defaultSocketBufferSize = 0 -) - -// RemoteSamplingConfig defines config key for remote sampling fetch endpoint -type RemoteSamplingConfig struct { - HostEndpoint string `mapstructure:"host_endpoint"` - StrategyFile string `mapstructure:"strategy_file"` - StrategyFileReloadInterval time.Duration `mapstructure:"strategy_file_reload_interval"` - configgrpc.GRPCClientSettings `mapstructure:",squash"` -} - -// Protocols is the configuration for the supported protocols. -type Protocols struct { - GRPC *configgrpc.GRPCServerSettings `mapstructure:"grpc"` - ThriftHTTP *confighttp.HTTPServerSettings `mapstructure:"thrift_http"` - ThriftBinary *ProtocolUDP `mapstructure:"thrift_binary"` - ThriftCompact *ProtocolUDP `mapstructure:"thrift_compact"` -} - -// ProtocolUDP is the configuration for a UDP protocol. -type ProtocolUDP struct { - Endpoint string `mapstructure:"endpoint"` - ServerConfigUDP `mapstructure:",squash"` -} - -// ServerConfigUDP is the server configuration for a UDP protocol. -type ServerConfigUDP struct { - QueueSize int `mapstructure:"queue_size"` - MaxPacketSize int `mapstructure:"max_packet_size"` - Workers int `mapstructure:"workers"` - SocketBufferSize int `mapstructure:"socket_buffer_size"` -} - -// DefaultServerConfigUDP creates the default ServerConfigUDP. -func DefaultServerConfigUDP() ServerConfigUDP { - return ServerConfigUDP{ - QueueSize: defaultQueueSize, - MaxPacketSize: defaultMaxPacketSize, - Workers: defaultServerWorkers, - SocketBufferSize: defaultSocketBufferSize, - } -} - -// Config defines configuration for Jaeger receiver. -type Config struct { - Protocols `mapstructure:"protocols"` - RemoteSampling *RemoteSamplingConfig `mapstructure:"remote_sampling"` -} - -var _ component.Config = (*Config)(nil) -var _ confmap.Unmarshaler = (*Config)(nil) - -// Validate checks the receiver configuration is valid -func (cfg *Config) Validate() error { - if cfg.GRPC == nil && - cfg.ThriftHTTP == nil && - cfg.ThriftBinary == nil && - cfg.ThriftCompact == nil { - return fmt.Errorf("must specify at least one protocol when using the Jaeger receiver") - } - - if cfg.GRPC != nil { - if err := checkPortFromEndpoint(cfg.GRPC.NetAddr.Endpoint); err != nil { - return fmt.Errorf("invalid port number for the gRPC endpoint: %w", err) - } - } - - if cfg.ThriftHTTP != nil { - if err := checkPortFromEndpoint(cfg.ThriftHTTP.Endpoint); err != nil { - return fmt.Errorf("invalid port number for the Thrift HTTP endpoint: %w", err) - } - } - - if cfg.ThriftBinary != nil { - if err := checkPortFromEndpoint(cfg.ThriftBinary.Endpoint); err != nil { - return fmt.Errorf("invalid port number for the Thrift UDP Binary endpoint: %w", err) - } - } - - if cfg.ThriftCompact != nil { - if err := checkPortFromEndpoint(cfg.ThriftCompact.Endpoint); err != nil { - return fmt.Errorf("invalid port number for the Thrift UDP Compact endpoint: %w", err) - } - } - - if cfg.RemoteSampling != nil { - if err := checkPortFromEndpoint(cfg.RemoteSampling.HostEndpoint); err != nil { - return fmt.Errorf("invalid port number for the Remote Sampling endpoint: %w", err) - } - - if len(cfg.RemoteSampling.StrategyFile) != 0 && cfg.GRPC == nil { - return fmt.Errorf("strategy file requires the gRPC protocol to be enabled") - } - - if cfg.RemoteSampling.StrategyFileReloadInterval < 0 { - return fmt.Errorf("strategy file reload interval should be great or equal zero") - } - } - - return nil -} - -// Unmarshal a config.Parser into the config struct. -func (cfg *Config) Unmarshal(componentParser *confmap.Conf) error { - if componentParser == nil || len(componentParser.AllKeys()) == 0 { - return fmt.Errorf("empty config for Jaeger receiver") - } - - // UnmarshalExact will not set struct properties to nil even if no key is provided, - // so set the protocol structs to nil where the keys were omitted. - err := componentParser.Unmarshal(cfg, confmap.WithErrorUnused()) - if err != nil { - return err - } - - protocols, err := componentParser.Sub(protocolsFieldName) - if err != nil { - return err - } - - if !protocols.IsSet(protoGRPC) { - cfg.GRPC = nil - } - if !protocols.IsSet(protoThriftHTTP) { - cfg.ThriftHTTP = nil - } - if !protocols.IsSet(protoThriftBinary) { - cfg.ThriftBinary = nil - } - if !protocols.IsSet(protoThriftCompact) { - cfg.ThriftCompact = nil - } - - return nil -} - -// checkPortFromEndpoint checks that the endpoint string contains a port in the format "address:port". If the -// port number cannot be parsed, returns an error. -func checkPortFromEndpoint(endpoint string) error { - _, portStr, err := net.SplitHostPort(endpoint) - if err != nil { - return fmt.Errorf("endpoint is not formatted correctly: %w", err) - } - port, err := strconv.ParseInt(portStr, 10, 0) - if err != nil { - return fmt.Errorf("endpoint port is not a number: %w", err) - } - if port < 1 || port > 65535 { - return fmt.Errorf("port number must be between 1 and 65535") - } - return nil -} diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/config_test.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/config_test.go deleted file mode 100644 index f55633d8801b..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/config_test.go +++ /dev/null @@ -1,291 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package jaegerreceiverdeprecated - -import ( - "path/filepath" - "testing" - "time" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config/configgrpc" - "go.opentelemetry.io/collector/config/confighttp" - "go.opentelemetry.io/collector/config/confignet" - "go.opentelemetry.io/collector/config/configtls" - "go.opentelemetry.io/collector/confmap/confmaptest" - - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/metadata" -) - -func TestLoadConfig(t *testing.T) { - t.Parallel() - - cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) - require.NoError(t, err) - - tests := []struct { - id component.ID - expected component.Config - }{ - { - id: component.NewIDWithName(metadata.Type, "customname"), - expected: &Config{ - Protocols: Protocols{ - GRPC: &configgrpc.GRPCServerSettings{ - NetAddr: confignet.NetAddr{ - Endpoint: "localhost:9876", - Transport: "tcp", - }, - }, - ThriftHTTP: &confighttp.HTTPServerSettings{ - Endpoint: ":3456", - }, - ThriftCompact: &ProtocolUDP{ - Endpoint: "0.0.0.0:456", - ServerConfigUDP: ServerConfigUDP{ - QueueSize: 100_000, - MaxPacketSize: 131_072, - Workers: 100, - SocketBufferSize: 65_536, - }, - }, - ThriftBinary: &ProtocolUDP{ - Endpoint: "0.0.0.0:789", - ServerConfigUDP: ServerConfigUDP{ - QueueSize: 1_000, - MaxPacketSize: 65_536, - Workers: 5, - SocketBufferSize: 0, - }, - }, - }, - RemoteSampling: &RemoteSamplingConfig{ - HostEndpoint: "0.0.0.0:5778", - GRPCClientSettings: configgrpc.GRPCClientSettings{ - Endpoint: "jaeger-collector:1234", - }, - StrategyFile: "/etc/strategies.json", - StrategyFileReloadInterval: time.Second * 10, - }, - }, - }, - { - id: component.NewIDWithName(metadata.Type, "defaults"), - expected: &Config{ - Protocols: Protocols{ - GRPC: &configgrpc.GRPCServerSettings{ - NetAddr: confignet.NetAddr{ - Endpoint: defaultGRPCBindEndpoint, - Transport: "tcp", - }, - }, - ThriftHTTP: &confighttp.HTTPServerSettings{ - Endpoint: defaultHTTPBindEndpoint, - }, - ThriftCompact: &ProtocolUDP{ - Endpoint: defaultThriftCompactBindEndpoint, - ServerConfigUDP: DefaultServerConfigUDP(), - }, - ThriftBinary: &ProtocolUDP{ - Endpoint: defaultThriftBinaryBindEndpoint, - ServerConfigUDP: DefaultServerConfigUDP(), - }, - }, - }, - }, - { - id: component.NewIDWithName(metadata.Type, "mixed"), - expected: &Config{ - Protocols: Protocols{ - GRPC: &configgrpc.GRPCServerSettings{ - NetAddr: confignet.NetAddr{ - Endpoint: "localhost:9876", - Transport: "tcp", - }, - }, - ThriftCompact: &ProtocolUDP{ - Endpoint: defaultThriftCompactBindEndpoint, - ServerConfigUDP: DefaultServerConfigUDP(), - }, - }, - }, - }, - { - id: component.NewIDWithName(metadata.Type, "tls"), - expected: &Config{ - Protocols: Protocols{ - GRPC: &configgrpc.GRPCServerSettings{ - NetAddr: confignet.NetAddr{ - Endpoint: "localhost:9876", - Transport: "tcp", - }, - TLSSetting: &configtls.TLSServerSetting{ - TLSSetting: configtls.TLSSetting{ - CertFile: "/test.crt", - KeyFile: "/test.key", - }, - }, - }, - ThriftHTTP: &confighttp.HTTPServerSettings{ - Endpoint: ":3456", - }, - }, - }, - }, - } - - for _, tt := range tests { - t.Run(tt.id.String(), func(t *testing.T) { - factory := NewFactory() - cfg := factory.CreateDefaultConfig() - - sub, err := cm.Sub(tt.id.String()) - require.NoError(t, err) - require.NoError(t, component.UnmarshalConfig(sub, cfg)) - - assert.NoError(t, component.ValidateConfig(cfg)) - assert.Equal(t, tt.expected, cfg) - }) - } -} - -func TestFailedLoadConfig(t *testing.T) { - cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) - require.NoError(t, err) - factory := NewFactory() - cfg := factory.CreateDefaultConfig() - - sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "typo_default_proto_config").String()) - require.NoError(t, err) - err = component.UnmarshalConfig(sub, cfg) - assert.EqualError(t, err, "1 error(s) decoding:\n\n* 'protocols' has invalid keys: thrift_htttp") - - sub, err = cm.Sub(component.NewIDWithName(metadata.Type, "bad_proto_config").String()) - require.NoError(t, err) - err = component.UnmarshalConfig(sub, cfg) - assert.EqualError(t, err, "1 error(s) decoding:\n\n* 'protocols' has invalid keys: thrift_htttp") - - sub, err = cm.Sub(component.NewIDWithName(metadata.Type, "empty").String()) - require.NoError(t, err) - err = component.UnmarshalConfig(sub, cfg) - assert.EqualError(t, err, "empty config for Jaeger receiver") -} - -func TestInvalidConfig(t *testing.T) { - testCases := []struct { - desc string - apply func(*Config) - err string - }{ - { - desc: "thrift-http-no-port", - apply: func(cfg *Config) { - cfg.ThriftHTTP = &confighttp.HTTPServerSettings{ - Endpoint: "localhost:", - } - }, - err: "receiver creation with no port number for Thrift HTTP must fail", - }, - { - desc: "thrift-udp-compact-no-port", - apply: func(cfg *Config) { - cfg.ThriftCompact = &ProtocolUDP{ - Endpoint: "localhost:", - } - }, - err: "receiver creation with no port number for Thrift UDP - Compact must fail", - }, - { - desc: "thrift-udp-binary-no-port", - apply: func(cfg *Config) { - cfg.ThriftBinary = &ProtocolUDP{ - Endpoint: "localhost:", - } - }, - err: "receiver creation with no port number for Thrift UDP - Binary must fail", - }, - { - desc: "remote-sampling-http-no-port", - apply: func(cfg *Config) { - cfg.RemoteSampling = &RemoteSamplingConfig{ - HostEndpoint: "localhost:", - } - }, - err: "receiver creation with no port number for the remote sampling HTTP endpoint must fail", - }, - { - desc: "grpc-invalid-host", - apply: func(cfg *Config) { - cfg.GRPC = &configgrpc.GRPCServerSettings{ - NetAddr: confignet.NetAddr{ - Endpoint: "1234", - Transport: "tcp", - }, - } - }, - err: "receiver creation with bad hostname must fail", - }, - { - desc: "no-protocols", - apply: func(cfg *Config) { - cfg.Protocols = Protocols{} - }, - err: "receiver creation with no protocols must fail", - }, - { - desc: "port-outside-of-range", - apply: func(cfg *Config) { - cfg.ThriftBinary = &ProtocolUDP{ - Endpoint: "localhost:65536", - } - }, - err: "receiver creation with too large port number must fail", - }, - { - desc: "port-outside-of-range", - apply: func(cfg *Config) { - cfg.Protocols = Protocols{} - cfg.ThriftCompact = &ProtocolUDP{ - Endpoint: defaultThriftCompactBindEndpoint, - } - cfg.RemoteSampling = &RemoteSamplingConfig{ - HostEndpoint: "localhost:5778", - StrategyFile: "strategies.json", - } - }, - err: "receiver creation without gRPC and with remote sampling config", - }, - { - desc: "reload-interval-outside-of-range", - apply: func(cfg *Config) { - cfg.Protocols.GRPC = &configgrpc.GRPCServerSettings{ - NetAddr: confignet.NetAddr{ - Endpoint: "1234", - Transport: "tcp", - }, - } - cfg.RemoteSampling = &RemoteSamplingConfig{ - HostEndpoint: "localhost:5778", - StrategyFile: "strategies.json", - StrategyFileReloadInterval: -time.Second, - } - }, - err: "strategy file reload interval should be great zero", - }, - } - for _, tC := range testCases { - t.Run(tC.desc, func(t *testing.T) { - factory := NewFactory() - cfg := factory.CreateDefaultConfig().(*Config) - - tC.apply(cfg) - - err := component.ValidateConfig(cfg) - assert.Error(t, err, tC.err) - - }) - } -} diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/doc.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/doc.go deleted file mode 100644 index 3b7bdb3c2c1e..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/doc.go +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -//go:generate mdatagen metadata.yaml - -// Package jaegerreceiver receives Jaeger traces. -package jaegerreceiverdeprecated // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated" diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/errors.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/errors.go deleted file mode 100644 index b1312c9621f6..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/errors.go +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package jaegerreceiverdeprecated // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated" - -type httpError struct { - msg string - statusCode int -} - -func (h httpError) Error() string { - return h.msg -} diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/factory.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/factory.go deleted file mode 100644 index 417e02531e05..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/factory.go +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package jaegerreceiverdeprecated // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated" - -// This file implements factory for Jaeger receiver. - -import ( - "context" - - "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config/configgrpc" - "go.opentelemetry.io/collector/config/confighttp" - "go.opentelemetry.io/collector/config/confignet" - "go.opentelemetry.io/collector/consumer" - "go.opentelemetry.io/collector/receiver" - - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/metadata" -) - -const ( - // Protocol values. - protoGRPC = "grpc" - protoThriftHTTP = "thrift_http" - protoThriftBinary = "thrift_binary" - protoThriftCompact = "thrift_compact" - - // Default endpoints to bind to. - defaultGRPCBindEndpoint = "0.0.0.0:14250" - defaultHTTPBindEndpoint = "0.0.0.0:14268" - defaultThriftCompactBindEndpoint = "0.0.0.0:6831" - defaultThriftBinaryBindEndpoint = "0.0.0.0:6832" -) - -// NewFactory creates a new Jaeger receiver factory. -func NewFactory() receiver.Factory { - return receiver.NewFactory( - metadata.Type, - createDefaultConfig, - receiver.WithTraces(createTracesReceiver, metadata.TracesStability)) -} - -// CreateDefaultConfig creates the default configuration for Jaeger receiver. -func createDefaultConfig() component.Config { - return &Config{ - Protocols: Protocols{ - GRPC: &configgrpc.GRPCServerSettings{ - NetAddr: confignet.NetAddr{ - Endpoint: defaultGRPCBindEndpoint, - Transport: "tcp", - }, - }, - ThriftHTTP: &confighttp.HTTPServerSettings{ - Endpoint: defaultHTTPBindEndpoint, - }, - ThriftBinary: &ProtocolUDP{ - Endpoint: defaultThriftBinaryBindEndpoint, - ServerConfigUDP: DefaultServerConfigUDP(), - }, - ThriftCompact: &ProtocolUDP{ - Endpoint: defaultThriftCompactBindEndpoint, - ServerConfigUDP: DefaultServerConfigUDP(), - }, - }, - } -} - -// createTracesReceiver creates a trace receiver based on provided config. -func createTracesReceiver( - _ context.Context, - set receiver.CreateSettings, - cfg component.Config, - nextConsumer consumer.Traces, -) (receiver.Traces, error) { - - // Convert settings in the source config to configuration struct - // that Jaeger receiver understands. - // Error handling for the conversion is done in the Validate function from the Config object itself. - - rCfg := cfg.(*Config) - - var config configuration - // Set ports - if rCfg.Protocols.GRPC != nil { - config.CollectorGRPCServerSettings = *rCfg.Protocols.GRPC - } - - if rCfg.Protocols.ThriftHTTP != nil { - config.CollectorHTTPSettings = *rCfg.ThriftHTTP - } - - if rCfg.Protocols.ThriftBinary != nil { - config.AgentBinaryThrift = *rCfg.ThriftBinary - } - - if rCfg.Protocols.ThriftCompact != nil { - config.AgentCompactThrift = *rCfg.ThriftCompact - } - - // Create the receiver. - return newJaegerReceiver(set.ID, &config, nextConsumer, set) -} diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/factory_test.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/factory_test.go deleted file mode 100644 index 87b99596571a..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/factory_test.go +++ /dev/null @@ -1,175 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package jaegerreceiverdeprecated - -import ( - "context" - "path/filepath" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/config/configgrpc" - "go.opentelemetry.io/collector/config/confighttp" - "go.opentelemetry.io/collector/config/confignet" - "go.opentelemetry.io/collector/config/configtls" - "go.opentelemetry.io/collector/confmap/confmaptest" - "go.opentelemetry.io/collector/receiver/receivertest" - - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/metadata" -) - -func TestTypeStr(t *testing.T) { - factory := NewFactory() - - assert.Equal(t, "jaeger", string(factory.Type())) -} - -func TestCreateDefaultConfig(t *testing.T) { - factory := NewFactory() - cfg := factory.CreateDefaultConfig() - assert.NotNil(t, cfg, "failed to create default config") - assert.NoError(t, componenttest.CheckConfigStruct(cfg)) -} - -func TestCreateReceiver(t *testing.T) { - factory := NewFactory() - cfg := factory.CreateDefaultConfig() - // have to enable at least one protocol for the jaeger receiver to be created - cfg.(*Config).Protocols.GRPC = &configgrpc.GRPCServerSettings{ - NetAddr: confignet.NetAddr{ - Endpoint: defaultGRPCBindEndpoint, - Transport: "tcp", - }, - } - set := receivertest.NewNopCreateSettings() - tReceiver, err := factory.CreateTracesReceiver(context.Background(), set, cfg, nil) - assert.NoError(t, err, "receiver creation failed") - assert.NotNil(t, tReceiver, "receiver creation failed") - - mReceiver, err := factory.CreateMetricsReceiver(context.Background(), set, cfg, nil) - assert.Equal(t, err, component.ErrDataTypeIsNotSupported) - assert.Nil(t, mReceiver) -} - -func TestCreateReceiverGeneralConfig(t *testing.T) { - cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) - require.NoError(t, err) - factory := NewFactory() - cfg := factory.CreateDefaultConfig() - - sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "customname").String()) - require.NoError(t, err) - require.NoError(t, component.UnmarshalConfig(sub, cfg)) - - set := receivertest.NewNopCreateSettings() - tReceiver, err := factory.CreateTracesReceiver(context.Background(), set, cfg, nil) - assert.NoError(t, err, "receiver creation failed") - assert.NotNil(t, tReceiver, "receiver creation failed") - - mReceiver, err := factory.CreateMetricsReceiver(context.Background(), set, cfg, nil) - assert.Equal(t, err, component.ErrDataTypeIsNotSupported) - assert.Nil(t, mReceiver) -} - -// default ports retrieved from https://www.jaegertracing.io/docs/1.16/deployment/ -func TestCreateDefaultGRPCEndpoint(t *testing.T) { - factory := NewFactory() - cfg := factory.CreateDefaultConfig() - - cfg.(*Config).Protocols.GRPC = &configgrpc.GRPCServerSettings{ - NetAddr: confignet.NetAddr{ - Endpoint: defaultGRPCBindEndpoint, - Transport: "tcp", - }, - } - set := receivertest.NewNopCreateSettings() - r, err := factory.CreateTracesReceiver(context.Background(), set, cfg, nil) - - assert.NoError(t, err, "unexpected error creating receiver") - assert.Equal(t, defaultGRPCBindEndpoint, r.(*jReceiver).config.CollectorGRPCServerSettings.NetAddr.Endpoint, "grpc port should be default") -} - -func TestCreateTLSGPRCEndpoint(t *testing.T) { - factory := NewFactory() - cfg := factory.CreateDefaultConfig() - - cfg.(*Config).Protocols.GRPC = &configgrpc.GRPCServerSettings{ - NetAddr: confignet.NetAddr{ - Endpoint: defaultGRPCBindEndpoint, - Transport: "tcp", - }, - TLSSetting: &configtls.TLSServerSetting{ - TLSSetting: configtls.TLSSetting{ - CertFile: "./testdata/server.crt", - KeyFile: "./testdata/server.key", - }, - }, - } - set := receivertest.NewNopCreateSettings() - - _, err := factory.CreateTracesReceiver(context.Background(), set, cfg, nil) - assert.NoError(t, err, "tls-enabled receiver creation failed") -} - -func TestCreateTLSThriftHTTPEndpoint(t *testing.T) { - factory := NewFactory() - cfg := factory.CreateDefaultConfig() - - cfg.(*Config).Protocols.ThriftHTTP = &confighttp.HTTPServerSettings{ - Endpoint: defaultHTTPBindEndpoint, - TLSSetting: &configtls.TLSServerSetting{ - TLSSetting: configtls.TLSSetting{ - CertFile: "./testdata/server.crt", - KeyFile: "./testdata/server.key", - }, - }, - } - - set := receivertest.NewNopCreateSettings() - - _, err := factory.CreateTracesReceiver(context.Background(), set, cfg, nil) - assert.NoError(t, err, "tls-enabled receiver creation failed") -} - -func TestCreateInvalidHTTPEndpoint(t *testing.T) { - factory := NewFactory() - cfg := factory.CreateDefaultConfig() - - set := receivertest.NewNopCreateSettings() - r, err := factory.CreateTracesReceiver(context.Background(), set, cfg, nil) - - assert.NoError(t, err, "unexpected error creating receiver") - assert.Equal(t, defaultHTTPBindEndpoint, r.(*jReceiver).config.CollectorHTTPSettings.Endpoint, "http port should be default") -} - -func TestCreateInvalidThriftBinaryEndpoint(t *testing.T) { - factory := NewFactory() - cfg := factory.CreateDefaultConfig() - - cfg.(*Config).Protocols.ThriftBinary = &ProtocolUDP{ - Endpoint: defaultThriftBinaryBindEndpoint, - } - set := receivertest.NewNopCreateSettings() - r, err := factory.CreateTracesReceiver(context.Background(), set, cfg, nil) - - assert.NoError(t, err, "unexpected error creating receiver") - assert.Equal(t, defaultThriftBinaryBindEndpoint, r.(*jReceiver).config.AgentBinaryThrift.Endpoint, "thrift port should be default") -} - -func TestCreateInvalidThriftCompactEndpoint(t *testing.T) { - factory := NewFactory() - cfg := factory.CreateDefaultConfig() - - cfg.(*Config).Protocols.ThriftCompact = &ProtocolUDP{ - Endpoint: defaultThriftCompactBindEndpoint, - } - set := receivertest.NewNopCreateSettings() - r, err := factory.CreateTracesReceiver(context.Background(), set, cfg, nil) - - assert.NoError(t, err, "unexpected error creating receiver") - assert.Equal(t, defaultThriftCompactBindEndpoint, r.(*jReceiver).config.AgentCompactThrift.Endpoint, "thrift port should be default") -} diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/clientcfghttp/cfgmgr.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/clientcfghttp/cfgmgr.go deleted file mode 100644 index c4132a8126ad..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/clientcfghttp/cfgmgr.go +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 -// -// Copyright (c) 2020 The Jaeger Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientcfghttp // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/clientcfghttp" - -import ( - "context" - "errors" - - "github.com/jaegertracing/jaeger/thrift-gen/baggage" - "github.com/jaegertracing/jaeger/thrift-gen/sampling" - - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/strategystore" -) - -// ConfigManager implements ClientConfigManager. -type ConfigManager struct { - SamplingStrategyStore strategystore.StrategyStore - BaggageManager baggage.BaggageRestrictionManager -} - -// GetSamplingStrategy implements ClientConfigManager.GetSamplingStrategy. -func (c *ConfigManager) GetSamplingStrategy(ctx context.Context, serviceName string) (*sampling.SamplingStrategyResponse, error) { - return c.SamplingStrategyStore.GetSamplingStrategy(ctx, serviceName) -} - -// GetBaggageRestrictions implements ClientConfigManager.GetBaggageRestrictions. -func (c *ConfigManager) GetBaggageRestrictions(ctx context.Context, serviceName string) ([]*baggage.BaggageRestriction, error) { - if c.BaggageManager == nil { - return nil, errors.New("baggage restrictions not implemented") - } - return c.BaggageManager.GetBaggageRestrictions(ctx, serviceName) -} diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/clientcfghttp/cfgmgr_test.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/clientcfghttp/cfgmgr_test.go deleted file mode 100644 index e510385c5527..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/clientcfghttp/cfgmgr_test.go +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 -// -// Copyright (c) 2020 The Jaeger Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientcfghttp - -import ( - "context" - "errors" - "testing" - - "github.com/jaegertracing/jaeger/thrift-gen/baggage" - "github.com/jaegertracing/jaeger/thrift-gen/sampling" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -type mockSamplingStore struct { - samplingResponse *sampling.SamplingStrategyResponse -} - -func (m *mockSamplingStore) GetSamplingStrategy(_ context.Context, _ string) (*sampling.SamplingStrategyResponse, error) { - if m.samplingResponse == nil { - return nil, errors.New("no mock response provided") - } - return m.samplingResponse, nil -} - -type mockBaggageMgr struct { - baggageResponse []*baggage.BaggageRestriction -} - -func (m *mockBaggageMgr) GetBaggageRestrictions(_ context.Context, _ string) ([]*baggage.BaggageRestriction, error) { - if m.baggageResponse == nil { - return nil, errors.New("no mock response provided") - } - return m.baggageResponse, nil -} - -func TestConfigManager(t *testing.T) { - bgm := &mockBaggageMgr{} - mgr := &ConfigManager{ - SamplingStrategyStore: &mockSamplingStore{ - samplingResponse: &sampling.SamplingStrategyResponse{}, - }, - BaggageManager: bgm, - } - t.Run("GetSamplingStrategy", func(t *testing.T) { - r, err := mgr.GetSamplingStrategy(context.Background(), "foo") - require.NoError(t, err) - assert.Equal(t, sampling.SamplingStrategyResponse{}, *r) - }) - t.Run("GetBaggageRestrictions", func(t *testing.T) { - expResp := []*baggage.BaggageRestriction{} - bgm.baggageResponse = expResp - r, err := mgr.GetBaggageRestrictions(context.Background(), "foo") - require.NoError(t, err) - assert.Equal(t, expResp, r) - }) - t.Run("GetBaggageRestrictionsError", func(t *testing.T) { - mgr.BaggageManager = nil - _, err := mgr.GetBaggageRestrictions(context.Background(), "foo") - assert.EqualError(t, err, "baggage restrictions not implemented") - }) -} diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/clientcfghttp/handler.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/clientcfghttp/handler.go deleted file mode 100644 index 828481b385ae..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/clientcfghttp/handler.go +++ /dev/null @@ -1,199 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 -// -// Copyright (c) 2019 The Jaeger Authors. -// Copyright (c) 2017 Uber Technologies, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientcfghttp // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/clientcfghttp" - -import ( - "encoding/json" - "errors" - "fmt" - "net/http" - "strings" - - "github.com/gorilla/mux" - "github.com/jaegertracing/jaeger/pkg/metrics" - tSampling "github.com/jaegertracing/jaeger/thrift-gen/sampling" - - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/configmanager" -) - -const mimeTypeApplicationJSON = "application/json" - -var errBadRequest = errors.New("bad request") - -// HTTPHandlerParams contains parameters that must be passed to NewHTTPHandler. -type HTTPHandlerParams struct { - ConfigManager configmanager.ClientConfigManager // required - MetricsFactory metrics.Factory // required - - // BasePath will be used as a prefix for the endpoints, e.g. "/api" - BasePath string - - // LegacySamplingEndpoint enables returning sampling strategy from "/" endpoint - // using Thrift 0.9.2 enum codes. - LegacySamplingEndpoint bool -} - -// HTTPHandler implements endpoints for used by Jaeger clients to retrieve client configuration, -// such as sampling and baggage restrictions. -type HTTPHandler struct { - params HTTPHandlerParams - metrics struct { - // Number of good sampling requests - SamplingRequestSuccess metrics.Counter `metric:"http-server.requests" tags:"type=sampling"` - - // Number of good sampling requests against the old endpoint / using Thrift 0.9.2 enum codes - LegacySamplingRequestSuccess metrics.Counter `metric:"http-server.requests" tags:"type=sampling-legacy"` - - // Number of good baggage requests - BaggageRequestSuccess metrics.Counter `metric:"http-server.requests" tags:"type=baggage"` - - // Number of bad requests (400s) - BadRequest metrics.Counter `metric:"http-server.errors" tags:"status=4xx,source=all"` - - // Number of collector proxy failures - CollectorProxyFailures metrics.Counter `metric:"http-server.errors" tags:"status=5xx,source=collector-proxy"` - - // Number of bad responses due to malformed thrift - BadThriftFailures metrics.Counter `metric:"http-server.errors" tags:"status=5xx,source=thrift"` - - // Number of failed response writes from http server - WriteFailures metrics.Counter `metric:"http-server.errors" tags:"status=5xx,source=write"` - } -} - -// NewHTTPHandler creates new HTTPHandler. -func NewHTTPHandler(params HTTPHandlerParams) *HTTPHandler { - handler := &HTTPHandler{params: params} - metrics.MustInit(&handler.metrics, params.MetricsFactory, nil) - return handler -} - -// RegisterRoutes registers configuration handlers with Gorilla Router. -func (h *HTTPHandler) RegisterRoutes(router *mux.Router) { - prefix := h.params.BasePath - if h.params.LegacySamplingEndpoint { - router.HandleFunc(prefix+"/", func(w http.ResponseWriter, r *http.Request) { - h.serveSamplingHTTP(w, r, true /* thriftEnums092 */) - }).Methods(http.MethodGet) - } - - router.HandleFunc(prefix+"/sampling", func(w http.ResponseWriter, r *http.Request) { - h.serveSamplingHTTP(w, r, false /* thriftEnums092 */) - }).Methods(http.MethodGet) - - router.HandleFunc(prefix+"/baggageRestrictions", func(w http.ResponseWriter, r *http.Request) { - h.serveBaggageHTTP(w, r) - }).Methods(http.MethodGet) -} - -func (h *HTTPHandler) serviceFromRequest(w http.ResponseWriter, r *http.Request) (string, error) { - services := r.URL.Query()["service"] - if len(services) != 1 { - h.metrics.BadRequest.Inc(1) - http.Error(w, "'service' parameter must be provided once", http.StatusBadRequest) - return "", errBadRequest - } - return services[0], nil -} - -func (h *HTTPHandler) writeJSON(w http.ResponseWriter, json []byte) error { - w.Header().Add("Content-Type", mimeTypeApplicationJSON) - if _, err := w.Write(json); err != nil { - h.metrics.WriteFailures.Inc(1) - return err - } - return nil -} - -func (h *HTTPHandler) serveSamplingHTTP(w http.ResponseWriter, r *http.Request, thriftEnums092 bool) { - service, err := h.serviceFromRequest(w, r) - if err != nil { - return - } - resp, err := h.params.ConfigManager.GetSamplingStrategy(r.Context(), service) - if err != nil { - h.metrics.CollectorProxyFailures.Inc(1) - http.Error(w, fmt.Sprintf("collector error: %+v", err), http.StatusInternalServerError) - return - } - jsonBytes, err := json.Marshal(resp) - if err != nil { - h.metrics.BadThriftFailures.Inc(1) - http.Error(w, "cannot marshall Thrift to JSON", http.StatusInternalServerError) - return - } - if thriftEnums092 { - jsonBytes = h.encodeThriftEnums092(jsonBytes) - } - if err = h.writeJSON(w, jsonBytes); err != nil { - return - } - if thriftEnums092 { - h.metrics.LegacySamplingRequestSuccess.Inc(1) - } else { - h.metrics.SamplingRequestSuccess.Inc(1) - } -} - -func (h *HTTPHandler) serveBaggageHTTP(w http.ResponseWriter, r *http.Request) { - service, err := h.serviceFromRequest(w, r) - if err != nil { - return - } - resp, err := h.params.ConfigManager.GetBaggageRestrictions(r.Context(), service) - if err != nil { - h.metrics.CollectorProxyFailures.Inc(1) - http.Error(w, fmt.Sprintf("collector error: %+v", err), http.StatusInternalServerError) - return - } - // NB. it's literally impossible for this Marshal to fail - jsonBytes, _ := json.Marshal(resp) - if err = h.writeJSON(w, jsonBytes); err != nil { - return - } - h.metrics.BaggageRequestSuccess.Inc(1) -} - -var samplingStrategyTypes = []tSampling.SamplingStrategyType{ - tSampling.SamplingStrategyType_PROBABILISTIC, - tSampling.SamplingStrategyType_RATE_LIMITING, -} - -// Replace string enum values produced from Thrift 0.9.3 generated classes -// with integer codes produced from Thrift 0.9.2 generated classes. -// -// For example: -// -// Thrift 0.9.2 classes generate this JSON: -// {"strategyType":0,"probabilisticSampling":{"samplingRate":0.5},"rateLimitingSampling":null,"operationSampling":null} -// -// Thrift 0.9.3 classes generate this JSON: -// {"strategyType":"PROBABILISTIC","probabilisticSampling":{"samplingRate":0.5}} -func (h *HTTPHandler) encodeThriftEnums092(json []byte) []byte { - str := string(json) - for _, strategyType := range samplingStrategyTypes { - str = strings.Replace( - str, - fmt.Sprintf(`"strategyType":"%s"`, strategyType.String()), - fmt.Sprintf(`"strategyType":%d`, strategyType), - 1, - ) - } - return []byte(str) -} diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/clientcfghttp/thrift-0.9.2/.nocover b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/clientcfghttp/thrift-0.9.2/.nocover deleted file mode 100644 index 152f4437a158..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/clientcfghttp/thrift-0.9.2/.nocover +++ /dev/null @@ -1 +0,0 @@ -Thrift-generated files diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/clientcfghttp/thrift-0.9.2/constants.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/clientcfghttp/thrift-0.9.2/constants.go deleted file mode 100644 index 4486e3c2db91..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/clientcfghttp/thrift-0.9.2/constants.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 -// -// Copyright (c) 2019 The Jaeger Authors. -// Copyright (c) 2017 Uber Technologies, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Autogenerated by Thrift Compiler (0.9.2) -// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - -package sampling - -import ( - "bytes" - "fmt" - - "github.com/apache/thrift/lib/go/thrift" -) - -// (needed to ensure safety because of naive import list construction.) -var _ = thrift.ZERO -var _ = fmt.Printf -var _ = bytes.Equal - -func init() { -} diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/clientcfghttp/thrift-0.9.2/ttypes.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/clientcfghttp/thrift-0.9.2/ttypes.go deleted file mode 100644 index 1a2724652a03..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/clientcfghttp/thrift-0.9.2/ttypes.go +++ /dev/null @@ -1,790 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 -// -// Copyright (c) 2019 The Jaeger Authors. -// Copyright (c) 2017 Uber Technologies, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Autogenerated by Thrift Compiler (0.9.2) but manually adapted to 0.14.x - -// nolint -package sampling // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/clientcfghttp/thrift-0.9.2" - -import ( - "bytes" - "context" - "fmt" - - "github.com/apache/thrift/lib/go/thrift" -) - -// (needed to ensure safety because of naive import list construction.) -var _ = thrift.ZERO -var _ = fmt.Printf -var _ = bytes.Equal - -var GoUnusedProtection__ int - -type SamplingStrategyType int64 - -const ( - SamplingStrategyType_PROBABILISTIC SamplingStrategyType = 0 - SamplingStrategyType_RATE_LIMITING SamplingStrategyType = 1 -) - -func (p SamplingStrategyType) String() string { - switch p { - case SamplingStrategyType_PROBABILISTIC: - return "SamplingStrategyType_PROBABILISTIC" - case SamplingStrategyType_RATE_LIMITING: - return "SamplingStrategyType_RATE_LIMITING" - } - return "" -} - -func SamplingStrategyTypeFromString(s string) (SamplingStrategyType, error) { - switch s { - case "SamplingStrategyType_PROBABILISTIC": - return SamplingStrategyType_PROBABILISTIC, nil - case "SamplingStrategyType_RATE_LIMITING": - return SamplingStrategyType_RATE_LIMITING, nil - } - return SamplingStrategyType(0), fmt.Errorf("not a valid SamplingStrategyType string") -} - -func SamplingStrategyTypePtr(v SamplingStrategyType) *SamplingStrategyType { return &v } - -type ProbabilisticSamplingStrategy struct { - SamplingRate float64 `thrift:"samplingRate,1,required" json:"samplingRate"` -} - -func NewProbabilisticSamplingStrategy() *ProbabilisticSamplingStrategy { - return &ProbabilisticSamplingStrategy{} -} - -func (p *ProbabilisticSamplingStrategy) GetSamplingRate() float64 { - return p.SamplingRate -} -func (p *ProbabilisticSamplingStrategy) Read(iprot thrift.TProtocol) error { - ctx := context.Background() - if _, err := iprot.ReadStructBegin(ctx); err != nil { - return fmt.Errorf("%T read error: %s", p, err) - } - for { - _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx) - if err != nil { - return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) - } - if fieldTypeId == thrift.STOP { - break - } - switch fieldId { - case 1: - if err := p.ReadField1(iprot); err != nil { - return err - } - default: - if err := iprot.Skip(ctx, fieldTypeId); err != nil { - return err - } - } - if err := iprot.ReadFieldEnd(ctx); err != nil { - return err - } - } - if err := iprot.ReadStructEnd(ctx); err != nil { - return fmt.Errorf("%T read struct end error: %s", p, err) - } - return nil -} - -func (p *ProbabilisticSamplingStrategy) ReadField1(iprot thrift.TProtocol) error { - if v, err := iprot.ReadDouble(context.Background()); err != nil { - return fmt.Errorf("error reading field 1: %s", err) - } else { - p.SamplingRate = v - } - return nil -} - -func (p *ProbabilisticSamplingStrategy) Write(oprot thrift.TProtocol) error { - ctx := context.Background() - if err := oprot.WriteStructBegin(ctx, "ProbabilisticSamplingStrategy"); err != nil { - return fmt.Errorf("%T write struct begin error: %s", p, err) - } - if err := p.writeField1(oprot); err != nil { - return err - } - if err := oprot.WriteFieldStop(ctx); err != nil { - return fmt.Errorf("write field stop error: %s", err) - } - if err := oprot.WriteStructEnd(ctx); err != nil { - return fmt.Errorf("write struct stop error: %s", err) - } - return nil -} - -func (p *ProbabilisticSamplingStrategy) writeField1(oprot thrift.TProtocol) (err error) { - ctx := context.Background() - if err := oprot.WriteFieldBegin(ctx, "samplingRate", thrift.DOUBLE, 1); err != nil { - return fmt.Errorf("%T write field begin error 1:samplingRate: %s", p, err) - } - if err := oprot.WriteDouble(ctx, float64(p.SamplingRate)); err != nil { - return fmt.Errorf("%T.samplingRate (1) field write error: %s", p, err) - } - if err := oprot.WriteFieldEnd(ctx); err != nil { - return fmt.Errorf("%T write field end error 1:samplingRate: %s", p, err) - } - return err -} - -func (p *ProbabilisticSamplingStrategy) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("ProbabilisticSamplingStrategy(%+v)", *p) -} - -type RateLimitingSamplingStrategy struct { - MaxTracesPerSecond int16 `thrift:"maxTracesPerSecond,1,required" json:"maxTracesPerSecond"` -} - -func NewRateLimitingSamplingStrategy() *RateLimitingSamplingStrategy { - return &RateLimitingSamplingStrategy{} -} - -func (p *RateLimitingSamplingStrategy) GetMaxTracesPerSecond() int16 { - return p.MaxTracesPerSecond -} -func (p *RateLimitingSamplingStrategy) Read(iprot thrift.TProtocol) error { - ctx := context.Background() - if _, err := iprot.ReadStructBegin(ctx); err != nil { - return fmt.Errorf("%T read error: %s", p, err) - } - for { - _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx) - if err != nil { - return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) - } - if fieldTypeId == thrift.STOP { - break - } - switch fieldId { - case 1: - if err := p.ReadField1(iprot); err != nil { - return err - } - default: - if err := iprot.Skip(ctx, fieldTypeId); err != nil { - return err - } - } - if err := iprot.ReadFieldEnd(ctx); err != nil { - return err - } - } - if err := iprot.ReadStructEnd(ctx); err != nil { - return fmt.Errorf("%T read struct end error: %s", p, err) - } - return nil -} - -func (p *RateLimitingSamplingStrategy) ReadField1(iprot thrift.TProtocol) error { - if v, err := iprot.ReadI16(context.Background()); err != nil { - return fmt.Errorf("error reading field 1: %s", err) - } else { - p.MaxTracesPerSecond = v - } - return nil -} - -func (p *RateLimitingSamplingStrategy) Write(oprot thrift.TProtocol) error { - ctx := context.Background() - if err := oprot.WriteStructBegin(ctx, "RateLimitingSamplingStrategy"); err != nil { - return fmt.Errorf("%T write struct begin error: %s", p, err) - } - if err := p.writeField1(oprot); err != nil { - return err - } - if err := oprot.WriteFieldStop(ctx); err != nil { - return fmt.Errorf("write field stop error: %s", err) - } - if err := oprot.WriteStructEnd(ctx); err != nil { - return fmt.Errorf("write struct stop error: %s", err) - } - return nil -} - -func (p *RateLimitingSamplingStrategy) writeField1(oprot thrift.TProtocol) (err error) { - ctx := context.Background() - if err := oprot.WriteFieldBegin(ctx, "maxTracesPerSecond", thrift.I16, 1); err != nil { - return fmt.Errorf("%T write field begin error 1:maxTracesPerSecond: %s", p, err) - } - if err := oprot.WriteI16(ctx, int16(p.MaxTracesPerSecond)); err != nil { - return fmt.Errorf("%T.maxTracesPerSecond (1) field write error: %s", p, err) - } - if err := oprot.WriteFieldEnd(ctx); err != nil { - return fmt.Errorf("%T write field end error 1:maxTracesPerSecond: %s", p, err) - } - return err -} - -func (p *RateLimitingSamplingStrategy) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("RateLimitingSamplingStrategy(%+v)", *p) -} - -type OperationSamplingStrategy struct { - Operation string `thrift:"operation,1,required" json:"operation"` - ProbabilisticSampling *ProbabilisticSamplingStrategy `thrift:"probabilisticSampling,2,required" json:"probabilisticSampling"` -} - -func NewOperationSamplingStrategy() *OperationSamplingStrategy { - return &OperationSamplingStrategy{} -} - -func (p *OperationSamplingStrategy) GetOperation() string { - return p.Operation -} - -var OperationSamplingStrategy_ProbabilisticSampling_DEFAULT *ProbabilisticSamplingStrategy - -func (p *OperationSamplingStrategy) GetProbabilisticSampling() *ProbabilisticSamplingStrategy { - if !p.IsSetProbabilisticSampling() { - return OperationSamplingStrategy_ProbabilisticSampling_DEFAULT - } - return p.ProbabilisticSampling -} -func (p *OperationSamplingStrategy) IsSetProbabilisticSampling() bool { - return p.ProbabilisticSampling != nil -} - -func (p *OperationSamplingStrategy) Read(iprot thrift.TProtocol) error { - ctx := context.Background() - if _, err := iprot.ReadStructBegin(ctx); err != nil { - return fmt.Errorf("%T read error: %s", p, err) - } - for { - _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx) - if err != nil { - return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) - } - if fieldTypeId == thrift.STOP { - break - } - switch fieldId { - case 1: - if err := p.ReadField1(iprot); err != nil { - return err - } - case 2: - if err := p.ReadField2(iprot); err != nil { - return err - } - default: - if err := iprot.Skip(ctx, fieldTypeId); err != nil { - return err - } - } - if err := iprot.ReadFieldEnd(ctx); err != nil { - return err - } - } - if err := iprot.ReadStructEnd(ctx); err != nil { - return fmt.Errorf("%T read struct end error: %s", p, err) - } - return nil -} - -func (p *OperationSamplingStrategy) ReadField1(iprot thrift.TProtocol) error { - if v, err := iprot.ReadString(context.Background()); err != nil { - return fmt.Errorf("error reading field 1: %s", err) - } else { - p.Operation = v - } - return nil -} - -func (p *OperationSamplingStrategy) ReadField2(iprot thrift.TProtocol) error { - p.ProbabilisticSampling = &ProbabilisticSamplingStrategy{} - if err := p.ProbabilisticSampling.Read(iprot); err != nil { - return fmt.Errorf("%T error reading struct: %s", p.ProbabilisticSampling, err) - } - return nil -} - -func (p *OperationSamplingStrategy) Write(oprot thrift.TProtocol) error { - ctx := context.Background() - if err := oprot.WriteStructBegin(ctx, "OperationSamplingStrategy"); err != nil { - return fmt.Errorf("%T write struct begin error: %s", p, err) - } - if err := p.writeField1(oprot); err != nil { - return err - } - if err := p.writeField2(oprot); err != nil { - return err - } - if err := oprot.WriteFieldStop(ctx); err != nil { - return fmt.Errorf("write field stop error: %s", err) - } - if err := oprot.WriteStructEnd(ctx); err != nil { - return fmt.Errorf("write struct stop error: %s", err) - } - return nil -} - -func (p *OperationSamplingStrategy) writeField1(oprot thrift.TProtocol) (err error) { - ctx := context.Background() - if err := oprot.WriteFieldBegin(ctx, "operation", thrift.STRING, 1); err != nil { - return fmt.Errorf("%T write field begin error 1:operation: %s", p, err) - } - if err := oprot.WriteString(ctx, string(p.Operation)); err != nil { - return fmt.Errorf("%T.operation (1) field write error: %s", p, err) - } - if err := oprot.WriteFieldEnd(ctx); err != nil { - return fmt.Errorf("%T write field end error 1:operation: %s", p, err) - } - return err -} - -func (p *OperationSamplingStrategy) writeField2(oprot thrift.TProtocol) (err error) { - ctx := context.Background() - if err := oprot.WriteFieldBegin(ctx, "probabilisticSampling", thrift.STRUCT, 2); err != nil { - return fmt.Errorf("%T write field begin error 2:probabilisticSampling: %s", p, err) - } - if err := p.ProbabilisticSampling.Write(oprot); err != nil { - return fmt.Errorf("%T error writing struct: %s", p.ProbabilisticSampling, err) - } - if err := oprot.WriteFieldEnd(ctx); err != nil { - return fmt.Errorf("%T write field end error 2:probabilisticSampling: %s", p, err) - } - return err -} - -func (p *OperationSamplingStrategy) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("OperationSamplingStrategy(%+v)", *p) -} - -type PerOperationSamplingStrategies struct { - DefaultSamplingProbability float64 `thrift:"defaultSamplingProbability,1,required" json:"defaultSamplingProbability"` - DefaultLowerBoundTracesPerSecond float64 `thrift:"defaultLowerBoundTracesPerSecond,2,required" json:"defaultLowerBoundTracesPerSecond"` - PerOperationStrategies []*OperationSamplingStrategy `thrift:"perOperationStrategies,3,required" json:"perOperationStrategies"` -} - -func NewPerOperationSamplingStrategies() *PerOperationSamplingStrategies { - return &PerOperationSamplingStrategies{} -} - -func (p *PerOperationSamplingStrategies) GetDefaultSamplingProbability() float64 { - return p.DefaultSamplingProbability -} - -func (p *PerOperationSamplingStrategies) GetDefaultLowerBoundTracesPerSecond() float64 { - return p.DefaultLowerBoundTracesPerSecond -} - -func (p *PerOperationSamplingStrategies) GetPerOperationStrategies() []*OperationSamplingStrategy { - return p.PerOperationStrategies -} -func (p *PerOperationSamplingStrategies) Read(iprot thrift.TProtocol) error { - ctx := context.Background() - if _, err := iprot.ReadStructBegin(ctx); err != nil { - return fmt.Errorf("%T read error: %s", p, err) - } - for { - _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx) - if err != nil { - return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) - } - if fieldTypeId == thrift.STOP { - break - } - switch fieldId { - case 1: - if err := p.ReadField1(iprot); err != nil { - return err - } - case 2: - if err := p.ReadField2(iprot); err != nil { - return err - } - case 3: - if err := p.ReadField3(iprot); err != nil { - return err - } - default: - if err := iprot.Skip(ctx, fieldTypeId); err != nil { - return err - } - } - if err := iprot.ReadFieldEnd(ctx); err != nil { - return err - } - } - if err := iprot.ReadStructEnd(ctx); err != nil { - return fmt.Errorf("%T read struct end error: %s", p, err) - } - return nil -} - -func (p *PerOperationSamplingStrategies) ReadField1(iprot thrift.TProtocol) error { - if v, err := iprot.ReadDouble(context.Background()); err != nil { - return fmt.Errorf("error reading field 1: %s", err) - } else { - p.DefaultSamplingProbability = v - } - return nil -} - -func (p *PerOperationSamplingStrategies) ReadField2(iprot thrift.TProtocol) error { - if v, err := iprot.ReadDouble(context.Background()); err != nil { - return fmt.Errorf("error reading field 2: %s", err) - } else { - p.DefaultLowerBoundTracesPerSecond = v - } - return nil -} - -func (p *PerOperationSamplingStrategies) ReadField3(iprot thrift.TProtocol) error { - ctx := context.Background() - _, size, err := iprot.ReadListBegin(ctx) - if err != nil { - return fmt.Errorf("error reading list begin: %s", err) - } - tSlice := make([]*OperationSamplingStrategy, 0, size) - p.PerOperationStrategies = tSlice - for i := 0; i < size; i++ { - _elem0 := &OperationSamplingStrategy{} - if err := _elem0.Read(iprot); err != nil { - return fmt.Errorf("%T error reading struct: %s", _elem0, err) - } - p.PerOperationStrategies = append(p.PerOperationStrategies, _elem0) - } - if err := iprot.ReadListEnd(ctx); err != nil { - return fmt.Errorf("error reading list end: %s", err) - } - return nil -} - -func (p *PerOperationSamplingStrategies) Write(oprot thrift.TProtocol) error { - ctx := context.Background() - if err := oprot.WriteStructBegin(ctx, "PerOperationSamplingStrategies"); err != nil { - return fmt.Errorf("%T write struct begin error: %s", p, err) - } - if err := p.writeField1(oprot); err != nil { - return err - } - if err := p.writeField2(oprot); err != nil { - return err - } - if err := p.writeField3(oprot); err != nil { - return err - } - if err := oprot.WriteFieldStop(ctx); err != nil { - return fmt.Errorf("write field stop error: %s", err) - } - if err := oprot.WriteStructEnd(ctx); err != nil { - return fmt.Errorf("write struct stop error: %s", err) - } - return nil -} - -func (p *PerOperationSamplingStrategies) writeField1(oprot thrift.TProtocol) (err error) { - ctx := context.Background() - if err := oprot.WriteFieldBegin(ctx, "defaultSamplingProbability", thrift.DOUBLE, 1); err != nil { - return fmt.Errorf("%T write field begin error 1:defaultSamplingProbability: %s", p, err) - } - if err := oprot.WriteDouble(ctx, float64(p.DefaultSamplingProbability)); err != nil { - return fmt.Errorf("%T.defaultSamplingProbability (1) field write error: %s", p, err) - } - if err := oprot.WriteFieldEnd(ctx); err != nil { - return fmt.Errorf("%T write field end error 1:defaultSamplingProbability: %s", p, err) - } - return err -} - -func (p *PerOperationSamplingStrategies) writeField2(oprot thrift.TProtocol) (err error) { - ctx := context.Background() - if err := oprot.WriteFieldBegin(ctx, "defaultLowerBoundTracesPerSecond", thrift.DOUBLE, 2); err != nil { - return fmt.Errorf("%T write field begin error 2:defaultLowerBoundTracesPerSecond: %s", p, err) - } - if err := oprot.WriteDouble(ctx, float64(p.DefaultLowerBoundTracesPerSecond)); err != nil { - return fmt.Errorf("%T.defaultLowerBoundTracesPerSecond (2) field write error: %s", p, err) - } - if err := oprot.WriteFieldEnd(ctx); err != nil { - return fmt.Errorf("%T write field end error 2:defaultLowerBoundTracesPerSecond: %s", p, err) - } - return err -} - -func (p *PerOperationSamplingStrategies) writeField3(oprot thrift.TProtocol) (err error) { - ctx := context.Background() - if err := oprot.WriteFieldBegin(ctx, "perOperationStrategies", thrift.LIST, 3); err != nil { - return fmt.Errorf("%T write field begin error 3:perOperationStrategies: %s", p, err) - } - if err := oprot.WriteListBegin(ctx, thrift.STRUCT, len(p.PerOperationStrategies)); err != nil { - return fmt.Errorf("error writing list begin: %s", err) - } - for _, v := range p.PerOperationStrategies { - if err := v.Write(oprot); err != nil { - return fmt.Errorf("%T error writing struct: %s", v, err) - } - } - if err := oprot.WriteListEnd(ctx); err != nil { - return fmt.Errorf("error writing list end: %s", err) - } - if err := oprot.WriteFieldEnd(ctx); err != nil { - return fmt.Errorf("%T write field end error 3:perOperationStrategies: %s", p, err) - } - return err -} - -func (p *PerOperationSamplingStrategies) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("PerOperationSamplingStrategies(%+v)", *p) -} - -type SamplingStrategyResponse struct { - StrategyType SamplingStrategyType `thrift:"strategyType,1,required" json:"strategyType"` - ProbabilisticSampling *ProbabilisticSamplingStrategy `thrift:"probabilisticSampling,2" json:"probabilisticSampling"` - RateLimitingSampling *RateLimitingSamplingStrategy `thrift:"rateLimitingSampling,3" json:"rateLimitingSampling"` - OperationSampling *PerOperationSamplingStrategies `thrift:"operationSampling,4" json:"operationSampling"` -} - -func NewSamplingStrategyResponse() *SamplingStrategyResponse { - return &SamplingStrategyResponse{} -} - -func (p *SamplingStrategyResponse) GetStrategyType() SamplingStrategyType { - return p.StrategyType -} - -var SamplingStrategyResponse_ProbabilisticSampling_DEFAULT *ProbabilisticSamplingStrategy - -func (p *SamplingStrategyResponse) GetProbabilisticSampling() *ProbabilisticSamplingStrategy { - if !p.IsSetProbabilisticSampling() { - return SamplingStrategyResponse_ProbabilisticSampling_DEFAULT - } - return p.ProbabilisticSampling -} - -var SamplingStrategyResponse_RateLimitingSampling_DEFAULT *RateLimitingSamplingStrategy - -func (p *SamplingStrategyResponse) GetRateLimitingSampling() *RateLimitingSamplingStrategy { - if !p.IsSetRateLimitingSampling() { - return SamplingStrategyResponse_RateLimitingSampling_DEFAULT - } - return p.RateLimitingSampling -} - -var SamplingStrategyResponse_OperationSampling_DEFAULT *PerOperationSamplingStrategies - -func (p *SamplingStrategyResponse) GetOperationSampling() *PerOperationSamplingStrategies { - if !p.IsSetOperationSampling() { - return SamplingStrategyResponse_OperationSampling_DEFAULT - } - return p.OperationSampling -} -func (p *SamplingStrategyResponse) IsSetProbabilisticSampling() bool { - return p.ProbabilisticSampling != nil -} - -func (p *SamplingStrategyResponse) IsSetRateLimitingSampling() bool { - return p.RateLimitingSampling != nil -} - -func (p *SamplingStrategyResponse) IsSetOperationSampling() bool { - return p.OperationSampling != nil -} - -func (p *SamplingStrategyResponse) Read(iprot thrift.TProtocol) error { - ctx := context.Background() - if _, err := iprot.ReadStructBegin(ctx); err != nil { - return fmt.Errorf("%T read error: %s", p, err) - } - for { - _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx) - if err != nil { - return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) - } - if fieldTypeId == thrift.STOP { - break - } - switch fieldId { - case 1: - if err := p.ReadField1(iprot); err != nil { - return err - } - case 2: - if err := p.ReadField2(iprot); err != nil { - return err - } - case 3: - if err := p.ReadField3(iprot); err != nil { - return err - } - case 4: - if err := p.ReadField4(iprot); err != nil { - return err - } - default: - if err := iprot.Skip(ctx, fieldTypeId); err != nil { - return err - } - } - if err := iprot.ReadFieldEnd(ctx); err != nil { - return err - } - } - if err := iprot.ReadStructEnd(ctx); err != nil { - return fmt.Errorf("%T read struct end error: %s", p, err) - } - return nil -} - -func (p *SamplingStrategyResponse) ReadField1(iprot thrift.TProtocol) error { - if v, err := iprot.ReadI32(context.Background()); err != nil { - return fmt.Errorf("error reading field 1: %s", err) - } else { - temp := SamplingStrategyType(v) - p.StrategyType = temp - } - return nil -} - -func (p *SamplingStrategyResponse) ReadField2(iprot thrift.TProtocol) error { - p.ProbabilisticSampling = &ProbabilisticSamplingStrategy{} - if err := p.ProbabilisticSampling.Read(iprot); err != nil { - return fmt.Errorf("%T error reading struct: %s", p.ProbabilisticSampling, err) - } - return nil -} - -func (p *SamplingStrategyResponse) ReadField3(iprot thrift.TProtocol) error { - p.RateLimitingSampling = &RateLimitingSamplingStrategy{} - if err := p.RateLimitingSampling.Read(iprot); err != nil { - return fmt.Errorf("%T error reading struct: %s", p.RateLimitingSampling, err) - } - return nil -} - -func (p *SamplingStrategyResponse) ReadField4(iprot thrift.TProtocol) error { - p.OperationSampling = &PerOperationSamplingStrategies{} - if err := p.OperationSampling.Read(iprot); err != nil { - return fmt.Errorf("%T error reading struct: %s", p.OperationSampling, err) - } - return nil -} - -func (p *SamplingStrategyResponse) Write(oprot thrift.TProtocol) error { - ctx := context.Background() - if err := oprot.WriteStructBegin(ctx, "SamplingStrategyResponse"); err != nil { - return fmt.Errorf("%T write struct begin error: %s", p, err) - } - if err := p.writeField1(oprot); err != nil { - return err - } - if err := p.writeField2(oprot); err != nil { - return err - } - if err := p.writeField3(oprot); err != nil { - return err - } - if err := p.writeField4(oprot); err != nil { - return err - } - if err := oprot.WriteFieldStop(ctx); err != nil { - return fmt.Errorf("write field stop error: %s", err) - } - if err := oprot.WriteStructEnd(ctx); err != nil { - return fmt.Errorf("write struct stop error: %s", err) - } - return nil -} - -func (p *SamplingStrategyResponse) writeField1(oprot thrift.TProtocol) (err error) { - ctx := context.Background() - if err := oprot.WriteFieldBegin(ctx, "strategyType", thrift.I32, 1); err != nil { - return fmt.Errorf("%T write field begin error 1:strategyType: %s", p, err) - } - if err := oprot.WriteI32(ctx, int32(p.StrategyType)); err != nil { - return fmt.Errorf("%T.strategyType (1) field write error: %s", p, err) - } - if err := oprot.WriteFieldEnd(ctx); err != nil { - return fmt.Errorf("%T write field end error 1:strategyType: %s", p, err) - } - return err -} - -func (p *SamplingStrategyResponse) writeField2(oprot thrift.TProtocol) (err error) { - ctx := context.Background() - if p.IsSetProbabilisticSampling() { - if err := oprot.WriteFieldBegin(ctx, "probabilisticSampling", thrift.STRUCT, 2); err != nil { - return fmt.Errorf("%T write field begin error 2:probabilisticSampling: %s", p, err) - } - if err := p.ProbabilisticSampling.Write(oprot); err != nil { - return fmt.Errorf("%T error writing struct: %s", p.ProbabilisticSampling, err) - } - if err := oprot.WriteFieldEnd(ctx); err != nil { - return fmt.Errorf("%T write field end error 2:probabilisticSampling: %s", p, err) - } - } - return err -} - -func (p *SamplingStrategyResponse) writeField3(oprot thrift.TProtocol) (err error) { - ctx := context.Background() - if p.IsSetRateLimitingSampling() { - if err := oprot.WriteFieldBegin(ctx, "rateLimitingSampling", thrift.STRUCT, 3); err != nil { - return fmt.Errorf("%T write field begin error 3:rateLimitingSampling: %s", p, err) - } - if err := p.RateLimitingSampling.Write(oprot); err != nil { - return fmt.Errorf("%T error writing struct: %s", p.RateLimitingSampling, err) - } - if err := oprot.WriteFieldEnd(ctx); err != nil { - return fmt.Errorf("%T write field end error 3:rateLimitingSampling: %s", p, err) - } - } - return err -} - -func (p *SamplingStrategyResponse) writeField4(oprot thrift.TProtocol) (err error) { - ctx := context.Background() - if p.IsSetOperationSampling() { - if err := oprot.WriteFieldBegin(ctx, "operationSampling", thrift.STRUCT, 4); err != nil { - return fmt.Errorf("%T write field begin error 4:operationSampling: %s", p, err) - } - if err := p.OperationSampling.Write(oprot); err != nil { - return fmt.Errorf("%T error writing struct: %s", p.OperationSampling, err) - } - if err := oprot.WriteFieldEnd(ctx); err != nil { - return fmt.Errorf("%T write field end error 4:operationSampling: %s", p, err) - } - } - return err -} - -func (p *SamplingStrategyResponse) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("SamplingStrategyResponse(%+v)", *p) -} diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/configmanager/grpc/manager.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/configmanager/grpc/manager.go deleted file mode 100644 index 2cb700f76d82..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/configmanager/grpc/manager.go +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 -// -// Copyright (c) 2018 The Jaeger Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package grpc // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/configmanager/grpc" - -import ( - "context" - "errors" - - "github.com/jaegertracing/jaeger/model/converter/thrift/jaeger" - "github.com/jaegertracing/jaeger/proto-gen/api_v2" - "github.com/jaegertracing/jaeger/thrift-gen/baggage" - "github.com/jaegertracing/jaeger/thrift-gen/sampling" - "google.golang.org/grpc" -) - -// SamplingManager returns sampling decisions from collector over gRPC. -type SamplingManager struct { - client api_v2.SamplingManagerClient -} - -// NewConfigManager creates gRPC sampling manager. -func NewConfigManager(conn *grpc.ClientConn) *SamplingManager { - return &SamplingManager{ - client: api_v2.NewSamplingManagerClient(conn), - } -} - -// GetSamplingStrategy returns sampling strategies from collector. -func (s *SamplingManager) GetSamplingStrategy(ctx context.Context, serviceName string) (*sampling.SamplingStrategyResponse, error) { - r, err := s.client.GetSamplingStrategy(ctx, &api_v2.SamplingStrategyParameters{ServiceName: serviceName}) - if err != nil { - return nil, err - } - return jaeger.ConvertSamplingResponseFromDomain(r) -} - -// GetBaggageRestrictions returns baggage restrictions from collector. -func (s *SamplingManager) GetBaggageRestrictions(_ context.Context, _ string) ([]*baggage.BaggageRestriction, error) { - return nil, errors.New("baggage not implemented") -} diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/configmanager/manager.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/configmanager/manager.go deleted file mode 100644 index 5ff87d249ab5..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/configmanager/manager.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 -// -// Copyright (c) 2019 The Jaeger Authors. -// Copyright (c) 2017 Uber Technologies, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package configmanager // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/configmanager" - -import ( - "context" - - "github.com/jaegertracing/jaeger/thrift-gen/baggage" - "github.com/jaegertracing/jaeger/thrift-gen/sampling" -) - -// ClientConfigManager decides: -// 1) which sampling strategy a given service should be using -// 2) which baggage restrictions a given service should be using. -type ClientConfigManager interface { - GetSamplingStrategy(ctx context.Context, serviceName string) (*sampling.SamplingStrategyResponse, error) - GetBaggageRestrictions(ctx context.Context, serviceName string) ([]*baggage.BaggageRestriction, error) -} diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/configmanager/metrics.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/configmanager/metrics.go deleted file mode 100644 index 33a37d12a450..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/configmanager/metrics.go +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 -// -// Copyright (c) 2018 The Jaeger Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package configmanager // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/configmanager" - -import ( - "context" - - "github.com/jaegertracing/jaeger/pkg/metrics" - "github.com/jaegertracing/jaeger/thrift-gen/baggage" - "github.com/jaegertracing/jaeger/thrift-gen/sampling" -) - -// configManagerMetrics holds metrics related to ClientConfigManager -type configManagerMetrics struct { - // Number of successful sampling rate responses from collector - SamplingSuccess metrics.Counter `metric:"collector-proxy" tags:"result=ok,endpoint=sampling"` - - // Number of failed sampling rate responses from collector - SamplingFailures metrics.Counter `metric:"collector-proxy" tags:"result=err,endpoint=sampling"` - - // Number of successful baggage restriction responses from collector - BaggageSuccess metrics.Counter `metric:"collector-proxy" tags:"result=ok,endpoint=baggage"` - - // Number of failed baggage restriction responses from collector - BaggageFailures metrics.Counter `metric:"collector-proxy" tags:"result=err,endpoint=baggage"` -} - -// ManagerWithMetrics is manager with metrics integration. -type ManagerWithMetrics struct { - wrapped ClientConfigManager - metrics configManagerMetrics -} - -// WrapWithMetrics wraps ClientConfigManager and creates metrics for its invocations. -func WrapWithMetrics(manager ClientConfigManager, mFactory metrics.Factory) *ManagerWithMetrics { - m := configManagerMetrics{} - _ = metrics.Init(&m, mFactory, nil) - return &ManagerWithMetrics{wrapped: manager, metrics: m} -} - -// GetSamplingStrategy returns sampling strategy from server. -func (m *ManagerWithMetrics) GetSamplingStrategy(ctx context.Context, serviceName string) (*sampling.SamplingStrategyResponse, error) { - r, err := m.wrapped.GetSamplingStrategy(ctx, serviceName) - if err != nil { - m.metrics.SamplingFailures.Inc(1) - } else { - m.metrics.SamplingSuccess.Inc(1) - } - return r, err -} - -// GetBaggageRestrictions returns baggage restrictions from server. -func (m *ManagerWithMetrics) GetBaggageRestrictions(ctx context.Context, serviceName string) ([]*baggage.BaggageRestriction, error) { - r, err := m.wrapped.GetBaggageRestrictions(ctx, serviceName) - if err != nil { - m.metrics.BaggageFailures.Inc(1) - } else { - m.metrics.BaggageSuccess.Inc(1) - } - return r, err -} diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/httpserver/srv.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/httpserver/srv.go deleted file mode 100644 index f988c8579c60..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/httpserver/srv.go +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 -// -// Copyright (c) 2019 The Jaeger Authors. -// Copyright (c) 2017 Uber Technologies, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package httpserver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/httpserver" - -import ( - "net/http" - "time" - - "github.com/gorilla/mux" - "github.com/jaegertracing/jaeger/pkg/metrics" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" - - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/clientcfghttp" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/configmanager" -) - -// NewHTTPServer creates a new server that hosts an HTTP/JSON endpoint for clients -// to query for sampling strategies and baggage restrictions. -func NewHTTPServer(hostPort string, manager configmanager.ClientConfigManager, mFactory metrics.Factory, logger *zap.Logger) *http.Server { - handler := clientcfghttp.NewHTTPHandler(clientcfghttp.HTTPHandlerParams{ - ConfigManager: manager, - MetricsFactory: mFactory, - LegacySamplingEndpoint: true, - }) - r := mux.NewRouter() - handler.RegisterRoutes(r) - errorLog, _ := zap.NewStdLogAt(logger, zapcore.ErrorLevel) - return &http.Server{ - Addr: hostPort, - Handler: r, - ErrorLog: errorLog, - ReadHeaderTimeout: 2 * time.Second, - } -} diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/httpserver/srv_test.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/httpserver/srv_test.go deleted file mode 100644 index 272bb9b579a9..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/httpserver/srv_test.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 -// -// Copyright (c) 2019 The Jaeger Authors. -// Copyright (c) 2017 Uber Technologies, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package httpserver - -import ( - "testing" - - "github.com/stretchr/testify/assert" - "go.uber.org/zap" -) - -func TestHTTPServer(t *testing.T) { - s := NewHTTPServer(":1", nil, nil, zap.NewNop()) - assert.NotNil(t, s) -} diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/metadata/generated_status.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/metadata/generated_status.go deleted file mode 100644 index efc542c560a6..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/metadata/generated_status.go +++ /dev/null @@ -1,12 +0,0 @@ -// Code generated by mdatagen. DO NOT EDIT. - -package metadata - -import ( - "go.opentelemetry.io/collector/component" -) - -const ( - Type = "jaeger" - TracesStability = component.StabilityLevelBeta -) diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/grpc_handler.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/grpc_handler.go deleted file mode 100644 index 468f3202acdb..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/grpc_handler.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 -// -// Copyright (c) 2018 The Jaeger Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package sampling // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling" - -import ( - "context" - - "github.com/jaegertracing/jaeger/model/converter/thrift/jaeger" - "github.com/jaegertracing/jaeger/proto-gen/api_v2" - - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/strategystore" -) - -// GRPCHandler is sampling strategy handler for gRPC. -type GRPCHandler struct { - store strategystore.StrategyStore -} - -// NewGRPCHandler creates a handler that controls sampling strategies for services. -func NewGRPCHandler(store strategystore.StrategyStore) GRPCHandler { - return GRPCHandler{ - store: store, - } -} - -// GetSamplingStrategy returns sampling decision from store. -func (s GRPCHandler) GetSamplingStrategy(ctx context.Context, param *api_v2.SamplingStrategyParameters) (*api_v2.SamplingStrategyResponse, error) { - r, err := s.store.GetSamplingStrategy(ctx, param.GetServiceName()) - if err != nil { - return nil, err - } - return jaeger.ConvertSamplingResponseToDomain(r) -} diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/grpc_handler_test.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/grpc_handler_test.go deleted file mode 100644 index 350670c5f098..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/grpc_handler_test.go +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 -// -// Copyright (c) 2018 The Jaeger Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package sampling - -import ( - "errors" - "testing" - - "github.com/jaegertracing/jaeger/proto-gen/api_v2" - "github.com/jaegertracing/jaeger/thrift-gen/sampling" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "golang.org/x/net/context" -) - -type mockSamplingStore struct{} - -func (s mockSamplingStore) GetSamplingStrategy(_ context.Context, serviceName string) (*sampling.SamplingStrategyResponse, error) { - if serviceName == "error" { - return nil, errors.New("some error") - } else if serviceName == "nil" { - return nil, nil - } - return &sampling.SamplingStrategyResponse{StrategyType: sampling.SamplingStrategyType_PROBABILISTIC}, nil -} - -func TestNewGRPCHandler(t *testing.T) { - tests := []struct { - req *api_v2.SamplingStrategyParameters - resp *api_v2.SamplingStrategyResponse - err string - }{ - {req: &api_v2.SamplingStrategyParameters{ServiceName: "error"}, err: "some error"}, - {req: &api_v2.SamplingStrategyParameters{ServiceName: "nil"}, resp: nil}, - {req: &api_v2.SamplingStrategyParameters{ServiceName: "foo"}, resp: &api_v2.SamplingStrategyResponse{StrategyType: api_v2.SamplingStrategyType_PROBABILISTIC}}, - } - h := NewGRPCHandler(mockSamplingStore{}) - for _, test := range tests { - resp, err := h.GetSamplingStrategy(context.Background(), test.req) - if test.err != "" { - assert.EqualError(t, err, test.err) - require.Nil(t, resp) - } else { - require.NoError(t, err) - assert.Equal(t, test.resp, resp) - } - } -} diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/model/empty_test.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/model/empty_test.go deleted file mode 100644 index 7a825c8ad6d4..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/model/empty_test.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 -// -// Copyright (c) 2018 The Jaeger Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package model - -// import "testing" - -// func TestNothing(t *testing.T) { -// // just get the code coverage -// } diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/model/sampling.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/model/sampling.go deleted file mode 100644 index dac7fdef1ee1..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/model/sampling.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 -// -// Copyright (c) 2019 The Jaeger Authors. -// Copyright (c) 2017 Uber Technologies, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package model // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/model" - -// Throughput keeps track of the queries an operation received. -type Throughput struct { - Service string - Operation string - Count int64 - Probabilities map[string]struct{} -} - -// ServiceOperationProbabilities contains the sampling probabilities for all operations in a service. -// ie [service][operation] = probability -type ServiceOperationProbabilities map[string]map[string]float64 - -// ServiceOperationQPS contains the qps for all operations in a service. -// ie [service][operation] = qps -type ServiceOperationQPS map[string]map[string]float64 - -// ProbabilityAndQPS contains the sampling probability and measured qps for an operation. -type ProbabilityAndQPS struct { - Probability float64 - QPS float64 -} - -// ServiceOperationData contains the sampling probabilities and measured qps for all operations in a service. -// ie [service][operation] = ProbabilityAndQPS -type ServiceOperationData map[string]map[string]*ProbabilityAndQPS diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/strategystore/empty_test.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/strategystore/empty_test.go deleted file mode 100644 index 67dcb38f4611..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/strategystore/empty_test.go +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 -// -// Copyright (c) 2019 The Jaeger Authors. -// Copyright (c) 2017 Uber Technologies, Inc. -// -// Copyright (c) 2019 The Jaeger Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package strategystore diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/strategystore/factory.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/strategystore/factory.go deleted file mode 100644 index bf8db2d1efc6..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/strategystore/factory.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 -// -// Copyright (c) 2018 The Jaeger Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package strategystore // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/strategystore" - -import ( - "github.com/jaegertracing/jaeger/pkg/metrics" - "github.com/jaegertracing/jaeger/storage" - "go.uber.org/zap" -) - -// Factory defines an interface for a factory that can create implementations of different strategy storage components. -// Implementations are also encouraged to implement plugin.Configurable interface. -// -// # See also -// -// plugin.Configurable -type Factory interface { - // Initialize performs internal initialization of the factory. - Initialize(metricsFactory metrics.Factory, ssFactory storage.SamplingStoreFactory, logger *zap.Logger) error - - // CreateStrategyStore initializes the StrategyStore and returns it. - CreateStrategyStore() (StrategyStore, Aggregator, error) -} diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/strategystore/interface.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/strategystore/interface.go deleted file mode 100644 index dc0404c7c69d..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/strategystore/interface.go +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 -// -// Copyright (c) 2018 The Jaeger Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package strategystore // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/sampling/strategystore" - -import ( - "context" - "io" - - "github.com/jaegertracing/jaeger/thrift-gen/sampling" -) - -// StrategyStore keeps track of service specific sampling strategies. -type StrategyStore interface { - // GetSamplingStrategy retrieves the sampling strategy for the specified service. - GetSamplingStrategy(ctx context.Context, serviceName string) (*sampling.SamplingStrategyResponse, error) -} - -// Aggregator defines an interface used to aggregate operation throughput. -type Aggregator interface { - // Close() from io.Closer stops the aggregator from aggregating throughput. - io.Closer - - // RecordThroughput records throughput for an operation for aggregation. - RecordThroughput(service, operation, samplerType string, probability float64) - - // Start starts aggregating operation throughput. - Start() -} diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/jaeger_agent_test.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/jaeger_agent_test.go deleted file mode 100644 index 010ec340d8a6..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/jaeger_agent_test.go +++ /dev/null @@ -1,251 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package jaegerreceiverdeprecated - -import ( - "context" - "fmt" - "net" - "net/http" - "testing" - "time" - - "github.com/apache/thrift/lib/go/thrift" - "github.com/jaegertracing/jaeger/cmd/agent/app/servers/thriftudp" - "github.com/jaegertracing/jaeger/model" - jaegerconvert "github.com/jaegertracing/jaeger/model/converter/thrift/jaeger" - "github.com/jaegertracing/jaeger/proto-gen/api_v2" - "github.com/jaegertracing/jaeger/thrift-gen/agent" - jaegerthrift "github.com/jaegertracing/jaeger/thrift-gen/jaeger" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/consumer/consumertest" - "go.opentelemetry.io/collector/pdata/ptrace" - "go.opentelemetry.io/collector/receiver/receivertest" - conventions "go.opentelemetry.io/collector/semconv/v1.6.1" - "google.golang.org/grpc" - - "github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/metadata" -) - -var jaegerAgent = component.NewIDWithName(metadata.Type, "agent_test") - -func TestJaegerAgentUDP_ThriftCompact(t *testing.T) { - addr := testutil.GetAvailableLocalAddress(t) - testJaegerAgent(t, addr, &configuration{ - AgentCompactThrift: ProtocolUDP{ - Endpoint: addr, - ServerConfigUDP: DefaultServerConfigUDP(), - }, - }) -} - -func TestJaegerAgentUDP_ThriftCompact_InvalidPort(t *testing.T) { - config := &configuration{ - AgentCompactThrift: ProtocolUDP{ - Endpoint: "0.0.0.0:999999", - ServerConfigUDP: DefaultServerConfigUDP(), - }, - } - set := receivertest.NewNopCreateSettings() - jr, err := newJaegerReceiver(jaegerAgent, config, nil, set) - require.NoError(t, err) - - assert.Error(t, jr.Start(context.Background(), componenttest.NewNopHost()), "should not have been able to startTraceReception") - - require.NoError(t, jr.Shutdown(context.Background())) -} - -func TestJaegerAgentUDP_ThriftBinary(t *testing.T) { - addr := testutil.GetAvailableLocalAddress(t) - testJaegerAgent(t, addr, &configuration{ - AgentBinaryThrift: ProtocolUDP{ - Endpoint: addr, - ServerConfigUDP: DefaultServerConfigUDP(), - }, - }) -} - -func TestJaegerAgentUDP_ThriftBinary_PortInUse(t *testing.T) { - // This test confirms that the thrift binary port is opened correctly. This is all we can test at the moment. See above. - addr := testutil.GetAvailableLocalAddress(t) - - config := &configuration{ - AgentBinaryThrift: ProtocolUDP{ - Endpoint: addr, - ServerConfigUDP: DefaultServerConfigUDP(), - }, - } - set := receivertest.NewNopCreateSettings() - jr, err := newJaegerReceiver(jaegerAgent, config, nil, set) - require.NoError(t, err) - - assert.NoError(t, jr.startAgent(componenttest.NewNopHost()), "Start failed") - t.Cleanup(func() { require.NoError(t, jr.Shutdown(context.Background())) }) - - l, err := net.Listen("udp", addr) - assert.Error(t, err, "should not have been able to listen to the port") - - if l != nil { - l.Close() - } -} - -func TestJaegerAgentUDP_ThriftBinary_InvalidPort(t *testing.T) { - config := &configuration{ - AgentBinaryThrift: ProtocolUDP{ - Endpoint: "0.0.0.0:999999", - ServerConfigUDP: DefaultServerConfigUDP(), - }, - } - set := receivertest.NewNopCreateSettings() - jr, err := newJaegerReceiver(jaegerAgent, config, nil, set) - require.NoError(t, err) - - assert.Error(t, jr.Start(context.Background(), componenttest.NewNopHost()), "should not have been able to startTraceReception") - - require.NoError(t, jr.Shutdown(context.Background())) -} - -func initializeGRPCTestServer(t *testing.T, beforeServe func(server *grpc.Server), opts ...grpc.ServerOption) (*grpc.Server, net.Addr) { - server := grpc.NewServer(opts...) - lis, err := net.Listen("tcp", "localhost:0") - require.NoError(t, err) - beforeServe(server) - go func() { - err := server.Serve(lis) - require.NoError(t, err) - }() - return server, lis.Addr() -} - -type mockSamplingHandler struct { -} - -func (*mockSamplingHandler) GetSamplingStrategy(context.Context, *api_v2.SamplingStrategyParameters) (*api_v2.SamplingStrategyResponse, error) { - return &api_v2.SamplingStrategyResponse{StrategyType: api_v2.SamplingStrategyType_PROBABILISTIC}, nil -} - -func TestJaegerHTTP(t *testing.T) { - s, _ := initializeGRPCTestServer(t, func(s *grpc.Server) { - api_v2.RegisterSamplingManagerServer(s, &mockSamplingHandler{}) - }) - defer s.GracefulStop() - - endpoint := testutil.GetAvailableLocalAddress(t) - config := &configuration{ - AgentHTTPEndpoint: endpoint, - } - set := receivertest.NewNopCreateSettings() - jr, err := newJaegerReceiver(jaegerAgent, config, nil, set) - require.NoError(t, err) - t.Cleanup(func() { require.NoError(t, jr.Shutdown(context.Background())) }) - - assert.NoError(t, jr.Start(context.Background(), componenttest.NewNopHost()), "Start failed") - - // allow http server to start - assert.Eventually(t, func() bool { - var conn net.Conn - conn, err = net.Dial("tcp", endpoint) - if err == nil && conn != nil { - conn.Close() - return true - } - return false - }, 10*time.Second, 5*time.Millisecond, "failed to wait for the port to be open") - - resp, err := http.Get(fmt.Sprintf("http://%s/sampling?service=test", endpoint)) - assert.NoError(t, err, "should not have failed to make request") - if resp != nil { - assert.Equal(t, 500, resp.StatusCode, "should have returned 200") - return - } - t.Fail() -} - -func testJaegerAgent(t *testing.T, agentEndpoint string, receiverConfig *configuration) { - // 1. Create the Jaeger receiver aka "server" - sink := new(consumertest.TracesSink) - set := receivertest.NewNopCreateSettings() - jr, err := newJaegerReceiver(jaegerAgent, receiverConfig, sink, set) - require.NoError(t, err) - t.Cleanup(func() { require.NoError(t, jr.Shutdown(context.Background())) }) - - for i := 0; i < 3; i++ { - err = jr.Start(context.Background(), componenttest.NewNopHost()) - if err == nil { - break - } - - time.Sleep(50 * time.Millisecond) - } - require.NoError(t, err, "Start failed") - - // 2. Then send spans to the Jaeger receiver. - jexp, err := newClientUDP(agentEndpoint, jr.config.AgentBinaryThrift.Endpoint != "") - require.NoError(t, err, "Failed to create the Jaeger OpenTelemetry exporter for the live application") - - // 3. Now finally send some spans - td := generateTraceData() - batches, err := jaeger.ProtoFromTraces(td) - require.NoError(t, err) - for _, batch := range batches { - require.NoError(t, jexp.EmitBatch(context.Background(), modelToThrift(batch))) - } - - require.Eventually(t, func() bool { - return sink.SpanCount() > 0 - }, 10*time.Second, 5*time.Millisecond) - - gotTraces := sink.AllTraces() - require.Equal(t, 1, len(gotTraces)) - assert.EqualValues(t, td, gotTraces[0]) -} - -func newClientUDP(hostPort string, binary bool) (*agent.AgentClient, error) { - clientTransport, err := thriftudp.NewTUDPClientTransport(hostPort, "") - if err != nil { - return nil, err - } - var protocolFactory thrift.TProtocolFactory - if binary { - protocolFactory = thrift.NewTBinaryProtocolFactoryConf(nil) - } else { - protocolFactory = thrift.NewTCompactProtocolFactoryConf(nil) - } - return agent.NewAgentClientFactory(clientTransport, protocolFactory), nil -} - -// Cannot use the testdata because timestamps are nanoseconds. -func generateTraceData() ptrace.Traces { - td := ptrace.NewTraces() - rs := td.ResourceSpans().AppendEmpty() - rs.Resource().Attributes().PutStr(conventions.AttributeServiceName, "test") - span := rs.ScopeSpans().AppendEmpty().Spans().AppendEmpty() - span.SetSpanID([8]byte{0, 1, 2, 3, 4, 5, 6, 7}) - span.SetTraceID([16]byte{0, 1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1, 0}) - span.SetStartTimestamp(1581452772000000000) - span.SetEndTimestamp(1581452773000000000) - return td -} - -func modelToThrift(batch *model.Batch) *jaegerthrift.Batch { - return &jaegerthrift.Batch{ - Process: processModelToThrift(batch.Process), - Spans: jaegerconvert.FromDomain(batch.Spans), - } -} - -func processModelToThrift(process *model.Process) *jaegerthrift.Process { - if process == nil { - return nil - } - return &jaegerthrift.Process{ - ServiceName: process.ServiceName, - } -} diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/metadata.yaml b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/metadata.yaml deleted file mode 100644 index 7b9b51627872..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/metadata.yaml +++ /dev/null @@ -1,17 +0,0 @@ -type: jaeger - -status: - class: receiver - stability: - beta: [traces] - distributions: - - core - - contrib - - aws - - grafana - - observiq - - redhat - - splunk - - sumo - codeowners: - active: [jpkrohling] diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/testdata/ca.crt b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/testdata/ca.crt deleted file mode 100644 index 5b3ac9ca4d1f..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/testdata/ca.crt +++ /dev/null @@ -1,20 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIDNjCCAh4CCQDm8/gmxPra7zANBgkqhkiG9w0BAQsFADBdMQswCQYDVQQGEwJB -VTESMBAGA1UECAwJQXVzdHJhbGlhMQ8wDQYDVQQHDAZTeWRuZXkxEjAQBgNVBAoM -CU15T3JnTmFtZTEVMBMGA1UEAwwMTXlDb21tb25OYW1lMB4XDTIyMDgwMzA0NDQ0 -OFoXDTMyMDczMTA0NDQ0OFowXTELMAkGA1UEBhMCQVUxEjAQBgNVBAgMCUF1c3Ry -YWxpYTEPMA0GA1UEBwwGU3lkbmV5MRIwEAYDVQQKDAlNeU9yZ05hbWUxFTATBgNV -BAMMDE15Q29tbW9uTmFtZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB -AKDQxV8fMvsl4YhMiY3EiT0ylKQ0VkUwvWE4yfem6LFYaZa0fOe1zc3V9DXmcH9A -PXXa+XwlK7xfXSddGoD7XfxLKdU8FiU+bXs/pEeRPQ+5oraInTcAQ265HXkPmiiQ -XN6qRlwAoC2NgV9OKvUHEqpw/Z/edCLfbBipT+PfBeAtK9Dv0v3hXAqDQlotERxM -uRa9VYETbw/hjj+DIVGZWCnpiQXlepxoZJJiGw1p2Ca0aN5mWDNvMz9bFWo+Szz6 -FqR1S6Tqw5M3jS0NMkI1e0mZSxGBqYXy/x7ep9j5UjmAtHl8oKpDS23HXqnxnjLi -mnM/dipizaJKwidw9SA/fRMCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAZsJE1yx/ -m9zy29eB6l2278bWvRP/2zbpBVziOmwLq5vYdtTn9S1o8TJ8MFAa3B9D0oLSb+n5 -biJqK4rwKRWezoalHo6/vVxQDY1FgVT0RmYKdL9xdc4YBPdBfHnvlEqcXPYBpvoH -0w0ZIu1UxkDij8RNxc5aePflAyVZxg3RNh0jN0qiwB2d4VqOzr9XAh4b1DFRaI9r -X0MG+4ptxdNM7StKJGsJvnZ686Ep/6/2Z4B2guBGkcoSuSRUwr1ft8DuJBM5QLwa -wUPFTcCoyfHzNpYaIp2pTSScFEXmLlV/E7TiST0EEiqNsZAaDPttuAdDRSUe/1CX -hxDsgqzefB2kWQ== ------END CERTIFICATE----- diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/testdata/client.crt b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/testdata/client.crt deleted file mode 100644 index af6038866c2e..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/testdata/client.crt +++ /dev/null @@ -1,20 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIDVTCCAj2gAwIBAgIJAOPSCYfRo9dVMA0GCSqGSIb3DQEBCwUAMF0xCzAJBgNV -BAYTAkFVMRIwEAYDVQQIDAlBdXN0cmFsaWExDzANBgNVBAcMBlN5ZG5leTESMBAG -A1UECgwJTXlPcmdOYW1lMRUwEwYDVQQDDAxNeUNvbW1vbk5hbWUwHhcNMjIwODAz -MDQ0NDQ4WhcNMzIwNzMxMDQ0NDQ4WjBdMQswCQYDVQQGEwJBVTESMBAGA1UECAwJ -QXVzdHJhbGlhMQ8wDQYDVQQHDAZTeWRuZXkxEjAQBgNVBAoMCU15T3JnTmFtZTEV -MBMGA1UEAwwMTXlDb21tb25OYW1lMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB -CgKCAQEAzEzroaSqc9ytdbHvtDtLlLL7DFflK8Xuya1DZRXaqWEZN7wluCCnKWbO -qqSKSDsDgiIj3in5yhQfw+ekQ9+WQmJJVbxclBy8RPFZABHuYkP8JwhqezW0ozK8 -soUOxTjj5khuznUyqihx3fBVOS3eyRW89M7k8RRj7IWctlFzPHhFCdCWMzM9rkBU -lI+a2igqkGMA/1w5/Q9+d0FvPOlvi47JSzZx47TU3TI7vppr+UQmA6L+IZvdA04A -KjBYH1YNo2Ek5z1j+B9dnXlhYhe+OeB18dUAVwPqh9MGOn5wDYYdKMC78v0OWnC3 -EHTAbixEB8Mwgh74xYpQPnMB09csKwIDAQABoxgwFjAUBgNVHREEDTALgglsb2Nh -bGhvc3QwDQYJKoZIhvcNAQELBQADggEBACvgrBWXuUKB9EUOHdJcIvaGlalZXgbA -qX62ipSx9L791NSwpf9S9iZjDmzNpxizOzSSznHoxObsgCa5R1yMiqvcjmVBUJbw -JfYH6Gt4glk2alNL8PjY/6SnG08t+xkvXHtdKO6asC0L1GmM9BPnd+djFyMqsPXx -CaHLERK2HgbDXvumlPWmR9j8zm/jen3Pw/w3KKc+5XLrc5V5zcG0+WqV307MaIOS -vIm4BhUABC4co01vwWvA+OrSy+sAyfMPeuPHe2kVUPwKMIciVGyl58BrVtvqcHZW -sHGa/cOSp4B/6DXjbcvO8G4CA0VGKl0X7QENSi4x09HsgnQ75DMWvk8= ------END CERTIFICATE----- diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/testdata/client.key b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/testdata/client.key deleted file mode 100644 index 68761c8f7309..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/testdata/client.key +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEowIBAAKCAQEAzEzroaSqc9ytdbHvtDtLlLL7DFflK8Xuya1DZRXaqWEZN7wl -uCCnKWbOqqSKSDsDgiIj3in5yhQfw+ekQ9+WQmJJVbxclBy8RPFZABHuYkP8Jwhq -ezW0ozK8soUOxTjj5khuznUyqihx3fBVOS3eyRW89M7k8RRj7IWctlFzPHhFCdCW -MzM9rkBUlI+a2igqkGMA/1w5/Q9+d0FvPOlvi47JSzZx47TU3TI7vppr+UQmA6L+ -IZvdA04AKjBYH1YNo2Ek5z1j+B9dnXlhYhe+OeB18dUAVwPqh9MGOn5wDYYdKMC7 -8v0OWnC3EHTAbixEB8Mwgh74xYpQPnMB09csKwIDAQABAoIBAC8KXw7/DUhUPZRl -/h1vsb1xYKC89EWZ85t4S5ZQ6+IoO1g7+CtnSVYdF+TusfBjtjEWj0+uNpey/oVr -JsWCC+UJIH2fO2nXG/p739RGTK9PnBWYuHvaJ9eT7SLlxDrhGIiDkQ/0qE/JtD44 -AkeCKlP+r11m7gwcd82UDjtkkbYQSZkEh4m4AAF3TNxan2B+9KrgAX9KT1fNrs8B -XPzo/y3YXHEhIpvFyxm96+R/gaVTvfk2CQD/rnfoB5y3W3zfvFwWvnSQRoZqamQQ -Zza8b7HQ0P0mLJxlt0ui1jkEe3ljqKA3CgHhWh0NYPtgfKA5+61xo4XA83k7UvR+ -Ku5My7ECgYEA+E5fkfX8cr0BqIAMNuGuagTelADfAPWlATtzcJqOXZMFLkWJ9NxI -IioQ3I88YjBmGqP/+ktGsIz7N+GB0liXU2iU3c1vOnXuoQJNsXhcRTb5YjTk3e3L -qGPj+fS3ZlgjnO3IBLubjH47klJr2oGw1x4MfB6zWN9p1OwJHcQQPJ8CgYEA0qF7 -qTw8558/lS70CrdkhrtHaeseWCyv94nodcHGY3SxvVVzJsxP6So02ovnatfxS2IC -/6V2VQPnXnHBFCREw1NpiG1lVaxiDpKBTd7hd3rv/KqYojb22NVZqFoW5nUrot/x -li/krgelc0+RiIDHXKLp9MNu/yurWmEWD2p52PUCgYBTH1Fo+FLZSiJq+Oqd2LDd -duHX4+7DUHg7UF6VvHeaJaRfWBIVsURIg5J/c0fAivkzQ+FmNZrlcVyL2WbvNo75 -8hGbqrDofiAzMCU4GtWwqfWUBab0EC3UIhRoUZ6vmSPa3dLOmss4ne1tT0Ahtrav -XLTLPC/HuYqhJ57pov/YewKBgFI6ap1x/9Do0Zi7ANjiKaOTn1iRSoJfx76anx7B -rGKNXwosPs0pvBSpvoKHVavXa8LjG4qUHPMpl/y96gOj+RhMCwoQsxvUNV+9AC/X -UCwl2WTJcNb7IDkcaWkY6pHDsmpehOD+B4eNQqEWshkZNTtL+ovsc/u4H6gj+MnB -5pm1AoGBALUwryV4ue/e1KU73Q852yfiH6RkPfO33IiBsLzUT5XJ+y7SKUP2BwGB -vnkB2wf/X7JlGxGrGMJLpgNQTFAkJ4DFsObE9nNh4bSfmQOz3+1OtCLUPn1/+Yjh -Z9GL7LODsu+UDKnDvxc6e91fGQz9nSxGhSgWntC/e2sGxU4T5H+5 ------END RSA PRIVATE KEY----- diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/testdata/config.yaml b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/testdata/config.yaml deleted file mode 100644 index e380fcdd7a99..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/testdata/config.yaml +++ /dev/null @@ -1,67 +0,0 @@ -# The following demonstrates specifying different endpoints. -# The Jaeger receiver connects to ports on all available network interfaces. -# Ex: `endpoint: "9876"` is incorrect. -# Ex: `endpoint: "1.2.3.4:9876"` and ":9876" is correct. -jaeger/customname: - protocols: - grpc: - endpoint: "localhost:9876" - thrift_http: - endpoint: ":3456" - thrift_compact: - endpoint: "0.0.0.0:456" - queue_size: 100_000 - max_packet_size: 131_072 - workers: 100 - socket_buffer_size: 65_536 - thrift_binary: - endpoint: "0.0.0.0:789" - queue_size: 1_000 - max_packet_size: 65_536 - workers: 5 - socket_buffer_size: 0 - remote_sampling: - host_endpoint: "0.0.0.0:5778" - endpoint: "jaeger-collector:1234" - strategy_file: "/etc/strategies.json" - strategy_file_reload_interval: 10s -# The following demonstrates how to enable protocols with defaults. -jaeger/defaults: - protocols: - grpc: - thrift_http: - thrift_compact: - thrift_binary: -# The following demonstrates only enabling certain protocols with defaults/overrides. -jaeger/mixed: - protocols: - grpc: - endpoint: "localhost:9876" - thrift_compact: -# The following demonstrates specifying different endpoints. -# The Jaeger receiver connects to ports on all available network interfaces. -# Ex: `endpoint: "9876"` is incorrect. -# Ex: `endpoint: "1.2.3.4:9876"` and ":9876" is correct. -jaeger/tls: - protocols: - grpc: - tls: - cert_file: /test.crt - key_file: /test.key - endpoint: "localhost:9876" - thrift_http: - endpoint: ":3456" -jaeger/empty: -# The following demonstrates how to enable protocols with defaults -jaeger/typo_default_proto_config: - protocols: - grpc: - endpoint: "127.0.0.1:123" - thrift_htttp: -jaeger/no_proto_config: - protocols: -# The following demonstrates how to enable protocols with defaults -jaeger/bad_proto_config: - protocols: - thrift_htttp: - endpoint: "127.0.0.1:123" diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/testdata/server.crt b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/testdata/server.crt deleted file mode 100644 index f92d2acb9105..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/testdata/server.crt +++ /dev/null @@ -1,20 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIDVTCCAj2gAwIBAgIJAOPSCYfRo9dUMA0GCSqGSIb3DQEBCwUAMF0xCzAJBgNV -BAYTAkFVMRIwEAYDVQQIDAlBdXN0cmFsaWExDzANBgNVBAcMBlN5ZG5leTESMBAG -A1UECgwJTXlPcmdOYW1lMRUwEwYDVQQDDAxNeUNvbW1vbk5hbWUwHhcNMjIwODAz -MDQ0NDQ4WhcNMzIwNzMxMDQ0NDQ4WjBdMQswCQYDVQQGEwJBVTESMBAGA1UECAwJ -QXVzdHJhbGlhMQ8wDQYDVQQHDAZTeWRuZXkxEjAQBgNVBAoMCU15T3JnTmFtZTEV -MBMGA1UEAwwMTXlDb21tb25OYW1lMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB -CgKCAQEAyEPiDsD4JXTB7AeyVsFkhKLq1jQCgtWTEQoFYW6lSnbD+yGhUcN1ntpU -R4QSFm+NmIPHzoD3wgwZ5Fcp1Tir3HgnvKJeUhVNnPE1EZcuiO69n0W8SGqLExVK -noEH3gI9Zygen0aHhN6b1za+m67j9FYIhbxN6jZJ83XP7t5N56trWGQ3sZA8Tsqs -oFHTrNVjE1IugPaQs4qst/qFIRbC6z47LarUmXG2jrTAMJQBqBeaxaEWy5Ty9gNy -nz4fqli9/faUJkyocyhOn971EDK3PSR5BV/MGWHfvcgKrsNyJh6/njQjQIGHZAZo -ooIKEzPvoCGHfJrhYd8UKw+RkHgtWwIDAQABoxgwFjAUBgNVHREEDTALgglsb2Nh -bGhvc3QwDQYJKoZIhvcNAQELBQADggEBAGKl+WK1Mf6g5D+bKvb5fq1GCJyLLL2I -Skmr+HRfnCzFrrdB6uL5IHiZ5xHJ1xZkoymGF0WabcsmYDe0J19nFWUH6Jv8CeFC -2Qz/iy+XZxWQxD17yRTpek48HxGVio4bwzGGsQN13+RVPbocqpiu3oKeO1NAei8J -intveT0LiwsKQ6VhJ39lu0ayAWUc+5FaDwtCMjU+1uSVRivMWkAXFTol6eKG8iAJ -kqtMaeagEkWWLb+UMV22XpaYNiTfQ2OKqUTcZUPzokNn/Mr45nRsc1ZFNie8UuiK -6HXiFa7p6QFY74Tqot9fS1tpp63S/k70KM5/wZs7E452Bj67+TRTcOY= ------END CERTIFICATE----- diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/testdata/server.key b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/testdata/server.key deleted file mode 100644 index 3090f4e00bb6..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/testdata/server.key +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEogIBAAKCAQEAyEPiDsD4JXTB7AeyVsFkhKLq1jQCgtWTEQoFYW6lSnbD+yGh -UcN1ntpUR4QSFm+NmIPHzoD3wgwZ5Fcp1Tir3HgnvKJeUhVNnPE1EZcuiO69n0W8 -SGqLExVKnoEH3gI9Zygen0aHhN6b1za+m67j9FYIhbxN6jZJ83XP7t5N56trWGQ3 -sZA8TsqsoFHTrNVjE1IugPaQs4qst/qFIRbC6z47LarUmXG2jrTAMJQBqBeaxaEW -y5Ty9gNynz4fqli9/faUJkyocyhOn971EDK3PSR5BV/MGWHfvcgKrsNyJh6/njQj -QIGHZAZoooIKEzPvoCGHfJrhYd8UKw+RkHgtWwIDAQABAoIBAGjbumK1QXkDQIKg -qQ1p54LXdxS/WM0+nOmgEJ8qexuZQhadTkVsjYqmkNh9W6cps782yQjkWFXfVjNM -PFgrezlOJKhNcAuUofXaCkpymWgTcXAS6HoWZ0mPrWl+8Cqbi6EWzaniGRVGJd0z -CeykTzFhVscHiNhooqH6fux4s9vn5FDgflVpka0XuOuurF6+9inCAVJHN1C3BNLD -tyZEFW31nR7ImOp37pEI6nE/Q2ecBT97j4kFN+hzYsH4qUYq2iAA/bR4ZLwZ17xc -FbFeGEmVhePVpNPAQ82v36AlWQsK30y7DwPsWlYRkcpsG3QP6+TGnaBM0AFCypY4 -w12DzaECgYEA+pLx3KmVH0zaPiTXFI/RRedipYkmIlyMI+/GfuSInXSWlCSvdOV/ -PTrQoVNvsmObz73kAh2I+KGS9+7arX4O4Qm74Sb3SbCHUGa/wNyv8Nqvo9LraRR0 -RY2fgAS3UL2ZHESJX5aVXa5S3it1tu10K8c9ofpekq/uJ5IaJ81FvbECgYEAzJoN -NRTUCR721wFo4t4OYUdbxLU8CKvj0osouQAQwYhT+EKCp1I9pqvvE4Amxi2Xmysv -Eu4JGy4Ti3jWAwu1XwhkwzSGTuN2/ECJ7EunaFXGeYef9RqR2+JCqGadLfnZZGsN -5/NlbZZ8+Em//9wGDmZz9ZJFnZZPSHxgKmKdYssCgYAqPatYL55b8HC6GSvI45W7 -2w3eKgirsj5NsJYdvhjpskXQI38Qjb+tasTQ7WffAru5gaF2WdRFVbeY5EMpDB8m -AKYThqYZXhDxlOCueoWObM8/JsdYp4ISV5WT1zev/MZa5ZLi8leruz9tBJaLh+wV -lTjmnXZj9BSJxy9xlkEzgQKBgFU8ICBq6uJZ2e88ERvh8g+okJxj+/yIz0IY4wAe -/NwDFSgpXRCjfDeBDPoMuxp4R95GoTe7nmOKUG4cCtv99rL+ZivEJ+eZbyorIMol -wjn+8c4TKBoN1ZHKsoZBKV3L5jqlNofYp/p9ZNZyst++I2/AUrKNGx9JTQIfflhp -+LL9AoGAKyMMGec4MyP3KA4AEEOTShgJ0P6zSj3i/rsC8jiH6yIxSO+Ii+9BdzlF -WblemYFFa5AwWeogycdeWwAX4YVrYAsZmmVb/zt/KvJIi9OwwtmAwGaLLl1Zqtca -uGOifl+ukutwvmL5pzKyCP3SxwkG0F9mVWQVhg13L+/YDZ8v0tg= ------END RSA PRIVATE KEY----- diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/testdata/strategies.json b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/testdata/strategies.json deleted file mode 100644 index 4e8eff73f3f1..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/testdata/strategies.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "service_strategies": [ - { - "service": "foo", - "type": "probabilistic", - "param": 0.8, - "operation_strategies": [ - { - "operation": "op1", - "type": "probabilistic", - "param": 0.2 - }, - { - "operation": "op2", - "type": "probabilistic", - "param": 0.4 - } - ] - }, - { - "service": "bar", - "type": "ratelimiting", - "param": 5 - } - ], - "default_strategy": { - "type": "probabilistic", - "param": 0.5 - } - } \ No newline at end of file diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/trace_receiver.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/trace_receiver.go deleted file mode 100644 index 93ddcf8b22cc..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/trace_receiver.go +++ /dev/null @@ -1,424 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package jaegerreceiverdeprecated // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated" - -import ( - "context" - "errors" - "fmt" - "html" - "io" - "mime" - "net/http" - "sync" - - apacheThrift "github.com/apache/thrift/lib/go/thrift" - "github.com/gorilla/mux" - "github.com/jaegertracing/jaeger/cmd/agent/app/processors" - "github.com/jaegertracing/jaeger/cmd/agent/app/servers" - "github.com/jaegertracing/jaeger/cmd/agent/app/servers/thriftudp" - "github.com/jaegertracing/jaeger/model" - "github.com/jaegertracing/jaeger/pkg/metrics" - "github.com/jaegertracing/jaeger/proto-gen/api_v2" - "github.com/jaegertracing/jaeger/thrift-gen/agent" - "github.com/jaegertracing/jaeger/thrift-gen/baggage" - "github.com/jaegertracing/jaeger/thrift-gen/jaeger" - "github.com/jaegertracing/jaeger/thrift-gen/sampling" - "github.com/jaegertracing/jaeger/thrift-gen/zipkincore" - "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config/configgrpc" - "go.opentelemetry.io/collector/config/confighttp" - "go.opentelemetry.io/collector/consumer" - "go.opentelemetry.io/collector/obsreport" - "go.opentelemetry.io/collector/receiver" - "go.uber.org/multierr" - "google.golang.org/grpc" - - jaegertranslator "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/configmanager" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/internal/httpserver" -) - -// configuration defines the behavior and the ports that -// the Jaeger receiver will use. -type configuration struct { - CollectorHTTPSettings confighttp.HTTPServerSettings - CollectorGRPCServerSettings configgrpc.GRPCServerSettings - - AgentCompactThrift ProtocolUDP - AgentBinaryThrift ProtocolUDP - AgentHTTPEndpoint string -} - -// Receiver type is used to receive spans that were originally intended to be sent to Jaeger. -// This receiver is basically a Jaeger collector. -type jReceiver struct { - nextConsumer consumer.Traces - id component.ID - - config *configuration - - grpc *grpc.Server - collectorServer *http.Server - - agentProcessors []processors.Processor - agentServer *http.Server - - goroutines sync.WaitGroup - - settings receiver.CreateSettings - - grpcObsrecv *obsreport.Receiver - httpObsrecv *obsreport.Receiver -} - -const ( - agentTransportBinary = "udp_thrift_binary" - agentTransportCompact = "udp_thrift_compact" - collectorHTTPTransport = "collector_http" - grpcTransport = "grpc" - - thriftFormat = "thrift" - protobufFormat = "protobuf" -) - -var ( - acceptedThriftFormats = map[string]struct{}{ - "application/x-thrift": {}, - "application/vnd.apache.thrift.binary": {}, - } -) - -// newJaegerReceiver creates a TracesReceiver that receives traffic as a Jaeger collector, and -// also as a Jaeger agent. -func newJaegerReceiver( - id component.ID, - config *configuration, - nextConsumer consumer.Traces, - set receiver.CreateSettings, -) (*jReceiver, error) { - grpcObsrecv, err := obsreport.NewReceiver(obsreport.ReceiverSettings{ - ReceiverID: id, - Transport: grpcTransport, - ReceiverCreateSettings: set, - }) - if err != nil { - return nil, err - } - httpObsrecv, err := obsreport.NewReceiver(obsreport.ReceiverSettings{ - ReceiverID: id, - Transport: collectorHTTPTransport, - ReceiverCreateSettings: set, - }) - if err != nil { - return nil, err - } - - return &jReceiver{ - config: config, - nextConsumer: nextConsumer, - id: id, - settings: set, - grpcObsrecv: grpcObsrecv, - httpObsrecv: httpObsrecv, - }, nil -} - -func (jr *jReceiver) Start(_ context.Context, host component.Host) error { - if err := jr.startAgent(host); err != nil { - return err - } - - return jr.startCollector(host) -} - -func (jr *jReceiver) Shutdown(ctx context.Context) error { - var errs error - - if jr.agentServer != nil { - if aerr := jr.agentServer.Shutdown(ctx); aerr != nil { - errs = multierr.Append(errs, aerr) - } - } - for _, processor := range jr.agentProcessors { - processor.Stop() - } - - if jr.collectorServer != nil { - if cerr := jr.collectorServer.Shutdown(ctx); cerr != nil { - errs = multierr.Append(errs, cerr) - } - } - if jr.grpc != nil { - jr.grpc.GracefulStop() - } - - jr.goroutines.Wait() - return errs -} - -func consumeTraces(ctx context.Context, batch *jaeger.Batch, consumer consumer.Traces) (int, error) { - if batch == nil { - return 0, nil - } - td, err := jaegertranslator.ThriftToTraces(batch) - if err != nil { - return 0, err - } - return len(batch.Spans), consumer.ConsumeTraces(ctx, td) -} - -var _ agent.Agent = (*agentHandler)(nil) -var _ api_v2.CollectorServiceServer = (*jReceiver)(nil) -var _ configmanager.ClientConfigManager = (*notImplementedConfigManager)(nil) - -var errNotImplemented = fmt.Errorf("not implemented") - -type notImplementedConfigManager struct{} - -func (notImplementedConfigManager) GetSamplingStrategy(_ context.Context, _ string) (*sampling.SamplingStrategyResponse, error) { - return nil, errNotImplemented -} - -func (notImplementedConfigManager) GetBaggageRestrictions(_ context.Context, _ string) ([]*baggage.BaggageRestriction, error) { - return nil, errNotImplemented -} - -type agentHandler struct { - nextConsumer consumer.Traces - obsrecv *obsreport.Receiver -} - -// EmitZipkinBatch is unsupported agent's -func (h *agentHandler) EmitZipkinBatch(context.Context, []*zipkincore.Span) (err error) { - panic("unsupported receiver") -} - -// EmitBatch implements thrift-gen/agent/Agent and it forwards -// Jaeger spans received by the Jaeger agent processor. -func (h *agentHandler) EmitBatch(ctx context.Context, batch *jaeger.Batch) error { - ctx = h.obsrecv.StartTracesOp(ctx) - numSpans, err := consumeTraces(ctx, batch, h.nextConsumer) - h.obsrecv.EndTracesOp(ctx, thriftFormat, numSpans, err) - return err -} - -func (jr *jReceiver) PostSpans(ctx context.Context, r *api_v2.PostSpansRequest) (*api_v2.PostSpansResponse, error) { - ctx = jr.grpcObsrecv.StartTracesOp(ctx) - - batch := r.GetBatch() - td, err := jaegertranslator.ProtoToTraces([]*model.Batch{&batch}) - if err != nil { - jr.grpcObsrecv.EndTracesOp(ctx, protobufFormat, len(batch.Spans), err) - return nil, err - } - - err = jr.nextConsumer.ConsumeTraces(ctx, td) - jr.grpcObsrecv.EndTracesOp(ctx, protobufFormat, len(batch.Spans), err) - if err != nil { - return nil, err - } - - return &api_v2.PostSpansResponse{}, nil -} - -func (jr *jReceiver) startAgent(host component.Host) error { - if jr.config == nil { - return nil - } - - if jr.config.AgentBinaryThrift.Endpoint != "" { - obsrecv, err := obsreport.NewReceiver(obsreport.ReceiverSettings{ - ReceiverID: jr.id, - Transport: agentTransportBinary, - ReceiverCreateSettings: jr.settings, - }) - if err != nil { - return err - } - - h := &agentHandler{ - nextConsumer: jr.nextConsumer, - obsrecv: obsrecv, - } - processor, err := jr.buildProcessor(jr.config.AgentBinaryThrift.Endpoint, jr.config.AgentBinaryThrift.ServerConfigUDP, apacheThrift.NewTBinaryProtocolFactoryConf(nil), h) - if err != nil { - return err - } - jr.agentProcessors = append(jr.agentProcessors, processor) - } - - if jr.config.AgentCompactThrift.Endpoint != "" { - obsrecv, err := obsreport.NewReceiver(obsreport.ReceiverSettings{ - ReceiverID: jr.id, - Transport: agentTransportCompact, - ReceiverCreateSettings: jr.settings, - }) - if err != nil { - return err - } - h := &agentHandler{ - nextConsumer: jr.nextConsumer, - obsrecv: obsrecv, - } - processor, err := jr.buildProcessor(jr.config.AgentCompactThrift.Endpoint, jr.config.AgentCompactThrift.ServerConfigUDP, apacheThrift.NewTCompactProtocolFactoryConf(nil), h) - if err != nil { - return err - } - jr.agentProcessors = append(jr.agentProcessors, processor) - } - - jr.goroutines.Add(len(jr.agentProcessors)) - for _, processor := range jr.agentProcessors { - go func(p processors.Processor) { - defer jr.goroutines.Done() - p.Serve() - }(processor) - } - - if jr.config.AgentHTTPEndpoint != "" { - jr.agentServer = httpserver.NewHTTPServer(jr.config.AgentHTTPEndpoint, ¬ImplementedConfigManager{}, metrics.NullFactory, jr.settings.Logger) - - jr.goroutines.Add(1) - go func() { - defer jr.goroutines.Done() - if err := jr.agentServer.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) && err != nil { - host.ReportFatalError(fmt.Errorf("jaeger agent server error: %w", err)) - } - }() - } - - return nil -} - -func (jr *jReceiver) buildProcessor(address string, cfg ServerConfigUDP, factory apacheThrift.TProtocolFactory, a agent.Agent) (processors.Processor, error) { - handler := agent.NewAgentProcessor(a) - transport, err := thriftudp.NewTUDPServerTransport(address) - if err != nil { - return nil, err - } - if cfg.SocketBufferSize > 0 { - if err = transport.SetSocketBufferSize(cfg.SocketBufferSize); err != nil { - return nil, err - } - } - server, err := servers.NewTBufferedServer(transport, cfg.QueueSize, cfg.MaxPacketSize, metrics.NullFactory) - if err != nil { - return nil, err - } - processor, err := processors.NewThriftProcessor(server, cfg.Workers, metrics.NullFactory, factory, handler, jr.settings.Logger) - if err != nil { - return nil, err - } - return processor, nil -} - -func (jr *jReceiver) decodeThriftHTTPBody(r *http.Request) (*jaeger.Batch, *httpError) { - bodyBytes, err := io.ReadAll(r.Body) - r.Body.Close() - if err != nil { - return nil, &httpError{ - fmt.Sprintf("Unable to process request body: %v", err), - http.StatusInternalServerError, - } - } - - contentType, _, err := mime.ParseMediaType(r.Header.Get("Content-Type")) - if err != nil { - return nil, &httpError{ - fmt.Sprintf("Cannot parse content type: %v", err), - http.StatusBadRequest, - } - } - if _, ok := acceptedThriftFormats[contentType]; !ok { - return nil, &httpError{ - fmt.Sprintf("Unsupported content type: %v", contentType), - http.StatusBadRequest, - } - } - - tdes := apacheThrift.NewTDeserializer() - batch := &jaeger.Batch{} - if err = tdes.Read(r.Context(), batch, bodyBytes); err != nil { - return nil, &httpError{ - fmt.Sprintf("Unable to process request body: %v", err), - http.StatusBadRequest, - } - } - return batch, nil -} - -// HandleThriftHTTPBatch implements Jaeger HTTP Thrift handler. -func (jr *jReceiver) HandleThriftHTTPBatch(w http.ResponseWriter, r *http.Request) { - ctx := jr.httpObsrecv.StartTracesOp(r.Context()) - - batch, hErr := jr.decodeThriftHTTPBody(r) - if hErr != nil { - http.Error(w, html.EscapeString(hErr.msg), hErr.statusCode) - jr.httpObsrecv.EndTracesOp(ctx, thriftFormat, 0, hErr) - return - } - - numSpans, err := consumeTraces(ctx, batch, jr.nextConsumer) - if err != nil { - http.Error(w, fmt.Sprintf("Cannot submit Jaeger batch: %v", err), http.StatusInternalServerError) - } else { - w.WriteHeader(http.StatusAccepted) - } - jr.httpObsrecv.EndTracesOp(ctx, thriftFormat, numSpans, err) -} - -func (jr *jReceiver) startCollector(host component.Host) error { - if jr.config == nil { - return nil - } - - if jr.config.CollectorHTTPSettings.Endpoint != "" { - cln, err := jr.config.CollectorHTTPSettings.ToListener() - if err != nil { - return fmt.Errorf("failed to bind to Collector address %q: %w", - jr.config.CollectorHTTPSettings.Endpoint, err) - } - - nr := mux.NewRouter() - nr.HandleFunc("/api/traces", jr.HandleThriftHTTPBatch).Methods(http.MethodPost) - jr.collectorServer, err = jr.config.CollectorHTTPSettings.ToServer(host, jr.settings.TelemetrySettings, nr) - if err != nil { - return err - } - - jr.goroutines.Add(1) - go func() { - defer jr.goroutines.Done() - if errHTTP := jr.collectorServer.Serve(cln); !errors.Is(errHTTP, http.ErrServerClosed) && errHTTP != nil { - host.ReportFatalError(errHTTP) - } - }() - } - - if jr.config.CollectorGRPCServerSettings.NetAddr.Endpoint != "" { - var err error - jr.grpc, err = jr.config.CollectorGRPCServerSettings.ToServer(host, jr.settings.TelemetrySettings) - if err != nil { - return fmt.Errorf("failed to build the options for the Jaeger gRPC Collector: %w", err) - } - - ln, err := jr.config.CollectorGRPCServerSettings.ToListener() - if err != nil { - return fmt.Errorf("failed to bind to gRPC address %q: %w", jr.config.CollectorGRPCServerSettings.NetAddr, err) - } - - api_v2.RegisterCollectorServiceServer(jr.grpc, jr) - - jr.goroutines.Add(1) - go func() { - defer jr.goroutines.Done() - if errGrpc := jr.grpc.Serve(ln); !errors.Is(errGrpc, grpc.ErrServerStopped) && errGrpc != nil { - host.ReportFatalError(errGrpc) - } - }() - } - - return nil -} diff --git a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/trace_receiver_test.go b/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/trace_receiver_test.go deleted file mode 100644 index f82b540edc67..000000000000 --- a/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated/trace_receiver_test.go +++ /dev/null @@ -1,413 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package jaegerreceiverdeprecated - -import ( - "bytes" - "context" - "encoding/binary" - "fmt" - "io" - "net" - "net/http" - "net/http/httptest" - "path/filepath" - "testing" - "time" - - "github.com/apache/thrift/lib/go/thrift" - "github.com/jaegertracing/jaeger/model" - "github.com/jaegertracing/jaeger/proto-gen/api_v2" - jaegerthrift "github.com/jaegertracing/jaeger/thrift-gen/jaeger" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/config/configgrpc" - "go.opentelemetry.io/collector/config/confighttp" - "go.opentelemetry.io/collector/config/confignet" - "go.opentelemetry.io/collector/config/configtls" - "go.opentelemetry.io/collector/consumer/consumertest" - "go.opentelemetry.io/collector/pdata/pcommon" - "go.opentelemetry.io/collector/pdata/ptrace" - "go.opentelemetry.io/collector/receiver/receivertest" - conventions "go.opentelemetry.io/collector/semconv/v1.6.1" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials" - "google.golang.org/grpc/credentials/insecure" - - "github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger" -) - -var jaegerReceiver = component.NewIDWithName("jaeger", "receiver_test") - -func TestTraceSource(t *testing.T) { - set := receivertest.NewNopCreateSettings() - jr, err := newJaegerReceiver(jaegerReceiver, &configuration{}, nil, set) - require.NoError(t, err) - require.NotNil(t, jr) -} - -func jaegerBatchToHTTPBody(b *jaegerthrift.Batch) (*http.Request, error) { - body, err := thrift.NewTSerializer().Write(context.Background(), b) - if err != nil { - return nil, err - } - r := httptest.NewRequest("POST", "/api/traces", bytes.NewReader(body)) - r.Header.Add("content-type", "application/x-thrift") - return r, nil -} - -func TestThriftHTTPBodyDecode(t *testing.T) { - jr := jReceiver{} - batch := &jaegerthrift.Batch{ - Process: jaegerthrift.NewProcess(), - Spans: []*jaegerthrift.Span{jaegerthrift.NewSpan()}, - } - r, err := jaegerBatchToHTTPBody(batch) - require.NoError(t, err, "failed to prepare http body") - - gotBatch, hErr := jr.decodeThriftHTTPBody(r) - require.Nil(t, hErr, "failed to decode http body") - assert.Equal(t, batch, gotBatch) -} - -func TestReception(t *testing.T) { - addr := testutil.GetAvailableLocalAddress(t) - // 1. Create the Jaeger receiver aka "server" - config := &configuration{ - CollectorHTTPSettings: confighttp.HTTPServerSettings{ - Endpoint: addr, - }, - } - sink := new(consumertest.TracesSink) - - set := receivertest.NewNopCreateSettings() - jr, err := newJaegerReceiver(jaegerReceiver, config, sink, set) - require.NoError(t, err) - - require.NoError(t, jr.Start(context.Background(), componenttest.NewNopHost())) - t.Cleanup(func() { require.NoError(t, jr.Shutdown(context.Background())) }) - - // 2. Then send spans to the Jaeger receiver. - _, port, _ := net.SplitHostPort(addr) - collectorAddr := fmt.Sprintf("http://localhost:%s/api/traces", port) - td := generateTraceData() - batches, err := jaeger.ProtoFromTraces(td) - require.NoError(t, err) - for _, batch := range batches { - require.NoError(t, sendToCollector(collectorAddr, modelToThrift(batch))) - } - - assert.NoError(t, err, "should not have failed to create the Jaeger OpenCensus exporter") - - gotTraces := sink.AllTraces() - assert.Equal(t, 1, len(gotTraces)) - - assert.EqualValues(t, td, gotTraces[0]) -} - -func TestPortsNotOpen(t *testing.T) { - // an empty config should result in no open ports - config := &configuration{} - - sink := new(consumertest.TracesSink) - - set := receivertest.NewNopCreateSettings() - jr, err := newJaegerReceiver(jaegerReceiver, config, sink, set) - require.NoError(t, err) - - require.NoError(t, jr.Start(context.Background(), componenttest.NewNopHost())) - t.Cleanup(func() { require.NoError(t, jr.Shutdown(context.Background())) }) - - // there is a race condition here that we're ignoring. - // this test may occasionally pass incorrectly, but it will not fail incorrectly - // TODO: consider adding a way for a receiver to asynchronously signal that is ready to receive spans to eliminate races/arbitrary waits - l, err := net.Listen("tcp", "localhost:14250") - assert.NoError(t, err, "should have been able to listen on 14250. jaeger receiver incorrectly started grpc") - if l != nil { - l.Close() - } - - l, err = net.Listen("tcp", "localhost:14268") - assert.NoError(t, err, "should have been able to listen on 14268. jaeger receiver incorrectly started thrift_http") - if l != nil { - l.Close() - } -} - -func TestGRPCReception(t *testing.T) { - // prepare - config := &configuration{ - CollectorGRPCServerSettings: configgrpc.GRPCServerSettings{ - NetAddr: confignet.NetAddr{ - Endpoint: testutil.GetAvailableLocalAddress(t), - Transport: "tcp", - }, - }, - } - sink := new(consumertest.TracesSink) - - set := receivertest.NewNopCreateSettings() - jr, err := newJaegerReceiver(jaegerReceiver, config, sink, set) - require.NoError(t, err) - - require.NoError(t, jr.Start(context.Background(), componenttest.NewNopHost())) - t.Cleanup(func() { require.NoError(t, jr.Shutdown(context.Background())) }) - - conn, err := grpc.Dial(config.CollectorGRPCServerSettings.NetAddr.Endpoint, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) - require.NoError(t, err) - defer conn.Close() - - cl := api_v2.NewCollectorServiceClient(conn) - - now := time.Unix(1542158650, 536343000).UTC() - d10min := 10 * time.Minute - d2sec := 2 * time.Second - nowPlus10min := now.Add(d10min) - nowPlus10min2sec := now.Add(d10min).Add(d2sec) - - // test - req := grpcFixture(t, now, d10min, d2sec) - resp, err := cl.PostSpans(context.Background(), req, grpc.WaitForReady(true)) - - // verify - assert.NoError(t, err, "should not have failed to post spans") - assert.NotNil(t, resp, "response should not have been nil") - - gotTraces := sink.AllTraces() - assert.Equal(t, 1, len(gotTraces)) - want := expectedTraceData(now, nowPlus10min, nowPlus10min2sec) - - assert.Len(t, req.Batch.Spans, want.SpanCount(), "got a conflicting amount of spans") - - assert.EqualValues(t, want, gotTraces[0]) -} - -func TestGRPCReceptionWithTLS(t *testing.T) { - // prepare - tlsCreds := &configtls.TLSServerSetting{ - TLSSetting: configtls.TLSSetting{ - CertFile: filepath.Join("testdata", "server.crt"), - KeyFile: filepath.Join("testdata", "server.key"), - }, - } - - grpcServerSettings := configgrpc.GRPCServerSettings{ - NetAddr: confignet.NetAddr{ - Endpoint: testutil.GetAvailableLocalAddress(t), - Transport: "tcp", - }, - TLSSetting: tlsCreds, - } - - config := &configuration{ - CollectorGRPCServerSettings: grpcServerSettings, - } - sink := new(consumertest.TracesSink) - - set := receivertest.NewNopCreateSettings() - jr, err := newJaegerReceiver(jaegerReceiver, config, sink, set) - require.NoError(t, err) - - require.NoError(t, jr.Start(context.Background(), componenttest.NewNopHost())) - t.Cleanup(func() { require.NoError(t, jr.Shutdown(context.Background())) }) - - creds, err := credentials.NewClientTLSFromFile(filepath.Join("testdata", "server.crt"), "localhost") - require.NoError(t, err) - conn, err := grpc.Dial(grpcServerSettings.NetAddr.Endpoint, grpc.WithTransportCredentials(creds), grpc.WithBlock()) - require.NoError(t, err) - defer conn.Close() - - cl := api_v2.NewCollectorServiceClient(conn) - - now := time.Now() - d10min := 10 * time.Minute - d2sec := 2 * time.Second - nowPlus10min := now.Add(d10min) - nowPlus10min2sec := now.Add(d10min).Add(d2sec) - - // test - req := grpcFixture(t, now, d10min, d2sec) - resp, err := cl.PostSpans(context.Background(), req, grpc.WaitForReady(true)) - - // verify - assert.NoError(t, err, "should not have failed to post spans") - assert.NotNil(t, resp, "response should not have been nil") - - gotTraces := sink.AllTraces() - assert.Equal(t, 1, len(gotTraces)) - want := expectedTraceData(now, nowPlus10min, nowPlus10min2sec) - - assert.Len(t, req.Batch.Spans, want.SpanCount(), "got a conflicting amount of spans") - assert.EqualValues(t, want, gotTraces[0]) -} - -func expectedTraceData(t1, t2, t3 time.Time) ptrace.Traces { - traceID := pcommon.TraceID( - [16]byte{0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 0x80}) - parentSpanID := pcommon.SpanID([8]byte{0x1F, 0x1E, 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18}) - childSpanID := pcommon.SpanID([8]byte{0xAF, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, 0xA8}) - - traces := ptrace.NewTraces() - rs := traces.ResourceSpans().AppendEmpty() - rs.Resource().Attributes().PutStr(conventions.AttributeServiceName, "issaTest") - rs.Resource().Attributes().PutBool("bool", true) - rs.Resource().Attributes().PutStr("string", "yes") - rs.Resource().Attributes().PutInt("int64", 10000000) - spans := rs.ScopeSpans().AppendEmpty().Spans() - - span0 := spans.AppendEmpty() - span0.SetSpanID(childSpanID) - span0.SetParentSpanID(parentSpanID) - span0.SetTraceID(traceID) - span0.SetName("DBSearch") - span0.SetStartTimestamp(pcommon.NewTimestampFromTime(t1)) - span0.SetEndTimestamp(pcommon.NewTimestampFromTime(t2)) - span0.Status().SetCode(ptrace.StatusCodeError) - span0.Status().SetMessage("Stale indices") - - span1 := spans.AppendEmpty() - span1.SetSpanID(parentSpanID) - span1.SetTraceID(traceID) - span1.SetName("ProxyFetch") - span1.SetStartTimestamp(pcommon.NewTimestampFromTime(t2)) - span1.SetEndTimestamp(pcommon.NewTimestampFromTime(t3)) - span1.Status().SetCode(ptrace.StatusCodeError) - span1.Status().SetMessage("Frontend crash") - - return traces -} - -func grpcFixture(t *testing.T, t1 time.Time, d1, d2 time.Duration) *api_v2.PostSpansRequest { - traceID := model.TraceID{} - require.NoError(t, traceID.Unmarshal([]byte{0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 0x80})) - - parentSpanID := model.NewSpanID(binary.BigEndian.Uint64([]byte{0x1F, 0x1E, 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18})) - childSpanID := model.NewSpanID(binary.BigEndian.Uint64([]byte{0xAF, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, 0xA8})) - - return &api_v2.PostSpansRequest{ - Batch: model.Batch{ - Process: &model.Process{ - ServiceName: "issaTest", - Tags: []model.KeyValue{ - model.Bool("bool", true), - model.String("string", "yes"), - model.Int64("int64", 1e7), - }, - }, - Spans: []*model.Span{ - { - TraceID: traceID, - SpanID: childSpanID, - OperationName: "DBSearch", - StartTime: t1, - Duration: d1, - Tags: []model.KeyValue{ - model.String(conventions.OtelStatusDescription, "Stale indices"), - model.Int64(conventions.OtelStatusCode, int64(ptrace.StatusCodeError)), - model.Bool("error", true), - }, - References: []model.SpanRef{ - { - TraceID: traceID, - SpanID: parentSpanID, - RefType: model.SpanRefType_CHILD_OF, - }, - }, - }, - { - TraceID: traceID, - SpanID: parentSpanID, - OperationName: "ProxyFetch", - StartTime: t1.Add(d1), - Duration: d2, - Tags: []model.KeyValue{ - model.String(conventions.OtelStatusDescription, "Frontend crash"), - model.Int64(conventions.OtelStatusCode, int64(ptrace.StatusCodeError)), - model.Bool("error", true), - }, - }, - }, - }, - } -} - -func TestSampling(t *testing.T) { - config := &configuration{ - CollectorGRPCServerSettings: configgrpc.GRPCServerSettings{NetAddr: confignet.NetAddr{ - Endpoint: testutil.GetAvailableLocalAddress(t), - Transport: "tcp", - }}, - } - sink := new(consumertest.TracesSink) - - set := receivertest.NewNopCreateSettings() - jr, err := newJaegerReceiver(jaegerReceiver, config, sink, set) - require.NoError(t, err) - - require.NoError(t, jr.Start(context.Background(), componenttest.NewNopHost())) - t.Cleanup(func() { require.NoError(t, jr.Shutdown(context.Background())) }) - - conn, err := grpc.Dial(config.CollectorGRPCServerSettings.NetAddr.Endpoint, grpc.WithTransportCredentials(insecure.NewCredentials())) - assert.NoError(t, err) - defer conn.Close() - - cl := api_v2.NewSamplingManagerClient(conn) - - resp, err := cl.GetSamplingStrategy(context.Background(), &api_v2.SamplingStrategyParameters{ - ServiceName: "foo", - }) - assert.Error(t, err, "expect: unknown service jaeger.api_v2.SamplingManager") - assert.Nil(t, resp) -} - -func TestConsumeThriftTrace(t *testing.T) { - tests := []struct { - batch *jaegerthrift.Batch - numSpans int - }{ - { - batch: nil, - }, - { - batch: &jaegerthrift.Batch{Spans: []*jaegerthrift.Span{{}}}, - numSpans: 1, - }, - } - for _, test := range tests { - numSpans, err := consumeTraces(context.Background(), test.batch, consumertest.NewNop()) - require.NoError(t, err) - assert.Equal(t, test.numSpans, numSpans) - } -} - -func sendToCollector(endpoint string, batch *jaegerthrift.Batch) error { - buf, err := thrift.NewTSerializer().Write(context.Background(), batch) - if err != nil { - return err - } - req, err := http.NewRequest("POST", endpoint, bytes.NewBuffer(buf)) - if err != nil { - return err - } - req.Header.Set("Content-Type", "application/x-thrift") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - - _, err = io.Copy(io.Discard, resp.Body) - if err != nil { - return err - } - resp.Body.Close() - - if resp.StatusCode < 200 || resp.StatusCode >= 300 { - return fmt.Errorf("failed to upload traces; HTTP status code: %d", resp.StatusCode) - } - return nil -} diff --git a/testbed/testbed/multi_receiver_test_case.go b/testbed/testbed/multi_receiver_test_case.go index b75c8d03dc40..07c776d0c46f 100644 --- a/testbed/testbed/multi_receiver_test_case.go +++ b/testbed/testbed/multi_receiver_test_case.go @@ -32,7 +32,7 @@ type MultiReceiverTestCase struct { Sender DataSender Receivers []DataReceiver - LoadGenerator *LoadGenerator + LoadGenerator *ProviderSender MockBackends map[DataReceiver]*MockBackend validator *MultiReceiverTestCaseValidator @@ -102,8 +102,9 @@ func NewMultiReceiverTestCase( tc.resourceSpec.ResourceCheckPeriod = tc.Duration } - tc.LoadGenerator, err = NewLoadGenerator(dataProvider, sender) + lg, err := NewLoadGenerator(dataProvider, sender) require.NoError(t, err, "Cannot create generator") + tc.LoadGenerator = lg.(*ProviderSender) for _, receiver := range receivers { tc.MockBackends[receiver] = NewMockBackend(tc.composeTestResultFileName("backend.log"), receiver) @@ -143,20 +144,20 @@ func (tc *MultiReceiverTestCase) StartAgent(args ...string) { } }() - endpoint := tc.LoadGenerator.sender.GetEndpoint() + endpoint := tc.LoadGenerator.Sender.GetEndpoint() if endpoint != nil { // Wait for agent to start. We consider the agent started when we can // connect to the port to which we intend to send load. We only do this // if the endpoint is not-empty, i.e. the sender does use network (some senders // like text log writers don't). tc.WaitFor(func() bool { - conn, err := net.Dial(tc.LoadGenerator.sender.GetEndpoint().Network(), tc.LoadGenerator.sender.GetEndpoint().String()) + conn, err := net.Dial(tc.LoadGenerator.Sender.GetEndpoint().Network(), tc.LoadGenerator.Sender.GetEndpoint().String()) if err == nil && conn != nil { conn.Close() return true } return false - }, fmt.Sprintf("connection to %s:%s", tc.LoadGenerator.sender.GetEndpoint().Network(), tc.LoadGenerator.sender.GetEndpoint().String())) + }, fmt.Sprintf("connection to %s:%s", tc.LoadGenerator.Sender.GetEndpoint().Network(), tc.LoadGenerator.Sender.GetEndpoint().String())) } } @@ -322,4 +323,3 @@ func (tc *MultiReceiverTestCase) logStatsOnce() { backend.GetStats()) } } -