Skip to content

Commit

Permalink
add server config instead of options
Browse files Browse the repository at this point in the history
Signed-off-by: chahatsagarmain <[email protected]>
  • Loading branch information
chahatsagarmain committed Nov 29, 2024
1 parent 641ddf2 commit 9bb39e2
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 70 deletions.
27 changes: 4 additions & 23 deletions cmd/collector/app/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package app
import (
"context"
"fmt"
"io"
"net/http"
"time"

Expand Down Expand Up @@ -47,13 +46,10 @@ type Collector struct {
tenancyMgr *tenancy.Manager

// state, read only
hServer *http.Server
grpcServer *grpc.Server
otlpReceiver receiver.Traces
zipkinReceiver receiver.Traces
tlsGRPCCertWatcherCloser io.Closer
tlsHTTPCertWatcherCloser io.Closer
tlsZipkinCertWatcherCloser io.Closer
hServer *http.Server
grpcServer *grpc.Server
otlpReceiver receiver.Traces
zipkinReceiver receiver.Traces
}

// CollectorParams to construct a new Jaeger Collector.
Expand Down Expand Up @@ -131,10 +127,6 @@ func (c *Collector) Start(options *flags.CollectorOptions) error {
}
c.hServer = httpServer

c.tlsGRPCCertWatcherCloser = &options.GRPC.TLS
c.tlsHTTPCertWatcherCloser = &options.HTTP.TLS
c.tlsZipkinCertWatcherCloser = &options.Zipkin.TLS

if options.Zipkin.HTTPHostPort == "" {
c.logger.Info("Not listening for Zipkin HTTP traffic, port not configured")
} else {
Expand Down Expand Up @@ -209,17 +201,6 @@ func (c *Collector) Close() error {
}
}

// watchers actually never return errors from Close
if c.tlsGRPCCertWatcherCloser != nil {
_ = c.tlsGRPCCertWatcherCloser.Close()
}
if c.tlsHTTPCertWatcherCloser != nil {
_ = c.tlsHTTPCertWatcherCloser.Close()
}
if c.tlsZipkinCertWatcherCloser != nil {
_ = c.tlsZipkinCertWatcherCloser.Close()
}

return nil
}

