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:
raf 2026-03-06 23:22:45 +03:00
commit 2aaf84e425
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF

View file

@ -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