Merge pull request #3642 from yfouquet/master

[Fix] Service tags not added to health checks
pull/3750/head
James Phillips 2017-12-14 13:59:39 -08:00 committed by GitHub
commit f491a55e47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 6 deletions

View File

@ -1592,6 +1592,7 @@ func (a *Agent) AddService(service *structs.NodeService, chkTypes []*structs.Che
Notes: chkType.Notes, Notes: chkType.Notes,
ServiceID: service.ID, ServiceID: service.ID,
ServiceName: service.Service, ServiceName: service.Service,
ServiceTags: service.Tags,
} }
if chkType.Status != "" { if chkType.Status != "" {
check.Status = chkType.Status check.Status = chkType.Status

View File

@ -290,6 +290,7 @@ func TestAgent_AddService(t *testing.T) {
Notes: "note1", Notes: "note1",
ServiceID: "svcid1", ServiceID: "svcid1",
ServiceName: "svcname1", ServiceName: "svcname1",
ServiceTags: []string{"tag1"},
}, },
}, },
}, },
@ -329,6 +330,7 @@ func TestAgent_AddService(t *testing.T) {
Notes: "note1", Notes: "note1",
ServiceID: "svcid2", ServiceID: "svcid2",
ServiceName: "svcname2", ServiceName: "svcname2",
ServiceTags: []string{"tag2"},
}, },
"check-noname": &structs.HealthCheck{ "check-noname": &structs.HealthCheck{
Node: "node1", Node: "node1",
@ -337,6 +339,7 @@ func TestAgent_AddService(t *testing.T) {
Status: "critical", Status: "critical",
ServiceID: "svcid2", ServiceID: "svcid2",
ServiceName: "svcname2", ServiceName: "svcname2",
ServiceTags: []string{"tag2"},
}, },
"service:svcid2:3": &structs.HealthCheck{ "service:svcid2:3": &structs.HealthCheck{
Node: "node1", Node: "node1",
@ -345,6 +348,7 @@ func TestAgent_AddService(t *testing.T) {
Status: "critical", Status: "critical",
ServiceID: "svcid2", ServiceID: "svcid2",
ServiceName: "svcname2", ServiceName: "svcname2",
ServiceTags: []string{"tag2"},
}, },
"service:svcid2:4": &structs.HealthCheck{ "service:svcid2:4": &structs.HealthCheck{
Node: "node1", Node: "node1",
@ -353,6 +357,7 @@ func TestAgent_AddService(t *testing.T) {
Status: "critical", Status: "critical",
ServiceID: "svcid2", ServiceID: "svcid2",
ServiceName: "svcname2", ServiceName: "svcname2",
ServiceTags: []string{"tag2"},
}, },
}, },
}, },

View File

@ -55,7 +55,8 @@ $ curl \
"Notes": "", "Notes": "",
"Output": "", "Output": "",
"ServiceID": "redis", "ServiceID": "redis",
"ServiceName": "redis" "ServiceName": "redis",
"ServiceTags": ["primary"]
} }
} }
``` ```

View File

@ -51,7 +51,7 @@ $ curl \
"redis": { "redis": {
"ID": "redis", "ID": "redis",
"Service": "redis", "Service": "redis",
"Tags": null, "Tags": [],
"Address": "", "Address": "",
"Port": 8000 "Port": 8000
} }

View File

@ -62,7 +62,7 @@ $ curl \
"Output": "", "Output": "",
"ServiceID": "", "ServiceID": "",
"ServiceName": "", "ServiceName": "",
"ServiceTags": null "ServiceTags": []
}, },
{ {
"ID": "40e4a748-2192-161a-0510-9bf59fe950b5", "ID": "40e4a748-2192-161a-0510-9bf59fe950b5",
@ -239,7 +239,7 @@ $ curl \
"Output": "", "Output": "",
"ServiceID": "", "ServiceID": "",
"ServiceName": "", "ServiceName": "",
"ServiceTags": null "ServiceTags": []
} }
] ]
} }
@ -303,7 +303,7 @@ $ curl \
"Output": "", "Output": "",
"ServiceID": "", "ServiceID": "",
"ServiceName": "", "ServiceName": "",
"ServiceTags": null "ServiceTags": []
}, },
{ {
"Node": "foobar", "Node": "foobar",

View File

@ -75,7 +75,7 @@ can be run on either node):
```text ```text
vagrant@n1:~$ curl http://localhost:8500/v1/health/state/critical 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 We can see that there is only a single check, our `web` service check, in the