Expand Down
13 changes: 7 additions & 6 deletions cmd/collector/app/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/spf13/viper"
"go.opentelemetry.io/collector/config/configtls"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/internal/flags"
Expand Down Expand Up @@ -120,7 +121,7 @@ type CollectorOptions struct {
// HTTPHostPort is the host:port address that the Zipkin collector service listens in on for http requests
HTTPHostPort string
// TLS configures secure transport for Zipkin endpoint to collect spans
TLS tlscfg.Options
TLS *configtls.ServerConfig
// CORS allows CORS requests , sets the values for Allowed Headers and Allowed Origins.
CORS corscfg.Options
// KeepAlive configures allow Keep-Alive for Zipkin HTTP server
Expand All @@ -142,7 +143,7 @@ type HTTPOptions struct {
// HostPort is the host:port address that the server listens on
HostPort string
// TLS configures secure transport for HTTP endpoint
TLS tlscfg.Options
TLS *configtls.ServerConfig
// ReadTimeout sets the respective parameter of http.Server
ReadTimeout time.Duration
// ReadHeaderTimeout sets the respective parameter of http.Server
Expand All @@ -158,7 +159,7 @@ type GRPCOptions struct {
// HostPort is the host:port address that the collector service listens in on for gRPC requests
HostPort string
// TLS configures secure transport for gRPC endpoint to collect spans
TLS tlscfg.Options
TLS *configtls.ServerConfig
// MaxReceiveMessageLength is the maximum message size receivable by the gRPC Collector.
MaxReceiveMessageLength int
// MaxConnectionAge is a duration for the maximum amount of time a connection may exist.
Expand Down Expand Up @@ -232,7 +233,7 @@ func (opts *HTTPOptions) initFromViper(v *viper.Viper, _ *zap.Logger, cfg server
if err != nil {
return fmt.Errorf("failed to parse HTTP TLS options: %w", err)
}
opts.TLS = tlsOpts
opts.TLS = tlsOpts.ToOtelServerConfig()
return nil
}

Expand All @@ -245,7 +246,7 @@ func (opts *GRPCOptions) initFromViper(v *viper.Viper, _ *zap.Logger, cfg server
if err != nil {
return fmt.Errorf("failed to parse gRPC TLS options: %w", err)
}
opts.TLS = tlsOpts
opts.TLS = tlsOpts.ToOtelServerConfig()
opts.Tenancy = tenancy.InitFromViper(v)

return nil
Expand Down Expand Up @@ -282,7 +283,7 @@ func (cOpts *CollectorOptions) InitFromViper(v *viper.Viper, logger *zap.Logger)
if err != nil {
return cOpts, fmt.Errorf("failed to parse Zipkin TLS options: %w", err)
}
cOpts.Zipkin.TLS = tlsZipkin
cOpts.Zipkin.TLS = tlsZipkin.ToOtelServerConfig()
cOpts.Zipkin.CORS = corsZipkinFlags.InitFromViper(v)

return cOpts, nil
Expand Down
8 changes: 4 additions & 4 deletions cmd/collector/app/handler/otlp_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ func applyGRPCSettings(cfg *configgrpc.ServerConfig, opts *flags.GRPCOptions) {
if opts.HostPort != "" {
cfg.NetAddr.Endpoint = opts.HostPort
}
if opts.TLS.Enabled {
cfg.TLSSetting = opts.TLS.ToOtelServerConfig()
if opts.TLS != nil {
cfg.TLSSetting = opts.TLS
}
if opts.MaxReceiveMessageLength > 0 {
cfg.MaxRecvMsgSizeMiB = int(opts.MaxReceiveMessageLength / (1024 * 1024))
Expand All @@ -123,8 +123,8 @@ func applyHTTPSettings(cfg *confighttp.ServerConfig, opts *flags.HTTPOptions) {
if opts.HostPort != "" {
cfg.Endpoint = opts.HostPort
}
if opts.TLS.Enabled {
cfg.TLSSetting = opts.TLS.ToOtelServerConfig()
if opts.TLS != nil {
cfg.TLSSetting = opts.TLS
}

cfg.CORS = &confighttp.CORSConfig{
Expand Down
40 changes: 21 additions & 19 deletions cmd/collector/app/handler/otlp_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.opentelemetry.io/collector/pipeline"
Expand All @@ -20,7 +21,6 @@ import (

"github.com/jaegertracing/jaeger/cmd/collector/app/flags"
"github.com/jaegertracing/jaeger/pkg/config/corscfg"
"github.com/jaegertracing/jaeger/pkg/config/tlscfg"
"github.com/jaegertracing/jaeger/pkg/tenancy"
"github.com/jaegertracing/jaeger/pkg/testutils"
)
Expand Down Expand Up @@ -138,15 +138,16 @@ func TestApplyOTLPGRPCServerSettings(t *testing.T) {
MaxReceiveMessageLength: 42 * 1024 * 1024,
MaxConnectionAge: 33 * time.Second,
MaxConnectionAgeGrace: 37 * time.Second,
TLS: tlscfg.Options{
Enabled: true,
CAPath: "ca",
CertPath: "cert",
KeyPath: "key",
ClientCAPath: "clientca",
MinVersion: "1.1",
MaxVersion: "1.3",
ReloadInterval: 24 * time.Hour,
TLS: &configtls.ServerConfig{
ClientCAFile: "clientca",
Config: configtls.Config{
CAFile: "ca",
CertFile: "cert",
KeyFile: "key",
MinVersion: "1.1",
MaxVersion: "1.3",
ReloadInterval: 24 * time.Hour,
},
},
}
applyGRPCSettings(otlpReceiverConfig.GRPC, grpcOpts)
Expand All @@ -173,15 +174,16 @@ func TestApplyOTLPHTTPServerSettings(t *testing.T) {

httpOpts := &flags.HTTPOptions{
HostPort: ":12345",
TLS: tlscfg.Options{
Enabled: true,
CAPath: "ca",
CertPath: "cert",
KeyPath: "key",
ClientCAPath: "clientca",
MinVersion: "1.1",
MaxVersion: "1.3",
ReloadInterval: 24 * time.Hour,
TLS: &configtls.ServerConfig{
ClientCAFile: "clientca",
Config: configtls.Config{
CAFile: "ca",
CertFile: "cert",
KeyFile: "key",
MinVersion: "1.1",
MaxVersion: "1.3",
ReloadInterval: 24 * time.Hour,
},
},
CORS: corscfg.Options{
AllowedOrigins: []string{"http://example.domain.com", "http://*.domain.com"},
Expand Down
2 changes: 1 addition & 1 deletion cmd/collector/app/handler/zipkin_receiver_tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func TestSpanCollectorZipkinTLS(t *testing.T) {

opts := &flags.CollectorOptions{}
opts.Zipkin.HTTPHostPort = ports.PortToHostPort(ports.CollectorZipkin)
opts.Zipkin.TLS = test.serverTLS
opts.Zipkin.TLS = test.serverTLS.ToOtelServerConfig()

server, err := StartZipkinReceiver(opts, logger, spanProcessor, tm)
if test.expectServerFail {
Expand Down
8 changes: 4 additions & 4 deletions cmd/collector/app/server/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net"
"time"

"go.opentelemetry.io/collector/config/configtls"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
Expand All @@ -20,13 +21,12 @@ import (
"github.com/jaegertracing/jaeger/cmd/collector/app/handler"
"github.com/jaegertracing/jaeger/cmd/collector/app/sampling"
"github.com/jaegertracing/jaeger/cmd/collector/app/sampling/samplingstrategy"
"github.com/jaegertracing/jaeger/pkg/config/tlscfg"
"github.com/jaegertracing/jaeger/proto-gen/api_v2"
)

// GRPCServerParams to construct a new Jaeger Collector gRPC Server
type GRPCServerParams struct {
TLSConfig tlscfg.Options
TLSConfig *configtls.ServerConfig
HostPort string
Handler *handler.GRPCHandler
SamplingProvider samplingstrategy.Provider
Expand All @@ -53,9 +53,9 @@ func StartGRPCServer(params *GRPCServerParams) (*grpc.Server, error) {
MaxConnectionAgeGrace: params.MaxConnectionAgeGrace,
}))

if params.TLSConfig.Enabled {
if params.TLSConfig != nil {
// user requested a server with TLS, setup creds
tlsCfg, err := params.TLSConfig.ToOtelServerConfig().LoadTLSConfig(context.Background())
tlsCfg, err := params.TLSConfig.LoadTLSConfig(context.Background())
if err != nil {
return nil, err
}
Expand Down
13 changes: 7 additions & 6 deletions cmd/collector/app/server/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,17 @@ func TestSpanCollector(t *testing.T) {

func TestCollectorStartWithTLS(t *testing.T) {
logger, _ := zap.NewDevelopment()
opts := tlscfg.Options{
Enabled: true,
CertPath: testCertKeyLocation + "/example-server-cert.pem",
KeyPath: testCertKeyLocation + "/example-server-key.pem",
ClientCAPath: testCertKeyLocation + "/example-CA-cert.pem",
}
params := &GRPCServerParams{
Handler: handler.NewGRPCHandler(logger, &mockSpanProcessor{}, &tenancy.Manager{}),
SamplingProvider: &mockSamplingProvider{},
Logger: logger,
TLSConfig: tlscfg.Options{
Enabled: true,
CertPath: testCertKeyLocation + "/example-server-cert.pem",
KeyPath: testCertKeyLocation + "/example-server-key.pem",
ClientCAPath: testCertKeyLocation + "/example-CA-cert.pem",
},
TLSConfig: opts.ToOtelServerConfig(),
}
server, err := StartGRPCServer(params)
require.NoError(t, err)
Expand Down
10 changes: 5 additions & 5 deletions cmd/collector/app/server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
"time"

"github.com/gorilla/mux"
"go.opentelemetry.io/collector/config/configtls"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

"github.com/jaegertracing/jaeger/cmd/collector/app/handler"
"github.com/jaegertracing/jaeger/cmd/collector/app/sampling/samplingstrategy"
clientcfgHandler "github.com/jaegertracing/jaeger/pkg/clientcfg/clientcfghttp"
"github.com/jaegertracing/jaeger/pkg/config/tlscfg"
"github.com/jaegertracing/jaeger/pkg/healthcheck"
"github.com/jaegertracing/jaeger/pkg/httpmetrics"
"github.com/jaegertracing/jaeger/pkg/metrics"
Expand All @@ -25,7 +25,7 @@ import (

// HTTPServerParams to construct a new Jaeger Collector HTTP Server
type HTTPServerParams struct {
TLSConfig tlscfg.Options
TLSConfig *configtls.ServerConfig
HostPort string
Handler handler.JaegerBatchesHandler
SamplingProvider samplingstrategy.Provider
Expand Down Expand Up @@ -53,8 +53,8 @@ func StartHTTPServer(params *HTTPServerParams) (*http.Server, error) {
IdleTimeout: params.IdleTimeout,
ErrorLog: errorLog,
}
if params.TLSConfig.Enabled {
tlsCfg, err := params.TLSConfig.ToOtelServerConfig().LoadTLSConfig(context.Background())
if params.TLSConfig != nil {
tlsCfg, err := params.TLSConfig.LoadTLSConfig(context.Background())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -91,7 +91,7 @@ func serveHTTP(server *http.Server, listener net.Listener, params *HTTPServerPar
server.Handler = httpmetrics.Wrap(recoveryHandler(r), params.MetricsFactory, params.Logger)
go func() {
var err error
if params.TLSConfig.Enabled {
if params.TLSConfig != nil {
err = server.ServeTLS(listener, "", "")
} else {
err = server.Serve(listener)
Expand Down
4 changes: 2 additions & 2 deletions cmd/collector/app/server/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestCreateTLSHTTPServerError(t *testing.T) {
HostPort: fmt.Sprintf(":%d", ports.CollectorHTTP),
HealthCheck: healthcheck.New(),
Logger: logger,
TLSConfig: tlsCfg,
TLSConfig: tlsCfg.ToOtelServerConfig(),
}
_, err := StartHTTPServer(params)
require.Error(t, err)
Expand Down Expand Up @@ -194,7 +194,7 @@ func TestSpanCollectorHTTPS(t *testing.T) {
MetricsFactory: mFact,
HealthCheck: healthcheck.New(),
Logger: logger,
TLSConfig: test.TLS,
TLSConfig: test.TLS.ToOtelServerConfig(),
}

server, err := StartHTTPServer(params)
Expand Down

0 comments on commit 9bb39e2

Please sign in to comment.