Skip to content

Commit

Permalink
[v2][storage] Implement GetServices and GetOperations in v2 facto…
Browse files Browse the repository at this point in the history
…ry adapter (jaegertracing#6325)

## Which problem is this PR solving?
- Towards jaegertracing#5079 

## Description of the changes
- This PR implements `GetServices` and `GetOperations` in the v2
`factoryadapter`

## How was this change tested?
- Added unit tests

## Checklist
- [x] I have read
https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md
- [x] I have signed all commits
- [x] I have added unit tests for the new functionality
- [x] I have run lint and test steps successfully
  - for `jaeger`: `make lint test`
  - for `jaeger-ui`: `yarn lint` and `yarn test`

---------

Signed-off-by: Mahad Zaryab <[email protected]>
  • Loading branch information
mahadzaryab1 authored Dec 8, 2024
1 parent b264d2c commit f0769e6
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 16 deletions.
19 changes: 15 additions & 4 deletions storage_v2/factoryadapter/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,23 @@ func (*TraceReader) GetTrace(_ context.Context, _ pcommon.TraceID) (ptrace.Trace
panic("not implemented")
}

func (*TraceReader) GetServices(_ context.Context) ([]string, error) {
panic("not implemented")
func (tr *TraceReader) GetServices(ctx context.Context) ([]string, error) {
return tr.spanReader.GetServices(ctx)
}

func (*TraceReader) GetOperations(_ context.Context, _ tracestore.OperationQueryParameters) ([]tracestore.Operation, error) {
panic("not implemented")
func (tr *TraceReader) GetOperations(ctx context.Context, query tracestore.OperationQueryParameters) ([]tracestore.Operation, error) {
o, err := tr.spanReader.GetOperations(ctx, spanstore.OperationQueryParameters{
ServiceName: query.ServiceName,
SpanKind: query.SpanKind,
})
var operations []tracestore.Operation
for _, operation := range o {
operations = append(operations, tracestore.Operation{
Name: operation.Name,
SpanKind: operation.SpanKind,
})
}
return operations, err
}

func (*TraceReader) FindTraces(_ context.Context, _ tracestore.TraceQueryParameters) ([]ptrace.Traces, error) {
Expand Down
87 changes: 75 additions & 12 deletions storage_v2/factoryadapter/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package factoryadapter

import (
"context"
"errors"
"testing"
"time"

Expand All @@ -16,6 +17,8 @@ import (
"github.com/jaegertracing/jaeger/model"
"github.com/jaegertracing/jaeger/plugin/storage/memory"
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/depstore"
"github.com/jaegertracing/jaeger/storage_v2/tracestore"
)
Expand Down Expand Up @@ -66,23 +69,83 @@ func TestTraceReader_GetTracePanics(t *testing.T) {
require.Panics(t, func() { traceReader.GetTrace(context.Background(), pcommon.NewTraceIDEmpty()) })
}

func TestTraceReader_GetServicesPanics(t *testing.T) {
memstore := memory.NewStore()
func TestTraceReader_GetServicesDelegatesToSpanReader(t *testing.T) {
sr := new(spanStoreMocks.Reader)
expectedServices := []string{"service-a", "service-b"}
sr.On("GetServices", mock.Anything).Return(expectedServices, nil)
traceReader := &TraceReader{
spanReader: memstore,
spanReader: sr,
}
require.Panics(t, func() { traceReader.GetServices(context.Background()) })
services, err := traceReader.GetServices(context.Background())
require.NoError(t, err)
require.Equal(t, expectedServices, services)
}

func TestTraceReader_GetOperationsPanics(t *testing.T) {
memstore := memory.NewStore()
traceReader := &TraceReader{
spanReader: memstore,
func TestTraceReader_GetOperationsDelegatesResponse(t *testing.T) {
tests := []struct {
name string
operations []spanstore.Operation
expectedOperations []tracestore.Operation
err error
}{
{
name: "successful response",
operations: []spanstore.Operation{
{
Name: "operation-a",
SpanKind: "server",
},
{
Name: "operation-b",
SpanKind: "server",
},
},
expectedOperations: []tracestore.Operation{
{
Name: "operation-a",
SpanKind: "server",
},
{
Name: "operation-b",
SpanKind: "server",
},
},
},
{
name: "nil response",
operations: nil,
expectedOperations: nil,
},
{
name: "error response",
operations: nil,
expectedOperations: nil,
err: errors.New("test error"),
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
sr := new(spanStoreMocks.Reader)
sr.On("GetOperations",
mock.Anything,
spanstore.OperationQueryParameters{
ServiceName: "service-a",
SpanKind: "server",
}).Return(test.operations, test.err)
traceReader := &TraceReader{
spanReader: sr,
}
operations, err := traceReader.GetOperations(
context.Background(),
tracestore.OperationQueryParameters{
ServiceName: "service-a",
SpanKind: "server",
})
require.ErrorIs(t, err, test.err)
require.Equal(t, test.expectedOperations, operations)
})
}
require.Panics(
t,
func() { traceReader.GetOperations(context.Background(), tracestore.OperationQueryParameters{}) },
)
}

func TestTraceReader_FindTracesPanics(t *testing.T) {
Expand Down

0 comments on commit f0769e6

Please sign in to comment.