-
Notifications
You must be signed in to change notification settings - Fork 353
/
Copy pathhealthy_endpoints.go
50 lines (40 loc) · 1.24 KB
/
healthy_endpoints.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package proxy
import (
"math/rand"
"github.com/zalando/skipper/metrics"
"github.com/zalando/skipper/routing"
)
type healthyEndpoints struct {
rnd *rand.Rand
maxUnhealthyEndpointsRatio float64
}
func (h *healthyEndpoints) filterHealthyEndpoints(ctx *context, endpoints []routing.LBEndpoint, metrics metrics.Metrics) []routing.LBEndpoint {
if h == nil {
return endpoints
}
p := h.rnd.Float64()
unhealthyEndpointsCount := 0
maxUnhealthyEndpointsCount := float64(len(endpoints)) * h.maxUnhealthyEndpointsRatio
filtered := make([]routing.LBEndpoint, 0, len(endpoints))
for _, e := range endpoints {
dropProbability := e.Metrics.HealthCheckDropProbability()
if p < dropProbability {
ctx.Logger().Debugf("Dropping endpoint %q due to passive health check: p=%0.2f, dropProbability=%0.2f",
e.Host, p, dropProbability)
metrics.IncCounter("passive-health-check.endpoints.dropped")
unhealthyEndpointsCount++
} else {
filtered = append(filtered, e)
}
if float64(unhealthyEndpointsCount) > maxUnhealthyEndpointsCount {
return endpoints
}
}
if len(filtered) == 0 {
return endpoints
}
if len(filtered) < len(endpoints) {
metrics.IncCounter("passive-health-check.requests.passed")
}
return filtered
}