forked from jaegertracing/jaeger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v2][storage] Implement reverse adapter to translate v2 storage api t…
…o v1 (jaegertracing#6485) ## Which problem is this PR solving? - Resolves jaegertracing#6480 ## Description of the changes - This PR implements a reverse adapter (`SpanReader`) that wraps a native v2 storage interface (`tracestore.Reader`) and downgrades it to implement the v1 storage interface (`spanstore.Reader`). - The reverse adapter was integrated with the v1 query service. This code path will only get executed once we start upgrading the existing storage implementations to implement the new `tracestore.Reader` interface as a part of jaegertracing#6458 ## How was this change tested? - CI - Added new 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`: `npm run lint` and `npm run test` --------- Signed-off-by: Mahad Zaryab <[email protected]> Signed-off-by: adityachopra29 <[email protected]>
- Loading branch information
1 parent
616448a
commit 9b4467a
Showing
9 changed files
with
623 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Copyright (c) 2025 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package v1adapter | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/jaegertracing/jaeger/model" | ||
"github.com/jaegertracing/jaeger/storage/spanstore" | ||
"github.com/jaegertracing/jaeger/storage_v2/tracestore" | ||
) | ||
|
||
var _ spanstore.Reader = (*SpanReader)(nil) | ||
|
||
var errTooManyTracesFound = errors.New("too many traces found") | ||
|
||
// SpanReader wraps a tracestore.Reader so that it can be downgraded to implement | ||
// the v1 spanstore.Reader interface. | ||
type SpanReader struct { | ||
traceReader tracestore.Reader | ||
} | ||
|
||
func NewSpanReader(traceReader tracestore.Reader) *SpanReader { | ||
return &SpanReader{ | ||
traceReader: traceReader, | ||
} | ||
} | ||
|
||
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 | ||
} else if len(traces) > 1 { | ||
return nil, errTooManyTracesFound | ||
} | ||
return traces[0], nil | ||
} | ||
|
||
func (sr *SpanReader) GetServices(ctx context.Context) ([]string, error) { | ||
return sr.traceReader.GetServices(ctx) | ||
} | ||
|
||
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 | ||
} | ||
|
||
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) | ||
} | ||
|
||
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, | ||
}) | ||
return V1TraceIDsFromSeq2(traceIDsIter) | ||
} |
Oops, something went wrong.