Skip to content

Commit

Permalink
Fix Prometheus factory signature (jaegertracing#3681)
Browse files Browse the repository at this point in the history
  • Loading branch information
yurishkuro committed May 16, 2022
1 parent a49094c commit 96e7464
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pkg/testutils/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions plugin/metrics/disabled/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down
2 changes: 2 additions & 0 deletions plugin/metrics/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions plugin/metrics/prometheus/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
18 changes: 12 additions & 6 deletions plugin/metrics/prometheus/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}
Expand All @@ -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")
}
3 changes: 3 additions & 0 deletions plugin/sampling/strategystore/adaptive/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions plugin/sampling/strategystore/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions plugin/sampling/strategystore/static/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions plugin/storage/badger/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package badger
import (
"expvar"
"flag"
"io"
"os"
"strings"
"time"
Expand All @@ -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"
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions plugin/storage/cassandra/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions plugin/storage/es/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions plugin/storage/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ const (
// AllStorageTypes defines all available storage backends
var AllStorageTypes = []string{cassandraStorageType, opensearchStorageType, elasticsearchStorageType, memoryStorageType, kafkaStorageType, badgerStorageType, grpcPluginStorageType}

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
Expand Down
8 changes: 6 additions & 2 deletions plugin/storage/grpc/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ 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"
"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 storage components backed by a storage plugin.
type Factory struct {
options Options
Expand All @@ -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{}
Expand Down
6 changes: 6 additions & 0 deletions plugin/storage/kafka/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions plugin/storage/memory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 96e7464

Please sign in to comment.