Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
Miek Gieben
2020-01-16 19:45:43 +01:00
parent 45f11f3276
commit 246782b726
4 changed files with 25 additions and 21 deletions

View File

@@ -54,10 +54,10 @@ func (a *assignment) clusters() []string {
// Select selects a backend from cla, using weighted random selection. It only selects
// backends that are reporting healthy.
func (a *assignment) Select(cluster string) net.IP {
func (a *assignment) Select(cluster string) (net.IP, bool) {
cla := a.clusterLoadAssignment(cluster)
if cla == nil {
return nil
return nil, false
}
total := 0
@@ -81,7 +81,7 @@ func (a *assignment) Select(cluster string) net.IP {
// continue
// }
if r == i {
return net.ParseIP(lb.GetEndpoint().GetAddress().GetSocketAddress().GetAddress())
return net.ParseIP(lb.GetEndpoint().GetAddress().GetSocketAddress().GetAddress()), true
}
i++
}
@@ -98,9 +98,9 @@ func (a *assignment) Select(cluster string) net.IP {
// }
r -= int(lb.GetLoadBalancingWeight().GetValue())
if r <= 0 {
return net.ParseIP(lb.GetEndpoint().GetAddress().GetSocketAddress().GetAddress())
return net.ParseIP(lb.GetEndpoint().GetAddress().GetSocketAddress().GetAddress()), true
}
}
}
return nil
return nil, false
}