Skip to content

Commit

Permalink
Use Initialize instead of InitializeMetricsFactory
Browse files Browse the repository at this point in the history
Signed-off-by: FlamingSaint <[email protected]>
  • Loading branch information
FlamingSaint committed Jul 14, 2024
1 parent 636191b commit c39f8ec
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 25 deletions.
2 changes: 1 addition & 1 deletion cmd/all-in-one/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
25 changes: 15 additions & 10 deletions cmd/jaeger/internal/extension/jaegerquery/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,32 @@ 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")
}
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)
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/query/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion plugin/metrics/disabled/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions plugin/metrics/disabled/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions plugin/metrics/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/metrics/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions plugin/metrics/prometheus/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/metrics/prometheus/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:")
Expand Down
2 changes: 1 addition & 1 deletion storage/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions storage/mocks/MetricsFactory.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c39f8ec

Please sign in to comment.