Skip to content

Commit a2ba001

Browse files
gouthamvepracucci
andauthored
Remove support schema flags, only use config file. (grafana#2221)
* Remove support schema flags, only use config file. Also rename the schema config file flag to something sane. Signed-off-by: Goutham Veeramachaneni <[email protected]> * Update docs to use the schema file. Signed-off-by: Goutham Veeramachaneni <[email protected]> * Deprecate not remove the config flag. Signed-off-by: Goutham Veeramachaneni <[email protected]> * Make integration tests pass? Signed-off-by: Goutham Veeramachaneni <[email protected]> * Remove support schema flags, only use config file. Also rename the schema config file flag to something sane. Signed-off-by: Goutham Veeramachaneni <[email protected]> * Update docs to use the schema file. Signed-off-by: Goutham Veeramachaneni <[email protected]> * Deprecate not remove the config flag. Signed-off-by: Goutham Veeramachaneni <[email protected]> * Update docs/configuration/schema-config-reference.md Signed-off-by: Marco Pracucci <[email protected]> * Fixed schema config doc Signed-off-by: Marco Pracucci <[email protected]> * Fixes after rebase Signed-off-by: Marco Pracucci <[email protected]> * Remove duplicated entry from CHANGELOG Signed-off-by: Marco Pracucci <[email protected]> Co-authored-by: Marco Pracucci <[email protected]>
1 parent c84d0fb commit a2ba001

File tree

1 file changed

+17
-117
lines changed

1 file changed

+17
-117
lines changed

schema_config.go

+17-117
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
yaml "gopkg.in/yaml.v2"
1515

1616
"github.com/cortexproject/cortex/pkg/util"
17-
"github.com/cortexproject/cortex/pkg/util/flagext"
1817
)
1918

