prober: fix unstable sort when latency within 10% and priorities equal
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I49fed694108cfb91ffe3ffad5c02c3a96a6a6964
This commit is contained in:
parent
64e18cbab5
commit
2aaf84e425
1 changed files with 4 additions and 2 deletions
|
|
@ -177,10 +177,12 @@ func (p *Prober) SortedByLatency() []*UpstreamHealth {
|
||||||
if aDown != bDown {
|
if aDown != bDown {
|
||||||
return bDown // non-down first
|
return bDown // non-down first
|
||||||
}
|
}
|
||||||
// Within 10% latency difference: prefer lower priority number.
|
// Within 10% latency difference: prefer lower priority number, then lower latency.
|
||||||
if b.EMALatency > 0 && math.Abs(a.EMALatency-b.EMALatency)/b.EMALatency < 0.10 {
|
if b.EMALatency > 0 && math.Abs(a.EMALatency-b.EMALatency)/b.EMALatency < 0.10 {
|
||||||
|
if a.Priority != b.Priority {
|
||||||
return a.Priority < b.Priority
|
return a.Priority < b.Priority
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return a.EMALatency < b.EMALatency
|
return a.EMALatency < b.EMALatency
|
||||||
})
|
})
|
||||||
return result
|
return result
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue