Skip to content

Commit

Permalink
Fix factory init, rename opts func
Browse files Browse the repository at this point in the history
Signed-off-by: Daniil Rutskiy <[email protected]>
  • Loading branch information
dstdfx committed Oct 1, 2020
1 parent 43f74e8 commit c6bbaf9
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 21 deletions.
4 changes: 2 additions & 2 deletions cmd/agent/app/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (b *Builder) CreateAgent(primaryProxy CollectorProxy, logger *zap.Logger, m
return nil, fmt.Errorf("cannot create processors: %w", err)
}
server := b.HTTPServer.getHTTPServer(primaryProxy.GetManager(), mFactory)
b.setExpvarOptions(mFactory)
b.publishOpts(mFactory)

return NewAgent(processors, server, logger), nil
}
Expand All @@ -129,7 +129,7 @@ func (b *Builder) getReporter(primaryProxy CollectorProxy) reporter.Reporter {
return reporter.NewMultiReporter(rep...)
}

func (b *Builder) setExpvarOptions(mFactory metrics.Factory) {
func (b *Builder) publishOpts(mFactory metrics.Factory) {
internalFactory := mFactory.Namespace(metrics.NSOptions{Name: "internal"})
for _, p := range b.Processors {
prefix := fmt.Sprintf(processorPrefixFmt, p.Model, p.Protocol)
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/app/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func TestCreateCollectorProxy_UnknownReporter(t *testing.T) {
assert.EqualError(t, err, "unknown reporter type ")
}

func TestSetExpvarOptions(t *testing.T) {
func TestPublishOpts(t *testing.T) {
v := viper.New()
cfg := &Builder{}
command := cobra.Command{}
Expand Down
8 changes: 5 additions & 3 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ func main() {
return err
}
logger := svc.Logger // shortcut
baseFactory := svc.MetricsFactory.Namespace(metrics.NSOptions{Name: "jaeger"})
baseFactory := svc.MetricsFactory.
Namespace(metrics.NSOptions{Name: "jaeger"}).
Namespace(metrics.NSOptions{Name: "agent"})
mFactory := fork.New("internal",
jexpvar.NewFactory(10).Namespace(metrics.NSOptions{}), // backend for internal opts
baseFactory.Namespace(metrics.NSOptions{Name: "agent"}))
jexpvar.NewFactory(10), // backend for internal opts
baseFactory)

rOpts := new(reporter.Options).InitFromViper(v, logger)
grpcBuilder := grpc.NewConnBuilder().InitFromViper(v)
Expand Down
2 changes: 1 addition & 1 deletion cmd/all-in-one/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ by default uses only in-memory database.`,
logger := svc.Logger // shortcut
rootMetricsFactory := svc.MetricsFactory // shortcut
metricsFactory := fork.New("internal",
jexpvar.NewFactory(10).Namespace(metrics.NSOptions{}), // backend for internal opts
jexpvar.NewFactory(10), // backend for internal opts
rootMetricsFactory.Namespace(metrics.NSOptions{Name: "jaeger"}))

tracerCloser := initTracer(rootMetricsFactory, svc.Logger)
Expand Down
4 changes: 2 additions & 2 deletions cmd/collector/app/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ func (c *Collector) Start(builderOpts *CollectorOptions) error {
} else {
c.zkServer = zkServer
}
c.setExpvarOptions(builderOpts)
c.publishOpts(builderOpts)

return nil
}

func (c *Collector) setExpvarOptions(cOpts *CollectorOptions) {
func (c *Collector) publishOpts(cOpts *CollectorOptions) {
internalFactory := c.metricsFactory.Namespace(metrics.NSOptions{Name: "internal"})
internalFactory.Gauge(metrics.Options{Name: collectorNumWorkers}).Update(int64(cOpts.NumWorkers))
internalFactory.Gauge(metrics.Options{Name: collectorQueueSize}).Update(int64(cOpts.QueueSize))
Expand Down
2 changes: 1 addition & 1 deletion cmd/collector/app/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (m *mockStrategyStore) GetSamplingStrategy(_ context.Context, serviceName s
return &sampling.SamplingStrategyResponse{}, nil
}

func TestCollector_SetExpvarOptions(t *testing.T) {
func TestCollector_PublishOpts(t *testing.T) {
// prepare
hc := healthcheck.New()
logger := zap.NewNop()
Expand Down
2 changes: 1 addition & 1 deletion cmd/collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func main() {
logger := svc.Logger // shortcut
baseFactory := svc.MetricsFactory.Namespace(metrics.NSOptions{Name: "jaeger"})
metricsFactory := fork.New("internal",
jexpvar.NewFactory(10).Namespace(metrics.NSOptions{}), // backend for internal opts
jexpvar.NewFactory(10), // backend for internal opts
baseFactory.Namespace(metrics.NSOptions{Name: "collector"}))

storageFactory.InitFromViper(v)
Expand Down
8 changes: 4 additions & 4 deletions plugin/storage/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const (
badgerStorageType = "badger"
downsamplingRatio = "downsampling.ratio"
downsamplingHashSalt = "downsampling.hashsalt"
spanStorageType = "span-storage.type"
spanStorageType = "span-storage-type"

// defaultDownsamplingRatio is the default downsampling ratio.
defaultDownsamplingRatio = 1.0
Expand Down Expand Up @@ -112,7 +112,7 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger)
return err
}
}
f.setExpvarOptions()
f.publishOpts()

return nil
}
Expand Down Expand Up @@ -253,10 +253,10 @@ func (f *Factory) Close() error {
return multierror.Wrap(errs)
}

func (f *Factory) setExpvarOptions() {
func (f *Factory) publishOpts() {
internalFactory := f.metricsFactory.Namespace(metrics.NSOptions{Name: "internal"})
internalFactory.Gauge(metrics.Options{Name: downsamplingRatio}).
Update(int64(f.FactoryConfig.DownsamplingRatio))
internalFactory.Gauge(metrics.Options{Name: spanStorageType + "." + f.SpanReaderType}).
internalFactory.Gauge(metrics.Options{Name: spanStorageType + "-" + f.SpanReaderType}).
Update(1)
}
6 changes: 3 additions & 3 deletions plugin/storage/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func TestParsingDownsamplingRatio(t *testing.T) {
assert.Equal(t, f.FactoryConfig.DownsamplingRatio, 0.5)
}

func TestSetExpvarOptions(t *testing.T) {
func TestPublishOpts(t *testing.T) {
f, err := NewFactory(defaultCfg())
require.NoError(t, err)

Expand All @@ -363,14 +363,14 @@ func TestSetExpvarOptions(t *testing.T) {
f.metricsFactory = metricsFactory

// This method is called inside factory.Initialize method
f.setExpvarOptions()
f.publishOpts()

forkFactory.AssertGaugeMetrics(t, metricstest.ExpectedMetric{
Name: "internal." + downsamplingRatio,
Value: int(f.DownsamplingRatio),
})
forkFactory.AssertGaugeMetrics(t, metricstest.ExpectedMetric{
Name: strings.Join([]string{"internal", spanStorageType, f.SpanReaderType}, "."),
Name: "internal." + spanStorageType + "-" + f.SpanReaderType,
Value: 1,
})
}
Expand Down
4 changes: 2 additions & 2 deletions plugin/storage/memory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger)
f.metricsFactory, f.logger = metricsFactory, logger
f.store = WithConfiguration(f.options.Configuration)
logger.Info("Memory storage initialized", zap.Any("configuration", f.store.config))
f.setExpvarOptions()
f.publishOpts()

return nil
}
Expand All @@ -79,7 +79,7 @@ func (f *Factory) CreateDependencyReader() (dependencystore.Reader, error) {
return f.store, nil
}

func (f *Factory) setExpvarOptions() {
func (f *Factory) publishOpts() {
internalFactory := f.metricsFactory.Namespace(metrics.NSOptions{Name: "internal"})
internalFactory.Gauge(metrics.Options{Name: limit}).
Update(int64(f.options.Configuration.MaxTraces))
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/memory/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestInitFromOptions(t *testing.T) {
assert.Equal(t, o, f.options)
}

func TestSetExpvarOptions(t *testing.T) {
func TestPublishOpts(t *testing.T) {
f := NewFactory()
v, command := config.Viperize(f.AddFlags)
command.ParseFlags([]string{"--memory.max-traces=100"})
Expand Down

0 comments on commit c6bbaf9

Please sign in to comment.