From 9aac97395eae56b9940b51b74332582ea876b2cc Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Thu, 1 Nov 2018 22:23:03 +0000 Subject: [PATCH] Yaml schema config dates in human-readable form yyyy-mm-dd instead of Unix epoch milliseconds Signed-off-by: Bryan Boreham --- composite_store.go | 2 +- schema_config.go | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/composite_store.go b/composite_store.go index 185c5691c37b7..a706803ab93a9 100644 --- a/composite_store.go +++ b/composite_store.go @@ -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 } diff --git a/schema_config.go b/schema_config.go index b8983e5101cc2..5d113923489da 100644 --- a/schema_config.go +++ b/schema_config.go @@ -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"` @@ -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, }, @@ -221,12 +223,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) }