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

[chore] Return nil from storage factories when there is an error in creating span reader #6293

Merged
merged 6 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions plugin/storage/cassandra/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func NewSession(c *config.Configuration) (cassandra.Session, error) {
func (f *Factory) CreateSpanReader() (spanstore.Reader, error) {
sr, err := cSpanStore.NewSpanReader(f.primarySession, f.primaryMetricsFactory, f.logger, f.tracer.Tracer("cSpanStore.SpanReader"))
if err != nil {
return sr, err
return nil, err
}
return spanstoremetrics.NewReaderDecorator(sr, f.primaryMetricsFactory), nil
}
Expand All @@ -248,7 +248,7 @@ func (f *Factory) CreateArchiveSpanReader() (spanstore.Reader, error) {
}
sr, err := cSpanStore.NewSpanReader(f.archiveSession, f.archiveMetricsFactory, f.logger, f.tracer.Tracer("cSpanStore.SpanReader"))
if err != nil {
return sr, err
return nil, err
}
return spanstoremetrics.NewReaderDecorator(sr, f.archiveMetricsFactory), nil
}
Expand Down
22 changes: 22 additions & 0 deletions plugin/storage/cassandra/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,28 @@ func TestCassandraFactory(t *testing.T) {
require.NoError(t, f.Close())
}

func TestCreateSpanReaderError(t *testing.T) {
session := &mocks.Session{}
query := &mocks.Query{}
session.On("Query",
mock.AnythingOfType("string"),
mock.Anything).Return(query)
session.On("Query",
mock.AnythingOfType("string"),
mock.Anything).Return(query)
query.On("Exec").Return(errors.New("table does not exist"))
f := NewFactory()
f.archiveConfig = &config.Configuration{}
f.sessionBuilderFn = new(mockSessionBuilder).add(session, nil).add(session, nil).build
require.NoError(t, f.Initialize(metrics.NullFactory, zap.NewNop()))
r, err := f.CreateSpanReader()
require.Error(t, err)
require.Nil(t, r)
ar, err := f.CreateArchiveSpanReader()
require.Error(t, err)
require.Nil(t, ar)
}

func TestExclusiveWhitelistBlacklist(t *testing.T) {
f := NewFactory()
v, command := viperize.Viperize(f.AddFlags)
Expand Down
4 changes: 2 additions & 2 deletions plugin/storage/es/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (f *Factory) getArchiveClient() es.Client {
func (f *Factory) CreateSpanReader() (spanstore.Reader, error) {
sr, err := createSpanReader(f.getPrimaryClient, f.primaryConfig, false, f.logger, f.tracer)
if err != nil {
return sr, err
return nil, err
}
return spanstoremetrics.NewReaderDecorator(sr, f.primaryMetricsFactory), nil
}
Expand All @@ -220,7 +220,7 @@ func (f *Factory) CreateArchiveSpanReader() (spanstore.Reader, error) {
}
sr, err := createSpanReader(f.getArchiveClient, f.archiveConfig, true, f.logger, f.tracer)
if err != nil {
return sr, err
return nil, err
}
return spanstoremetrics.NewReaderDecorator(sr, f.archiveMetricsFactory), nil
}
Expand Down
9 changes: 8 additions & 1 deletion plugin/storage/es/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ func TestElasticsearchILMUsedWithoutReadWriteAliases(t *testing.T) {
f.primaryConfig = &escfg.Configuration{
UseILM: true,
}
f.archiveConfig = &escfg.Configuration{}
f.archiveConfig = &escfg.Configuration{
Enabled: true,
UseILM: true,
}
f.newClientFn = (&mockClientBuilder{}).NewClient
require.NoError(t, f.Initialize(metrics.NullFactory, zap.NewNop()))
defer f.Close()
Expand All @@ -134,6 +137,10 @@ func TestElasticsearchILMUsedWithoutReadWriteAliases(t *testing.T) {
r, err := f.CreateSpanReader()
require.EqualError(t, err, "--es.use-ilm must always be used in conjunction with --es.use-aliases to ensure ES writers and readers refer to the single index mapping")
assert.Nil(t, r)

ar, err := f.CreateArchiveSpanReader()
require.EqualError(t, err, "--es.use-ilm must always be used in conjunction with --es.use-aliases to ensure ES writers and readers refer to the single index mapping")
assert.Nil(t, ar)
}

func TestTagKeysAsFields(t *testing.T) {
Expand Down
Loading