From ab9568020870f2df91548d69dc31d4bdfc4a7522 Mon Sep 17 00:00:00 2001 From: Tim Raymond Date: Thu, 17 Dec 2015 11:22:31 -0500 Subject: [PATCH] Change configuration package to influxdata/config 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]. [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. --- Godeps | 3 + cluster/config.go | 18 +++--- cluster/config_test.go | 4 +- cluster/shard_writer_test.go | 4 +- cmd/influxd/run/command.go | 6 +- cmd/influxd/run/config.go | 46 +++++--------- cmd/influxd/run/config_command.go | 4 +- cmd/influxd/run/server_helpers_test.go | 2 +- monitor/config.go | 10 +-- monitor/config_test.go | 4 +- services/admin/config_test.go | 4 +- services/collectd/config.go | 22 +++---- services/collectd/config_test.go | 4 +- services/collectd/service_test.go | 4 +- services/continuous_querier/config.go | 6 +- services/continuous_querier/config_test.go | 4 +- services/graphite/config.go | 30 ++++----- services/graphite/config_test.go | 4 +- services/graphite/service_test.go | 6 +- services/hh/config.go | 26 ++++---- services/hh/config_test.go | 6 +- services/httpd/config_test.go | 4 +- services/meta/config.go | 36 +++++------ services/meta/config_test.go | 4 +- services/meta/service_test.go | 4 +- services/opentsdb/config.go | 26 ++++---- services/opentsdb/config_test.go | 4 +- services/precreator/config.go | 12 ++-- services/precreator/config_test.go | 4 +- services/precreator/service_test.go | 6 +- services/retention/config.go | 8 +-- services/retention/config_test.go | 4 +- services/subscriber/config_test.go | 4 +- services/udp/config.go | 22 +++---- services/udp/config_test.go | 4 +- stress/basic.go | 1 + stress/config.go | 14 +++-- stress/run.go | 10 +++ stress/stress.toml | 2 +- stress/template.go | 2 +- toml/toml.go | 72 ---------------------- toml/toml_test.go | 45 -------------- tsdb/config.go | 42 ++++++------- 43 files changed, 218 insertions(+), 329 deletions(-) delete mode 100644 toml/toml.go delete mode 100644 toml/toml_test.go diff --git a/Godeps b/Godeps index d429ffc4e27..520a3df8fb0 100644 --- a/Godeps +++ b/Godeps @@ -11,9 +11,12 @@ github.com/golang/snappy 5979233c5d6225d4a8e438cdd0b411888449ddab github.com/hashicorp/go-msgpack fa3f63826f7c23912c15263591e65d54d080b458 github.com/hashicorp/raft 8fd9a2fdfd154f4b393aa24cff91e3c317efe839 github.com/hashicorp/raft-boltdb d1e82c1ec3f15ee991f7cc7ffd5b67ff6f5bbaee +github.com/influxdata/config 45e0b9a7d1805982fca48b9c753c3b2541aea2bd +github.com/influxdata/toml 51291e16df98ff89f93f3b949ff023ca1ad599b4 github.com/influxdata/usage-client 475977e68d79883d9c8d67131c84e4241523f452 github.com/jwilder/encoding 07d88d4f35eec497617bee0c7bfe651a796dae13 github.com/kimor79/gollectd 61d0deeb4ffcc167b2a1baa8efd72365692811bc +github.com/naoina/go-stringutil 6b638e95a32d0c1131db0e7fe83775cbea4a0d0b github.com/paulbellamy/ratecounter 5a11f585a31379765c190c033b6ad39956584447 github.com/peterh/liner ad1edfd30321d8f006ccf05f1e0524adeb943060 github.com/rakyll/statik 274df120e9065bdd08eb1120e0375e3dc1ae8465 diff --git a/cluster/config.go b/cluster/config.go index 0f1453ec2fa..1f8af13281b 100644 --- a/cluster/config.go +++ b/cluster/config.go @@ -3,7 +3,7 @@ package cluster import ( "time" - "github.com/influxdata/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 ed3bdf8c3cf..f55512107ee 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/influxdata/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 ffbcbebaa1f..c434cc72a54 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/influxdata/influxdb/cluster" "github.com/influxdata/influxdb/models" - "github.com/influxdata/influxdb/toml" ) // Ensure the shard writer can successfully write a single request. @@ -195,7 +195,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.TSDBStore diff --git a/cmd/influxd/run/command.go b/cmd/influxd/run/command.go index e3a4bff6fd5..8734b9ee948 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" ) const logo = ` @@ -212,9 +212,11 @@ func (cmd *Command) ParseConfig(path string) (*Config, error) { } log.Printf("Using configuration at: %s\n", path) + l := log.New(cmd.Stderr, "[config] ", log.LstdFlags) config := NewConfig() - if _, err := toml.DecodeFile(path, &config); err != nil { + cfg.SetLogger(l) + if err := cfg.DecodeFile(path, config); err != nil { return nil, err } diff --git a/cmd/influxd/run/config.go b/cmd/influxd/run/config.go index bbfa18c742d..702c881088b 100644 --- a/cmd/influxd/run/config.go +++ b/cmd/influxd/run/config.go @@ -39,6 +39,18 @@ const ( // Config represents the configuration format for the influxd binary. type Config struct { + // Server reporting + ReportingDisabled bool `toml:"reporting-disabled"` + + // BindAddress is the address that all TCP services use (Raft, Snapshot, Cluster, etc.) + BindAddress string `toml:"bind-address"` + + // Hostname is the hostname portion to use when registering local + // addresses. This hostname must be resolvable from other nodes. + Hostname string `toml:"hostname"` + + Join string `toml:"join"` + Meta *meta.Config `toml:"meta"` Data tsdb.Config `toml:"data"` Cluster cluster.Config `toml:"cluster"` @@ -49,25 +61,13 @@ type Config struct { Monitor monitor.Config `toml:"monitor"` Subscriber subscriber.Config `toml:"subscriber"` HTTPD httpd.Config `toml:"http"` - Graphites []graphite.Config `toml:"graphite"` + Graphites []graphite.Config `toml:"graphite" doc:"List of graphite listen endpoints"` Collectd collectd.Config `toml:"collectd"` OpenTSDB opentsdb.Config `toml:"opentsdb"` UDPs []udp.Config `toml:"udp"` ContinuousQuery continuous_querier.Config `toml:"continuous_queries"` HintedHandoff hh.Config `toml:"hinted-handoff"` - - // Server reporting - ReportingDisabled bool `toml:"reporting-disabled"` - - // BindAddress is the address that all TCP services use (Raft, Snapshot, Cluster, etc.) - BindAddress string `toml:"bind-address"` - - // Hostname is the hostname portion to use when registering local - // addresses. This hostname must be resolvable from other nodes. - Hostname string `toml:"hostname"` - - Join string `toml:"join"` } // NewConfig returns an instance of Config with reasonable defaults. @@ -90,30 +90,14 @@ 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` - + c.UDPs = []udp.Config{udp.NewConfig()} + c.Graphites = []graphite.Config{graphite.NewConfig()} return c } -// InitTableAttrs initialises all ARRAY attributes if 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 diff --git a/cmd/influxd/run/config_command.go b/cmd/influxd/run/config_command.go index ee102213e00..22b23c1b3d7 100644 --- a/cmd/influxd/run/config_command.go +++ b/cmd/influxd/run/config_command.go @@ -7,6 +7,7 @@ import ( "os" "github.com/BurntSushi/toml" + cfg "github.com/influxdata/config" ) // PrintConfigCommand represents the command executed by "influxd config". @@ -51,7 +52,7 @@ func (cmd *PrintConfigCommand) Run(args ...string) error { return fmt.Errorf("%s. To generate a valid configuration file run `influxd config > influxdb.generated.conf`", err) } - toml.NewEncoder(cmd.Stdout).Encode(config) + cfg.NewEncoder(cmd.Stdout).Encode(config) fmt.Fprint(cmd.Stdout, "\n") return nil @@ -68,7 +69,6 @@ func (cmd *PrintConfigCommand) parseConfig(path string) (*Config, error) { if _, err := toml.DecodeFile(path, &config); err != nil { return nil, err } - config.InitTableAttrs() return config, nil } diff --git a/cmd/influxd/run/server_helpers_test.go b/cmd/influxd/run/server_helpers_test.go index a5bee471d2d..82c7d1e3142 100644 --- a/cmd/influxd/run/server_helpers_test.go +++ b/cmd/influxd/run/server_helpers_test.go @@ -18,11 +18,11 @@ import ( "testing" "time" + toml "github.com/influxdata/config" "github.com/influxdata/influxdb/client/v2" "github.com/influxdata/influxdb/cmd/influxd/run" "github.com/influxdata/influxdb/services/httpd" "github.com/influxdata/influxdb/services/meta" - "github.com/influxdata/influxdb/toml" ) const emptyResults = `{"results":[{}]}` diff --git a/monitor/config.go b/monitor/config.go index 68e862f2edb..966f598bf50 100644 --- a/monitor/config.go +++ b/monitor/config.go @@ -3,7 +3,7 @@ package monitor import ( "time" - "github.com/influxdata/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 e0b55988da1..2a0d8b992e9 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/influxdata/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 69690811007..90c27bc121f 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/influxdata/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 a794b352fe6..3a91ed7066e 100644 --- a/services/collectd/config.go +++ b/services/collectd/config.go @@ -3,7 +3,7 @@ package collectd import ( "time" - "github.com/influxdata/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 46eeee80576..b65a9ec4e3d 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/influxdata/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 d475b0aff32..eaa81a83795 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/influxdata/influxdb/cluster" "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/services/meta" - "github.com/influxdata/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 e98b791e240..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/influxdata/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 0d3fbd7985a..19f8e3578e8 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/influxdata/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 b3ea197f984..cb4c1694244 100644 --- a/services/graphite/config.go +++ b/services/graphite/config.go @@ -5,8 +5,8 @@ import ( "strings" "time" + "github.com/influxdata/config" "github.com/influxdata/influxdb/models" - "github.com/influxdata/influxdb/toml" ) const ( @@ -51,18 +51,18 @@ const ( // Config represents the configuration for Graphite endpoints. type Config struct { - Enabled bool `toml:"enabled"` - BindAddress string `toml:"bind-address"` - Database string `toml:"database"` - 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"` + Enabled bool `toml:"enabled"` + BindAddress string `toml:"bind-address"` + Database string `toml:"database"` + 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"` } // NewConfig returns a new instance of Config with defaults. @@ -73,7 +73,7 @@ func NewConfig() Config { Protocol: DefaultProtocol, BatchSize: DefaultBatchSize, BatchPending: DefaultBatchPending, - BatchTimeout: toml.Duration(DefaultBatchTimeout), + BatchTimeout: config.Duration(DefaultBatchTimeout), ConsistencyLevel: DefaultConsistencyLevel, Separator: DefaultSeparator, } @@ -99,7 +99,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 9c1700f3440..15dc495b814 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/influxdata/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 c5bcda7584b..11c8adcecaa 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/influxdata/influxdb/cluster" "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/services/graphite" "github.com/influxdata/influxdb/services/meta" - "github.com/influxdata/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 f6f3003f2ee..942d5c0a6e1 100644 --- a/services/hh/config.go +++ b/services/hh/config.go @@ -4,7 +4,7 @@ import ( "errors" "time" - "github.com/influxdata/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 2f57a57b465..faccbea6b67 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/influxdata/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 4e9103afe70..7db4a85b55b 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/influxdata/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 948b3493d67..4291cba4da1 100644 --- a/services/meta/config.go +++ b/services/meta/config.go @@ -5,7 +5,7 @@ import ( "net" "time" - "github.com/influxdata/influxdb/toml" + "github.com/influxdata/config" ) const ( @@ -61,18 +61,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. @@ -82,12 +82,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, JoinPeers: []string{}, } diff --git a/services/meta/config_test.go b/services/meta/config_test.go index 8861324d358..5d57c888e0f 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/influxdata/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 41117ca57b3..b65a1d4a971 100644 --- a/services/meta/service_test.go +++ b/services/meta/service_test.go @@ -14,12 +14,12 @@ import ( "testing" "time" + "github.com/influxdata/config" "github.com/influxdata/influxdb" "github.com/influxdata/influxdb/influxql" "github.com/influxdata/influxdb/services/meta" "github.com/influxdata/influxdb/tcp" - "github.com/influxdata/influxdb/toml" ) func TestMetaService_CreateDatabase(t *testing.T) { @@ -1378,7 +1378,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 821d8bdb79b..fbae0e10996 100644 --- a/services/opentsdb/config.go +++ b/services/opentsdb/config.go @@ -3,7 +3,7 @@ package opentsdb import ( "time" - "github.com/influxdata/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 b82fda05e15..995b3b271e1 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/influxdata/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 f1ffb70c183..28744cd3727 100644 --- a/services/precreator/config.go +++ b/services/precreator/config.go @@ -3,7 +3,7 @@ package precreator import ( "time" - "github.com/influxdata/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 338d4e8de38..448ba2544b4 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/influxdata/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 bb2d20ddf9e..3a058fb1613 100644 --- a/services/precreator/service_test.go +++ b/services/precreator/service_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - "github.com/influxdata/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 56b8f53ead2..fdb659a707e 100644 --- a/services/retention/config.go +++ b/services/retention/config.go @@ -3,16 +3,16 @@ package retention import ( "time" - "github.com/influxdata/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 45699ea2669..b19183fc5c2 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/influxdata/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 030405e1ee6..fb90c9b624c 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/influxdata/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 e064f751792..423775068bf 100644 --- a/services/udp/config.go +++ b/services/udp/config.go @@ -3,7 +3,7 @@ package udp import ( "time" - "github.com/influxdata/influxdb/toml" + "github.com/influxdata/config" ) const ( @@ -65,14 +65,14 @@ 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"` - Precision string `toml:"precision"` - 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"` + Precision string `toml:"precision"` + UDPPayloadSize int `toml:"udp-payload-size"` } // NewConfig returns a new instance of Config with defaults. @@ -83,7 +83,7 @@ func NewConfig() Config { RetentionPolicy: DefaultRetentionPolicy, BatchSize: DefaultBatchSize, BatchPending: DefaultBatchPending, - BatchTimeout: toml.Duration(DefaultBatchTimeout), + BatchTimeout: config.Duration(DefaultBatchTimeout), } } @@ -101,7 +101,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.Precision == "" { d.Precision = DefaultPrecision diff --git a/services/udp/config_test.go b/services/udp/config_test.go index aaffc95d6db..074779e5f72 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/influxdata/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 67c6b15364d..c46509f6620 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 d1cf872f56f..e60bed7ce62 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 0b9b5436767..00000000000 --- a/toml/toml.go +++ /dev/null @@ -1,72 +0,0 @@ -package toml // import "github.com/influxdata/influxdb/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 bc8db22ccd7..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/influxdata/influxdb/cmd/influxd/run" - itoml "github.com/influxdata/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 12992a369a4..a9b35013522 100644 --- a/tsdb/config.go +++ b/tsdb/config.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - "github.com/influxdata/influxdb/toml" + "github.com/influxdata/config" ) const ( @@ -77,28 +77,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"` } @@ -109,22 +109,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, }