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

[storage] Remove usages of jaegerstorage.GetStorageFactory #6624

Closed
Closed
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (ext *rsExtension) startFileBasedStrategyProvider(_ context.Context) error

func (ext *rsExtension) startAdaptiveStrategyProvider(host component.Host) error {
storageName := ext.cfg.Adaptive.SamplingStore
f, err := jaegerstorage.GetStorageFactory(storageName, host)
f, err := jaegerstorage.GetTraceStoreFactory(storageName, host)
if err != nil {
return fmt.Errorf("cannot find storage factory: %w", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func newStorageCleaner(config *Config, telset component.TelemetrySettings) *stor
}

func (c *storageCleaner) Start(_ context.Context, host component.Host) error {
storageFactory, err := jaegerstorage.GetStorageFactory(c.config.TraceStorage, host)
storageFactory, err := jaegerstorage.GetTraceStoreFactory(c.config.TraceStorage, host)
if err != nil {
return fmt.Errorf("cannot find storage factory '%s': %w", c.config.TraceStorage, err)
}
Expand Down
33 changes: 33 additions & 0 deletions storage_v2/v1adapter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@

import (
"context"
"errors"
"io"

"github.com/jaegertracing/jaeger/pkg/distributedlock"
storage_v1 "github.com/jaegertracing/jaeger/storage"
"github.com/jaegertracing/jaeger/storage/samplingstore"
"github.com/jaegertracing/jaeger/storage_v2/depstore"
"github.com/jaegertracing/jaeger/storage_v2/tracestore"
)
Expand Down Expand Up @@ -61,3 +64,33 @@
}
return NewDependencyReader(dr), nil
}

// CreateLock implements storage_v1.SamplingStoreFactory
func (f *Factory) CreateLock() (distributedlock.Lock, error) {
Copy link
Collaborator

@mahadzaryab1 mahadzaryab1 Jan 28, 2025

Choose a reason for hiding this comment

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

@yurishkuro This approach works but there's a slight change in behaviour. Consider the following:

  • Before this PR, if a storage didn't implement the storage.SamplingStoreFactory - it would fail here
  • As a result of the changes PR, the check I linked above will always pass but it would fail in the following check here

I don't see a huge downside to doing it this way except maybe a slightly different/confusing error message. We could mitigate that by returning a specific error here that we check for upstream and return the same error message as before. What do you think? The other approach would be to only construct the factory adapter based on the interfaces the underlying factory implements.

Copy link
Member

Choose a reason for hiding this comment

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

As long as we fail during startup, as opposed to later when processing incoming data, it should be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could mitigate that by returning a specific error here that we check for upstream and return the same error message as before

I've changed the error checking to something along the lines of this. Please have a look.

ss, ok := f.ss.(storage_v1.SamplingStoreFactory)
if !ok {
return nil, errors.New("storage backend does not support sampling store")
}
lock, err := ss.CreateLock()
return lock, err

Check warning on line 75 in storage_v2/v1adapter/factory.go

View check run for this annotation

Codecov / codecov/patch

storage_v2/v1adapter/factory.go#L69-L75

Added lines #L69 - L75 were not covered by tests
}

// CreateSamplingStore implements storage_v1.SamplingStoreFactory
func (f *Factory) CreateSamplingStore(maxBuckets int) (samplingstore.Store, error) {
ss, ok := f.ss.(storage_v1.SamplingStoreFactory)
if !ok {
return nil, errors.New("storage backend does not support sampling store")
}
store, err := ss.CreateSamplingStore(maxBuckets)
return store, err

Check warning on line 85 in storage_v2/v1adapter/factory.go

View check run for this annotation

Codecov / codecov/patch

storage_v2/v1adapter/factory.go#L79-L85

Added lines #L79 - L85 were not covered by tests
}

// Purge implements storage_v1.Purger
func (f *Factory) Purge(ctx context.Context) error {
p, ok := f.ss.(storage_v1.Purger)
if !ok {
return errors.New("storage backend does not support Purger")
}
err := p.Purge(ctx)
return err

Check warning on line 95 in storage_v2/v1adapter/factory.go

View check run for this annotation

Codecov / codecov/patch

storage_v2/v1adapter/factory.go#L89-L95

Added lines #L89 - L95 were not covered by tests
}
Loading