From d3c2c8d0bd0269deb999375306aba0cf920e9127 Mon Sep 17 00:00:00 2001 From: rjs211 Date: Sun, 7 Feb 2021 15:45:18 +0530 Subject: [PATCH] minor refactor Signed-off-by: rjs211 --- cmd/collector/app/collector.go | 18 +- .../jaegerreceiver/jaeger_receiver.go | 2 +- .../jaegerreceiver/jaeger_receiver_test.go | 210 +++++++++--------- 3 files changed, 117 insertions(+), 113 deletions(-) diff --git a/cmd/collector/app/collector.go b/cmd/collector/app/collector.go index eb3e174c502..d90770a7941 100644 --- a/cmd/collector/app/collector.go +++ b/cmd/collector/app/collector.go @@ -45,11 +45,11 @@ type Collector struct { spanHandlers *SpanHandlers // state, read only - hServer *http.Server - zkServer *http.Server - grpcServer *grpc.Server - TLSGRPCCloser io.Closer - TLSHTTPCloser io.Closer + hServer *http.Server + zkServer *http.Server + grpcServer *grpc.Server + tlsGRPCCertWatcherCloser io.Closer + tlsHTTPCertWatcherCloser io.Closer } // CollectorParams to construct a new Jaeger Collector. @@ -112,8 +112,8 @@ func (c *Collector) Start(builderOpts *CollectorOptions) error { } c.hServer = httpServer - c.TLSGRPCCloser = &builderOpts.TLSGRPC - c.TLSHTTPCloser = &builderOpts.TLSHTTP + c.tlsGRPCCertWatcherCloser = &builderOpts.TLSGRPC + c.tlsHTTPCertWatcherCloser = &builderOpts.TLSHTTP zkServer, err := server.StartZipkinServer(&server.ZipkinServerParams{ HostPort: builderOpts.CollectorZipkinHTTPHostPort, Handler: c.spanHandlers.ZipkinSpansHandler, @@ -168,11 +168,11 @@ func (c *Collector) Close() error { c.logger.Error("failed to close span processor.", zap.Error(err)) } - if err := c.TLSGRPCCloser.Close(); err != nil { + if err := c.tlsGRPCCertWatcherCloser.Close(); err != nil { c.logger.Error("failed to close gRPC TLS certificate watcher", zap.Error(err)) } - if err := c.TLSHTTPCloser.Close(); err != nil { + if err := c.tlsHTTPCertWatcherCloser.Close(); err != nil { c.logger.Error("failed to close HTTP TLS certificate watcher", zap.Error(err)) } diff --git a/cmd/opentelemetry/app/receiver/jaegerreceiver/jaeger_receiver.go b/cmd/opentelemetry/app/receiver/jaegerreceiver/jaeger_receiver.go index e6801f23787..acee145935b 100644 --- a/cmd/opentelemetry/app/receiver/jaegerreceiver/jaeger_receiver.go +++ b/cmd/opentelemetry/app/receiver/jaegerreceiver/jaeger_receiver.go @@ -120,7 +120,7 @@ func configureCollector(v *viper.Viper, cfg *jaegerreceiver.Config) { } } cfg.ThriftHTTP.TLSSetting = &configtls.TLSServerSetting{ - ClientCAFile: cOpts.TLSGRPC.ClientCAPath, + ClientCAFile: cOpts.TLSHTTP.ClientCAPath, TLSSetting: configtls.TLSSetting{ CertFile: cOpts.TLSHTTP.CertPath, KeyFile: cOpts.TLSHTTP.KeyPath, diff --git a/cmd/opentelemetry/app/receiver/jaegerreceiver/jaeger_receiver_test.go b/cmd/opentelemetry/app/receiver/jaegerreceiver/jaeger_receiver_test.go index 77111443ee4..d19ab0e2cc6 100644 --- a/cmd/opentelemetry/app/receiver/jaegerreceiver/jaeger_receiver_test.go +++ b/cmd/opentelemetry/app/receiver/jaegerreceiver/jaeger_receiver_test.go @@ -16,6 +16,7 @@ package jaegerreceiver import ( "context" + "fmt" "path" "testing" @@ -25,13 +26,16 @@ import ( "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config/configerror" "go.opentelemetry.io/collector/config/configgrpc" + "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/config/configmodels" "go.opentelemetry.io/collector/config/confignet" "go.opentelemetry.io/collector/config/configtest" "go.opentelemetry.io/collector/config/configtls" "go.opentelemetry.io/collector/receiver/jaegerreceiver" + 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) { @@ -53,109 +57,109 @@ func TestDefaultValueFromViper(t *testing.T) { 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: jaegerreceiver.Protocols{}, - // }, - // }, - // { - // name: "thriftCompact", - // flags: []string{fmt.Sprintf("--%s=%s", thriftCompactHostPort, "localhost:9999")}, - // expected: &jaegerreceiver.Config{ - // Protocols: jaegerreceiver.Protocols{ - // ThriftCompact: &jaegerreceiver.ProtocolUDP{ - // Endpoint: "localhost:9999", - // ServerConfigUDP: jaegerreceiver.DefaultServerConfigUDP(), - // }, - // }, - // }, - // }, - // { - // name: "thriftBinary", - // flags: []string{fmt.Sprintf("--%s=%s", thriftBinaryHostPort, "localhost:8888")}, - // expected: &jaegerreceiver.Config{ - // Protocols: jaegerreceiver.Protocols{ - // ThriftBinary: &jaegerreceiver.ProtocolUDP{ - // Endpoint: "localhost:8888", - // ServerConfigUDP: jaegerreceiver.DefaultServerConfigUDP(), - // }, - // }, - // }, - // }, - // { - // name: "grpc", - // flags: []string{fmt.Sprintf("--%s=%s", collectorApp.CollectorGRPCHostPort, "localhost:7894")}, - // expected: &jaegerreceiver.Config{ - // Protocols: jaegerreceiver.Protocols{ - // GRPC: &configgrpc.GRPCServerSettings{ - // NetAddr: confignet.NetAddr{ - // Endpoint: "localhost:7894", - // }, - // }, - // }, - // }, - // }, - // { - // name: "thriftHttp", - // flags: []string{fmt.Sprintf("--%s=%s", collectorApp.CollectorHTTPHostPort, "localhost:8080")}, - // expected: &jaegerreceiver.Config{ - // Protocols: jaegerreceiver.Protocols{ - // ThriftHTTP: &confighttp.HTTPServerSettings{ - // 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: jaegerreceiver.Protocols{ - // ThriftHTTP: &confighttp.HTTPServerSettings{ - // Endpoint: "localhost:8089", - // }, - // ThriftBinary: &jaegerreceiver.ProtocolUDP{ - // Endpoint: "localhost:2222", - // ServerConfigUDP: jaegerreceiver.DefaultServerConfigUDP(), - // }, - // }, - // }, - // }, - // { - // name: "remoteSampling", - // flags: []string{ - // "--http-server.host-port=machine:1", - // "--sampling.strategies-file=foo", - // "--reporter.grpc.host-port=coll:33", - // "--reporter.grpc.tls.enabled=true", - // "--reporter.grpc.tls.ca=cacert.pem", - // "--reporter.grpc.tls.cert=cert.pem", - // "--reporter.grpc.tls.key=key.key", - // }, - // expected: &jaegerreceiver.Config{ - // RemoteSampling: &jaegerreceiver.RemoteSamplingConfig{ - // StrategyFile: "foo", - // HostEndpoint: "machine:1", - // GRPCClientSettings: configgrpc.GRPCClientSettings{ - // Endpoint: "coll:33", - // TLSSetting: configtls.TLSClientSetting{ - // Insecure: false, - // TLSSetting: configtls.TLSSetting{ - // CAFile: "cacert.pem", - // CertFile: "cert.pem", - // KeyFile: "key.key", - // }, - // }, - // }, - // }, - // Protocols: jaegerreceiver.Protocols{}, - // }, - // }, + { + name: "samplingStrategyFile", + flags: []string{fmt.Sprintf("--%s=%s", static.SamplingStrategiesFile, "conf.json")}, + expected: &jaegerreceiver.Config{ + RemoteSampling: &jaegerreceiver.RemoteSamplingConfig{ + StrategyFile: "conf.json", + }, + Protocols: jaegerreceiver.Protocols{}, + }, + }, + { + name: "thriftCompact", + flags: []string{fmt.Sprintf("--%s=%s", thriftCompactHostPort, "localhost:9999")}, + expected: &jaegerreceiver.Config{ + Protocols: jaegerreceiver.Protocols{ + ThriftCompact: &jaegerreceiver.ProtocolUDP{ + Endpoint: "localhost:9999", + ServerConfigUDP: jaegerreceiver.DefaultServerConfigUDP(), + }, + }, + }, + }, + { + name: "thriftBinary", + flags: []string{fmt.Sprintf("--%s=%s", thriftBinaryHostPort, "localhost:8888")}, + expected: &jaegerreceiver.Config{ + Protocols: jaegerreceiver.Protocols{ + ThriftBinary: &jaegerreceiver.ProtocolUDP{ + Endpoint: "localhost:8888", + ServerConfigUDP: jaegerreceiver.DefaultServerConfigUDP(), + }, + }, + }, + }, + { + name: "grpc", + flags: []string{fmt.Sprintf("--%s=%s", collectorApp.CollectorGRPCHostPort, "localhost:7894")}, + expected: &jaegerreceiver.Config{ + Protocols: jaegerreceiver.Protocols{ + GRPC: &configgrpc.GRPCServerSettings{ + NetAddr: confignet.NetAddr{ + Endpoint: "localhost:7894", + }, + }, + }, + }, + }, + { + name: "thriftHttp", + flags: []string{fmt.Sprintf("--%s=%s", collectorApp.CollectorHTTPHostPort, "localhost:8080")}, + expected: &jaegerreceiver.Config{ + Protocols: jaegerreceiver.Protocols{ + ThriftHTTP: &confighttp.HTTPServerSettings{ + 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: jaegerreceiver.Protocols{ + ThriftHTTP: &confighttp.HTTPServerSettings{ + Endpoint: "localhost:8089", + }, + ThriftBinary: &jaegerreceiver.ProtocolUDP{ + Endpoint: "localhost:2222", + ServerConfigUDP: jaegerreceiver.DefaultServerConfigUDP(), + }, + }, + }, + }, + { + name: "remoteSampling", + flags: []string{ + "--http-server.host-port=machine:1", + "--sampling.strategies-file=foo", + "--reporter.grpc.host-port=coll:33", + "--reporter.grpc.tls.enabled=true", + "--reporter.grpc.tls.ca=cacert.pem", + "--reporter.grpc.tls.cert=cert.pem", + "--reporter.grpc.tls.key=key.key", + }, + expected: &jaegerreceiver.Config{ + RemoteSampling: &jaegerreceiver.RemoteSamplingConfig{ + StrategyFile: "foo", + HostEndpoint: "machine:1", + GRPCClientSettings: configgrpc.GRPCClientSettings{ + Endpoint: "coll:33", + TLSSetting: configtls.TLSClientSetting{ + Insecure: false, + TLSSetting: configtls.TLSSetting{ + CAFile: "cacert.pem", + CertFile: "cert.pem", + KeyFile: "key.key", + }, + }, + }, + }, + Protocols: jaegerreceiver.Protocols{}, + }, + }, { name: "collectorTLS", flags: []string{