Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use defaults for Graphite input where necessary #2895

Merged
merged 2 commits into from
Jun 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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