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

Remove archive storage factory #5279

Closed
6 changes: 2 additions & 4 deletions cmd/query/app/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,12 @@ func TestBuildQueryServiceOptions(t *testing.T) {

comboFactory := struct {
*mocks.Factory
*mocks.ArchiveFactory
}{
&mocks.Factory{},
&mocks.ArchiveFactory{},
}

comboFactory.ArchiveFactory.On("CreateArchiveSpanReader").Return(&spanstore_mocks.Reader{}, nil)
comboFactory.ArchiveFactory.On("CreateArchiveSpanWriter").Return(&spanstore_mocks.Writer{}, nil)
comboFactory.Factory.On("CreateSpanReader").Return(&spanstore_mocks.Reader{}, nil)
comboFactory.Factory.On("CreateSpanWriter").Return(&spanstore_mocks.Writer{}, nil)

qSvcOpts = qOpts.BuildQueryServiceOptions(comboFactory, zap.NewNop())
assert.NotNil(t, qSvcOpts)
Expand Down
9 changes: 2 additions & 7 deletions cmd/query/app/querysvc/query_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,7 @@ func (qs QueryService) GetCapabilities() StorageCapabilities {

// InitArchiveStorage tries to initialize archive storage reader/writer if storage factory supports them.
func (opts *QueryServiceOptions) InitArchiveStorage(storageFactory storage.Factory, logger *zap.Logger) bool {
archiveFactory, ok := storageFactory.(storage.ArchiveFactory)
if !ok {
logger.Info("Archive storage not supported by the factory")
return false
}
reader, err := archiveFactory.CreateArchiveSpanReader()
reader, err := storageFactory.CreateSpanReader()
Copy link
Member

Choose a reason for hiding this comment

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

This is not equivalent to previous behavior. Whoever calls this function is passing the primary storage factory, and you're just using it straight up.

if errors.Is(err, storage.ErrArchiveStorageNotConfigured) || errors.Is(err, storage.ErrArchiveStorageNotSupported) {
logger.Info("Archive storage not created", zap.String("reason", err.Error()))
return false
Expand All @@ -152,7 +147,7 @@ func (opts *QueryServiceOptions) InitArchiveStorage(storageFactory storage.Facto
logger.Error("Cannot init archive storage reader", zap.Error(err))
return false
}
writer, err := archiveFactory.CreateArchiveSpanWriter()
writer, err := storageFactory.CreateSpanWriter()
if errors.Is(err, storage.ErrArchiveStorageNotConfigured) || errors.Is(err, storage.ErrArchiveStorageNotSupported) {
logger.Info("Archive storage not created", zap.String("reason", err.Error()))
return false
Expand Down
35 changes: 14 additions & 21 deletions cmd/query/app/querysvc/query_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,50 +305,43 @@ func TestGetCapabilitiesWithSupportsArchive(t *testing.T) {
assert.Equal(t, expectedStorageCapabilities, tqs.queryService.GetCapabilities())
}

type fakeStorageFactory1 struct{}

type fakeStorageFactory2 struct {
fakeStorageFactory1
type fakeStorageFactory struct {
r spanstore.Reader
w spanstore.Writer
rErr error
wErr error
}

func (*fakeStorageFactory1) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error {
func (*fakeStorageFactory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error {
return nil
}
func (*fakeStorageFactory1) CreateSpanReader() (spanstore.Reader, error) { return nil, nil }
func (*fakeStorageFactory1) CreateSpanWriter() (spanstore.Writer, error) { return nil, nil }
func (*fakeStorageFactory1) CreateDependencyReader() (dependencystore.Reader, error) { return nil, nil }

func (f *fakeStorageFactory2) CreateArchiveSpanReader() (spanstore.Reader, error) { return f.r, f.rErr }
func (f *fakeStorageFactory2) CreateArchiveSpanWriter() (spanstore.Writer, error) { return f.w, f.wErr }
func (f *fakeStorageFactory) CreateSpanReader() (spanstore.Reader, error) { return f.r, f.rErr }
func (f *fakeStorageFactory) CreateSpanWriter() (spanstore.Writer, error) { return f.w, f.wErr }
func (f *fakeStorageFactory) CreateDependencyReader() (dependencystore.Reader, error) {
return nil, nil
}

var (
_ storage.Factory = new(fakeStorageFactory1)
_ storage.ArchiveFactory = new(fakeStorageFactory2)
)
var _ storage.Factory = new(fakeStorageFactory)

func TestInitArchiveStorageErrors(t *testing.T) {
opts := &QueryServiceOptions{}
logger := zap.NewNop()

assert.False(t, opts.InitArchiveStorage(new(fakeStorageFactory1), logger))
// assert.False(t, opts.InitArchiveStorage(new(fakeStorageFactory), logger))
assert.False(t, opts.InitArchiveStorage(
&fakeStorageFactory2{rErr: storage.ErrArchiveStorageNotConfigured},
&fakeStorageFactory{rErr: storage.ErrArchiveStorageNotConfigured},
logger,
))
assert.False(t, opts.InitArchiveStorage(
&fakeStorageFactory2{rErr: errors.New("error")},
&fakeStorageFactory{rErr: errors.New("error")},
logger,
))
assert.False(t, opts.InitArchiveStorage(
&fakeStorageFactory2{wErr: storage.ErrArchiveStorageNotConfigured},
&fakeStorageFactory{wErr: storage.ErrArchiveStorageNotConfigured},
logger,
))
assert.False(t, opts.InitArchiveStorage(
&fakeStorageFactory2{wErr: errors.New("error")},
&fakeStorageFactory{wErr: errors.New("error")},
logger,
))
}
Expand All @@ -359,7 +352,7 @@ func TestInitArchiveStorage(t *testing.T) {
reader := &spanstoremocks.Reader{}
writer := &spanstoremocks.Writer{}
assert.True(t, opts.InitArchiveStorage(
&fakeStorageFactory2{r: reader, w: writer},
&fakeStorageFactory{r: reader, w: writer},
logger,
))
assert.Equal(t, reader, opts.ArchiveSpanReader)
Expand Down
6 changes: 2 additions & 4 deletions plugin/storage/blackhole/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ import (
"github.com/jaegertracing/jaeger/storage/spanstore"
)

var ( // interface comformance checks
_ storage.Factory = (*Factory)(nil)
_ storage.ArchiveFactory = (*Factory)(nil)
)
// interface comformance checks
var _ storage.Factory = (*Factory)(nil)

// Factory implements storage.Factory and creates blackhole storage components.
type Factory struct {
Expand Down
1 change: 0 additions & 1 deletion plugin/storage/cassandra/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const (

var ( // interface comformance checks
_ storage.Factory = (*Factory)(nil)
_ storage.ArchiveFactory = (*Factory)(nil)
_ storage.SamplingStoreFactory = (*Factory)(nil)
_ io.Closer = (*Factory)(nil)
_ plugin.Configurable = (*Factory)(nil)
Expand Down
7 changes: 3 additions & 4 deletions plugin/storage/es/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ const (
)

var ( // interface comformance checks
_ storage.Factory = (*Factory)(nil)
_ storage.ArchiveFactory = (*Factory)(nil)
_ io.Closer = (*Factory)(nil)
_ plugin.Configurable = (*Factory)(nil)
_ storage.Factory = (*Factory)(nil)
_ io.Closer = (*Factory)(nil)
_ plugin.Configurable = (*Factory)(nil)
)

// Factory implements storage.Factory for Elasticsearch backend.
Expand Down
19 changes: 5 additions & 14 deletions plugin/storage/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ func AllSamplingStorageTypes() []string {
}

var ( // interface comformance checks
_ storage.Factory = (*Factory)(nil)
_ storage.ArchiveFactory = (*Factory)(nil)
_ io.Closer = (*Factory)(nil)
_ plugin.Configurable = (*Factory)(nil)
_ storage.Factory = (*Factory)(nil)
_ io.Closer = (*Factory)(nil)
_ plugin.Configurable = (*Factory)(nil)
)

// Factory implements storage.Factory interface as a meta-factory for storage components.
Expand Down Expand Up @@ -299,11 +298,7 @@ func (f *Factory) CreateArchiveSpanReader() (spanstore.Reader, error) {
if !ok {
return nil, fmt.Errorf("no %s backend registered for span store", f.SpanReaderType)
}
archive, ok := factory.(storage.ArchiveFactory)
if !ok {
return nil, storage.ErrArchiveStorageNotSupported
}
return archive.CreateArchiveSpanReader()
return factory.CreateSpanReader()
}

// CreateArchiveSpanWriter implements storage.ArchiveFactory
Expand All @@ -312,11 +307,7 @@ func (f *Factory) CreateArchiveSpanWriter() (spanstore.Writer, error) {
if !ok {
return nil, fmt.Errorf("no %s backend registered for span store", f.SpanWriterTypes[0])
}
archive, ok := factory.(storage.ArchiveFactory)
if !ok {
return nil, storage.ErrArchiveStorageNotSupported
}
return archive.CreateArchiveSpanWriter()
return factory.CreateSpanWriter()
}

var _ io.Closer = (*Factory)(nil)
Expand Down
11 changes: 5 additions & 6 deletions plugin/storage/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func TestCreate(t *testing.T) {
depReader := new(depStoreMocks.Reader)

mock.On("CreateSpanReader").Return(spanReader, errors.New("span-reader-error"))
mock.On("CreateSpanWriter").Once().Return(spanWriter, errors.New("span-writer-error"))
mock.On("CreateSpanWriter").Twice().Return(spanWriter, errors.New("span-writer-error"))
mock.On("CreateDependencyReader").Return(depReader, errors.New("dep-reader-error"))

r, err := f.CreateSpanReader()
Expand All @@ -146,10 +146,10 @@ func TestCreate(t *testing.T) {
require.EqualError(t, err, "dep-reader-error")

_, err = f.CreateArchiveSpanReader()
require.EqualError(t, err, "archive storage not supported")
require.EqualError(t, err, "span-reader-error")

_, err = f.CreateArchiveSpanWriter()
require.EqualError(t, err, "archive storage not supported")
require.EqualError(t, err, "span-writer-error")

mock.On("CreateSpanWriter").Return(spanWriter, nil)
m := metrics.NullFactory
Expand Down Expand Up @@ -234,15 +234,14 @@ func TestCreateArchive(t *testing.T) {

mock := &struct {
mocks.Factory
mocks.ArchiveFactory
}{}
f.factories[cassandraStorageType] = mock

archiveSpanReader := new(spanStoreMocks.Reader)
archiveSpanWriter := new(spanStoreMocks.Writer)

mock.ArchiveFactory.On("CreateArchiveSpanReader").Return(archiveSpanReader, errors.New("archive-span-reader-error"))
mock.ArchiveFactory.On("CreateArchiveSpanWriter").Return(archiveSpanWriter, errors.New("archive-span-writer-error"))
mock.Factory.On("CreateSpanReader").Return(archiveSpanReader, errors.New("archive-span-reader-error"))
mock.Factory.On("CreateSpanWriter").Return(archiveSpanWriter, errors.New("archive-span-writer-error"))

ar, err := f.CreateArchiveSpanReader()
assert.Equal(t, archiveSpanReader, ar)
Expand Down
7 changes: 3 additions & 4 deletions plugin/storage/grpc/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ import (
)

var ( // interface comformance checks
_ storage.Factory = (*Factory)(nil)
_ storage.ArchiveFactory = (*Factory)(nil)
_ io.Closer = (*Factory)(nil)
_ plugin.Configurable = (*Factory)(nil)
_ storage.Factory = (*Factory)(nil)
_ io.Closer = (*Factory)(nil)
_ plugin.Configurable = (*Factory)(nil)
)

// Factory implements storage.Factory and creates storage components backed by a storage plugin.
Expand Down
1 change: 1 addition & 0 deletions plugin/storage/grpc/shared/grpc_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ func (s *GRPCHandler) GetArchiveTrace(r *storage_v1.GetTraceRequest, stream stor
if errors.Is(err, spanstore.ErrTraceNotFound) {
return status.Errorf(codes.NotFound, spanstore.ErrTraceNotFound.Error())
}

if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion plugin/storage/memory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (

var ( // interface comformance checks
_ storage.Factory = (*Factory)(nil)
_ storage.ArchiveFactory = (*Factory)(nil)
_ storage.SamplingStoreFactory = (*Factory)(nil)
_ plugin.Configurable = (*Factory)(nil)
)
Expand Down
9 changes: 0 additions & 9 deletions storage/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,6 @@ var (
ErrArchiveStorageNotSupported = errors.New("archive storage not supported")
)

// ArchiveFactory is an additional interface that can be implemented by a factory to support trace archiving.
type ArchiveFactory interface {
// CreateArchiveSpanReader creates a spanstore.Reader.
CreateArchiveSpanReader() (spanstore.Reader, error)

// CreateArchiveSpanWriter creates a spanstore.Writer.
CreateArchiveSpanWriter() (spanstore.Writer, error)
}

// MetricsFactory defines an interface for a factory that can create implementations of different metrics storage components.
// Implementations are also encouraged to implement plugin.Configurable interface.
//
Expand Down
72 changes: 0 additions & 72 deletions storage/mocks/ArchiveFactory.go

This file was deleted.

Loading