From 5ee737b8d48aa8bd59e4284f1dc69195f21d5cc7 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Tue, 19 Aug 2014 14:19:31 -0700 Subject: [PATCH] agent: Adding watches config --- command/agent/config.go | 8 ++++++++ command/agent/config_test.go | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/command/agent/config.go b/command/agent/config.go index 87584e1a2b..e40f4b568b 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -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)) diff --git a/command/agent/config_test.go b/command/agent/config_test.go index 9bc67c69c0..b57037a51e 100644 --- a/command/agent/config_test.go +++ b/command/agent/config_test.go @@ -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)