diff --git a/cluster/config.go b/cluster/config.go index 76107436877..1f8af13281b 100644 --- a/cluster/config.go +++ b/cluster/config.go @@ -3,7 +3,7 @@ package cluster import ( "time" - "github.com/influxdb/influxdb/toml" + "github.com/influxdata/config" ) const ( @@ -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, } } diff --git a/cluster/config_test.go b/cluster/config_test.go index db5e5ddc103..83370eb9212 100644 --- a/cluster/config_test.go +++ b/cluster/config_test.go @@ -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 { diff --git a/cluster/shard_writer_test.go b/cluster/shard_writer_test.go index 4c68377d9d1..7a2918a1323 100644 --- a/cluster/shard_writer_test.go +++ b/cluster/shard_writer_test.go @@ -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. @@ -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 diff --git a/cmd/influxd/run/command.go b/cmd/influxd/run/command.go index 5ef967e389b..3dd04c1af1a 100644 --- a/cmd/influxd/run/command.go +++ b/cmd/influxd/run/command.go @@ -13,7 +13,7 @@ import ( "strings" "time" - "github.com/BurntSushi/toml" + cfg "github.com/influxdata/config" "github.com/influxdb/influxdb" ) @@ -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 } diff --git a/cmd/influxd/run/server_helpers_test.go b/cmd/influxd/run/server_helpers_test.go index 71c8dbb369b..f523a645f50 100644 --- a/cmd/influxd/run/server_helpers_test.go +++ b/cmd/influxd/run/server_helpers_test.go @@ -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":[{}]}` @@ -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 diff --git a/monitor/config.go b/monitor/config.go index a5a78bf28f4..966f598bf50 100644 --- a/monitor/config.go +++ b/monitor/config.go @@ -3,7 +3,7 @@ package monitor import ( "time" - "github.com/influxdb/influxdb/toml" + "github.com/influxdata/config" ) const ( @@ -20,9 +20,9 @@ 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. @@ -30,6 +30,6 @@ func NewConfig() Config { return Config{ StoreEnabled: true, StoreDatabase: DefaultStoreDatabase, - StoreInterval: toml.Duration(DefaultStoreInterval), + StoreInterval: config.Duration(DefaultStoreInterval), } } diff --git a/monitor/config_test.go b/monitor/config_test.go index ee62e734662..514a3941e50 100644 --- a/monitor/config_test.go +++ b/monitor/config_test.go @@ -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" diff --git a/services/admin/config_test.go b/services/admin/config_test.go index 1ad2e19dd7a..8462fb9d350 100644 --- a/services/admin/config_test.go +++ b/services/admin/config_test.go @@ -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 diff --git a/services/collectd/config.go b/services/collectd/config.go index 97904a08b34..3a91ed7066e 100644 --- a/services/collectd/config.go +++ b/services/collectd/config.go @@ -3,7 +3,7 @@ package collectd import ( "time" - "github.com/influxdb/influxdb/toml" + "github.com/influxdata/config" ) const ( @@ -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" @@ -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. diff --git a/services/collectd/config_test.go b/services/collectd/config_test.go index c419dcfa9c2..6160b0c6ab6 100644 --- a/services/collectd/config_test.go +++ b/services/collectd/config_test.go @@ -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" diff --git a/services/collectd/service_test.go b/services/collectd/service_test.go index 3928b463c47..56d80b5a376 100644 --- a/services/collectd/service_test.go +++ b/services/collectd/service_test.go @@ -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. @@ -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 diff --git a/services/continuous_querier/config.go b/services/continuous_querier/config.go index 584f2ac68e7..6ecd31ae157 100644 --- a/services/continuous_querier/config.go +++ b/services/continuous_querier/config.go @@ -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. @@ -23,7 +23,7 @@ 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. @@ -31,6 +31,6 @@ func NewConfig() Config { return Config{ LogEnabled: true, Enabled: true, - RunInterval: toml.Duration(DefaultRunInterval), + RunInterval: config.Duration(DefaultRunInterval), } } diff --git a/services/continuous_querier/config_test.go b/services/continuous_querier/config_test.go index fb3e9475e3d..3c372384bed 100644 --- a/services/continuous_querier/config_test.go +++ b/services/continuous_querier/config_test.go @@ -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 { diff --git a/services/graphite/config.go b/services/graphite/config.go index fc7b16c98e7..a754b5b4846 100644 --- a/services/graphite/config.go +++ b/services/graphite/config.go @@ -5,8 +5,8 @@ import ( "strings" "time" + "github.com/influxdata/config" "github.com/influxdb/influxdb/models" - "github.com/influxdb/influxdb/toml" ) const ( @@ -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 @@ -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 diff --git a/services/graphite/config_test.go b/services/graphite/config_test.go index e9efc64668e..ec949603327 100644 --- a/services/graphite/config_test.go +++ b/services/graphite/config_test.go @@ -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 diff --git a/services/graphite/service_test.go b/services/graphite/service_test.go index 3e5fb42d4c0..41b052f687c 100644 --- a/services/graphite/service_test.go +++ b/services/graphite/service_test.go @@ -7,11 +7,11 @@ import ( "testing" "time" + cfg "github.com/influxdata/config" "github.com/influxdb/influxdb/cluster" "github.com/influxdb/influxdb/models" "github.com/influxdb/influxdb/services/graphite" "github.com/influxdb/influxdb/services/meta" - "github.com/influxdb/influxdb/toml" ) func Test_ServerGraphiteTCP(t *testing.T) { @@ -22,7 +22,7 @@ func Test_ServerGraphiteTCP(t *testing.T) { config := graphite.Config{} config.Database = "graphitedb" config.BatchSize = 0 // No batching. - config.BatchTimeout = toml.Duration(time.Second) + config.BatchTimeout = cfg.Duration(time.Second) config.BindAddress = ":0" service, err := graphite.NewService(config) @@ -97,7 +97,7 @@ func Test_ServerGraphiteUDP(t *testing.T) { config := graphite.Config{} config.Database = "graphitedb" config.BatchSize = 0 // No batching. - config.BatchTimeout = toml.Duration(time.Second) + config.BatchTimeout = cfg.Duration(time.Second) config.BindAddress = ":10000" config.Protocol = "udp" diff --git a/services/hh/config.go b/services/hh/config.go index cf00df4db9b..942d5c0a6e1 100644 --- a/services/hh/config.go +++ b/services/hh/config.go @@ -4,7 +4,7 @@ import ( "errors" "time" - "github.com/influxdb/influxdb/toml" + "github.com/influxdata/config" ) const ( @@ -37,14 +37,14 @@ const ( // Config is a hinted handoff configuration. type Config struct { - Enabled bool `toml:"enabled"` - Dir string `toml:"dir"` - MaxSize int64 `toml:"max-size"` - MaxAge toml.Duration `toml:"max-age"` - RetryRateLimit int64 `toml:"retry-rate-limit"` - RetryInterval toml.Duration `toml:"retry-interval"` - RetryMaxInterval toml.Duration `toml:"retry-max-interval"` - PurgeInterval toml.Duration `toml:"purge-interval"` + Enabled bool `toml:"enabled"` + Dir string `toml:"dir"` + MaxSize int64 `toml:"max-size"` + MaxAge config.Duration `toml:"max-age"` + RetryRateLimit int64 `toml:"retry-rate-limit"` + RetryInterval config.Duration `toml:"retry-interval"` + RetryMaxInterval config.Duration `toml:"retry-max-interval"` + PurgeInterval config.Duration `toml:"purge-interval"` } // NewConfig returns a new Config. @@ -52,11 +52,11 @@ func NewConfig() Config { return Config{ Enabled: false, MaxSize: DefaultMaxSize, - MaxAge: toml.Duration(DefaultMaxAge), + MaxAge: config.Duration(DefaultMaxAge), RetryRateLimit: DefaultRetryRateLimit, - RetryInterval: toml.Duration(DefaultRetryInterval), - RetryMaxInterval: toml.Duration(DefaultRetryMaxInterval), - PurgeInterval: toml.Duration(DefaultPurgeInterval), + RetryInterval: config.Duration(DefaultRetryInterval), + RetryMaxInterval: config.Duration(DefaultRetryMaxInterval), + PurgeInterval: config.Duration(DefaultPurgeInterval), } } diff --git a/services/hh/config_test.go b/services/hh/config_test.go index f9fbfe172d0..5f7efe2edc6 100644 --- a/services/hh/config_test.go +++ b/services/hh/config_test.go @@ -4,14 +4,14 @@ import ( "testing" "time" - "github.com/BurntSushi/toml" + "github.com/influxdata/config" "github.com/influxdb/influxdb/services/hh" ) func TestConfigParse(t *testing.T) { // Parse configuration. var c hh.Config - if _, err := toml.Decode(` + if err := config.Decode(` enabled = false retry-interval = "10m" retry-max-interval = "100m" @@ -57,7 +57,7 @@ purge-interval = "1h" func TestDefaultDisabled(t *testing.T) { // Parse empty configuration. var c hh.Config - if _, err := toml.Decode(``, &c); err != nil { + if err := config.Decode(``, &c); err != nil { t.Fatal(err) } diff --git a/services/httpd/config_test.go b/services/httpd/config_test.go index 9a8d034cdde..c8116a66b65 100644 --- a/services/httpd/config_test.go +++ b/services/httpd/config_test.go @@ -3,14 +3,14 @@ package httpd_test import ( "testing" - "github.com/BurntSushi/toml" + "github.com/influxdata/config" "github.com/influxdb/influxdb/services/httpd" ) func TestConfig_Parse(t *testing.T) { // Parse configuration. var c httpd.Config - if _, err := toml.Decode(` + if err := config.Decode(` enabled = true bind-address = ":8080" auth-enabled = true diff --git a/services/meta/config.go b/services/meta/config.go index 4a5202cd5d0..e68844a4de4 100644 --- a/services/meta/config.go +++ b/services/meta/config.go @@ -5,7 +5,7 @@ import ( "net" "time" - "github.com/influxdb/influxdb/toml" + "github.com/influxdata/config" ) const ( @@ -57,18 +57,18 @@ type Config struct { HTTPSCertificate string `toml:"https-certificate"` // JoinPeers if specified gives other metastore servers to join this server to the cluster - JoinPeers []string `toml:"-"` - RetentionAutoCreate bool `toml:"retention-autocreate"` - ElectionTimeout toml.Duration `toml:"election-timeout"` - HeartbeatTimeout toml.Duration `toml:"heartbeat-timeout"` - LeaderLeaseTimeout toml.Duration `toml:"leader-lease-timeout"` - CommitTimeout toml.Duration `toml:"commit-timeout"` - ClusterTracing bool `toml:"cluster-tracing"` - RaftPromotionEnabled bool `toml:"raft-promotion-enabled"` - LoggingEnabled bool `toml:"logging-enabled"` - PprofEnabled bool `toml:"pprof-enabled"` - - LeaseDuration toml.Duration `toml:"lease-duration"` + JoinPeers []string `toml:"-"` + RetentionAutoCreate bool `toml:"retention-autocreate"` + ElectionTimeout config.Duration `toml:"election-timeout"` + HeartbeatTimeout config.Duration `toml:"heartbeat-timeout"` + LeaderLeaseTimeout config.Duration `toml:"leader-lease-timeout"` + CommitTimeout config.Duration `toml:"commit-timeout"` + ClusterTracing bool `toml:"cluster-tracing"` + RaftPromotionEnabled bool `toml:"raft-promotion-enabled"` + LoggingEnabled bool `toml:"logging-enabled"` + PprofEnabled bool `toml:"pprof-enabled"` + + LeaseDuration config.Duration `toml:"lease-duration"` } // NewConfig builds a new configuration with default values. @@ -78,12 +78,12 @@ func NewConfig() *Config { BindAddress: DefaultRaftBindAddress, HTTPBindAddress: DefaultHTTPBindAddress, RetentionAutoCreate: true, - ElectionTimeout: toml.Duration(DefaultElectionTimeout), - HeartbeatTimeout: toml.Duration(DefaultHeartbeatTimeout), - LeaderLeaseTimeout: toml.Duration(DefaultLeaderLeaseTimeout), - CommitTimeout: toml.Duration(DefaultCommitTimeout), + ElectionTimeout: config.Duration(DefaultElectionTimeout), + HeartbeatTimeout: config.Duration(DefaultHeartbeatTimeout), + LeaderLeaseTimeout: config.Duration(DefaultLeaderLeaseTimeout), + CommitTimeout: config.Duration(DefaultCommitTimeout), RaftPromotionEnabled: DefaultRaftPromotionEnabled, - LeaseDuration: toml.Duration(DefaultLeaseDuration), + LeaseDuration: config.Duration(DefaultLeaseDuration), LoggingEnabled: DefaultLoggingEnabled, } } diff --git a/services/meta/config_test.go b/services/meta/config_test.go index b2b976852eb..c375e7f89c9 100644 --- a/services/meta/config_test.go +++ b/services/meta/config_test.go @@ -4,14 +4,14 @@ import ( "testing" "time" - "github.com/BurntSushi/toml" + "github.com/influxdata/config" "github.com/influxdb/influxdb/services/meta" ) func TestConfig_Parse(t *testing.T) { // Parse configuration. var c meta.Config - if _, err := toml.Decode(` + if err := config.Decode(` enabled = false dir = "/tmp/foo" election-timeout = "10s" diff --git a/services/meta/service_test.go b/services/meta/service_test.go index 505b8a660a0..ce63a08d107 100644 --- a/services/meta/service_test.go +++ b/services/meta/service_test.go @@ -13,10 +13,10 @@ import ( "testing" "time" + "github.com/influxdata/config" "github.com/influxdb/influxdb/influxql" "github.com/influxdb/influxdb/services/meta" "github.com/influxdb/influxdb/tcp" - "github.com/influxdb/influxdb/toml" ) func TestMetaService_CreateDatabase(t *testing.T) { @@ -1219,7 +1219,7 @@ func newConfig() *meta.Config { cfg.BindAddress = "127.0.0.1:0" cfg.HTTPBindAddress = "127.0.0.1:0" cfg.Dir = testTempDir(2) - cfg.LeaseDuration = toml.Duration(1 * time.Second) + cfg.LeaseDuration = config.Duration(1 * time.Second) return cfg } diff --git a/services/opentsdb/config.go b/services/opentsdb/config.go index 8486a66e541..fbae0e10996 100644 --- a/services/opentsdb/config.go +++ b/services/opentsdb/config.go @@ -3,7 +3,7 @@ package opentsdb import ( "time" - "github.com/influxdb/influxdb/toml" + "github.com/influxdata/config" ) const ( @@ -31,17 +31,17 @@ const ( // Config represents the configuration of the OpenTSDB service. type Config struct { - Enabled bool `toml:"enabled"` - BindAddress string `toml:"bind-address"` - Database string `toml:"database"` - RetentionPolicy string `toml:"retention-policy"` - ConsistencyLevel string `toml:"consistency-level"` - TLSEnabled bool `toml:"tls-enabled"` - Certificate string `toml:"certificate"` - BatchSize int `toml:"batch-size"` - BatchPending int `toml:"batch-pending"` - BatchTimeout toml.Duration `toml:"batch-timeout"` - LogPointErrors bool `toml:"log-point-errors"` + Enabled bool `toml:"enabled"` + BindAddress string `toml:"bind-address"` + Database string `toml:"database"` + RetentionPolicy string `toml:"retention-policy"` + ConsistencyLevel string `toml:"consistency-level"` + TLSEnabled bool `toml:"tls-enabled"` + Certificate string `toml:"certificate"` + BatchSize int `toml:"batch-size"` + BatchPending int `toml:"batch-pending"` + BatchTimeout config.Duration `toml:"batch-timeout"` + LogPointErrors bool `toml:"log-point-errors"` } // NewConfig returns a new config for the service. @@ -55,7 +55,7 @@ func NewConfig() Config { Certificate: "/etc/ssl/influxdb.pem", BatchSize: DefaultBatchSize, BatchPending: DefaultBatchPending, - BatchTimeout: toml.Duration(DefaultBatchTimeout), + BatchTimeout: config.Duration(DefaultBatchTimeout), LogPointErrors: true, } } diff --git a/services/opentsdb/config_test.go b/services/opentsdb/config_test.go index 84bb999c4be..9cc98537e1f 100644 --- a/services/opentsdb/config_test.go +++ b/services/opentsdb/config_test.go @@ -3,14 +3,14 @@ package opentsdb_test import ( "testing" - "github.com/BurntSushi/toml" + "github.com/influxdata/config" "github.com/influxdb/influxdb/services/opentsdb" ) func TestConfig_Parse(t *testing.T) { // Parse configuration. var c opentsdb.Config - if _, err := toml.Decode(` + if err := config.Decode(` enabled = true bind-address = ":9000" database = "xxx" diff --git a/services/precreator/config.go b/services/precreator/config.go index af0f34b16e6..28744cd3727 100644 --- a/services/precreator/config.go +++ b/services/precreator/config.go @@ -3,7 +3,7 @@ package precreator import ( "time" - "github.com/influxdb/influxdb/toml" + "github.com/influxdata/config" ) const ( @@ -17,16 +17,16 @@ const ( // Config represents the configuration for shard precreation. type Config struct { - Enabled bool `toml:"enabled"` - CheckInterval toml.Duration `toml:"check-interval"` - AdvancePeriod toml.Duration `toml:"advance-period"` + Enabled bool `toml:"enabled"` + CheckInterval config.Duration `toml:"check-interval"` + AdvancePeriod config.Duration `toml:"advance-period"` } // NewConfig returns a new Config with defaults. func NewConfig() Config { return Config{ Enabled: true, - CheckInterval: toml.Duration(DefaultCheckInterval), - AdvancePeriod: toml.Duration(DefaultAdvancePeriod), + CheckInterval: config.Duration(DefaultCheckInterval), + AdvancePeriod: config.Duration(DefaultAdvancePeriod), } } diff --git a/services/precreator/config_test.go b/services/precreator/config_test.go index e247672830f..2a5c6acc887 100644 --- a/services/precreator/config_test.go +++ b/services/precreator/config_test.go @@ -4,14 +4,14 @@ import ( "testing" "time" - "github.com/BurntSushi/toml" + "github.com/influxdata/config" "github.com/influxdb/influxdb/services/precreator" ) func TestConfig_Parse(t *testing.T) { // Parse configuration. var c precreator.Config - if _, err := toml.Decode(` + if err := config.Decode(` enabled = true check-interval = "2m" advance-period = "10m" diff --git a/services/precreator/service_test.go b/services/precreator/service_test.go index 8e05f584e58..3a058fb1613 100644 --- a/services/precreator/service_test.go +++ b/services/precreator/service_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - "github.com/influxdb/influxdb/toml" + "github.com/influxdata/config" ) func Test_ShardPrecreation(t *testing.T) { @@ -28,8 +28,8 @@ func Test_ShardPrecreation(t *testing.T) { } srv, err := NewService(Config{ - CheckInterval: toml.Duration(time.Minute), - AdvancePeriod: toml.Duration(advancePeriod), + CheckInterval: config.Duration(time.Minute), + AdvancePeriod: config.Duration(advancePeriod), }) if err != nil { t.Fatalf("failed to create shard precreation service: %s", err.Error()) diff --git a/services/retention/config.go b/services/retention/config.go index b4a259d1d93..fdb659a707e 100644 --- a/services/retention/config.go +++ b/services/retention/config.go @@ -3,16 +3,16 @@ package retention import ( "time" - "github.com/influxdb/influxdb/toml" + "github.com/influxdata/config" ) // Config represents the configuration for the retention service. type Config struct { - Enabled bool `toml:"enabled"` - CheckInterval toml.Duration `toml:"check-interval"` + Enabled bool `toml:"enabled"` + CheckInterval config.Duration `toml:"check-interval"` } // NewConfig returns an instance of Config with defaults. func NewConfig() Config { - return Config{Enabled: true, CheckInterval: toml.Duration(30 * time.Minute)} + return Config{Enabled: true, CheckInterval: config.Duration(30 * time.Minute)} } diff --git a/services/retention/config_test.go b/services/retention/config_test.go index c1bbca90dc5..a2f010dae87 100644 --- a/services/retention/config_test.go +++ b/services/retention/config_test.go @@ -4,14 +4,14 @@ import ( "testing" "time" - "github.com/BurntSushi/toml" + "github.com/influxdata/config" "github.com/influxdb/influxdb/services/retention" ) func TestConfig_Parse(t *testing.T) { // Parse configuration. var c retention.Config - if _, err := toml.Decode(` + if err := config.Decode(` enabled = true check-interval = "1s" `, &c); err != nil { diff --git a/services/subscriber/config_test.go b/services/subscriber/config_test.go index 7d633a3f727..4a5984ef3dc 100644 --- a/services/subscriber/config_test.go +++ b/services/subscriber/config_test.go @@ -3,14 +3,14 @@ package subscriber_test import ( "testing" - "github.com/BurntSushi/toml" + "github.com/influxdata/config" "github.com/influxdb/influxdb/services/subscriber" ) func TestConfig_Parse(t *testing.T) { // Parse configuration. var c subscriber.Config - if _, err := toml.Decode(` + if err := config.Decode(` enabled = false `, &c); err != nil { t.Fatal(err) diff --git a/services/udp/config.go b/services/udp/config.go index 30b949c2196..5c29bac5893 100644 --- a/services/udp/config.go +++ b/services/udp/config.go @@ -3,7 +3,7 @@ package udp import ( "time" - "github.com/influxdb/influxdb/toml" + "github.com/influxdata/config" ) const ( @@ -56,13 +56,13 @@ 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"` - ReadBuffer int `toml:"read-buffer"` - BatchTimeout toml.Duration `toml:"batch-timeout"` - UDPPayloadSize int `toml:"udp-payload-size"` + Database string `toml:"database"` + RetentionPolicy string `toml:"retention-policy"` + BatchSize int `toml:"batch-size"` + BatchPending int `toml:"batch-pending"` + ReadBuffer int `toml:"read-buffer"` + BatchTimeout config.Duration `toml:"batch-timeout"` + UDPPayloadSize int `toml:"udp-payload-size"` } // WithDefaults takes the given config and returns a new config with any required @@ -79,7 +79,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.ReadBuffer == 0 { d.ReadBuffer = DefaultReadBuffer diff --git a/services/udp/config_test.go b/services/udp/config_test.go index 71ac272ca5d..9f61cbf742d 100644 --- a/services/udp/config_test.go +++ b/services/udp/config_test.go @@ -4,14 +4,14 @@ import ( "testing" "time" - "github.com/BurntSushi/toml" + "github.com/influxdata/config" "github.com/influxdb/influxdb/services/udp" ) func TestConfig_Parse(t *testing.T) { // Parse configuration. var c udp.Config - if _, err := toml.Decode(` + if err := config.Decode(` enabled = true bind-address = ":4444" database = "awesomedb" diff --git a/stress/basic.go b/stress/basic.go index ad82f1292c9..86cbd844265 100644 --- a/stress/basic.go +++ b/stress/basic.go @@ -70,6 +70,7 @@ func (f AbstractFields) Template() (string, []string) { // BasicPointGenerator implements the PointGenerator interface type BasicPointGenerator struct { + Enabled bool `toml:"enabled"` PointCount int `toml:"point_count"` Tick string `toml:"tick"` Jitter bool `toml:"jitter"` diff --git a/stress/config.go b/stress/config.go index 6749986b6a8..223accc500a 100644 --- a/stress/config.go +++ b/stress/config.go @@ -3,7 +3,7 @@ package stress import ( "flag" "fmt" - "github.com/BurntSushi/toml" + "github.com/influxdata/config" "strings" ) @@ -78,20 +78,26 @@ func DecodeFile(s string) (*Config, error) { t := &Config{} // Decode the toml file - if _, err := toml.DecodeFile(s, t); err != nil { + cfg, err := config.NewConfig(s, struct{}{}) + if err != nil { + return nil, err + } + + cfg.Decode(t) + if err != nil { return nil, err } return t, nil } -// DecodeConfig takes a file path for a toml config file +// DecodeConfig takes string of toml source // and returns a pointer to a Config Struct. func DecodeConfig(s string) (*Config, error) { t := &Config{} // Decode the toml file - if _, err := toml.Decode(s, t); err != nil { + if err := config.Decode(s, t); err != nil { return nil, err } diff --git a/stress/run.go b/stress/run.go index 4aaed4ddc93..824ad860c39 100644 --- a/stress/run.go +++ b/stress/run.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "net/http" + "strconv" "sync" "time" ) @@ -204,6 +205,15 @@ func NewWriter(p PointGenerator, i InfluxClient) Writer { // Query is query type Query string +func (q *Query) UnmarshalTOML(data []byte) error { + str, err := strconv.Unquote(string(data)) + if err != nil { + return err + } + *q = Query(str) + return nil +} + // QueryGenerator is an interface that is used // to define queries that will be ran on the DB. type QueryGenerator interface { diff --git a/stress/stress.toml b/stress/stress.toml index fcbd4a4d76c..954fb2af7e7 100644 --- a/stress/stress.toml +++ b/stress/stress.toml @@ -23,7 +23,7 @@ value = "us-west" [[write.point_generator.basic.field]] key = "value" - value = "float64" + type = "float64" [write.influx_client] diff --git a/stress/template.go b/stress/template.go index 71572fff8b2..7b3360c819a 100644 --- a/stress/template.go +++ b/stress/template.go @@ -27,7 +27,7 @@ var s = ` value = "us-west" [[write.point_generator.basic.field]] key = "value" - value = "float64" + type = "float64" [write.influx_client] diff --git a/toml/toml.go b/toml/toml.go deleted file mode 100644 index 105c908c70a..00000000000 --- a/toml/toml.go +++ /dev/null @@ -1,72 +0,0 @@ -package toml - -import ( - "fmt" - "strconv" - "time" -) - -// maxInt is the largest integer representable by a word (architecture dependent). -const maxInt = int64(^uint(0) >> 1) - -// Duration is a TOML wrapper type for time.Duration. -type Duration time.Duration - -func (d Duration) String() string { - return time.Duration(d).String() -} - -// UnmarshalText parses a TOML value into a duration value. -func (d *Duration) UnmarshalText(text []byte) error { - // Ignore if there is no value set. - if len(text) == 0 { - return nil - } - - // Otherwise parse as a duration formatted string. - duration, err := time.ParseDuration(string(text)) - if err != nil { - return err - } - - // Set duration and return. - *d = Duration(duration) - return nil -} - -// MarshalText converts a duration to a string for decoding toml -func (d Duration) MarshalText() (text []byte, err error) { - return []byte(d.String()), nil -} - -// Size represents a TOML parseable file size. -// Users can specify size using "m" for megabytes and "g" for gigabytes. -type Size int - -// UnmarshalText parses a byte size from text. -func (s *Size) UnmarshalText(text []byte) error { - // Parse numeric portion of value. - length := len(string(text)) - size, err := strconv.ParseInt(string(text[:length-1]), 10, 64) - if err != nil { - return err - } - - // Parse unit of measure ("m", "g", etc). - switch suffix := text[len(text)-1]; suffix { - case 'm': - size *= 1 << 20 // MB - case 'g': - size *= 1 << 30 // GB - default: - return fmt.Errorf("unknown size suffix: %c", suffix) - } - - // Check for overflow. - if size > maxInt { - return fmt.Errorf("size %d cannot be represented by an int", size) - } - - *s = Size(size) - return nil -} diff --git a/toml/toml_test.go b/toml/toml_test.go deleted file mode 100644 index dcf56b1ce89..00000000000 --- a/toml/toml_test.go +++ /dev/null @@ -1,45 +0,0 @@ -package toml_test - -import ( - "bytes" - "strings" - "testing" - "time" - - "github.com/BurntSushi/toml" - "github.com/influxdb/influxdb/cmd/influxd/run" - itoml "github.com/influxdb/influxdb/toml" -) - -// Ensure that megabyte sizes can be parsed. -func TestSize_UnmarshalText_MB(t *testing.T) { - var s itoml.Size - if err := s.UnmarshalText([]byte("200m")); err != nil { - t.Fatalf("unexpected error: %s", err) - } else if s != 200*(1<<20) { - t.Fatalf("unexpected size: %d", s) - } -} - -// Ensure that gigabyte sizes can be parsed. -func TestSize_UnmarshalText_GB(t *testing.T) { - var s itoml.Size - if err := s.UnmarshalText([]byte("1g")); err != nil { - t.Fatalf("unexpected error: %s", err) - } else if s != 1073741824 { - t.Fatalf("unexpected size: %d", s) - } -} - -func TestConfig_Encode(t *testing.T) { - var c run.Config - c.Cluster.WriteTimeout = itoml.Duration(time.Minute) - buf := new(bytes.Buffer) - if err := toml.NewEncoder(buf).Encode(&c); err != nil { - t.Fatal("Failed to encode: ", err) - } - got, search := buf.String(), `write-timeout = "1m0s"` - if !strings.Contains(got, search) { - t.Fatalf("Encoding config failed.\nfailed to find %s in:\n%s\n", search, got) - } -} diff --git a/tsdb/config.go b/tsdb/config.go index 91d4c0bc866..b143fd38e62 100644 --- a/tsdb/config.go +++ b/tsdb/config.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - "github.com/influxdb/influxdb/toml" + "github.com/influxdata/config" ) const ( @@ -76,28 +76,28 @@ type Config struct { Engine string `toml:"engine"` // WAL config options for b1 (introduced in 0.9.2) - MaxWALSize int `toml:"max-wal-size"` - WALFlushInterval toml.Duration `toml:"wal-flush-interval"` - WALPartitionFlushDelay toml.Duration `toml:"wal-partition-flush-delay"` + MaxWALSize int `toml:"max-wal-size"` + WALFlushInterval config.Duration `toml:"wal-flush-interval"` + WALPartitionFlushDelay config.Duration `toml:"wal-partition-flush-delay"` // WAL configuration options for bz1 (introduced in 0.9.3) - WALDir string `toml:"wal-dir"` - WALLoggingEnabled bool `toml:"wal-logging-enabled"` - WALReadySeriesSize int `toml:"wal-ready-series-size"` - WALCompactionThreshold float64 `toml:"wal-compaction-threshold"` - WALMaxSeriesSize int `toml:"wal-max-series-size"` - WALFlushColdInterval toml.Duration `toml:"wal-flush-cold-interval"` - WALPartitionSizeThreshold uint64 `toml:"wal-partition-size-threshold"` + WALDir string `toml:"wal-dir"` + WALLoggingEnabled bool `toml:"wal-logging-enabled"` + WALReadySeriesSize int `toml:"wal-ready-series-size"` + WALCompactionThreshold float64 `toml:"wal-compaction-threshold"` + WALMaxSeriesSize int `toml:"wal-max-series-size"` + WALFlushColdInterval config.Duration `toml:"wal-flush-cold-interval"` + WALPartitionSizeThreshold uint64 `toml:"wal-partition-size-threshold"` // Query logging QueryLogEnabled bool `toml:"query-log-enabled"` // Compaction options for tsm1 (descriptions above with defaults) - CacheMaxMemorySize uint64 `toml:"cache-max-memory-size"` - CacheSnapshotMemorySize uint64 `toml:"cache-snapshot-memory-size"` - CacheSnapshotWriteColdDuration toml.Duration `toml:"cache-snapshot-write-cold-duration"` - CompactFullWriteColdDuration toml.Duration `toml:"compact-full-write-cold-duration"` - MaxPointsPerBlock int `toml:"max-points-per-block"` + CacheMaxMemorySize uint64 `toml:"cache-max-memory-size"` + CacheSnapshotMemorySize uint64 `toml:"cache-snapshot-memory-size"` + CacheSnapshotWriteColdDuration config.Duration `toml:"cache-snapshot-write-cold-duration"` + CompactFullWriteColdDuration config.Duration `toml:"compact-full-write-cold-duration"` + MaxPointsPerBlock int `toml:"max-points-per-block"` DataLoggingEnabled bool `toml:"data-logging-enabled"` } @@ -107,22 +107,22 @@ func NewConfig() Config { Engine: DefaultEngine, Enabled: true, // data node enabled by default MaxWALSize: DefaultMaxWALSize, - WALFlushInterval: toml.Duration(DefaultWALFlushInterval), - WALPartitionFlushDelay: toml.Duration(DefaultWALPartitionFlushDelay), + WALFlushInterval: config.Duration(DefaultWALFlushInterval), + WALPartitionFlushDelay: config.Duration(DefaultWALPartitionFlushDelay), WALLoggingEnabled: true, WALReadySeriesSize: DefaultReadySeriesSize, WALCompactionThreshold: DefaultCompactionThreshold, WALMaxSeriesSize: DefaultMaxSeriesSize, - WALFlushColdInterval: toml.Duration(DefaultFlushColdInterval), + WALFlushColdInterval: config.Duration(DefaultFlushColdInterval), WALPartitionSizeThreshold: DefaultPartitionSizeThreshold, QueryLogEnabled: true, CacheMaxMemorySize: DefaultCacheMaxMemorySize, CacheSnapshotMemorySize: DefaultCacheSnapshotMemorySize, - CacheSnapshotWriteColdDuration: toml.Duration(DefaultCacheSnapshotWriteColdDuration), - CompactFullWriteColdDuration: toml.Duration(DefaultCompactFullWriteColdDuration), + CacheSnapshotWriteColdDuration: config.Duration(DefaultCacheSnapshotWriteColdDuration), + CompactFullWriteColdDuration: config.Duration(DefaultCompactFullWriteColdDuration), DataLoggingEnabled: true, }