agent: Summarize node level checks as well

This commit is contained in:
Armon Dadgar 2014-04-30 10:12:24 -07:00 committed by Jack Pearkes
parent 8b2dc6dc4f
commit d1213d4e17
2 changed files with 19 additions and 13 deletions

View File

@ -130,22 +130,28 @@ func summarizeServices(dump structs.NodeDump) []*ServiceSummary {
// Aggregate all the node information // Aggregate all the node information
for _, node := range dump { 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 := getService(service.Service)
sum.Nodes = append(sum.Nodes, node.Node) sum.Nodes = append(sum.Nodes, node.Node)
nodeServices[idx] = sum
} }
for _, check := range node.Checks { for _, check := range node.Checks {
var services []*ServiceSummary
if check.ServiceName == "" { if check.ServiceName == "" {
continue services = nodeServices
} else {
services = []*ServiceSummary{getService(check.ServiceName)}
} }
sum := getService(check.ServiceName) for _, sum := range services {
switch check.Status { switch check.Status {
case structs.HealthPassing: case structs.HealthPassing:
sum.ChecksPassing++ sum.ChecksPassing++
case structs.HealthWarning: case structs.HealthWarning:
sum.ChecksWarning++ sum.ChecksWarning++
case structs.HealthCritical: case structs.HealthCritical:
sum.ChecksCritical++ sum.ChecksCritical++
}
} }
} }
} }

View File

@ -126,7 +126,7 @@ func TestSummarizeServices(t *testing.T) {
}, },
Checks: []*structs.HealthCheck{ Checks: []*structs.HealthCheck{
&structs.HealthCheck{ &structs.HealthCheck{
Status: structs.HealthCritical, Status: structs.HealthPassing,
ServiceName: "", ServiceName: "",
}, },
&structs.HealthCheck{ &structs.HealthCheck{
@ -173,7 +173,7 @@ func TestSummarizeServices(t *testing.T) {
expectAPI := &ServiceSummary{ expectAPI := &ServiceSummary{
Name: "api", Name: "api",
Nodes: []string{"foo"}, Nodes: []string{"foo"},
ChecksPassing: 0, ChecksPassing: 1,
ChecksWarning: 1, ChecksWarning: 1,
ChecksCritical: 0, ChecksCritical: 0,
} }
@ -195,7 +195,7 @@ func TestSummarizeServices(t *testing.T) {
expectWeb := &ServiceSummary{ expectWeb := &ServiceSummary{
Name: "web", Name: "web",
Nodes: []string{"bar", "foo"}, Nodes: []string{"bar", "foo"},
ChecksPassing: 1, ChecksPassing: 2,
ChecksWarning: 0, ChecksWarning: 0,
ChecksCritical: 1, ChecksCritical: 1,
} }