diff --git a/cmd/all-in-one/main.go b/cmd/all-in-one/main.go index 056467f0c37..8f2dd9f9efa 100644 --- a/cmd/all-in-one/main.go +++ b/cmd/all-in-one/main.go @@ -117,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, baseFactory) + metricsQueryService, err := createMetricsQueryService(metricsReaderFactory, v, baseTelset) if err != nil { logger.Fatal("Failed to create metrics reader", zap.Error(err)) } @@ -237,15 +237,14 @@ 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(metricsReaderMetricsFactory, 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) diff --git a/cmd/jaeger/internal/extension/jaegerquery/server_test.go b/cmd/jaeger/internal/extension/jaegerquery/server_test.go index ecdabc623f4..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(metrics.Factory, *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 4be154595d9..13fcbe54abf 100644 --- a/cmd/jaeger/internal/extension/jaegerstorage/extension.go +++ b/cmd/jaeger/internal/extension/jaegerstorage/extension.go @@ -177,10 +177,11 @@ func (s *storageExt) Start(_ context.Context, host component.Host) error { var metricsFactory storage.MetricsFactory var err error if cfg.Prometheus != nil { + promTelset := telset + promTelset.Metrics = scopedMetricsFactory(metricStorageName, "prometheus") metricsFactory, err = prometheus.NewFactoryWithConfig( *cfg.Prometheus, - scopedMetricsFactory(metricStorageName, "prometheus"), - s.telset.Logger) + 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 df00f37e272..67425b2c9cc 100644 --- a/cmd/query/main.go +++ b/cmd/query/main.go @@ -98,7 +98,7 @@ func main() { logger.Fatal("Failed to create dependency reader", zap.Error(err)) } - metricsQueryService, err := createMetricsQueryService(metricsReaderFactory, v, logger, baseFactory) + metricsQueryService, err := createMetricsQueryService(metricsReaderFactory, v, baseTelset) if err != nil { logger.Fatal("Failed to create metrics query service", zap.Error(err)) } @@ -165,15 +165,14 @@ 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(metricsReaderMetricsFactory, 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) diff --git a/plugin/metrics/disabled/factory.go b/plugin/metrics/disabled/factory.go index 0b407d674d5..b630760f8a9 100644 --- a/plugin/metrics/disabled/factory.go +++ b/plugin/metrics/disabled/factory.go @@ -9,7 +9,7 @@ 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/storage/metricsstore" ) @@ -31,7 +31,7 @@ func (*Factory) AddFlags(_ *flag.FlagSet) {} func (*Factory) InitFromViper(_ *viper.Viper, _ *zap.Logger) {} // Initialize implements storage.MetricsFactory. -func (*Factory) Initialize(_ metrics.Factory, _ *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 5caac5d9fbf..d26d97b1010 100644 --- a/plugin/metrics/disabled/factory_test.go +++ b/plugin/metrics/disabled/factory_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap" - "github.com/jaegertracing/jaeger/pkg/metrics" + "github.com/jaegertracing/jaeger/pkg/telemetry" "github.com/jaegertracing/jaeger/storage" ) @@ -18,9 +18,9 @@ var _ storage.MetricsFactory = new(Factory) func TestPrometheusFactory(t *testing.T) { f := NewFactory() - require.NoError(t, f.Initialize(metrics.NullFactory, zap.NewNop())) + require.NoError(t, f.Initialize(telemetry.NoopSettings())) - err := f.Initialize(metrics.NullFactory, 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 2cf96bc2de0..d6ecf7214ec 100644 --- a/plugin/metrics/factory.go +++ b/plugin/metrics/factory.go @@ -11,6 +11,7 @@ import ( "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" @@ -64,15 +65,16 @@ func (*Factory) getFactoryOfType(factoryType string) (storage.MetricsFactory, er } // Initialize implements storage.MetricsFactory. -func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error { +func (f *Factory) Initialize(telset telemetry.Settings) error { for kind, factory := range f.factories { - mf := metricsFactory.Namespace(metrics.NSOptions{ + scopedTelset := telset + scopedTelset.Metrics = telset.Metrics.Namespace(metrics.NSOptions{ Name: "storage", Tags: map[string]string{ "kind": kind, }, }) - factory.Initialize(mf, logger) + factory.Initialize(scopedTelset) } return nil } diff --git a/plugin/metrics/factory_test.go b/plugin/metrics/factory_test.go index 2e4e306e076..555b0c027f2 100644 --- a/plugin/metrics/factory_test.go +++ b/plugin/metrics/factory_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap" - "github.com/jaegertracing/jaeger/pkg/metrics" + "github.com/jaegertracing/jaeger/pkg/telemetry" "github.com/jaegertracing/jaeger/plugin/metrics/disabled" "github.com/jaegertracing/jaeger/storage" "github.com/jaegertracing/jaeger/storage/mocks" @@ -54,7 +54,7 @@ func TestCreateMetricsReader(t *testing.T) { require.NoError(t, err) require.NotNil(t, f) - require.NoError(t, f.Initialize(metrics.NullFactory, 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 61290dcf3f9..aaa47c7d86f 100644 --- a/plugin/metrics/prometheus/factory.go +++ b/plugin/metrics/prometheus/factory.go @@ -7,12 +7,10 @@ import ( "flag" "github.com/spf13/viper" - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/trace" "go.uber.org/zap" - "github.com/jaegertracing/jaeger/pkg/metrics" "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" @@ -23,16 +21,15 @@ 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 - metricsFactory metrics.Factory + options *Options + telset telemetry.Settings } // NewFactory creates a new Factory. func NewFactory() *Factory { + telset := telemetry.NoopSettings() return &Factory{ - tracer: otel.GetTracerProvider(), + telset: telset, options: NewOptions(), } } @@ -50,24 +47,23 @@ func (f *Factory) InitFromViper(v *viper.Viper, logger *zap.Logger) { } // Initialize implements storage.MetricsFactory. -func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error { - f.metricsFactory, f.logger = metricsFactory, 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) { - mr, err := 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 mr, err } - return metricstoremetrics.NewReaderDecorator(mr, f.metricsFactory), nil + return metricstoremetrics.NewReaderDecorator(mr, f.telset.Metrics), nil } func NewFactoryWithConfig( cfg config.Configuration, - metricsFactory metrics.Factory, - logger *zap.Logger, + telset telemetry.Settings, ) (*Factory, error) { if err := cfg.Validate(); err != nil { return nil, err @@ -76,6 +72,6 @@ func NewFactoryWithConfig( f.options = &Options{ Configuration: cfg, } - f.Initialize(metricsFactory, logger) + f.Initialize(telset) return f, nil } diff --git a/plugin/metrics/prometheus/factory_test.go b/plugin/metrics/prometheus/factory_test.go index 8bf663558d8..b74c8354d80 100644 --- a/plugin/metrics/prometheus/factory_test.go +++ b/plugin/metrics/prometheus/factory_test.go @@ -13,8 +13,8 @@ import ( "go.uber.org/zap" "github.com/jaegertracing/jaeger/pkg/config" - "github.com/jaegertracing/jaeger/pkg/metrics" 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" ) @@ -23,8 +23,8 @@ var _ storage.MetricsFactory = new(Factory) func TestPrometheusFactory(t *testing.T) { f := NewFactory() - require.NoError(t, f.Initialize(metrics.NullFactory, 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) @@ -127,7 +127,7 @@ func TestFailedTLSOptions(t *testing.T) { func TestEmptyFactoryConfig(t *testing.T) { cfg := promCfg.Configuration{} - _, err := NewFactoryWithConfig(cfg, metrics.NullFactory, zap.NewNop()) + _, err := NewFactoryWithConfig(cfg, telemetry.NoopSettings()) require.Error(t, err) } @@ -135,7 +135,7 @@ func TestFactoryConfig(t *testing.T) { cfg := promCfg.Configuration{ ServerURL: "localhost:1234", } - _, err := NewFactoryWithConfig(cfg, metrics.NullFactory, zap.NewNop()) + _, err := NewFactoryWithConfig(cfg, telemetry.NoopSettings()) require.NoError(t, err) } diff --git a/storage/factory.go b/storage/factory.go index 4b73670b332..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(metricsFactory metrics.Factory, 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 368c070ded0..f2a087dee88 100644 --- a/storage/mocks/MetricsFactory.go +++ b/storage/mocks/MetricsFactory.go @@ -8,12 +8,10 @@ package mocks import ( - metrics "github.com/jaegertracing/jaeger/pkg/metrics" 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 @@ -51,17 +49,17 @@ func (_m *MetricsFactory) CreateMetricsReader() (metricsstore.Reader, error) { return r0, r1 } -// Initialize provides a mock function with given fields: metricsFactory, logger -func (_m *MetricsFactory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error { - ret := _m.Called(metricsFactory, 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(metrics.Factory, *zap.Logger) error); ok { - r0 = rf(metricsFactory, logger) + if rf, ok := ret.Get(0).(func(telemetry.Settings) error); ok { + r0 = rf(telset) } else { r0 = ret.Error(0) }