Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid duplicate expvar metrics - fixes #716 #726

Merged
merged 3 commits into from
Mar 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions cmd/query/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,23 @@ func main() {
}

func archiveOptions(storageFactory istorage.Factory, logger *zap.Logger) []app.HandlerOption {
reader, err := storageFactory.CreateSpanReader()
archiveFactory, ok := storageFactory.(istorage.ArchiveFactory)
if !ok {
logger.Info("Archive storage not supported by the factory")
return nil
}
reader, err := archiveFactory.CreateArchiveSpanReader()
if err == istorage.ErrArchiveStorageNotConfigured || err == istorage.ErrArchiveStorageNotSupported {
logger.Info("Archive storage not created", zap.String("reason", err.Error()))
return nil
}
if err != nil {
logger.Error("Cannot init archive storage reader", zap.Error(err))
return nil
}
writer, err := storageFactory.CreateSpanWriter()
writer, err := archiveFactory.CreateArchiveSpanWriter()
if err == istorage.ErrArchiveStorageNotConfigured || err == istorage.ErrArchiveStorageNotSupported {
logger.Info("Archive storage not created", zap.String("reason", err.Error()))
return nil
}
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions examples/hotrod/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import (

"github.com/spf13/cobra"
"github.com/uber/jaeger-lib/metrics"
"github.com/uber/jaeger-lib/metrics/go-kit"
"github.com/uber/jaeger-lib/metrics/go-kit/expvar"
jexpvar "github.com/uber/jaeger-lib/metrics/expvar"
jprom "github.com/uber/jaeger-lib/metrics/prometheus"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -61,7 +60,7 @@ func init() {
// initMetrics is called before the command is executed.
func initMetrics() {
if metricsBackend == "expvar" {
metricsFactory = xkit.Wrap("", expvar.NewFactory(10)) // 10 buckets for histograms
metricsFactory = jexpvar.NewFactory(10) // 10 buckets for histograms
logger.Info("Using expvar as metrics backend")
} else if metricsBackend == "prometheus" {
metricsFactory = jprom.New()
Expand Down
12 changes: 7 additions & 5 deletions glide.lock

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

2 changes: 1 addition & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import:
subpackages:
- transport
- package: github.com/uber/jaeger-lib
version: ^1.2.1
version: ^1.4.0
- package: github.com/uber/tchannel-go
version: v1.1.0
subpackages:
Expand Down
5 changes: 2 additions & 3 deletions pkg/metrics/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/spf13/viper"
"github.com/uber/jaeger-lib/metrics"
xkit "github.com/uber/jaeger-lib/metrics/go-kit"
kitexpvar "github.com/uber/jaeger-lib/metrics/go-kit/expvar"
jexpvar "github.com/uber/jaeger-lib/metrics/expvar"
jprom "github.com/uber/jaeger-lib/metrics/prometheus"
)

Expand Down Expand Up @@ -73,7 +72,7 @@ func (b *Builder) CreateMetricsFactory(namespace string) (metrics.Factory, error
return metricsFactory, nil
}
if b.Backend == "expvar" {
metricsFactory := xkit.Wrap(namespace, kitexpvar.NewFactory(10))
metricsFactory := jexpvar.NewFactory(10).Namespace(namespace, nil)
b.handler = expvar.Handler()
return metricsFactory, nil
}
Expand Down
21 changes: 13 additions & 8 deletions plugin/storage/cassandra/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ const (
type Factory struct {
Options *Options

metricsFactory metrics.Factory
logger *zap.Logger
primaryMetricsFactory metrics.Factory
archiveMetricsFactory metrics.Factory
logger *zap.Logger

primaryConfig config.SessionBuilder
primarySession cassandra.Session
Expand Down Expand Up @@ -71,7 +72,9 @@ func (f *Factory) InitFromViper(v *viper.Viper) {

// Initialize implements storage.Factory
func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error {
f.metricsFactory, f.logger = metricsFactory, logger
f.primaryMetricsFactory = metricsFactory.Namespace("cassandra", nil)
f.archiveMetricsFactory = metricsFactory.Namespace("cassandra-archive", nil)
f.logger = logger

primarySession, err := f.primaryConfig.NewSession()
if err != nil {
Expand All @@ -85,37 +88,39 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger)
} else {
return err
}
} else {
logger.Info("Cassandra archive storage configuration is empty, skipping")
}
return nil
}

// CreateSpanReader implements storage.Factory
func (f *Factory) CreateSpanReader() (spanstore.Reader, error) {
return cSpanStore.NewSpanReader(f.primarySession, f.metricsFactory, f.logger), nil
return cSpanStore.NewSpanReader(f.primarySession, f.primaryMetricsFactory, f.logger), nil
}

// CreateSpanWriter implements storage.Factory
func (f *Factory) CreateSpanWriter() (spanstore.Writer, error) {
return cSpanStore.NewSpanWriter(f.primarySession, f.Options.SpanStoreWriteCacheTTL, f.metricsFactory, f.logger), nil
return cSpanStore.NewSpanWriter(f.primarySession, f.Options.SpanStoreWriteCacheTTL, f.primaryMetricsFactory, f.logger), nil
}

// CreateDependencyReader implements storage.Factory
func (f *Factory) CreateDependencyReader() (dependencystore.Reader, error) {
return cDepStore.NewDependencyStore(f.primarySession, f.Options.DepStoreDataFrequency, f.metricsFactory, f.logger), nil
return cDepStore.NewDependencyStore(f.primarySession, f.Options.DepStoreDataFrequency, f.primaryMetricsFactory, f.logger), nil
}

// CreateArchiveSpanReader implements storage.ArchiveFactory
func (f *Factory) CreateArchiveSpanReader() (spanstore.Reader, error) {
if f.archiveSession == nil {
return nil, storage.ErrArchiveStorageNotConfigured
}
return cSpanStore.NewSpanReader(f.archiveSession, f.metricsFactory, f.logger), nil
return cSpanStore.NewSpanReader(f.archiveSession, f.archiveMetricsFactory, f.logger), nil
}

// CreateArchiveSpanWriter implements storage.ArchiveFactory
func (f *Factory) CreateArchiveSpanWriter() (spanstore.Writer, error) {
if f.archiveSession == nil {
return nil, storage.ErrArchiveStorageNotConfigured
}
return cSpanStore.NewSpanWriter(f.archiveSession, f.Options.SpanStoreWriteCacheTTL, f.metricsFactory, f.logger), nil
return cSpanStore.NewSpanWriter(f.archiveSession, f.Options.SpanStoreWriteCacheTTL, f.archiveMetricsFactory, f.logger), nil
}
5 changes: 4 additions & 1 deletion plugin/storage/cassandra/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/jaegertracing/jaeger/pkg/cassandra"
"github.com/jaegertracing/jaeger/pkg/cassandra/mocks"
"github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/testutils"
"github.com/jaegertracing/jaeger/storage"
)

Expand All @@ -43,6 +44,7 @@ func (m *mockSessionBuilder) NewSession() (cassandra.Session, error) {
}

func TestCassandraFactory(t *testing.T) {
logger, logBuf := testutils.NewLogger()
f := NewFactory()
v, command := config.Viperize(f.AddFlags)
command.ParseFlags([]string{"--cassandra-archive.enabled=true"})
Expand All @@ -58,7 +60,8 @@ func TestCassandraFactory(t *testing.T) {
assert.EqualError(t, f.Initialize(metrics.NullFactory, zap.NewNop()), "made-up error")

f.archiveConfig = nil
assert.NoError(t, f.Initialize(metrics.NullFactory, zap.NewNop()))
assert.NoError(t, f.Initialize(metrics.NullFactory, logger))
assert.Contains(t, logBuf.String(), "Cassandra archive storage configuration is empty, skipping")

_, err := f.CreateSpanReader()
assert.NoError(t, err)
Expand Down