diff --git a/cmd/query/app/querysvc/query_service.go b/cmd/query/app/querysvc/query_service.go index be6a2bc256e..4eff06eeb7b 100644 --- a/cmd/query/app/querysvc/query_service.go +++ b/cmd/query/app/querysvc/query_service.go @@ -19,6 +19,12 @@ import ( "github.com/jaegertracing/jaeger/storage_v2/v1adapter" ) +var errNoArchiveSpanStorage = errors.New("archive span storage was not configured") + +const ( + defaultMaxClockSkewAdjust = time.Second +) + // QueryServiceOptions has optional members of QueryService type QueryServiceOptions struct { ArchiveSpanReader spanstore.Reader @@ -26,6 +32,14 @@ type QueryServiceOptions struct { Adjuster adjuster.Adjuster } +// StorageCapabilities is a feature flag for query service +type StorageCapabilities struct { + ArchiveStorage bool `json:"archiveStorage"` + // TODO: Maybe add metrics Storage here + // SupportRegex bool + // SupportTagFilter bool +} + // QueryService contains span utils required by the query-service. type QueryService struct { traceReader tracestore.Reader @@ -123,7 +137,7 @@ func (qs QueryService) FindTraces(ctx context.Context, query *TraceQueryParamete // ArchiveTrace is the queryService utility to archive traces. func (qs QueryService) ArchiveTrace(ctx context.Context, query spanstore.GetTraceParameters) error { if qs.options.ArchiveSpanWriter == nil { - return ErrNoArchiveSpanStorage + return errNoArchiveSpanStorage } trace, err := qs.GetTrace(ctx, GetTraceParameters{GetTraceParameters: query}) if err != nil { diff --git a/cmd/query/app/querysvc/query_service_test.go b/cmd/query/app/querysvc/query_service_test.go index ff2b744d74b..64ef7500e3f 100644 --- a/cmd/query/app/querysvc/query_service_test.go +++ b/cmd/query/app/querysvc/query_service_test.go @@ -402,7 +402,7 @@ func TestArchiveTraceNoOptions(t *testing.T) { } err := tqs.queryService.ArchiveTrace(context.WithValue(ctx, contextKey("foo"), "bar"), query) - assert.Equal(t, ErrNoArchiveSpanStorage, err) + assert.Equal(t, errNoArchiveSpanStorage, err) } // Test QueryService.ArchiveTrace() with ArchiveSpanWriter but invalid traceID. diff --git a/cmd/query/app/querysvc/query_service_v2.go b/cmd/query/app/querysvc/v2/querysvc/service.go similarity index 97% rename from cmd/query/app/querysvc/query_service_v2.go rename to cmd/query/app/querysvc/v2/querysvc/service.go index 28be19f198f..e0383388f3e 100644 --- a/cmd/query/app/querysvc/query_service_v2.go +++ b/cmd/query/app/querysvc/v2/querysvc/service.go @@ -11,7 +11,7 @@ import ( "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/ptrace" - "github.com/jaegertracing/jaeger/cmd/query/app/querysvc/adjuster" + "github.com/jaegertracing/jaeger/cmd/query/app/querysvc/v2/adjuster" "github.com/jaegertracing/jaeger/internal/jptrace" "github.com/jaegertracing/jaeger/model" "github.com/jaegertracing/jaeger/pkg/iter" @@ -19,7 +19,7 @@ import ( "github.com/jaegertracing/jaeger/storage_v2/tracestore" ) -var ErrNoArchiveSpanStorage = errors.New("archive span storage was not configured") +var errNoArchiveSpanStorage = errors.New("archive span storage was not configured") const ( defaultMaxClockSkewAdjust = time.Second @@ -137,7 +137,7 @@ func (qs QueryServiceV2) FindTraces( // an error indicating that there is no archive span storage available. func (qs QueryServiceV2) ArchiveTrace(ctx context.Context, query tracestore.GetTraceParams) error { if qs.options.ArchiveTraceWriter == nil { - return ErrNoArchiveSpanStorage + return errNoArchiveSpanStorage } getTracesIter := qs.GetTraces( ctx, GetTraceParams{TraceIDs: []tracestore.GetTraceParams{query}}, diff --git a/cmd/query/app/querysvc/query_service_v2_test.go b/cmd/query/app/querysvc/v2/querysvc/service_test.go similarity index 94% rename from cmd/query/app/querysvc/query_service_v2_test.go rename to cmd/query/app/querysvc/v2/querysvc/service_test.go index a90bbc59c8f..1993fc87ac7 100644 --- a/cmd/query/app/querysvc/query_service_v2_test.go +++ b/cmd/query/app/querysvc/v2/querysvc/service_test.go @@ -1,7 +1,7 @@ // Copyright (c) 2024 The Jaeger Authors. // SPDX-License-Identifier: Apache-2.0 -package querysvc_test +package querysvc import ( "context" @@ -15,7 +15,6 @@ import ( "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/ptrace" - "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" "github.com/jaegertracing/jaeger/model" "github.com/jaegertracing/jaeger/pkg/iter" "github.com/jaegertracing/jaeger/storage_v2/depstore" @@ -33,7 +32,7 @@ var ( ) type testQueryService struct { - queryService *querysvc.QueryServiceV2 + queryService *QueryServiceV2 traceReader *tracestoremocks.Reader depsReader *depstoremocks.Reader @@ -41,10 +40,10 @@ type testQueryService struct { archiveTraceWriter *tracestoremocks.Writer } -type testOption func(*testQueryService, *querysvc.QueryServiceOptionsV2) +type testOption func(*testQueryService, *QueryServiceOptionsV2) func withArchiveTraceReader() testOption { - return func(tqs *testQueryService, options *querysvc.QueryServiceOptionsV2) { + return func(tqs *testQueryService, options *QueryServiceOptionsV2) { r := &tracestoremocks.Reader{} tqs.archiveTraceReader = r options.ArchiveTraceReader = r @@ -52,7 +51,7 @@ func withArchiveTraceReader() testOption { } func withArchiveTraceWriter() testOption { - return func(tqs *testQueryService, options *querysvc.QueryServiceOptionsV2) { + return func(tqs *testQueryService, options *QueryServiceOptionsV2) { r := &tracestoremocks.Writer{} tqs.archiveTraceWriter = r options.ArchiveTraceWriter = r @@ -63,7 +62,7 @@ func initializeTestService(opts ...testOption) *testQueryService { traceReader := &tracestoremocks.Reader{} dependencyStorage := &depstoremocks.Reader{} - options := querysvc.QueryServiceOptionsV2{} + options := QueryServiceOptionsV2{} tqs := testQueryService{ traceReader: traceReader, @@ -74,7 +73,7 @@ func initializeTestService(opts ...testOption) *testQueryService { opt(&tqs, &options) } - tqs.queryService = querysvc.NewQueryServiceV2(traceReader, dependencyStorage, options) + tqs.queryService = NewQueryServiceV2(traceReader, dependencyStorage, options) return &tqs } @@ -102,7 +101,7 @@ func TestGetTraces_ErrorInReader(t *testing.T) { yield(nil, assert.AnError) })).Once() - params := querysvc.GetTraceParams{ + params := GetTraceParams{ TraceIDs: []tracestore.GetTraceParams{ { TraceID: testTraceID, @@ -121,7 +120,7 @@ func TestGetTraces_Success(t *testing.T) { yield([]ptrace.Traces{makeTestTrace()}, nil) })).Once() - params := querysvc.GetTraceParams{ + params := GetTraceParams{ TraceIDs: []tracestore.GetTraceParams{ {TraceID: testTraceID}, }, @@ -190,7 +189,7 @@ func TestGetTraces_WithRawTraces(t *testing.T) { tqs.traceReader.On("GetTraces", mock.Anything, tracestore.GetTraceParams{TraceID: testTraceID}). Return(responseIter).Once() - params := querysvc.GetTraceParams{ + params := GetTraceParams{ TraceIDs: []tracestore.GetTraceParams{ { TraceID: testTraceID, @@ -222,7 +221,7 @@ func TestGetTraces_TraceInArchiveStorage(t *testing.T) { yield([]ptrace.Traces{makeTestTrace()}, nil) })).Once() - params := querysvc.GetTraceParams{ + params := GetTraceParams{ TraceIDs: []tracestore.GetTraceParams{ {TraceID: testTraceID}, }, @@ -282,7 +281,7 @@ func TestFindTraces_Success(t *testing.T) { } tqs.traceReader.On("FindTraces", mock.Anything, queryParams).Return(responseIter).Once() - query := querysvc.TraceQueryParams{TraceQueryParams: queryParams} + query := TraceQueryParams{TraceQueryParams: queryParams} getTracesIter := tqs.queryService.FindTraces(context.Background(), query) gotTraces, err := iter.FlattenWithErrors(getTracesIter) require.NoError(t, err) @@ -356,7 +355,7 @@ func TestFindTraces_WithRawTraces(t *testing.T) { }). Return(responseIter).Once() - query := querysvc.TraceQueryParams{ + query := TraceQueryParams{ TraceQueryParams: tracestore.TraceQueryParams{ ServiceName: "service", OperationName: "operation", @@ -388,7 +387,7 @@ func TestArchiveTrace(t *testing.T) { name: "no options", options: nil, setupMocks: func(*testQueryService) {}, - expectedError: querysvc.ErrNoArchiveSpanStorage, + expectedError: errNoArchiveSpanStorage, }, { name: "get trace error", @@ -471,18 +470,18 @@ func TestGetCapabilities(t *testing.T) { tests := []struct { name string options []testOption - expected querysvc.StorageCapabilities + expected StorageCapabilities }{ { name: "without archive storage", - expected: querysvc.StorageCapabilities{ + expected: StorageCapabilities{ ArchiveStorage: false, }, }, { name: "with archive storage", options: []testOption{withArchiveTraceReader(), withArchiveTraceWriter()}, - expected: querysvc.StorageCapabilities{ + expected: StorageCapabilities{ ArchiveStorage: true, }, },