mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 08:23:45 +00:00
fix: calculate conservative SLO percentiles
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package observability
|
||||
|
||||
import (
|
||||
"math"
|
||||
"sort"
|
||||
"time"
|
||||
)
|
||||
@@ -52,7 +53,13 @@ func percentile(values []time.Duration, p float64) time.Duration {
|
||||
}
|
||||
ordered := append([]time.Duration(nil), values...)
|
||||
sort.Slice(ordered, func(i, j int) bool { return ordered[i] < ordered[j] })
|
||||
index := int(float64(len(ordered)-1) * p)
|
||||
index := int(math.Ceil(p*float64(len(ordered)))) - 1
|
||||
if index < 0 {
|
||||
index = 0
|
||||
}
|
||||
if index >= len(ordered) {
|
||||
index = len(ordered) - 1
|
||||
}
|
||||
return ordered[index]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user