diff --git a/cmd/jaeger/config-cassandra.yaml b/cmd/jaeger/config-cassandra.yaml index 0076fa48fd0..582e870de12 100644 --- a/cmd/jaeger/config-cassandra.yaml +++ b/cmd/jaeger/config-cassandra.yaml @@ -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: @@ -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: diff --git a/pkg/cassandra/config/config.go b/pkg/cassandra/config/config.go index 05e35f19e65..23fa3b0767a 100644 --- a/pkg/cassandra/config/config.go +++ b/pkg/cassandra/config/config.go @@ -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 { diff --git a/plugin/storage/cassandra/schema/schema.go b/plugin/storage/cassandra/schema/schema.go index ff36b3a9920..7f002dd5ca6 100644 --- a/plugin/storage/cassandra/schema/schema.go +++ b/plugin/storage/cassandra/schema/schema.go @@ -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 @@ -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]) @@ -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