mirror of https://github.com/hashicorp/consul
agent: Fixing passing filter. Fixes #241
parent
7ae573d79d
commit
135c409573
|
@ -117,6 +117,7 @@ func (s *HTTPServer) HealthServiceNodes(resp http.ResponseWriter, req *http.Requ
|
||||||
// filterNonPassing is used to filter out any nodes that have check that are not passing
|
// filterNonPassing is used to filter out any nodes that have check that are not passing
|
||||||
func filterNonPassing(nodes structs.CheckServiceNodes) structs.CheckServiceNodes {
|
func filterNonPassing(nodes structs.CheckServiceNodes) structs.CheckServiceNodes {
|
||||||
n := len(nodes)
|
n := len(nodes)
|
||||||
|
OUTER:
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
node := nodes[i]
|
node := nodes[i]
|
||||||
for _, check := range node.Checks {
|
for _, check := range node.Checks {
|
||||||
|
@ -124,6 +125,7 @@ func filterNonPassing(nodes structs.CheckServiceNodes) structs.CheckServiceNodes
|
||||||
nodes[i], nodes[n-1] = nodes[n-1], structs.CheckServiceNode{}
|
nodes[i], nodes[n-1] = nodes[n-1], structs.CheckServiceNode{}
|
||||||
n--
|
n--
|
||||||
i--
|
i--
|
||||||
|
continue OUTER
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -182,3 +183,39 @@ func TestHealthServiceNodes_PassingFilter(t *testing.T) {
|
||||||
t.Fatalf("bad: %v", obj)
|
t.Fatalf("bad: %v", obj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFilterNonPassing(t *testing.T) {
|
||||||
|
nodes := structs.CheckServiceNodes{
|
||||||
|
structs.CheckServiceNode{
|
||||||
|
Checks: structs.HealthChecks{
|
||||||
|
&structs.HealthCheck{
|
||||||
|
Status: structs.HealthCritical,
|
||||||
|
},
|
||||||
|
&structs.HealthCheck{
|
||||||
|
Status: structs.HealthCritical,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
structs.CheckServiceNode{
|
||||||
|
Checks: structs.HealthChecks{
|
||||||
|
&structs.HealthCheck{
|
||||||
|
Status: structs.HealthCritical,
|
||||||
|
},
|
||||||
|
&structs.HealthCheck{
|
||||||
|
Status: structs.HealthCritical,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
structs.CheckServiceNode{
|
||||||
|
Checks: structs.HealthChecks{
|
||||||
|
&structs.HealthCheck{
|
||||||
|
Status: structs.HealthPassing,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
out := filterNonPassing(nodes)
|
||||||
|
if len(out) != 1 && reflect.DeepEqual(out[0], nodes[2]) {
|
||||||
|
t.Fatalf("bad: %v", out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue