mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-07 03:17:50 +00:00
Merge pull request #714 from linhvo/582-config-tag
update config to match with json tag
This commit is contained in:
commit
8c3dfff9c9
5 changed files with 31 additions and 30 deletions
|
|
@ -60,10 +60,10 @@ func TestServerConfig(t *testing.T) {
|
|||
validation: func() error {
|
||||
v := validator{}
|
||||
v.Check(cmd.Server.Config.DataDir, actualDataDir)
|
||||
v.Check(cmd.Server.Config.Host, "example.com:10111")
|
||||
v.Check(cmd.Server.Config.Bind, "example.com:10111")
|
||||
v.Check(cmd.Server.Config.Cluster.ReplicaN, 2)
|
||||
v.Check(cmd.Server.Config.Cluster.Hosts, []string{"example.com:10111", "example.com:10110"})
|
||||
v.Check(cmd.Server.Config.Cluster.PollingInterval, pilosa.Duration(time.Second*182))
|
||||
v.Check(cmd.Server.Config.Cluster.PollInterval, pilosa.Duration(time.Second*182))
|
||||
return v.Error()
|
||||
},
|
||||
},
|
||||
|
|
@ -113,7 +113,7 @@ func TestServerConfig(t *testing.T) {
|
|||
validation: func() error {
|
||||
v := validator{}
|
||||
v.Check(cmd.Server.Config.Cluster.Hosts, []string{"localhost:19444"})
|
||||
v.Check(cmd.Server.Config.Cluster.PollingInterval, pilosa.Duration(time.Minute*2))
|
||||
v.Check(cmd.Server.Config.Cluster.PollInterval, pilosa.Duration(time.Minute*2))
|
||||
v.Check(cmd.Server.Config.AntiEntropy.Interval, pilosa.Duration(time.Minute*11))
|
||||
v.Check(cmd.Server.CPUProfile, profFile.Name())
|
||||
v.Check(cmd.Server.CPUTime, time.Minute)
|
||||
|
|
|
|||
30
config.go
30
config.go
|
|
@ -39,17 +39,17 @@ const (
|
|||
// Config represents the configuration for the command.
|
||||
type Config struct {
|
||||
DataDir string `toml:"data-dir"`
|
||||
Host string `toml:"host"`
|
||||
Bind string `toml:"bind"`
|
||||
|
||||
Cluster struct {
|
||||
ReplicaN int `toml:"replicas"`
|
||||
Type string `toml:"type"`
|
||||
Hosts []string `toml:"hosts"`
|
||||
InternalHosts []string `toml:"internal-hosts"`
|
||||
PollingInterval Duration `toml:"polling-interval"`
|
||||
InternalPort string `toml:"internal-port"`
|
||||
GossipSeed string `toml:"gossip-seed"`
|
||||
LongQueryTime Duration `toml:"long-query-time"`
|
||||
ReplicaN int `toml:"replicas"`
|
||||
Type string `toml:"type"`
|
||||
Hosts []string `toml:"hosts"`
|
||||
InternalHosts []string `toml:"internal-hosts"`
|
||||
PollInterval Duration `toml:"poll-interval"`
|
||||
InternalPort string `toml:"internal-port"`
|
||||
GossipSeed string `toml:"gossip-seed"`
|
||||
LongQueryTime Duration `toml:"long-query-time"`
|
||||
} `toml:"cluster"`
|
||||
|
||||
Plugins struct {
|
||||
|
|
@ -67,21 +67,21 @@ type Config struct {
|
|||
LogPath string `toml:"log-path"`
|
||||
|
||||
Metric struct {
|
||||
Service string `toml:"service"`
|
||||
Host string `toml:"host"`
|
||||
PollingInterval Duration `toml:"interval"`
|
||||
} `toml:"metrics"`
|
||||
Service string `toml:"service"`
|
||||
Host string `toml:"host"`
|
||||
PollInterval Duration `toml:"poll-interval"`
|
||||
} `toml:"metric"`
|
||||
}
|
||||
|
||||
// NewConfig returns an instance of Config with default options.
|
||||
func NewConfig() *Config {
|
||||
c := &Config{
|
||||
Host: DefaultHost + ":" + DefaultPort,
|
||||
Bind: DefaultHost + ":" + DefaultPort,
|
||||
MaxWritesPerRequest: DefaultMaxWritesPerRequest,
|
||||
}
|
||||
c.Cluster.ReplicaN = DefaultReplicaN
|
||||
c.Cluster.Type = DefaultClusterType
|
||||
c.Cluster.PollingInterval = Duration(DefaultPollingInterval)
|
||||
c.Cluster.PollInterval = Duration(DefaultPollingInterval)
|
||||
c.Cluster.Hosts = []string{}
|
||||
c.Cluster.InternalHosts = []string{}
|
||||
c.AntiEntropy.Interval = Duration(DefaultAntiEntropyInterval)
|
||||
|
|
|
|||
|
|
@ -25,12 +25,13 @@ import (
|
|||
func BuildServerFlags(cmd *cobra.Command, srv *server.Command) {
|
||||
flags := cmd.Flags()
|
||||
flags.StringVarP(&srv.Config.DataDir, "data-dir", "d", "~/.pilosa", "Directory to store pilosa data files.")
|
||||
flags.StringVarP(&srv.Config.Host, "bind", "b", ":10101", "Default URI on which pilosa should listen.")
|
||||
flags.StringVarP(&srv.Config.Bind, "bind", "b", ":10101", "Default URI on which pilosa should listen.")
|
||||
flags.IntVarP(&srv.Config.MaxWritesPerRequest, "max-writes-per-request", "", srv.Config.MaxWritesPerRequest, "Number of write commands per request.")
|
||||
flags.IntVarP(&srv.Config.Cluster.ReplicaN, "cluster.replicas", "", 1, "Number of hosts each piece of data should be stored on.")
|
||||
flags.StringSliceVarP(&srv.Config.Cluster.Hosts, "cluster.hosts", "", []string{}, "Comma separated list of hosts in cluster.")
|
||||
flags.StringSliceVarP(&srv.Config.Cluster.InternalHosts, "cluster.internal-hosts", "", []string{}, "Comma separated list of hosts in cluster used for internal communication.")
|
||||
flags.DurationVarP((*time.Duration)(&srv.Config.Cluster.PollingInterval), "cluster.poll-interval", "", time.Minute, "Polling interval for cluster.") // TODO what actually is this?
|
||||
flags.DurationVarP((*time.Duration)(&srv.Config.Cluster.PollInterval), "cluster.poll-interval", "", time.Minute, "Polling interval for cluster.") // TODO what actually is this?
|
||||
flags.DurationVarP((*time.Duration)(&srv.Config.Cluster.LongQueryTime), "cluster.long-query-time", "", time.Minute, "Long Query Time.")
|
||||
flags.StringVarP(&srv.Config.Plugins.Path, "plugins.path", "", "", "Path to plugin directory.")
|
||||
flags.StringVar(&srv.Config.LogPath, "log-path", "", "Log path")
|
||||
flags.DurationVarP((*time.Duration)(&srv.Config.AntiEntropy.Interval), "anti-entropy.interval", "", time.Minute*10, "Interval at which to run anti-entropy routine.")
|
||||
|
|
@ -41,5 +42,5 @@ func BuildServerFlags(cmd *cobra.Command, srv *server.Command) {
|
|||
flags.StringVarP(&srv.Config.Cluster.InternalPort, "cluster.internal-port", "", "", "Port to which pilosa should bind for internal state sharing.")
|
||||
flags.StringVarP(&srv.Config.Metric.Service, "metric.service", "", "nop", "Default URI on which pilosa should listen.")
|
||||
flags.StringVarP(&srv.Config.Metric.Host, "metric.host", "", "", "Default URI to send metrics.")
|
||||
flags.DurationVarP((*time.Duration)(&srv.Config.Metric.PollingInterval), "metric.poll-interval", "", time.Minute*0, "Polling interval metrics.")
|
||||
flags.DurationVarP((*time.Duration)(&srv.Config.Metric.PollInterval), "metric.poll-interval", "", time.Minute*0, "Polling interval metrics.")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ func (m *Command) SetupServer() error {
|
|||
// Configure holder.
|
||||
m.Server.Logger().Printf("Using data from: %s\n", m.Config.DataDir)
|
||||
m.Server.Holder.Path = m.Config.DataDir
|
||||
m.Server.MetricInterval = time.Duration(m.Config.Metric.PollingInterval)
|
||||
m.Server.MetricInterval = time.Duration(m.Config.Metric.PollInterval)
|
||||
m.Server.Holder.Stats, err = NewStatsClient(m.Config.Metric.Service, m.Config.Metric.Host)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -142,7 +142,7 @@ func (m *Command) SetupServer() error {
|
|||
// Copy configuration flags.
|
||||
m.Server.MaxWritesPerRequest = m.Config.MaxWritesPerRequest
|
||||
|
||||
m.Server.Host, err = normalizeHost(m.Config.Host)
|
||||
m.Server.Host, err = normalizeHost(m.Config.Bind)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -172,11 +172,11 @@ func (m *Command) SetupServer() error {
|
|||
gossipSeed = m.Config.Cluster.GossipSeed
|
||||
}
|
||||
// get the host portion of addr to use for binding
|
||||
gossipHost, _, err := net.SplitHostPort(m.Config.Host)
|
||||
gossipHost, _, err := net.SplitHostPort(m.Config.Bind)
|
||||
if err != nil {
|
||||
gossipHost = m.Config.Host
|
||||
gossipHost = m.Config.Bind
|
||||
}
|
||||
gossipNodeSet := gossip.NewGossipNodeSet(m.Config.Host, gossipHost, gossipPort, gossipSeed, m.Server)
|
||||
gossipNodeSet := gossip.NewGossipNodeSet(m.Config.Bind, gossipHost, gossipPort, gossipSeed, m.Server)
|
||||
m.Server.Cluster.NodeSet = gossipNodeSet
|
||||
m.Server.Broadcaster = gossipNodeSet
|
||||
m.Server.BroadcastReceiver = gossipNodeSet
|
||||
|
|
|
|||
|
|
@ -346,10 +346,10 @@ func TestMain_FrameRestore(t *testing.T) {
|
|||
|
||||
// Ensure the host can be parsed.
|
||||
func TestConfig_Parse_Host(t *testing.T) {
|
||||
if c, err := ParseConfig(`host = "local"`); err != nil {
|
||||
if c, err := ParseConfig(`bind = "local"`); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if c.Host != "local" {
|
||||
t.Fatalf("unexpected host: %s", c.Host)
|
||||
} else if c.Bind != "local" {
|
||||
t.Fatalf("unexpected host: %s", c.Bind)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -583,7 +583,7 @@ func NewMain() *Main {
|
|||
m := &Main{Command: server.NewCommand(os.Stdin, os.Stdout, os.Stderr)}
|
||||
m.Server.Network = *test.Network
|
||||
m.Config.DataDir = path
|
||||
m.Config.Host = "localhost:0"
|
||||
m.Config.Bind = "localhost:0"
|
||||
m.Command.Stdin = &m.Stdin
|
||||
m.Command.Stdout = &m.Stdout
|
||||
m.Command.Stderr = &m.Stderr
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue