diff --git a/command/agent/ui_endpoint.go b/command/agent/ui_endpoint.go index 21c9eeb41..f9eb72a57 100644 --- a/command/agent/ui_endpoint.go +++ b/command/agent/ui_endpoint.go @@ -130,22 +130,28 @@ func summarizeServices(dump structs.NodeDump) []*ServiceSummary { // Aggregate all the node information for _, node := range dump { - for _, service := range node.Services { + nodeServices := make([]*ServiceSummary, len(node.Services)) + for idx, service := range node.Services { sum := getService(service.Service) sum.Nodes = append(sum.Nodes, node.Node) + nodeServices[idx] = sum } for _, check := range node.Checks { + var services []*ServiceSummary if check.ServiceName == "" { - continue + services = nodeServices + } else { + services = []*ServiceSummary{getService(check.ServiceName)} } - sum := getService(check.ServiceName) - switch check.Status { - case structs.HealthPassing: - sum.ChecksPassing++ - case structs.HealthWarning: - sum.ChecksWarning++ - case structs.HealthCritical: - sum.ChecksCritical++ + for _, sum := range services { + switch check.Status { + case structs.HealthPassing: + sum.ChecksPassing++ + case structs.HealthWarning: + sum.ChecksWarning++ + case structs.HealthCritical: + sum.ChecksCritical++ + } } } } diff --git a/command/agent/ui_endpoint_test.go b/command/agent/ui_endpoint_test.go index af22a8c8a..c056e433e 100644 --- a/command/agent/ui_endpoint_test.go +++ b/command/agent/ui_endpoint_test.go @@ -126,7 +126,7 @@ func TestSummarizeServices(t *testing.T) { }, Checks: []*structs.HealthCheck{ &structs.HealthCheck{ - Status: structs.HealthCritical, + Status: structs.HealthPassing, ServiceName: "", }, &structs.HealthCheck{ @@ -173,7 +173,7 @@ func TestSummarizeServices(t *testing.T) { expectAPI := &ServiceSummary{ Name: "api", Nodes: []string{"foo"}, - ChecksPassing: 0, + ChecksPassing: 1, ChecksWarning: 1, ChecksCritical: 0, } @@ -195,7 +195,7 @@ func TestSummarizeServices(t *testing.T) { expectWeb := &ServiceSummary{ Name: "web", Nodes: []string{"bar", "foo"}, - ChecksPassing: 1, + ChecksPassing: 2, ChecksWarning: 0, ChecksCritical: 1, }