-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v2] Add v1 factory converter to v2 storage factory (#5497)
## Which problem is this PR solving? - Part of #5334 ## Description of the changes - Current storageextension uses v1 storage factory and transitioning from v1 to v2 requires v2 to implement the v1 storage factory interface. This PR helps by creating a wrapper factory to implement v1 storage factory converted from v2 spanstore interface. ## How was this change tested? - unit tests ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [ ] 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: James Ryans <james.ryans2012@gmail.com> Co-authored-by: Yuri Shkuro <yurishkuro@users.noreply.github.com>
- Loading branch information
1 parent
1c1f22b
commit 3f6f5fe
Showing
10 changed files
with
327 additions
and
42 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
5 changes: 5 additions & 0 deletions
5
cmd/jaeger/internal/extension/jaegerstorage/factoryadapter/README.md
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,5 @@ | ||
# Storage Factory Converter | ||
|
||
A temporary v1 storage factory wrapper to implement v2 storage APIs. | ||
This way, the existing v1 storage factories declared in `jaegerstorageextension` | ||
can act as v2 storage while we migrate to v2 storage APIs. |
49 changes: 49 additions & 0 deletions
49
cmd/jaeger/internal/extension/jaegerstorage/factoryadapter/factory.go
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,49 @@ | ||
// Copyright (c) 2024 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package factoryadapter | ||
|
||
import ( | ||
"context" | ||
"io" | ||
|
||
storage_v1 "github.com/jaegertracing/jaeger/storage" | ||
"github.com/jaegertracing/jaeger/storage_v2/spanstore" | ||
) | ||
|
||
type Factory struct { | ||
ss storage_v1.Factory | ||
} | ||
|
||
func NewFactory(ss storage_v1.Factory) spanstore.Factory { | ||
return &Factory{ | ||
ss: ss, | ||
} | ||
} | ||
|
||
// Initialize implements spanstore.Factory. | ||
func (*Factory) Initialize(_ context.Context) error { | ||
panic("not implemented") | ||
} | ||
|
||
// Close implements spanstore.Factory. | ||
func (f *Factory) Close(_ context.Context) error { | ||
if closer, ok := f.ss.(io.Closer); ok { | ||
return closer.Close() | ||
} | ||
return nil | ||
} | ||
|
||
// CreateTraceReader implements spanstore.Factory. | ||
func (*Factory) CreateTraceReader() (spanstore.Reader, error) { | ||
panic("not implemented") | ||
} | ||
|
||
// CreateTraceWriter implements spanstore.Factory. | ||
func (f *Factory) CreateTraceWriter() (spanstore.Writer, error) { | ||
spanWriter, err := f.ss.CreateSpanWriter() | ||
if err != nil { | ||
return nil, err | ||
} | ||
return NewTraceWriter(spanWriter), nil | ||
} |
66 changes: 66 additions & 0 deletions
66
cmd/jaeger/internal/extension/jaegerstorage/factoryadapter/factory_test.go
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,66 @@ | ||
// Copyright (c) 2024 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package factoryadapter | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/jaegertracing/jaeger/plugin/storage/grpc" | ||
factoryMocks "github.com/jaegertracing/jaeger/storage/mocks" | ||
spanstoreMocks "github.com/jaegertracing/jaeger/storage/spanstore/mocks" | ||
) | ||
|
||
func TestAdapterInitialize(t *testing.T) { | ||
defer func() { | ||
if r := recover(); r == nil { | ||
t.Errorf("initialize did not panic") | ||
} | ||
}() | ||
|
||
f := &Factory{} | ||
_ = f.Initialize(context.Background()) | ||
} | ||
|
||
func TestAdapterCloseNotOk(t *testing.T) { | ||
f := NewFactory(&factoryMocks.Factory{}) | ||
require.NoError(t, f.Close(context.Background())) | ||
} | ||
|
||
func TestAdapterClose(t *testing.T) { | ||
f := NewFactory(grpc.NewFactory()) | ||
require.NoError(t, f.Close(context.Background())) | ||
} | ||
|
||
func TestAdapterCreateTraceReader(t *testing.T) { | ||
defer func() { | ||
if r := recover(); r == nil { | ||
t.Errorf("create trace reader did not panic") | ||
} | ||
}() | ||
|
||
f := &Factory{} | ||
f.CreateTraceReader() | ||
} | ||
|
||
func TestAdapterCreateTraceWriterError(t *testing.T) { | ||
f1 := new(factoryMocks.Factory) | ||
f1.On("CreateSpanWriter").Return(nil, errors.New("mock error")) | ||
|
||
f := NewFactory(f1) | ||
_, err := f.CreateTraceWriter() | ||
require.ErrorContains(t, err, "mock error") | ||
} | ||
|
||
func TestAdapterCreateTraceWriter(t *testing.T) { | ||
f1 := new(factoryMocks.Factory) | ||
f1.On("CreateSpanWriter").Return(new(spanstoreMocks.Writer), nil) | ||
|
||
f := NewFactory(f1) | ||
_, err := f.CreateTraceWriter() | ||
require.NoError(t, err) | ||
} |
14 changes: 14 additions & 0 deletions
14
cmd/jaeger/internal/extension/jaegerstorage/factoryadapter/package_test.go
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,14 @@ | ||
// Copyright (c) 2024 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package factoryadapter | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/jaegertracing/jaeger/pkg/testutils" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
testutils.VerifyGoLeaks(m) | ||
} |
Oops, something went wrong.