From e3891db55b63adeabd64a0313c1fe5e1d81f33d5 Mon Sep 17 00:00:00 2001 From: Matt Keeler Date: Mon, 9 Mar 2020 11:56:19 -0400 Subject: [PATCH] Gather instance counts of aggregated services (#7415) --- agent/ui_endpoint.go | 5 +++++ agent/ui_endpoint_test.go | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/agent/ui_endpoint.go b/agent/ui_endpoint.go index 5fb02d5af6..39bb2fb828 100644 --- a/agent/ui_endpoint.go +++ b/agent/ui_endpoint.go @@ -21,6 +21,7 @@ type ServiceSummary struct { Name string Tags []string Nodes []string + InstanceCount int ChecksPassing int ChecksWarning int ChecksCritical int @@ -165,6 +166,9 @@ func summarizeServices(dump structs.CheckServiceNodes) []*ServiceSummary { serv = &ServiceSummary{ Name: service.ID, EnterpriseMeta: service.EnterpriseMeta, + // the other code will increment this unconditionally so we + // shouldn't initialize it to 1 + InstanceCount: 0, } summary[service] = serv services = append(services, service) @@ -179,6 +183,7 @@ func summarizeServices(dump structs.CheckServiceNodes) []*ServiceSummary { sum := getService(sid) sum.Nodes = append(sum.Nodes, csn.Node.Node) sum.Kind = svc.Kind + sum.InstanceCount += 1 for _, tag := range svc.Tags { found := false for _, existing := range sum.Tags { diff --git a/agent/ui_endpoint_test.go b/agent/ui_endpoint_test.go index 667f995ecc..58dbe0f12d 100644 --- a/agent/ui_endpoint_test.go +++ b/agent/ui_endpoint_test.go @@ -322,6 +322,7 @@ func TestUiServices(t *testing.T) { Name: "api", Tags: []string{"tag1", "tag2"}, Nodes: []string{"foo"}, + InstanceCount: 1, ChecksPassing: 2, ChecksWarning: 1, ChecksCritical: 0, @@ -332,6 +333,7 @@ func TestUiServices(t *testing.T) { Name: "cache", Tags: nil, Nodes: []string{"zip"}, + InstanceCount: 1, ChecksPassing: 0, ChecksWarning: 0, ChecksCritical: 0, @@ -342,6 +344,7 @@ func TestUiServices(t *testing.T) { Name: "web", Tags: nil, Nodes: []string{"bar", "foo"}, + InstanceCount: 2, ChecksPassing: 2, ChecksWarning: 1, ChecksCritical: 1, @@ -353,6 +356,7 @@ func TestUiServices(t *testing.T) { Name: "consul", Tags: nil, Nodes: []string{a.Config.NodeName}, + InstanceCount: 1, ChecksPassing: 1, ChecksWarning: 0, ChecksCritical: 0, @@ -385,6 +389,7 @@ func TestUiServices(t *testing.T) { Name: "api", Tags: []string{"tag1", "tag2"}, Nodes: []string{"foo"}, + InstanceCount: 1, ChecksPassing: 2, ChecksWarning: 1, ChecksCritical: 0, @@ -395,6 +400,7 @@ func TestUiServices(t *testing.T) { Name: "web", Tags: nil, Nodes: []string{"bar", "foo"}, + InstanceCount: 2, ChecksPassing: 2, ChecksWarning: 1, ChecksCritical: 1,