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 the
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.
  • Loading branch information
timraymond authored and nathanielc committed Mar 1, 2016
1 parent 2ad6ea2 commit 7f68c1b
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 39 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ With #144 you can now join streams with differing group by dimensions.
- [#145](https://github.com/influxdata/kapacitor/issues/145): The InfluxDB Out Node now writes data to InfluxDB in buffers.
- [#215](https://github.com/influxdata/kapacitor/issues/215): Add performance metrics to nodes for average execution times and node throughput values.
- [#144](https://github.com/influxdata/kapacitor/issues/144): Can now join streams with differing dimensions using the join.On property.
- [#155](https://github.com/influxdata/kapacitor/pull/155): Standardized config across TICK stack.


### Bugfixes
Expand Down
4 changes: 2 additions & 2 deletions cmd/kapacitord/run/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"runtime"
"strconv"

"github.com/BurntSushi/toml"
cfg "github.com/influxdata/config"
"github.com/influxdata/kapacitor/services/logging"
)

Expand Down Expand Up @@ -207,7 +207,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
6 changes: 3 additions & 3 deletions cmd/kapacitord/run/config_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"io"
"os"

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

// PrintConfigCommand represents the command executed by "kapacitord config".
Expand Down Expand Up @@ -57,7 +57,7 @@ func (cmd *PrintConfigCommand) Run(args ...string) error {
return fmt.Errorf("%s. To generate a valid configuration file run `kapacitord config > kapacitor.generated.conf`.", err)
}

toml.NewEncoder(cmd.Stdout).Encode(config)
cfg.NewEncoder(cmd.Stdout).Encode(config)
fmt.Fprint(cmd.Stdout, "\n")

return nil
Expand All @@ -71,7 +71,7 @@ func (cmd *PrintConfigCommand) parseConfig(path string) (*Config, error) {
}

config := NewConfig()
if _, err := toml.DecodeFile(path, &config); err != nil {
if err := cfg.DecodeFile(path, &config); err != nil {
return nil, err
}
return config, nil
Expand Down
6 changes: 3 additions & 3 deletions cmd/kapacitord/run/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"os"
"testing"

"github.com/BurntSushi/toml"
"github.com/influxdata/config"
"github.com/influxdata/kapacitor/cmd/kapacitord/run"
)

// Ensure the configuration can be parsed.
func TestConfig_Parse(t *testing.T) {
// Parse configuration.
var c run.Config
if _, err := toml.Decode(`
if err := config.Decode(`
[replay]
dir = "/tmp/replay"
Expand All @@ -34,7 +34,7 @@ dir = "/tmp/task"
func TestConfig_Parse_EnvOverride(t *testing.T) {
// Parse configuration.
var c run.Config
if _, err := toml.Decode(`
if err := config.Decode(`
[replay]
dir = "/tmp/replay"
Expand Down
Binary file added cmd/kapacitord/run/run.test
Binary file not shown.
7 changes: 4 additions & 3 deletions cmd/kapacitord/run/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ import (
"testing"
"time"

"github.com/influxdata/config"
"github.com/influxdata/kapacitor"
"github.com/influxdata/kapacitor/cmd/kapacitord/run"
"github.com/influxdata/kapacitor/services/udf"
"github.com/influxdata/kapacitor/vendor/github.com/influxdb/influxdb/toml"
client "github.com/influxdb/influxdb/client/v2"
"github.com/influxdb/influxdb/influxql"
"github.com/influxdb/influxdb/models"
"github.com/influxdb/influxdb/toml"
)

func TestServer_Ping(t *testing.T) {
Expand Down Expand Up @@ -792,7 +793,7 @@ func TestServer_UDFStreamAgents(t *testing.T) {
},
config: udf.FunctionConfig{
Prog: filepath.Join(tdir, "movavg"),
Timeout: toml.Duration(time.Minute),
Timeout: config.Duration(time.Minute),
},
},
// Python
Expand All @@ -801,7 +802,7 @@ func TestServer_UDFStreamAgents(t *testing.T) {
config: udf.FunctionConfig{
Prog: "python2",
Args: []string{"-u", filepath.Join(udfDir, "agent/examples/moving_avg/moving_avg.py")},
Timeout: toml.Duration(time.Minute),
Timeout: config.Duration(time.Minute),
Env: map[string]string{
"PYTHONPATH": strings.Join(
[]string{filepath.Join(udfDir, "agent/py"), os.Getenv("PYTHONPATH")},
Expand Down
14 changes: 7 additions & 7 deletions services/deadman/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package deadman
import (
"time"

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

const (
// Default deadman's switch interval
DefaultInterval = toml.Duration(time.Second * 10)
DefaultInterval = config.Duration(time.Second * 10)
// Default deadman's switch threshold
DefaultThreshold = float64(0)
// Default deadman's switch id
Expand All @@ -18,11 +18,11 @@ const (
)

type Config struct {
Interval toml.Duration `toml:"interval"`
Threshold float64 `toml:"threshold"`
Id string `toml:"id"`
Message string `toml:"message"`
Global bool `toml:"global"`
Interval config.Duration `toml:"interval"`
Threshold float64 `toml:"threshold"`
Id string `toml:"id"`
Message string `toml:"message"`
Global bool `toml:"global"`
}

func NewConfig() Config {
Expand Down
6 changes: 3 additions & 3 deletions services/smtp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package smtp
import (
"time"

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

type Config struct {
Expand All @@ -21,7 +21,7 @@ type Config struct {
// Default To addresses
To []string `toml:"to"`
// Close connection to SMTP server after idle timeout has elapsed
IdleTimeout toml.Duration `toml:"idle-timeout"`
IdleTimeout config.Duration `toml:"idle-timeout"`
}

func NewConfig() Config {
Expand All @@ -30,6 +30,6 @@ func NewConfig() Config {
Port: 25,
Username: "",
Password: "",
IdleTimeout: toml.Duration(time.Second * 30),
IdleTimeout: config.Duration(time.Second * 30),
}
}
16 changes: 8 additions & 8 deletions services/stats/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ package stats
import (
"time"

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

const (
DefaultDatabse = "_kapacitor"
DefaultRetentionPolicy = "default"
DefaultStatsInterval = toml.Duration(10 * time.Second)
DefaultStatsInterval = config.Duration(10 * time.Second)
DefaultTimingSampleRate = 0.10
DefaultTimingMovingAverageSize = 1000
)

type Config struct {
Enabled bool `toml:"enabled"`
StatsInterval toml.Duration `toml:"stats-interval"`
Database string `toml:"database"`
RetentionPolicy string `toml:"retention-policy"`
TimingSampleRate float64 `toml:"timing-sample-rate"`
TimingMovingAverageSize int `toml:"timing-movavg-size"`
Enabled bool `toml:"enabled"`
StatsInterval config.Duration `toml:"stats-interval"`
Database string `toml:"database"`
RetentionPolicy string `toml:"retention-policy"`
TimingSampleRate float64 `toml:"timing-sample-rate"`
TimingMovingAverageSize int `toml:"timing-movavg-size"`
}

func NewConfig() Config {
Expand Down
8 changes: 4 additions & 4 deletions services/task_store/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import (
"fmt"
"time"

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

type Config struct {
Dir string `toml:"dir"`
SnapshotInterval toml.Duration `toml:"snapshot-interval"`
Dir string `toml:"dir"`
SnapshotInterval config.Duration `toml:"snapshot-interval"`
}

func NewConfig() Config {
return Config{
Dir: "./tasks",
SnapshotInterval: toml.Duration(time.Minute),
SnapshotInterval: config.Duration(time.Minute),
}
}

Expand Down
4 changes: 2 additions & 2 deletions services/udf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"time"

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

type Config struct {
Expand All @@ -14,7 +14,7 @@ type Config struct {
type FunctionConfig struct {
Prog string `toml:"prog"`
Args []string `toml:"args"`
Timeout toml.Duration `toml:"timeout"`
Timeout config.Duration `toml:"timeout"`
Env map[string]string `toml:"env"`
}

Expand Down
4 changes: 2 additions & 2 deletions services/udp/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package udp_test
import (
"testing"

"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"
Expand Down
2 changes: 0 additions & 2 deletions udf/agent/examples/moving_avg/moving_avg.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import sys
import json
from agent import Agent, Handler
Expand Down Expand Up @@ -67,7 +66,6 @@ def info(self):
response.info.options['size'].valueTypes.append(udf_pb2.INT)
response.info.options['as'].valueTypes.append(udf_pb2.STRING)

logger.info("info")
return response

def init(self, init_req):
Expand Down
1 change: 1 addition & 0 deletions vendor/github.com/influxdata/influxdb
Submodule influxdb added at 903ea3

0 comments on commit 7f68c1b

Please sign in to comment.