From 71c522ed79d9e30cf20508bb70afc3fb1ad83f26 Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Thu, 28 Nov 2024 21:18:25 -0500 Subject: [PATCH] fix Signed-off-by: Yuri Shkuro --- cmd/all-in-one/main.go | 2 +- .../internal/extension/jaegerquery/server.go | 14 +++++++++- .../extension/jaegerquery/server_test.go | 28 +++++++++++-------- .../extension/jaegerstorage/extension_test.go | 2 +- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/cmd/all-in-one/main.go b/cmd/all-in-one/main.go index c3d4003a54a..781515bd615 100644 --- a/cmd/all-in-one/main.go +++ b/cmd/all-in-one/main.go @@ -100,7 +100,7 @@ by default uses only in-memory database.`, } storageFactory.InitFromViper(v, logger) - if err := storageFactory.Initialize(baseFactory, logger); err != nil { + if err := storageFactory.Initialize(baseTelset.Metrics, baseTelset.Logger); err != nil { logger.Fatal("Failed to init storage factory", zap.Error(err)) } diff --git a/cmd/jaeger/internal/extension/jaegerquery/server.go b/cmd/jaeger/internal/extension/jaegerquery/server.go index 99c32629cda..0a8377d741f 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server.go @@ -7,6 +7,7 @@ import ( "context" "errors" "fmt" + "time" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/extension" @@ -59,7 +60,17 @@ func (s *server) Start(ctx context.Context, host component.Host) error { if err != nil { return fmt.Errorf("could not initialize a tracer: %w", err) } - s.closeTracer = tracerProvider.Close + // make sure to close the tracer if subsequent code exists with error + success := false + defer func() { + if success { + s.closeTracer = tracerProvider.Close + } else { + ctx, cx := context.WithTimeout(context.Background(), 10*time.Second) + tracerProvider.Close(ctx) + cx() + } + }() telset := telemetry.FromOtelComponent(s.telset, host) telset.TracerProvider = tracerProvider.OTEL @@ -114,6 +125,7 @@ func (s *server) Start(ctx context.Context, host component.Host) error { return fmt.Errorf("could not start jaeger-query: %w", err) } + success = true return nil } diff --git a/cmd/jaeger/internal/extension/jaegerquery/server_test.go b/cmd/jaeger/internal/extension/jaegerquery/server_test.go index 6fd95566e9f..54b3733f24c 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server_test.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server_test.go @@ -17,9 +17,8 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config/confignet" - "go.opentelemetry.io/collector/config/configtelemetry" - "go.opentelemetry.io/otel/metric" noopmetric "go.opentelemetry.io/otel/metric/noop" + nooptrace "go.opentelemetry.io/otel/trace/noop" "go.uber.org/zap" "go.uber.org/zap/zaptest" @@ -134,7 +133,7 @@ func TestServerStart(t *testing.T) { expectedErr string }{ { - name: "Non-empty config with fake storage host", + name: "Real server with non-empty config", config: &Config{ Storage: Storage{ TracesArchive: "jaeger_storage", @@ -204,15 +203,16 @@ func TestServerStart(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + // Despite using Noop Tracer below, query service also creates jtracer. + // We want to prevent that tracer from sampling anything in this test. + t.Setenv("OTEL_TRACES_SAMPLER", "always_off") telemetrySettings := component.TelemetrySettings{ - Logger: zaptest.NewLogger(t, zaptest.WrapOptions(zap.AddCaller())), - LeveledMeterProvider: func(_ configtelemetry.Level) metric.MeterProvider { - return noopmetric.NewMeterProvider() - }, - MeterProvider: noopmetric.NewMeterProvider(), + Logger: zaptest.NewLogger(t, zaptest.WrapOptions(zap.AddCaller())), + MeterProvider: noopmetric.NewMeterProvider(), + TracerProvider: nooptrace.NewTracerProvider(), } - tt.config.HTTP.Endpoint = ":0" - tt.config.GRPC.NetAddr.Endpoint = ":0" + tt.config.HTTP.Endpoint = "localhost:0" + tt.config.GRPC.NetAddr.Endpoint = "localhost:0" tt.config.GRPC.NetAddr.Transport = confignet.TransportTypeTCP server := newServer(tt.config, telemetrySettings) err := server.Start(context.Background(), host) @@ -297,7 +297,9 @@ func TestServerAddArchiveStorage(t *testing.T) { t.Run(tt.name, func(t *testing.T) { logger, buf := testutils.NewLogger() telemetrySettings := component.TelemetrySettings{ - Logger: logger, + Logger: logger, + MeterProvider: noopmetric.NewMeterProvider(), + TracerProvider: nooptrace.NewTracerProvider(), } server := newServer(tt.config, telemetrySettings) if tt.extension != nil { @@ -347,7 +349,9 @@ func TestServerAddMetricsStorage(t *testing.T) { t.Run(tt.name, func(t *testing.T) { logger, buf := testutils.NewLogger() telemetrySettings := component.TelemetrySettings{ - Logger: logger, + Logger: logger, + MeterProvider: noopmetric.NewMeterProvider(), + TracerProvider: nooptrace.NewTracerProvider(), } server := newServer(tt.config, telemetrySettings) if tt.extension != nil { diff --git a/cmd/jaeger/internal/extension/jaegerstorage/extension_test.go b/cmd/jaeger/internal/extension/jaegerstorage/extension_test.go index 2fe4cc88d10..6213c912765 100644 --- a/cmd/jaeger/internal/extension/jaegerstorage/extension_test.go +++ b/cmd/jaeger/internal/extension/jaegerstorage/extension_test.go @@ -39,7 +39,7 @@ type errorFactory struct { closeErr error } -func (errorFactory) Initialize(_ metrics.Factory, _ *zap.Logger) error { +func (errorFactory) Initialize(metrics.Factory, *zap.Logger) error { panic("not implemented") }