Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Yuri Shkuro <[email protected]>
  • Loading branch information
yurishkuro committed Nov 29, 2024
1 parent 4c197fe commit 71c522e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/all-in-one/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
14 changes: 13 additions & 1 deletion cmd/jaeger/internal/extension/jaegerquery/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"errors"
"fmt"
"time"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/extension"
Expand Down Expand Up @@ -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)
}

Check warning on line 62 in cmd/jaeger/internal/extension/jaegerquery/server.go

View check run for this annotation

Codecov / codecov/patch

cmd/jaeger/internal/extension/jaegerquery/server.go#L61-L62

Added lines #L61 - L62 were not covered by tests
s.closeTracer = tracerProvider.Close
// make sure to close the tracer if subsequent code exists with error
success := false
defer func() {

Check failure on line 65 in cmd/jaeger/internal/extension/jaegerquery/server.go

View workflow job for this annotation

GitHub Actions / lint

Function `Start$1` should pass the context parameter (contextcheck)
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
Expand Down Expand Up @@ -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
}

Expand Down
28 changes: 16 additions & 12 deletions cmd/jaeger/internal/extension/jaegerquery/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down

0 comments on commit 71c522e

Please sign in to comment.