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 640027e10d
commit 9f2e236cf8
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
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++
}
}
}
}

View File

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