agent: Adding watches config

This commit is contained in:
Armon Dadgar 2014-08-19 14:19:31 -07:00
parent 4d66b11c91
commit 5ee737b8d4
2 changed files with 23 additions and 0 deletions

View File

@ -229,6 +229,11 @@ type Config struct {
// this acts like deny.
ACLDownPolicy string `mapstructure:"acl_down_policy"`
// Watches are used to monitor various endpoints and to invoke a
// handler to act appropriately. These are managed entirely in the
// agent layer using the standard APIs.
Watches []string `mapstructure:"watches"`
// AEInterval controls the anti-entropy interval. This is how often
// the agent attempts to reconcile it's local state with the server'
// representation of our state. Defaults to every 60s.
@ -648,6 +653,9 @@ func MergeConfig(a, b *Config) *Config {
if b.ACLDefaultPolicy != "" {
result.ACLDefaultPolicy = b.ACLDefaultPolicy
}
if len(b.Watches) != 0 {
result.Watches = append(result.Watches, b.Watches...)
}
// Copy the start join addresses
result.StartJoin = make([]string, 0, len(a.StartJoin)+len(b.StartJoin))

View File

@ -384,6 +384,20 @@ func TestDecodeConfig(t *testing.T) {
if config.ACLDefaultPolicy != "deny" {
t.Fatalf("bad: %#v", config)
}
// Watches
input = `{"watches": ["type:keyprefix prefix:foo/ handler:foobar"]}`
config, err = DecodeConfig(bytes.NewReader([]byte(input)))
if err != nil {
t.Fatalf("err: %s", err)
}
if len(config.Watches) != 1 {
t.Fatalf("bad: %#v", config)
}
if config.Watches[0] != "type:keyprefix prefix:foo/ handler:foobar" {
t.Fatalf("bad: %#v", config)
}
}
func TestDecodeConfig_Service(t *testing.T) {
@ -538,6 +552,7 @@ func TestMergeConfig(t *testing.T) {
ACLTTLRaw: "15s",
ACLDownPolicy: "deny",
ACLDefaultPolicy: "deny",
Watches: []string{"type:keyprefix prefix:foobar/ handler:foo"},
}
c := MergeConfig(a, b)