Skip to content

Commit

Permalink
Merge pull request grafana#1106 from cortexproject/yaml-schema-dates
Browse files Browse the repository at this point in the history
Yaml schema config dates in human-readable form
  • Loading branch information
bboreham authored Nov 5, 2018
2 parents c6f8c3d + 9aac973 commit 02f8f17
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composite_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (c *CompositeStore) AddPeriod(storeCfg StoreConfig, cfg PeriodConfig, stora
if err != nil {
return err
}
c.stores = append(c.stores, compositeStoreEntry{start: cfg.From, Store: store})
c.stores = append(c.stores, compositeStoreEntry{start: model.TimeFromUnixNano(cfg.From.UnixNano()), Store: store})
return nil
}

Expand Down
20 changes: 16 additions & 4 deletions schema_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const (

// PeriodConfig defines the schema and tables to use for a period of time
type PeriodConfig struct {
From model.Time `yaml:"from"`
From model.Time `yaml:"-"` // used when working with config
FromStr string `yaml:"from,omitempty"` // used when loading from yaml
Store string `yaml:"store"`
Schema string `yaml:"schema"`
IndexTables PeriodicTableConfig `yaml:"index"`
Expand Down Expand Up @@ -93,9 +94,10 @@ func (cfg *SchemaConfig) translate() error {

add := func(t string, f model.Time) {
cfg.Configs = append(cfg.Configs, PeriodConfig{
From: f,
Schema: t,
Store: cfg.legacy.StorageClient,
From: f,
FromStr: f.Time().Format("2006-01-02"),
Schema: t,
Store: cfg.legacy.StorageClient,
IndexTables: PeriodicTableConfig{
Prefix: cfg.legacy.OriginalTableName,
Tags: cfg.legacy.IndexTables.Tags,
Expand Down Expand Up @@ -222,12 +224,22 @@ func (cfg *SchemaConfig) Load() error {
if err := decoder.Decode(&cfg); err != nil {
return err
}
for i := range cfg.Configs {
t, err := time.Parse("2006-01-02", cfg.Configs[i].FromStr)
if err != nil {
return err
}
cfg.Configs[i].From = model.TimeFromUnix(t.Unix())
}

return nil
}

// PrintYaml dumps the yaml to stdout, to aid in migration
func (cfg SchemaConfig) PrintYaml() {
for i := range cfg.Configs {
cfg.Configs[i].FromStr = cfg.Configs[i].From.Time().Format("2006-01-02")
}
encoder := yaml.NewEncoder(os.Stdout)
encoder.Encode(cfg)
}
Expand Down

0 comments on commit 02f8f17

Please sign in to comment.