From 87c3c46208ac77db1e999ae5adca9a7bacac0fae Mon Sep 17 00:00:00 2001 From: Cory LaNou Date: Wed, 1 Apr 2015 20:20:04 -0500 Subject: [PATCH 1/3] encode toml durations correctly --- cmd/influxd/config.go | 9 +++++++++ cmd/influxd/config_test.go | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/cmd/influxd/config.go b/cmd/influxd/config.go index ebb2db50522..6458ded8f42 100644 --- a/cmd/influxd/config.go +++ b/cmd/influxd/config.go @@ -326,6 +326,10 @@ func (s *Size) UnmarshalText(text []byte) error { // Duration is a TOML wrapper type for time.Duration. type Duration time.Duration +func (d Duration) String() string { + return time.Duration(d).String() +} + // UnmarshalText parses a TOML value into a duration value. func (d *Duration) UnmarshalText(text []byte) error { // Ignore if there is no value set. @@ -344,6 +348,11 @@ func (d *Duration) UnmarshalText(text []byte) error { return nil } +// MarshalText converts a duration to a string for decoding toml +func (d Duration) MarshalText() (text []byte, err error) { + return []byte(d.String()), nil +} + // ParseConfigFile parses a configuration file at a given path. func ParseConfigFile(path string) (*Config, error) { c, err := NewConfig() diff --git a/cmd/influxd/config_test.go b/cmd/influxd/config_test.go index 588252546ba..a541d3c86dc 100644 --- a/cmd/influxd/config_test.go +++ b/cmd/influxd/config_test.go @@ -1,11 +1,13 @@ package main_test import ( + "bytes" "reflect" "strings" "testing" "time" + "github.com/BurntSushi/toml" main "github.com/influxdb/influxdb/cmd/influxd" ) @@ -141,6 +143,10 @@ func TestParseConfig(t *testing.T) { t.Fatalf("cluster dir mismatch: %v", c.Cluster.Dir) } + if c.Statistics.WriteInterval.String() != "1m0s" { + t.Fatalf("Statistics.WriteInterval mismatch: %v", c.Statistics.WriteInterval) + } + // TODO: UDP Servers testing. /* c.Assert(config.UdpServers, HasLen, 1) @@ -150,6 +156,19 @@ func TestParseConfig(t *testing.T) { */ } +func TestEncodeConfig(t *testing.T) { + c := main.Config{} + c.Statistics.WriteInterval = main.Duration(time.Minute) + buf := new(bytes.Buffer) + if err := toml.NewEncoder(buf).Encode(&c); err != nil { + t.Fatal("Failed to encode: ", err) + } + got, search := buf.String(), `write-interval = "1m0s"` + if !strings.Contains(got, search) { + t.Fatalf("Encoding config failed.\nfailed to find %s in:\n%s\n", search, got) + } +} + // Testing configuration file. const testFile = ` # Welcome to the InfluxDB configuration file. From ccf9428836673e94065a37ad8ace3b57e6e574e8 Mon Sep 17 00:00:00 2001 From: Cory LaNou Date: Wed, 1 Apr 2015 20:43:14 -0500 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71a945d3666..16cf8bc6a9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## v0.9.0-rc19 [unreleased] + +### Bugfixes +- [#2145](https://github.com/influxdb/influxdb/pull/2145): Encode toml durations correctly. + ## v0.9.0-rc18 [2015-03-31] ### Bugfixes From 176e05eb9a6ad8917c8acd20d144dc998351ac60 Mon Sep 17 00:00:00 2001 From: Cory LaNou Date: Wed, 1 Apr 2015 20:54:34 -0500 Subject: [PATCH 3/3] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16cf8bc6a9a..f6d45992718 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## v0.9.0-rc19 [unreleased] ### Bugfixes -- [#2145](https://github.com/influxdb/influxdb/pull/2145): Encode toml durations correctly. +- [#2145](https://github.com/influxdb/influxdb/pull/2145): Encode toml durations correctly which fixes default configuration generation `influxd config`. ## v0.9.0-rc18 [2015-03-31]