agent: Adding new CheckUpdateInterval config

This commit is contained in:
Armon Dadgar 2014-06-09 12:13:14 -07:00
parent 0f7792bc27
commit 971d093283
2 changed files with 49 additions and 17 deletions

View File

@ -173,6 +173,14 @@ type Config struct {
// true, we ignore the leave, and rejoin the cluster on start. // true, we ignore the leave, and rejoin the cluster on start.
RejoinAfterLeave bool `mapstructure:"rejoin_after_leave"` RejoinAfterLeave bool `mapstructure:"rejoin_after_leave"`
// CheckUpdateInterval controls the interval on which the output of a health check
// is updated if there is no change to the state. For example, a check in a steady
// state may run every 5 second generating a unique output (timestamp, etc), forcing
// constant writes. This allows Consul to defer the write for some period of time,
// reducing the write pressure when the state is steady.
CheckUpdateInterval time.Duration `mapstructure:"-"`
CheckUpdateIntervalRaw string `mapstructure:"check_update_interval" json:"-"`
// AEInterval controls the anti-entropy interval. This is how often // AEInterval controls the anti-entropy interval. This is how often
// the agent attempts to reconcile it's local state with the server' // the agent attempts to reconcile it's local state with the server'
// representation of our state. Defaults to every 60s. // representation of our state. Defaults to every 60s.
@ -221,6 +229,7 @@ func DefaultConfig() *Config {
MaxStale: 5 * time.Second, MaxStale: 5 * time.Second,
}, },
Protocol: consul.ProtocolVersionMax, Protocol: consul.ProtocolVersionMax,
CheckUpdateInterval: 5 * time.Minute,
AEInterval: time.Minute, AEInterval: time.Minute,
} }
} }
@ -309,6 +318,14 @@ func DecodeConfig(r io.Reader) (*Config, error) {
} }
} }
if raw := result.CheckUpdateIntervalRaw; raw != "" {
dur, err := time.ParseDuration(raw)
if err != nil {
return nil, fmt.Errorf("CheckUpdateInterval invalid: %v", err)
}
result.CheckUpdateInterval = dur
}
return &result, nil return &result, nil
} }
@ -536,6 +553,9 @@ func MergeConfig(a, b *Config) *Config {
if b.DNSConfig.MaxStale != 0 { if b.DNSConfig.MaxStale != 0 {
result.DNSConfig.MaxStale = b.DNSConfig.MaxStale result.DNSConfig.MaxStale = b.DNSConfig.MaxStale
} }
if b.CheckUpdateInterval != 0 {
result.CheckUpdateInterval = b.CheckUpdateInterval
}
// Copy the start join addresses // Copy the start join addresses
result.StartJoin = make([]string, 0, len(a.StartJoin)+len(b.StartJoin)) result.StartJoin = make([]string, 0, len(a.StartJoin)+len(b.StartJoin))

View File

@ -324,6 +324,17 @@ func TestDecodeConfig(t *testing.T) {
if config.DNSConfig.ServiceTTL["web"] != 30*time.Second { if config.DNSConfig.ServiceTTL["web"] != 30*time.Second {
t.Fatalf("bad: %#v", config) t.Fatalf("bad: %#v", config)
} }
// CheckUpdateInterval
input = `{"check_update_interval": "10m"}`
config, err = DecodeConfig(bytes.NewReader([]byte(input)))
if err != nil {
t.Fatalf("err: %s", err)
}
if config.CheckUpdateInterval != 10*time.Minute {
t.Fatalf("bad: %#v", config)
}
} }
func TestDecodeConfig_Service(t *testing.T) { func TestDecodeConfig_Service(t *testing.T) {
@ -466,6 +477,7 @@ func TestMergeConfig(t *testing.T) {
UiDir: "/opt/consul-ui", UiDir: "/opt/consul-ui",
EnableSyslog: true, EnableSyslog: true,
RejoinAfterLeave: true, RejoinAfterLeave: true,
CheckUpdateInterval: 8 * time.Minute,
} }
c := MergeConfig(a, b) c := MergeConfig(a, b)