Gather instance counts of aggregated services (#7415)

pull/7417/head
Matt Keeler 2020-03-09 11:56:19 -04:00 committed by GitHub
parent ba9849bdf8
commit e3891db55b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -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 {

View File

@ -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,