Merge pull request #2895 from influxdb/fix_graphite_defaults
Use defaults for Graphite input where necessarypull/2900/head
commit
3273db25f2
|
@ -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]
|
||||
|
||||
|
|
|
@ -79,8 +79,11 @@
|
|||
|
||||
[[graphite]]
|
||||
enabled = false
|
||||
# protocol = ""
|
||||
# bind-address = ""
|
||||
# bind-address = ":2003"
|
||||
# protocol = "tcp"
|
||||
# consistency-level = "one"
|
||||
# name-separator = "."
|
||||
# name-position = "last"
|
||||
|
||||
###
|
||||
### [collectd]
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue