From 6935b605a7decd7e711954f281e671ea66687ad9 Mon Sep 17 00:00:00 2001 From: Pavol Loffay Date: Thu, 14 May 2020 16:40:47 +0200 Subject: [PATCH] Refactor flags Signed-off-by: Pavol Loffay --- cmd/agent/app/reporter/grpc/flags.go | 7 +- cmd/collector/app/builder_flags.go | 23 ++- .../app/defaults/default_config_test.go | 146 +++++++++++++++++- .../jaegerexporter/jaeger_exporter_test.go | 29 +++- .../app/{util.go => flags.go} | 15 +- .../app/processor/resourceprocessor/flags.go | 28 ++++ .../resourceprocessor/resource_processor.go | 9 -- .../app/receiver/jaegerreceiver/flags.go | 39 +++++ .../jaegerreceiver/jaeger_receiver.go | 14 +- .../jaegerreceiver/jaeger_receiver_test.go | 8 +- cmd/opentelemetry-collector/cmd/agent/main.go | 10 +- .../cmd/collector/main.go | 12 +- .../cmd/ingester/main.go | 6 +- .../sampling/strategystore/static/options.go | 7 +- 14 files changed, 287 insertions(+), 66 deletions(-) rename cmd/opentelemetry-collector/app/{util.go => flags.go} (71%) create mode 100644 cmd/opentelemetry-collector/app/processor/resourceprocessor/flags.go create mode 100644 cmd/opentelemetry-collector/app/receiver/jaegerreceiver/flags.go diff --git a/cmd/agent/app/reporter/grpc/flags.go b/cmd/agent/app/reporter/grpc/flags.go index e557a8be6fb..43c25502b82 100644 --- a/cmd/agent/app/reporter/grpc/flags.go +++ b/cmd/agent/app/reporter/grpc/flags.go @@ -39,9 +39,14 @@ var tlsFlagsConfig = tlscfg.ClientFlagsConfig{ // AddFlags adds flags for Options. func AddFlags(flags *flag.FlagSet) { - flags.String(collectorHostPort, "", "Comma-separated string representing host:port of a static list of collectors to connect to directly") flags.Uint(retry, defaultMaxRetry, "Sets the maximum number of retries for a call") flags.Int(discoveryMinPeers, 3, "Max number of collectors to which the agent will try to connect at any given time") + AddOTELFlags(flags) +} + +// AddOTELFlags adds flags that are exposed by OTEL collector +func AddOTELFlags(flags *flag.FlagSet) { + flags.String(collectorHostPort, "", "Comma-separated string representing host:port of a static list of collectors to connect to directly") tlsFlagsConfig.AddFlags(flags) } diff --git a/cmd/collector/app/builder_flags.go b/cmd/collector/app/builder_flags.go index c62b88c511e..dbd112b4fc5 100644 --- a/cmd/collector/app/builder_flags.go +++ b/cmd/collector/app/builder_flags.go @@ -27,12 +27,14 @@ import ( ) const ( - collectorDynQueueSizeMemory = "collector.queue-size-memory" - collectorQueueSize = "collector.queue-size" - collectorNumWorkers = "collector.num-workers" - collectorHTTPPort = "collector.http-port" - collectorGRPCPort = "collector.grpc-port" - CollectorHTTPHostPort = "collector.http-server.host-port" + collectorDynQueueSizeMemory = "collector.queue-size-memory" + collectorQueueSize = "collector.queue-size" + collectorNumWorkers = "collector.num-workers" + collectorHTTPPort = "collector.http-port" + collectorGRPCPort = "collector.grpc-port" + // CollectorHTTPHostPort is a flag for collector HTTP port + CollectorHTTPHostPort = "collector.http-server.host-port" + // CollectorGRPCHostPort is a flag for collector gRPC port CollectorGRPCHostPort = "collector.grpc-server.host-port" collectorZipkinHTTPPort = "collector.zipkin.http-port" collectorZipkinHTTPHostPort = "collector.zipkin.host-port" @@ -82,13 +84,18 @@ func AddFlags(flags *flag.FlagSet) { flags.Int(collectorHTTPPort, 0, collectorHTTPPortWarning+" see --"+CollectorHTTPHostPort) flags.Int(collectorGRPCPort, 0, collectorGRPCPortWarning+" see --"+CollectorGRPCHostPort) flags.Int(collectorZipkinHTTPPort, 0, collectorZipkinHTTPPortWarning+" see --"+collectorZipkinHTTPHostPort) - flags.String(CollectorHTTPHostPort, ports.PortToHostPort(ports.CollectorHTTP), "The host:port (e.g. 127.0.0.1:5555 or :5555) of the collector's HTTP server") - flags.String(CollectorGRPCHostPort, ports.PortToHostPort(ports.CollectorGRPC), "The host:port (e.g. 127.0.0.1:5555 or :5555) of the collector's GRPC server") flags.String(collectorZipkinHTTPHostPort, ports.PortToHostPort(0), "The host:port (e.g. 127.0.0.1:5555 or :5555) of the collector's Zipkin server") flags.Uint(collectorDynQueueSizeMemory, 0, "(experimental) The max memory size in MiB to use for the dynamic queue.") flags.String(collectorTags, "", "One or more tags to be added to the Process tags of all spans passing through this collector. Ex: key1=value1,key2=${envVar:defaultValue}") flags.String(collectorZipkinAllowedOrigins, "*", "Comma separated list of allowed origins for the Zipkin collector service, default accepts all") flags.String(collectorZipkinAllowedHeaders, "content-type", "Comma separated list of allowed headers for the Zipkin collector service, default content-type") + AddOTELFlags(flags) +} + +// AddOTELFlags adds flags that are exposed by OTEL collector +func AddOTELFlags(flags *flag.FlagSet) { + flags.String(CollectorHTTPHostPort, ports.PortToHostPort(ports.CollectorHTTP), "The host:port (e.g. 127.0.0.1:5555 or :5555) of the collector's HTTP server") + flags.String(CollectorGRPCHostPort, ports.PortToHostPort(ports.CollectorGRPC), "The host:port (e.g. 127.0.0.1:5555 or :5555) of the collector's GRPC server") tlsFlagsConfig.AddFlags(flags) } diff --git a/cmd/opentelemetry-collector/app/defaults/default_config_test.go b/cmd/opentelemetry-collector/app/defaults/default_config_test.go index c9befea7b47..0e6fe314f87 100644 --- a/cmd/opentelemetry-collector/app/defaults/default_config_test.go +++ b/cmd/opentelemetry-collector/app/defaults/default_config_test.go @@ -23,13 +23,15 @@ import ( "github.com/open-telemetry/opentelemetry-collector/config/configmodels" "github.com/open-telemetry/opentelemetry-collector/exporter/jaegerexporter" "github.com/open-telemetry/opentelemetry-collector/processor/resourceprocessor" + "github.com/open-telemetry/opentelemetry-collector/receiver" "github.com/open-telemetry/opentelemetry-collector/receiver/jaegerreceiver" + "github.com/open-telemetry/opentelemetry-collector/receiver/zipkinreceiver" "github.com/spf13/viper" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/zap" - "github.com/jaegertracing/jaeger/cmd/agent/app/reporter/grpc" + "github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app" "github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/exporter/cassandra" "github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/exporter/elasticsearch" "github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/exporter/grpcplugin" @@ -118,7 +120,7 @@ func TestDefaultCollectorConfig(t *testing.T) { } for _, test := range tests { t.Run(test.storageType, func(t *testing.T) { - v, _ := jConfig.Viperize(grpc.AddFlags) + v, _ := jConfig.Viperize(app.AddComponentFlags) factories := Components(v) for key, val := range test.config { v.Set(key, val) @@ -162,6 +164,87 @@ func TestDefaultCollectorConfig(t *testing.T) { } } +func TestCreateCollectorReceivers(t *testing.T) { + tests := []struct { + name string + args []string + zipkinHostPort string + receivers configmodels.Receivers + }{ + { + name: "defaultWithoutZipkin", + args: []string{}, + zipkinHostPort: ":0", + receivers: configmodels.Receivers{ + "jaeger": &jaegerreceiver.Config{ + TypeVal: "jaeger", + NameVal: "jaeger", + Protocols: map[string]*receiver.SecureReceiverSettings{ + "grpc": { + ReceiverSettings: configmodels.ReceiverSettings{ + Endpoint: gRPCEndpoint, + }, + }, + "thrift_http": { + ReceiverSettings: configmodels.ReceiverSettings{ + Endpoint: httpThriftBinaryEndpoint, + }, + }, + }, + }, + }, + }, + { + name: "configurationViaFlags", + args: []string{ + "--collector.grpc-server.host-port=host:11", + "--collector.grpc.tls.cert=cacert.crt", + "--collector.grpc.tls.key=keycert.crt", + "--collector.http-server.host-port=host2:22", + }, + zipkinHostPort: "localhost:55", + receivers: configmodels.Receivers{ + "jaeger": &jaegerreceiver.Config{ + TypeVal: "jaeger", + NameVal: "jaeger", + Protocols: map[string]*receiver.SecureReceiverSettings{ + "grpc": { + ReceiverSettings: configmodels.ReceiverSettings{ + Endpoint: "host:11", + }, + TLSCredentials: &receiver.TLSCredentials{ + CertFile: "cacert.crt", + KeyFile: "keycert.crt", + }, + }, + "thrift_http": { + ReceiverSettings: configmodels.ReceiverSettings{ + Endpoint: "host2:22", + }, + }, + }, + }, + "zipkin": &zipkinreceiver.Config{ + ReceiverSettings: configmodels.ReceiverSettings{ + NameVal: "zipkin", + TypeVal: "zipkin", + Endpoint: "localhost:55", + }, + }, + }, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + v, c := jConfig.Viperize(app.AddComponentFlags) + require.NoError(t, c.ParseFlags(test.args)) + factories := Components(v) + recvs := createCollectorReceivers(test.zipkinHostPort, factories) + assert.Equal(t, test.receivers, recvs) + }) + } +} + func TestDefaultAgentConfig(t *testing.T) { tests := []struct { config map[string]interface{} @@ -196,7 +279,7 @@ func TestDefaultAgentConfig(t *testing.T) { } for _, test := range tests { t.Run(fmt.Sprintf("%v", test.config), func(t *testing.T) { - v, _ := jConfig.Viperize(grpc.AddFlags) + v, _ := jConfig.Viperize(app.AddComponentFlags) for key, val := range test.config { v.Set(key, val) } @@ -221,6 +304,63 @@ func TestDefaultAgentConfig(t *testing.T) { } } +func TestCreateAgentReceivers(t *testing.T) { + tests := []struct { + args []string + receivers configmodels.Receivers + }{ + { + args: []string{""}, + receivers: configmodels.Receivers{ + "jaeger": &jaegerreceiver.Config{ + TypeVal: "jaeger", + NameVal: "jaeger", + Protocols: map[string]*receiver.SecureReceiverSettings{ + "thrift_compact": { + ReceiverSettings: configmodels.ReceiverSettings{ + Endpoint: udpThriftCompactEndpoint, + }, + }, + "thrift_binary": { + ReceiverSettings: configmodels.ReceiverSettings{ + Endpoint: udpThriftBinaryEndpoint, + }, + }, + }, + }, + }, + }, + { + args: []string{"--processor.jaeger-binary.server-host-port=host:1", "--processor.jaeger-compact.server-host-port=host:2"}, + receivers: configmodels.Receivers{ + "jaeger": &jaegerreceiver.Config{ + TypeVal: "jaeger", + NameVal: "jaeger", + Protocols: map[string]*receiver.SecureReceiverSettings{ + "thrift_binary": { + ReceiverSettings: configmodels.ReceiverSettings{ + Endpoint: "host:1", + }, + }, + "thrift_compact": { + ReceiverSettings: configmodels.ReceiverSettings{ + Endpoint: "host:2", + }, + }, + }, + }, + }, + }, + } + for _, test := range tests { + v, c := jConfig.Viperize(app.AddComponentFlags) + require.NoError(t, c.ParseFlags(test.args)) + factories := Components(v) + recvs := createAgentReceivers(factories) + assert.Equal(t, test.receivers, recvs) + } +} + func TestDefaultIngesterConfig(t *testing.T) { tests := []struct { storageType string diff --git a/cmd/opentelemetry-collector/app/exporter/jaegerexporter/jaeger_exporter_test.go b/cmd/opentelemetry-collector/app/exporter/jaegerexporter/jaeger_exporter_test.go index 317db56bf66..ab327d05ab6 100644 --- a/cmd/opentelemetry-collector/app/exporter/jaegerexporter/jaeger_exporter_test.go +++ b/cmd/opentelemetry-collector/app/exporter/jaegerexporter/jaeger_exporter_test.go @@ -1,8 +1,24 @@ +// 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 jaegerexporter import ( "context" - jConfig "github.com/jaegertracing/jaeger/pkg/config" + "path" + "testing" + "github.com/open-telemetry/opentelemetry-collector/component" "github.com/open-telemetry/opentelemetry-collector/config" "github.com/open-telemetry/opentelemetry-collector/config/configerror" @@ -10,14 +26,13 @@ import ( "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" + "github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/receiver/jaegerreceiver" + jConfig "github.com/jaegertracing/jaeger/pkg/config" ) func TestDefaultValues(t *testing.T) { - v, c := jConfig.Viperize(grpcRep.AddFlags) + v, c := jConfig.Viperize(jaegerreceiver.AddFlags) err := c.ParseFlags([]string{}) require.NoError(t, err) @@ -33,7 +48,7 @@ func TestDefaultValues(t *testing.T) { } func TestDefaultValueFromViper(t *testing.T) { - v, c := jConfig.Viperize(grpcRep.AddFlags) + v, c := jConfig.Viperize(jaegerreceiver.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) @@ -53,7 +68,7 @@ func TestLoadConfigAndFlags(t *testing.T) { factories, err := config.ExampleComponents() require.NoError(t, err) - v, c := jConfig.Viperize(grpcRep.AddFlags) + v, c := jConfig.Viperize(jaegerreceiver.AddFlags) err = c.ParseFlags([]string{"--reporter.grpc.host-port=foo"}) require.NoError(t, err) diff --git a/cmd/opentelemetry-collector/app/util.go b/cmd/opentelemetry-collector/app/flags.go similarity index 71% rename from cmd/opentelemetry-collector/app/util.go rename to cmd/opentelemetry-collector/app/flags.go index 65afa2592dc..e60dc078f02 100644 --- a/cmd/opentelemetry-collector/app/util.go +++ b/cmd/opentelemetry-collector/app/flags.go @@ -19,15 +19,26 @@ import ( "fmt" "strings" + jConfigFile "github.com/jaegertracing/jaeger/cmd/flags" "github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/exporter/cassandra" "github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/exporter/elasticsearch" "github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/exporter/grpcplugin" "github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/exporter/kafka" + "github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/processor/resourceprocessor" + "github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/receiver/jaegerreceiver" ) -// StorageFlags return a function that adds storage flags. +// AddComponentFlags adds all flags exposed by components +func AddComponentFlags(flags *flag.FlagSet) { + // Jaeger receiver (via sampling strategies receiver) exposes the same flags as exporter. + jaegerreceiver.AddFlags(flags) + resourceprocessor.AddFlags(flags) + jConfigFile.AddConfigFileFlag(flags) +} + +// AddStorageFlags return a function that adds storage flags. // storage parameter can contain a comma separated list of supported Jaeger storage backends. -func StorageFlags(storage string) (func(*flag.FlagSet), error) { +func AddStorageFlags(storage string) (func(*flag.FlagSet), error) { var flagFn []func(*flag.FlagSet) for _, s := range strings.Split(storage, ",") { switch s { diff --git a/cmd/opentelemetry-collector/app/processor/resourceprocessor/flags.go b/cmd/opentelemetry-collector/app/processor/resourceprocessor/flags.go new file mode 100644 index 00000000000..fd783f24cc9 --- /dev/null +++ b/cmd/opentelemetry-collector/app/processor/resourceprocessor/flags.go @@ -0,0 +1,28 @@ +// 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 resourceprocessor + +import ( + "flag" + "fmt" + + "github.com/jaegertracing/jaeger/cmd/agent/app/reporter" +) + +// AddFlags adds flags for Options. +func AddFlags(flags *flag.FlagSet) { + flags.String(reporter.AgentTagsDeprecated, "", fmt.Sprintf("(deprecated, use --%s) One or more tags to be added to the Process tags of all spans passing through this agent. Ex: key1=value1,key2=${envVar:defaultValue}", resourceLabels)) + flags.String(resourceLabels, "", "One or more tags to be added to the Process tags of all spans passing through this agent. Ex: key1=value1,key2=${envVar:defaultValue}") +} diff --git a/cmd/opentelemetry-collector/app/processor/resourceprocessor/resource_processor.go b/cmd/opentelemetry-collector/app/processor/resourceprocessor/resource_processor.go index a4cfe891ab2..feb18e1e2fc 100644 --- a/cmd/opentelemetry-collector/app/processor/resourceprocessor/resource_processor.go +++ b/cmd/opentelemetry-collector/app/processor/resourceprocessor/resource_processor.go @@ -15,9 +15,6 @@ package resourceprocessor import ( - "flag" - "fmt" - "github.com/open-telemetry/opentelemetry-collector/component" "github.com/open-telemetry/opentelemetry-collector/config/configmodels" "github.com/open-telemetry/opentelemetry-collector/consumer" @@ -88,9 +85,3 @@ func (f Factory) CreateMetricsProcessor( ) (component.MetricsProcessorOld, error) { return f.Wrapped.CreateMetricsProcessor(logger, nextConsumer, cfg) } - -// AddFlags adds flags for Options. -func AddFlags(flags *flag.FlagSet) { - flags.String(reporter.AgentTagsDeprecated, "", fmt.Sprintf("(deprecated, use --%s) One or more tags to be added to the Process tags of all spans passing through this agent. Ex: key1=value1,key2=${envVar:defaultValue}", resourceLabels)) - flags.String(resourceLabels, "", "One or more tags to be added to the Process tags of all spans passing through this agent. Ex: key1=value1,key2=${envVar:defaultValue}") -} diff --git a/cmd/opentelemetry-collector/app/receiver/jaegerreceiver/flags.go b/cmd/opentelemetry-collector/app/receiver/jaegerreceiver/flags.go new file mode 100644 index 00000000000..e87c5f491f2 --- /dev/null +++ b/cmd/opentelemetry-collector/app/receiver/jaegerreceiver/flags.go @@ -0,0 +1,39 @@ +// 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 jaegerreceiver + +import ( + "flag" + "strconv" + + grpcRep "github.com/jaegertracing/jaeger/cmd/agent/app/reporter/grpc" + collectorApp "github.com/jaegertracing/jaeger/cmd/collector/app" + "github.com/jaegertracing/jaeger/plugin/sampling/strategystore/static" + "github.com/jaegertracing/jaeger/ports" +) + +const ( + thriftBinaryHostPort = "processor.jaeger-binary.server-host-port" + thriftCompactHostPort = "processor.jaeger-compact.server-host-port" +) + +// AddFlags adds flags to flag set. +func AddFlags(flags *flag.FlagSet) { + flags.String(thriftBinaryHostPort, ":"+strconv.Itoa(ports.AgentJaegerThriftBinaryUDP), "host:port for the UDP server") + flags.String(thriftCompactHostPort, ":"+strconv.Itoa(ports.AgentJaegerThriftCompactUDP), "host:port for the UDP server") + collectorApp.AddOTELFlags(flags) + grpcRep.AddOTELFlags(flags) + static.AddOTELFlags(flags) +} diff --git a/cmd/opentelemetry-collector/app/receiver/jaegerreceiver/jaeger_receiver.go b/cmd/opentelemetry-collector/app/receiver/jaegerreceiver/jaeger_receiver.go index da1a3bd931e..5ebce48ff7f 100644 --- a/cmd/opentelemetry-collector/app/receiver/jaegerreceiver/jaeger_receiver.go +++ b/cmd/opentelemetry-collector/app/receiver/jaegerreceiver/jaeger_receiver.go @@ -25,16 +25,11 @@ import ( "github.com/spf13/viper" agentApp "github.com/jaegertracing/jaeger/cmd/agent/app" - "github.com/jaegertracing/jaeger/cmd/agent/app/reporter/grpc" + grpcRep "github.com/jaegertracing/jaeger/cmd/agent/app/reporter/grpc" collectorApp "github.com/jaegertracing/jaeger/cmd/collector/app" "github.com/jaegertracing/jaeger/plugin/sampling/strategystore/static" ) -const ( - thriftBinaryHostPort = "processor.jaeger-binary.server-host-port" - thriftCompactHostPort = "processor.jaeger-compact.server-host-port" -) - // Factory wraps jaegerreceiver.Factory and makes the default config configurable via viper. // For instance this enables using flags as default values in the config object. type Factory struct { @@ -67,6 +62,7 @@ func configureAgent(v *viper.Viper, cfg *jaegerreceiver.Config) { if v.IsSet(thriftBinaryHostPort) { cfg.Protocols["thrift_binary"] = &receiver.SecureReceiverSettings{ ReceiverSettings: configmodels.ReceiverSettings{ + // TODO OTEL does not expose number of workers or queue length Endpoint: v.GetString(thriftBinaryHostPort), }, } @@ -74,6 +70,7 @@ func configureAgent(v *viper.Viper, cfg *jaegerreceiver.Config) { if v.IsSet(thriftCompactHostPort) { cfg.Protocols["thrift_compact"] = &receiver.SecureReceiverSettings{ ReceiverSettings: configmodels.ReceiverSettings{ + // TODO OTEL does not expose number of workers or queue length Endpoint: v.GetString(thriftCompactHostPort), }, } @@ -89,8 +86,9 @@ func configureCollector(v *viper.Viper, cfg *jaegerreceiver.Config) { Endpoint: cOpts.CollectorGRPCHostPort, }, } - if cOpts.TLS.ClientCAPath != "" && cOpts.TLS.KeyPath != "" { + if cOpts.TLS.CertPath != "" && cOpts.TLS.KeyPath != "" { cfg.Protocols["grpc"].TLSCredentials = &receiver.TLSCredentials{ + // TODO client-ca is missing in OTEL KeyFile: cOpts.TLS.KeyPath, CertFile: cOpts.TLS.CertPath, } @@ -113,7 +111,7 @@ func createDefaultSamplingConfig(v *viper.Viper) *jaegerreceiver.RemoteSamplingC StrategyFile: strategyFile, } } - repCfg := grpc.ConnBuilder{} + repCfg := grpcRep.ConnBuilder{} repCfg.InitFromViper(v) // This is for agent mode. // This uses --reporter.grpc.host-port flag to set the fetch endpoint for the sampling strategies. 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 fdb8e365da7..346e004692a 100644 --- a/cmd/opentelemetry-collector/app/receiver/jaegerreceiver/jaeger_receiver_test.go +++ b/cmd/opentelemetry-collector/app/receiver/jaegerreceiver/jaeger_receiver_test.go @@ -29,15 +29,13 @@ import ( "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" ) func TestDefaultValues(t *testing.T) { - v, c := jConfig.Viperize(static.AddFlags) + v, c := jConfig.Viperize(AddFlags) err := c.ParseFlags([]string{}) require.NoError(t, err) @@ -112,7 +110,7 @@ func TestDefaultValueFromViper(t *testing.T) { } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - v, c := jConfig.Viperize(static.AddFlags, grpcRep.AddFlags, agentApp.AddFlags, collectorApp.AddFlags) + v, c := jConfig.Viperize(AddFlags) err := c.ParseFlags(test.flags) require.NoError(t, err) f := &Factory{ @@ -131,7 +129,7 @@ func TestLoadConfigAndFlags(t *testing.T) { factories, err := config.ExampleComponents() require.NoError(t, err) - v, c := jConfig.Viperize(static.AddFlags) + v, c := jConfig.Viperize(AddFlags) err = c.ParseFlags([]string{"--sampling.strategies-file=bar.json"}) require.NoError(t, err) diff --git a/cmd/opentelemetry-collector/cmd/agent/main.go b/cmd/opentelemetry-collector/cmd/agent/main.go index c1963e67886..b9d0adcb00b 100644 --- a/cmd/opentelemetry-collector/cmd/agent/main.go +++ b/cmd/opentelemetry-collector/cmd/agent/main.go @@ -25,13 +25,11 @@ import ( "github.com/open-telemetry/opentelemetry-collector/service/builder" "github.com/spf13/viper" - "github.com/jaegertracing/jaeger/cmd/agent/app/reporter/grpc" jflags "github.com/jaegertracing/jaeger/cmd/flags" + "github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app" "github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/defaults" - "github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/processor/resourceprocessor" jconfig "github.com/jaegertracing/jaeger/pkg/config" "github.com/jaegertracing/jaeger/pkg/version" - "github.com/jaegertracing/jaeger/plugin/sampling/strategystore/static" ) func main() { @@ -75,13 +73,9 @@ func main() { handleErr(err) cmd := svc.Command() - // TODO add collector HTTP thrift and gRPC server host port flags jconfig.AddFlags(v, cmd, - jflags.AddConfigFileFlag, - grpc.AddFlags, - static.AddFlags, - resourceprocessor.AddFlags, + app.AddComponentFlags, ) // parse flags to propagate Jaeger config file flag value to viper diff --git a/cmd/opentelemetry-collector/cmd/collector/main.go b/cmd/opentelemetry-collector/cmd/collector/main.go index cba02eb55a9..4bd5073706c 100644 --- a/cmd/opentelemetry-collector/cmd/collector/main.go +++ b/cmd/opentelemetry-collector/cmd/collector/main.go @@ -25,15 +25,12 @@ import ( "github.com/open-telemetry/opentelemetry-collector/service/builder" "github.com/spf13/viper" - "github.com/jaegertracing/jaeger/cmd/agent/app/reporter/grpc" collectorApp "github.com/jaegertracing/jaeger/cmd/collector/app" jflags "github.com/jaegertracing/jaeger/cmd/flags" "github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app" "github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/defaults" - "github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/processor/resourceprocessor" jConfig "github.com/jaegertracing/jaeger/pkg/config" "github.com/jaegertracing/jaeger/pkg/version" - "github.com/jaegertracing/jaeger/plugin/sampling/strategystore/static" "github.com/jaegertracing/jaeger/plugin/storage" ) @@ -89,20 +86,15 @@ func main() { // Add Jaeger specific flags to service command // this passes flag values to viper. - storageFlags, err := app.StorageFlags(storageType) + storageFlags, err := app.AddStorageFlags(storageType) if err != nil { handleErr(err) } cmd := svc.Command() - // TODO add agent UDP processors flags jConfig.AddFlags(v, cmd, - collectorApp.AddFlags, - jflags.AddConfigFileFlag, + app.AddComponentFlags, storageFlags, - static.AddFlags, - grpc.AddFlags, - resourceprocessor.AddFlags, ) // parse flags to propagate Jaeger config file flag value to viper diff --git a/cmd/opentelemetry-collector/cmd/ingester/main.go b/cmd/opentelemetry-collector/cmd/ingester/main.go index 4564f4123e9..2729ac71ace 100644 --- a/cmd/opentelemetry-collector/cmd/ingester/main.go +++ b/cmd/opentelemetry-collector/cmd/ingester/main.go @@ -26,7 +26,6 @@ import ( "github.com/spf13/viper" jflags "github.com/jaegertracing/jaeger/cmd/flags" - ingesterApp "github.com/jaegertracing/jaeger/cmd/ingester/app" "github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app" "github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/defaults" jconfig "github.com/jaegertracing/jaeger/pkg/config" @@ -84,7 +83,7 @@ func main() { // Add Jaeger specific flags to service command // this passes flag values to viper. - storageFlags, err := app.StorageFlags(storageType) + storageFlags, err := app.AddStorageFlags(storageType) if err != nil { handleErr(err) } @@ -92,8 +91,7 @@ func main() { cmd := svc.Command() jconfig.AddFlags(v, cmd, - jflags.AddConfigFileFlag, - ingesterApp.AddFlags, + app.AddComponentFlags, storageFlags, ) diff --git a/plugin/sampling/strategystore/static/options.go b/plugin/sampling/strategystore/static/options.go index ffc55ba870c..0ef18fbf2ea 100644 --- a/plugin/sampling/strategystore/static/options.go +++ b/plugin/sampling/strategystore/static/options.go @@ -37,8 +37,13 @@ type Options struct { // AddFlags adds flags for Options func AddFlags(flagSet *flag.FlagSet) { - flagSet.String(SamplingStrategiesFile, "", "The path for the sampling strategies file in JSON format. See sampling documentation to see format of the file") flagSet.Duration(samplingStrategiesReloadInterval, 0, "Reload interval to check and reload sampling strategies file. Zero value means no reloading") + AddOTELFlags(flagSet) +} + +// AddOTELFlags adds flags that are exposed by OTEL collector +func AddOTELFlags(flagSet *flag.FlagSet) { + flagSet.String(SamplingStrategiesFile, "", "The path for the sampling strategies file in JSON format. See sampling documentation to see format of the file") } // InitFromViper initializes Options with properties from viper