From c5600ba2fd17c41feefb8c1d599371ec8c0d820d Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Sat, 16 Nov 2024 11:26:41 -0500 Subject: [PATCH 01/17] Add Reader With V2 Interface Signed-off-by: Mahad Zaryab --- storage_v2/factoryadapter/reader.go | 54 ++++++++++++ storage_v2/factoryadapter/reader_test.go | 103 +++++++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 storage_v2/factoryadapter/reader.go create mode 100644 storage_v2/factoryadapter/reader_test.go diff --git a/storage_v2/factoryadapter/reader.go b/storage_v2/factoryadapter/reader.go new file mode 100644 index 00000000000..6074966874d --- /dev/null +++ b/storage_v2/factoryadapter/reader.go @@ -0,0 +1,54 @@ +// Copyright (c) 2024 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + +package factoryadapter + +import ( + "context" + "errors" + + "go.opentelemetry.io/collector/pdata/pcommon" + "go.opentelemetry.io/collector/pdata/ptrace" + + spanstore_v1 "github.com/jaegertracing/jaeger/storage/spanstore" + "github.com/jaegertracing/jaeger/storage_v2/spanstore" +) + +var ErrV1ReaderNotAvailable = errors.New("v1 reader is not available") + +type TraceReader struct { + spanReader spanstore_v1.Reader +} + +func GetV1Reader(reader spanstore.Reader) (spanstore_v1.Reader, error) { + if tr, ok := reader.(*TraceReader); ok { + return tr.spanReader, nil + } + return nil, ErrV1ReaderNotAvailable +} + +func NewTraceReader(spanReader spanstore_v1.Reader) *TraceReader { + return &TraceReader{ + spanReader: spanReader, + } +} + +func (*TraceReader) GetTrace(_ context.Context, _ pcommon.TraceID) (ptrace.Traces, error) { + panic("not implemented") +} + +func (*TraceReader) GetServices(_ context.Context) ([]string, error) { + panic("not implemented") +} + +func (*TraceReader) GetOperations(_ context.Context, _ spanstore.OperationQueryParameters) ([]spanstore.Operation, error) { + panic("not implemented") +} + +func (*TraceReader) FindTraces(_ context.Context, _ spanstore.TraceQueryParameters) ([]ptrace.Traces, error) { + panic("not implemented") +} + +func (*TraceReader) FindTraceIDs(_ context.Context, _ spanstore.TraceQueryParameters) ([]pcommon.TraceID, error) { + panic("not implemented") +} diff --git a/storage_v2/factoryadapter/reader_test.go b/storage_v2/factoryadapter/reader_test.go new file mode 100644 index 00000000000..fb5155b524b --- /dev/null +++ b/storage_v2/factoryadapter/reader_test.go @@ -0,0 +1,103 @@ +// Copyright (c) 2024 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + +package factoryadapter + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/pdata/pcommon" + "go.opentelemetry.io/collector/pdata/ptrace" + + "github.com/jaegertracing/jaeger/plugin/storage/memory" + "github.com/jaegertracing/jaeger/storage_v2/spanstore" +) + +func TestGetV1Reader_NoError(t *testing.T) { + memstore := memory.NewStore() + traceReader := &TraceReader{ + spanReader: memstore, + } + v1Reader, err := GetV1Reader(traceReader) + require.NoError(t, err) + require.Equal(t, memstore, v1Reader) +} + +type fakeReader struct{} + +func (*fakeReader) GetTrace(_ context.Context, _ pcommon.TraceID) (ptrace.Traces, error) { + panic("not implemented") +} + +func (*fakeReader) GetServices(_ context.Context) ([]string, error) { + panic("not implemented") +} + +func (*fakeReader) GetOperations(_ context.Context, _ spanstore.OperationQueryParameters) ([]spanstore.Operation, error) { + panic("not implemented") +} + +func (*fakeReader) FindTraces(_ context.Context, _ spanstore.TraceQueryParameters) ([]ptrace.Traces, error) { + panic("not implemented") +} + +func (*fakeReader) FindTraceIDs(_ context.Context, _ spanstore.TraceQueryParameters) ([]pcommon.TraceID, error) { + panic("not implemented") +} + +func TestGetV1Reader_Error(t *testing.T) { + fr := &fakeReader{} + _, err := GetV1Reader(fr) + require.ErrorIs(t, err, ErrV1ReaderNotAvailable) +} + +func TestTraceReader_GetTracePanics(t *testing.T) { + memstore := memory.NewStore() + traceReader := &TraceReader{ + spanReader: memstore, + } + require.Panics(t, func() { traceReader.GetTrace(context.Background(), pcommon.NewTraceIDEmpty()) }) +} + +func TestTraceReader_GetServicesPanics(t *testing.T) { + memstore := memory.NewStore() + traceReader := &TraceReader{ + spanReader: memstore, + } + require.Panics(t, func() { traceReader.GetServices(context.Background()) }) +} + +func TestTraceReader_GetOperationsPanics(t *testing.T) { + memstore := memory.NewStore() + traceReader := &TraceReader{ + spanReader: memstore, + } + require.Panics( + t, + func() { traceReader.GetOperations(context.Background(), spanstore.OperationQueryParameters{}) }, + ) +} + +func TestTraceReader_FindTracesPanics(t *testing.T) { + memstore := memory.NewStore() + traceReader := &TraceReader{ + spanReader: memstore, + } + require.Panics( + t, + func() { traceReader.FindTraces(context.Background(), spanstore.TraceQueryParameters{}) }, + ) +} + +func TestTraceReader_FindTraceIDsPanics(t *testing.T) { + memstore := memory.NewStore() + traceReader := &TraceReader{ + spanReader: memstore, + } + require.Panics( + t, + func() { traceReader.FindTraceIDs(context.Background(), spanstore.TraceQueryParameters{}) }, + ) +} From 23c7700938f0990b056e61753261ca59247ad4d8 Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Sat, 16 Nov 2024 11:39:51 -0500 Subject: [PATCH 02/17] Hold TraceReader In Query Service Signed-off-by: Mahad Zaryab --- cmd/all-in-one/main.go | 4 +- .../internal/extension/jaegerquery/server.go | 4 +- cmd/query/app/querysvc/query_service.go | 44 +++++++++++++------ cmd/query/main.go | 4 +- 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/cmd/all-in-one/main.go b/cmd/all-in-one/main.go index f7d650ffdee..23aa86fe68d 100644 --- a/cmd/all-in-one/main.go +++ b/cmd/all-in-one/main.go @@ -44,6 +44,7 @@ import ( metricsstoreMetrics "github.com/jaegertracing/jaeger/storage/metricsstore/metrics" "github.com/jaegertracing/jaeger/storage/spanstore" storageMetrics "github.com/jaegertracing/jaeger/storage/spanstore/metrics" + "github.com/jaegertracing/jaeger/storage_v2/factoryadapter" ) // all-in-one/main is a standalone full-stack jaeger backend, backed by a memory store @@ -225,7 +226,8 @@ func startQuery( telset telemetery.Setting, ) *queryApp.Server { spanReader = storageMetrics.NewReadMetricsDecorator(spanReader, telset.Metrics) - qs := querysvc.NewQueryService(spanReader, depReader, *queryOpts) + traceReader := factoryadapter.NewTraceReader(spanReader) + qs := querysvc.NewQueryService(traceReader, depReader, *queryOpts) server, err := queryApp.NewServer(context.Background(), qs, metricsQueryService, qOpts, tm, telset) if err != nil { diff --git a/cmd/jaeger/internal/extension/jaegerquery/server.go b/cmd/jaeger/internal/extension/jaegerquery/server.go index 7966cb6f110..510e90a0cab 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server.go @@ -24,6 +24,7 @@ import ( "github.com/jaegertracing/jaeger/plugin/metrics/disabled" "github.com/jaegertracing/jaeger/storage/metricsstore" storageMetrics "github.com/jaegertracing/jaeger/storage/spanstore/metrics" + "github.com/jaegertracing/jaeger/storage_v2/factoryadapter" ) var ( @@ -66,6 +67,7 @@ func (s *server) Start(ctx context.Context, host component.Host) error { } spanReader = storageMetrics.NewReadMetricsDecorator(spanReader, queryMetricsFactory) + traceReader := factoryadapter.NewTraceReader(spanReader) depReader, err := f.CreateDependencyReader() if err != nil { @@ -76,7 +78,7 @@ func (s *server) Start(ctx context.Context, host component.Host) error { if err := s.addArchiveStorage(&opts, host); err != nil { return err } - qs := querysvc.NewQueryService(spanReader, depReader, opts) + qs := querysvc.NewQueryService(traceReader, depReader, opts) mqs, err := s.createMetricReader(host) if err != nil { diff --git a/cmd/query/app/querysvc/query_service.go b/cmd/query/app/querysvc/query_service.go index 135ecc60bbe..5e23de8f499 100644 --- a/cmd/query/app/querysvc/query_service.go +++ b/cmd/query/app/querysvc/query_service.go @@ -14,7 +14,9 @@ import ( "github.com/jaegertracing/jaeger/model/adjuster" "github.com/jaegertracing/jaeger/storage" "github.com/jaegertracing/jaeger/storage/dependencystore" - "github.com/jaegertracing/jaeger/storage/spanstore" + spanstore_v1 "github.com/jaegertracing/jaeger/storage/spanstore" + "github.com/jaegertracing/jaeger/storage_v2/factoryadapter" + "github.com/jaegertracing/jaeger/storage_v2/spanstore" ) var errNoArchiveSpanStorage = errors.New("archive span storage was not configured") @@ -25,8 +27,8 @@ const ( // QueryServiceOptions has optional members of QueryService type QueryServiceOptions struct { - ArchiveSpanReader spanstore.Reader - ArchiveSpanWriter spanstore.Writer + ArchiveSpanReader spanstore_v1.Reader + ArchiveSpanWriter spanstore_v1.Writer Adjuster adjuster.Adjuster } @@ -40,15 +42,15 @@ type StorageCapabilities struct { // QueryService contains span utils required by the query-service. type QueryService struct { - spanReader spanstore.Reader + traceReader spanstore.Reader dependencyReader dependencystore.Reader options QueryServiceOptions } // NewQueryService returns a new QueryService. -func NewQueryService(spanReader spanstore.Reader, dependencyReader dependencystore.Reader, options QueryServiceOptions) *QueryService { +func NewQueryService(traceReader spanstore.Reader, dependencyReader dependencystore.Reader, options QueryServiceOptions) *QueryService { qsvc := &QueryService{ - spanReader: spanReader, + traceReader: traceReader, dependencyReader: dependencyReader, options: options, } @@ -61,7 +63,11 @@ func NewQueryService(spanReader spanstore.Reader, dependencyReader dependencysto // GetTrace is the queryService implementation of spanstore.Reader.GetTrace func (qs QueryService) GetTrace(ctx context.Context, traceID model.TraceID) (*model.Trace, error) { - trace, err := qs.spanReader.GetTrace(ctx, traceID) + spanReader, err := factoryadapter.GetV1Reader(qs.traceReader) + if err != nil { + return nil, err + } + trace, err := spanReader.GetTrace(ctx, traceID) if errors.Is(err, spanstore.ErrTraceNotFound) { if qs.options.ArchiveSpanReader == nil { return nil, err @@ -73,20 +79,32 @@ func (qs QueryService) GetTrace(ctx context.Context, traceID model.TraceID) (*mo // GetServices is the queryService implementation of spanstore.Reader.GetServices func (qs QueryService) GetServices(ctx context.Context) ([]string, error) { - return qs.spanReader.GetServices(ctx) + spanReader, err := factoryadapter.GetV1Reader(qs.traceReader) + if err != nil { + return nil, err + } + return spanReader.GetServices(ctx) } // GetOperations is the queryService implementation of spanstore.Reader.GetOperations func (qs QueryService) GetOperations( ctx context.Context, - query spanstore.OperationQueryParameters, -) ([]spanstore.Operation, error) { - return qs.spanReader.GetOperations(ctx, query) + query spanstore_v1.OperationQueryParameters, +) ([]spanstore_v1.Operation, error) { + spanReader, err := factoryadapter.GetV1Reader(qs.traceReader) + if err != nil { + return nil, err + } + return spanReader.GetOperations(ctx, query) } // FindTraces is the queryService implementation of spanstore.Reader.FindTraces -func (qs QueryService) FindTraces(ctx context.Context, query *spanstore.TraceQueryParameters) ([]*model.Trace, error) { - return qs.spanReader.FindTraces(ctx, query) +func (qs QueryService) FindTraces(ctx context.Context, query *spanstore_v1.TraceQueryParameters) ([]*model.Trace, error) { + spanReader, err := factoryadapter.GetV1Reader(qs.traceReader) + if err != nil { + return nil, err + } + return spanReader.FindTraces(ctx, query) } // ArchiveTrace is the queryService utility to archive traces. diff --git a/cmd/query/main.go b/cmd/query/main.go index 61b5975cb05..1ab4c5f113b 100644 --- a/cmd/query/main.go +++ b/cmd/query/main.go @@ -37,6 +37,7 @@ import ( "github.com/jaegertracing/jaeger/ports" metricsstoreMetrics "github.com/jaegertracing/jaeger/storage/metricsstore/metrics" spanstoreMetrics "github.com/jaegertracing/jaeger/storage/spanstore/metrics" + "github.com/jaegertracing/jaeger/storage_v2/factoryadapter" ) func main() { @@ -92,6 +93,7 @@ func main() { logger.Fatal("Failed to create span reader", zap.Error(err)) } spanReader = spanstoreMetrics.NewReadMetricsDecorator(spanReader, metricsFactory) + traceReader := factoryadapter.NewTraceReader(spanReader) dependencyReader, err := storageFactory.CreateDependencyReader() if err != nil { logger.Fatal("Failed to create dependency reader", zap.Error(err)) @@ -103,7 +105,7 @@ func main() { } queryServiceOptions := queryOpts.BuildQueryServiceOptions(storageFactory, logger) queryService := querysvc.NewQueryService( - spanReader, + traceReader, dependencyReader, *queryServiceOptions) tm := tenancy.NewManager(&queryOpts.Tenancy) From 2b53471cad69ccc34b2ec568d61a54e428d6ad99 Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Sat, 16 Nov 2024 12:07:27 -0500 Subject: [PATCH 03/17] Generate Mocks For V2 Storage Signed-off-by: Mahad Zaryab --- .mockery.yaml | 3 + storage_v2/spanstore/mocks/Factory.go | 130 ++++++++++++++++++ storage_v2/spanstore/mocks/Reader.go | 186 ++++++++++++++++++++++++++ storage_v2/spanstore/mocks/Writer.go | 52 +++++++ 4 files changed, 371 insertions(+) create mode 100644 storage_v2/spanstore/mocks/Factory.go create mode 100644 storage_v2/spanstore/mocks/Reader.go create mode 100644 storage_v2/spanstore/mocks/Writer.go diff --git a/.mockery.yaml b/.mockery.yaml index 48f9c27d4b9..ecfd99003ac 100644 --- a/.mockery.yaml +++ b/.mockery.yaml @@ -67,3 +67,6 @@ packages: github.com/jaegertracing/jaeger/storage/spanstore: config: all: true + github.com/jaegertracing/jaeger/storage_v2/spanstore: + config: + all: true diff --git a/storage_v2/spanstore/mocks/Factory.go b/storage_v2/spanstore/mocks/Factory.go new file mode 100644 index 00000000000..fbd140b5c92 --- /dev/null +++ b/storage_v2/spanstore/mocks/Factory.go @@ -0,0 +1,130 @@ +// Copyright (c) The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 +// +// Run 'make generate-mocks' to regenerate. + +// Code generated by mockery. DO NOT EDIT. + +package mocks + +import ( + context "context" + + spanstore "github.com/jaegertracing/jaeger/storage_v2/spanstore" + mock "github.com/stretchr/testify/mock" +) + +// Factory is an autogenerated mock type for the Factory type +type Factory struct { + mock.Mock +} + +// Close provides a mock function with given fields: ctx +func (_m *Factory) Close(ctx context.Context) error { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Close") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context) error); ok { + r0 = rf(ctx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// CreateTraceReader provides a mock function with given fields: +func (_m *Factory) CreateTraceReader() (spanstore.Reader, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for CreateTraceReader") + } + + var r0 spanstore.Reader + var r1 error + if rf, ok := ret.Get(0).(func() (spanstore.Reader, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() spanstore.Reader); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(spanstore.Reader) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CreateTraceWriter provides a mock function with given fields: +func (_m *Factory) CreateTraceWriter() (spanstore.Writer, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for CreateTraceWriter") + } + + var r0 spanstore.Writer + var r1 error + if rf, ok := ret.Get(0).(func() (spanstore.Writer, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() spanstore.Writer); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(spanstore.Writer) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Initialize provides a mock function with given fields: ctx +func (_m *Factory) Initialize(ctx context.Context) error { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Initialize") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context) error); ok { + r0 = rf(ctx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// NewFactory creates a new instance of Factory. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewFactory(t interface { + mock.TestingT + Cleanup(func()) +}) *Factory { + mock := &Factory{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/storage_v2/spanstore/mocks/Reader.go b/storage_v2/spanstore/mocks/Reader.go new file mode 100644 index 00000000000..933cc037a9e --- /dev/null +++ b/storage_v2/spanstore/mocks/Reader.go @@ -0,0 +1,186 @@ +// Copyright (c) The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 +// +// Run 'make generate-mocks' to regenerate. + +// Code generated by mockery. DO NOT EDIT. + +package mocks + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + pcommon "go.opentelemetry.io/collector/pdata/pcommon" + + ptrace "go.opentelemetry.io/collector/pdata/ptrace" + + spanstore "github.com/jaegertracing/jaeger/storage_v2/spanstore" +) + +// Reader is an autogenerated mock type for the Reader type +type Reader struct { + mock.Mock +} + +// FindTraceIDs provides a mock function with given fields: ctx, query +func (_m *Reader) FindTraceIDs(ctx context.Context, query spanstore.TraceQueryParameters) ([]pcommon.TraceID, error) { + ret := _m.Called(ctx, query) + + if len(ret) == 0 { + panic("no return value specified for FindTraceIDs") + } + + var r0 []pcommon.TraceID + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, spanstore.TraceQueryParameters) ([]pcommon.TraceID, error)); ok { + return rf(ctx, query) + } + if rf, ok := ret.Get(0).(func(context.Context, spanstore.TraceQueryParameters) []pcommon.TraceID); ok { + r0 = rf(ctx, query) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]pcommon.TraceID) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, spanstore.TraceQueryParameters) error); ok { + r1 = rf(ctx, query) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// FindTraces provides a mock function with given fields: ctx, query +func (_m *Reader) FindTraces(ctx context.Context, query spanstore.TraceQueryParameters) ([]ptrace.Traces, error) { + ret := _m.Called(ctx, query) + + if len(ret) == 0 { + panic("no return value specified for FindTraces") + } + + var r0 []ptrace.Traces + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, spanstore.TraceQueryParameters) ([]ptrace.Traces, error)); ok { + return rf(ctx, query) + } + if rf, ok := ret.Get(0).(func(context.Context, spanstore.TraceQueryParameters) []ptrace.Traces); ok { + r0 = rf(ctx, query) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]ptrace.Traces) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, spanstore.TraceQueryParameters) error); ok { + r1 = rf(ctx, query) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetOperations provides a mock function with given fields: ctx, query +func (_m *Reader) GetOperations(ctx context.Context, query spanstore.OperationQueryParameters) ([]spanstore.Operation, error) { + ret := _m.Called(ctx, query) + + if len(ret) == 0 { + panic("no return value specified for GetOperations") + } + + var r0 []spanstore.Operation + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, spanstore.OperationQueryParameters) ([]spanstore.Operation, error)); ok { + return rf(ctx, query) + } + if rf, ok := ret.Get(0).(func(context.Context, spanstore.OperationQueryParameters) []spanstore.Operation); ok { + r0 = rf(ctx, query) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]spanstore.Operation) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, spanstore.OperationQueryParameters) error); ok { + r1 = rf(ctx, query) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetServices provides a mock function with given fields: ctx +func (_m *Reader) GetServices(ctx context.Context) ([]string, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for GetServices") + } + + var r0 []string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]string, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []string); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetTrace provides a mock function with given fields: ctx, traceID +func (_m *Reader) GetTrace(ctx context.Context, traceID pcommon.TraceID) (ptrace.Traces, error) { + ret := _m.Called(ctx, traceID) + + if len(ret) == 0 { + panic("no return value specified for GetTrace") + } + + var r0 ptrace.Traces + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, pcommon.TraceID) (ptrace.Traces, error)); ok { + return rf(ctx, traceID) + } + if rf, ok := ret.Get(0).(func(context.Context, pcommon.TraceID) ptrace.Traces); ok { + r0 = rf(ctx, traceID) + } else { + r0 = ret.Get(0).(ptrace.Traces) + } + + if rf, ok := ret.Get(1).(func(context.Context, pcommon.TraceID) error); ok { + r1 = rf(ctx, traceID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewReader creates a new instance of Reader. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewReader(t interface { + mock.TestingT + Cleanup(func()) +}) *Reader { + mock := &Reader{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/storage_v2/spanstore/mocks/Writer.go b/storage_v2/spanstore/mocks/Writer.go new file mode 100644 index 00000000000..a827057b26f --- /dev/null +++ b/storage_v2/spanstore/mocks/Writer.go @@ -0,0 +1,52 @@ +// Copyright (c) The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 +// +// Run 'make generate-mocks' to regenerate. + +// Code generated by mockery. DO NOT EDIT. + +package mocks + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + ptrace "go.opentelemetry.io/collector/pdata/ptrace" +) + +// Writer is an autogenerated mock type for the Writer type +type Writer struct { + mock.Mock +} + +// WriteTraces provides a mock function with given fields: ctx, td +func (_m *Writer) WriteTraces(ctx context.Context, td ptrace.Traces) error { + ret := _m.Called(ctx, td) + + if len(ret) == 0 { + panic("no return value specified for WriteTraces") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, ptrace.Traces) error); ok { + r0 = rf(ctx, td) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// NewWriter creates a new instance of Writer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewWriter(t interface { + mock.TestingT + Cleanup(func()) +}) *Writer { + mock := &Writer{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} From 617c30c04a537d92ead9f0024fda43b74d49d9f3 Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Sat, 16 Nov 2024 12:07:40 -0500 Subject: [PATCH 04/17] Fix Unit Tests Signed-off-by: Mahad Zaryab --- cmd/anonymizer/app/query/query_test.go | 4 +++- cmd/query/app/apiv3/grpc_handler_test.go | 3 ++- cmd/query/app/apiv3/http_gateway_test.go | 3 ++- cmd/query/app/grpc_handler_test.go | 5 +++-- cmd/query/app/http_handler_test.go | 7 +++++-- cmd/query/app/querysvc/query_service_test.go | 4 +++- cmd/query/app/server_test.go | 4 +++- cmd/query/app/token_propagation_test.go | 4 +++- 8 files changed, 24 insertions(+), 10 deletions(-) diff --git a/cmd/anonymizer/app/query/query_test.go b/cmd/anonymizer/app/query/query_test.go index 86b7fd55ed8..8d91ba5febd 100644 --- a/cmd/anonymizer/app/query/query_test.go +++ b/cmd/anonymizer/app/query/query_test.go @@ -21,6 +21,7 @@ import ( dependencyStoreMocks "github.com/jaegertracing/jaeger/storage/dependencystore/mocks" "github.com/jaegertracing/jaeger/storage/spanstore" spanstoremocks "github.com/jaegertracing/jaeger/storage/spanstore/mocks" + "github.com/jaegertracing/jaeger/storage_v2/factoryadapter" ) var ( @@ -55,11 +56,12 @@ type testServer struct { func newTestServer(t *testing.T) *testServer { spanReader := &spanstoremocks.Reader{} + traceReader := factoryadapter.NewTraceReader(spanReader) metricsReader, err := disabled.NewMetricsReader() require.NoError(t, err) q := querysvc.NewQueryService( - spanReader, + traceReader, &dependencyStoreMocks.Reader{}, querysvc.QueryServiceOptions{}, ) diff --git a/cmd/query/app/apiv3/grpc_handler_test.go b/cmd/query/app/apiv3/grpc_handler_test.go index bb3c08d9b59..36297505292 100644 --- a/cmd/query/app/apiv3/grpc_handler_test.go +++ b/cmd/query/app/apiv3/grpc_handler_test.go @@ -23,6 +23,7 @@ import ( dependencyStoreMocks "github.com/jaegertracing/jaeger/storage/dependencystore/mocks" "github.com/jaegertracing/jaeger/storage/spanstore" spanstoremocks "github.com/jaegertracing/jaeger/storage/spanstore/mocks" + "github.com/jaegertracing/jaeger/storage_v2/factoryadapter" ) var ( @@ -57,7 +58,7 @@ func newTestServerClient(t *testing.T) *testServerClient { } q := querysvc.NewQueryService( - tsc.reader, + factoryadapter.NewTraceReader(tsc.reader), &dependencyStoreMocks.Reader{}, querysvc.QueryServiceOptions{}, ) diff --git a/cmd/query/app/apiv3/http_gateway_test.go b/cmd/query/app/apiv3/http_gateway_test.go index 6feaba989c6..5f742a0522f 100644 --- a/cmd/query/app/apiv3/http_gateway_test.go +++ b/cmd/query/app/apiv3/http_gateway_test.go @@ -25,6 +25,7 @@ import ( dependencyStoreMocks "github.com/jaegertracing/jaeger/storage/dependencystore/mocks" "github.com/jaegertracing/jaeger/storage/spanstore" spanstoremocks "github.com/jaegertracing/jaeger/storage/spanstore/mocks" + "github.com/jaegertracing/jaeger/storage_v2/factoryadapter" ) func setupHTTPGatewayNoServer( @@ -35,7 +36,7 @@ func setupHTTPGatewayNoServer( reader: &spanstoremocks.Reader{}, } - q := querysvc.NewQueryService(gw.reader, + q := querysvc.NewQueryService(factoryadapter.NewTraceReader(gw.reader), &dependencyStoreMocks.Reader{}, querysvc.QueryServiceOptions{}, ) diff --git a/cmd/query/app/grpc_handler_test.go b/cmd/query/app/grpc_handler_test.go index 016ee19b77f..2e364d35562 100644 --- a/cmd/query/app/grpc_handler_test.go +++ b/cmd/query/app/grpc_handler_test.go @@ -33,6 +33,7 @@ import ( metricsmocks "github.com/jaegertracing/jaeger/storage/metricsstore/mocks" "github.com/jaegertracing/jaeger/storage/spanstore" spanstoremocks "github.com/jaegertracing/jaeger/storage/spanstore/mocks" + "github.com/jaegertracing/jaeger/storage_v2/factoryadapter" ) var ( @@ -901,7 +902,7 @@ func initializeTenantedTestServerGRPCWithOptions(t *testing.T, tm *tenancy.Manag require.NoError(t, err) q := querysvc.NewQueryService( - spanReader, + factoryadapter.NewTraceReader(spanReader), dependencyReader, querysvc.QueryServiceOptions{ ArchiveSpanReader: archiveSpanReader, @@ -1165,7 +1166,7 @@ func TestNewGRPCHandlerWithEmptyOptions(t *testing.T) { require.NoError(t, err) q := querysvc.NewQueryService( - &spanstoremocks.Reader{}, + factoryadapter.NewTraceReader(&spanstoremocks.Reader{}), &depsmocks.Reader{}, querysvc.QueryServiceOptions{}) diff --git a/cmd/query/app/http_handler_test.go b/cmd/query/app/http_handler_test.go index 5da9482af87..7bc8808c5c1 100644 --- a/cmd/query/app/http_handler_test.go +++ b/cmd/query/app/http_handler_test.go @@ -42,6 +42,7 @@ import ( metricsmocks "github.com/jaegertracing/jaeger/storage/metricsstore/mocks" "github.com/jaegertracing/jaeger/storage/spanstore" spanstoremocks "github.com/jaegertracing/jaeger/storage/spanstore/mocks" + "github.com/jaegertracing/jaeger/storage_v2/factoryadapter" ) const millisToNanosMultiplier = int64(time.Millisecond / time.Nanosecond) @@ -119,7 +120,8 @@ func initializeTestServerWithOptions( options = append(options, HandlerOptions.Logger(zaptest.NewLogger(t))) readStorage := &spanstoremocks.Reader{} dependencyStorage := &depsmocks.Reader{} - qs := querysvc.NewQueryService(readStorage, dependencyStorage, queryOptions) + traceReader := factoryadapter.NewTraceReader(readStorage) + qs := querysvc.NewQueryService(traceReader, dependencyStorage, queryOptions) r := NewRouter() apiHandler := NewAPIHandler(qs, options...) apiHandler.RegisterRoutes(r) @@ -198,8 +200,9 @@ func TestLogOnServerError(t *testing.T) { zapCore, logs := observer.New(zap.InfoLevel) logger := zap.New(zapCore) readStorage := &spanstoremocks.Reader{} + traceReader := factoryadapter.NewTraceReader(readStorage) dependencyStorage := &depsmocks.Reader{} - qs := querysvc.NewQueryService(readStorage, dependencyStorage, querysvc.QueryServiceOptions{}) + qs := querysvc.NewQueryService(traceReader, dependencyStorage, querysvc.QueryServiceOptions{}) h := NewAPIHandler(qs, HandlerOptions.Logger(logger)) e := errors.New("test error") h.handleError(&httptest.ResponseRecorder{}, e, http.StatusInternalServerError) diff --git a/cmd/query/app/querysvc/query_service_test.go b/cmd/query/app/querysvc/query_service_test.go index 582a4568509..9cf6cea9128 100644 --- a/cmd/query/app/querysvc/query_service_test.go +++ b/cmd/query/app/querysvc/query_service_test.go @@ -23,6 +23,7 @@ import ( depsmocks "github.com/jaegertracing/jaeger/storage/dependencystore/mocks" "github.com/jaegertracing/jaeger/storage/spanstore" spanstoremocks "github.com/jaegertracing/jaeger/storage/spanstore/mocks" + "github.com/jaegertracing/jaeger/storage_v2/factoryadapter" ) const millisToNanosMultiplier = int64(time.Millisecond / time.Nanosecond) @@ -87,6 +88,7 @@ func withAdjuster() testOption { func initializeTestService(optionAppliers ...testOption) *testQueryService { readStorage := &spanstoremocks.Reader{} + traceReader := factoryadapter.NewTraceReader(readStorage) dependencyStorage := &depsmocks.Reader{} options := QueryServiceOptions{} @@ -100,7 +102,7 @@ func initializeTestService(optionAppliers ...testOption) *testQueryService { optApplier(&tqs, &options) } - tqs.queryService = NewQueryService(readStorage, dependencyStorage, options) + tqs.queryService = NewQueryService(traceReader, dependencyStorage, options) return &tqs } diff --git a/cmd/query/app/server_test.go b/cmd/query/app/server_test.go index 1bbc9993724..f26cd78b5fa 100644 --- a/cmd/query/app/server_test.go +++ b/cmd/query/app/server_test.go @@ -46,6 +46,7 @@ import ( "github.com/jaegertracing/jaeger/proto-gen/api_v2" depsmocks "github.com/jaegertracing/jaeger/storage/dependencystore/mocks" spanstoremocks "github.com/jaegertracing/jaeger/storage/spanstore/mocks" + "github.com/jaegertracing/jaeger/storage_v2/factoryadapter" ) var testCertKeyLocation = "../../../pkg/config/tlscfg/testdata" @@ -337,10 +338,11 @@ type fakeQueryService struct { func makeQuerySvc() *fakeQueryService { spanReader := &spanstoremocks.Reader{} + traceReader := factoryadapter.NewTraceReader(spanReader) dependencyReader := &depsmocks.Reader{} expectedServices := []string{"test"} spanReader.On("GetServices", mock.AnythingOfType("*context.valueCtx")).Return(expectedServices, nil) - qs := querysvc.NewQueryService(spanReader, dependencyReader, querysvc.QueryServiceOptions{}) + qs := querysvc.NewQueryService(traceReader, dependencyReader, querysvc.QueryServiceOptions{}) return &fakeQueryService{ qs: qs, spanReader: spanReader, diff --git a/cmd/query/app/token_propagation_test.go b/cmd/query/app/token_propagation_test.go index ea6e4535b79..d7b7c537707 100644 --- a/cmd/query/app/token_propagation_test.go +++ b/cmd/query/app/token_propagation_test.go @@ -32,6 +32,7 @@ import ( "github.com/jaegertracing/jaeger/pkg/tenancy" "github.com/jaegertracing/jaeger/plugin/storage/es" "github.com/jaegertracing/jaeger/ports" + "github.com/jaegertracing/jaeger/storage_v2/factoryadapter" ) const ( @@ -86,8 +87,9 @@ func runQueryService(t *testing.T, esURL string) *Server { spanReader, err := f.CreateSpanReader() require.NoError(t, err) + traceReader := factoryadapter.NewTraceReader(spanReader) - querySvc := querysvc.NewQueryService(spanReader, nil, querysvc.QueryServiceOptions{}) + querySvc := querysvc.NewQueryService(traceReader, nil, querysvc.QueryServiceOptions{}) telset := telemetery.Setting{ Logger: flagsSvc.Logger, TracerProvider: jtracer.NoOp().OTEL, From dcf635791f8e73d8ad4eeedc1c06f407276f59d4 Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Sun, 17 Nov 2024 08:06:28 -0500 Subject: [PATCH 05/17] Implement Create Trace Reader For V2 Factory Signed-off-by: Mahad Zaryab --- storage_v2/factoryadapter/factory.go | 8 ++++++-- storage_v2/factoryadapter/factory_test.go | 21 ++++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/storage_v2/factoryadapter/factory.go b/storage_v2/factoryadapter/factory.go index 57b2cece3ca..7a03114e9e5 100644 --- a/storage_v2/factoryadapter/factory.go +++ b/storage_v2/factoryadapter/factory.go @@ -35,8 +35,12 @@ func (f *Factory) Close(_ context.Context) error { } // CreateTraceReader implements spanstore.Factory. -func (*Factory) CreateTraceReader() (spanstore.Reader, error) { - panic("not implemented") +func (f *Factory) CreateTraceReader() (spanstore.Reader, error) { + spanReader, err := f.ss.CreateSpanReader() + if err != nil { + return nil, err + } + return NewTraceReader(spanReader), nil } // CreateTraceWriter implements spanstore.Factory. diff --git a/storage_v2/factoryadapter/factory_test.go b/storage_v2/factoryadapter/factory_test.go index 1cfcbb0f17b..a8e2819ce0f 100644 --- a/storage_v2/factoryadapter/factory_test.go +++ b/storage_v2/factoryadapter/factory_test.go @@ -37,14 +37,21 @@ func TestAdapterClose(t *testing.T) { } func TestAdapterCreateTraceReader(t *testing.T) { - defer func() { - if r := recover(); r == nil { - t.Errorf("create trace reader did not panic") - } - }() + f1 := new(factoryMocks.Factory) + f1.On("CreateSpanReader").Return(new(spanstoreMocks.Reader), nil) - f := &Factory{} - f.CreateTraceReader() + f := NewFactory(f1) + _, err := f.CreateTraceReader() + require.NoError(t, err) +} + +func TestAdapterCreateTraceReaderError(t *testing.T) { + f1 := new(factoryMocks.Factory) + f1.On("CreateSpanReader").Return(nil, errors.New("mock error")) + + f := NewFactory(f1) + _, err := f.CreateTraceReader() + require.ErrorContains(t, err, "mock error") } func TestAdapterCreateTraceWriterError(t *testing.T) { From 1175e6e7221cdbce962f1a060b720ab105a17c47 Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Sun, 17 Nov 2024 08:06:40 -0500 Subject: [PATCH 06/17] Initialize V2 Factories And Use CreateTraceReader Signed-off-by: Mahad Zaryab --- cmd/all-in-one/main.go | 13 ++++++------- .../internal/extension/jaegerquery/server.go | 18 ++++++++++-------- cmd/query/main.go | 9 ++++----- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/cmd/all-in-one/main.go b/cmd/all-in-one/main.go index 23aa86fe68d..d2b97337c7f 100644 --- a/cmd/all-in-one/main.go +++ b/cmd/all-in-one/main.go @@ -42,9 +42,8 @@ import ( "github.com/jaegertracing/jaeger/ports" "github.com/jaegertracing/jaeger/storage/dependencystore" metricsstoreMetrics "github.com/jaegertracing/jaeger/storage/metricsstore/metrics" - "github.com/jaegertracing/jaeger/storage/spanstore" - storageMetrics "github.com/jaegertracing/jaeger/storage/spanstore/metrics" "github.com/jaegertracing/jaeger/storage_v2/factoryadapter" + "github.com/jaegertracing/jaeger/storage_v2/spanstore" ) // all-in-one/main is a standalone full-stack jaeger backend, backed by a memory store @@ -60,6 +59,7 @@ func main() { if err != nil { log.Fatalf("Cannot initialize storage factory: %v", err) } + v2Factory := factoryadapter.NewFactory(storageFactory) samplingStrategyFactoryConfig, err := ss.FactoryConfigFromEnv() if err != nil { log.Fatalf("Cannot initialize sampling strategy factory config: %v", err) @@ -101,7 +101,7 @@ by default uses only in-memory database.`, logger.Fatal("Failed to init storage factory", zap.Error(err)) } - spanReader, err := storageFactory.CreateSpanReader() + traceReader, err := v2Factory.CreateTraceReader() if err != nil { logger.Fatal("Failed to create span reader", zap.Error(err)) } @@ -172,7 +172,7 @@ by default uses only in-memory database.`, // query querySrv := startQuery( svc, qOpts, qOpts.BuildQueryServiceOptions(storageFactory, logger), - spanReader, dependencyReader, metricsQueryService, + traceReader, dependencyReader, metricsQueryService, tm, telset, ) @@ -219,14 +219,13 @@ func startQuery( svc *flags.Service, qOpts *queryApp.QueryOptions, queryOpts *querysvc.QueryServiceOptions, - spanReader spanstore.Reader, + traceReader spanstore.Reader, depReader dependencystore.Reader, metricsQueryService querysvc.MetricsQueryService, tm *tenancy.Manager, telset telemetery.Setting, ) *queryApp.Server { - spanReader = storageMetrics.NewReadMetricsDecorator(spanReader, telset.Metrics) - traceReader := factoryadapter.NewTraceReader(spanReader) + // TODO: decorate trace reader with metrics qs := querysvc.NewQueryService(traceReader, depReader, *queryOpts) server, err := queryApp.NewServer(context.Background(), qs, metricsQueryService, qOpts, tm, telset) diff --git a/cmd/jaeger/internal/extension/jaegerquery/server.go b/cmd/jaeger/internal/extension/jaegerquery/server.go index 510e90a0cab..c7e3669145d 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server.go @@ -23,8 +23,6 @@ import ( "github.com/jaegertracing/jaeger/pkg/tenancy" "github.com/jaegertracing/jaeger/plugin/metrics/disabled" "github.com/jaegertracing/jaeger/storage/metricsstore" - storageMetrics "github.com/jaegertracing/jaeger/storage/spanstore/metrics" - "github.com/jaegertracing/jaeger/storage_v2/factoryadapter" ) var ( @@ -56,20 +54,24 @@ func (s *server) Start(ctx context.Context, host component.Host) error { mf := otelmetrics.NewFactory(s.telset.MeterProvider) baseFactory := mf.Namespace(metrics.NSOptions{Name: "jaeger"}) queryMetricsFactory := baseFactory.Namespace(metrics.NSOptions{Name: "query"}) - f, err := jaegerstorage.GetStorageFactory(s.config.Storage.TracesPrimary, host) + v1Factory, err := jaegerstorage.GetStorageFactory(s.config.Storage.TracesPrimary, host) if err != nil { - return fmt.Errorf("cannot find primary storage %s: %w", s.config.Storage.TracesPrimary, err) + return fmt.Errorf("cannot find primary storage from v1 factory %s: %w", s.config.Storage.TracesPrimary, err) + } + v2Factory, err := jaegerstorage.GetStorageFactoryV2(s.config.Storage.TracesPrimary, host) + if err != nil { + return fmt.Errorf("cannot find primary storage from v2 factory %s: %w", s.config.Storage.TracesPrimary, err) } - spanReader, err := f.CreateSpanReader() + v1Factory.CreateSpanReader() + traceReader, err := v2Factory.CreateTraceReader() if err != nil { return fmt.Errorf("cannot create span reader: %w", err) } - spanReader = storageMetrics.NewReadMetricsDecorator(spanReader, queryMetricsFactory) - traceReader := factoryadapter.NewTraceReader(spanReader) + // TODO: decorate trace reader with metrics - depReader, err := f.CreateDependencyReader() + depReader, err := v1Factory.CreateDependencyReader() if err != nil { return fmt.Errorf("cannot create dependencies reader: %w", err) } diff --git a/cmd/query/main.go b/cmd/query/main.go index 1ab4c5f113b..9029ce7b575 100644 --- a/cmd/query/main.go +++ b/cmd/query/main.go @@ -36,7 +36,6 @@ import ( "github.com/jaegertracing/jaeger/plugin/storage" "github.com/jaegertracing/jaeger/ports" metricsstoreMetrics "github.com/jaegertracing/jaeger/storage/metricsstore/metrics" - spanstoreMetrics "github.com/jaegertracing/jaeger/storage/spanstore/metrics" "github.com/jaegertracing/jaeger/storage_v2/factoryadapter" ) @@ -47,6 +46,7 @@ func main() { if err != nil { log.Fatalf("Cannot initialize storage factory: %v", err) } + v2Factory := factoryadapter.NewFactory(storageFactory) fc := metricsPlugin.FactoryConfigFromEnv() metricsReaderFactory, err := metricsPlugin.NewFactory(fc) @@ -88,12 +88,11 @@ func main() { if err := storageFactory.Initialize(baseFactory, logger); err != nil { logger.Fatal("Failed to init storage factory", zap.Error(err)) } - spanReader, err := storageFactory.CreateSpanReader() + traceReader, err := v2Factory.CreateTraceReader() if err != nil { - logger.Fatal("Failed to create span reader", zap.Error(err)) + logger.Fatal("Failed to create trace reader", zap.Error(err)) } - spanReader = spanstoreMetrics.NewReadMetricsDecorator(spanReader, metricsFactory) - traceReader := factoryadapter.NewTraceReader(spanReader) + // TODO: decorate trace reader with metrics dependencyReader, err := storageFactory.CreateDependencyReader() if err != nil { logger.Fatal("Failed to create dependency reader", zap.Error(err)) From 16830075597e97db0bedc0e159d20df416cbd3c0 Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Sun, 17 Nov 2024 08:08:59 -0500 Subject: [PATCH 07/17] Address Feedback For Error Variable Signed-off-by: Mahad Zaryab --- storage_v2/factoryadapter/reader.go | 4 ++-- storage_v2/factoryadapter/reader_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/storage_v2/factoryadapter/reader.go b/storage_v2/factoryadapter/reader.go index 6074966874d..b4dc4a6ab1a 100644 --- a/storage_v2/factoryadapter/reader.go +++ b/storage_v2/factoryadapter/reader.go @@ -14,7 +14,7 @@ import ( "github.com/jaegertracing/jaeger/storage_v2/spanstore" ) -var ErrV1ReaderNotAvailable = errors.New("v1 reader is not available") +var errV1ReaderNotAvailable = errors.New("spanstore.Reader is not a wrapper around v1 reader") type TraceReader struct { spanReader spanstore_v1.Reader @@ -24,7 +24,7 @@ func GetV1Reader(reader spanstore.Reader) (spanstore_v1.Reader, error) { if tr, ok := reader.(*TraceReader); ok { return tr.spanReader, nil } - return nil, ErrV1ReaderNotAvailable + return nil, errV1ReaderNotAvailable } func NewTraceReader(spanReader spanstore_v1.Reader) *TraceReader { diff --git a/storage_v2/factoryadapter/reader_test.go b/storage_v2/factoryadapter/reader_test.go index fb5155b524b..dd671d8f5ce 100644 --- a/storage_v2/factoryadapter/reader_test.go +++ b/storage_v2/factoryadapter/reader_test.go @@ -50,7 +50,7 @@ func (*fakeReader) FindTraceIDs(_ context.Context, _ spanstore.TraceQueryParamet func TestGetV1Reader_Error(t *testing.T) { fr := &fakeReader{} _, err := GetV1Reader(fr) - require.ErrorIs(t, err, ErrV1ReaderNotAvailable) + require.ErrorIs(t, err, errV1ReaderNotAvailable) } func TestTraceReader_GetTracePanics(t *testing.T) { From df9875ab8c6e787d833d9d9f11fab8b766f54a04 Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Sat, 30 Nov 2024 12:23:40 -0500 Subject: [PATCH 08/17] Fix Errors From Merge Commit Signed-off-by: Mahad Zaryab --- cmd/all-in-one/main.go | 7 ++----- .../internal/extension/jaegerquery/server.go | 16 ++++------------ .../extension/jaegerquery/server_test.go | 2 +- cmd/query/app/token_propagation_test.go | 2 +- cmd/query/main.go | 4 +--- 5 files changed, 9 insertions(+), 22 deletions(-) diff --git a/cmd/all-in-one/main.go b/cmd/all-in-one/main.go index e13d50ee961..fb84484233c 100644 --- a/cmd/all-in-one/main.go +++ b/cmd/all-in-one/main.go @@ -39,11 +39,9 @@ import ( "github.com/jaegertracing/jaeger/plugin/storage" "github.com/jaegertracing/jaeger/ports" "github.com/jaegertracing/jaeger/storage/dependencystore" + "github.com/jaegertracing/jaeger/storage/metricsstore/metricstoremetrics" "github.com/jaegertracing/jaeger/storage_v2/factoryadapter" "github.com/jaegertracing/jaeger/storage_v2/spanstore" - "github.com/jaegertracing/jaeger/storage/metricsstore/metricstoremetrics" - "github.com/jaegertracing/jaeger/storage/spanstore" - "github.com/jaegertracing/jaeger/storage/spanstore/spanstoremetrics" ) // all-in-one/main is a standalone full-stack jaeger backend, backed by a memory store @@ -226,8 +224,7 @@ func startQuery( tm *tenancy.Manager, telset telemetry.Settings, ) *queryApp.Server { - spanReader = spanstoremetrics.NewReaderDecorator(spanReader, telset.Metrics) - qs := querysvc.NewQueryService(spanReader, depReader, *queryOpts) + qs := querysvc.NewQueryService(traceReader, depReader, *queryOpts) server, err := queryApp.NewServer(context.Background(), qs, metricsQueryService, qOpts, tm, telset) if err != nil { diff --git a/cmd/jaeger/internal/extension/jaegerquery/server.go b/cmd/jaeger/internal/extension/jaegerquery/server.go index e99819e0f2d..30eeab616b4 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server.go @@ -23,7 +23,6 @@ import ( "github.com/jaegertracing/jaeger/plugin/metrics/disabled" "github.com/jaegertracing/jaeger/storage/metricsstore" "github.com/jaegertracing/jaeger/storage/metricsstore/metricstoremetrics" - "github.com/jaegertracing/jaeger/storage/spanstore/spanstoremetrics" ) var ( @@ -52,10 +51,6 @@ func (*server) Dependencies() []component.ID { } func (s *server) Start(ctx context.Context, host component.Host) error { - mf := otelmetrics.NewFactory(s.telset.MeterProvider) - baseFactory := mf.Namespace(metrics.NSOptions{Name: "jaeger"}) - queryMetricsFactory := baseFactory.Namespace(metrics.NSOptions{Name: "query"}) - v1Factory, err := jaegerstorage.GetStorageFactory(s.config.Storage.TracesPrimary, host) // TODO OTel-collector does not initialize the tracer currently // https://github.com/open-telemetry/opentelemetry-collector/issues/7532 //nolint @@ -79,23 +74,20 @@ func (s *server) Start(ctx context.Context, host component.Host) error { Namespace(metrics.NSOptions{Name: "jaeger"}). Namespace(metrics.NSOptions{Name: "query"}) - f, err := jaegerstorage.GetStorageFactory(s.config.Storage.TracesPrimary, host) + v1Factory, err := jaegerstorage.GetStorageFactory(s.config.Storage.TracesPrimary, host) if err != nil { return fmt.Errorf("cannot find primary storage from v1 factory %s: %w", s.config.Storage.TracesPrimary, err) } - v2Factory, err := jaegerstorage.GetStorageFactoryV2(s.config.Storage.TracesPrimary, host) + f, err := jaegerstorage.GetStorageFactoryV2(s.config.Storage.TracesPrimary, host) if err != nil { return fmt.Errorf("cannot find primary storage from v2 factory %s: %w", s.config.Storage.TracesPrimary, err) } - v1Factory.CreateSpanReader() - traceReader, err := v2Factory.CreateTraceReader() + traceReader, err := f.CreateTraceReader() if err != nil { - return fmt.Errorf("cannot create span reader: %w", err) + return fmt.Errorf("cannot create trace reader: %w", err) } - spanReader = spanstoremetrics.NewReaderDecorator(spanReader, telset.Metrics) - depReader, err := v1Factory.CreateDependencyReader() if err != nil { return fmt.Errorf("cannot create dependencies reader: %w", err) diff --git a/cmd/jaeger/internal/extension/jaegerquery/server_test.go b/cmd/jaeger/internal/extension/jaegerquery/server_test.go index 54b3733f24c..eaf436ba8d1 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server_test.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server_test.go @@ -158,7 +158,7 @@ func TestServerStart(t *testing.T) { TracesPrimary: "need-span-reader-error", }, }, - expectedErr: "cannot create span reader", + expectedErr: "cannot create trace reader", }, { name: "dependency error", diff --git a/cmd/query/app/token_propagation_test.go b/cmd/query/app/token_propagation_test.go index 5ce7ae4ac14..0a48802f37b 100644 --- a/cmd/query/app/token_propagation_test.go +++ b/cmd/query/app/token_propagation_test.go @@ -88,7 +88,7 @@ func runQueryService(t *testing.T, esURL string) *Server { require.NoError(t, err) traceReader := factoryadapter.NewTraceReader(spanReader) - querySvc := querysvc.NewQueryService(spanReader, nil, querysvc.QueryServiceOptions{}) + querySvc := querysvc.NewQueryService(traceReader, nil, querysvc.QueryServiceOptions{}) server, err := NewServer(context.Background(), querySvc, nil, &QueryOptions{ BearerTokenPropagation: true, diff --git a/cmd/query/main.go b/cmd/query/main.go index 82b571500ec..0e7bd303e35 100644 --- a/cmd/query/main.go +++ b/cmd/query/main.go @@ -32,9 +32,8 @@ import ( metricsPlugin "github.com/jaegertracing/jaeger/plugin/metrics" "github.com/jaegertracing/jaeger/plugin/storage" "github.com/jaegertracing/jaeger/ports" - "github.com/jaegertracing/jaeger/storage_v2/factoryadapter" "github.com/jaegertracing/jaeger/storage/metricsstore/metricstoremetrics" - "github.com/jaegertracing/jaeger/storage/spanstore/spanstoremetrics" + "github.com/jaegertracing/jaeger/storage_v2/factoryadapter" ) func main() { @@ -97,7 +96,6 @@ func main() { if err != nil { logger.Fatal("Failed to create trace reader", zap.Error(err)) } - spanReader = spanstoremetrics.NewReaderDecorator(spanReader, metricsFactory) dependencyReader, err := storageFactory.CreateDependencyReader() if err != nil { logger.Fatal("Failed to create dependency reader", zap.Error(err)) From 51bffb4e6d2ff951b5494e41999d037de1174c41 Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Sat, 30 Nov 2024 12:31:23 -0500 Subject: [PATCH 09/17] Move V2 Factory Initialization After V1 Signed-off-by: Mahad Zaryab --- cmd/all-in-one/main.go | 2 +- cmd/query/main.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/all-in-one/main.go b/cmd/all-in-one/main.go index fb84484233c..70a8d9a3ec5 100644 --- a/cmd/all-in-one/main.go +++ b/cmd/all-in-one/main.go @@ -57,7 +57,6 @@ func main() { if err != nil { log.Fatalf("Cannot initialize storage factory: %v", err) } - v2Factory := factoryadapter.NewFactory(storageFactory) samplingStrategyFactoryConfig, err := ss.FactoryConfigFromEnv() if err != nil { log.Fatalf("Cannot initialize sampling strategy factory config: %v", err) @@ -107,6 +106,7 @@ by default uses only in-memory database.`, logger.Fatal("Failed to init storage factory", zap.Error(err)) } + v2Factory := factoryadapter.NewFactory(storageFactory) traceReader, err := v2Factory.CreateTraceReader() if err != nil { logger.Fatal("Failed to create span reader", zap.Error(err)) diff --git a/cmd/query/main.go b/cmd/query/main.go index 0e7bd303e35..814d571f91a 100644 --- a/cmd/query/main.go +++ b/cmd/query/main.go @@ -43,7 +43,6 @@ func main() { if err != nil { log.Fatalf("Cannot initialize storage factory: %v", err) } - v2Factory := factoryadapter.NewFactory(storageFactory) fc := metricsPlugin.FactoryConfigFromEnv() metricsReaderFactory, err := metricsPlugin.NewFactory(fc) @@ -92,6 +91,8 @@ func main() { if err := storageFactory.Initialize(baseTelset.Metrics, baseTelset.Logger); err != nil { logger.Fatal("Failed to init storage factory", zap.Error(err)) } + + v2Factory := factoryadapter.NewFactory(storageFactory) traceReader, err := v2Factory.CreateTraceReader() if err != nil { logger.Fatal("Failed to create trace reader", zap.Error(err)) From 226e3cafb42ca2a9e7b08b278f5a939ec5f26ca5 Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Sat, 30 Nov 2024 12:47:40 -0500 Subject: [PATCH 10/17] Add Missing Tests In Query Service Signed-off-by: Mahad Zaryab --- cmd/query/app/querysvc/query_service_test.go | 71 ++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/cmd/query/app/querysvc/query_service_test.go b/cmd/query/app/querysvc/query_service_test.go index 9cf6cea9128..85b82913f3d 100644 --- a/cmd/query/app/querysvc/query_service_test.go +++ b/cmd/query/app/querysvc/query_service_test.go @@ -12,6 +12,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/pdata/pcommon" + "go.opentelemetry.io/collector/pdata/ptrace" "go.uber.org/zap" "github.com/jaegertracing/jaeger/model" @@ -24,6 +26,7 @@ import ( "github.com/jaegertracing/jaeger/storage/spanstore" spanstoremocks "github.com/jaegertracing/jaeger/storage/spanstore/mocks" "github.com/jaegertracing/jaeger/storage_v2/factoryadapter" + v2spanstore "github.com/jaegertracing/jaeger/storage_v2/spanstore" ) const millisToNanosMultiplier = int64(time.Millisecond / time.Nanosecond) @@ -106,6 +109,28 @@ func initializeTestService(optionAppliers ...testOption) *testQueryService { return &tqs } +type fakeReader struct{} + +func (*fakeReader) GetTrace(_ context.Context, _ pcommon.TraceID) (ptrace.Traces, error) { + panic("not implemented") +} + +func (*fakeReader) GetServices(_ context.Context) ([]string, error) { + panic("not implemented") +} + +func (*fakeReader) GetOperations(_ context.Context, _ v2spanstore.OperationQueryParameters) ([]v2spanstore.Operation, error) { + panic("not implemented") +} + +func (*fakeReader) FindTraces(_ context.Context, _ v2spanstore.TraceQueryParameters) ([]ptrace.Traces, error) { + panic("not implemented") +} + +func (*fakeReader) FindTraceIDs(_ context.Context, _ v2spanstore.TraceQueryParameters) ([]pcommon.TraceID, error) { + panic("not implemented") +} + // Test QueryService.GetTrace() func TestGetTraceSuccess(t *testing.T) { tqs := initializeTestService() @@ -131,6 +156,15 @@ func TestGetTraceNotFound(t *testing.T) { assert.Equal(t, err, spanstore.ErrTraceNotFound) } +func TestGetTrace_V1ReaderNotFound(t *testing.T) { + fr := &fakeReader{} + qs := QueryService{ + traceReader: fr, + } + _, err := qs.GetTrace(context.Background(), mockTraceID) + require.Error(t, err) +} + // Test QueryService.GetTrace() with ArchiveSpanReader func TestGetTraceFromArchiveStorage(t *testing.T) { tqs := initializeTestService(withArchiveSpanReader()) @@ -159,6 +193,15 @@ func TestGetServices(t *testing.T) { assert.Equal(t, expectedServices, actualServices) } +func TestGetServices_V1ReaderNotFound(t *testing.T) { + fr := &fakeReader{} + qs := QueryService{ + traceReader: fr, + } + _, err := qs.GetServices(context.Background()) + require.Error(t, err) +} + // Test QueryService.GetOperations() for success. func TestGetOperations(t *testing.T) { tqs := initializeTestService() @@ -177,6 +220,16 @@ func TestGetOperations(t *testing.T) { assert.Equal(t, expectedOperations, actualOperations) } +func TestGetOperations_V1ReaderNotFound(t *testing.T) { + fr := &fakeReader{} + qs := QueryService{ + traceReader: fr, + } + operationQuery := spanstore.OperationQueryParameters{ServiceName: "abc/trifle"} + _, err := qs.GetOperations(context.Background(), operationQuery) + require.Error(t, err) +} + // Test QueryService.FindTraces() for success. func TestFindTraces(t *testing.T) { tqs := initializeTestService() @@ -198,6 +251,24 @@ func TestFindTraces(t *testing.T) { assert.Len(t, traces, 1) } +func TestFindTraces_V1ReaderNotFound(t *testing.T) { + fr := &fakeReader{} + qs := QueryService{ + traceReader: fr, + } + duration, err := time.ParseDuration("20ms") + require.NoError(t, err) + params := &spanstore.TraceQueryParameters{ + ServiceName: "service", + OperationName: "operation", + StartTimeMax: time.Now(), + DurationMin: duration, + NumTraces: 200, + } + _, err = qs.FindTraces(context.Background(), params) + require.Error(t, err) +} + // Test QueryService.ArchiveTrace() with no ArchiveSpanWriter. func TestArchiveTraceNoOptions(t *testing.T) { tqs := initializeTestService() From d76eeba91f3ae0c9213166088b1cd8121866d239 Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Mon, 2 Dec 2024 10:02:51 -0500 Subject: [PATCH 11/17] Remove Unused Imports Signed-off-by: Mahad Zaryab --- cmd/all-in-one/main.go | 1 - cmd/query/main.go | 1 - 2 files changed, 2 deletions(-) diff --git a/cmd/all-in-one/main.go b/cmd/all-in-one/main.go index fff2da22b70..da09688d677 100644 --- a/cmd/all-in-one/main.go +++ b/cmd/all-in-one/main.go @@ -39,7 +39,6 @@ import ( "github.com/jaegertracing/jaeger/plugin/storage" "github.com/jaegertracing/jaeger/ports" "github.com/jaegertracing/jaeger/storage/dependencystore" - "github.com/jaegertracing/jaeger/storage/metricstore/metricstoremetrics" "github.com/jaegertracing/jaeger/storage_v2/factoryadapter" "github.com/jaegertracing/jaeger/storage_v2/spanstore" ) diff --git a/cmd/query/main.go b/cmd/query/main.go index 6f80173bf58..5d32b5db10f 100644 --- a/cmd/query/main.go +++ b/cmd/query/main.go @@ -32,7 +32,6 @@ import ( metricsPlugin "github.com/jaegertracing/jaeger/plugin/metricstore" "github.com/jaegertracing/jaeger/plugin/storage" "github.com/jaegertracing/jaeger/ports" - "github.com/jaegertracing/jaeger/storage/metricstore/metricstoremetrics" "github.com/jaegertracing/jaeger/storage_v2/factoryadapter" ) From 5cad28e3c093affb1816a37716f751981c8d0780 Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Mon, 2 Dec 2024 15:17:54 -0500 Subject: [PATCH 12/17] Fix Package Renaming Signed-off-by: Mahad Zaryab --- cmd/all-in-one/main.go | 4 ++-- cmd/query/app/querysvc/query_service.go | 18 +++++++++--------- cmd/query/app/querysvc/query_service_test.go | 8 ++++---- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/cmd/all-in-one/main.go b/cmd/all-in-one/main.go index da09688d677..9b7b89dfba1 100644 --- a/cmd/all-in-one/main.go +++ b/cmd/all-in-one/main.go @@ -40,7 +40,7 @@ import ( "github.com/jaegertracing/jaeger/ports" "github.com/jaegertracing/jaeger/storage/dependencystore" "github.com/jaegertracing/jaeger/storage_v2/factoryadapter" - "github.com/jaegertracing/jaeger/storage_v2/spanstore" + "github.com/jaegertracing/jaeger/storage_v2/tracestore" ) // all-in-one/main is a standalone full-stack jaeger backend, backed by a memory store @@ -217,7 +217,7 @@ func startQuery( svc *flags.Service, qOpts *queryApp.QueryOptions, queryOpts *querysvc.QueryServiceOptions, - traceReader spanstore.Reader, + traceReader tracestore.Reader, depReader dependencystore.Reader, metricsQueryService querysvc.MetricsQueryService, tm *tenancy.Manager, diff --git a/cmd/query/app/querysvc/query_service.go b/cmd/query/app/querysvc/query_service.go index bd9d19402ea..f627c3c8344 100644 --- a/cmd/query/app/querysvc/query_service.go +++ b/cmd/query/app/querysvc/query_service.go @@ -14,9 +14,9 @@ import ( "github.com/jaegertracing/jaeger/model/adjuster" "github.com/jaegertracing/jaeger/storage" "github.com/jaegertracing/jaeger/storage/dependencystore" - spanstore_v1 "github.com/jaegertracing/jaeger/storage/spanstore" + "github.com/jaegertracing/jaeger/storage/spanstore" "github.com/jaegertracing/jaeger/storage_v2/factoryadapter" - "github.com/jaegertracing/jaeger/storage_v2/spanstore" + "github.com/jaegertracing/jaeger/storage_v2/tracestore" ) var errNoArchiveSpanStorage = errors.New("archive span storage was not configured") @@ -27,8 +27,8 @@ const ( // QueryServiceOptions has optional members of QueryService type QueryServiceOptions struct { - ArchiveSpanReader spanstore_v1.Reader - ArchiveSpanWriter spanstore_v1.Writer + ArchiveSpanReader spanstore.Reader + ArchiveSpanWriter spanstore.Writer Adjuster adjuster.Adjuster } @@ -42,13 +42,13 @@ type StorageCapabilities struct { // QueryService contains span utils required by the query-service. type QueryService struct { - traceReader spanstore.Reader + traceReader tracestore.Reader dependencyReader dependencystore.Reader options QueryServiceOptions } // NewQueryService returns a new QueryService. -func NewQueryService(traceReader spanstore.Reader, dependencyReader dependencystore.Reader, options QueryServiceOptions) *QueryService { +func NewQueryService(traceReader tracestore.Reader, dependencyReader dependencystore.Reader, options QueryServiceOptions) *QueryService { qsvc := &QueryService{ traceReader: traceReader, dependencyReader: dependencyReader, @@ -89,8 +89,8 @@ func (qs QueryService) GetServices(ctx context.Context) ([]string, error) { // GetOperations is the queryService implementation of spanstore.Reader.GetOperations func (qs QueryService) GetOperations( ctx context.Context, - query spanstore_v1.OperationQueryParameters, -) ([]spanstore_v1.Operation, error) { + query spanstore.OperationQueryParameters, +) ([]spanstore.Operation, error) { spanReader, err := factoryadapter.GetV1Reader(qs.traceReader) if err != nil { return nil, err @@ -99,7 +99,7 @@ func (qs QueryService) GetOperations( } // FindTraces is the queryService implementation of spanstore.Reader.FindTraces -func (qs QueryService) FindTraces(ctx context.Context, query *spanstore_v1.TraceQueryParameters) ([]*model.Trace, error) { +func (qs QueryService) FindTraces(ctx context.Context, query *spanstore.TraceQueryParameters) ([]*model.Trace, error) { spanReader, err := factoryadapter.GetV1Reader(qs.traceReader) if err != nil { return nil, err diff --git a/cmd/query/app/querysvc/query_service_test.go b/cmd/query/app/querysvc/query_service_test.go index 85b82913f3d..3a9f906d2b5 100644 --- a/cmd/query/app/querysvc/query_service_test.go +++ b/cmd/query/app/querysvc/query_service_test.go @@ -26,7 +26,7 @@ import ( "github.com/jaegertracing/jaeger/storage/spanstore" spanstoremocks "github.com/jaegertracing/jaeger/storage/spanstore/mocks" "github.com/jaegertracing/jaeger/storage_v2/factoryadapter" - v2spanstore "github.com/jaegertracing/jaeger/storage_v2/spanstore" + "github.com/jaegertracing/jaeger/storage_v2/tracestore" ) const millisToNanosMultiplier = int64(time.Millisecond / time.Nanosecond) @@ -119,15 +119,15 @@ func (*fakeReader) GetServices(_ context.Context) ([]string, error) { panic("not implemented") } -func (*fakeReader) GetOperations(_ context.Context, _ v2spanstore.OperationQueryParameters) ([]v2spanstore.Operation, error) { +func (*fakeReader) GetOperations(_ context.Context, _ tracestore.OperationQueryParameters) ([]tracestore.Operation, error) { panic("not implemented") } -func (*fakeReader) FindTraces(_ context.Context, _ v2spanstore.TraceQueryParameters) ([]ptrace.Traces, error) { +func (*fakeReader) FindTraces(_ context.Context, _ tracestore.TraceQueryParameters) ([]ptrace.Traces, error) { panic("not implemented") } -func (*fakeReader) FindTraceIDs(_ context.Context, _ v2spanstore.TraceQueryParameters) ([]pcommon.TraceID, error) { +func (*fakeReader) FindTraceIDs(_ context.Context, _ tracestore.TraceQueryParameters) ([]pcommon.TraceID, error) { panic("not implemented") } From 2bf30b6929db3c28c83acff6795152b8eef70eba Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Mon, 2 Dec 2024 15:21:34 -0500 Subject: [PATCH 13/17] Regenerate Mocks Signed-off-by: Mahad Zaryab --- .mockery.yaml | 2 +- storage/mocks/MetricStoreFactory.go | 82 +++++++++++ storage_v2/tracestore/mocks/Factory.go | 130 +++++++++++++++++ storage_v2/tracestore/mocks/Reader.go | 186 +++++++++++++++++++++++++ storage_v2/tracestore/mocks/Writer.go | 52 +++++++ 5 files changed, 451 insertions(+), 1 deletion(-) create mode 100644 storage/mocks/MetricStoreFactory.go create mode 100644 storage_v2/tracestore/mocks/Factory.go create mode 100644 storage_v2/tracestore/mocks/Reader.go create mode 100644 storage_v2/tracestore/mocks/Writer.go diff --git a/.mockery.yaml b/.mockery.yaml index de981aa312e..a0f879a5a35 100644 --- a/.mockery.yaml +++ b/.mockery.yaml @@ -73,6 +73,6 @@ packages: github.com/jaegertracing/jaeger/storage/spanstore: config: all: true - github.com/jaegertracing/jaeger/storage_v2/spanstore: + github.com/jaegertracing/jaeger/storage_v2/tracestore: config: all: true diff --git a/storage/mocks/MetricStoreFactory.go b/storage/mocks/MetricStoreFactory.go new file mode 100644 index 00000000000..1302a76e928 --- /dev/null +++ b/storage/mocks/MetricStoreFactory.go @@ -0,0 +1,82 @@ +// Copyright (c) The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 +// +// Run 'make generate-mocks' to regenerate. + +// Code generated by mockery. DO NOT EDIT. + +package mocks + +import ( + metricstore "github.com/jaegertracing/jaeger/storage/metricstore" + mock "github.com/stretchr/testify/mock" + + telemetry "github.com/jaegertracing/jaeger/pkg/telemetry" +) + +// MetricStoreFactory is an autogenerated mock type for the MetricStoreFactory type +type MetricStoreFactory struct { + mock.Mock +} + +// CreateMetricsReader provides a mock function with given fields: +func (_m *MetricStoreFactory) CreateMetricsReader() (metricstore.Reader, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for CreateMetricsReader") + } + + var r0 metricstore.Reader + var r1 error + if rf, ok := ret.Get(0).(func() (metricstore.Reader, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() metricstore.Reader); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(metricstore.Reader) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Initialize provides a mock function with given fields: telset +func (_m *MetricStoreFactory) Initialize(telset telemetry.Settings) error { + ret := _m.Called(telset) + + if len(ret) == 0 { + panic("no return value specified for Initialize") + } + + var r0 error + if rf, ok := ret.Get(0).(func(telemetry.Settings) error); ok { + r0 = rf(telset) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// NewMetricStoreFactory creates a new instance of MetricStoreFactory. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMetricStoreFactory(t interface { + mock.TestingT + Cleanup(func()) +}) *MetricStoreFactory { + mock := &MetricStoreFactory{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/storage_v2/tracestore/mocks/Factory.go b/storage_v2/tracestore/mocks/Factory.go new file mode 100644 index 00000000000..ae439a0e49d --- /dev/null +++ b/storage_v2/tracestore/mocks/Factory.go @@ -0,0 +1,130 @@ +// Copyright (c) The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 +// +// Run 'make generate-mocks' to regenerate. + +// Code generated by mockery. DO NOT EDIT. + +package mocks + +import ( + context "context" + + tracestore "github.com/jaegertracing/jaeger/storage_v2/tracestore" + mock "github.com/stretchr/testify/mock" +) + +// Factory is an autogenerated mock type for the Factory type +type Factory struct { + mock.Mock +} + +// Close provides a mock function with given fields: ctx +func (_m *Factory) Close(ctx context.Context) error { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Close") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context) error); ok { + r0 = rf(ctx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// CreateTraceReader provides a mock function with given fields: +func (_m *Factory) CreateTraceReader() (tracestore.Reader, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for CreateTraceReader") + } + + var r0 tracestore.Reader + var r1 error + if rf, ok := ret.Get(0).(func() (tracestore.Reader, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() tracestore.Reader); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(tracestore.Reader) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CreateTraceWriter provides a mock function with given fields: +func (_m *Factory) CreateTraceWriter() (tracestore.Writer, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for CreateTraceWriter") + } + + var r0 tracestore.Writer + var r1 error + if rf, ok := ret.Get(0).(func() (tracestore.Writer, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() tracestore.Writer); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(tracestore.Writer) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Initialize provides a mock function with given fields: ctx +func (_m *Factory) Initialize(ctx context.Context) error { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Initialize") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context) error); ok { + r0 = rf(ctx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// NewFactory creates a new instance of Factory. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewFactory(t interface { + mock.TestingT + Cleanup(func()) +}) *Factory { + mock := &Factory{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/storage_v2/tracestore/mocks/Reader.go b/storage_v2/tracestore/mocks/Reader.go new file mode 100644 index 00000000000..a8ef4b103c0 --- /dev/null +++ b/storage_v2/tracestore/mocks/Reader.go @@ -0,0 +1,186 @@ +// Copyright (c) The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 +// +// Run 'make generate-mocks' to regenerate. + +// Code generated by mockery. DO NOT EDIT. + +package mocks + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + pcommon "go.opentelemetry.io/collector/pdata/pcommon" + + ptrace "go.opentelemetry.io/collector/pdata/ptrace" + + tracestore "github.com/jaegertracing/jaeger/storage_v2/tracestore" +) + +// Reader is an autogenerated mock type for the Reader type +type Reader struct { + mock.Mock +} + +// FindTraceIDs provides a mock function with given fields: ctx, query +func (_m *Reader) FindTraceIDs(ctx context.Context, query tracestore.TraceQueryParameters) ([]pcommon.TraceID, error) { + ret := _m.Called(ctx, query) + + if len(ret) == 0 { + panic("no return value specified for FindTraceIDs") + } + + var r0 []pcommon.TraceID + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, tracestore.TraceQueryParameters) ([]pcommon.TraceID, error)); ok { + return rf(ctx, query) + } + if rf, ok := ret.Get(0).(func(context.Context, tracestore.TraceQueryParameters) []pcommon.TraceID); ok { + r0 = rf(ctx, query) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]pcommon.TraceID) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, tracestore.TraceQueryParameters) error); ok { + r1 = rf(ctx, query) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// FindTraces provides a mock function with given fields: ctx, query +func (_m *Reader) FindTraces(ctx context.Context, query tracestore.TraceQueryParameters) ([]ptrace.Traces, error) { + ret := _m.Called(ctx, query) + + if len(ret) == 0 { + panic("no return value specified for FindTraces") + } + + var r0 []ptrace.Traces + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, tracestore.TraceQueryParameters) ([]ptrace.Traces, error)); ok { + return rf(ctx, query) + } + if rf, ok := ret.Get(0).(func(context.Context, tracestore.TraceQueryParameters) []ptrace.Traces); ok { + r0 = rf(ctx, query) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]ptrace.Traces) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, tracestore.TraceQueryParameters) error); ok { + r1 = rf(ctx, query) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetOperations provides a mock function with given fields: ctx, query +func (_m *Reader) GetOperations(ctx context.Context, query tracestore.OperationQueryParameters) ([]tracestore.Operation, error) { + ret := _m.Called(ctx, query) + + if len(ret) == 0 { + panic("no return value specified for GetOperations") + } + + var r0 []tracestore.Operation + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, tracestore.OperationQueryParameters) ([]tracestore.Operation, error)); ok { + return rf(ctx, query) + } + if rf, ok := ret.Get(0).(func(context.Context, tracestore.OperationQueryParameters) []tracestore.Operation); ok { + r0 = rf(ctx, query) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]tracestore.Operation) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, tracestore.OperationQueryParameters) error); ok { + r1 = rf(ctx, query) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetServices provides a mock function with given fields: ctx +func (_m *Reader) GetServices(ctx context.Context) ([]string, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for GetServices") + } + + var r0 []string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]string, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []string); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetTrace provides a mock function with given fields: ctx, traceID +func (_m *Reader) GetTrace(ctx context.Context, traceID pcommon.TraceID) (ptrace.Traces, error) { + ret := _m.Called(ctx, traceID) + + if len(ret) == 0 { + panic("no return value specified for GetTrace") + } + + var r0 ptrace.Traces + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, pcommon.TraceID) (ptrace.Traces, error)); ok { + return rf(ctx, traceID) + } + if rf, ok := ret.Get(0).(func(context.Context, pcommon.TraceID) ptrace.Traces); ok { + r0 = rf(ctx, traceID) + } else { + r0 = ret.Get(0).(ptrace.Traces) + } + + if rf, ok := ret.Get(1).(func(context.Context, pcommon.TraceID) error); ok { + r1 = rf(ctx, traceID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewReader creates a new instance of Reader. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewReader(t interface { + mock.TestingT + Cleanup(func()) +}) *Reader { + mock := &Reader{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/storage_v2/tracestore/mocks/Writer.go b/storage_v2/tracestore/mocks/Writer.go new file mode 100644 index 00000000000..a827057b26f --- /dev/null +++ b/storage_v2/tracestore/mocks/Writer.go @@ -0,0 +1,52 @@ +// Copyright (c) The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 +// +// Run 'make generate-mocks' to regenerate. + +// Code generated by mockery. DO NOT EDIT. + +package mocks + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + ptrace "go.opentelemetry.io/collector/pdata/ptrace" +) + +// Writer is an autogenerated mock type for the Writer type +type Writer struct { + mock.Mock +} + +// WriteTraces provides a mock function with given fields: ctx, td +func (_m *Writer) WriteTraces(ctx context.Context, td ptrace.Traces) error { + ret := _m.Called(ctx, td) + + if len(ret) == 0 { + panic("no return value specified for WriteTraces") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, ptrace.Traces) error); ok { + r0 = rf(ctx, td) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// NewWriter creates a new instance of Writer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewWriter(t interface { + mock.TestingT + Cleanup(func()) +}) *Writer { + mock := &Writer{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} From a0ccfe360b5911171c4aa08eb77e332602686594 Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Mon, 2 Dec 2024 15:24:55 -0500 Subject: [PATCH 14/17] Remove Old Mocks Signed-off-by: Mahad Zaryab --- storage_v2/spanstore/mocks/Factory.go | 130 ------------------ storage_v2/spanstore/mocks/Reader.go | 186 -------------------------- storage_v2/spanstore/mocks/Writer.go | 52 ------- 3 files changed, 368 deletions(-) delete mode 100644 storage_v2/spanstore/mocks/Factory.go delete mode 100644 storage_v2/spanstore/mocks/Reader.go delete mode 100644 storage_v2/spanstore/mocks/Writer.go diff --git a/storage_v2/spanstore/mocks/Factory.go b/storage_v2/spanstore/mocks/Factory.go deleted file mode 100644 index fbd140b5c92..00000000000 --- a/storage_v2/spanstore/mocks/Factory.go +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (c) The Jaeger Authors. -// SPDX-License-Identifier: Apache-2.0 -// -// Run 'make generate-mocks' to regenerate. - -// Code generated by mockery. DO NOT EDIT. - -package mocks - -import ( - context "context" - - spanstore "github.com/jaegertracing/jaeger/storage_v2/spanstore" - mock "github.com/stretchr/testify/mock" -) - -// Factory is an autogenerated mock type for the Factory type -type Factory struct { - mock.Mock -} - -// Close provides a mock function with given fields: ctx -func (_m *Factory) Close(ctx context.Context) error { - ret := _m.Called(ctx) - - if len(ret) == 0 { - panic("no return value specified for Close") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context) error); ok { - r0 = rf(ctx) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// CreateTraceReader provides a mock function with given fields: -func (_m *Factory) CreateTraceReader() (spanstore.Reader, error) { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for CreateTraceReader") - } - - var r0 spanstore.Reader - var r1 error - if rf, ok := ret.Get(0).(func() (spanstore.Reader, error)); ok { - return rf() - } - if rf, ok := ret.Get(0).(func() spanstore.Reader); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(spanstore.Reader) - } - } - - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// CreateTraceWriter provides a mock function with given fields: -func (_m *Factory) CreateTraceWriter() (spanstore.Writer, error) { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for CreateTraceWriter") - } - - var r0 spanstore.Writer - var r1 error - if rf, ok := ret.Get(0).(func() (spanstore.Writer, error)); ok { - return rf() - } - if rf, ok := ret.Get(0).(func() spanstore.Writer); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(spanstore.Writer) - } - } - - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// Initialize provides a mock function with given fields: ctx -func (_m *Factory) Initialize(ctx context.Context) error { - ret := _m.Called(ctx) - - if len(ret) == 0 { - panic("no return value specified for Initialize") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context) error); ok { - r0 = rf(ctx) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// NewFactory creates a new instance of Factory. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewFactory(t interface { - mock.TestingT - Cleanup(func()) -}) *Factory { - mock := &Factory{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/storage_v2/spanstore/mocks/Reader.go b/storage_v2/spanstore/mocks/Reader.go deleted file mode 100644 index 933cc037a9e..00000000000 --- a/storage_v2/spanstore/mocks/Reader.go +++ /dev/null @@ -1,186 +0,0 @@ -// Copyright (c) The Jaeger Authors. -// SPDX-License-Identifier: Apache-2.0 -// -// Run 'make generate-mocks' to regenerate. - -// Code generated by mockery. DO NOT EDIT. - -package mocks - -import ( - context "context" - - mock "github.com/stretchr/testify/mock" - pcommon "go.opentelemetry.io/collector/pdata/pcommon" - - ptrace "go.opentelemetry.io/collector/pdata/ptrace" - - spanstore "github.com/jaegertracing/jaeger/storage_v2/spanstore" -) - -// Reader is an autogenerated mock type for the Reader type -type Reader struct { - mock.Mock -} - -// FindTraceIDs provides a mock function with given fields: ctx, query -func (_m *Reader) FindTraceIDs(ctx context.Context, query spanstore.TraceQueryParameters) ([]pcommon.TraceID, error) { - ret := _m.Called(ctx, query) - - if len(ret) == 0 { - panic("no return value specified for FindTraceIDs") - } - - var r0 []pcommon.TraceID - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, spanstore.TraceQueryParameters) ([]pcommon.TraceID, error)); ok { - return rf(ctx, query) - } - if rf, ok := ret.Get(0).(func(context.Context, spanstore.TraceQueryParameters) []pcommon.TraceID); ok { - r0 = rf(ctx, query) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]pcommon.TraceID) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, spanstore.TraceQueryParameters) error); ok { - r1 = rf(ctx, query) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// FindTraces provides a mock function with given fields: ctx, query -func (_m *Reader) FindTraces(ctx context.Context, query spanstore.TraceQueryParameters) ([]ptrace.Traces, error) { - ret := _m.Called(ctx, query) - - if len(ret) == 0 { - panic("no return value specified for FindTraces") - } - - var r0 []ptrace.Traces - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, spanstore.TraceQueryParameters) ([]ptrace.Traces, error)); ok { - return rf(ctx, query) - } - if rf, ok := ret.Get(0).(func(context.Context, spanstore.TraceQueryParameters) []ptrace.Traces); ok { - r0 = rf(ctx, query) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]ptrace.Traces) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, spanstore.TraceQueryParameters) error); ok { - r1 = rf(ctx, query) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// GetOperations provides a mock function with given fields: ctx, query -func (_m *Reader) GetOperations(ctx context.Context, query spanstore.OperationQueryParameters) ([]spanstore.Operation, error) { - ret := _m.Called(ctx, query) - - if len(ret) == 0 { - panic("no return value specified for GetOperations") - } - - var r0 []spanstore.Operation - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, spanstore.OperationQueryParameters) ([]spanstore.Operation, error)); ok { - return rf(ctx, query) - } - if rf, ok := ret.Get(0).(func(context.Context, spanstore.OperationQueryParameters) []spanstore.Operation); ok { - r0 = rf(ctx, query) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]spanstore.Operation) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, spanstore.OperationQueryParameters) error); ok { - r1 = rf(ctx, query) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// GetServices provides a mock function with given fields: ctx -func (_m *Reader) GetServices(ctx context.Context) ([]string, error) { - ret := _m.Called(ctx) - - if len(ret) == 0 { - panic("no return value specified for GetServices") - } - - var r0 []string - var r1 error - if rf, ok := ret.Get(0).(func(context.Context) ([]string, error)); ok { - return rf(ctx) - } - if rf, ok := ret.Get(0).(func(context.Context) []string); ok { - r0 = rf(ctx) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]string) - } - } - - if rf, ok := ret.Get(1).(func(context.Context) error); ok { - r1 = rf(ctx) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// GetTrace provides a mock function with given fields: ctx, traceID -func (_m *Reader) GetTrace(ctx context.Context, traceID pcommon.TraceID) (ptrace.Traces, error) { - ret := _m.Called(ctx, traceID) - - if len(ret) == 0 { - panic("no return value specified for GetTrace") - } - - var r0 ptrace.Traces - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, pcommon.TraceID) (ptrace.Traces, error)); ok { - return rf(ctx, traceID) - } - if rf, ok := ret.Get(0).(func(context.Context, pcommon.TraceID) ptrace.Traces); ok { - r0 = rf(ctx, traceID) - } else { - r0 = ret.Get(0).(ptrace.Traces) - } - - if rf, ok := ret.Get(1).(func(context.Context, pcommon.TraceID) error); ok { - r1 = rf(ctx, traceID) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// NewReader creates a new instance of Reader. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewReader(t interface { - mock.TestingT - Cleanup(func()) -}) *Reader { - mock := &Reader{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/storage_v2/spanstore/mocks/Writer.go b/storage_v2/spanstore/mocks/Writer.go deleted file mode 100644 index a827057b26f..00000000000 --- a/storage_v2/spanstore/mocks/Writer.go +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) The Jaeger Authors. -// SPDX-License-Identifier: Apache-2.0 -// -// Run 'make generate-mocks' to regenerate. - -// Code generated by mockery. DO NOT EDIT. - -package mocks - -import ( - context "context" - - mock "github.com/stretchr/testify/mock" - ptrace "go.opentelemetry.io/collector/pdata/ptrace" -) - -// Writer is an autogenerated mock type for the Writer type -type Writer struct { - mock.Mock -} - -// WriteTraces provides a mock function with given fields: ctx, td -func (_m *Writer) WriteTraces(ctx context.Context, td ptrace.Traces) error { - ret := _m.Called(ctx, td) - - if len(ret) == 0 { - panic("no return value specified for WriteTraces") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, ptrace.Traces) error); ok { - r0 = rf(ctx, td) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// NewWriter creates a new instance of Writer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewWriter(t interface { - mock.TestingT - Cleanup(func()) -}) *Writer { - mock := &Writer{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} From 9b181e4e2ad8a5644207d5d12ef463c197e1ce33 Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Thu, 5 Dec 2024 09:17:07 -0500 Subject: [PATCH 15/17] Apply suggestions from code review comments / errors Signed-off-by: Yuri Shkuro --- cmd/jaeger/internal/extension/jaegerquery/server.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/jaeger/internal/extension/jaegerquery/server.go b/cmd/jaeger/internal/extension/jaegerquery/server.go index d0668e66b00..29f836e9c89 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server.go @@ -72,13 +72,14 @@ func (s *server) Start(ctx context.Context, host component.Host) error { Namespace(metrics.NSOptions{Name: "jaeger"}). Namespace(metrics.NSOptions{Name: "query"}) + // TODO currently v1 is still needed because of dependency storage v1Factory, err := jaegerstorage.GetStorageFactory(s.config.Storage.TracesPrimary, host) if err != nil { - return fmt.Errorf("cannot find primary storage from v1 factory %s: %w", s.config.Storage.TracesPrimary, err) + return fmt.Errorf("cannot find v1 factory for primary storage %s: %w", s.config.Storage.TracesPrimary, err) } f, err := jaegerstorage.GetStorageFactoryV2(s.config.Storage.TracesPrimary, host) if err != nil { - return fmt.Errorf("cannot find primary storage from v2 factory %s: %w", s.config.Storage.TracesPrimary, err) + return fmt.Errorf("cannot find v2 factory for primary storage %s: %w", s.config.Storage.TracesPrimary, err) } traceReader, err := f.CreateTraceReader() @@ -92,6 +93,7 @@ func (s *server) Start(ctx context.Context, host component.Host) error { } var opts querysvc.QueryServiceOptions + // TODO archive storage still uses v1 factory if err := s.addArchiveStorage(&opts, host); err != nil { return err } From d30b889fce7852acfbafb7f5770f2fb6a0551dca Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Thu, 5 Dec 2024 09:32:32 -0500 Subject: [PATCH 16/17] regen-mock Signed-off-by: Yuri Shkuro --- storage_v2/tracestore/mocks/Factory.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/storage_v2/tracestore/mocks/Factory.go b/storage_v2/tracestore/mocks/Factory.go index ae439a0e49d..922d57ae2c4 100644 --- a/storage_v2/tracestore/mocks/Factory.go +++ b/storage_v2/tracestore/mocks/Factory.go @@ -37,7 +37,7 @@ func (_m *Factory) Close(ctx context.Context) error { return r0 } -// CreateTraceReader provides a mock function with given fields: +// CreateTraceReader provides a mock function with no fields func (_m *Factory) CreateTraceReader() (tracestore.Reader, error) { ret := _m.Called() @@ -67,7 +67,7 @@ func (_m *Factory) CreateTraceReader() (tracestore.Reader, error) { return r0, r1 } -// CreateTraceWriter provides a mock function with given fields: +// CreateTraceWriter provides a mock function with no fields func (_m *Factory) CreateTraceWriter() (tracestore.Writer, error) { ret := _m.Called() From 68286672b165a35db0722c8f3cbc36eee1538673 Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Thu, 5 Dec 2024 09:36:19 -0500 Subject: [PATCH 17/17] fix test Signed-off-by: Yuri Shkuro --- cmd/jaeger/internal/extension/jaegerquery/server_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/jaeger/internal/extension/jaegerquery/server_test.go b/cmd/jaeger/internal/extension/jaegerquery/server_test.go index 716608b479e..70e60d78768 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server_test.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server_test.go @@ -150,7 +150,7 @@ func TestServerStart(t *testing.T) { TracesPrimary: "need-factory-error", }, }, - expectedErr: "cannot find primary storage", + expectedErr: "cannot find v1 factory for primary storage", }, { name: "span reader error",