Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cmd/jaeger/internal/extension/jaegerstorage/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/jaegertracing/jaeger/plugin/storage/memory"
"github.com/jaegertracing/jaeger/storage"
"github.com/jaegertracing/jaeger/storage_v2/factoryadapter"
"github.com/jaegertracing/jaeger/storage_v2/tracestore"
)

var _ Extension = (*storageExt)(nil)
Expand Down Expand Up @@ -74,7 +73,7 @@ func GetMetricStorageFactory(name string, host component.Host) (storage.MetricSt
return mf, nil
}

func GetStorageFactoryV2(name string, host component.Host) (tracestore.Factory, error) {
func GetStorageFactoryV2(name string, host component.Host) (*factoryadapter.Factory, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't know about this - adapter is implementation detail, this function should not leak it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yurishkuro I was trying to follow's Go's best practice here of returning structs instead of interfaces. If we want to keep the interface return, we'll need to define another function GetDependencyStoreFactory with a different return type (depstore.Reader) but it will do the exact same thing. Let me know what you think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not the best practice in this case. The return-struct best practice applies to constructors. GetStorageFactoryV2 is not a constructor, it's an accessor that is supposed to return a storage interface. The caller of this function is not supposed to know about the implementation of that interface and accordingly should not be able to take dependency on the concrete returned type, which could be wider than the interface alone.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good - so should we have two accessors here (something like GetTraceStoreFactory and GetDependencyStoreFactory)? Their return types would be different but the implementations would be the same.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we should. Implementations are only the same today, not in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good to me! done

f, err := GetStorageFactory(name, host)
if err != nil {
return nil, err
Expand Down
11 changes: 11 additions & 0 deletions storage_v2/depstore/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) 2024 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package depstore

import "github.com/jaegertracing/jaeger/storage_v2"

type Factory interface {
storage_v2.FactoryBase
CreateDependencyReader() (Reader, error)
}
14 changes: 14 additions & 0 deletions storage_v2/depstore/package_test.go
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 depstore

import (
"testing"

"github.com/jaegertracing/jaeger/pkg/testutils"
)

func TestMain(m *testing.M) {
testutils.VerifyGoLeaks(m)
}
16 changes: 16 additions & 0 deletions storage_v2/depstore/reader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2024 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package depstore

import (
"context"
"time"

"github.com/jaegertracing/jaeger/model"
)

// Reader can load service dependencies from storage.
type Reader interface {
GetDependencies(ctx context.Context, endTs time.Time, lookback time.Duration) ([]model.DependencyLink, error)
}
8 changes: 7 additions & 1 deletion storage_v2/factoryadapter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import (
"io"

storage_v1 "github.com/jaegertracing/jaeger/storage"
"github.com/jaegertracing/jaeger/storage_v2/depstore"
"github.com/jaegertracing/jaeger/storage_v2/tracestore"
)

type Factory struct {
ss storage_v1.Factory
}

func NewFactory(ss storage_v1.Factory) tracestore.Factory {
func NewFactory(ss storage_v1.Factory) *Factory {
return &Factory{
ss: ss,
}
Expand Down Expand Up @@ -51,3 +52,8 @@ func (f *Factory) CreateTraceWriter() (tracestore.Writer, error) {
}
return NewTraceWriter(spanWriter), nil
}

// CreateDependencyReader implements depstore.Factory.
func (f *Factory) CreateDependencyReader() (depstore.Reader, error) {
return f.ss.CreateDependencyReader()
}
21 changes: 21 additions & 0 deletions storage_v2/factoryadapter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/jaegertracing/jaeger/plugin/storage/grpc"
dependencyStoreMocks "github.com/jaegertracing/jaeger/storage/dependencystore/mocks"
factoryMocks "github.com/jaegertracing/jaeger/storage/mocks"
spanstoreMocks "github.com/jaegertracing/jaeger/storage/spanstore/mocks"
)
Expand Down Expand Up @@ -69,3 +70,23 @@ func TestAdapterCreateTraceWriter(t *testing.T) {
_, err := f.CreateTraceWriter()
require.NoError(t, err)
}

func TestAdapterCreateDependencyReader(t *testing.T) {
f1 := new(factoryMocks.Factory)
f1.On("CreateDependencyReader").Return(new(dependencyStoreMocks.Reader), nil)

f := NewFactory(f1)
r, err := f.CreateDependencyReader()
require.NoError(t, err)
require.NotNil(t, r)
}

func TestAdapterCreateDependencyReaderError(t *testing.T) {
f1 := new(factoryMocks.Factory)
testErr := errors.New("test error")
f1.On("CreateDependencyReader").Return(nil, testErr)

f := NewFactory(f1)
_, err := f.CreateDependencyReader()
require.ErrorIs(t, err, testErr)
}
Loading