-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[jaeger-v2] Consolidate Options And NamespaceConfig For Badger Storage (
#5937) ## Which problem is this PR solving? - Part of #5926 ## Description of the changes - Removed the `Options` struct and renamed `NamespaceConfig` to `Namespace` for Badger Storage - Moved v2-related configuration items to `config.go` while leaving v1 cli flags in `options.go` ## How was this change tested? - CI ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `yarn lint` and `yarn test` --------- Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
- Loading branch information
1 parent
8d8719a
commit 978ecbf
Showing
14 changed files
with
237 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright (c) 2024 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package badger | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"time" | ||
|
||
"github.com/asaskevich/govalidator" | ||
) | ||
|
||
const ( | ||
defaultMaintenanceInterval time.Duration = 5 * time.Minute | ||
defaultMetricsUpdateInterval time.Duration = 10 * time.Second | ||
defaultTTL time.Duration = time.Hour * 72 | ||
defaultDataDir string = string(os.PathSeparator) + "data" | ||
defaultValueDir string = defaultDataDir + string(os.PathSeparator) + "values" | ||
defaultKeysDir string = defaultDataDir + string(os.PathSeparator) + "keys" | ||
) | ||
|
||
// Config is badger's internal configuration data. | ||
type Config struct { | ||
// 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"` | ||
// Ephemeral, if set to true, will store data in a temporary file system. | ||
// 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. | ||
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 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"` | ||
} | ||
|
||
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. | ||
Spans time.Duration `mapstructure:"spans"` | ||
} | ||
|
||
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"` | ||
} | ||
|
||
func DefaultConfig() *Config { | ||
defaultBadgerDataDir := getCurrentExecutableDir() | ||
return &Config{ | ||
TTL: TTL{ | ||
Spans: defaultTTL, | ||
}, | ||
SyncWrites: false, // Performance over durability | ||
Ephemeral: true, // Default is ephemeral storage | ||
Directories: Directories{ | ||
Keys: defaultBadgerDataDir + defaultKeysDir, | ||
Values: defaultBadgerDataDir + defaultValueDir, | ||
}, | ||
MaintenanceInterval: defaultMaintenanceInterval, | ||
MetricsUpdateInterval: defaultMetricsUpdateInterval, | ||
} | ||
} | ||
|
||
func getCurrentExecutableDir() string { | ||
// We ignore the error, this will fail later when trying to start the store | ||
exec, _ := os.Executable() | ||
return filepath.Dir(exec) | ||
} | ||
|
||
func (c *Config) Validate() error { | ||
_, err := govalidator.ValidateStruct(c) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) 2024 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package badger | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestValidate_DoesNotReturnErrorWhenValid(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
cfg *Config | ||
}{ | ||
{ | ||
name: "non-required fields not set", | ||
cfg: &Config{}, | ||
}, | ||
{ | ||
name: "all fields are set", | ||
cfg: &Config{ | ||
TTL: TTL{ | ||
Spans: time.Second, | ||
}, | ||
Directories: Directories{ | ||
Keys: "some-key-directory", | ||
Values: "some-values-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.cfg.Validate() | ||
require.NoError(t, err) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.