From aadc9171c17ddb44d3d5c33aa69ea7a8d81b43f8 Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Sat, 16 Nov 2024 11:26:41 -0500 Subject: [PATCH] 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 000000000000..6074966874d0 --- /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 000000000000..fb5155b524bd --- /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{}) }, + ) +}