diff --git a/cmd/all-in-one/main.go b/cmd/all-in-one/main.go index bc2c0e48162..8f2dd9f9efa 100644 --- a/cmd/all-in-one/main.go +++ b/cmd/all-in-one/main.go @@ -39,7 +39,6 @@ import ( "github.com/jaegertracing/jaeger/plugin/storage" "github.com/jaegertracing/jaeger/ports" "github.com/jaegertracing/jaeger/storage/dependencystore" - "github.com/jaegertracing/jaeger/storage/metricsstore/metricstoremetrics" "github.com/jaegertracing/jaeger/storage/spanstore" ) @@ -118,7 +117,7 @@ by default uses only in-memory database.`, logger.Fatal("Failed to create dependency reader", zap.Error(err)) } - metricsQueryService, err := createMetricsQueryService(metricsReaderFactory, v, logger, queryMetricsFactory) + metricsQueryService, err := createMetricsQueryService(metricsReaderFactory, v, baseTelset) if err != nil { logger.Fatal("Failed to create metrics reader", zap.Error(err)) } @@ -238,20 +237,18 @@ func startQuery( func createMetricsQueryService( metricsReaderFactory *metricsPlugin.Factory, v *viper.Viper, - logger *zap.Logger, - metricsReaderMetricsFactory metrics.Factory, + telset telemetry.Settings, ) (querysvc.MetricsQueryService, error) { - if err := metricsReaderFactory.Initialize(logger); err != nil { + if err := metricsReaderFactory.Initialize(telset); err != nil { return nil, fmt.Errorf("failed to init metrics reader factory: %w", err) } // Ensure default parameter values are loaded correctly. - metricsReaderFactory.InitFromViper(v, logger) + metricsReaderFactory.InitFromViper(v, telset.Logger) reader, err := metricsReaderFactory.CreateMetricsReader() if err != nil { return nil, fmt.Errorf("failed to create metrics reader: %w", err) } - // Decorate the metrics reader with metrics instrumentation. - return metricstoremetrics.NewReaderDecorator(reader, metricsReaderMetricsFactory), nil + return reader, nil } diff --git a/cmd/jaeger/internal/extension/jaegerquery/server.go b/cmd/jaeger/internal/extension/jaegerquery/server.go index 9def6f5fe99..dd81c42f6f1 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server.go @@ -15,14 +15,12 @@ import ( "github.com/jaegertracing/jaeger/cmd/jaeger/internal/extension/jaegerstorage" queryApp "github.com/jaegertracing/jaeger/cmd/query/app" "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" - "github.com/jaegertracing/jaeger/internal/metrics/otelmetrics" "github.com/jaegertracing/jaeger/pkg/jtracer" "github.com/jaegertracing/jaeger/pkg/metrics" "github.com/jaegertracing/jaeger/pkg/telemetry" "github.com/jaegertracing/jaeger/pkg/tenancy" "github.com/jaegertracing/jaeger/plugin/metrics/disabled" "github.com/jaegertracing/jaeger/storage/metricsstore" - "github.com/jaegertracing/jaeger/storage/metricsstore/metricstoremetrics" ) var ( @@ -156,10 +154,7 @@ func (s *server) createMetricReader(host component.Host) (metricsstore.Reader, e return nil, fmt.Errorf("cannot create metrics reader %w", err) } - // Decorate the metrics reader with metrics instrumentation. - mf := otelmetrics.NewFactory(s.telset.MeterProvider) - mf = mf.Namespace(metrics.NSOptions{Name: "jaeger_metricstore"}) - return metricstoremetrics.NewReaderDecorator(metricsReader, mf), nil + return metricsReader, nil } func (s *server) Shutdown(ctx context.Context) error { diff --git a/cmd/jaeger/internal/extension/jaegerquery/server_test.go b/cmd/jaeger/internal/extension/jaegerquery/server_test.go index 54b3733f24c..b8a68a119c6 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server_test.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server_test.go @@ -26,6 +26,7 @@ import ( "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" "github.com/jaegertracing/jaeger/internal/grpctest" "github.com/jaegertracing/jaeger/pkg/metrics" + "github.com/jaegertracing/jaeger/pkg/telemetry" "github.com/jaegertracing/jaeger/pkg/testutils" "github.com/jaegertracing/jaeger/storage" "github.com/jaegertracing/jaeger/storage/dependencystore" @@ -73,7 +74,7 @@ type fakeMetricsFactory struct { } // Initialize implements storage.MetricsFactory. -func (fmf fakeMetricsFactory) Initialize(*zap.Logger) error { +func (fmf fakeMetricsFactory) Initialize(telemetry.Settings) error { if fmf.name == "need-initialize-error" { return errors.New("test-error") } diff --git a/cmd/jaeger/internal/extension/jaegerstorage/extension.go b/cmd/jaeger/internal/extension/jaegerstorage/extension.go index 7b3d5f454d9..1a227c0199b 100644 --- a/cmd/jaeger/internal/extension/jaegerstorage/extension.go +++ b/cmd/jaeger/internal/extension/jaegerstorage/extension.go @@ -117,12 +117,13 @@ 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 { + scopedMetricsFactory := func(name, kind, role string) metrics.Factory { return telset.Metrics.Namespace(metrics.NSOptions{ Name: "storage", Tags: map[string]string{ "name": name, "kind": kind, + "role": role, }, }) } @@ -134,35 +135,35 @@ func (s *storageExt) Start(_ context.Context, host component.Host) error { case cfg.Memory != nil: factory, err = memory.NewFactoryWithConfig( *cfg.Memory, - getMetricsFactory(storageName, "memory"), + scopedMetricsFactory(storageName, "memory", "tracestore"), s.telset.Logger, ), nil case cfg.Badger != nil: factory, err = badger.NewFactoryWithConfig( *cfg.Badger, - getMetricsFactory(storageName, "badger"), + scopedMetricsFactory(storageName, "badger", "tracestore"), s.telset.Logger) case cfg.GRPC != nil: grpcTelset := telset - grpcTelset.Metrics = getMetricsFactory(storageName, "grpc") + grpcTelset.Metrics = scopedMetricsFactory(storageName, "grpc", "tracestore") //nolint: contextcheck factory, err = grpc.NewFactoryWithConfig(*cfg.GRPC, grpcTelset) case cfg.Cassandra != nil: factory, err = cassandra.NewFactoryWithConfig( *cfg.Cassandra, - getMetricsFactory(storageName, "cassandra"), + scopedMetricsFactory(storageName, "cassandra", "tracestore"), s.telset.Logger, ) case cfg.Elasticsearch != nil: factory, err = es.NewFactoryWithConfig( *cfg.Elasticsearch, - getMetricsFactory(storageName, "elasticsearch"), + scopedMetricsFactory(storageName, "elasticsearch", "tracestore"), s.telset.Logger, ) case cfg.Opensearch != nil: factory, err = es.NewFactoryWithConfig( *cfg.Opensearch, - getMetricsFactory(storageName, "opensearch"), + scopedMetricsFactory(storageName, "opensearch", "tracestore"), s.telset.Logger, ) } @@ -177,7 +178,11 @@ func (s *storageExt) Start(_ context.Context, host component.Host) error { var metricsFactory storage.MetricsFactory var err error if cfg.Prometheus != nil { - metricsFactory, err = prometheus.NewFactoryWithConfig(*cfg.Prometheus, s.telset.Logger) + promTelset := telset + promTelset.Metrics = scopedMetricsFactory(metricStorageName, "prometheus", "metricstore") + metricsFactory, err = prometheus.NewFactoryWithConfig( + *cfg.Prometheus, + promTelset) } if err != nil { return fmt.Errorf("failed to initialize metrics storage '%s': %w", metricStorageName, err) diff --git a/cmd/query/main.go b/cmd/query/main.go index 6c3e6261f96..67425b2c9cc 100644 --- a/cmd/query/main.go +++ b/cmd/query/main.go @@ -32,7 +32,6 @@ import ( metricsPlugin "github.com/jaegertracing/jaeger/plugin/metrics" "github.com/jaegertracing/jaeger/plugin/storage" "github.com/jaegertracing/jaeger/ports" - "github.com/jaegertracing/jaeger/storage/metricsstore/metricstoremetrics" ) func main() { @@ -99,7 +98,7 @@ func main() { logger.Fatal("Failed to create dependency reader", zap.Error(err)) } - metricsQueryService, err := createMetricsQueryService(metricsReaderFactory, v, logger, metricsFactory) + metricsQueryService, err := createMetricsQueryService(metricsReaderFactory, v, baseTelset) if err != nil { logger.Fatal("Failed to create metrics query service", zap.Error(err)) } @@ -166,20 +165,18 @@ func main() { func createMetricsQueryService( metricsReaderFactory *metricsPlugin.Factory, v *viper.Viper, - logger *zap.Logger, - metricsReaderMetricsFactory metrics.Factory, + telset telemetry.Settings, ) (querysvc.MetricsQueryService, error) { - if err := metricsReaderFactory.Initialize(logger); err != nil { + if err := metricsReaderFactory.Initialize(telset); err != nil { return nil, fmt.Errorf("failed to init metrics reader factory: %w", err) } // Ensure default parameter values are loaded correctly. - metricsReaderFactory.InitFromViper(v, logger) + metricsReaderFactory.InitFromViper(v, telset.Logger) reader, err := metricsReaderFactory.CreateMetricsReader() if err != nil { return nil, fmt.Errorf("failed to create metrics reader: %w", err) } - // Decorate the metrics reader with metrics instrumentation. - return metricstoremetrics.NewReaderDecorator(reader, metricsReaderMetricsFactory), nil + return reader, nil } diff --git a/plugin/metrics/disabled/factory.go b/plugin/metrics/disabled/factory.go index fa7aa9f529d..b630760f8a9 100644 --- a/plugin/metrics/disabled/factory.go +++ b/plugin/metrics/disabled/factory.go @@ -9,6 +9,7 @@ import ( "github.com/spf13/viper" "go.uber.org/zap" + "github.com/jaegertracing/jaeger/pkg/telemetry" "github.com/jaegertracing/jaeger/plugin" "github.com/jaegertracing/jaeger/storage/metricsstore" ) @@ -30,7 +31,7 @@ func (*Factory) AddFlags(_ *flag.FlagSet) {} func (*Factory) InitFromViper(_ *viper.Viper, _ *zap.Logger) {} // Initialize implements storage.MetricsFactory. -func (*Factory) Initialize(_ *zap.Logger) error { +func (*Factory) Initialize(_ telemetry.Settings) error { return nil } diff --git a/plugin/metrics/disabled/factory_test.go b/plugin/metrics/disabled/factory_test.go index fac3e142fc4..d26d97b1010 100644 --- a/plugin/metrics/disabled/factory_test.go +++ b/plugin/metrics/disabled/factory_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap" + "github.com/jaegertracing/jaeger/pkg/telemetry" "github.com/jaegertracing/jaeger/storage" ) @@ -17,9 +18,9 @@ var _ storage.MetricsFactory = new(Factory) func TestPrometheusFactory(t *testing.T) { f := NewFactory() - require.NoError(t, f.Initialize(zap.NewNop())) + require.NoError(t, f.Initialize(telemetry.NoopSettings())) - err := f.Initialize(nil) + err := f.Initialize(telemetry.NoopSettings()) require.NoError(t, err) f.AddFlags(nil) diff --git a/plugin/metrics/factory.go b/plugin/metrics/factory.go index fd663838a03..1e5e5830247 100644 --- a/plugin/metrics/factory.go +++ b/plugin/metrics/factory.go @@ -10,6 +10,8 @@ import ( "github.com/spf13/viper" "go.uber.org/zap" + "github.com/jaegertracing/jaeger/pkg/metrics" + "github.com/jaegertracing/jaeger/pkg/telemetry" "github.com/jaegertracing/jaeger/plugin" "github.com/jaegertracing/jaeger/plugin/metrics/disabled" "github.com/jaegertracing/jaeger/plugin/metrics/prometheus" @@ -63,9 +65,17 @@ func (*Factory) getFactoryOfType(factoryType string) (storage.MetricsFactory, er } // Initialize implements storage.MetricsFactory. -func (f *Factory) Initialize(logger *zap.Logger) error { - for _, factory := range f.factories { - factory.Initialize(logger) +func (f *Factory) Initialize(telset telemetry.Settings) error { + for kind, factory := range f.factories { + scopedTelset := telset + scopedTelset.Metrics = telset.Metrics.Namespace(metrics.NSOptions{ + Name: "storage", + Tags: map[string]string{ + "kind": kind, + "role": "metricstore", + }, + }) + factory.Initialize(scopedTelset) } return nil } diff --git a/plugin/metrics/factory_test.go b/plugin/metrics/factory_test.go index d7f6229b6eb..555b0c027f2 100644 --- a/plugin/metrics/factory_test.go +++ b/plugin/metrics/factory_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap" + "github.com/jaegertracing/jaeger/pkg/telemetry" "github.com/jaegertracing/jaeger/plugin/metrics/disabled" "github.com/jaegertracing/jaeger/storage" "github.com/jaegertracing/jaeger/storage/mocks" @@ -53,7 +54,7 @@ func TestCreateMetricsReader(t *testing.T) { require.NoError(t, err) require.NotNil(t, f) - require.NoError(t, f.Initialize(zap.NewNop())) + require.NoError(t, f.Initialize(telemetry.NoopSettings())) reader, err := f.CreateMetricsReader() require.NoError(t, err) diff --git a/plugin/metrics/prometheus/factory.go b/plugin/metrics/prometheus/factory.go index 56c63456de0..8aaa0d2e1af 100644 --- a/plugin/metrics/prometheus/factory.go +++ b/plugin/metrics/prometheus/factory.go @@ -7,14 +7,14 @@ import ( "flag" "github.com/spf13/viper" - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/trace" "go.uber.org/zap" "github.com/jaegertracing/jaeger/pkg/prometheus/config" + "github.com/jaegertracing/jaeger/pkg/telemetry" "github.com/jaegertracing/jaeger/plugin" prometheusstore "github.com/jaegertracing/jaeger/plugin/metrics/prometheus/metricsstore" "github.com/jaegertracing/jaeger/storage/metricsstore" + "github.com/jaegertracing/jaeger/storage/metricsstore/metricstoremetrics" ) var _ plugin.Configurable = (*Factory)(nil) @@ -22,14 +22,14 @@ var _ plugin.Configurable = (*Factory)(nil) // Factory implements storage.Factory and creates storage components backed by memory store. type Factory struct { options *Options - logger *zap.Logger - tracer trace.TracerProvider + telset telemetry.Settings } // NewFactory creates a new Factory. func NewFactory() *Factory { + telset := telemetry.NoopSettings() return &Factory{ - tracer: otel.GetTracerProvider(), + telset: telset, options: NewOptions(), } } @@ -47,19 +47,23 @@ func (f *Factory) InitFromViper(v *viper.Viper, logger *zap.Logger) { } // Initialize implements storage.MetricsFactory. -func (f *Factory) Initialize(logger *zap.Logger) error { - f.logger = logger +func (f *Factory) Initialize(telset telemetry.Settings) error { + f.telset = telset return nil } // CreateMetricsReader implements storage.MetricsFactory. func (f *Factory) CreateMetricsReader() (metricsstore.Reader, error) { - return prometheusstore.NewMetricsReader(f.options.Configuration, f.logger, f.tracer) + mr, err := prometheusstore.NewMetricsReader(f.options.Configuration, f.telset.Logger, f.telset.TracerProvider) + if err != nil { + return nil, err + } + return metricstoremetrics.NewReaderDecorator(mr, f.telset.Metrics), nil } func NewFactoryWithConfig( cfg config.Configuration, - logger *zap.Logger, + telset telemetry.Settings, ) (*Factory, error) { if err := cfg.Validate(); err != nil { return nil, err @@ -68,6 +72,6 @@ func NewFactoryWithConfig( f.options = &Options{ Configuration: cfg, } - f.Initialize(logger) + f.Initialize(telset) return f, nil } diff --git a/plugin/metrics/prometheus/factory_test.go b/plugin/metrics/prometheus/factory_test.go index 8662badb54a..c14778928d5 100644 --- a/plugin/metrics/prometheus/factory_test.go +++ b/plugin/metrics/prometheus/factory_test.go @@ -14,6 +14,7 @@ import ( "github.com/jaegertracing/jaeger/pkg/config" promCfg "github.com/jaegertracing/jaeger/pkg/prometheus/config" + "github.com/jaegertracing/jaeger/pkg/telemetry" "github.com/jaegertracing/jaeger/pkg/testutils" "github.com/jaegertracing/jaeger/storage" ) @@ -22,8 +23,8 @@ var _ storage.MetricsFactory = new(Factory) func TestPrometheusFactory(t *testing.T) { f := NewFactory() - require.NoError(t, f.Initialize(zap.NewNop())) - assert.NotNil(t, f.logger) + require.NoError(t, f.Initialize(telemetry.NoopSettings())) + assert.NotNil(t, f.telset) listener, err := net.Listen("tcp", "localhost:") require.NoError(t, err) @@ -37,6 +38,15 @@ func TestPrometheusFactory(t *testing.T) { assert.NotNil(t, reader) } +func TestCreateMetricsReaderError(t *testing.T) { + f := NewFactory() + f.options.TLS.CAFile = "/does/not/exist" + require.NoError(t, f.Initialize(telemetry.NoopSettings())) + reader, err := f.CreateMetricsReader() + require.Error(t, err) + require.Nil(t, reader) +} + func TestWithDefaultConfiguration(t *testing.T) { f := NewFactory() assert.Equal(t, "http://localhost:9090", f.options.ServerURL) @@ -126,7 +136,7 @@ func TestFailedTLSOptions(t *testing.T) { func TestEmptyFactoryConfig(t *testing.T) { cfg := promCfg.Configuration{} - _, err := NewFactoryWithConfig(cfg, zap.NewNop()) + _, err := NewFactoryWithConfig(cfg, telemetry.NoopSettings()) require.Error(t, err) } @@ -134,7 +144,7 @@ func TestFactoryConfig(t *testing.T) { cfg := promCfg.Configuration{ ServerURL: "localhost:1234", } - _, err := NewFactoryWithConfig(cfg, zap.NewNop()) + _, err := NewFactoryWithConfig(cfg, telemetry.NoopSettings()) require.NoError(t, err) } diff --git a/storage/factory.go b/storage/factory.go index ca4afe34259..efe4414543b 100644 --- a/storage/factory.go +++ b/storage/factory.go @@ -12,6 +12,7 @@ import ( "github.com/jaegertracing/jaeger/pkg/distributedlock" "github.com/jaegertracing/jaeger/pkg/metrics" + "github.com/jaegertracing/jaeger/pkg/telemetry" "github.com/jaegertracing/jaeger/storage/dependencystore" "github.com/jaegertracing/jaeger/storage/metricsstore" "github.com/jaegertracing/jaeger/storage/samplingstore" @@ -86,7 +87,7 @@ type ArchiveFactory interface { type MetricsFactory interface { // Initialize performs internal initialization of the factory, such as opening connections to the backend store. // It is called after all configuration of the factory itself has been done. - Initialize(logger *zap.Logger) error + Initialize(telset telemetry.Settings) error // CreateMetricsReader creates a metricsstore.Reader. CreateMetricsReader() (metricsstore.Reader, error) diff --git a/storage/mocks/MetricsFactory.go b/storage/mocks/MetricsFactory.go index 4d5d5823450..f2a087dee88 100644 --- a/storage/mocks/MetricsFactory.go +++ b/storage/mocks/MetricsFactory.go @@ -11,7 +11,7 @@ import ( metricsstore "github.com/jaegertracing/jaeger/storage/metricsstore" mock "github.com/stretchr/testify/mock" - zap "go.uber.org/zap" + telemetry "github.com/jaegertracing/jaeger/pkg/telemetry" ) // MetricsFactory is an autogenerated mock type for the MetricsFactory type @@ -49,17 +49,17 @@ func (_m *MetricsFactory) CreateMetricsReader() (metricsstore.Reader, error) { return r0, r1 } -// Initialize provides a mock function with given fields: logger -func (_m *MetricsFactory) Initialize(logger *zap.Logger) error { - ret := _m.Called(logger) +// Initialize provides a mock function with given fields: telset +func (_m *MetricsFactory) Initialize(telset telemetry.Settings) error { + ret := _m.Called(telset) if len(ret) == 0 { panic("no return value specified for Initialize") } var r0 error - if rf, ok := ret.Get(0).(func(*zap.Logger) error); ok { - r0 = rf(logger) + if rf, ok := ret.Get(0).(func(telemetry.Settings) error); ok { + r0 = rf(telset) } else { r0 = ret.Error(0) }