diff --git a/cmd/all-in-one/main.go b/cmd/all-in-one/main.go index d19332b2614..a051573e5a6 100644 --- a/cmd/all-in-one/main.go +++ b/cmd/all-in-one/main.go @@ -302,7 +302,7 @@ func createMetricsQueryService( logger *zap.Logger, metricsReaderMetricsFactory metrics.Factory, ) (querysvc.MetricsQueryService, error) { - if err := metricsReaderFactory.InitializeMetricsFactory(logger); err != nil { + if err := metricsReaderFactory.Initialize(logger); err != nil { return nil, fmt.Errorf("failed to init metrics reader factory: %w", err) } diff --git a/cmd/jaeger/internal/extension/jaegerquery/server_test.go b/cmd/jaeger/internal/extension/jaegerquery/server_test.go index 55845bd46a8..c5107c4339d 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server_test.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server_test.go @@ -56,13 +56,6 @@ func (ff fakeFactory) CreateSpanWriter() (spanstore.Writer, error) { return &spanstoremocks.Writer{}, nil } -func (ff fakeFactory) CreateMetricsReader() (metricsstore.Reader, error) { - if ff.name == "need-span-writer-error" { - return nil, fmt.Errorf("test-error") - } - return &metricsstoremocks.Reader{}, nil -} - func (ff fakeFactory) Initialize(metrics.Factory, *zap.Logger) error { if ff.name == "need-initialize-error" { return fmt.Errorf("test-error") @@ -70,13 +63,25 @@ func (ff fakeFactory) Initialize(metrics.Factory, *zap.Logger) error { return nil } -func (ff fakeFactory) InitializeMetricsFactory(*zap.Logger) error { - if ff.name == "need-initialize-error" { +type fakeMetricsFactory struct { + name string +} + +// Initialize implements storage.MetricsFactory. +func (fmf fakeMetricsFactory) Initialize(*zap.Logger) error { + if fmf.name == "need-initialize-error" { return fmt.Errorf("test-error") } return nil } +func (fmf fakeMetricsFactory) CreateMetricsReader() (metricsstore.Reader, error) { + if fmf.name == "need-span-writer-error" { + return nil, fmt.Errorf("test-error") + } + return &metricsstoremocks.Reader{}, nil +} + type fakeStorageExt struct{} var _ jaegerstorage.Extension = (*fakeStorageExt)(nil) @@ -92,7 +97,7 @@ func (fakeStorageExt) MetricsFactory(name string) (storage.MetricsFactory, bool) if name == "need-factory-error" { return nil, false } - return fakeFactory{name: name}, true + return fakeMetricsFactory{name: name}, true } func (fakeStorageExt) Start(context.Context, component.Host) error { diff --git a/cmd/query/main.go b/cmd/query/main.go index 249fc15cdb5..36c54c63197 100644 --- a/cmd/query/main.go +++ b/cmd/query/main.go @@ -170,7 +170,7 @@ func createMetricsQueryService( logger *zap.Logger, metricsReaderMetricsFactory metrics.Factory, ) (querysvc.MetricsQueryService, error) { - if err := metricsReaderFactory.InitializeMetricsFactory(logger); err != nil { + if err := metricsReaderFactory.Initialize(logger); err != nil { return nil, fmt.Errorf("failed to init metrics reader factory: %w", err) } diff --git a/plugin/metrics/disabled/factory.go b/plugin/metrics/disabled/factory.go index 88aaeb30a44..48ca5de3e2f 100644 --- a/plugin/metrics/disabled/factory.go +++ b/plugin/metrics/disabled/factory.go @@ -41,7 +41,7 @@ func (*Factory) AddFlags(_ *flag.FlagSet) {} func (*Factory) InitFromViper(_ *viper.Viper, _ *zap.Logger) {} // Initialize implements storage.MetricsFactory. -func (*Factory) InitializeMetricsFactory(_ *zap.Logger) error { +func (*Factory) Initialize(_ *zap.Logger) error { return nil } diff --git a/plugin/metrics/disabled/factory_test.go b/plugin/metrics/disabled/factory_test.go index f38252e3268..3504edbd723 100644 --- a/plugin/metrics/disabled/factory_test.go +++ b/plugin/metrics/disabled/factory_test.go @@ -28,9 +28,9 @@ var _ storage.MetricsFactory = new(Factory) func TestPrometheusFactory(t *testing.T) { f := NewFactory() - require.NoError(t, f.InitializeMetricsFactory(zap.NewNop())) + require.NoError(t, f.Initialize(zap.NewNop())) - err := f.InitializeMetricsFactory(nil) + err := f.Initialize(nil) require.NoError(t, err) f.AddFlags(nil) diff --git a/plugin/metrics/factory.go b/plugin/metrics/factory.go index 764edd16907..48b54bc7866 100644 --- a/plugin/metrics/factory.go +++ b/plugin/metrics/factory.go @@ -74,9 +74,9 @@ func (*Factory) getFactoryOfType(factoryType string) (storage.MetricsFactory, er } // Initialize implements storage.MetricsFactory. -func (f *Factory) InitializeMetricsFactory(logger *zap.Logger) error { +func (f *Factory) Initialize(logger *zap.Logger) error { for _, factory := range f.factories { - factory.InitializeMetricsFactory(logger) + factory.Initialize(logger) } return nil } diff --git a/plugin/metrics/factory_test.go b/plugin/metrics/factory_test.go index b0134802e46..0cacf652612 100644 --- a/plugin/metrics/factory_test.go +++ b/plugin/metrics/factory_test.go @@ -64,7 +64,7 @@ func TestCreateMetricsReader(t *testing.T) { require.NoError(t, err) require.NotNil(t, f) - require.NoError(t, f.InitializeMetricsFactory(zap.NewNop())) + require.NoError(t, f.Initialize(zap.NewNop())) reader, err := f.CreateMetricsReader() require.NoError(t, err) diff --git a/plugin/metrics/prometheus/factory.go b/plugin/metrics/prometheus/factory.go index 62206969d0b..3ac09b963b9 100644 --- a/plugin/metrics/prometheus/factory.go +++ b/plugin/metrics/prometheus/factory.go @@ -58,7 +58,7 @@ func (f *Factory) InitFromViper(v *viper.Viper, logger *zap.Logger) { } // Initialize implements storage.MetricsFactory. -func (f *Factory) InitializeMetricsFactory(logger *zap.Logger) error { +func (f *Factory) Initialize(logger *zap.Logger) error { f.logger = logger return nil } @@ -80,7 +80,7 @@ func NewFactoryWithConfig( f.options = &Options{ Configuration: cfg, } - err := f.InitializeMetricsFactory(logger) + err := f.Initialize(logger) if err != nil { return nil, err } diff --git a/plugin/metrics/prometheus/factory_test.go b/plugin/metrics/prometheus/factory_test.go index c63b77151d1..bd49eca32d5 100644 --- a/plugin/metrics/prometheus/factory_test.go +++ b/plugin/metrics/prometheus/factory_test.go @@ -32,7 +32,7 @@ var _ storage.MetricsFactory = new(Factory) func TestPrometheusFactory(t *testing.T) { f := NewFactory() - require.NoError(t, f.InitializeMetricsFactory(zap.NewNop())) + require.NoError(t, f.Initialize(zap.NewNop())) assert.NotNil(t, f.logger) listener, err := net.Listen("tcp", "localhost:") diff --git a/storage/factory.go b/storage/factory.go index b7c7fa6e759..61ef31f969b 100644 --- a/storage/factory.go +++ b/storage/factory.go @@ -100,7 +100,7 @@ var ( 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. - InitializeMetricsFactory(logger *zap.Logger) error // Tests will fail as MetricsFactory and Factory Interface require Initialize but with different param's + Initialize(logger *zap.Logger) error // Tests will fail as MetricsFactory and Factory Interface require Initialize but with different param's // CreateMetricsReader creates a metricsstore.Reader. CreateMetricsReader() (metricsstore.Reader, error) diff --git a/storage/mocks/MetricsFactory.go b/storage/mocks/MetricsFactory.go index b27d2c91631..4d5d5823450 100644 --- a/storage/mocks/MetricsFactory.go +++ b/storage/mocks/MetricsFactory.go @@ -49,12 +49,12 @@ func (_m *MetricsFactory) CreateMetricsReader() (metricsstore.Reader, error) { return r0, r1 } -// InitializeMetricsFactory provides a mock function with given fields: logger -func (_m *MetricsFactory) InitializeMetricsFactory(logger *zap.Logger) error { +// Initialize provides a mock function with given fields: logger +func (_m *MetricsFactory) Initialize(logger *zap.Logger) error { ret := _m.Called(logger) if len(ret) == 0 { - panic("no return value specified for InitializeMetricsFactory") + panic("no return value specified for Initialize") } var r0 error