diff --git a/cmd/all-in-one/main.go b/cmd/all-in-one/main.go index 10578721248..6524d20da25 100644 --- a/cmd/all-in-one/main.go +++ b/cmd/all-in-one/main.go @@ -142,7 +142,7 @@ by default uses only in-memory database.`, logger.Fatal("Failed to configure query service", zap.Error(err)) } - tm := tenancy.NewManager(&cOpts.GRPC.Tenancy) + tm := tenancy.NewManager(&cOpts.Tenancy) // collector c := collectorApp.New(&collectorApp.CollectorParams{ diff --git a/cmd/collector/app/collector.go b/cmd/collector/app/collector.go index 44b1ef47803..be9e08c9fd1 100644 --- a/cmd/collector/app/collector.go +++ b/cmd/collector/app/collector.go @@ -6,10 +6,11 @@ package app import ( "context" "fmt" - "io" "net/http" "time" + "go.opentelemetry.io/collector/config/configgrpc" + "go.opentelemetry.io/collector/config/confignet" "go.opentelemetry.io/collector/receiver" "go.uber.org/zap" "google.golang.org/grpc" @@ -47,13 +48,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. @@ -101,26 +99,28 @@ func (c *Collector) Start(options *flags.CollectorOptions) error { c.spanProcessor = handlerBuilder.BuildSpanProcessor(additionalProcessors...) c.spanHandlers = handlerBuilder.BuildHandlers(c.spanProcessor) - + // fmt.Printf("%v \n",options.GRPC.NetAddr.Endpoint) grpcServer, err := server.StartGRPCServer(&server.GRPCServerParams{ - HostPort: options.GRPC.HostPort, - Handler: c.spanHandlers.GRPCHandler, - TLSConfig: options.GRPC.TLS, - SamplingProvider: c.samplingProvider, - Logger: c.logger, - MaxReceiveMessageLength: options.GRPC.MaxReceiveMessageLength, - MaxConnectionAge: options.GRPC.MaxConnectionAge, - MaxConnectionAgeGrace: options.GRPC.MaxConnectionAgeGrace, + Handler: c.spanHandlers.GRPCHandler, + SamplingProvider: c.samplingProvider, + Logger: c.logger, + ServerConfig: &configgrpc.ServerConfig{ + NetAddr: confignet.AddrConfig{ + Endpoint: options.GRPC.NetAddr.Endpoint, + }, + TLSSetting: options.GRPC.TLSSetting, + MaxRecvMsgSizeMiB: options.GRPC.MaxRecvMsgSizeMiB, + Keepalive: options.GRPC.Keepalive, + }, }) if err != nil { return fmt.Errorf("could not start gRPC server: %w", err) } c.grpcServer = grpcServer - httpServer, err := server.StartHTTPServer(&server.HTTPServerParams{ - HostPort: options.HTTP.HostPort, + HostPort: options.HTTP.Endpoint, Handler: c.spanHandlers.JaegerBatchesHandler, - TLSConfig: options.HTTP.TLS, + TLSConfig: options.HTTP.TLSSetting, HealthCheck: c.hCheck, MetricsFactory: c.metricsFactory, SamplingProvider: c.samplingProvider, @@ -131,13 +131,10 @@ 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 == "" { + if options.Zipkin.Endpoint == "" { c.logger.Info("Not listening for Zipkin HTTP traffic, port not configured") } else { + fmt.Printf("%v zipkin\n", options.Zipkin.Endpoint) zipkinReceiver, err := handler.StartZipkinReceiver(options, c.logger, c.spanProcessor, c.tenancyMgr) if err != nil { return fmt.Errorf("could not start Zipkin receiver: %w", err) @@ -146,6 +143,7 @@ func (c *Collector) Start(options *flags.CollectorOptions) error { } if options.OTLP.Enabled { + fmt.Printf("otlp enabled \n") otlpReceiver, err := handler.StartOTLPReceiver(options, c.logger, c.spanProcessor, c.tenancyMgr) if err != nil { return fmt.Errorf("could not start OTLP receiver: %w", err) @@ -209,17 +207,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 } diff --git a/cmd/collector/app/collector_test.go b/cmd/collector/app/collector_test.go index 35c0576d630..96605f73135 100644 --- a/cmd/collector/app/collector_test.go +++ b/cmd/collector/app/collector_test.go @@ -6,6 +6,7 @@ package app import ( "context" "expvar" + "fmt" "io" "sync/atomic" "testing" @@ -13,6 +14,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/config/configgrpc" "go.uber.org/zap" "github.com/jaegertracing/jaeger/cmd/collector/app/flags" @@ -28,12 +30,23 @@ var _ (io.Closer) = (*Collector)(nil) func optionsForEphemeralPorts() *flags.CollectorOptions { collectorOpts := &flags.CollectorOptions{} - collectorOpts.GRPC.HostPort = ":0" - collectorOpts.HTTP.HostPort = ":0" + collectorOpts.GRPC.NetAddr.Endpoint = ":0" + collectorOpts.GRPC.Keepalive = &configgrpc.KeepaliveServerConfig{ + ServerParameters: &configgrpc.KeepaliveServerParameters{ + MaxConnectionIdle: 10, + }, + } + collectorOpts.HTTP.Endpoint = ":0" collectorOpts.OTLP.Enabled = true - collectorOpts.OTLP.GRPC.HostPort = ":0" - collectorOpts.OTLP.HTTP.HostPort = ":0" - collectorOpts.Zipkin.HTTPHostPort = ":0" + collectorOpts.OTLP.GRPC.NetAddr.Endpoint = ":0" + collectorOpts.OTLP.GRPC.Keepalive = &configgrpc.KeepaliveServerConfig{ + ServerParameters: &configgrpc.KeepaliveServerParameters{ + MaxConnectionIdle: 10, + }, + } + collectorOpts.OTLP.HTTP.Endpoint = ":0" + collectorOpts.Zipkin.Endpoint = ":0" + collectorOpts.Tenancy = tenancy.Options{} return collectorOpts } @@ -78,6 +91,8 @@ func TestNewCollector(t *testing.T) { }) collectorOpts := optionsForEphemeralPorts() + fmt.Printf("Collector Options: %+v\n", collectorOpts.OTLP.GRPC) + fmt.Print(collectorOpts.OTLP.HTTP.Endpoint) require.NoError(t, c.Start(collectorOpts)) assert.NotNil(t, c.SpanHandlers()) require.NoError(t, c.Close()) @@ -112,23 +127,23 @@ func TestCollector_StartErrors(t *testing.T) { var options *flags.CollectorOptions options = optionsForEphemeralPorts() - options.GRPC.HostPort = ":-1" + options.GRPC.NetAddr.Endpoint = ":-1" run("gRPC", options, "could not start gRPC server") options = optionsForEphemeralPorts() - options.HTTP.HostPort = ":-1" + options.HTTP.Endpoint = ":-1" run("HTTP", options, "could not start HTTP server") options = optionsForEphemeralPorts() - options.Zipkin.HTTPHostPort = ":-1" + options.Zipkin.Endpoint = ":-1" run("Zipkin", options, "could not start Zipkin receiver") options = optionsForEphemeralPorts() - options.OTLP.GRPC.HostPort = ":-1" + options.OTLP.GRPC.NetAddr.Endpoint = ":-1" run("OTLP/GRPC", options, "could not start OTLP receiver") options = optionsForEphemeralPorts() - options.OTLP.HTTP.HostPort = ":-1" + options.OTLP.HTTP.Endpoint = ":-1" run("OTLP/HTTP", options, "could not start OTLP receiver") } diff --git a/cmd/collector/app/flags/flags.go b/cmd/collector/app/flags/flags.go index 5c68169c881..54c1141d975 100644 --- a/cmd/collector/app/flags/flags.go +++ b/cmd/collector/app/flags/flags.go @@ -10,6 +10,8 @@ import ( "time" "github.com/spf13/viper" + "go.opentelemetry.io/collector/config/configgrpc" + "go.opentelemetry.io/collector/config/confighttp" "go.uber.org/zap" "github.com/jaegertracing/jaeger/cmd/internal/flags" @@ -106,30 +108,23 @@ type CollectorOptions struct { // NumWorkers is the number of internal workers in a collector NumWorkers int // HTTP section defines options for HTTP server - HTTP HTTPOptions + HTTP confighttp.ServerConfig // GRPC section defines options for gRPC server - GRPC GRPCOptions + GRPC configgrpc.ServerConfig // OTLP section defines options for servers accepting OpenTelemetry OTLP format OTLP struct { Enabled bool - GRPC GRPCOptions - HTTP HTTPOptions + GRPC configgrpc.ServerConfig + HTTP confighttp.ServerConfig } // Zipkin section defines options for Zipkin HTTP server - Zipkin 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 - // 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 - KeepAlive bool - } + Zipkin confighttp.ServerConfig // CollectorTags is the string representing collector tags to append to each and every span CollectorTags map[string]string // SpanSizeMetricsEnabled determines whether to enable metrics based on processed span size SpanSizeMetricsEnabled bool + + Tenancy tenancy.Options } type serverFlagsConfig struct { @@ -137,40 +132,6 @@ type serverFlagsConfig struct { tls tlscfg.ServerFlagsConfig } -// HTTPOptions defines options for an HTTP server -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 - // ReadTimeout sets the respective parameter of http.Server - ReadTimeout time.Duration - // ReadHeaderTimeout sets the respective parameter of http.Server - ReadHeaderTimeout time.Duration - // IdleTimeout sets the respective parameter of http.Server - IdleTimeout time.Duration - // CORS allows CORS requests , sets the values for Allowed Headers and Allowed Origins. - CORS corscfg.Options -} - -// GRPCOptions defines options for a gRPC server -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 - // 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. - // See gRPC's keepalive.ServerParameters#MaxConnectionAge. - MaxConnectionAge time.Duration - // MaxConnectionAgeGrace is an additive period after MaxConnectionAge after which the connection will be forcibly closed. - // See gRPC's keepalive.ServerParameters#MaxConnectionAgeGrace. - MaxConnectionAgeGrace time.Duration - // Tenancy configures tenancy for endpoints that collect spans - Tenancy tenancy.Options -} - // AddFlags adds flags for CollectorOptions func AddFlags(flagSet *flag.FlagSet) { flagSet.Int(flagNumWorkers, DefaultNumWorkers, "The number of workers pulling items from the queue") @@ -223,30 +184,34 @@ func addGRPCFlags(flagSet *flag.FlagSet, cfg serverFlagsConfig, defaultHostPort cfg.tls.AddFlags(flagSet) } -func (opts *HTTPOptions) initFromViper(v *viper.Viper, _ *zap.Logger, cfg serverFlagsConfig) error { - opts.HostPort = ports.FormatHostPort(v.GetString(cfg.prefix + "." + flagSuffixHostPort)) - opts.IdleTimeout = v.GetDuration(cfg.prefix + "." + flagSuffixHTTPIdleTimeout) - opts.ReadTimeout = v.GetDuration(cfg.prefix + "." + flagSuffixHTTPReadTimeout) - opts.ReadHeaderTimeout = v.GetDuration(cfg.prefix + "." + flagSuffixHTTPReadHeaderTimeout) +func initHTTPFromViper(v *viper.Viper, _ *zap.Logger, opts *confighttp.ServerConfig, cfg serverFlagsConfig) error { tlsOpts, err := cfg.tls.InitFromViper(v) if err != nil { return fmt.Errorf("failed to parse HTTP TLS options: %w", err) } - opts.TLS = tlsOpts + opts.TLSSetting = tlsOpts.ToOtelServerConfig() + opts.Endpoint = ports.FormatHostPort(v.GetString(cfg.prefix + "." + flagSuffixHostPort)) + opts.IdleTimeout = v.GetDuration(cfg.prefix + "." + flagSuffixHTTPIdleTimeout) + opts.ReadTimeout = v.GetDuration(cfg.prefix + "." + flagSuffixHTTPReadTimeout) + opts.ReadHeaderTimeout = v.GetDuration(cfg.prefix + "." + flagSuffixHTTPReadHeaderTimeout) + return nil } -func (opts *GRPCOptions) initFromViper(v *viper.Viper, _ *zap.Logger, cfg serverFlagsConfig) error { - opts.HostPort = ports.FormatHostPort(v.GetString(cfg.prefix + "." + flagSuffixHostPort)) - opts.MaxReceiveMessageLength = v.GetInt(cfg.prefix + "." + flagSuffixGRPCMaxReceiveMessageLength) - opts.MaxConnectionAge = v.GetDuration(cfg.prefix + "." + flagSuffixGRPCMaxConnectionAge) - opts.MaxConnectionAgeGrace = v.GetDuration(cfg.prefix + "." + flagSuffixGRPCMaxConnectionAgeGrace) +func initGRPCFromViper(v *viper.Viper, _ *zap.Logger, opts *configgrpc.ServerConfig, cfg serverFlagsConfig) error { tlsOpts, err := cfg.tls.InitFromViper(v) if err != nil { - return fmt.Errorf("failed to parse gRPC TLS options: %w", err) + return fmt.Errorf("failed to parse GRPC TLS options: %w", err) + } + opts.TLSSetting = tlsOpts.ToOtelServerConfig() + opts.NetAddr.Endpoint = ports.FormatHostPort(v.GetString(cfg.prefix + "." + flagSuffixHostPort)) + opts.MaxRecvMsgSizeMiB = v.GetInt(cfg.prefix+"."+flagSuffixGRPCMaxReceiveMessageLength) * 1024 * 1024 + opts.Keepalive = &configgrpc.KeepaliveServerConfig{ + ServerParameters: &configgrpc.KeepaliveServerParameters{ + MaxConnectionAge: v.GetDuration(cfg.prefix + "." + flagSuffixGRPCMaxConnectionAge), + MaxConnectionAgeGrace: v.GetDuration(cfg.prefix + "." + flagSuffixGRPCMaxConnectionAgeGrace), + }, } - opts.TLS = tlsOpts - opts.Tenancy = tenancy.InitFromViper(v) return nil } @@ -258,32 +223,35 @@ func (cOpts *CollectorOptions) InitFromViper(v *viper.Viper, logger *zap.Logger) cOpts.QueueSize = v.GetUint(flagQueueSize) cOpts.DynQueueSizeMemory = v.GetUint(flagDynQueueSizeMemory) * 1024 * 1024 // we receive in MiB and store in bytes cOpts.SpanSizeMetricsEnabled = v.GetBool(flagSpanSizeMetricsEnabled) + cOpts.Tenancy = tenancy.InitFromViper(v) - if err := cOpts.HTTP.initFromViper(v, logger, httpServerFlagsCfg); err != nil { + if err := initHTTPFromViper(v, logger, &cOpts.HTTP, httpServerFlagsCfg); err != nil { return cOpts, fmt.Errorf("failed to parse HTTP server options: %w", err) } - if err := cOpts.GRPC.initFromViper(v, logger, grpcServerFlagsCfg); err != nil { + if err := initGRPCFromViper(v, logger, &cOpts.GRPC, grpcServerFlagsCfg); err != nil { return cOpts, fmt.Errorf("failed to parse gRPC server options: %w", err) } cOpts.OTLP.Enabled = v.GetBool(flagCollectorOTLPEnabled) - if err := cOpts.OTLP.HTTP.initFromViper(v, logger, otlpServerFlagsCfg.HTTP); err != nil { + if err := initHTTPFromViper(v, logger, &cOpts.OTLP.HTTP, otlpServerFlagsCfg.HTTP); err != nil { return cOpts, fmt.Errorf("failed to parse OTLP/HTTP server options: %w", err) } - cOpts.OTLP.HTTP.CORS = corsOTLPFlags.InitFromViper(v) - if err := cOpts.OTLP.GRPC.initFromViper(v, logger, otlpServerFlagsCfg.GRPC); err != nil { + corsOpts := corsOTLPFlags.InitFromViper(v) + cOpts.OTLP.HTTP.CORS = corsOpts.ToOTELCorsConfig() + if err := initGRPCFromViper(v, logger, &cOpts.GRPC, otlpServerFlagsCfg.GRPC); err != nil { return cOpts, fmt.Errorf("failed to parse OTLP/gRPC server options: %w", err) } - cOpts.Zipkin.KeepAlive = v.GetBool(flagZipkinKeepAliveEnabled) - cOpts.Zipkin.HTTPHostPort = ports.FormatHostPort(v.GetString(flagZipkinHTTPHostPort)) + // cOpts.Zipkin. = v.GetBool(flagZipkinKeepAliveEnabled) + cOpts.Zipkin.Endpoint = ports.FormatHostPort(v.GetString(flagZipkinHTTPHostPort)) tlsZipkin, err := tlsZipkinFlagsConfig.InitFromViper(v) if err != nil { return cOpts, fmt.Errorf("failed to parse Zipkin TLS options: %w", err) } - cOpts.Zipkin.TLS = tlsZipkin - cOpts.Zipkin.CORS = corsZipkinFlags.InitFromViper(v) + cOpts.Zipkin.TLSSetting = tlsZipkin.ToOtelServerConfig() + corsOpts = corsZipkinFlags.InitFromViper(v) + cOpts.Zipkin.CORS = corsOpts.ToOTELCorsConfig() return cOpts, nil } diff --git a/cmd/collector/app/flags/flags_test.go b/cmd/collector/app/flags/flags_test.go index 9d261465c09..bc8b3b81367 100644 --- a/cmd/collector/app/flags/flags_test.go +++ b/cmd/collector/app/flags/flags_test.go @@ -26,9 +26,9 @@ func TestCollectorOptionsWithFlags_CheckHostPort(t *testing.T) { _, err := c.InitFromViper(v, zap.NewNop()) require.NoError(t, err) - assert.Equal(t, ":5678", c.HTTP.HostPort) - assert.Equal(t, ":1234", c.GRPC.HostPort) - assert.Equal(t, ":3456", c.Zipkin.HTTPHostPort) + assert.Equal(t, ":5678", c.HTTP.Endpoint) + assert.Equal(t, ":1234", c.GRPC.NetAddr.Endpoint) + assert.Equal(t, ":3456", c.Zipkin.Endpoint) } func TestCollectorOptionsWithFlags_CheckFullHostPort(t *testing.T) { @@ -42,9 +42,9 @@ func TestCollectorOptionsWithFlags_CheckFullHostPort(t *testing.T) { _, err := c.InitFromViper(v, zap.NewNop()) require.NoError(t, err) - assert.Equal(t, ":5678", c.HTTP.HostPort) - assert.Equal(t, "127.0.0.1:1234", c.GRPC.HostPort) - assert.Equal(t, "0.0.0.0:3456", c.Zipkin.HTTPHostPort) + assert.Equal(t, ":5678", c.HTTP.Endpoint) + assert.Equal(t, "127.0.0.1:1234", c.GRPC.NetAddr.Endpoint) + assert.Equal(t, "0.0.0.0:3456", c.Zipkin.Endpoint) } func TestCollectorOptionsWithFailedTLSFlags(t *testing.T) { @@ -107,7 +107,7 @@ func TestCollectorOptionsWithFlags_CheckMaxReceiveMessageLength(t *testing.T) { _, err := c.InitFromViper(v, zap.NewNop()) require.NoError(t, err) - assert.Equal(t, 8388608, c.GRPC.MaxReceiveMessageLength) + assert.Equal(t, 8388608, c.GRPC.MaxRecvMsgSizeMiB) } func TestCollectorOptionsWithFlags_CheckMaxConnectionAge(t *testing.T) { @@ -123,8 +123,8 @@ func TestCollectorOptionsWithFlags_CheckMaxConnectionAge(t *testing.T) { _, err := c.InitFromViper(v, zap.NewNop()) require.NoError(t, err) - assert.Equal(t, 5*time.Minute, c.GRPC.MaxConnectionAge) - assert.Equal(t, time.Minute, c.GRPC.MaxConnectionAgeGrace) + assert.Equal(t, 5*time.Minute, c.GRPC.Keepalive.ServerParameters.MaxConnectionAge) + assert.Equal(t, time.Minute, c.GRPC.Keepalive.ServerParameters.MaxConnectionAgeGrace) assert.Equal(t, 5*time.Minute, c.HTTP.IdleTimeout) assert.Equal(t, 6*time.Minute, c.HTTP.ReadTimeout) assert.Equal(t, 5*time.Second, c.HTTP.ReadHeaderTimeout) @@ -136,7 +136,7 @@ func TestCollectorOptionsWithFlags_CheckNoTenancy(t *testing.T) { command.ParseFlags([]string{}) c.InitFromViper(v, zap.NewNop()) - assert.False(t, c.GRPC.Tenancy.Enabled) + assert.False(t, c.Tenancy.Enabled) } func TestCollectorOptionsWithFlags_CheckSimpleTenancy(t *testing.T) { @@ -147,8 +147,8 @@ func TestCollectorOptionsWithFlags_CheckSimpleTenancy(t *testing.T) { }) c.InitFromViper(v, zap.NewNop()) - assert.True(t, c.GRPC.Tenancy.Enabled) - assert.Equal(t, "x-tenant", c.GRPC.Tenancy.Header) + assert.True(t, c.Tenancy.Enabled) + assert.Equal(t, "x-tenant", c.Tenancy.Header) } func TestCollectorOptionsWithFlags_CheckFullTenancy(t *testing.T) { @@ -161,21 +161,21 @@ func TestCollectorOptionsWithFlags_CheckFullTenancy(t *testing.T) { }) c.InitFromViper(v, zap.NewNop()) - assert.True(t, c.GRPC.Tenancy.Enabled) - assert.Equal(t, "custom-tenant-header", c.GRPC.Tenancy.Header) - assert.Equal(t, []string{"acme", "hardware-store"}, c.GRPC.Tenancy.Tenants) + assert.True(t, c.Tenancy.Enabled) + assert.Equal(t, "custom-tenant-header", c.Tenancy.Header) + assert.Equal(t, []string{"acme", "hardware-store"}, c.Tenancy.Tenants) } -func TestCollectorOptionsWithFlags_CheckZipkinKeepAlive(t *testing.T) { - c := &CollectorOptions{} - v, command := config.Viperize(AddFlags) - command.ParseFlags([]string{ - "--collector.zipkin.keep-alive=false", - }) - c.InitFromViper(v, zap.NewNop()) +// func TestCollectorOptionsWithFlags_CheckZipkinKeepAlive(t *testing.T) { +// c := &CollectorOptions{} +// v, command := config.Viperize(AddFlags) +// command.ParseFlags([]string{ +// "--collector.zipkin.keep-alive=false", +// }) +// c.InitFromViper(v, zap.NewNop()) - assert.False(t, c.Zipkin.KeepAlive) -} +// assert.False(t, c.Zipkin.KeepAlive) +// } func TestMain(m *testing.M) { testutils.VerifyGoLeaks(m) diff --git a/cmd/collector/app/handler/otlp_receiver.go b/cmd/collector/app/handler/otlp_receiver.go index fb54d931bf8..afa7ff8b96d 100644 --- a/cmd/collector/app/handler/otlp_receiver.go +++ b/cmd/collector/app/handler/otlp_receiver.go @@ -10,10 +10,7 @@ import ( otlp2jaeger "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componentstatus" - "go.opentelemetry.io/collector/config/configgrpc" - "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/config/configtelemetry" - "go.opentelemetry.io/collector/config/configtls" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/extension" "go.opentelemetry.io/collector/pdata/ptrace" @@ -27,7 +24,6 @@ import ( "github.com/jaegertracing/jaeger/cmd/collector/app/flags" "github.com/jaegertracing/jaeger/cmd/collector/app/processor" - "github.com/jaegertracing/jaeger/pkg/config/tlscfg" "github.com/jaegertracing/jaeger/pkg/tenancy" ) @@ -62,8 +58,10 @@ func startOTLPReceiver( cfg component.Config, nextConsumer consumer.Traces) (receiver.Traces, error), ) (receiver.Traces, error) { otlpReceiverConfig := otlpFactory.CreateDefaultConfig().(*otlpreceiver.Config) - applyGRPCSettings(otlpReceiverConfig.GRPC, &options.OTLP.GRPC) - applyHTTPSettings(otlpReceiverConfig.HTTP.ServerConfig, &options.OTLP.HTTP) + otlpReceiverConfig.GRPC = &options.OTLP.GRPC + otlpReceiverConfig.HTTP.ServerConfig = &options.OTLP.HTTP + fmt.Printf("OTLP HTTP Endpoint: %s\n", otlpReceiverConfig.HTTP.ServerConfig.Endpoint) + fmt.Printf("OTLP GRPC Endpoint: %s\n", otlpReceiverConfig.GRPC.NetAddr.Endpoint) statusReporter := func(ev *componentstatus.Event) { // TODO this could be wired into changing healthcheck.HealthCheck logger.Info("OTLP receiver status change", zap.Stringer("status", ev.Status())) @@ -101,54 +99,6 @@ func startOTLPReceiver( return otlpReceiver, nil } -func applyGRPCSettings(cfg *configgrpc.ServerConfig, opts *flags.GRPCOptions) { - if opts.HostPort != "" { - cfg.NetAddr.Endpoint = opts.HostPort - } - if opts.TLS.Enabled { - cfg.TLSSetting = applyTLSSettings(&opts.TLS) - } - if opts.MaxReceiveMessageLength > 0 { - cfg.MaxRecvMsgSizeMiB = int(opts.MaxReceiveMessageLength / (1024 * 1024)) - } - if opts.MaxConnectionAge != 0 || opts.MaxConnectionAgeGrace != 0 { - cfg.Keepalive = &configgrpc.KeepaliveServerConfig{ - ServerParameters: &configgrpc.KeepaliveServerParameters{ - MaxConnectionAge: opts.MaxConnectionAge, - MaxConnectionAgeGrace: opts.MaxConnectionAgeGrace, - }, - } - } -} - -func applyHTTPSettings(cfg *confighttp.ServerConfig, opts *flags.HTTPOptions) { - if opts.HostPort != "" { - cfg.Endpoint = opts.HostPort - } - if opts.TLS.Enabled { - cfg.TLSSetting = applyTLSSettings(&opts.TLS) - } - - cfg.CORS = &confighttp.CORSConfig{ - AllowedOrigins: opts.CORS.AllowedOrigins, - AllowedHeaders: opts.CORS.AllowedHeaders, - } -} - -func applyTLSSettings(opts *tlscfg.Options) *configtls.ServerConfig { - return &configtls.ServerConfig{ - Config: configtls.Config{ - CAFile: opts.CAPath, - CertFile: opts.CertPath, - KeyFile: opts.KeyPath, - MinVersion: opts.MinVersion, - MaxVersion: opts.MaxVersion, - ReloadInterval: opts.ReloadInterval, - }, - ClientCAFile: opts.ClientCAPath, - } -} - func newConsumerDelegate(logger *zap.Logger, spanProcessor processor.SpanProcessor, tm *tenancy.Manager) *consumerDelegate { return &consumerDelegate{ batchConsumer: newBatchConsumer(logger, diff --git a/cmd/collector/app/handler/otlp_receiver_test.go b/cmd/collector/app/handler/otlp_receiver_test.go index 1f18c3d07bb..c36abac0b09 100644 --- a/cmd/collector/app/handler/otlp_receiver_test.go +++ b/cmd/collector/app/handler/otlp_receiver_test.go @@ -7,11 +7,13 @@ import ( "context" "errors" "testing" - "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config/configgrpc" + "go.opentelemetry.io/collector/config/confighttp" + "go.opentelemetry.io/collector/config/confignet" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/pdata/ptrace" "go.opentelemetry.io/collector/pipeline" @@ -19,19 +21,19 @@ import ( "go.opentelemetry.io/collector/receiver/otlpreceiver" "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" ) func optionsWithPorts(port string) *flags.CollectorOptions { opts := &flags.CollectorOptions{} - opts.OTLP.GRPC = flags.GRPCOptions{ - HostPort: port, + opts.OTLP.HTTP = confighttp.ServerConfig{ + Endpoint: port, } - opts.OTLP.HTTP = flags.HTTPOptions{ - HostPort: port, + opts.OTLP.GRPC = configgrpc.ServerConfig{ + NetAddr: confignet.AddrConfig{ + Endpoint: port, + }, } return opts } @@ -128,80 +130,3 @@ func TestOtelHost(t *testing.T) { assert.Nil(t, host.GetExtensions()) assert.Nil(t, host.GetExporters()) } - -func TestApplyOTLPGRPCServerSettings(t *testing.T) { - otlpFactory := otlpreceiver.NewFactory() - otlpReceiverConfig := otlpFactory.CreateDefaultConfig().(*otlpreceiver.Config) - - grpcOpts := &flags.GRPCOptions{ - HostPort: ":54321", - 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, - }, - } - applyGRPCSettings(otlpReceiverConfig.GRPC, grpcOpts) - out := otlpReceiverConfig.GRPC - assert.Equal(t, ":54321", out.NetAddr.Endpoint) - assert.EqualValues(t, 42, out.MaxRecvMsgSizeMiB) - require.NotNil(t, out.Keepalive) - require.NotNil(t, out.Keepalive.ServerParameters) - assert.Equal(t, 33*time.Second, out.Keepalive.ServerParameters.MaxConnectionAge) - assert.Equal(t, 37*time.Second, out.Keepalive.ServerParameters.MaxConnectionAgeGrace) - require.NotNil(t, out.TLSSetting) - assert.Equal(t, "ca", out.TLSSetting.CAFile) - assert.Equal(t, "cert", out.TLSSetting.CertFile) - assert.Equal(t, "key", out.TLSSetting.KeyFile) - assert.Equal(t, "clientca", out.TLSSetting.ClientCAFile) - assert.Equal(t, "1.1", out.TLSSetting.MinVersion) - assert.Equal(t, "1.3", out.TLSSetting.MaxVersion) - assert.Equal(t, 24*time.Hour, out.TLSSetting.ReloadInterval) -} - -func TestApplyOTLPHTTPServerSettings(t *testing.T) { - otlpFactory := otlpreceiver.NewFactory() - otlpReceiverConfig := otlpFactory.CreateDefaultConfig().(*otlpreceiver.Config) - - 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, - }, - CORS: corscfg.Options{ - AllowedOrigins: []string{"http://example.domain.com", "http://*.domain.com"}, - AllowedHeaders: []string{"Content-Type", "Accept", "X-Requested-With"}, - }, - } - - applyHTTPSettings(otlpReceiverConfig.HTTP.ServerConfig, httpOpts) - - out := otlpReceiverConfig.HTTP - - assert.Equal(t, ":12345", out.Endpoint) - require.NotNil(t, out.TLSSetting) - assert.Equal(t, "ca", out.TLSSetting.CAFile) - assert.Equal(t, "cert", out.TLSSetting.CertFile) - assert.Equal(t, "key", out.TLSSetting.KeyFile) - assert.Equal(t, "clientca", out.TLSSetting.ClientCAFile) - assert.Equal(t, "1.1", out.TLSSetting.MinVersion) - assert.Equal(t, "1.3", out.TLSSetting.MaxVersion) - assert.Equal(t, 24*time.Hour, out.TLSSetting.ReloadInterval) - assert.Equal(t, []string{"Content-Type", "Accept", "X-Requested-With"}, out.CORS.AllowedHeaders) - assert.Equal(t, []string{"http://example.domain.com", "http://*.domain.com"}, out.CORS.AllowedOrigins) -} diff --git a/cmd/collector/app/handler/zipkin_receiver.go b/cmd/collector/app/handler/zipkin_receiver.go index 983ee4bd2a5..357df299c58 100644 --- a/cmd/collector/app/handler/zipkin_receiver.go +++ b/cmd/collector/app/handler/zipkin_receiver.go @@ -56,12 +56,7 @@ func startZipkinReceiver( cfg component.Config, nextConsumer consumer.Traces) (receiver.Traces, error), ) (receiver.Traces, error) { receiverConfig := zipkinFactory.CreateDefaultConfig().(*zipkinreceiver.Config) - applyHTTPSettings(&receiverConfig.ServerConfig, &flags.HTTPOptions{ - HostPort: options.Zipkin.HTTPHostPort, - TLS: options.Zipkin.TLS, - CORS: options.HTTP.CORS, - // TODO keepAlive not supported? - }) + receiverConfig.ServerConfig = options.Zipkin receiverSettings := receiver.Settings{ TelemetrySettings: component.TelemetrySettings{ Logger: logger, diff --git a/cmd/collector/app/handler/zipkin_receiver_test.go b/cmd/collector/app/handler/zipkin_receiver_test.go index 584dbc56cda..d6ad98c4319 100644 --- a/cmd/collector/app/handler/zipkin_receiver_test.go +++ b/cmd/collector/app/handler/zipkin_receiver_test.go @@ -37,7 +37,7 @@ func TestZipkinReceiver(t *testing.T) { tm := &tenancy.Manager{} opts := &flags.CollectorOptions{} - opts.Zipkin.HTTPHostPort = ":11911" + opts.Zipkin.Endpoint = ":11911" rec, err := StartZipkinReceiver(opts, logger, spanProcessor, tm) require.NoError(t, err) @@ -138,7 +138,7 @@ func TestStartZipkinReceiver_Error(t *testing.T) { tm := &tenancy.Manager{} opts := &flags.CollectorOptions{} - opts.Zipkin.HTTPHostPort = ":-1" + opts.Zipkin.Endpoint = ":-1" _, err := StartZipkinReceiver(opts, logger, spanProcessor, tm) require.ErrorContains(t, err, "could not start Zipkin receiver") diff --git a/cmd/collector/app/handler/zipkin_receiver_tls_test.go b/cmd/collector/app/handler/zipkin_receiver_tls_test.go index 060327360a6..f0f8e80a07e 100644 --- a/cmd/collector/app/handler/zipkin_receiver_tls_test.go +++ b/cmd/collector/app/handler/zipkin_receiver_tls_test.go @@ -13,7 +13,6 @@ import ( "time" "github.com/stretchr/testify/require" - "go.uber.org/zap" "github.com/jaegertracing/jaeger/cmd/collector/app/flags" "github.com/jaegertracing/jaeger/pkg/config/tlscfg" @@ -163,9 +162,8 @@ func TestSpanCollectorZipkinTLS(t *testing.T) { tm := &tenancy.Manager{} opts := &flags.CollectorOptions{} - opts.Zipkin.HTTPHostPort = ports.PortToHostPort(ports.CollectorZipkin) - opts.Zipkin.TLS = test.serverTLS - defer test.serverTLS.Close() + opts.Zipkin.Endpoint = ports.PortToHostPort(ports.CollectorZipkin) + opts.Zipkin.TLSSetting = test.serverTLS.ToOtelServerConfig() server, err := StartZipkinReceiver(opts, logger, spanProcessor, tm) if test.expectServerFail { @@ -177,8 +175,7 @@ func TestSpanCollectorZipkinTLS(t *testing.T) { require.NoError(t, server.Shutdown(context.Background())) }() - clientTLSCfg, err0 := test.clientTLS.Config(zap.NewNop()) - defer test.clientTLS.Close() + clientTLSCfg, err0 := test.clientTLS.ToOtelClientConfig().LoadTLSConfig(context.Background()) require.NoError(t, err0) dialer := &net.Dialer{Timeout: 2 * time.Second} conn, clientError := tls.DialWithDialer(dialer, "tcp", fmt.Sprintf("localhost:%d", ports.CollectorZipkin), clientTLSCfg) @@ -197,7 +194,8 @@ func TestSpanCollectorZipkinTLS(t *testing.T) { } response, requestError := client.Post(fmt.Sprintf("https://localhost:%d", ports.CollectorZipkin), "", nil) - + fmt.Print(response) + fmt.Print(requestError) if test.expectZipkinClientErr { require.Error(t, requestError) } else { diff --git a/cmd/collector/app/server/grpc.go b/cmd/collector/app/server/grpc.go index a740fe5b8fe..8100158a943 100644 --- a/cmd/collector/app/server/grpc.go +++ b/cmd/collector/app/server/grpc.go @@ -4,10 +4,11 @@ package server import ( + "context" "fmt" "net" - "time" + "go.opentelemetry.io/collector/config/configgrpc" "go.uber.org/zap" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -19,21 +20,16 @@ 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 - HostPort string - Handler *handler.GRPCHandler - SamplingProvider samplingstrategy.Provider - Logger *zap.Logger - OnError func(error) - MaxReceiveMessageLength int - MaxConnectionAge time.Duration - MaxConnectionAgeGrace time.Duration + *configgrpc.ServerConfig + Handler *handler.GRPCHandler + SamplingProvider samplingstrategy.Provider + Logger *zap.Logger + OnError func(error) // Set by the server to indicate the actual host:port of the server. HostPortActual string @@ -44,17 +40,19 @@ func StartGRPCServer(params *GRPCServerParams) (*grpc.Server, error) { var server *grpc.Server var grpcOpts []grpc.ServerOption - if params.MaxReceiveMessageLength > 0 { - grpcOpts = append(grpcOpts, grpc.MaxRecvMsgSize(params.MaxReceiveMessageLength)) + if params.MaxRecvMsgSizeMiB > 0 { + grpcOpts = append(grpcOpts, grpc.MaxRecvMsgSize(params.MaxRecvMsgSizeMiB)) + } + if params.Keepalive != nil { + grpcOpts = append(grpcOpts, grpc.KeepaliveParams(keepalive.ServerParameters{ + MaxConnectionAge: params.Keepalive.ServerParameters.MaxConnectionAge, + MaxConnectionAgeGrace: params.Keepalive.ServerParameters.MaxConnectionAgeGrace, + })) } - grpcOpts = append(grpcOpts, grpc.KeepaliveParams(keepalive.ServerParameters{ - MaxConnectionAge: params.MaxConnectionAge, - MaxConnectionAgeGrace: params.MaxConnectionAgeGrace, - })) - if params.TLSConfig.Enabled { + if params.TLSSetting != nil { // user requested a server with TLS, setup creds - tlsCfg, err := params.TLSConfig.Config(params.Logger) + tlsCfg, err := params.TLSSetting.LoadTLSConfig(context.Background()) if err != nil { return nil, err } @@ -65,8 +63,8 @@ func StartGRPCServer(params *GRPCServerParams) (*grpc.Server, error) { server = grpc.NewServer(grpcOpts...) reflection.Register(server) - - listener, err := net.Listen("tcp", params.HostPort) + fmt.Printf("grpc endpoint %v \n", params.NetAddr.Endpoint) + listener, err := net.Listen("tcp", params.NetAddr.Endpoint) if err != nil { return nil, fmt.Errorf("failed to listen on gRPC port: %w", err) } diff --git a/cmd/collector/app/server/grpc_test.go b/cmd/collector/app/server/grpc_test.go index 19594ebcfa7..b0fa1cd40ca 100644 --- a/cmd/collector/app/server/grpc_test.go +++ b/cmd/collector/app/server/grpc_test.go @@ -10,6 +10,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/config/configgrpc" + "go.opentelemetry.io/collector/config/confignet" "go.uber.org/zap" "go.uber.org/zap/zapcore" "go.uber.org/zap/zaptest/observer" @@ -28,7 +30,11 @@ import ( func TestFailToListen(t *testing.T) { logger, _ := zap.NewDevelopment() server, err := StartGRPCServer(&GRPCServerParams{ - HostPort: ":-1", + ServerConfig: &configgrpc.ServerConfig{ + NetAddr: confignet.AddrConfig{ + Endpoint: ":-1", + }, + }, Handler: handler.NewGRPCHandler(logger, &mockSpanProcessor{}, &tenancy.Manager{}), SamplingProvider: &mockSamplingProvider{}, Logger: logger, @@ -63,10 +69,12 @@ func TestFailServe(t *testing.T) { func TestSpanCollector(t *testing.T) { logger, _ := zap.NewDevelopment() params := &GRPCServerParams{ - Handler: handler.NewGRPCHandler(logger, &mockSpanProcessor{}, &tenancy.Manager{}), - SamplingProvider: &mockSamplingProvider{}, - Logger: logger, - MaxReceiveMessageLength: 1024 * 1024, + Handler: handler.NewGRPCHandler(logger, &mockSpanProcessor{}, &tenancy.Manager{}), + SamplingProvider: &mockSamplingProvider{}, + Logger: logger, + ServerConfig: &configgrpc.ServerConfig{ + MaxRecvMsgSizeMiB: 1, + }, } server, err := StartGRPCServer(params) @@ -87,21 +95,23 @@ 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", + ServerConfig: &configgrpc.ServerConfig{ + TLSSetting: opts.ToOtelServerConfig(), }, } server, err := StartGRPCServer(params) require.NoError(t, err) defer server.Stop() - defer params.TLSConfig.Close() } func TestCollectorReflection(t *testing.T) { diff --git a/cmd/collector/app/server/http.go b/cmd/collector/app/server/http.go index c519e6df495..411df873b2e 100644 --- a/cmd/collector/app/server/http.go +++ b/cmd/collector/app/server/http.go @@ -4,18 +4,19 @@ package server import ( + "context" "net" "net/http" "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" @@ -24,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 @@ -52,8 +53,8 @@ func StartHTTPServer(params *HTTPServerParams) (*http.Server, error) { IdleTimeout: params.IdleTimeout, ErrorLog: errorLog, } - if params.TLSConfig.Enabled { - tlsCfg, err := params.TLSConfig.Config(params.Logger) // This checks if the certificates are correctly provided + if params.TLSConfig != nil { + tlsCfg, err := params.TLSConfig.LoadTLSConfig(context.Background()) if err != nil { return nil, err } @@ -90,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) diff --git a/cmd/collector/app/server/http_test.go b/cmd/collector/app/server/http_test.go index 46184bd8b89..b72cfc54039 100644 --- a/cmd/collector/app/server/http_test.go +++ b/cmd/collector/app/server/http_test.go @@ -4,6 +4,7 @@ package server import ( + "context" "crypto/tls" "fmt" "net" @@ -50,11 +51,10 @@ 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) - defer params.TLSConfig.Close() } func TestSpanCollectorHTTP(t *testing.T) { @@ -194,9 +194,8 @@ func TestSpanCollectorHTTPS(t *testing.T) { MetricsFactory: mFact, HealthCheck: healthcheck.New(), Logger: logger, - TLSConfig: test.TLS, + TLSConfig: test.TLS.ToOtelServerConfig(), } - defer params.TLSConfig.Close() server, err := StartHTTPServer(params) require.NoError(t, err) @@ -204,8 +203,7 @@ func TestSpanCollectorHTTPS(t *testing.T) { require.NoError(t, server.Close()) }() - clientTLSCfg, err0 := test.clientTLS.Config(logger) - defer test.clientTLS.Close() + clientTLSCfg, err0 := test.clientTLS.ToOtelClientConfig().LoadTLSConfig(context.Background()) require.NoError(t, err0) dialer := &net.Dialer{Timeout: 2 * time.Second} conn, clientError := tls.DialWithDialer(dialer, "tcp", "localhost:"+strconv.Itoa(ports.CollectorHTTP), clientTLSCfg) diff --git a/cmd/collector/main.go b/cmd/collector/main.go index db658c209b4..5c10bbfaca7 100644 --- a/cmd/collector/main.go +++ b/cmd/collector/main.go @@ -89,7 +89,7 @@ func main() { if err != nil { logger.Fatal("Failed to initialize collector", zap.Error(err)) } - tm := tenancy.NewManager(&collectorOpts.GRPC.Tenancy) + tm := tenancy.NewManager(&collectorOpts.Tenancy) collector := app.New(&app.CollectorParams{ ServiceName: serviceName, diff --git a/pkg/config/corscfg/options.go b/pkg/config/corscfg/options.go index 9dd1f7ffd5a..3f7979b07f8 100644 --- a/pkg/config/corscfg/options.go +++ b/pkg/config/corscfg/options.go @@ -3,7 +3,16 @@ package corscfg +import "go.opentelemetry.io/collector/config/confighttp" + type Options struct { AllowedOrigins []string AllowedHeaders []string } + +func (o *Options) ToOTELCorsConfig() *confighttp.CORSConfig { + return &confighttp.CORSConfig{ + AllowedOrigins: o.AllowedOrigins, + AllowedHeaders: o.AllowedHeaders, + } +}