mirror of https://github.com/status-im/consul.git
agent: Summarize node level checks as well
This commit is contained in:
parent
8b2dc6dc4f
commit
d1213d4e17
|
@ -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++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue