Skip to content

Commit

Permalink
Merge pull request #2895 from influxdb/fix_graphite_defaults
Browse files Browse the repository at this point in the history
Use defaults for Graphite input where necessary
  • Loading branch information
otoolep committed Jun 11, 2015
2 parents 9c7f23e + e76f3c7 commit 3273db2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
7 changes: 5 additions & 2 deletions etc/config.sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@

[[graphite]]
enabled = false
# protocol = ""
# bind-address = ""
# bind-address = ":2003"
# protocol = "tcp"
# consistency-level = "one"
# name-separator = "."
# name-position = "last"

###
### [collectd]
Expand Down
25 changes: 25 additions & 0 deletions services/graphite/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
19 changes: 11 additions & 8 deletions services/graphite/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3273db2

Please sign in to comment.