Add graphite and udp services to the default config generator

Fix #4752
pull/5255/head
Nicholas Katsaros 2015-11-05 16:42:21 -05:00 committed by Thibault Cohen
parent 8e100998fa
commit a727266744
4 changed files with 52 additions and 1 deletions

View File

@ -84,12 +84,30 @@ func NewConfig() *Config {
c.HintedHandoff = hh.NewConfig()
c.BindAddress = DefaultBindAddress
// All ARRAY attributes have to be init after toml decode
// See: https://github.com/BurntSushi/toml/pull/68
// Those attributes will be initialized in Config.InitTableAttrs method
// Concerned Attributes:
// * `c.Graphites`
// * `c.UDPs`
return c
}
// Init all ARRAY attributes if it's empty
func (c *Config) InitTableAttrs() {
if len(c.UDPs) == 0 {
c.UDPs = []udp.Config{udp.NewConfig()}
}
if len(c.Graphites) == 0 {
c.Graphites = []graphite.Config{graphite.NewConfig()}
}
}
// NewDemoConfig returns the config that runs when no config is specified.
func NewDemoConfig() (*Config, error) {
c := NewConfig()
c.InitTableAttrs()
var homeDir string
// By default, store meta and data files in current users home directory

View File

@ -68,6 +68,7 @@ func (cmd *PrintConfigCommand) parseConfig(path string) (*Config, error) {
if _, err := toml.DecodeFile(path, &config); err != nil {
return nil, err
}
config.InitTableAttrs()
return config, nil
}

View File

@ -51,9 +51,9 @@ const (
// Config represents the configuration for Graphite endpoints.
type Config struct {
Enabled bool `toml:"enabled"`
BindAddress string `toml:"bind-address"`
Database string `toml:"database"`
Enabled bool `toml:"enabled"`
Protocol string `toml:"protocol"`
BatchSize int `toml:"batch-size"`
BatchPending int `toml:"batch-pending"`
@ -65,6 +65,20 @@ type Config struct {
UDPReadBuffer int `toml:"udp-read-buffer"`
}
// NewConfig returns a new instance of Config with defaults.
func NewConfig() Config {
return Config{
BindAddress: DefaultBindAddress,
Database: DefaultDatabase,
Protocol: DefaultProtocol,
BatchSize: DefaultBatchSize,
BatchPending: DefaultBatchPending,
BatchTimeout: toml.Duration(DefaultBatchTimeout),
ConsistencyLevel: DefaultConsistencyLevel,
Separator: DefaultSeparator,
}
}
// WithDefaults takes the given config and returns a new config with any required
// default values set.
func (c *Config) WithDefaults() *Config {

View File

@ -7,9 +7,15 @@ import (
)
const (
// DefaultBindAddress is the default binding interface if none is specified.
DefaultBindAddress = ":8089"
// DefaultDatabase is the default database for UDP traffic.
DefaultDatabase = "udp"
// DefaultRetentionPolicy is the default retention policy used for writes.
DefaultRetentionPolicy = ""
// DefaultBatchSize is the default UDP batch size.
DefaultBatchSize = 5000
@ -69,6 +75,18 @@ type Config struct {
UDPPayloadSize int `toml:"udp-payload-size"`
}
// NewConfig returns a new instance of Config with defaults.
func NewConfig() Config {
return Config{
BindAddress: DefaultBindAddress,
Database: DefaultDatabase,
RetentionPolicy: DefaultRetentionPolicy,
BatchSize: DefaultBatchSize,
BatchPending: DefaultBatchPending,
BatchTimeout: toml.Duration(DefaultBatchTimeout),
}
}
// WithDefaults takes the given config and returns a new config with any required
// default values set.
func (c *Config) WithDefaults() *Config {