From 557f1493985b9164be40ba6e5a1fa214aea9396f Mon Sep 17 00:00:00 2001 From: Mahad Zaryab <43658574+mahadzaryab1@users.noreply.github.com> Date: Sat, 30 Nov 2024 15:12:26 -0500 Subject: [PATCH] [v2][storage] Move span reader decorator to storage factories (#6280) ## Which problem is this PR solving? - Towards #6219 ## Description of the changes - This PR moves the decoration of the span readers with the metrics factory to inside the storage factory itself rather than handling it a higher level (ex. all-in-one, query server/extension). - For v2, the namespacing of the metrics has been moved from the query extension to the storage extension. - For v1, the namespacing of the metrics has been moved from the various binaries to the storage meta-factory. - This PR contains a few breaking changes as it changes the namespace under which the following metrics are published: - Storage specific metrics were that were being pushed under `jaeger_query` to will now be pushed undder `jaeger_storage` - Cassandra specific metrics were pushed under `jaeger_cassandra` and `jaeger_cassandra-archive` will now be pushed under `jaeger_storage` with the following tags: - `kind=cassandra` - `role=primary` or `role=archive` - `name` with the name of the storage (in jaeger-v2 only) - ElasticSearch/OpenSearch specific metrics were being pushed under `jaeger_index_create` will now be pushed under `jaeger_storage_index_create` with the following tags: - `kind=elasticsearch`/kind=`opensearch` - `role=primary` or `role=archive` - `name` with the name of the storage (in jaeger-v2 only) ## How was this change tested? - CI - We've booked https://github.com/jaegertracing/jaeger/issues/6278 to implement a framework that will allow for validation of metrics ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] 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: Mahad Zaryab Co-authored-by: Yuri Shkuro --- cmd/all-in-one/main.go | 2 - .../internal/extension/jaegerquery/server.go | 3 -- .../extension/jaegerstorage/extension.go | 42 +++++++++++++--- cmd/query/main.go | 2 - plugin/storage/badger/factory.go | 14 ++++-- plugin/storage/cassandra/factory.go | 40 +++++++++++++-- plugin/storage/es/factory.go | 50 +++++++++++++------ plugin/storage/es/spanstore/reader.go | 2 - plugin/storage/es/spanstore/reader_test.go | 3 -- plugin/storage/factory.go | 10 +++- plugin/storage/grpc/factory.go | 19 ++++++- plugin/storage/grpc/factory_test.go | 2 +- plugin/storage/memory/factory.go | 19 ++++++- plugin/storage/memory/factory_test.go | 2 +- 14 files changed, 160 insertions(+), 50 deletions(-) diff --git a/cmd/all-in-one/main.go b/cmd/all-in-one/main.go index 2bdae2beaf8..bc2c0e48162 100644 --- a/cmd/all-in-one/main.go +++ b/cmd/all-in-one/main.go @@ -41,7 +41,6 @@ import ( "github.com/jaegertracing/jaeger/storage/dependencystore" "github.com/jaegertracing/jaeger/storage/metricsstore/metricstoremetrics" "github.com/jaegertracing/jaeger/storage/spanstore" - "github.com/jaegertracing/jaeger/storage/spanstore/spanstoremetrics" ) // all-in-one/main is a standalone full-stack jaeger backend, backed by a memory store @@ -223,7 +222,6 @@ func startQuery( tm *tenancy.Manager, telset telemetry.Settings, ) *queryApp.Server { - spanReader = spanstoremetrics.NewReaderDecorator(spanReader, telset.Metrics) qs := querysvc.NewQueryService(spanReader, depReader, *queryOpts) server, err := queryApp.NewServer(context.Background(), qs, metricsQueryService, qOpts, tm, telset) diff --git a/cmd/jaeger/internal/extension/jaegerquery/server.go b/cmd/jaeger/internal/extension/jaegerquery/server.go index 6a9c2b22df4..9def6f5fe99 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server.go @@ -23,7 +23,6 @@ import ( "github.com/jaegertracing/jaeger/plugin/metrics/disabled" "github.com/jaegertracing/jaeger/storage/metricsstore" "github.com/jaegertracing/jaeger/storage/metricsstore/metricstoremetrics" - "github.com/jaegertracing/jaeger/storage/spanstore/spanstoremetrics" ) var ( @@ -85,8 +84,6 @@ func (s *server) Start(ctx context.Context, host component.Host) error { return fmt.Errorf("cannot create span reader: %w", err) } - spanReader = spanstoremetrics.NewReaderDecorator(spanReader, telset.Metrics) - depReader, err := f.CreateDependencyReader() if err != nil { return fmt.Errorf("cannot create dependencies reader: %w", err) diff --git a/cmd/jaeger/internal/extension/jaegerstorage/extension.go b/cmd/jaeger/internal/extension/jaegerstorage/extension.go index e931b611de9..7b3d5f454d9 100644 --- a/cmd/jaeger/internal/extension/jaegerstorage/extension.go +++ b/cmd/jaeger/internal/extension/jaegerstorage/extension.go @@ -117,24 +117,54 @@ func newStorageExt(config *Config, telset component.TelemetrySettings) *storageE func (s *storageExt) Start(_ context.Context, host component.Host) error { telset := telemetry.FromOtelComponent(s.telset, host) telset.Metrics = telset.Metrics.Namespace(metrics.NSOptions{Name: "jaeger"}) + getMetricsFactory := func(name, kind string) metrics.Factory { + return telset.Metrics.Namespace(metrics.NSOptions{ + Name: "storage", + Tags: map[string]string{ + "name": name, + "kind": kind, + }, + }) + } for storageName, cfg := range s.config.TraceBackends { s.telset.Logger.Sugar().Infof("Initializing storage '%s'", storageName) var factory storage.Factory var err error = errors.New("empty configuration") switch { case cfg.Memory != nil: - factory, err = memory.NewFactoryWithConfig(*cfg.Memory, telset.Metrics, s.telset.Logger), nil + factory, err = memory.NewFactoryWithConfig( + *cfg.Memory, + getMetricsFactory(storageName, "memory"), + s.telset.Logger, + ), nil case cfg.Badger != nil: - factory, err = badger.NewFactoryWithConfig(*cfg.Badger, telset.Metrics, s.telset.Logger) + factory, err = badger.NewFactoryWithConfig( + *cfg.Badger, + getMetricsFactory(storageName, "badger"), + s.telset.Logger) case cfg.GRPC != nil: + grpcTelset := telset + grpcTelset.Metrics = getMetricsFactory(storageName, "grpc") //nolint: contextcheck - factory, err = grpc.NewFactoryWithConfig(*cfg.GRPC, telset) + factory, err = grpc.NewFactoryWithConfig(*cfg.GRPC, grpcTelset) case cfg.Cassandra != nil: - factory, err = cassandra.NewFactoryWithConfig(*cfg.Cassandra, telset.Metrics, s.telset.Logger) + factory, err = cassandra.NewFactoryWithConfig( + *cfg.Cassandra, + getMetricsFactory(storageName, "cassandra"), + s.telset.Logger, + ) case cfg.Elasticsearch != nil: - factory, err = es.NewFactoryWithConfig(*cfg.Elasticsearch, telset.Metrics, s.telset.Logger) + factory, err = es.NewFactoryWithConfig( + *cfg.Elasticsearch, + getMetricsFactory(storageName, "elasticsearch"), + s.telset.Logger, + ) case cfg.Opensearch != nil: - factory, err = es.NewFactoryWithConfig(*cfg.Opensearch, telset.Metrics, s.telset.Logger) + factory, err = es.NewFactoryWithConfig( + *cfg.Opensearch, + getMetricsFactory(storageName, "opensearch"), + s.telset.Logger, + ) } if err != nil { return fmt.Errorf("failed to initialize storage '%s': %w", storageName, err) diff --git a/cmd/query/main.go b/cmd/query/main.go index 0376b7a60ee..6c3e6261f96 100644 --- a/cmd/query/main.go +++ b/cmd/query/main.go @@ -33,7 +33,6 @@ import ( "github.com/jaegertracing/jaeger/plugin/storage" "github.com/jaegertracing/jaeger/ports" "github.com/jaegertracing/jaeger/storage/metricsstore/metricstoremetrics" - "github.com/jaegertracing/jaeger/storage/spanstore/spanstoremetrics" ) func main() { @@ -95,7 +94,6 @@ func main() { if err != nil { logger.Fatal("Failed to create span reader", zap.Error(err)) } - spanReader = spanstoremetrics.NewReaderDecorator(spanReader, metricsFactory) dependencyReader, err := storageFactory.CreateDependencyReader() if err != nil { logger.Fatal("Failed to create dependency reader", zap.Error(err)) diff --git a/plugin/storage/badger/factory.go b/plugin/storage/badger/factory.go index 63d05612c22..01758c2eab1 100644 --- a/plugin/storage/badger/factory.go +++ b/plugin/storage/badger/factory.go @@ -27,6 +27,7 @@ import ( "github.com/jaegertracing/jaeger/storage/dependencystore" "github.com/jaegertracing/jaeger/storage/samplingstore" "github.com/jaegertracing/jaeger/storage/spanstore" + "github.com/jaegertracing/jaeger/storage/spanstore/spanstoremetrics" ) const ( @@ -50,10 +51,11 @@ var ( // interface comformance checks // Factory implements storage.Factory for Badger backend. type Factory struct { - Config *Config - store *badger.DB - cache *badgerStore.CacheStore - logger *zap.Logger + Config *Config + store *badger.DB + cache *badgerStore.CacheStore + logger *zap.Logger + metricsFactory metrics.Factory tmpDir string maintenanceDone chan bool @@ -115,6 +117,7 @@ func (f *Factory) configure(config *Config) { // Initialize implements storage.Factory func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error { f.logger = logger + f.metricsFactory = metricsFactory opts := badger.DefaultOptions("") @@ -173,7 +176,8 @@ func initializeDir(path string) { // CreateSpanReader implements storage.Factory func (f *Factory) CreateSpanReader() (spanstore.Reader, error) { - return badgerStore.NewTraceReader(f.store, f.cache), nil + tr := badgerStore.NewTraceReader(f.store, f.cache) + return spanstoremetrics.NewReaderDecorator(tr, f.metricsFactory), nil } // CreateSpanWriter implements storage.Factory diff --git a/plugin/storage/cassandra/factory.go b/plugin/storage/cassandra/factory.go index 49c7a2a9c55..1d91b8347dd 100644 --- a/plugin/storage/cassandra/factory.go +++ b/plugin/storage/cassandra/factory.go @@ -32,6 +32,7 @@ import ( "github.com/jaegertracing/jaeger/storage/dependencystore" "github.com/jaegertracing/jaeger/storage/samplingstore" "github.com/jaegertracing/jaeger/storage/spanstore" + "github.com/jaegertracing/jaeger/storage/spanstore/spanstoremetrics" ) const ( @@ -52,6 +53,7 @@ var ( // interface comformance checks type Factory struct { Options *Options + metricsFactory metrics.Factory primaryMetricsFactory metrics.Factory archiveMetricsFactory metrics.Factory logger *zap.Logger @@ -138,8 +140,21 @@ func (f *Factory) configureFromOptions(o *Options) { // Initialize implements storage.Factory func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error { - f.primaryMetricsFactory = metricsFactory.Namespace(metrics.NSOptions{Name: "cassandra", Tags: nil}) - f.archiveMetricsFactory = metricsFactory.Namespace(metrics.NSOptions{Name: "cassandra-archive", Tags: nil}) + f.metricsFactory = metricsFactory + f.primaryMetricsFactory = metricsFactory.Namespace( + metrics.NSOptions{ + Tags: map[string]string{ + "role": "primary", + }, + }, + ) + f.archiveMetricsFactory = metricsFactory.Namespace( + metrics.NSOptions{ + Tags: map[string]string{ + "role": "archive", + }, + }, + ) f.logger = logger primarySession, err := f.sessionBuilderFn(&f.primaryConfig) @@ -204,7 +219,11 @@ func NewSession(c *config.Configuration) (cassandra.Session, error) { // CreateSpanReader implements storage.Factory func (f *Factory) CreateSpanReader() (spanstore.Reader, error) { - return cSpanStore.NewSpanReader(f.primarySession, f.primaryMetricsFactory, f.logger, f.tracer.Tracer("cSpanStore.SpanReader")) + sr, err := cSpanStore.NewSpanReader(f.primarySession, f.primaryMetricsFactory, f.logger, f.tracer.Tracer("cSpanStore.SpanReader")) + if err != nil { + return sr, err + } + return spanstoremetrics.NewReaderDecorator(sr, f.primaryMetricsFactory), nil } // CreateSpanWriter implements storage.Factory @@ -227,7 +246,11 @@ func (f *Factory) CreateArchiveSpanReader() (spanstore.Reader, error) { if f.archiveSession == nil { return nil, storage.ErrArchiveStorageNotConfigured } - return cSpanStore.NewSpanReader(f.archiveSession, f.archiveMetricsFactory, f.logger, f.tracer.Tracer("cSpanStore.SpanReader")) + sr, err := cSpanStore.NewSpanReader(f.archiveSession, f.archiveMetricsFactory, f.logger, f.tracer.Tracer("cSpanStore.SpanReader")) + if err != nil { + return sr, err + } + return spanstoremetrics.NewReaderDecorator(sr, f.archiveMetricsFactory), nil } // CreateArchiveSpanWriter implements storage.ArchiveFactory @@ -255,7 +278,14 @@ func (f *Factory) CreateLock() (distributedlock.Lock, error) { // CreateSamplingStore implements storage.SamplingStoreFactory func (f *Factory) CreateSamplingStore(int /* maxBuckets */) (samplingstore.Store, error) { - return cSamplingStore.New(f.primarySession, f.primaryMetricsFactory, f.logger), nil + samplingMetricsFactory := f.metricsFactory.Namespace( + metrics.NSOptions{ + Tags: map[string]string{ + "role": "sampling", + }, + }, + ) + return cSamplingStore.New(f.primarySession, samplingMetricsFactory, f.logger), nil } func writerOptions(opts *Options) ([]cSpanStore.Option, error) { diff --git a/plugin/storage/es/factory.go b/plugin/storage/es/factory.go index 2ce06af5fc9..fff8b7e571f 100644 --- a/plugin/storage/es/factory.go +++ b/plugin/storage/es/factory.go @@ -33,6 +33,7 @@ import ( "github.com/jaegertracing/jaeger/storage/dependencystore" "github.com/jaegertracing/jaeger/storage/samplingstore" "github.com/jaegertracing/jaeger/storage/spanstore" + "github.com/jaegertracing/jaeger/storage/spanstore/spanstoremetrics" ) const ( @@ -52,9 +53,10 @@ var ( // interface comformance checks type Factory struct { Options *Options - metricsFactory metrics.Factory - logger *zap.Logger - tracer trace.TracerProvider + primaryMetricsFactory metrics.Factory + archiveMetricsFactory metrics.Factory + logger *zap.Logger + tracer trace.TracerProvider newClientFn func(c *config.Configuration, logger *zap.Logger, metricsFactory metrics.Factory) (es.Client, error) @@ -129,7 +131,21 @@ func (f *Factory) configureFromOptions(o *Options) { // Initialize implements storage.Factory. func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error { - f.metricsFactory, f.logger = metricsFactory, logger + f.primaryMetricsFactory = metricsFactory.Namespace( + metrics.NSOptions{ + Tags: map[string]string{ + "role": "primary", + }, + }, + ) + f.archiveMetricsFactory = metricsFactory.Namespace( + metrics.NSOptions{ + Tags: map[string]string{ + "role": "archive", + }, + }, + ) + f.logger = logger primaryClient, err := f.newClientFn(f.primaryConfig, logger, metricsFactory) if err != nil { @@ -180,12 +196,16 @@ func (f *Factory) getArchiveClient() es.Client { // CreateSpanReader implements storage.Factory func (f *Factory) CreateSpanReader() (spanstore.Reader, error) { - return createSpanReader(f.getPrimaryClient, f.primaryConfig, false, f.metricsFactory, f.logger, f.tracer) + sr, err := createSpanReader(f.getPrimaryClient, f.primaryConfig, false, f.logger, f.tracer) + if err != nil { + return sr, err + } + return spanstoremetrics.NewReaderDecorator(sr, f.primaryMetricsFactory), nil } // CreateSpanWriter implements storage.Factory func (f *Factory) CreateSpanWriter() (spanstore.Writer, error) { - return createSpanWriter(f.getPrimaryClient, f.primaryConfig, false, f.metricsFactory, f.logger) + return createSpanWriter(f.getPrimaryClient, f.primaryConfig, false, f.primaryMetricsFactory, f.logger) } // CreateDependencyReader implements storage.Factory @@ -198,7 +218,11 @@ func (f *Factory) CreateArchiveSpanReader() (spanstore.Reader, error) { if !f.archiveConfig.Enabled { return nil, nil } - return createSpanReader(f.getArchiveClient, f.archiveConfig, true, f.metricsFactory, f.logger, f.tracer) + sr, err := createSpanReader(f.getArchiveClient, f.archiveConfig, true, f.logger, f.tracer) + if err != nil { + return sr, err + } + return spanstoremetrics.NewReaderDecorator(sr, f.archiveMetricsFactory), nil } // CreateArchiveSpanWriter implements storage.ArchiveFactory @@ -206,14 +230,13 @@ func (f *Factory) CreateArchiveSpanWriter() (spanstore.Writer, error) { if !f.archiveConfig.Enabled { return nil, nil } - return createSpanWriter(f.getArchiveClient, f.archiveConfig, true, f.metricsFactory, f.logger) + return createSpanWriter(f.getArchiveClient, f.archiveConfig, true, f.archiveMetricsFactory, f.logger) } func createSpanReader( clientFn func() es.Client, cfg *config.Configuration, archive bool, - mFactory metrics.Factory, logger *zap.Logger, tp trace.TracerProvider, ) (spanstore.Reader, error) { @@ -232,7 +255,6 @@ func createSpanReader( Archive: archive, RemoteReadClusters: cfg.RemoteReadClusters, Logger: logger, - MetricsFactory: mFactory, Tracer: tp.Tracer("esSpanStore.SpanReader"), }), nil } @@ -352,14 +374,14 @@ func (f *Factory) Close() error { } func (f *Factory) onPrimaryPasswordChange() { - f.onClientPasswordChange(f.primaryConfig, &f.primaryClient) + f.onClientPasswordChange(f.primaryConfig, &f.primaryClient, f.primaryMetricsFactory) } func (f *Factory) onArchivePasswordChange() { - f.onClientPasswordChange(f.archiveConfig, &f.archiveClient) + f.onClientPasswordChange(f.archiveConfig, &f.archiveClient, f.archiveMetricsFactory) } -func (f *Factory) onClientPasswordChange(cfg *config.Configuration, client *atomic.Pointer[es.Client]) { +func (f *Factory) onClientPasswordChange(cfg *config.Configuration, client *atomic.Pointer[es.Client], mf metrics.Factory) { newPassword, err := loadTokenFromFile(cfg.Authentication.BasicAuthentication.PasswordFilePath) if err != nil { f.logger.Error("failed to reload password for Elasticsearch client", zap.Error(err)) @@ -370,7 +392,7 @@ func (f *Factory) onClientPasswordChange(cfg *config.Configuration, client *atom newCfg.Authentication.BasicAuthentication.Password = newPassword newCfg.Authentication.BasicAuthentication.PasswordFilePath = "" // avoid error that both are set - newClient, err := f.newClientFn(&newCfg, f.logger, f.metricsFactory) + newClient, err := f.newClientFn(&newCfg, f.logger, mf) if err != nil { f.logger.Error("failed to recreate Elasticsearch client with new password", zap.Error(err)) return diff --git a/plugin/storage/es/spanstore/reader.go b/plugin/storage/es/spanstore/reader.go index 47bd6dbcec2..622e3bcd01b 100644 --- a/plugin/storage/es/spanstore/reader.go +++ b/plugin/storage/es/spanstore/reader.go @@ -22,7 +22,6 @@ import ( "github.com/jaegertracing/jaeger/model" "github.com/jaegertracing/jaeger/pkg/es" cfg "github.com/jaegertracing/jaeger/pkg/es/config" - "github.com/jaegertracing/jaeger/pkg/metrics" "github.com/jaegertracing/jaeger/plugin/storage/es/spanstore/dbmodel" "github.com/jaegertracing/jaeger/storage/spanstore" ) @@ -113,7 +112,6 @@ type SpanReaderParams struct { Archive bool UseReadWriteAliases bool RemoteReadClusters []string - MetricsFactory metrics.Factory Logger *zap.Logger Tracer trace.Tracer } diff --git a/plugin/storage/es/spanstore/reader_test.go b/plugin/storage/es/spanstore/reader_test.go index 3b292008dcd..f40041c2abd 100644 --- a/plugin/storage/es/spanstore/reader_test.go +++ b/plugin/storage/es/spanstore/reader_test.go @@ -24,7 +24,6 @@ import ( "go.uber.org/zap" "go.uber.org/zap/zaptest" - "github.com/jaegertracing/jaeger/internal/metricstest" "github.com/jaegertracing/jaeger/model" "github.com/jaegertracing/jaeger/pkg/es" "github.com/jaegertracing/jaeger/pkg/es/config" @@ -187,7 +186,6 @@ func TestSpanReaderIndices(t *testing.T) { spanDataLayoutFormat := date.UTC().Format(spanDataLayout) serviceDataLayoutFormat := date.UTC().Format(serviceDataLayout) - metricsFactory := metricstest.NewFactory(0) logger, _ := testutils.NewLogger() tracer, _, closer := tracerProvider(t) defer closer() @@ -305,7 +303,6 @@ func TestSpanReaderIndices(t *testing.T) { for _, testCase := range testCases { testCase.params.Client = clientFn testCase.params.Logger = logger - testCase.params.MetricsFactory = metricsFactory testCase.params.Tracer = tracer.Tracer("test") r := NewSpanReader(testCase.params) diff --git a/plugin/storage/factory.go b/plugin/storage/factory.go index e088bef593f..58f81f3a5a4 100644 --- a/plugin/storage/factory.go +++ b/plugin/storage/factory.go @@ -137,8 +137,14 @@ func (*Factory) getFactoryOfType(factoryType string) (storage.Factory, error) { // Initialize implements storage.Factory. func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error { f.metricsFactory = metricsFactory - for _, factory := range f.factories { - if err := factory.Initialize(metricsFactory, logger); err != nil { + for kind, factory := range f.factories { + mf := metricsFactory.Namespace(metrics.NSOptions{ + Name: "storage", + Tags: map[string]string{ + "kind": kind, + }, + }) + if err := factory.Initialize(mf, logger); err != nil { return err } } diff --git a/plugin/storage/grpc/factory.go b/plugin/storage/grpc/factory.go index e198068a7cb..28edfa6f2ae 100644 --- a/plugin/storage/grpc/factory.go +++ b/plugin/storage/grpc/factory.go @@ -31,6 +31,7 @@ import ( "github.com/jaegertracing/jaeger/storage" "github.com/jaegertracing/jaeger/storage/dependencystore" "github.com/jaegertracing/jaeger/storage/spanstore" + "github.com/jaegertracing/jaeger/storage/spanstore/spanstoremetrics" ) var ( // interface comformance checks @@ -167,7 +168,14 @@ func (f *Factory) newRemoteStorage( // CreateSpanReader implements storage.Factory func (f *Factory) CreateSpanReader() (spanstore.Reader, error) { - return f.services.Store.SpanReader(), nil + primaryMetricsFactory := f.telset.Metrics.Namespace( + metrics.NSOptions{ + Tags: map[string]string{ + "role": "primary", + }, + }, + ) + return spanstoremetrics.NewReaderDecorator(f.services.Store.SpanReader(), primaryMetricsFactory), nil } // CreateSpanWriter implements storage.Factory @@ -197,7 +205,14 @@ func (f *Factory) CreateArchiveSpanReader() (spanstore.Reader, error) { if capabilities == nil || !capabilities.ArchiveSpanReader { return nil, storage.ErrArchiveStorageNotSupported } - return f.services.ArchiveStore.ArchiveSpanReader(), nil + archiveMetricsFactory := f.telset.Metrics.Namespace( + metrics.NSOptions{ + Tags: map[string]string{ + "role": "archive", + }, + }, + ) + return spanstoremetrics.NewReaderDecorator(f.services.ArchiveStore.ArchiveSpanReader(), archiveMetricsFactory), nil } // CreateArchiveSpanWriter implements storage.ArchiveFactory diff --git a/plugin/storage/grpc/factory_test.go b/plugin/storage/grpc/factory_test.go index c96897bae16..a9bf26c49c4 100644 --- a/plugin/storage/grpc/factory_test.go +++ b/plugin/storage/grpc/factory_test.go @@ -143,7 +143,7 @@ func TestInitFactory(t *testing.T) { reader, err := f.CreateSpanReader() require.NoError(t, err) - assert.Equal(t, f.services.Store.SpanReader(), reader) + assert.NotNil(t, reader) writer, err := f.CreateSpanWriter() require.NoError(t, err) diff --git a/plugin/storage/memory/factory.go b/plugin/storage/memory/factory.go index 59214cd5bfa..eb6924a6576 100644 --- a/plugin/storage/memory/factory.go +++ b/plugin/storage/memory/factory.go @@ -19,6 +19,7 @@ import ( "github.com/jaegertracing/jaeger/storage/dependencystore" "github.com/jaegertracing/jaeger/storage/samplingstore" "github.com/jaegertracing/jaeger/storage/spanstore" + "github.com/jaegertracing/jaeger/storage/spanstore/spanstoremetrics" ) var ( // interface comformance checks @@ -81,7 +82,14 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) // CreateSpanReader implements storage.Factory func (f *Factory) CreateSpanReader() (spanstore.Reader, error) { - return f.store, nil + primaryMetricsFactory := f.metricsFactory.Namespace( + metrics.NSOptions{ + Tags: map[string]string{ + "role": "primary", + }, + }, + ) + return spanstoremetrics.NewReaderDecorator(f.store, primaryMetricsFactory), nil } // CreateSpanWriter implements storage.Factory @@ -91,7 +99,14 @@ func (f *Factory) CreateSpanWriter() (spanstore.Writer, error) { // CreateArchiveSpanReader implements storage.ArchiveFactory func (f *Factory) CreateArchiveSpanReader() (spanstore.Reader, error) { - return f.store, nil + archiveMetricsFactory := f.metricsFactory.Namespace( + metrics.NSOptions{ + Tags: map[string]string{ + "role": "archive", + }, + }, + ) + return spanstoremetrics.NewReaderDecorator(f.store, archiveMetricsFactory), nil } // CreateArchiveSpanWriter implements storage.ArchiveFactory diff --git a/plugin/storage/memory/factory_test.go b/plugin/storage/memory/factory_test.go index f769dbfc065..63808142276 100644 --- a/plugin/storage/memory/factory_test.go +++ b/plugin/storage/memory/factory_test.go @@ -25,7 +25,7 @@ func TestMemoryStorageFactory(t *testing.T) { assert.NotNil(t, f.store) reader, err := f.CreateSpanReader() require.NoError(t, err) - assert.Equal(t, f.store, reader) + require.NotNil(t, reader) writer, err := f.CreateSpanWriter() require.NoError(t, err) assert.Equal(t, f.store, writer)