SLO Metrics: P99 & Burn Rate

medium · distributed-systems, observability, sre

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) - 1 in the sorted list.)
  • Burn rate of the error budget for a latency SLO. A request is good if latency <= threshold. errorRate = 1 - good/total burnRate = 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) <= 200000
  • 0 <= latency, threshold <= 1_000_000
  • 0 < target < 1

Notes

  • If latencies is empty, return p99=0, burnRate=0.
  • Use floating-point math for burn rate.
Run tests to see results
No issues detected