Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v2][storage] Implement reverse adapter to translate v2 storage api to v1 #6485

Merged
merged 14 commits into from
Jan 5, 2025
113 changes: 113 additions & 0 deletions storage_v2/v1adapter/spanreader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package v1adapter

import (
"context"

"github.com/jaegertracing/jaeger/model"
"github.com/jaegertracing/jaeger/storage/spanstore"
"github.com/jaegertracing/jaeger/storage_v2/tracestore"
"go.opentelemetry.io/collector/pdata/pcommon"
)

type SpanReader struct {
traceReader tracestore.Reader
}

func NewSpanReader(traceReader tracestore.Reader) *SpanReader {
return &SpanReader{
traceReader: traceReader,
}

Check warning on line 19 in storage_v2/v1adapter/spanreader.go

View check run for this annotation

Codecov / codecov/patch

storage_v2/v1adapter/spanreader.go#L16-L19

Added lines #L16 - L19 were not covered by tests
}

func (sr *SpanReader) GetTrace(ctx context.Context, query spanstore.GetTraceParameters) (*model.Trace, error) {
getTracesIter := sr.traceReader.GetTraces(ctx, tracestore.GetTraceParams{
TraceID: query.TraceID.ToOTELTraceID(),
Start: query.StartTime,
End: query.EndTime,
})
traces, err := V1TracesFromSeq2(getTracesIter)
if err != nil {
return nil, err
}
if len(traces) == 0 {
return nil, spanstore.ErrTraceNotFound
}
return traces[0], nil

Check warning on line 35 in storage_v2/v1adapter/spanreader.go

View check run for this annotation

Codecov / codecov/patch

storage_v2/v1adapter/spanreader.go#L22-L35

Added lines #L22 - L35 were not covered by tests
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
}

func (sr *SpanReader) GetServices(ctx context.Context) ([]string, error) {
return sr.traceReader.GetServices(ctx)

Check warning on line 39 in storage_v2/v1adapter/spanreader.go

View check run for this annotation

Codecov / codecov/patch

storage_v2/v1adapter/spanreader.go#L38-L39

Added lines #L38 - L39 were not covered by tests
}

func (sr *SpanReader) GetOperations(
ctx context.Context,
query spanstore.OperationQueryParameters,
) ([]spanstore.Operation, error) {
o, err := sr.traceReader.GetOperations(ctx, tracestore.OperationQueryParams{
ServiceName: query.ServiceName,
SpanKind: query.SpanKind,
})
if err != nil || o == nil {
return nil, err
}
operations := []spanstore.Operation{}
for _, operation := range o {
operations = append(operations, spanstore.Operation{
Name: operation.Name,
SpanKind: operation.SpanKind,
})
}
return operations, nil

Check warning on line 60 in storage_v2/v1adapter/spanreader.go

View check run for this annotation

Codecov / codecov/patch

storage_v2/v1adapter/spanreader.go#L45-L60

Added lines #L45 - L60 were not covered by tests
}

func (sr *SpanReader) FindTraces(
ctx context.Context,
query *spanstore.TraceQueryParameters,
) ([]*model.Trace, error) {
getTracesIter := sr.traceReader.FindTraces(ctx, tracestore.TraceQueryParams{
ServiceName: query.ServiceName,
OperationName: query.OperationName,
Tags: query.Tags,
StartTimeMin: query.StartTimeMin,
StartTimeMax: query.StartTimeMax,
DurationMin: query.DurationMin,
DurationMax: query.DurationMax,
NumTraces: query.NumTraces,
})
return V1TracesFromSeq2(getTracesIter)

Check warning on line 77 in storage_v2/v1adapter/spanreader.go

View check run for this annotation

Codecov / codecov/patch

storage_v2/v1adapter/spanreader.go#L66-L77

Added lines #L66 - L77 were not covered by tests
}

func (sr *SpanReader) FindTraceIDs(
ctx context.Context,
query *spanstore.TraceQueryParameters,
) ([]model.TraceID, error) {
traceIDsIter := sr.traceReader.FindTraceIDs(ctx, tracestore.TraceQueryParams{
ServiceName: query.ServiceName,
OperationName: query.OperationName,
Tags: query.Tags,
StartTimeMin: query.StartTimeMin,
StartTimeMax: query.StartTimeMax,
DurationMin: query.DurationMin,
DurationMax: query.DurationMax,
NumTraces: query.NumTraces,
})
var (
iterErr error
modelTraceIDs []model.TraceID
)
traceIDsIter(func(traceIDs []pcommon.TraceID, err error) bool {
if err != nil {
iterErr = err
return false
}
for _, traceID := range traceIDs {
model.TraceIDFromOTEL(traceID)
modelTraceIDs = append(modelTraceIDs, model.TraceIDFromOTEL(traceID))
}
return true

Check warning on line 107 in storage_v2/v1adapter/spanreader.go

View check run for this annotation

Codecov / codecov/patch

storage_v2/v1adapter/spanreader.go#L83-L107

Added lines #L83 - L107 were not covered by tests
})
if iterErr != nil {
return nil, iterErr
}
return modelTraceIDs, nil

Check warning on line 112 in storage_v2/v1adapter/spanreader.go

View check run for this annotation

Codecov / codecov/patch

storage_v2/v1adapter/spanreader.go#L109-L112

Added lines #L109 - L112 were not covered by tests
}
Loading