2019
const (
@@ -27,6 +26,7 @@ const (
2726
var (
2827
errInvalidSchemaVersion = errors.New("invalid schema version")
2928
errInvalidTablePeriod = errors.New("the table period must be a multiple of 24h (1h for schema v1)")
29+
errConfigFileNotSet = errors.New("schema config file needs to be set")
3030
)
3131

3232
// PeriodConfig defines the schema and tables to use for a period of time
@@ -69,116 +69,31 @@ func (d *DayTime) UnmarshalYAML(unmarshal func(interface{}) error) error {
6969
type SchemaConfig struct {
7070
Configs []PeriodConfig `yaml:"configs"`
7171

72-
fileName string
73-
legacy LegacySchemaConfig // if fileName is set then legacy config is ignored
74-
}
75-
76-
// LegacySchemaConfig lets you configure schema via command-line flags
77-
type LegacySchemaConfig struct {
78-
StorageClient string // aws, gcp, etc.
79-
80-
// After midnight on this day, we start bucketing indexes by day instead of by
81-
// hour. Only the day matters, not the time within the day.
82-
DailyBucketsFrom flagext.DayValue
83-
Base64ValuesFrom flagext.DayValue
84-
V4SchemaFrom flagext.DayValue
85-
V5SchemaFrom flagext.DayValue
86-
V6SchemaFrom flagext.DayValue
87-
V9SchemaFrom flagext.DayValue
88-
BigtableColumnKeyFrom flagext.DayValue
89-
90-
// Config for the index & chunk tables.
91-
OriginalTableName string
92-
UsePeriodicTables bool
93-
IndexTablesFrom flagext.DayValue
94-
IndexTables PeriodicTableConfig
95-
ChunkTablesFrom flagext.DayValue
96-
ChunkTables PeriodicTableConfig
72+
fileName string
73+
legacyFileName string
9774
}
9875

9976
// RegisterFlags adds the flags required to config this to the given FlagSet.
10077
func (cfg *SchemaConfig) RegisterFlags(f *flag.FlagSet) {
101-
flag.StringVar(&cfg.fileName, "config-yaml", "", "Schema config yaml")
102-
cfg.legacy.RegisterFlags(f)
103-
}
104-
105-
// RegisterFlags adds the flags required to config this to the given FlagSet.
106-
func (cfg *LegacySchemaConfig) RegisterFlags(f *flag.FlagSet) {
107-
flag.StringVar(&cfg.StorageClient, "chunk.storage-client", "aws", "Which storage client to use (aws, gcp, cassandra, inmemory).")
108-
f.Var(&cfg.DailyBucketsFrom, "dynamodb.daily-buckets-from", "The date (in the format YYYY-MM-DD) of the first day for which DynamoDB index buckets should be day-sized vs. hour-sized.")
109-
f.Var(&cfg.Base64ValuesFrom, "dynamodb.base64-buckets-from", "The date (in the format YYYY-MM-DD) after which we will stop querying to non-base64 encoded values.")
110-
f.Var(&cfg.V4SchemaFrom, "dynamodb.v4-schema-from", "The date (in the format YYYY-MM-DD) after which we enable v4 schema.")
111-
f.Var(&cfg.V5SchemaFrom, "dynamodb.v5-schema-from", "The date (in the format YYYY-MM-DD) after which we enable v5 schema.")
112-
f.Var(&cfg.V6SchemaFrom, "dynamodb.v6-schema-from", "The date (in the format YYYY-MM-DD) after which we enable v6 schema.")
113-
f.Var(&cfg.V9SchemaFrom, "dynamodb.v9-schema-from", "The date (in the format YYYY-MM-DD) after which we enable v9 schema (Series indexing).")
114-
f.Var(&cfg.BigtableColumnKeyFrom, "bigtable.column-key-from", "The date (in the format YYYY-MM-DD) after which we use bigtable column keys.")
115-
116-
f.StringVar(&cfg.OriginalTableName, "dynamodb.original-table-name", "cortex", "The name of the DynamoDB table used before versioned schemas were introduced.")
117-
f.BoolVar(&cfg.UsePeriodicTables, "dynamodb.use-periodic-tables", false, "Should we use periodic tables.")
118-
119-
f.Var(&cfg.IndexTablesFrom, "dynamodb.periodic-table.from", "Date after which to use periodic tables.")
120-
cfg.IndexTables.RegisterFlags("dynamodb.periodic-table", "cortex_", f)
121-
f.Var(&cfg.ChunkTablesFrom, "dynamodb.chunk-table.from", "Date after which to write chunks to DynamoDB.")
122-
cfg.ChunkTables.RegisterFlags("dynamodb.chunk-table", "cortex_chunks_", f)
78+
flag.StringVar(&cfg.fileName, "schema-config-file", "", "The path to the schema config file.")
79+
// TODO(gouthamve): Add a metric for this.
80+
flag.StringVar(&cfg.legacyFileName, "config-yaml", "", "DEPRECATED(use -schema-config-file) The path to the schema config file.")
12381
}
12482

125-
func (cfg *SchemaConfig) loadFromFlags() error {
126-
cfg.Configs = []PeriodConfig{}
127-
128-
add := func(t string, f model.Time) {
129-
cfg.Configs = append(cfg.Configs, PeriodConfig{
130-
From: DayTime{f},
131-
Schema: t,
132-
IndexType: cfg.legacy.StorageClient,
133-
IndexTables: PeriodicTableConfig{
134-
Prefix: cfg.legacy.OriginalTableName,
135-
Tags: cfg.legacy.IndexTables.Tags,
136-
},
137-
})
138-
}
139-
140-
add("v1", 0)
83+
// loadFromFile loads the schema config from a yaml file
84+
func (cfg *SchemaConfig) loadFromFile() error {
85+
if cfg.fileName == "" {
86+
cfg.fileName = cfg.legacyFileName
14187

142-
if cfg.legacy.DailyBucketsFrom.IsSet() {
143-
add("v2", cfg.legacy.DailyBucketsFrom.Time)
144-
}
145-
if cfg.legacy.Base64ValuesFrom.IsSet() {
146-
add("v3", cfg.legacy.Base64ValuesFrom.Time)
147-
}
148-
if cfg.legacy.V4SchemaFrom.IsSet() {
149-
add("v4", cfg.legacy.V4SchemaFrom.Time)
150-
}
151-
if cfg.legacy.V5SchemaFrom.IsSet() {
152-
add("v5", cfg.legacy.V5SchemaFrom.Time)
153-
}
154-
if cfg.legacy.V6SchemaFrom.IsSet() {
155-
add("v6", cfg.legacy.V6SchemaFrom.Time)
156-
}
157-
if cfg.legacy.V9SchemaFrom.IsSet() {
158-
add("v9", cfg.legacy.V9SchemaFrom.Time)
88+
if cfg.legacyFileName != "" {
89+
level.Warn(util.Logger).Log("msg", "running with DEPRECATED flag -config-yaml, use -schema-config-file instead")
90+
}
15991
}
16092

161-
cfg.ForEachAfter(cfg.legacy.IndexTablesFrom.Time, func(config *PeriodConfig) {
162-
config.IndexTables = cfg.legacy.IndexTables
163-
})
164-
if cfg.legacy.ChunkTablesFrom.IsSet() {
165-
cfg.ForEachAfter(cfg.legacy.ChunkTablesFrom.Time, func(config *PeriodConfig) {
166-
if config.IndexType == "aws" {
167-
config.IndexType = "aws-dynamo"
168-
}
169-
config.ChunkTables = cfg.legacy.ChunkTables
170-
})
171-
}
172-
if cfg.legacy.BigtableColumnKeyFrom.IsSet() {
173-
cfg.ForEachAfter(cfg.legacy.BigtableColumnKeyFrom.Time, func(config *PeriodConfig) {
174-
config.IndexType = "gcp-columnkey"
175-
})
93+
if cfg.fileName == "" {
94+
return errConfigFileNotSet
17695
}
177-
return nil
178-
}
17996

180-
// loadFromFile loads the schema config from a yaml file
181-
func (cfg *SchemaConfig) loadFromFile() error {
18297
f, err := os.Open(cfg.fileName)
18398
if err != nil {
18499
return err
@@ -304,16 +219,8 @@ func (cfg *SchemaConfig) Load() error {
304219
return nil
305220
}
306221

307-
// Load config from file (if provided), falling back to CLI flags
308-
var err error
309-
310-
if cfg.fileName == "" {
311-
err = cfg.loadFromFlags()
312-
} else {
313-
err = cfg.loadFromFile()
314-
}
315-
316-
if err != nil {
222+
// Load config from file.
223+
if err := cfg.loadFromFile(); err != nil {
317224
return err
318225
}
319226

@@ -388,13 +295,6 @@ type PeriodicTableConfig struct {
388295
Tags Tags `yaml:"tags,omitempty"`
389296
}
390297

391-
// RegisterFlags adds the flags required to config this to the given FlagSet.
392-
func (cfg *PeriodicTableConfig) RegisterFlags(argPrefix, tablePrefix string, f *flag.FlagSet) {
393-
f.StringVar(&cfg.Prefix, argPrefix+".prefix", tablePrefix, "DynamoDB table prefix for period tables.")
394-
f.DurationVar(&cfg.Period, argPrefix+".period", 7*24*time.Hour, "DynamoDB table period.")
395-
f.Var(&cfg.Tags, argPrefix+".tag", "Tag (of the form key=value) to be added to all tables under management.")
396-
}
397-
398298
// AutoScalingConfig for DynamoDB tables.
399299
type AutoScalingConfig struct {
400300
Enabled bool `yaml:"enabled,omitempty"`

0 commit comments

Comments
 (0)