Filter non-passing nodes without modifying cache

This commit is contained in:
Freddy 2019-04-16 10:29:34 -06:00 committed by GitHub
parent a320a23110
commit eebc788959
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -264,17 +264,21 @@ 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
func filterNonPassing(nodes structs.CheckServiceNodes) structs.CheckServiceNodes {
n := len(nodes)
// Make a copy of the cached nodes rather than operating on the cache directly
out := append(nodes[:0:0], nodes...)
OUTER:
for i := 0; i < n; i++ {
node := nodes[i]
node := out[i]
for _, check := range node.Checks {
if check.Status != api.HealthPassing {
nodes[i], nodes[n-1] = nodes[n-1], structs.CheckServiceNode{}
out[i], out[n-1] = out[n-1], structs.CheckServiceNode{}
n--
i--
continue OUTER
}
}
}
return nodes[:n]
return out[:n]
}