Error budget burn-rate alert
From per-minute good and total request counts, decide whether a multi-window burn-rate alert fires: the long and the short window must both burn the error budget faster than a threshold.
Statement
An SLO of 99.9% leaves an error budget of 0.1% of requests. The burn rate of a window is how fast it spends that budget: the window's error ratio divided by (1 − slo). A burn rate of 1 spends the budget exactly over the SLO period; a burn rate of 14.4 held for one hour spends 2% of a 30-day budget.
Write burn_rate_alert(minutes, slo, long_window, short_window, threshold). minutes is a list of (good, total) request counts, one per minute, oldest first, so the last item is the most recent minute. A window is the last long_window or short_window minutes, and its error ratio is bad requests over total requests across the whole window. Return True only when both windows have a burn rate above threshold.
The long window shows the burn is large enough to matter. The short window shows it is still going on, so the alert clears soon after the errors stop.
Examples
slo = 0.999, long_window = 60, short_window = 5, threshold = 14.4
60 minutes of (980, 1000) long 0.02 / 0.001 = 20, short 20 → True 55 minutes of (980, 1000), then 5 of (1000, 1000) long 1100 / 60000 / 0.001 = 18.3, short 0 → False 55 minutes of (1000, 1000), then 5 of (900, 1000) long 500 / 60000 / 0.001 = 8.3, short 100 → False
Constraints
Up to 10⁵ minutes. 1 ≤ short_window ≤ long_window, 0 < slo < 1 and 0 ≤ good ≤ total. With fewer minutes than a window, use the minutes there are. A window with no requests has a burn rate of 0. A burn rate equal to the threshold does not fire. With no minutes at all, return False.