Skip to content

Commit

Permalink
Change configuration package to influxdata/config
Browse files Browse the repository at this point in the history
We are unifying the way that we handle configuration across the products
into the influxdata/config package. This provides the same API as
BurntSushi/toml package used previously, but uses influxdata/toml under
the hood (which is a fork of naoina/toml). The underlying toml parser
has been changed because Telegraf uses specific features of this parser
that cannot be easily replicated with the BurntSushi parser.
Furthermore, our fork of naoina/toml provides support for maps and
pointers within structs and toml documentation facilities[1].

The toml subpackage and its related tests have also been moved into
influxdata/config. This is to allow other influxdata projects to also
use these types.

[1] This is accessible by adding a "doc" struct tag with a comment
describing a particular field of a config struct. When marshalling that
struct as TOML, the "doc" struct tag will be placed appropriately to
document that field in the resultant TOML output.
  • Loading branch information
timraymond committed Feb 2, 2016
1 parent fd85ae5 commit 2d2944d
Show file tree
Hide file tree
Showing 40 changed files with 199 additions and 299 deletions.
18 changes: 9 additions & 9 deletions cluster/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cluster
import (
"time"

"github.com/influxdb/influxdb/toml"
"github.com/influxdata/config"
)

const (
Expand All @@ -23,19 +23,19 @@ const (

// Config represents the configuration for the clustering service.
type Config struct {
ForceRemoteShardMapping bool `toml:"force-remote-mapping"`
WriteTimeout toml.Duration `toml:"write-timeout"`
ShardWriterTimeout toml.Duration `toml:"shard-writer-timeout"`
MaxRemoteWriteConnections int `toml:"max-remote-write-connections"`
ShardMapperTimeout toml.Duration `toml:"shard-mapper-timeout"`
ForceRemoteShardMapping bool `toml:"force-remote-mapping"`
WriteTimeout config.Duration `toml:"write-timeout"`
ShardWriterTimeout config.Duration `toml:"shard-writer-timeout"`
MaxRemoteWriteConnections int `toml:"max-remote-write-connections"`
ShardMapperTimeout config.Duration `toml:"shard-mapper-timeout"`
}

// NewConfig returns an instance of Config with defaults.
func NewConfig() Config {
return Config{
WriteTimeout: toml.Duration(DefaultWriteTimeout),
ShardWriterTimeout: toml.Duration(DefaultShardWriterTimeout),
ShardMapperTimeout: toml.Duration(DefaultShardMapperTimeout),
WriteTimeout: config.Duration(DefaultWriteTimeout),
ShardWriterTimeout: config.Duration(DefaultShardWriterTimeout),
ShardMapperTimeout: config.Duration(DefaultShardMapperTimeout),
MaxRemoteWriteConnections: DefaultMaxRemoteWriteConnections,
}
}
4 changes: 2 additions & 2 deletions cluster/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"testing"
"time"

"github.com/BurntSushi/toml"
"github.com/influxdata/config"
"github.com/influxdb/influxdb/cluster"
)

func TestConfig_Parse(t *testing.T) {
// Parse configuration.
var c cluster.Config
if _, err := toml.Decode(`
if err := config.Decode(`
shard-writer-timeout = "10s"
write-timeout = "20s"
`, &c); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cluster/shard_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"testing"
"time"

"github.com/influxdata/config"
"github.com/influxdb/influxdb/cluster"
"github.com/influxdb/influxdb/models"
"github.com/influxdb/influxdb/toml"
)

// Ensure the shard writer can successful write a single request.
Expand Down Expand Up @@ -190,7 +190,7 @@ func TestShardWriter_Write_ErrReadTimeout(t *testing.T) {
func TestShardWriter_Write_PoolMax(t *testing.T) {
ts := newTestWriteService(writeShardSlow)
s := cluster.NewService(cluster.Config{
ShardWriterTimeout: toml.Duration(100 * time.Millisecond),
ShardWriterTimeout: config.Duration(100 * time.Millisecond),
})
s.Listener = ts.muxln
s.TSDBStore = ts
Expand Down
4 changes: 2 additions & 2 deletions cmd/influxd/run/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"strings"
"time"

"github.com/BurntSushi/toml"
cfg "github.com/influxdata/config"
"github.com/influxdb/influxdb"
)

Expand Down Expand Up @@ -205,7 +205,7 @@ func (cmd *Command) ParseConfig(path string) (*Config, error) {
log.Printf("Using configuration at: %s\n", path)

config := NewConfig()
if _, err := toml.DecodeFile(path, &config); err != nil {
if err := cfg.DecodeFile(path, &config); err != nil {
return nil, err
}

Expand Down
14 changes: 7 additions & 7 deletions cmd/influxd/run/server_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
"testing"
"time"

"github.com/influxdata/config"
"github.com/influxdb/influxdb/client/v2"
"github.com/influxdb/influxdb/cmd/influxd/run"
"github.com/influxdb/influxdb/services/httpd"
"github.com/influxdb/influxdb/services/meta"
"github.com/influxdb/influxdb/toml"
)

const emptyResults = `{"results":[{}]}`
Expand Down Expand Up @@ -215,15 +215,15 @@ func (s *Server) MustWrite(db, rp, body string, params url.Values) string {
func NewConfig() *run.Config {
c := run.NewConfig()
c.ReportingDisabled = true
c.Cluster.ShardWriterTimeout = toml.Duration(30 * time.Second)
c.Cluster.WriteTimeout = toml.Duration(30 * time.Second)
c.Cluster.ShardWriterTimeout = config.Duration(30 * time.Second)
c.Cluster.WriteTimeout = config.Duration(30 * time.Second)
c.Meta.Dir = MustTempFile()
c.Meta.BindAddress = "127.0.0.1:0"
c.Meta.HTTPBindAddress = "127.0.0.1:0"
c.Meta.HeartbeatTimeout = toml.Duration(50 * time.Millisecond)
c.Meta.ElectionTimeout = toml.Duration(50 * time.Millisecond)
c.Meta.LeaderLeaseTimeout = toml.Duration(50 * time.Millisecond)
c.Meta.CommitTimeout = toml.Duration(5 * time.Millisecond)
c.Meta.HeartbeatTimeout = config.Duration(50 * time.Millisecond)
c.Meta.ElectionTimeout = config.Duration(50 * time.Millisecond)
c.Meta.LeaderLeaseTimeout = config.Duration(50 * time.Millisecond)
c.Meta.CommitTimeout = config.Duration(5 * time.Millisecond)

if !testing.Verbose() {
c.Meta.LoggingEnabled = false
Expand Down
10 changes: 5 additions & 5 deletions monitor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package monitor
import (
"time"

"github.com/influxdb/influxdb/toml"
"github.com/influxdata/config"
)

const (
Expand All @@ -20,16 +20,16 @@ const (

// Config represents the configuration for the monitor service.
type Config struct {
StoreEnabled bool `toml:"store-enabled"`
StoreDatabase string `toml:"store-database"`
StoreInterval toml.Duration `toml:"store-interval"`
StoreEnabled bool `toml:"store-enabled"`
StoreDatabase string `toml:"store-database"`
StoreInterval config.Duration `toml:"store-interval"`
}

// NewConfig returns an instance of Config with defaults.
func NewConfig() Config {
return Config{
StoreEnabled: true,
StoreDatabase: DefaultStoreDatabase,
StoreInterval: toml.Duration(DefaultStoreInterval),
StoreInterval: config.Duration(DefaultStoreInterval),
}
}
4 changes: 2 additions & 2 deletions monitor/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"testing"
"time"

"github.com/BurntSushi/toml"
"github.com/influxdata/config"
"github.com/influxdb/influxdb/monitor"
)

func TestConfig_Parse(t *testing.T) {
// Parse configuration.
var c monitor.Config
if _, err := toml.Decode(`
if err := config.Decode(`
store-enabled=true
store-database="the_db"
store-interval="10m"
Expand Down
4 changes: 2 additions & 2 deletions services/admin/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package admin_test
import (
"testing"

"github.com/BurntSushi/toml"
"github.com/influxdata/config"
"github.com/influxdb/influxdb/services/admin"
)

func TestConfig_Parse(t *testing.T) {
// Parse configuration.
var c admin.Config
if _, err := toml.Decode(`
if err := config.Decode(`
enabled = true
bind-address = ":8083"
https-enabled = true
Expand Down
22 changes: 11 additions & 11 deletions services/collectd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package collectd
import (
"time"

"github.com/influxdb/influxdb/toml"
"github.com/influxdata/config"
)

const (
Expand All @@ -23,7 +23,7 @@ const (
DefaultBatchPending = 10

// DefaultBatchDuration is the default batch timeout duration.
DefaultBatchDuration = toml.Duration(10 * time.Second)
DefaultBatchDuration = config.Duration(10 * time.Second)

// DefaultTypesDB is the default location of the collectd types db file.
DefaultTypesDB = "/usr/share/collectd/types.db"
Expand All @@ -44,15 +44,15 @@ const (

// Config represents a configuration for the collectd service.
type Config struct {
Enabled bool `toml:"enabled"`
BindAddress string `toml:"bind-address"`
Database string `toml:"database"`
RetentionPolicy string `toml:"retention-policy"`
BatchSize int `toml:"batch-size"`
BatchPending int `toml:"batch-pending"`
BatchDuration toml.Duration `toml:"batch-timeout"`
ReadBuffer int `toml:"read-buffer"`
TypesDB string `toml:"typesdb"`
Enabled bool `toml:"enabled"`
BindAddress string `toml:"bind-address"`
Database string `toml:"database"`
RetentionPolicy string `toml:"retention-policy"`
BatchSize int `toml:"batch-size"`
BatchPending int `toml:"batch-pending"`
BatchDuration config.Duration `toml:"batch-timeout"`
ReadBuffer int `toml:"read-buffer"`
TypesDB string `toml:"typesdb"`
}

// NewConfig returns a new instance of Config with defaults.
Expand Down
4 changes: 2 additions & 2 deletions services/collectd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package collectd_test
import (
"testing"

"github.com/BurntSushi/toml"
"github.com/influxdata/config"
"github.com/influxdb/influxdb/services/collectd"
)

func TestConfig_Parse(t *testing.T) {
// Parse configuration.
var c collectd.Config
if _, err := toml.Decode(`
if err := config.Decode(`
enabled = true
bind-address = ":9000"
database = "xxx"
Expand Down
4 changes: 2 additions & 2 deletions services/collectd/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"testing"
"time"

"github.com/influxdata/config"
"github.com/influxdb/influxdb/cluster"
"github.com/influxdb/influxdb/models"
"github.com/influxdb/influxdb/services/meta"
"github.com/influxdb/influxdb/toml"
)

// Test that the service checks / creates the target database on startup.
Expand Down Expand Up @@ -190,7 +190,7 @@ func newTestService(batchSize int, batchDuration time.Duration) *testService {
BindAddress: "127.0.0.1:0",
Database: "collectd_test",
BatchSize: batchSize,
BatchDuration: toml.Duration(batchDuration),
BatchDuration: config.Duration(batchDuration),
}),
}
s.Service.PointsWriter = &s.PointsWriter
Expand Down
6 changes: 3 additions & 3 deletions services/continuous_querier/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package continuous_querier
import (
"time"

"github.com/influxdb/influxdb/toml"
"github.com/influxdata/config"
)

// Default values for aspects of interval computation.
Expand All @@ -23,14 +23,14 @@ type Config struct {
// of the interval for running continuous queries. If you only aggregate continuous queries
// every minute, this should be set to 1 minute. The default is set to '1s' so the interval
// is compatible with most aggregations.
RunInterval toml.Duration `toml:"run-interval"`
RunInterval config.Duration `toml:"run-interval"`
}

// NewConfig returns a new instance of Config with defaults.
func NewConfig() Config {
return Config{
LogEnabled: true,
Enabled: true,
RunInterval: toml.Duration(DefaultRunInterval),
RunInterval: config.Duration(DefaultRunInterval),
}
}
4 changes: 2 additions & 2 deletions services/continuous_querier/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"testing"
"time"

"github.com/BurntSushi/toml"
"github.com/influxdata/config"
"github.com/influxdb/influxdb/services/continuous_querier"
)

func TestConfig_Parse(t *testing.T) {
// Parse configuration.
var c continuous_querier.Config
if _, err := toml.Decode(`
if err := config.Decode(`
run-interval = "1m"
enabled = true
`, &c); err != nil {
Expand Down
28 changes: 14 additions & 14 deletions services/graphite/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"strings"
"time"

"github.com/influxdata/config"
"github.com/influxdb/influxdb/models"
"github.com/influxdb/influxdb/toml"
)

const (
Expand Down Expand Up @@ -51,18 +51,18 @@ const (

// Config represents the configuration for Graphite endpoints.
type Config struct {
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"`
BatchTimeout toml.Duration `toml:"batch-timeout"`
ConsistencyLevel string `toml:"consistency-level"`
Templates []string `toml:"templates"`
Tags []string `toml:"tags"`
Separator string `toml:"separator"`
UDPReadBuffer int `toml:"udp-read-buffer"`
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"`
BatchTimeout config.Duration `toml:"batch-timeout"`
ConsistencyLevel string `toml:"consistency-level"`
Templates []string `toml:"templates"`
Tags []string `toml:"tags"`
Separator string `toml:"separator"`
UDPReadBuffer int `toml:"udp-read-buffer"`
}

// WithDefaults takes the given config and returns a new config with any required
Expand All @@ -85,7 +85,7 @@ func (c *Config) WithDefaults() *Config {
d.BatchPending = DefaultBatchPending
}
if d.BatchTimeout == 0 {
d.BatchTimeout = toml.Duration(DefaultBatchTimeout)
d.BatchTimeout = config.Duration(DefaultBatchTimeout)
}
if d.ConsistencyLevel == "" {
d.ConsistencyLevel = DefaultConsistencyLevel
Expand Down
4 changes: 2 additions & 2 deletions services/graphite/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"testing"
"time"

"github.com/BurntSushi/toml"
"github.com/influxdata/config"
"github.com/influxdb/influxdb/services/graphite"
)

func TestConfig_Parse(t *testing.T) {
// Parse configuration.
var c graphite.Config
if _, err := toml.Decode(`
if err := config.Decode(`
bind-address = ":8080"
database = "mydb"
enabled = true
Expand Down
Loading

0 comments on commit 2d2944d

Please sign in to comment.