Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
Signed-off-by: rjs211 <[email protected]>
  • Loading branch information
rjs211 committed Feb 7, 2021
1 parent 62b6d79 commit d3c2c8d
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 113 deletions.
18 changes: 9 additions & 9 deletions cmd/collector/app/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
210 changes: 107 additions & 103 deletions cmd/opentelemetry/app/receiver/jaegerreceiver/jaeger_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package jaegerreceiver

import (
"context"
"fmt"
"path"
"testing"

Expand All @@ -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) {
Expand All @@ -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{
Expand Down

0 comments on commit d3c2c8d

Please sign in to comment.