Skip to content

Commit

Permalink
minor fixes and added config in .yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
akstron committed Oct 25, 2024
1 parent b490ed1 commit 69275fb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
12 changes: 12 additions & 0 deletions cmd/jaeger/config-cassandra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ extensions:
cassandra:
schema:
keyspace: "jaeger_v1_dc1"
datacenter: "test"
trace_ttl: 172800
dependencies_ttl: 172800
replication_factor: 1
cas_version: 4
compaction_window: "1m"
connection:
auth:
basic:
Expand All @@ -35,6 +41,12 @@ extensions:
cassandra:
schema:
keyspace: "jaeger_v1_dc1"
datacenter: "test"
trace_ttl: 172800
dependencies_ttl: 172800
replication_factor: 1
cas_version: 4
compaction_window: "1m"
connection:
auth:
basic:
Expand Down
18 changes: 9 additions & 9 deletions pkg/cassandra/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ type Connection struct {
}

type SchemaConfig struct {
Datacenter string `mapstructure:"datacenter"`
TraceTTL int `mapstructure:"trace_ttl"`
DependenciesTTL int `mapstructure:"dependencies_ttl"`
ReplicationFactor int `mapstructure:"replication_factor"`
CasVersion int `mapstructure:"cas_version"`
CompactionWindow string `mapstructure:"compaction_window"`
Replication string `mapstructure:"replication"`
CompactionWindowSize int `mapstructure:"compaction_window_size"`
CompactionWindowUnit string `mapstructure:"compaction_window_unit"`
Datacenter string `mapstructure:"datacenter" valid:"optional"`
TraceTTL int `mapstructure:"trace_ttl" valid:"optional"`
DependenciesTTL int `mapstructure:"dependencies_ttl" valid:"optional"`
ReplicationFactor int `mapstructure:"replication_factor" valid:"optional"`
CasVersion int `mapstructure:"cas_version" valid:"optional"`
CompactionWindow string `mapstructure:"compaction_window" valid:"optional"`
Replication string `mapstructure:"replication" valid:"optional"`
CompactionWindowSize int `mapstructure:"compaction_window_size" valid:"optional"`
CompactionWindowUnit string `mapstructure:"compaction_window_unit" valid:"optional"`
}

type Schema struct {
Expand Down
21 changes: 7 additions & 14 deletions plugin/storage/cassandra/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ import (
"github.com/jaegertracing/jaeger/pkg/cassandra/config"
)

/*
SchemaConfig might contain some unset values for which we apply defaults.
There are other configs which needs to be created based on other configs.
Currently, below are the 3 properties which has to be created:
Replication
CompactionWindowSize
CompactionWindowUnit
*/

//go:embed v004-go-tmpl.cql.tmpl
//go:embed v004-go-tmpl-test.cql.tmpl
var schemaFile embed.FS
Expand Down Expand Up @@ -63,22 +53,20 @@ func applyDefaults(cfg *config.Schema) {
}
}

// Applies defaults for the configs and contructs other optional parameters from it
func constructCompleteSchemaConfig(cfg *config.Schema) error {
applyDefaults(cfg)

cfg.Replication = fmt.Sprintf("{'class': 'NetworkTopologyStrategy', '%s': '%v' }", cfg.Datacenter, cfg.ReplicationFactor)

if cfg.CompactionWindow != "" {
/*
TODO: Add below checks in govalidator
*/
isMatch, err := regexp.MatchString("^[0-9]+[mhd]$", cfg.CompactionWindow)
if err != nil {
return err
}

if !isMatch {
return fmt.Errorf("Invalid compaction window size format. Please use numeric value followed by 'm' for minutes, 'h' for hours, or 'd' for days.")
return fmt.Errorf("Invalid compaction window size format. Please use numeric value followed by 'm' for minutes, 'h' for hours, or 'd' for days")
}

cfg.CompactionWindowSize, err = strconv.Atoi(cfg.CompactionWindow[:len(cfg.CompactionWindow)-1])
Expand Down Expand Up @@ -175,6 +163,11 @@ func getCassandraQueriesFromQueryStrings(session cassandra.Session, queries []st
}

func contructSchemaQueries(session cassandra.Session, cfg *config.Schema) ([]cassandra.Query, error) {
err := constructCompleteSchemaConfig(cfg)
if err != nil {
return nil, err
}

queryFile, err := getQueryFileAsBytes(`v004-go-tmpl.cql.tmpl`, cfg)
if err != nil {
return nil, err
Expand Down

0 comments on commit 69275fb

Please sign in to comment.