Merge pull request #2900 from influxdb/fix_opentsdb_defaults

Set openTSDB defaults in service
pull/2886/head
Philip O'Toole 2015-06-10 20:50:42 -07:00
commit 6e41c1f2da
3 changed files with 27 additions and 4 deletions

View File

@ -8,6 +8,7 @@
- [#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
- [#2900](https://github.com/influxdb/influxdb/pull/2900): Use openTSDB input defaults where necessary
## v0.9.0-rc33 [2015-06-09]

View File

@ -30,3 +30,22 @@ func NewConfig() Config {
ConsistencyLevel: DefaultConsistencyLevel,
}
}
// 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.RetentionPolicy == "" {
d.RetentionPolicy = DefaultRetentionPolicy
}
if d.ConsistencyLevel == "" {
d.ConsistencyLevel = DefaultConsistencyLevel
}
return &d
}

View File

@ -44,16 +44,19 @@ type Service struct {
// NewService returns a new instance of Service.
func NewService(c Config) (*Service, error) {
consistencyLevel, err := cluster.ParseConsistencyLevel(c.ConsistencyLevel)
// Use defaults where necessary.
d := c.WithDefaults()
consistencyLevel, err := cluster.ParseConsistencyLevel(d.ConsistencyLevel)
if err != nil {
return nil, err
}
s := &Service{
err: make(chan error),
BindAddress: c.BindAddress,
Database: c.Database,
RetentionPolicy: c.RetentionPolicy,
BindAddress: d.BindAddress,
Database: d.Database,
RetentionPolicy: d.RetentionPolicy,
ConsistencyLevel: consistencyLevel,
Logger: log.New(os.Stderr, "[opentsdb] ", log.LstdFlags),
}