SLO Metrics: P99 & Burn Rate
SLO Metrics: P99 & Burn Rate
You are given a batch of request latencies (ms). Compute two common SLO metrics:
- P99 latency: the 99th percentile latency. (Index
ceil(0.99*n) - 1in the sorted list.) - Burn rate of the error budget for a latency SLO. A request is good if
latency <= threshold.errorRate = 1 - good/totalburnRate = errorRate / (1 - target)
Return p99 and burnRate.
Function signature
func SLOMetrics(latencies []int, threshold int, target float64) (p99 int, burnRate float64)
Example
latencies = [100, 120, 80, 200]
threshold = 150
target = 0.99
sorted = [80,100,120,200]
P99 index = ceil(0.99*4)-1 = 3
p99 = 200
errorRate = 1/4 = 0.25
burnRate = 0.25 / 0.01 = 25
Constraints
0 <= len(latencies) <= 2000000 <= latency, threshold <= 1_000_0000 < target < 1
Notes
- If
latenciesis empty, returnp99=0,burnRate=0. - Use floating-point math for burn rate.
Run tests to see results
No issues detected