Skip to content

Commit

Permalink
Move Query Service To V2 Package
Browse files Browse the repository at this point in the history
Signed-off-by: Mahad Zaryab <[email protected]>
  • Loading branch information
mahadzaryab1 committed Dec 31, 2024
1 parent a79bcac commit 5636427
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
16 changes: 15 additions & 1 deletion cmd/query/app/querysvc/query_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,27 @@ 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
ArchiveSpanWriter spanstore.Writer
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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/query/app/querysvc/query_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ 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"
"github.com/jaegertracing/jaeger/storage_v2/depstore"
"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
Expand Down Expand Up @@ -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}},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2024 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package querysvc_test
package querysvc

import (
"context"
Expand All @@ -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"
Expand All @@ -33,26 +32,26 @@ var (
)

type testQueryService struct {
queryService *querysvc.QueryServiceV2
queryService *QueryServiceV2
traceReader *tracestoremocks.Reader
depsReader *depstoremocks.Reader

archiveTraceReader *tracestoremocks.Reader
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
}
}

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
Expand All @@ -63,7 +62,7 @@ func initializeTestService(opts ...testOption) *testQueryService {
traceReader := &tracestoremocks.Reader{}
dependencyStorage := &depstoremocks.Reader{}

options := querysvc.QueryServiceOptionsV2{}
options := QueryServiceOptionsV2{}

tqs := testQueryService{
traceReader: traceReader,
Expand All @@ -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
}

Expand Down Expand Up @@ -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,
Expand All @@ -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},
},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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},
},
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
},
},
Expand Down

0 comments on commit 5636427

Please sign in to comment.