Add support for multiple checks in Consul Client (#4849)

This commit is contained in:
Rémi Lapeyre 2018-10-29 17:39:25 +01:00 committed by Jack Pearkes
parent a2485f60af
commit 70a051363f
2 changed files with 36 additions and 6 deletions

View File

@ -35,6 +35,7 @@ type CatalogService struct {
// We forgot to ever add ServiceProxyDestination here so no need to deprecate!
ServiceProxy *AgentServiceConnectProxyConfig
CreateIndex uint64
Checks HealthChecks
ModifyIndex uint64
}
@ -52,6 +53,7 @@ type CatalogRegistration struct {
Datacenter string
Service *AgentService
Check *AgentCheck
Checks HealthChecks
SkipNodeUpdate bool
}

View File

@ -664,20 +664,33 @@ func TestAPI_CatalogRegistration(t *testing.T) {
check := &AgentCheck{
Node: "foobar",
CheckID: "service:redis1",
CheckID: "service:redis1-a",
Name: "Redis health check",
Notes: "Script based health check",
Status: HealthPassing,
ServiceID: "redis1",
}
checks := HealthChecks{
&HealthCheck{
Node: "foobar",
CheckID: "service:redis1-b",
Name: "Redis health check",
Notes: "Script based health check",
Status: HealthPassing,
ServiceID: "redis1",
},
}
reg := &CatalogRegistration{
Datacenter: "dc1",
Node: "foobar",
Address: "192.168.10.10",
NodeMeta: map[string]string{"somekey": "somevalue"},
Service: service,
// Specifying both Check and Checks is accepted by Consul
Check: check,
Checks: checks,
}
// Register a connect proxy for that service too
proxy := &AgentService{
@ -722,8 +735,12 @@ func TestAPI_CatalogRegistration(t *testing.T) {
r.Fatal(err)
}
if health[0].CheckID != "service:redis1" {
r.Fatal("missing checkid service:redis1")
if health[0].CheckID != "service:redis1-a" {
r.Fatal("missing checkid service:redis1-a")
}
if health[1].CheckID != "service:redis1-b" {
r.Fatal("missing checkid service:redis1-b")
}
if v, ok := node.Node.Meta["somekey"]; !ok || v != "somevalue" {
@ -775,7 +792,18 @@ func TestAPI_CatalogRegistration(t *testing.T) {
Datacenter: "dc1",
Node: "foobar",
Address: "192.168.10.10",
CheckID: "service:redis1",
CheckID: "service:redis1-a",
}
if _, err := catalog.Deregister(dereg, nil); err != nil {
t.Fatalf("err: %v", err)
}
dereg = &CatalogDeregistration{
Datacenter: "dc1",
Node: "foobar",
Address: "192.168.10.10",
CheckID: "service:redis1-b",
}
if _, err := catalog.Deregister(dereg, nil); err != nil {
@ -789,7 +817,7 @@ func TestAPI_CatalogRegistration(t *testing.T) {
}
if len(health) != 0 {
r.Fatal("CheckID:service:redis1 is not deregistered")
r.Fatal("CheckID:service:redis1-a or CheckID:service:redis1-a is not deregistered")
}
})