From 78ef8e260887d0542cca3107606b135675e38db1 Mon Sep 17 00:00:00 2001 From: Shawn Cook Date: Fri, 24 Jul 2015 19:14:15 -0700 Subject: [PATCH 1/8] Add EnableTagDrift config parameter --- command/agent/agent.go | 3 +++ command/agent/command.go | 2 ++ command/agent/config.go | 7 +++++++ command/agent/config_test.go | 5 +++++ command/agent/local.go | 6 ++++++ consul/config.go | 4 ++++ 6 files changed, 27 insertions(+) diff --git a/command/agent/agent.go b/command/agent/agent.go index 449b03c476c7..16503fd2b5f2 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -290,6 +290,9 @@ func (a *Agent) consulConfig() *consul.Config { if a.config.SessionTTLMinRaw != "" { base.SessionTTLMin = a.config.SessionTTLMin } + if a.config.EnableTagDrift { + base.EnableTagDrift = false + } // Format the build string revision := a.config.Revision diff --git a/command/agent/command.go b/command/agent/command.go index 008eed42d804..271bdc49bf54 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -109,6 +109,8 @@ func (c *Command) readConfig() *Config { "number of retries for joining -wan") cmdFlags.StringVar(&retryIntervalWan, "retry-interval-wan", "", "interval between join -wan attempts") + cmdFlags.BoolVar(&cmdConfig.EnableTagDrift, "enable_tag_drift", false, + "enable tag drift - ignore tags during anti-entropy") if err := cmdFlags.Parse(c.args); err != nil { return nil diff --git a/command/agent/config.go b/command/agent/config.go index 5b3357a34e79..9d22cedebcde 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -395,6 +395,10 @@ type Config struct { // Minimum Session TTL SessionTTLMin time.Duration `mapstructure:"-"` SessionTTLMinRaw string `mapstructure:"session_ttl_min"` + + // EnableTagDrift when true will inhibit comparison + // of service tags during anti-entropy + EnableTagDrift bool `mapstructure:"enable_tag_drift"` } // UnixSocketPermissions contains information about a unix socket, and @@ -1068,6 +1072,9 @@ func MergeConfig(a, b *Config) *Config { result.HTTPAPIResponseHeaders[field] = value } } + if b.EnableTagDrift { + result.EnableTagDrift = false + } // 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 ed2a2921e065..9276478921c8 100644 --- a/command/agent/config_test.go +++ b/command/agent/config_test.go @@ -555,6 +555,10 @@ func TestDecodeConfig(t *testing.T) { t.Fatalf("bad: %#v", config) } + if !config.EnableTagDrift { + t.Fatalf("bad: %#v", config) + } + // ACLs input = `{"acl_token": "1234", "acl_datacenter": "dc2", "acl_ttl": "60s", "acl_down_policy": "deny", @@ -1214,6 +1218,7 @@ func TestMergeConfig(t *testing.T) { RPC: &net.TCPAddr{}, RPCRaw: "127.0.0.5:1233", }, + EnableTagDrift: false, } c := MergeConfig(a, b) diff --git a/command/agent/local.go b/command/agent/local.go index dbe38e79d025..3d7bdb5c0df8 100644 --- a/command/agent/local.go +++ b/command/agent/local.go @@ -377,6 +377,12 @@ func (l *localState) setSyncState() error { l.serviceStatus[id] = syncStatus{remoteDelete: true} continue } + + if l.config.EnableTagDrift { + l.logger.Printf("[DEBUG] Tag drift enabled.") + existing.Tags = nil + service.Tags = nil + } // If our definition is different, we need to update it equal := reflect.DeepEqual(existing, service) diff --git a/consul/config.go b/consul/config.go index 51b8a268d41a..b5264610162a 100644 --- a/consul/config.go +++ b/consul/config.go @@ -203,6 +203,10 @@ type Config struct { // UserEventHandler callback can be used to handle incoming // user events. This function should not block. UserEventHandler func(serf.UserEvent) + + // EnableTagDrift when true will inhibit comparison + // of service tags during anti-entropy + EnableTagDrift bool } // CheckVersion is used to check if the ProtocolVersion is valid From 824f584571df8badb427b28062e422a764ced0c7 Mon Sep 17 00:00:00 2001 From: Shawn Cook Date: Wed, 29 Jul 2015 11:29:16 -0700 Subject: [PATCH 2/8] Whitespace updates --- command/agent/local.go | 2 +- consul/config.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/command/agent/local.go b/command/agent/local.go index 3d7bdb5c0df8..fec95b6e9c31 100644 --- a/command/agent/local.go +++ b/command/agent/local.go @@ -377,7 +377,7 @@ func (l *localState) setSyncState() error { l.serviceStatus[id] = syncStatus{remoteDelete: true} continue } - + if l.config.EnableTagDrift { l.logger.Printf("[DEBUG] Tag drift enabled.") existing.Tags = nil diff --git a/consul/config.go b/consul/config.go index b5264610162a..840c19310114 100644 --- a/consul/config.go +++ b/consul/config.go @@ -203,7 +203,7 @@ type Config struct { // UserEventHandler callback can be used to handle incoming // user events. This function should not block. UserEventHandler func(serf.UserEvent) - + // EnableTagDrift when true will inhibit comparison // of service tags during anti-entropy EnableTagDrift bool From 4e067b2a45663953674a93adf36b07df85933372 Mon Sep 17 00:00:00 2001 From: Shawn Cook Date: Wed, 29 Jul 2015 12:22:35 -0700 Subject: [PATCH 3/8] Save and restore existingTags --- command/agent/local.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/command/agent/local.go b/command/agent/local.go index fec95b6e9c31..b3d562a9e76a 100644 --- a/command/agent/local.go +++ b/command/agent/local.go @@ -378,14 +378,19 @@ func (l *localState) setSyncState() error { continue } + var existingTags []string if l.config.EnableTagDrift { l.logger.Printf("[DEBUG] Tag drift enabled.") + existingTags = existing.Tags existing.Tags = nil service.Tags = nil } // If our definition is different, we need to update it equal := reflect.DeepEqual(existing, service) + if l.config.EnableTagDrift { + existing.Tags = existingTags + } l.serviceStatus[id] = syncStatus{inSync: equal} } From 2d2028977ba23efd474663e0305c3cd74a61952b Mon Sep 17 00:00:00 2001 From: Shawn Cook Date: Thu, 30 Jul 2015 09:22:36 -0700 Subject: [PATCH 4/8] Rather than storing tags, simply set service.Tags = existing.Tags --- command/agent/local.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/command/agent/local.go b/command/agent/local.go index b3d562a9e76a..42aba01a4397 100644 --- a/command/agent/local.go +++ b/command/agent/local.go @@ -378,19 +378,13 @@ func (l *localState) setSyncState() error { continue } - var existingTags []string if l.config.EnableTagDrift { - l.logger.Printf("[DEBUG] Tag drift enabled.") - existingTags = existing.Tags - existing.Tags = nil - service.Tags = nil + l.logger.Printf("[DEBUG] Tag drift enabled. Ignoring any tag modifications in service definition") + service.Tags = existing.Tags } // If our definition is different, we need to update it equal := reflect.DeepEqual(existing, service) - if l.config.EnableTagDrift { - existing.Tags = existingTags - } l.serviceStatus[id] = syncStatus{inSync: equal} } From d3803823cb5b9040b1b5dd2299630b59a5138eaa Mon Sep 17 00:00:00 2001 From: Shawn Cook Date: Fri, 31 Jul 2015 09:13:18 -0700 Subject: [PATCH 5/8] Default value true. Updating sprintf type --- command/agent/agent.go | 2 +- command/agent/command.go | 1 + command/agent/config.go | 2 +- command/agent/local.go | 5 ++++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/command/agent/agent.go b/command/agent/agent.go index 16503fd2b5f2..d75f55f832e6 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -291,7 +291,7 @@ func (a *Agent) consulConfig() *consul.Config { base.SessionTTLMin = a.config.SessionTTLMin } if a.config.EnableTagDrift { - base.EnableTagDrift = false + base.EnableTagDrift = true } // Format the build string diff --git a/command/agent/command.go b/command/agent/command.go index 271bdc49bf54..3aa05d9d15c6 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -747,6 +747,7 @@ AFTER_MIGRATE: c.Ui.Info(fmt.Sprintf("Gossip encrypt: %v, RPC-TLS: %v, TLS-Incoming: %v", gossipEncrypted, config.VerifyOutgoing, config.VerifyIncoming)) c.Ui.Info(fmt.Sprintf(" Atlas: %s", atlas)) + c.Ui.Info(fmt.Sprintf("EnableTagDrift: %v", config.EnableTagDrift)) // Enable log streaming c.Ui.Info("") diff --git a/command/agent/config.go b/command/agent/config.go index 9d22cedebcde..833da5770415 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -1073,7 +1073,7 @@ func MergeConfig(a, b *Config) *Config { } } if b.EnableTagDrift { - result.EnableTagDrift = false + result.EnableTagDrift = true } // Copy the start join addresses diff --git a/command/agent/local.go b/command/agent/local.go index 42aba01a4397..fc8864268125 100644 --- a/command/agent/local.go +++ b/command/agent/local.go @@ -378,9 +378,12 @@ func (l *localState) setSyncState() error { continue } + fmt.Printf("[INFO] EnableTagDrift: %+v\n", l.config.EnableTagDrift) if l.config.EnableTagDrift { - l.logger.Printf("[DEBUG] Tag drift enabled. Ignoring any tag modifications in service definition") + l.logger.Printf("[INFO] Tag drift enabled. Ignoring any tag modifications in service definition") service.Tags = existing.Tags + } else { + l.logger.Printf("[INFO] Tag drift disabled. Tags will be compared") } // If our definition is different, we need to update it From 7f8e8ded0baa326ce1d2618635c43a099823ac32 Mon Sep 17 00:00:00 2001 From: Shawn Cook Date: Fri, 31 Jul 2015 11:07:34 -0700 Subject: [PATCH 6/8] Remove extra printf --- command/agent/local.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/command/agent/local.go b/command/agent/local.go index fc8864268125..060d1b48df29 100644 --- a/command/agent/local.go +++ b/command/agent/local.go @@ -378,12 +378,11 @@ func (l *localState) setSyncState() error { continue } - fmt.Printf("[INFO] EnableTagDrift: %+v\n", l.config.EnableTagDrift) if l.config.EnableTagDrift { - l.logger.Printf("[INFO] Tag drift enabled. Ignoring any tag modifications in service definition") - service.Tags = existing.Tags + l.logger.Printf("[INFO] Tag drift enabled.") + existing.Tags = service.Tags } else { - l.logger.Printf("[INFO] Tag drift disabled. Tags will be compared") + l.logger.Printf("[DEBUG] Tag drift disabled.") } // If our definition is different, we need to update it From ff94edf0b1a7d187c939606d704621d74657313a Mon Sep 17 00:00:00 2001 From: Shawn Cook Date: Fri, 31 Jul 2015 11:13:42 -0700 Subject: [PATCH 7/8] Switch to debug --- command/agent/local.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command/agent/local.go b/command/agent/local.go index 060d1b48df29..321eacc8f36b 100644 --- a/command/agent/local.go +++ b/command/agent/local.go @@ -379,7 +379,7 @@ func (l *localState) setSyncState() error { } if l.config.EnableTagDrift { - l.logger.Printf("[INFO] Tag drift enabled.") + l.logger.Printf("[DEBUG] Tag drift enabled.") existing.Tags = service.Tags } else { l.logger.Printf("[DEBUG] Tag drift disabled.") From 27e9e2d0164ff2ae7fd48be1def562b02f268701 Mon Sep 17 00:00:00 2001 From: Shawn Cook Date: Mon, 3 Aug 2015 11:17:48 -0700 Subject: [PATCH 8/8] Fix test case and improve failure output: github.com/hashicorp/consul/command/agent TestDecodeConfig --- command/agent/config_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/command/agent/config_test.go b/command/agent/config_test.go index 9276478921c8..0cc5918ee4eb 100644 --- a/command/agent/config_test.go +++ b/command/agent/config_test.go @@ -555,8 +555,8 @@ func TestDecodeConfig(t *testing.T) { t.Fatalf("bad: %#v", config) } - if !config.EnableTagDrift { - t.Fatalf("bad: %#v", config) + if config.EnableTagDrift { + t.Fatalf("EnableTagDrift should be false by default. Actual config: %#v", config) } // ACLs