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 writer to v1 (j…
…aegertracing#6555) ## Which problem is this PR solving? - Towards jaegertracing#6065 ## Description of the changes - This PR implements a reverse adapter (SpanWriter) that wraps a native v2 storage writer (tracestore.Writer) and downgrades it to implement the v1 writer (spanstore.Writer). - This will be used by jaegertracing#6519 to downgrade a native v2 writer so that it can be used by the v1 query service ## 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`: `npm run lint` and `npm run test` --------- Signed-off-by: Mahad Zaryab <[email protected]>
- Loading branch information
1 parent
c36d588
commit 7189b52
Showing
6 changed files
with
100 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) 2025 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package v1adapter | ||
|
||
import ( | ||
"context" | ||
|
||
jaegerTranslator "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger" | ||
|
||
"github.com/jaegertracing/jaeger/model" | ||
"github.com/jaegertracing/jaeger/storage/spanstore" | ||
"github.com/jaegertracing/jaeger/storage_v2/tracestore" | ||
) | ||
|
||
var _ spanstore.Writer = (*SpanWriter)(nil) | ||
|
||
// SpanReader wraps a tracestore.Writer so that it can be downgraded to implement | ||
// the v1 spanstore.Writer interface. | ||
type SpanWriter struct { | ||
traceWriter tracestore.Writer | ||
} | ||
|
||
func NewSpanWriter(traceWriter tracestore.Writer) *SpanWriter { | ||
return &SpanWriter{ | ||
traceWriter: traceWriter, | ||
} | ||
} | ||
|
||
func (sw *SpanWriter) WriteSpan(ctx context.Context, span *model.Span) error { | ||
traces, _ := jaegerTranslator.ProtoToTraces([]*model.Batch{{Spans: []*model.Span{span}}}) | ||
return sw.traceWriter.WriteTraces(ctx, traces) | ||
} |
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,67 @@ | ||
// Copyright (c) 2025 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package v1adapter | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"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" | ||
|
||
"github.com/jaegertracing/jaeger/model" | ||
tracestoremocks "github.com/jaegertracing/jaeger/storage_v2/tracestore/mocks" | ||
) | ||
|
||
func TestSpanWriter_WriteSpan(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
mockReturnErr error | ||
expectedErr error | ||
}{ | ||
{ | ||
name: "success", | ||
mockReturnErr: nil, | ||
expectedErr: nil, | ||
}, | ||
{ | ||
name: "error in translator", | ||
mockReturnErr: assert.AnError, | ||
expectedErr: assert.AnError, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
mockTraceWriter := &tracestoremocks.Writer{} | ||
spanWriter := NewSpanWriter(mockTraceWriter) | ||
|
||
now := time.Now().UTC() | ||
testSpan := &model.Span{ | ||
TraceID: model.NewTraceID(0, 1), | ||
SpanID: model.NewSpanID(1), | ||
StartTime: now, | ||
Duration: time.Second, | ||
} | ||
|
||
traces := ptrace.NewTraces() | ||
resources := traces.ResourceSpans().AppendEmpty() | ||
scopes := resources.ScopeSpans().AppendEmpty() | ||
span := scopes.Spans().AppendEmpty() | ||
span.SetTraceID(pcommon.TraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1})) | ||
span.SetSpanID(pcommon.SpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 1})) | ||
span.SetStartTimestamp(pcommon.NewTimestampFromTime(now)) | ||
span.SetEndTimestamp(pcommon.NewTimestampFromTime(now.Add(time.Second))) | ||
|
||
mockTraceWriter.On("WriteTraces", mock.Anything, traces).Return(test.mockReturnErr) | ||
|
||
err := spanWriter.WriteSpan(context.Background(), testSpan) | ||
require.ErrorIs(t, err, test.expectedErr) | ||
}) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.