diff --git a/plugin/metrics/prometheus/factory.go b/plugin/metrics/prometheus/factory.go index aaa47c7d86f..8aaa0d2e1af 100644 --- a/plugin/metrics/prometheus/factory.go +++ b/plugin/metrics/prometheus/factory.go @@ -56,7 +56,7 @@ func (f *Factory) Initialize(telset telemetry.Settings) error { func (f *Factory) CreateMetricsReader() (metricsstore.Reader, error) { mr, err := prometheusstore.NewMetricsReader(f.options.Configuration, f.telset.Logger, f.telset.TracerProvider) if err != nil { - return mr, err + return nil, err } return metricstoremetrics.NewReaderDecorator(mr, f.telset.Metrics), nil } diff --git a/plugin/metrics/prometheus/factory_test.go b/plugin/metrics/prometheus/factory_test.go index b74c8354d80..c14778928d5 100644 --- a/plugin/metrics/prometheus/factory_test.go +++ b/plugin/metrics/prometheus/factory_test.go @@ -38,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)