diff --git a/pkg/testutils/logger.go b/pkg/testutils/logger.go index 00fe2b63969..0ffee92e671 100644 --- a/pkg/testutils/logger.go +++ b/pkg/testutils/logger.go @@ -30,7 +30,7 @@ import ( // NewLogger creates a new zap.Logger backed by a zaptest.Buffer, which is also returned. func NewLogger() (*zap.Logger, *Buffer) { core, buf := newRecordingCore() - logger := zap.New(core) + logger := zap.New(core, zap.OnFatal(zapcore.WriteThenPanic)) return logger, buf } diff --git a/plugin/metrics/disabled/factory.go b/plugin/metrics/disabled/factory.go index c3ec9800caf..ea3a4975340 100644 --- a/plugin/metrics/disabled/factory.go +++ b/plugin/metrics/disabled/factory.go @@ -20,9 +20,12 @@ import ( "github.com/spf13/viper" "go.uber.org/zap" + "github.com/jaegertracing/jaeger/plugin" "github.com/jaegertracing/jaeger/storage/metricsstore" ) +var _ plugin.Configurable = (*Factory)(nil) + // Factory implements storage.Factory that returns a Disabled metrics reader. type Factory struct{} diff --git a/plugin/metrics/factory.go b/plugin/metrics/factory.go index d2be4d7cf7f..a9f8e23fc59 100644 --- a/plugin/metrics/factory.go +++ b/plugin/metrics/factory.go @@ -38,6 +38,8 @@ const ( // AllStorageTypes defines all available storage backends. var AllStorageTypes = []string{prometheusStorageType} +var _ plugin.Configurable = (*Factory)(nil) + // Factory implements storage.Factory interface as a meta-factory for storage components. type Factory struct { FactoryConfig diff --git a/plugin/metrics/prometheus/factory.go b/plugin/metrics/prometheus/factory.go index 99f74b3956b..3c1440cd3ab 100644 --- a/plugin/metrics/prometheus/factory.go +++ b/plugin/metrics/prometheus/factory.go @@ -20,10 +20,13 @@ import ( "github.com/spf13/viper" "go.uber.org/zap" + "github.com/jaegertracing/jaeger/plugin" prometheusstore "github.com/jaegertracing/jaeger/plugin/metrics/prometheus/metricsstore" "github.com/jaegertracing/jaeger/storage/metricsstore" ) +var _ plugin.Configurable = (*Factory)(nil) + // Factory implements storage.Factory and creates storage components backed by memory store. type Factory struct { options *Options @@ -43,8 +46,10 @@ func (f *Factory) AddFlags(flagSet *flag.FlagSet) { } // InitFromViper implements plugin.Configurable. -func (f *Factory) InitFromViper(v *viper.Viper, logger *zap.Logger) error { - return f.options.InitFromViper(v) +func (f *Factory) InitFromViper(v *viper.Viper, logger *zap.Logger) { + if err := f.options.InitFromViper(v); err != nil { + logger.Fatal("Failed to initialize metrics storage factory", zap.Error(err)) + } } // Initialize implements storage.MetricsFactory. diff --git a/plugin/metrics/prometheus/factory_test.go b/plugin/metrics/prometheus/factory_test.go index d57dbca2593..957d8142c22 100644 --- a/plugin/metrics/prometheus/factory_test.go +++ b/plugin/metrics/prometheus/factory_test.go @@ -24,6 +24,7 @@ import ( "go.uber.org/zap" "github.com/jaegertracing/jaeger/pkg/config" + "github.com/jaegertracing/jaeger/pkg/testutils" "github.com/jaegertracing/jaeger/storage" ) @@ -62,9 +63,7 @@ func TestWithConfiguration(t *testing.T) { }) require.NoError(t, err) - err = f.InitFromViper(v, zap.NewNop()) - - require.NoError(t, err) + f.InitFromViper(v, zap.NewNop()) assert.Equal(t, f.options.Primary.ServerURL, "http://localhost:1234") assert.Equal(t, f.options.Primary.ConnectTimeout, 5*time.Second) } @@ -78,7 +77,14 @@ func TestFailedTLSOptions(t *testing.T) { }) require.NoError(t, err) - err = f.InitFromViper(v, zap.NewNop()) - require.Error(t, err) - assert.Contains(t, err.Error(), "failed to process Prometheus TLS options") + logger, logOut := testutils.NewLogger() + + defer func() { + r := recover() + t.Logf("%v", r) + assert.Contains(t, logOut.Lines()[0], "failed to process Prometheus TLS options") + }() + + f.InitFromViper(v, logger) + t.Errorf("f.InitFromViper did not panic") } diff --git a/plugin/sampling/strategystore/adaptive/factory.go b/plugin/sampling/strategystore/adaptive/factory.go index c17a7b1b0cf..01d1f0feb27 100644 --- a/plugin/sampling/strategystore/adaptive/factory.go +++ b/plugin/sampling/strategystore/adaptive/factory.go @@ -24,10 +24,13 @@ import ( "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/strategystore" "github.com/jaegertracing/jaeger/pkg/distributedlock" + "github.com/jaegertracing/jaeger/plugin" "github.com/jaegertracing/jaeger/storage" "github.com/jaegertracing/jaeger/storage/samplingstore" ) +var _ plugin.Configurable = (*Factory)(nil) + // Factory implements strategystore.Factory for an adaptive strategy store. type Factory struct { options *Options diff --git a/plugin/sampling/strategystore/factory.go b/plugin/sampling/strategystore/factory.go index d97d2965c73..5cd9716a014 100644 --- a/plugin/sampling/strategystore/factory.go +++ b/plugin/sampling/strategystore/factory.go @@ -37,8 +37,11 @@ const ( samplingTypeFile = "file" ) +// AllSamplingTypes lists all types of sampling factories. var AllSamplingTypes = []string{samplingTypeFile, samplingTypeAdaptive} +var _ plugin.Configurable = (*Factory)(nil) + // Factory implements strategystore.Factory interface as a meta-factory for strategy storage components. type Factory struct { FactoryConfig diff --git a/plugin/sampling/strategystore/static/factory.go b/plugin/sampling/strategystore/static/factory.go index ec7603efb8f..01dc0d9477d 100644 --- a/plugin/sampling/strategystore/static/factory.go +++ b/plugin/sampling/strategystore/static/factory.go @@ -22,9 +22,12 @@ import ( "go.uber.org/zap" "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/strategystore" + "github.com/jaegertracing/jaeger/plugin" "github.com/jaegertracing/jaeger/storage" ) +var _ plugin.Configurable = (*Factory)(nil) + // Factory implements strategystore.Factory for a static strategy store. type Factory struct { options *Options diff --git a/plugin/storage/badger/factory.go b/plugin/storage/badger/factory.go index 484b6191d8c..e33ed914539 100644 --- a/plugin/storage/badger/factory.go +++ b/plugin/storage/badger/factory.go @@ -17,6 +17,7 @@ package badger import ( "expvar" "flag" + "io" "os" "strings" "time" @@ -26,6 +27,7 @@ import ( "github.com/uber/jaeger-lib/metrics" "go.uber.org/zap" + "github.com/jaegertracing/jaeger/plugin" depStore "github.com/jaegertracing/jaeger/plugin/storage/badger/dependencystore" badgerStore "github.com/jaegertracing/jaeger/plugin/storage/badger/spanstore" "github.com/jaegertracing/jaeger/storage/dependencystore" @@ -39,6 +41,11 @@ const ( lastValueLogCleanedName = "badger_storage_valueloggc_last_run" ) +var ( + _ io.Closer = (*Factory)(nil) + _ plugin.Configurable = (*Factory)(nil) +) + // Factory implements storage.Factory for Badger backend. type Factory struct { Options *Options diff --git a/plugin/storage/cassandra/factory.go b/plugin/storage/cassandra/factory.go index 9f3c288be46..3cc28d395f6 100644 --- a/plugin/storage/cassandra/factory.go +++ b/plugin/storage/cassandra/factory.go @@ -28,6 +28,7 @@ import ( "github.com/jaegertracing/jaeger/pkg/cassandra/config" "github.com/jaegertracing/jaeger/pkg/distributedlock" "github.com/jaegertracing/jaeger/pkg/hostname" + "github.com/jaegertracing/jaeger/plugin" cLock "github.com/jaegertracing/jaeger/plugin/pkg/distributedlock/cassandra" cDepStore "github.com/jaegertracing/jaeger/plugin/storage/cassandra/dependencystore" cSamplingStore "github.com/jaegertracing/jaeger/plugin/storage/cassandra/samplingstore" @@ -44,6 +45,11 @@ const ( archiveStorageConfig = "cassandra-archive" ) +var ( + _ io.Closer = (*Factory)(nil) + _ plugin.Configurable = (*Factory)(nil) +) + // Factory implements storage.Factory for Cassandra backend. type Factory struct { Options *Options diff --git a/plugin/storage/es/factory.go b/plugin/storage/es/factory.go index 7878d022016..69f53cdadbe 100644 --- a/plugin/storage/es/factory.go +++ b/plugin/storage/es/factory.go @@ -26,6 +26,7 @@ import ( "github.com/jaegertracing/jaeger/pkg/es" "github.com/jaegertracing/jaeger/pkg/es/config" + "github.com/jaegertracing/jaeger/plugin" esDepStore "github.com/jaegertracing/jaeger/plugin/storage/es/dependencystore" "github.com/jaegertracing/jaeger/plugin/storage/es/mappings" esSpanStore "github.com/jaegertracing/jaeger/plugin/storage/es/spanstore" @@ -38,6 +39,11 @@ const ( archiveNamespace = "es-archive" ) +var ( + _ io.Closer = (*Factory)(nil) + _ plugin.Configurable = (*Factory)(nil) +) + // Factory implements storage.Factory for Elasticsearch backend. type Factory struct { Options *Options diff --git a/plugin/storage/factory.go b/plugin/storage/factory.go index 3e0f7f8bf05..61f68ebede9 100644 --- a/plugin/storage/factory.go +++ b/plugin/storage/factory.go @@ -80,6 +80,11 @@ func AllSamplingStorageTypes() []string { return backends } +var ( + _ io.Closer = (*Factory)(nil) + _ plugin.Configurable = (*Factory)(nil) +) + // Factory implements storage.Factory interface as a meta-factory for storage components. type Factory struct { FactoryConfig diff --git a/plugin/storage/grpc/factory.go b/plugin/storage/grpc/factory.go index e8867059c5b..5a28c2e3cf7 100644 --- a/plugin/storage/grpc/factory.go +++ b/plugin/storage/grpc/factory.go @@ -23,6 +23,7 @@ import ( "github.com/uber/jaeger-lib/metrics" "go.uber.org/zap" + "github.com/jaegertracing/jaeger/plugin" "github.com/jaegertracing/jaeger/plugin/storage/grpc/config" "github.com/jaegertracing/jaeger/plugin/storage/grpc/shared" "github.com/jaegertracing/jaeger/storage" @@ -30,6 +31,11 @@ import ( "github.com/jaegertracing/jaeger/storage/spanstore" ) +var ( + _ io.Closer = (*Factory)(nil) + _ plugin.Configurable = (*Factory)(nil) +) + // Factory implements storage.Factory and creates storage components backed by a storage plugin. type Factory struct { options Options @@ -44,8 +50,6 @@ type Factory struct { capabilities shared.PluginCapabilities } -var _ io.Closer = (*Factory)(nil) - // NewFactory creates a new Factory. func NewFactory() *Factory { return &Factory{} diff --git a/plugin/storage/kafka/factory.go b/plugin/storage/kafka/factory.go index 6fd037c1c08..1956ad751f1 100644 --- a/plugin/storage/kafka/factory.go +++ b/plugin/storage/kafka/factory.go @@ -25,10 +25,16 @@ import ( "go.uber.org/zap" "github.com/jaegertracing/jaeger/pkg/kafka/producer" + "github.com/jaegertracing/jaeger/plugin" "github.com/jaegertracing/jaeger/storage/dependencystore" "github.com/jaegertracing/jaeger/storage/spanstore" ) +var ( + _ io.Closer = (*Factory)(nil) + _ plugin.Configurable = (*Factory)(nil) +) + // Factory implements storage.Factory and creates write-only storage components backed by kafka. type Factory struct { options Options diff --git a/plugin/storage/memory/factory.go b/plugin/storage/memory/factory.go index 6aa2c3d41ec..a3f4f165a7a 100644 --- a/plugin/storage/memory/factory.go +++ b/plugin/storage/memory/factory.go @@ -23,11 +23,14 @@ import ( "go.uber.org/zap" "github.com/jaegertracing/jaeger/pkg/distributedlock" + "github.com/jaegertracing/jaeger/plugin" "github.com/jaegertracing/jaeger/storage/dependencystore" "github.com/jaegertracing/jaeger/storage/samplingstore" "github.com/jaegertracing/jaeger/storage/spanstore" ) +var _ plugin.Configurable = (*Factory)(nil) + // Factory implements storage.Factory and creates storage components backed by memory store. type Factory struct { options Options