From 389091d8311c39c055bf93f6f6ee735a43315160 Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Mon, 2 Sep 2024 15:52:56 -0400 Subject: [PATCH 1/8] Update godoc Comments For Configuration Struct Signed-off-by: Mahad Zaryab --- plugin/storage/badger/options.go | 35 +++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/plugin/storage/badger/options.go b/plugin/storage/badger/options.go index dfeef42fb78..e6e125fc01f 100644 --- a/plugin/storage/badger/options.go +++ b/plugin/storage/badger/options.go @@ -19,18 +19,33 @@ type Options struct { // This storage plugin does not support additional namespaces } -// NamespaceConfig is badger's internal configuration data +// NamespaceConfig is badger's internal configuration data. type NamespaceConfig struct { - namespace string - SpanStoreTTL time.Duration `mapstructure:"span_store_ttl"` - ValueDirectory string `mapstructure:"directory_value"` - KeyDirectory string `mapstructure:"directory_key"` - // Setting this to true will ignore ValueDirectory and KeyDirectory - Ephemeral bool `mapstructure:"ephemeral"` - SyncWrites bool `mapstructure:"consistency"` - MaintenanceInterval time.Duration `mapstructure:"maintenance_interval"` + namespace string + // SpanStoreTTL holds the amount of time that the span store data is stored. + // Once this duration has passed for a given key, it will no longer be accessible. + SpanStoreTTL time.Duration `mapstructure:"span_store_ttl"` + // KeyDirectory is the directory in which the keys are stored. Ephemeral must be + // set to false for this configuration to take effect. + KeyDirectory string `mapstructure:"directory_key"` + // ValueDirectory is the directory in which the values should be stored. Ephemeral must be + // set to false for this configuration to take effect. + ValueDirectory string `mapstructure:"directory_value"` + // Ephemeral, if set to true, will store data in a temporary file system. + // If set to true, KeyDirectory and ValueDirectory are ignored. + Ephemeral bool `mapstructure:"ephemeral"` + // SyncWrites, if set to true, will immediately sync all writes to disk. Note that + // setting this field to true will affect write performance. + SyncWrites bool `mapstructure:"consistency"` + // MaintenanceInterval is the regular interval after which a maintenance job is + // run on the values in the store. + MaintenanceInterval time.Duration `mapstructure:"maintenance_interval"` + // MetricsUpdateInterval is the regular interval after which metrics are collected + // by Jaeger. MetricsUpdateInterval time.Duration `mapstructure:"metrics_update_interval"` - ReadOnly bool `mapstructure:"read_only"` + // ReadOnly opens the data store in read-only mode. Multiple instances can open the same + // store in read-only mode. Values still in the write-ahead-log must be replayed before opening. + ReadOnly bool `mapstructure:"read_only"` } const ( From 06ec13d7c6a047b772f9204498b5655c21df9f12 Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Mon, 2 Sep 2024 18:01:45 -0400 Subject: [PATCH 2/8] Add Validate Method For Namespace Config Signed-off-by: Mahad Zaryab --- plugin/storage/badger/options.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugin/storage/badger/options.go b/plugin/storage/badger/options.go index e6e125fc01f..e8720964c00 100644 --- a/plugin/storage/badger/options.go +++ b/plugin/storage/badger/options.go @@ -9,6 +9,7 @@ import ( "path/filepath" "time" + "github.com/asaskevich/govalidator" "github.com/spf13/viper" "go.uber.org/zap" ) @@ -167,3 +168,8 @@ func initFromViper(cfg *NamespaceConfig, v *viper.Viper, _ *zap.Logger) { func (opt *Options) GetPrimary() NamespaceConfig { return opt.Primary } + +func (c *NamespaceConfig) Validate() error { + _, err := govalidator.ValidateStruct(c) + return err +} From f4ed853b4a1eda40fa12afd71911dcc7348b277b Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Mon, 2 Sep 2024 18:03:23 -0400 Subject: [PATCH 3/8] Add Test For Validate Method Signed-off-by: Mahad Zaryab --- plugin/storage/badger/options_test.go | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/plugin/storage/badger/options_test.go b/plugin/storage/badger/options_test.go index ab85e5da4fe..30fc9591741 100644 --- a/plugin/storage/badger/options_test.go +++ b/plugin/storage/badger/options_test.go @@ -8,6 +8,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "go.uber.org/zap" "github.com/jaegertracing/jaeger/pkg/config" @@ -53,3 +54,35 @@ func TestReadOnlyOptions(t *testing.T) { opts.InitFromViper(v, zap.NewNop()) assert.True(t, opts.GetPrimary().ReadOnly) } + +func TestValidate_DoesNotReturnErrorWhenValid(t *testing.T) { + tests := []struct { + name string + config *NamespaceConfig + }{ + { + name: "non-required fields not set", + config: &NamespaceConfig{}, + }, + { + name: "all fields are set", + config: &NamespaceConfig{ + SpanStoreTTL: time.Second, + KeyDirectory: "some-key-directory", + ValueDirectory: "some-value-directory", + Ephemeral: false, + SyncWrites: false, + MaintenanceInterval: time.Second, + MetricsUpdateInterval: time.Second, + ReadOnly: false, + }, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + err := test.config.Validate() + require.NoError(t, err) + }) + } +} From 3ef934eabf9da6746526a5d93b8aa3b5fbce2a84 Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Tue, 3 Sep 2024 20:31:00 -0400 Subject: [PATCH 4/8] Group Directory Fields Together Signed-off-by: Mahad Zaryab --- cmd/jaeger/config-badger.yaml | 10 +++++--- plugin/storage/badger/factory.go | 12 ++++----- plugin/storage/badger/factory_test.go | 6 +++-- plugin/storage/badger/options.go | 36 ++++++++++++++++----------- plugin/storage/badger/options_test.go | 12 +++++---- plugin/storage/badger/stats_linux.go | 4 +-- 6 files changed, 46 insertions(+), 34 deletions(-) diff --git a/cmd/jaeger/config-badger.yaml b/cmd/jaeger/config-badger.yaml index 5ce7ce9dbfe..7cbbdccd8bb 100644 --- a/cmd/jaeger/config-badger.yaml +++ b/cmd/jaeger/config-badger.yaml @@ -20,13 +20,15 @@ extensions: backends: some_store: badger: - directory_key: "/tmp/jaeger/" - directory_value: "/tmp/jaeger/" + directories: + keys: "/tmp/jaeger/" + values: "/tmp/jaeger/" ephemeral: false another_store: badger: - directory_key: "/tmp/jaeger_archive/" - directory_value: "/tmp/jaeger_archive/" + directories: + keys: "/tmp/jaeger_archive/" + values: "/tmp/jaeger_archive/" ephemeral: false receivers: diff --git a/plugin/storage/badger/factory.go b/plugin/storage/badger/factory.go index 8a00a2d958b..552a6459d21 100644 --- a/plugin/storage/badger/factory.go +++ b/plugin/storage/badger/factory.go @@ -126,16 +126,16 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) opts.Dir = f.tmpDir opts.ValueDir = f.tmpDir - f.Options.Primary.KeyDirectory = f.tmpDir - f.Options.Primary.ValueDirectory = f.tmpDir + f.Options.Primary.Directories.Keys = f.tmpDir + f.Options.Primary.Directories.Keys = f.tmpDir } else { // Errors are ignored as they're caught in the Open call - initializeDir(f.Options.Primary.KeyDirectory) - initializeDir(f.Options.Primary.ValueDirectory) + initializeDir(f.Options.Primary.Directories.Keys) + initializeDir(f.Options.Primary.Directories.Values) opts.SyncWrites = f.Options.Primary.SyncWrites - opts.Dir = f.Options.Primary.KeyDirectory - opts.ValueDir = f.Options.Primary.ValueDirectory + opts.Dir = f.Options.Primary.Directories.Keys + opts.ValueDir = f.Options.Primary.Directories.Values // These options make no sense with ephemeral data opts.ReadOnly = f.Options.Primary.ReadOnly diff --git a/plugin/storage/badger/factory_test.go b/plugin/storage/badger/factory_test.go index e3a9cf1b169..62a13207900 100644 --- a/plugin/storage/badger/factory_test.go +++ b/plugin/storage/badger/factory_test.go @@ -203,8 +203,10 @@ func TestBadgerStorageFactoryWithConfig(t *testing.T) { tmp := os.TempDir() defer os.Remove(tmp) cfg = NamespaceConfig{ - ValueDirectory: tmp, - KeyDirectory: tmp, + Directories: Directories{ + Keys: tmp, + Values: tmp, + }, Ephemeral: false, MaintenanceInterval: 5, MetricsUpdateInterval: 10, diff --git a/plugin/storage/badger/options.go b/plugin/storage/badger/options.go index e8720964c00..48d6c1197f0 100644 --- a/plugin/storage/badger/options.go +++ b/plugin/storage/badger/options.go @@ -26,14 +26,11 @@ type NamespaceConfig struct { // SpanStoreTTL holds the amount of time that the span store data is stored. // Once this duration has passed for a given key, it will no longer be accessible. SpanStoreTTL time.Duration `mapstructure:"span_store_ttl"` - // KeyDirectory is the directory in which the keys are stored. Ephemeral must be + // Directories contains the configuration for where items are stored. Ephemeral must be // set to false for this configuration to take effect. - KeyDirectory string `mapstructure:"directory_key"` - // ValueDirectory is the directory in which the values should be stored. Ephemeral must be - // set to false for this configuration to take effect. - ValueDirectory string `mapstructure:"directory_value"` + Directories Directories `mapstructure:"directories"` // Ephemeral, if set to true, will store data in a temporary file system. - // If set to true, KeyDirectory and ValueDirectory are ignored. + // If set to true, the configuration in Directories is ignored. Ephemeral bool `mapstructure:"ephemeral"` // SyncWrites, if set to true, will immediately sync all writes to disk. Note that // setting this field to true will affect write performance. @@ -49,6 +46,13 @@ type NamespaceConfig struct { ReadOnly bool `mapstructure:"read_only"` } +type Directories struct { + // Keys contains the directory in which the keys are stored. + Keys string `mapstructure:"keys"` + // Values contains the directory in which the values are stored. + Values string `mapstructure:"values"` +} + const ( defaultMaintenanceInterval time.Duration = 5 * time.Minute defaultMetricsUpdateInterval time.Duration = 10 * time.Second @@ -72,11 +76,13 @@ const ( func DefaultNamespaceConfig() NamespaceConfig { defaultBadgerDataDir := getCurrentExecutableDir() return NamespaceConfig{ - SpanStoreTTL: defaultTTL, - SyncWrites: false, // Performance over durability - Ephemeral: true, // Default is ephemeral storage - ValueDirectory: defaultBadgerDataDir + defaultValueDir, - KeyDirectory: defaultBadgerDataDir + defaultKeysDir, + SpanStoreTTL: defaultTTL, + SyncWrites: false, // Performance over durability + Ephemeral: true, // Default is ephemeral storage + Directories: Directories{ + Keys: defaultBadgerDataDir + defaultKeysDir, + Values: defaultBadgerDataDir + defaultValueDir, + }, MaintenanceInterval: defaultMaintenanceInterval, MetricsUpdateInterval: defaultMetricsUpdateInterval, } @@ -118,12 +124,12 @@ func addFlags(flagSet *flag.FlagSet, nsConfig NamespaceConfig) { ) flagSet.String( nsConfig.namespace+suffixKeyDirectory, - nsConfig.KeyDirectory, + nsConfig.Directories.Keys, "Path to store the keys (indexes), this directory should reside in SSD disk. Set ephemeral to false if you want to define this setting.", ) flagSet.String( nsConfig.namespace+suffixValueDirectory, - nsConfig.ValueDirectory, + nsConfig.Directories.Values, "Path to store the values (spans). Set ephemeral to false if you want to define this setting.", ) flagSet.Bool( @@ -155,8 +161,8 @@ func (opt *Options) InitFromViper(v *viper.Viper, logger *zap.Logger) { func initFromViper(cfg *NamespaceConfig, v *viper.Viper, _ *zap.Logger) { cfg.Ephemeral = v.GetBool(cfg.namespace + suffixEphemeral) - cfg.KeyDirectory = v.GetString(cfg.namespace + suffixKeyDirectory) - cfg.ValueDirectory = v.GetString(cfg.namespace + suffixValueDirectory) + cfg.Directories.Keys = v.GetString(cfg.namespace + suffixKeyDirectory) + cfg.Directories.Values = v.GetString(cfg.namespace + suffixValueDirectory) cfg.SyncWrites = v.GetBool(cfg.namespace + suffixSyncWrite) cfg.SpanStoreTTL = v.GetDuration(cfg.namespace + suffixSpanstoreTTL) cfg.MaintenanceInterval = v.GetDuration(cfg.namespace + suffixMaintenanceInterval) diff --git a/plugin/storage/badger/options_test.go b/plugin/storage/badger/options_test.go index 30fc9591741..ad8a10e19f7 100644 --- a/plugin/storage/badger/options_test.go +++ b/plugin/storage/badger/options_test.go @@ -40,8 +40,8 @@ func TestParseOptions(t *testing.T) { assert.False(t, opts.GetPrimary().Ephemeral) assert.True(t, opts.GetPrimary().SyncWrites) assert.Equal(t, time.Duration(168*time.Hour), opts.GetPrimary().SpanStoreTTL) - assert.Equal(t, "/var/lib/badger", opts.GetPrimary().KeyDirectory) - assert.Equal(t, "/mnt/slow/badger", opts.GetPrimary().ValueDirectory) + assert.Equal(t, "/var/lib/badger", opts.GetPrimary().Directories.Keys) + assert.Equal(t, "/mnt/slow/badger", opts.GetPrimary().Directories.Values) assert.False(t, opts.GetPrimary().ReadOnly) } @@ -67,9 +67,11 @@ func TestValidate_DoesNotReturnErrorWhenValid(t *testing.T) { { name: "all fields are set", config: &NamespaceConfig{ - SpanStoreTTL: time.Second, - KeyDirectory: "some-key-directory", - ValueDirectory: "some-value-directory", + SpanStoreTTL: time.Second, + Directories: Directories{ + Keys: "some-key-directory", + Values: "some-values-directory", + }, Ephemeral: false, SyncWrites: false, MaintenanceInterval: time.Second, diff --git a/plugin/storage/badger/stats_linux.go b/plugin/storage/badger/stats_linux.go index cb412379b3e..00341da12b3 100644 --- a/plugin/storage/badger/stats_linux.go +++ b/plugin/storage/badger/stats_linux.go @@ -12,11 +12,11 @@ func (f *Factory) diskStatisticsUpdate() error { // In case of ephemeral these are the same, but we'll report them separately for consistency var keyDirStatfs unix.Statfs_t // Error ignored to satisfy Codecov - _ = unix.Statfs(f.Options.GetPrimary().KeyDirectory, &keyDirStatfs) + _ = unix.Statfs(f.Options.GetPrimary().Directories.Keys, &keyDirStatfs) var valDirStatfs unix.Statfs_t // Error ignored to satisfy Codecov - _ = unix.Statfs(f.Options.GetPrimary().ValueDirectory, &valDirStatfs) + _ = unix.Statfs(f.Options.GetPrimary().Directories.Values, &valDirStatfs) // Using Bavail instead of Bfree to get non-priviledged user space available //nolint: gosec // G115 From e3752c87d87479e95b7b1d3132262a8d5d44b1c8 Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Tue, 3 Sep 2024 21:09:26 -0400 Subject: [PATCH 5/8] Create Separate Grouping For TTL Signed-off-by: Mahad Zaryab --- .../extension/jaegerstorage/config_test.go | 2 +- plugin/storage/badger/factory.go | 4 ++-- plugin/storage/badger/options.go | 24 ++++++++++++------- plugin/storage/badger/options_test.go | 8 ++++--- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/cmd/jaeger/internal/extension/jaegerstorage/config_test.go b/cmd/jaeger/internal/extension/jaegerstorage/config_test.go index 1b2718c4cda..4406f8212dd 100644 --- a/cmd/jaeger/internal/extension/jaegerstorage/config_test.go +++ b/cmd/jaeger/internal/extension/jaegerstorage/config_test.go @@ -61,7 +61,7 @@ backends: `) cfg := createDefaultConfig().(*Config) require.NoError(t, conf.Unmarshal(cfg)) - assert.NotEmpty(t, cfg.Backends["some_storage"].Badger.SpanStoreTTL) + assert.NotEmpty(t, cfg.Backends["some_storage"].Badger.TTL.SpanStore) } func TestConfigDefaultGRPC(t *testing.T) { diff --git a/plugin/storage/badger/factory.go b/plugin/storage/badger/factory.go index 552a6459d21..1636fdecd28 100644 --- a/plugin/storage/badger/factory.go +++ b/plugin/storage/badger/factory.go @@ -147,7 +147,7 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) } f.store = store - f.cache = badgerStore.NewCacheStore(f.store, f.Options.Primary.SpanStoreTTL, true) + f.cache = badgerStore.NewCacheStore(f.store, f.Options.Primary.TTL.SpanStore, true) f.metrics.ValueLogSpaceAvailable = metricsFactory.Gauge(metrics.Options{Name: valueLogSpaceAvailableName}) f.metrics.KeyLogSpaceAvailable = metricsFactory.Gauge(metrics.Options{Name: keyLogSpaceAvailableName}) @@ -178,7 +178,7 @@ func (f *Factory) CreateSpanReader() (spanstore.Reader, error) { // CreateSpanWriter implements storage.Factory func (f *Factory) CreateSpanWriter() (spanstore.Writer, error) { - return badgerStore.NewSpanWriter(f.store, f.cache, f.Options.Primary.SpanStoreTTL), nil + return badgerStore.NewSpanWriter(f.store, f.cache, f.Options.Primary.TTL.SpanStore), nil } // CreateDependencyReader implements storage.Factory diff --git a/plugin/storage/badger/options.go b/plugin/storage/badger/options.go index 48d6c1197f0..8815471a85a 100644 --- a/plugin/storage/badger/options.go +++ b/plugin/storage/badger/options.go @@ -23,9 +23,8 @@ type Options struct { // NamespaceConfig is badger's internal configuration data. type NamespaceConfig struct { namespace string - // SpanStoreTTL holds the amount of time that the span store data is stored. - // Once this duration has passed for a given key, it will no longer be accessible. - SpanStoreTTL time.Duration `mapstructure:"span_store_ttl"` + // TTL holds time-to-live configuration for the badger store. + TTL TTL `mapstructure:"ttl"` // Directories contains the configuration for where items are stored. Ephemeral must be // set to false for this configuration to take effect. Directories Directories `mapstructure:"directories"` @@ -46,6 +45,13 @@ type NamespaceConfig struct { ReadOnly bool `mapstructure:"read_only"` } +type TTL struct { + // SpanStore holds the amount of time that the span store data is stored. + // Once this duration has passed for a given key, span store data will + // no longer be accessible. + SpanStore time.Duration `mapstructure:"span_store"` +} + type Directories struct { // Keys contains the directory in which the keys are stored. Keys string `mapstructure:"keys"` @@ -76,9 +82,11 @@ const ( func DefaultNamespaceConfig() NamespaceConfig { defaultBadgerDataDir := getCurrentExecutableDir() return NamespaceConfig{ - SpanStoreTTL: defaultTTL, - SyncWrites: false, // Performance over durability - Ephemeral: true, // Default is ephemeral storage + TTL: TTL{ + SpanStore: defaultTTL, + }, + SyncWrites: false, // Performance over durability + Ephemeral: true, // Default is ephemeral storage Directories: Directories{ Keys: defaultBadgerDataDir + defaultKeysDir, Values: defaultBadgerDataDir + defaultValueDir, @@ -119,7 +127,7 @@ func addFlags(flagSet *flag.FlagSet, nsConfig NamespaceConfig) { ) flagSet.Duration( nsConfig.namespace+suffixSpanstoreTTL, - nsConfig.SpanStoreTTL, + nsConfig.TTL.SpanStore, "How long to store the data. Format is time.Duration (https://golang.org/pkg/time/#Duration)", ) flagSet.String( @@ -164,7 +172,7 @@ func initFromViper(cfg *NamespaceConfig, v *viper.Viper, _ *zap.Logger) { cfg.Directories.Keys = v.GetString(cfg.namespace + suffixKeyDirectory) cfg.Directories.Values = v.GetString(cfg.namespace + suffixValueDirectory) cfg.SyncWrites = v.GetBool(cfg.namespace + suffixSyncWrite) - cfg.SpanStoreTTL = v.GetDuration(cfg.namespace + suffixSpanstoreTTL) + cfg.TTL.SpanStore = v.GetDuration(cfg.namespace + suffixSpanstoreTTL) cfg.MaintenanceInterval = v.GetDuration(cfg.namespace + suffixMaintenanceInterval) cfg.MetricsUpdateInterval = v.GetDuration(cfg.namespace + suffixMetricsInterval) cfg.ReadOnly = v.GetBool(cfg.namespace + suffixReadOnly) diff --git a/plugin/storage/badger/options_test.go b/plugin/storage/badger/options_test.go index ad8a10e19f7..08b6ebeee1d 100644 --- a/plugin/storage/badger/options_test.go +++ b/plugin/storage/badger/options_test.go @@ -22,7 +22,7 @@ func TestDefaultOptionsParsing(t *testing.T) { assert.True(t, opts.GetPrimary().Ephemeral) assert.False(t, opts.GetPrimary().SyncWrites) - assert.Equal(t, time.Duration(72*time.Hour), opts.GetPrimary().SpanStoreTTL) + assert.Equal(t, time.Duration(72*time.Hour), opts.GetPrimary().TTL.SpanStore) } func TestParseOptions(t *testing.T) { @@ -39,7 +39,7 @@ func TestParseOptions(t *testing.T) { assert.False(t, opts.GetPrimary().Ephemeral) assert.True(t, opts.GetPrimary().SyncWrites) - assert.Equal(t, time.Duration(168*time.Hour), opts.GetPrimary().SpanStoreTTL) + assert.Equal(t, time.Duration(168*time.Hour), opts.GetPrimary().TTL.SpanStore) assert.Equal(t, "/var/lib/badger", opts.GetPrimary().Directories.Keys) assert.Equal(t, "/mnt/slow/badger", opts.GetPrimary().Directories.Values) assert.False(t, opts.GetPrimary().ReadOnly) @@ -67,7 +67,9 @@ func TestValidate_DoesNotReturnErrorWhenValid(t *testing.T) { { name: "all fields are set", config: &NamespaceConfig{ - SpanStoreTTL: time.Second, + TTL: TTL{ + SpanStore: time.Second, + }, Directories: Directories{ Keys: "some-key-directory", Values: "some-values-directory", From ce6d0e3c7285c473de5ee82ee0f821335c271c1d Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Tue, 3 Sep 2024 21:23:20 -0400 Subject: [PATCH 6/8] Rename Field Signed-off-by: Mahad Zaryab --- .../internal/extension/jaegerstorage/config_test.go | 2 +- plugin/storage/badger/factory.go | 4 ++-- plugin/storage/badger/options.go | 8 ++++---- plugin/storage/badger/options_test.go | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/jaeger/internal/extension/jaegerstorage/config_test.go b/cmd/jaeger/internal/extension/jaegerstorage/config_test.go index 4406f8212dd..ca0b8735cdd 100644 --- a/cmd/jaeger/internal/extension/jaegerstorage/config_test.go +++ b/cmd/jaeger/internal/extension/jaegerstorage/config_test.go @@ -61,7 +61,7 @@ backends: `) cfg := createDefaultConfig().(*Config) require.NoError(t, conf.Unmarshal(cfg)) - assert.NotEmpty(t, cfg.Backends["some_storage"].Badger.TTL.SpanStore) + assert.NotEmpty(t, cfg.Backends["some_storage"].Badger.TTL.Spans) } func TestConfigDefaultGRPC(t *testing.T) { diff --git a/plugin/storage/badger/factory.go b/plugin/storage/badger/factory.go index 1636fdecd28..be0c8f13487 100644 --- a/plugin/storage/badger/factory.go +++ b/plugin/storage/badger/factory.go @@ -147,7 +147,7 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) } f.store = store - f.cache = badgerStore.NewCacheStore(f.store, f.Options.Primary.TTL.SpanStore, true) + f.cache = badgerStore.NewCacheStore(f.store, f.Options.Primary.TTL.Spans, true) f.metrics.ValueLogSpaceAvailable = metricsFactory.Gauge(metrics.Options{Name: valueLogSpaceAvailableName}) f.metrics.KeyLogSpaceAvailable = metricsFactory.Gauge(metrics.Options{Name: keyLogSpaceAvailableName}) @@ -178,7 +178,7 @@ func (f *Factory) CreateSpanReader() (spanstore.Reader, error) { // CreateSpanWriter implements storage.Factory func (f *Factory) CreateSpanWriter() (spanstore.Writer, error) { - return badgerStore.NewSpanWriter(f.store, f.cache, f.Options.Primary.TTL.SpanStore), nil + return badgerStore.NewSpanWriter(f.store, f.cache, f.Options.Primary.TTL.Spans), nil } // CreateDependencyReader implements storage.Factory diff --git a/plugin/storage/badger/options.go b/plugin/storage/badger/options.go index 8815471a85a..b3e19d9405e 100644 --- a/plugin/storage/badger/options.go +++ b/plugin/storage/badger/options.go @@ -49,7 +49,7 @@ type TTL struct { // SpanStore holds the amount of time that the span store data is stored. // Once this duration has passed for a given key, span store data will // no longer be accessible. - SpanStore time.Duration `mapstructure:"span_store"` + Spans time.Duration `mapstructure:"spans"` } type Directories struct { @@ -83,7 +83,7 @@ func DefaultNamespaceConfig() NamespaceConfig { defaultBadgerDataDir := getCurrentExecutableDir() return NamespaceConfig{ TTL: TTL{ - SpanStore: defaultTTL, + Spans: defaultTTL, }, SyncWrites: false, // Performance over durability Ephemeral: true, // Default is ephemeral storage @@ -127,7 +127,7 @@ func addFlags(flagSet *flag.FlagSet, nsConfig NamespaceConfig) { ) flagSet.Duration( nsConfig.namespace+suffixSpanstoreTTL, - nsConfig.TTL.SpanStore, + nsConfig.TTL.Spans, "How long to store the data. Format is time.Duration (https://golang.org/pkg/time/#Duration)", ) flagSet.String( @@ -172,7 +172,7 @@ func initFromViper(cfg *NamespaceConfig, v *viper.Viper, _ *zap.Logger) { cfg.Directories.Keys = v.GetString(cfg.namespace + suffixKeyDirectory) cfg.Directories.Values = v.GetString(cfg.namespace + suffixValueDirectory) cfg.SyncWrites = v.GetBool(cfg.namespace + suffixSyncWrite) - cfg.TTL.SpanStore = v.GetDuration(cfg.namespace + suffixSpanstoreTTL) + cfg.TTL.Spans = v.GetDuration(cfg.namespace + suffixSpanstoreTTL) cfg.MaintenanceInterval = v.GetDuration(cfg.namespace + suffixMaintenanceInterval) cfg.MetricsUpdateInterval = v.GetDuration(cfg.namespace + suffixMetricsInterval) cfg.ReadOnly = v.GetBool(cfg.namespace + suffixReadOnly) diff --git a/plugin/storage/badger/options_test.go b/plugin/storage/badger/options_test.go index 08b6ebeee1d..4e88860a4ed 100644 --- a/plugin/storage/badger/options_test.go +++ b/plugin/storage/badger/options_test.go @@ -22,7 +22,7 @@ func TestDefaultOptionsParsing(t *testing.T) { assert.True(t, opts.GetPrimary().Ephemeral) assert.False(t, opts.GetPrimary().SyncWrites) - assert.Equal(t, time.Duration(72*time.Hour), opts.GetPrimary().TTL.SpanStore) + assert.Equal(t, time.Duration(72*time.Hour), opts.GetPrimary().TTL.Spans) } func TestParseOptions(t *testing.T) { @@ -39,7 +39,7 @@ func TestParseOptions(t *testing.T) { assert.False(t, opts.GetPrimary().Ephemeral) assert.True(t, opts.GetPrimary().SyncWrites) - assert.Equal(t, time.Duration(168*time.Hour), opts.GetPrimary().TTL.SpanStore) + assert.Equal(t, time.Duration(168*time.Hour), opts.GetPrimary().TTL.Spans) assert.Equal(t, "/var/lib/badger", opts.GetPrimary().Directories.Keys) assert.Equal(t, "/mnt/slow/badger", opts.GetPrimary().Directories.Values) assert.False(t, opts.GetPrimary().ReadOnly) @@ -68,7 +68,7 @@ func TestValidate_DoesNotReturnErrorWhenValid(t *testing.T) { name: "all fields are set", config: &NamespaceConfig{ TTL: TTL{ - SpanStore: time.Second, + Spans: time.Second, }, Directories: Directories{ Keys: "some-key-directory", From a0b019e4ab88563df0d49354b9a3601c13f46ea4 Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Wed, 4 Sep 2024 18:39:54 -0400 Subject: [PATCH 7/8] Fix Errors From Merge Conflict Resolving Signed-off-by: Mahad Zaryab --- plugin/storage/badger/options.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/plugin/storage/badger/options.go b/plugin/storage/badger/options.go index c6bb5a7e80d..6ebdcc78b26 100644 --- a/plugin/storage/badger/options.go +++ b/plugin/storage/badger/options.go @@ -126,17 +126,17 @@ func addFlags(flagSet *flag.FlagSet, nsConfig NamespaceConfig) { "Mark this storage ephemeral, data is stored in tmpfs.", ) flagSet.Duration( - nsConfig.namespace+suffixSpanstoreTTL, + prefix+suffixSpanstoreTTL, nsConfig.TTL.Spans, "How long to store the data. Format is time.Duration (https://golang.org/pkg/time/#Duration)", ) flagSet.String( - nsConfig.namespace+suffixKeyDirectory, + prefix+suffixKeyDirectory, nsConfig.Directories.Keys, "Path to store the keys (indexes), this directory should reside in SSD disk. Set ephemeral to false if you want to define this setting.", ) flagSet.String( - nsConfig.namespace+suffixValueDirectory, + prefix+suffixValueDirectory, nsConfig.Directories.Values, "Path to store the values (spans). Set ephemeral to false if you want to define this setting.", ) @@ -168,14 +168,14 @@ func (opt *Options) InitFromViper(v *viper.Viper, logger *zap.Logger) { } func initFromViper(cfg *NamespaceConfig, v *viper.Viper, _ *zap.Logger) { - cfg.Ephemeral = v.GetBool(cfg.namespace + suffixEphemeral) - cfg.Directories.Keys = v.GetString(cfg.namespace + suffixKeyDirectory) - cfg.Directories.Values = v.GetString(cfg.namespace + suffixValueDirectory) - cfg.SyncWrites = v.GetBool(cfg.namespace + suffixSyncWrite) - cfg.TTL.Spans = v.GetDuration(cfg.namespace + suffixSpanstoreTTL) - cfg.MaintenanceInterval = v.GetDuration(cfg.namespace + suffixMaintenanceInterval) - cfg.MetricsUpdateInterval = v.GetDuration(cfg.namespace + suffixMetricsInterval) - cfg.ReadOnly = v.GetBool(cfg.namespace + suffixReadOnly) + cfg.Ephemeral = v.GetBool(prefix + suffixEphemeral) + cfg.Directories.Keys = v.GetString(prefix + suffixKeyDirectory) + cfg.Directories.Values = v.GetString(prefix + suffixValueDirectory) + cfg.SyncWrites = v.GetBool(prefix + suffixSyncWrite) + cfg.TTL.Spans = v.GetDuration(prefix + suffixSpanstoreTTL) + cfg.MaintenanceInterval = v.GetDuration(prefix + suffixMaintenanceInterval) + cfg.MetricsUpdateInterval = v.GetDuration(prefix + suffixMetricsInterval) + cfg.ReadOnly = v.GetBool(prefix + suffixReadOnly) } // GetPrimary returns the primary namespace configuration From c5f9ffa8788637cb681413ce8b6092aea9d02df2 Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Wed, 4 Sep 2024 19:26:50 -0400 Subject: [PATCH 8/8] Fix Unit Test Failure Signed-off-by: Mahad Zaryab --- plugin/storage/badger/factory.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/storage/badger/factory.go b/plugin/storage/badger/factory.go index df189227fc7..1fdb2e8872c 100644 --- a/plugin/storage/badger/factory.go +++ b/plugin/storage/badger/factory.go @@ -127,7 +127,7 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) opts.ValueDir = f.tmpDir f.Options.Primary.Directories.Keys = f.tmpDir - f.Options.Primary.Directories.Keys = f.tmpDir + f.Options.Primary.Directories.Values = f.tmpDir } else { // Errors are ignored as they're caught in the Open call initializeDir(f.Options.Primary.Directories.Keys)