From e84f661f7e0280c71ee1948117b73f36b1d03d4f Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Wed, 10 Jun 2015 16:40:08 -0700 Subject: [PATCH 1/2] Use defaults for Graphite input where necessary --- etc/config.sample.toml | 7 +++++-- services/graphite/config.go | 25 +++++++++++++++++++++++++ services/graphite/service.go | 19 +++++++++++-------- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/etc/config.sample.toml b/etc/config.sample.toml index 7d932012c89..80017caaf14 100644 --- a/etc/config.sample.toml +++ b/etc/config.sample.toml @@ -79,8 +79,11 @@ [[graphite]] enabled = false - # protocol = "" - # bind-address = "" + # bind-address = ":2003" + # protocol = "tcp" + # consistency-level = "one" + # name-separator = "." + # name-position = "last" ### ### [collectd] diff --git a/services/graphite/config.go b/services/graphite/config.go index e2b910edd78..7ce76d3d913 100644 --- a/services/graphite/config.go +++ b/services/graphite/config.go @@ -55,3 +55,28 @@ func NewConfig() Config { func (c *Config) LastEnabled() bool { return c.NamePosition == strings.ToLower("last") } + +// WithDefaults takes the given config and returns a new config with any required +// default values set. +func (c *Config) WithDefaults() *Config { + d := *c + if d.BindAddress == "" { + d.BindAddress = DefaultBindAddress + } + if d.Database == "" { + d.Database = DefaultDatabase + } + if d.Protocol == "" { + d.Protocol = DefaultProtocol + } + if d.NamePosition == "" { + d.NamePosition = DefaultNamePosition + } + if d.NameSeparator == "" { + d.NameSeparator = DefaultNameSeparator + } + if d.ConsistencyLevel == "" { + d.ConsistencyLevel = DefaultConsistencyLevel + } + return &d +} diff --git a/services/graphite/service.go b/services/graphite/service.go index dea166a554f..c9725d929d0 100644 --- a/services/graphite/service.go +++ b/services/graphite/service.go @@ -49,25 +49,28 @@ type Service struct { // NewService returns an instance of the Graphite service. func NewService(c Config) (*Service, error) { + // Use defaults where necessary. + d := c.WithDefaults() + s := Service{ - bindAddress: c.BindAddress, - database: c.Database, - protocol: c.Protocol, - batchSize: c.BatchSize, - batchTimeout: time.Duration(c.BatchTimeout), + bindAddress: d.BindAddress, + database: d.Database, + protocol: d.Protocol, + batchSize: d.BatchSize, + batchTimeout: time.Duration(d.BatchTimeout), logger: log.New(os.Stderr, "[graphite] ", log.LstdFlags), done: make(chan struct{}), } - consistencyLevel, err := cluster.ParseConsistencyLevel(c.ConsistencyLevel) + consistencyLevel, err := cluster.ParseConsistencyLevel(d.ConsistencyLevel) if err != nil { return nil, err } s.consistencyLevel = consistencyLevel parser := NewParser() - parser.Separator = c.NameSeparator - parser.LastEnabled = c.LastEnabled() + parser.Separator = d.NameSeparator + parser.LastEnabled = d.LastEnabled() s.parser = parser return &s, nil From e76f3c77c25fa4f3b2a2b7a1d6a3a0587ecb19fc Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Wed, 10 Jun 2015 16:42:07 -0700 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b6f8f5cd84..d1073c90efc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - [#2700](https://github.com/influxdb/influxdb/issues/2700): Incorrect error message in database EncodeFields - [#2897](https://github.com/influxdb/influxdb/pull/2897): Ensure target Graphite database exists - [#2898](https://github.com/influxdb/influxdb/pull/2898): Ensure target openTSDB database exists +- [#2895](https://github.com/influxdb/influxdb/pull/2895): Use Graphite input defaults where necessary ## v0.9.0-rc33 [2015-06-09]