Skip to content

Commit

Permalink
use otel helper in collector
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 4a14e87 commit 641ddf2
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 29 deletions.
20 changes: 2 additions & 18 deletions cmd/collector/app/handler/otlp_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"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"
Expand All @@ -27,7 +26,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"
)

Expand Down Expand Up @@ -106,7 +104,7 @@ func applyGRPCSettings(cfg *configgrpc.ServerConfig, opts *flags.GRPCOptions) {
cfg.NetAddr.Endpoint = opts.HostPort
}
if opts.TLS.Enabled {
cfg.TLSSetting = applyTLSSettings(&opts.TLS)
cfg.TLSSetting = opts.TLS.ToOtelServerConfig()
}
if opts.MaxReceiveMessageLength > 0 {
cfg.MaxRecvMsgSizeMiB = int(opts.MaxReceiveMessageLength / (1024 * 1024))
Expand All @@ -126,7 +124,7 @@ func applyHTTPSettings(cfg *confighttp.ServerConfig, opts *flags.HTTPOptions) {
cfg.Endpoint = opts.HostPort
}
if opts.TLS.Enabled {
cfg.TLSSetting = applyTLSSettings(&opts.TLS)
cfg.TLSSetting = opts.TLS.ToOtelServerConfig()
}

cfg.CORS = &confighttp.CORSConfig{
Expand All @@ -135,20 +133,6 @@ func applyHTTPSettings(cfg *confighttp.ServerConfig, opts *flags.HTTPOptions) {
}
}

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,
Expand Down
5 changes: 1 addition & 4 deletions cmd/collector/app/handler/zipkin_receiver_tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -165,7 +164,6 @@ func TestSpanCollectorZipkinTLS(t *testing.T) {
opts := &flags.CollectorOptions{}
opts.Zipkin.HTTPHostPort = ports.PortToHostPort(ports.CollectorZipkin)
opts.Zipkin.TLS = test.serverTLS
defer test.serverTLS.Close()

server, err := StartZipkinReceiver(opts, logger, spanProcessor, tm)
if test.expectServerFail {
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion cmd/collector/app/server/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package server

import (
"context"
"fmt"
"net"
"time"
Expand Down Expand Up @@ -54,7 +55,7 @@ func StartGRPCServer(params *GRPCServerParams) (*grpc.Server, error) {

if params.TLSConfig.Enabled {
// user requested a server with TLS, setup creds
tlsCfg, err := params.TLSConfig.Config(params.Logger)
tlsCfg, err := params.TLSConfig.ToOtelServerConfig().LoadTLSConfig(context.Background())
if err != nil {
return nil, err
}
Expand Down
1 change: 0 additions & 1 deletion cmd/collector/app/server/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ func TestCollectorStartWithTLS(t *testing.T) {
server, err := StartGRPCServer(params)
require.NoError(t, err)
defer server.Stop()
defer params.TLSConfig.Close()
}

func TestCollectorReflection(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion cmd/collector/app/server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package server

import (
"context"
"net"
"net/http"
"time"
Expand Down Expand Up @@ -53,7 +54,7 @@ func StartHTTPServer(params *HTTPServerParams) (*http.Server, error) {
ErrorLog: errorLog,
}
if params.TLSConfig.Enabled {
tlsCfg, err := params.TLSConfig.Config(params.Logger) // This checks if the certificates are correctly provided
tlsCfg, err := params.TLSConfig.ToOtelServerConfig().LoadTLSConfig(context.Background())
if err != nil {
return nil, err
}
Expand Down
6 changes: 2 additions & 4 deletions cmd/collector/app/server/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package server

import (
"context"
"crypto/tls"
"fmt"
"net"
Expand Down Expand Up @@ -54,7 +55,6 @@ func TestCreateTLSHTTPServerError(t *testing.T) {
}
_, err := StartHTTPServer(params)
require.Error(t, err)
defer params.TLSConfig.Close()
}

func TestSpanCollectorHTTP(t *testing.T) {
Expand Down Expand Up @@ -196,16 +196,14 @@ func TestSpanCollectorHTTPS(t *testing.T) {
Logger: logger,
TLSConfig: test.TLS,
}
defer params.TLSConfig.Close()

server, err := StartHTTPServer(params)
require.NoError(t, err)
defer func() {
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)
Expand Down

0 comments on commit 641ddf2

Please sign in to comment.