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

Expose tunning options via expvar #2496

Merged
merged 12 commits into from
Oct 5, 2020
Prev Previous commit
Next Next commit
Expose additional storage options
Store following storage-related options in expvar:
- memory.max-traces
- downsampling.ratio

Signed-off-by: Daniil Rutskiy <dstdfx@gmail.com>
  • Loading branch information
dstdfx committed Oct 5, 2020
commit 1d19d1d8c1a8ec911b579a8189ccd939e2259003
8 changes: 8 additions & 0 deletions plugin/storage/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package storage

import (
"expvar"
"flag"
"fmt"
"io"
Expand Down Expand Up @@ -81,6 +82,7 @@ func NewFactory(config FactoryConfig) (*Factory, error) {
}
f.factories[t] = ff
}
f.setExpvarOptions()
return f, nil
}

Expand Down Expand Up @@ -249,3 +251,9 @@ func (f *Factory) Close() error {
}
return multierror.Wrap(errs)
}

func (f *Factory) setExpvarOptions() {
dstdfx marked this conversation as resolved.
Show resolved Hide resolved
if expvar.Get(downsamplingRatio) == nil {
expvar.NewInt(downsamplingRatio).Set(int64(f.FactoryConfig.DownsamplingRatio))
}
}
13 changes: 13 additions & 0 deletions plugin/storage/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package storage

import (
"errors"
"expvar"
"flag"
"fmt"
"io"
Expand Down Expand Up @@ -350,6 +351,18 @@ func TestParsingDownsamplingRatio(t *testing.T) {
assert.Equal(t, f.FactoryConfig.DownsamplingRatio, 0.5)
}

func TestSetExpvarOptions(t *testing.T) {
clearEnv()
defer clearEnv()

f, err := NewFactory(defaultCfg())
require.NoError(t, err)

gotDownsamplingRatio := expvar.Get(downsamplingRatio)

assert.Equal(t, f.DownsamplingRatio, gotDownsamplingRatio)
}

type errorCloseFactory struct {
closeErr error
}
Expand Down
8 changes: 8 additions & 0 deletions plugin/storage/memory/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package memory

import (
"expvar"
"flag"

"github.com/spf13/viper"
Expand All @@ -37,4 +38,11 @@ func AddFlags(flagSet *flag.FlagSet) {
// InitFromViper initializes the options struct with values from Viper
func (opt *Options) InitFromViper(v *viper.Viper) {
opt.Configuration.MaxTraces = v.GetInt(limit)
opt.setExpvarOptions()
}

func (opt *Options) setExpvarOptions() {
if expvar.Get(limit) == nil {
expvar.NewInt(limit).Set(int64(opt.Configuration.MaxTraces))
}
}
14 changes: 14 additions & 0 deletions plugin/storage/memory/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package memory

import (
"expvar"
"strconv"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -30,3 +32,15 @@ func TestOptionsWithFlags(t *testing.T) {

assert.Equal(t, 100, opts.Configuration.MaxTraces)
}

func TestOptionsWithFlags_CheckExpvarOptions(t *testing.T) {
v, command := config.Viperize(AddFlags)
command.ParseFlags([]string{"--memory.max-traces=100"})
opts := Options{}
opts.InitFromViper(v)

gotMaxTraces, err := strconv.Atoi(expvar.Get("memory.max-traces").String())
assert.NoError(t, err)

assert.Equal(t, 100, gotMaxTraces)
}