Multi-Window Burn Rate Alert
Problem Statement
Implement a multi-window burn-rate alert: fire only when the error budget is being consumed too fast over both a long and a short window (to catch fast burns while avoiding flapping).
Background
Burn rate = observed_error_rate / (1 - slo) — how many times faster than sustainable the budget is being spent. A page fires when the burn rate exceeds threshold over the long window AND over the short window simultaneously. Given error rates for each window, decide whether to alert.
Your Task
def burn_alert(slo, long_err_rate, short_err_rate, threshold):
Return True if both windows' burn rates exceed threshold, else False.
Input Format
- slo (float), long_err_rate, short_err_rate (float), threshold (float).
Output Format
- A boolean.
Sample
print(burn_alert(0.99, 0.15, 0.20, 10.0))
Output:
True
Example:
print(burn_alert(0.99, 0.15, 0.20, 10.0))
True
- Calculate the sustainable error budget rate by subtracting the SLO from 1, representing the maximum acceptable error fraction: 1−0.99=0.01.
- Determine the long-window burn rate by dividing the observed long error rate by the budget rate to see how many times faster the budget is being consumed: 0.15/0.01=15.
- Determine the short-window burn rate by dividing the observed short error rate by the budget rate: 0.20/0.01=20.
- Evaluate the alert condition, which requires both burn rates to strictly exceed the threshold of 10.0: 15>10.0 is true and 20>10.0 is true.
- The final output is True
Constraints:
- burn = err_rate / (1 - slo).
- Alert only if BOTH long and short burn > threshold.
- Return a bool.
1. Background Knowledge
In Site Reliability Engineering (SRE), a Service Level Objective (SLO) defines the minimum acceptable performance, typically expressed as a percentage of successful requests (e.g., 99.9%). The error budget is the complement of the SLO: 1−slo. It represents the fraction of requests that are allowed to fail before the service is considered unreliable. For an SLO of 0.99, the error budget is 0.01, meaning 1% of requests may fail.
The burn rate quantifies how quickly the error budget is being consumed relative to a sustainable pace. It is defined as:
burn_rate=1−sloobserved_error_rate​A burn rate of 1.0 means the budget is being consumed at the sustainable rate. A burn rate of 10.0 means the budget is being consumed 10 times faster than sustainable, which would exhaust the budget in 1/10th of the planned period.
The multi-window burn-rate alert pattern, popularized by Google SRE, uses two time windows (long and short) to balance sensitivity and stability. A long window (e.g., 6 hours) catches slow, steady degradation, while a short window (e.g., 30 minutes) catches sudden spikes. An alert fires only when both windows exceed a threshold simultaneously. This dual-condition logic prevents flapping (alerts that toggle on/off due to transient noise) while still catching fast burns that a long window alone would miss.
2. Algorithm Approach
This is a straightforward threshold comparison problem with a logical AND condition. The approach is:
- Compute the burn rate for each window independently using the formula above.
- Compare each burn rate against the given threshold.
- Return True only if both comparisons are satisfied.
There is no iterative or recursive structure; the solution is a direct arithmetic computation followed by a boolean conjunction.
3. Step-by-Step Strategy
Continue the full explanation
You're reading the free preview. Unlock the complete walkthrough, the code editor, test runner and reference solution with Premium.
Editor locked
The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.