From f4f7db0059f890015908ba20257aa2270ab6204f Mon Sep 17 00:00:00 2001 From: Yoann Fouquet Date: Fri, 3 Nov 2017 10:22:52 +0100 Subject: [PATCH 1/2] [Fix] Service tags not added to health checks Since commit 9685bdcd0ba4b4b3adb04f9c1dd67d637ca7894e, service tags are added to the health checks. Otherwise, when adding a service, tags are not added to its check. In updateSyncState, we compare the checks of the local agent with the checks of the catalog. It appears that the service tags are different (missing in one case), and so the check is synchronized. That increase the ModifyIndex periodically when nothing changes. Fixed it by adding serviceTags to the check. Note that the issue appeared in version 0.8.2. Looks related to #3259. --- agent/agent.go | 1 + agent/agent_test.go | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/agent/agent.go b/agent/agent.go index 2ebdd1b76..217467488 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -1603,6 +1603,7 @@ func (a *Agent) AddService(service *structs.NodeService, chkTypes []*structs.Che Notes: chkType.Notes, ServiceID: service.ID, ServiceName: service.Service, + ServiceTags: service.Tags, } if chkType.Status != "" { check.Status = chkType.Status diff --git a/agent/agent_test.go b/agent/agent_test.go index 3807227d6..0ea7fd32c 100644 --- a/agent/agent_test.go +++ b/agent/agent_test.go @@ -290,6 +290,7 @@ func TestAgent_AddService(t *testing.T) { Notes: "note1", ServiceID: "svcid1", ServiceName: "svcname1", + ServiceTags: []string{"tag1"}, }, }, }, @@ -329,6 +330,7 @@ func TestAgent_AddService(t *testing.T) { Notes: "note1", ServiceID: "svcid2", ServiceName: "svcname2", + ServiceTags: []string{"tag2"}, }, "check-noname": &structs.HealthCheck{ Node: "node1", @@ -337,6 +339,7 @@ func TestAgent_AddService(t *testing.T) { Status: "critical", ServiceID: "svcid2", ServiceName: "svcname2", + ServiceTags: []string{"tag2"}, }, "service:svcid2:3": &structs.HealthCheck{ Node: "node1", @@ -345,6 +348,7 @@ func TestAgent_AddService(t *testing.T) { Status: "critical", ServiceID: "svcid2", ServiceName: "svcname2", + ServiceTags: []string{"tag2"}, }, "service:svcid2:4": &structs.HealthCheck{ Node: "node1", @@ -353,6 +357,7 @@ func TestAgent_AddService(t *testing.T) { Status: "critical", ServiceID: "svcid2", ServiceName: "svcname2", + ServiceTags: []string{"tag2"}, }, }, }, From 6f5aecad765cc09bca00c49aaa8332059f378675 Mon Sep 17 00:00:00 2001 From: Yoann Fouquet Date: Thu, 23 Nov 2017 22:16:42 +0100 Subject: [PATCH 2/2] Adjust documentation for service tags of checks Add some missing ServiceTags. Replace null ServiceTags by empty list (ServiceTags cannot be null). --- website/source/api/agent/check.html.md | 3 ++- website/source/api/agent/service.html.md | 2 +- website/source/api/health.html.md | 6 +++--- website/source/intro/getting-started/checks.html.md | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/website/source/api/agent/check.html.md b/website/source/api/agent/check.html.md index da64214c7..f76c1e761 100644 --- a/website/source/api/agent/check.html.md +++ b/website/source/api/agent/check.html.md @@ -55,7 +55,8 @@ $ curl \ "Notes": "", "Output": "", "ServiceID": "redis", - "ServiceName": "redis" + "ServiceName": "redis", + "ServiceTags": ["primary"] } } ``` diff --git a/website/source/api/agent/service.html.md b/website/source/api/agent/service.html.md index 62670311e..eaf909f36 100644 --- a/website/source/api/agent/service.html.md +++ b/website/source/api/agent/service.html.md @@ -51,7 +51,7 @@ $ curl \ "redis": { "ID": "redis", "Service": "redis", - "Tags": null, + "Tags": [], "Address": "", "Port": 8000 } diff --git a/website/source/api/health.html.md b/website/source/api/health.html.md index 05508a11d..6f1639bb5 100644 --- a/website/source/api/health.html.md +++ b/website/source/api/health.html.md @@ -62,7 +62,7 @@ $ curl \ "Output": "", "ServiceID": "", "ServiceName": "", - "ServiceTags": null + "ServiceTags": [] }, { "ID": "40e4a748-2192-161a-0510-9bf59fe950b5", @@ -239,7 +239,7 @@ $ curl \ "Output": "", "ServiceID": "", "ServiceName": "", - "ServiceTags": null + "ServiceTags": [] } ] } @@ -303,7 +303,7 @@ $ curl \ "Output": "", "ServiceID": "", "ServiceName": "", - "ServiceTags": null + "ServiceTags": [] }, { "Node": "foobar", diff --git a/website/source/intro/getting-started/checks.html.md b/website/source/intro/getting-started/checks.html.md index d4e37c4b8..f3b79f1b3 100644 --- a/website/source/intro/getting-started/checks.html.md +++ b/website/source/intro/getting-started/checks.html.md @@ -75,7 +75,7 @@ can be run on either node): ```text vagrant@n1:~$ curl http://localhost:8500/v1/health/state/critical -[{"Node":"agent-two","CheckID":"service:web","Name":"Service 'web' check","Status":"critical","Notes":"","ServiceID":"web","ServiceName":"web"}] +[{"Node":"agent-two","CheckID":"service:web","Name":"Service 'web' check","Status":"critical","Notes":"","ServiceID":"web","ServiceName":"web","ServiceTags":["rails"]}] ``` We can see that there is only a single check, our `web` service check, in the