Skip to content

Commit

Permalink
Refactor Cassandra Configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Mahad Zaryab <[email protected]>
  • Loading branch information
mahadzaryab1 committed Jan 18, 2025
1 parent 9b8571d commit 8fc4680
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 32 deletions.
2 changes: 1 addition & 1 deletion cmd/jaeger/internal/extension/jaegerstorage/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (cfg *TraceBackend) Unmarshal(conf *confmap.Conf) error {
}
if conf.IsSet("cassandra") {
cfg.Cassandra = &cassandra.Options{
Primary: cassandra.NamespaceConfig{
NamespaceConfig: cassandra.NamespaceConfig{
Configuration: casCfg.DefaultConfiguration(),
Enabled: true,
},
Expand Down
16 changes: 8 additions & 8 deletions plugin/storage/cassandra/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import (
)

const (
primaryStorageConfig = "cassandra"
archiveStorageConfig = "cassandra-archive"
primaryStorageNamespace = "cassandra"
archiveStorageNamespace = "cassandra-archive"
)

var ( // interface comformance checks
Expand Down Expand Up @@ -68,15 +68,15 @@ type Factory struct {
func NewFactory() *Factory {
return &Factory{
tracer: otel.GetTracerProvider(),
Options: NewOptions(primaryStorageConfig),
Options: NewOptions(primaryStorageNamespace),
sessionBuilderFn: NewSession,
}
}

func NewArchiveFactory() *Factory {
return &Factory{
tracer: otel.GetTracerProvider(),
Options: NewOptions(archiveStorageConfig),
Options: NewOptions(archiveStorageNamespace),
sessionBuilderFn: NewSession,
}
}
Expand Down Expand Up @@ -109,7 +109,7 @@ type withConfigBuilder struct {

func (b *withConfigBuilder) build() (*Factory, error) {
b.f.configureFromOptions(b.opts)
if err := b.opts.Primary.Validate(); err != nil {
if err := b.opts.NamespaceConfig.Validate(); err != nil {
return nil, err
}
err := b.initializer(b.metricsFactory, b.logger)
Expand All @@ -133,19 +133,19 @@ func (f *Factory) InitFromViper(v *viper.Viper, _ *zap.Logger) {
// InitFromOptions initializes factory from options.
func (f *Factory) configureFromOptions(o *Options) {
f.Options = o
f.config = o.GetPrimary()
f.config = o.GetConfig()
}

// Initialize implements storage.Factory
func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error {
f.metricsFactory = metricsFactory
f.logger = logger

primarySession, err := f.sessionBuilderFn(&f.config)
session, err := f.sessionBuilderFn(&f.config)
if err != nil {
return err
}
f.session = primarySession
f.session = session

return nil
}
Expand Down
45 changes: 22 additions & 23 deletions plugin/storage/cassandra/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ const (
// to bind them to command line flag and apply overlays, so that some configurations
// (e.g. archive) may be underspecified and infer the rest of its parameters from primary.
type Options struct {
Primary NamespaceConfig `mapstructure:",squash"`
SpanStoreWriteCacheTTL time.Duration `mapstructure:"span_store_write_cache_ttl"`
Index IndexConfig `mapstructure:"index"`
NamespaceConfig `mapstructure:",squash"`
SpanStoreWriteCacheTTL time.Duration `mapstructure:"span_store_write_cache_ttl"`
Index IndexConfig `mapstructure:"index"`
}

// IndexConfig configures indexing.
Expand All @@ -76,7 +76,7 @@ type NamespaceConfig struct {
func NewOptions(namespace string) *Options {
// TODO all default values should be defined via cobra flags
options := &Options{
Primary: NamespaceConfig{
NamespaceConfig: NamespaceConfig{
Configuration: config.DefaultConfiguration(),
namespace: namespace,
Enabled: true,
Expand All @@ -89,28 +89,28 @@ func NewOptions(namespace string) *Options {

// AddFlags adds flags for Options
func (opt *Options) AddFlags(flagSet *flag.FlagSet) {
addFlags(flagSet, opt.Primary)
flagSet.Duration(opt.Primary.namespace+suffixSpanStoreWriteCacheTTL,
addFlags(flagSet, opt.NamespaceConfig)
flagSet.Duration(opt.namespace+suffixSpanStoreWriteCacheTTL,
opt.SpanStoreWriteCacheTTL,
"The duration to wait before rewriting an existing service or operation name")
flagSet.String(
opt.Primary.namespace+suffixIndexTagsBlacklist,
opt.namespace+suffixIndexTagsBlacklist,
opt.Index.TagBlackList,
"The comma-separated list of span tags to blacklist from being indexed. All other tags will be indexed. Mutually exclusive with the whitelist option.")
flagSet.String(
opt.Primary.namespace+suffixIndexTagsWhitelist,
opt.namespace+suffixIndexTagsWhitelist,
opt.Index.TagWhiteList,
"The comma-separated list of span tags to whitelist for being indexed. All other tags will not be indexed. Mutually exclusive with the blacklist option.")
flagSet.Bool(
opt.Primary.namespace+suffixIndexLogs,
opt.namespace+suffixIndexLogs,
!opt.Index.Logs,
"Controls log field indexing. Set to false to disable.")
flagSet.Bool(
opt.Primary.namespace+suffixIndexTags,
opt.namespace+suffixIndexTags,
!opt.Index.Tags,
"Controls tag indexing. Set to false to disable.")
flagSet.Bool(
opt.Primary.namespace+suffixIndexProcessTags,
opt.namespace+suffixIndexProcessTags,
!opt.Index.ProcessTags,
"Controls process tag indexing. Set to false to disable.")
}
Expand All @@ -119,7 +119,7 @@ func addFlags(flagSet *flag.FlagSet, nsConfig NamespaceConfig) {
tlsFlagsConfig := tlsFlagsConfig(nsConfig.namespace)
tlsFlagsConfig.AddFlags(flagSet)

if nsConfig.namespace != primaryStorageConfig {
if nsConfig.namespace != primaryStorageNamespace {
flagSet.Bool(
nsConfig.namespace+suffixEnabled,
false,
Expand Down Expand Up @@ -196,13 +196,13 @@ func addFlags(flagSet *flag.FlagSet, nsConfig NamespaceConfig) {

// InitFromViper initializes Options with properties from viper
func (opt *Options) InitFromViper(v *viper.Viper) {
opt.Primary.initFromViper(v)
opt.SpanStoreWriteCacheTTL = v.GetDuration(opt.Primary.namespace + suffixSpanStoreWriteCacheTTL)
opt.Index.TagBlackList = stripWhiteSpace(v.GetString(opt.Primary.namespace + suffixIndexTagsBlacklist))
opt.Index.TagWhiteList = stripWhiteSpace(v.GetString(opt.Primary.namespace + suffixIndexTagsWhitelist))
opt.Index.Tags = v.GetBool(opt.Primary.namespace + suffixIndexTags)
opt.Index.Logs = v.GetBool(opt.Primary.namespace + suffixIndexLogs)
opt.Index.ProcessTags = v.GetBool(opt.Primary.namespace + suffixIndexProcessTags)
opt.NamespaceConfig.initFromViper(v)
opt.SpanStoreWriteCacheTTL = v.GetDuration(opt.NamespaceConfig.namespace + suffixSpanStoreWriteCacheTTL)
opt.Index.TagBlackList = stripWhiteSpace(v.GetString(opt.NamespaceConfig.namespace + suffixIndexTagsBlacklist))
opt.Index.TagWhiteList = stripWhiteSpace(v.GetString(opt.NamespaceConfig.namespace + suffixIndexTagsWhitelist))
opt.Index.Tags = v.GetBool(opt.NamespaceConfig.namespace + suffixIndexTags)
opt.Index.Logs = v.GetBool(opt.NamespaceConfig.namespace + suffixIndexLogs)
opt.Index.ProcessTags = v.GetBool(opt.NamespaceConfig.namespace + suffixIndexProcessTags)
}

func tlsFlagsConfig(namespace string) tlscfg.ClientFlagsConfig {
Expand All @@ -213,7 +213,7 @@ func tlsFlagsConfig(namespace string) tlscfg.ClientFlagsConfig {

func (cfg *NamespaceConfig) initFromViper(v *viper.Viper) {
tlsFlagsConfig := tlsFlagsConfig(cfg.namespace)
if cfg.namespace != primaryStorageConfig {
if cfg.namespace != primaryStorageNamespace {
cfg.Enabled = v.GetBool(cfg.namespace + suffixEnabled)
}
cfg.Connection.ConnectionsPerHost = v.GetInt(cfg.namespace + suffixConnPerHost)
Expand Down Expand Up @@ -243,9 +243,8 @@ func (cfg *NamespaceConfig) initFromViper(v *viper.Viper) {
cfg.Connection.TLS = tlsCfg
}

// GetPrimary returns primary configuration.
func (opt *Options) GetPrimary() config.Configuration {
return opt.Primary.Configuration
func (opt *Options) GetConfig() config.Configuration {
return opt.NamespaceConfig.Configuration
}

// TagIndexBlacklist returns the list of blacklisted tags
Expand Down

0 comments on commit 8fc4680

Please sign in to comment.