diff --git a/cmd/opentelemetry-collector/app/exporter/jaegerexporter/.nocover b/cmd/opentelemetry-collector/app/exporter/jaegerexporter/.nocover deleted file mode 100644 index 9d6cf4b7fb6..00000000000 --- a/cmd/opentelemetry-collector/app/exporter/jaegerexporter/.nocover +++ /dev/null @@ -1 +0,0 @@ -FIXME diff --git a/cmd/opentelemetry-collector/app/exporter/jaegerexporter/jaeger_exporter.go b/cmd/opentelemetry-collector/app/exporter/jaegerexporter/jaeger_exporter.go index 2e84db08535..0b88f794e07 100644 --- a/cmd/opentelemetry-collector/app/exporter/jaegerexporter/jaeger_exporter.go +++ b/cmd/opentelemetry-collector/app/exporter/jaegerexporter/jaeger_exporter.go @@ -22,7 +22,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector/exporter/jaegerexporter" "github.com/spf13/viper" - "github.com/jaegertracing/jaeger/cmd/agent/app/reporter/grpc" + grpcRep "github.com/jaegertracing/jaeger/cmd/agent/app/reporter/grpc" ) // Factory wraps jaegerexporter.Factory and makes the default config configurable via viper. @@ -44,7 +44,7 @@ func (f Factory) Type() configmodels.Type { // CreateDefaultConfig returns default configuration of Factory. // This function implements OTEL component.ExporterFactoryBase interface. func (f Factory) CreateDefaultConfig() configmodels.Exporter { - repCfg := grpc.ConnBuilder{} + repCfg := grpcRep.ConnBuilder{} repCfg.InitFromViper(f.Viper) cfg := f.Wrapped.CreateDefaultConfig().(*jaegerexporter.Config) if len(repCfg.CollectorHostPorts) > 0 { diff --git a/cmd/opentelemetry-collector/app/exporter/jaegerexporter/jaeger_exporter_test.go b/cmd/opentelemetry-collector/app/exporter/jaegerexporter/jaeger_exporter_test.go new file mode 100644 index 00000000000..317db56bf66 --- /dev/null +++ b/cmd/opentelemetry-collector/app/exporter/jaegerexporter/jaeger_exporter_test.go @@ -0,0 +1,86 @@ +package jaegerexporter + +import ( + "context" + jConfig "github.com/jaegertracing/jaeger/pkg/config" + "github.com/open-telemetry/opentelemetry-collector/component" + "github.com/open-telemetry/opentelemetry-collector/config" + "github.com/open-telemetry/opentelemetry-collector/config/configerror" + "github.com/open-telemetry/opentelemetry-collector/config/configmodels" + "github.com/open-telemetry/opentelemetry-collector/exporter/jaegerexporter" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "path" + "testing" + + grpcRep "github.com/jaegertracing/jaeger/cmd/agent/app/reporter/grpc" +) + +func TestDefaultValues(t *testing.T) { + v, c := jConfig.Viperize(grpcRep.AddFlags) + err := c.ParseFlags([]string{}) + require.NoError(t, err) + + factory := &Factory{Viper: v, Wrapped: &jaegerexporter.Factory{}} + cfg := factory.CreateDefaultConfig().(*jaegerexporter.Config) + assert.Empty(t, cfg.GRPCSettings.Endpoint) + tlsConf := cfg.TLSConfig + assert.False(t, tlsConf.UseSecure) + assert.Empty(t, tlsConf.CaCert) + assert.Empty(t, tlsConf.ClientKey) + assert.Empty(t, tlsConf.ClientCert) + assert.Empty(t, tlsConf.ServerNameOverride) +} + +func TestDefaultValueFromViper(t *testing.T) { + v, c := jConfig.Viperize(grpcRep.AddFlags) + err := c.ParseFlags([]string{"--reporter.grpc.host-port=foo", "--reporter.grpc.tls.enabled=true", "--reporter.grpc.tls.ca=ca.crt"}) + require.NoError(t, err) + + f := &Factory{ + Wrapped: &jaegerexporter.Factory{}, + Viper: v, + } + + cfg := f.CreateDefaultConfig().(*jaegerexporter.Config) + assert.Equal(t, "foo", cfg.GRPCSettings.Endpoint) + tlsConfig := cfg.TLSConfig + assert.Equal(t, true, tlsConfig.UseSecure) + assert.Equal(t, "ca.crt", tlsConfig.CaCert) +} + +func TestLoadConfigAndFlags(t *testing.T) { + factories, err := config.ExampleComponents() + require.NoError(t, err) + + v, c := jConfig.Viperize(grpcRep.AddFlags) + err = c.ParseFlags([]string{"--reporter.grpc.host-port=foo"}) + require.NoError(t, err) + + factory := &Factory{Viper: v, Wrapped: &jaegerexporter.Factory{}} + assert.Equal(t, "foo", factory.CreateDefaultConfig().(*jaegerexporter.Config).GRPCSettings.Endpoint) + + factories.Exporters["jaeger"] = factory + colConfig, err := config.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + require.NoError(t, err) + require.NotNil(t, colConfig) + + cfg := colConfig.Exporters["jaeger"].(*jaegerexporter.Config) + assert.Equal(t, "bar", cfg.GRPCSettings.Endpoint) +} + +func TestType(t *testing.T) { + f := &Factory{ + Wrapped: &jaegerexporter.Factory{}, + } + assert.Equal(t, configmodels.Type("jaeger"), f.Type()) +} + +func TestCreateMetricsExporter(t *testing.T) { + f := &Factory{ + Wrapped: &jaegerexporter.Factory{}, + } + mReceiver, err := f.CreateMetricsExporter(context.Background(), component.ExporterCreateParams{}, nil) + assert.Equal(t, configerror.ErrDataTypeIsNotSupported, err) + assert.Nil(t, mReceiver) +} diff --git a/cmd/opentelemetry-collector/app/exporter/jaegerexporter/testdata/config.yaml b/cmd/opentelemetry-collector/app/exporter/jaegerexporter/testdata/config.yaml new file mode 100644 index 00000000000..14f994fd098 --- /dev/null +++ b/cmd/opentelemetry-collector/app/exporter/jaegerexporter/testdata/config.yaml @@ -0,0 +1,16 @@ +receivers: + examplereceiver: + +processors: + exampleprocessor: + +exporters: + jaeger: + endpoint: bar + +service: + pipelines: + traces: + receivers: [examplereceiver] + processors: [exampleprocessor] + exporters: [jaeger] diff --git a/cmd/opentelemetry-collector/app/receiver/jaegerreceiver/jaeger_receiver_test.go b/cmd/opentelemetry-collector/app/receiver/jaegerreceiver/jaeger_receiver_test.go index 48335f4a258..fdb8e365da7 100644 --- a/cmd/opentelemetry-collector/app/receiver/jaegerreceiver/jaeger_receiver_test.go +++ b/cmd/opentelemetry-collector/app/receiver/jaegerreceiver/jaeger_receiver_test.go @@ -16,6 +16,7 @@ package jaegerreceiver import ( "context" + "fmt" "path" "testing" @@ -23,11 +24,14 @@ import ( "github.com/open-telemetry/opentelemetry-collector/config" "github.com/open-telemetry/opentelemetry-collector/config/configerror" "github.com/open-telemetry/opentelemetry-collector/config/configmodels" + "github.com/open-telemetry/opentelemetry-collector/receiver" "github.com/open-telemetry/opentelemetry-collector/receiver/jaegerreceiver" - "github.com/spf13/viper" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + agentApp "github.com/jaegertracing/jaeger/cmd/agent/app" + grpcRep "github.com/jaegertracing/jaeger/cmd/agent/app/reporter/grpc" + collectorApp "github.com/jaegertracing/jaeger/cmd/collector/app" jConfig "github.com/jaegertracing/jaeger/pkg/config" "github.com/jaegertracing/jaeger/plugin/sampling/strategystore/static" ) @@ -40,19 +44,87 @@ func TestDefaultValues(t *testing.T) { factory := &Factory{Viper: v, Wrapped: &jaegerreceiver.Factory{}} cfg := factory.CreateDefaultConfig().(*jaegerreceiver.Config) assert.Nil(t, cfg.RemoteSampling) + assert.Empty(t, cfg.Protocols) } func TestDefaultValueFromViper(t *testing.T) { - v := viper.New() - v.Set(static.SamplingStrategiesFile, "config.json") - - f := &Factory{ - Wrapped: &jaegerreceiver.Factory{}, - Viper: v, + tests := []struct { + name string + flags []string + expected *jaegerreceiver.Config + }{ + { + name: "samplingStrategyFile", + flags: []string{fmt.Sprintf("--%s=%s", static.SamplingStrategiesFile, "conf.json")}, + expected: &jaegerreceiver.Config{ + RemoteSampling: &jaegerreceiver.RemoteSamplingConfig{ + StrategyFile: "conf.json", + }, + Protocols: map[string]*receiver.SecureReceiverSettings{}, + }, + }, + { + name: "thriftCompact", + flags: []string{fmt.Sprintf("--%s=%s", thriftCompactHostPort, "localhost:9999")}, + expected: &jaegerreceiver.Config{ + Protocols: map[string]*receiver.SecureReceiverSettings{ + "thrift_compact": {ReceiverSettings: configmodels.ReceiverSettings{Endpoint: "localhost:9999"}}, + }, + }, + }, + { + name: "thriftBinary", + flags: []string{fmt.Sprintf("--%s=%s", thriftBinaryHostPort, "localhost:8888")}, + expected: &jaegerreceiver.Config{ + Protocols: map[string]*receiver.SecureReceiverSettings{ + "thrift_binary": {ReceiverSettings: configmodels.ReceiverSettings{Endpoint: "localhost:8888"}}, + }, + }, + }, + { + name: "grpc", + flags: []string{fmt.Sprintf("--%s=%s", collectorApp.CollectorGRPCHostPort, "localhost:7894")}, + expected: &jaegerreceiver.Config{ + Protocols: map[string]*receiver.SecureReceiverSettings{ + "grpc": {ReceiverSettings: configmodels.ReceiverSettings{Endpoint: "localhost:7894"}}, + }, + }, + }, + { + name: "thriftHttp", + flags: []string{fmt.Sprintf("--%s=%s", collectorApp.CollectorHTTPHostPort, "localhost:8080")}, + expected: &jaegerreceiver.Config{ + Protocols: map[string]*receiver.SecureReceiverSettings{ + "thrift_http": {ReceiverSettings: configmodels.ReceiverSettings{Endpoint: "localhost:8080"}}, + }, + }, + }, + { + name: "thriftHttpAndThriftBinary", + flags: []string{fmt.Sprintf("--%s=%s", collectorApp.CollectorHTTPHostPort, "localhost:8089"), fmt.Sprintf("--%s=%s", thriftBinaryHostPort, "localhost:2222")}, + expected: &jaegerreceiver.Config{ + Protocols: map[string]*receiver.SecureReceiverSettings{ + "thrift_http": {ReceiverSettings: configmodels.ReceiverSettings{Endpoint: "localhost:8089"}}, + "thrift_binary": {ReceiverSettings: configmodels.ReceiverSettings{Endpoint: "localhost:2222"}}, + }, + }, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + v, c := jConfig.Viperize(static.AddFlags, grpcRep.AddFlags, agentApp.AddFlags, collectorApp.AddFlags) + err := c.ParseFlags(test.flags) + require.NoError(t, err) + f := &Factory{ + Wrapped: &jaegerreceiver.Factory{}, + Viper: v, + } + cfg := f.CreateDefaultConfig().(*jaegerreceiver.Config) + test.expected.TypeVal = "jaeger" + test.expected.NameVal = "jaeger" + assert.Equal(t, test.expected, cfg) + }) } - - cfg := f.CreateDefaultConfig().(*jaegerreceiver.Config) - assert.Equal(t, "config.json", cfg.RemoteSampling.StrategyFile) } func TestLoadConfigAndFlags(t *testing.T) {