Functional Weave
Code in Python

monitor.burn-rate

How fast an SLO's error budget is burning: the error rate as a multiple of the rate the SLO allows, in thousandths.

1.0.0 · published 2026-10-03 by charlie · Anterra

Pinned by 17 tests, run in TypeScript, Python and Rust.

What it does

How fast a service is spending its error budget: the error rate in a window divided by the error rate its SLO allows, as thousandths (`1000` = 1x).

burn = (bad / total) / ((10000 - target) / 10000)

For example

  • burn_rate(99.9%, 1,000,000, 1,000) → 1,000 0.1% errors against a 99.9% SLO is a burn rate of exactly 1x
  • burn_rate(99.9%, 10,000, 144) → 14,400 1.44% errors against 99.9% is the workbook's 14.4x fast-burn page threshold
  • burn_rate(99.9%, 1,000, 6) → 6,000 0.6% errors against 99.9% is the workbook's 6x page threshold

The function

The same function in TypeScript, Python and Rust, pinned by the same tests. Pick your language; the choice follows you around the registry.

def burn_rate(target_basis_points: int, total_events: int, bad_events: int) -> int
target_basis_pointsintthe SLO: 9990 = 99.9%; 1 to 9999
total_eventsintrequests (or seconds) in the window being measured
bad_eventsintthe failed ones; at most totalEvents
returnsintburn rate x 1000, half-up: 1000 spends the budget exactly over the SLO period, 14400 is 14.4x

Your code names it in one line, in the file that uses it

from fune.monitor.burn_rate import burn_rate  # monitor.burn-rate@^1
impl/python.py · 23 lines · open · raw
def _whole(value: object) -> bool:
    return isinstance(value, int) and not isinstance(value, bool)


def burn_rate(target_basis_points: int, total_events: int, bad_events: int) -> int:
    """How fast an SLO's error budget is burning, in thousandths: the window's
    error rate divided by the error rate the SLO allows. 1000 spends exactly
    the budget over the SLO period; 14400 (14.4x) spends 2% of a 30-day
    budget in one hour."""
    if not _whole(target_basis_points) or target_basis_points < 1 or target_basis_points > 9999:
        raise ValueError("targetBasisPoints must be a whole number from 1 to 9999 (10000 leaves no error budget), received %s" % (target_basis_points,))
    if not _whole(total_events) or total_events < 0:
        raise ValueError("totalEvents must be a whole number of at least 0, received %s" % (total_events,))
    if not _whole(bad_events) or bad_events < 0:
        raise ValueError("badEvents must be a whole number of at least 0, received %s" % (bad_events,))
    if bad_events > total_events:
        raise ValueError("badEvents must not exceed totalEvents: %d > %d" % (bad_events, total_events))
    # An empty window has no error rate; 0 keeps an alert quiet rather than failing it.
    if total_events == 0:
        return 0
    n = bad_events * 10000 * 1000
    d = total_events * (10000 - target_basis_points)
    return (2 * n + d) // (2 * d)

Install

fune build

With that line in your source, in a Python project (language python in fune.project), fune build resolves it and nothing else, pins them in fune.lock, downloads only the Python package of each, and builds the code above into your project’s .fune/build, one readable file per capability with a header linking back here. Or pin a range in fune.project and build in one step:

fune add monitor.burn-rate
Download for Python monitor.burn-rate-1.0.0-python.fune · 7,265 bytes sha256 3030b390b51ad3059c0fad29996efbaa90c482d35493ed3c7ce05ec783051808

The manifest, vectors and README with only the Python implementation. Install it without the registry with fune add ./monitor.burn-rate-1.0.0-python.fune, or fetch it from a terminal with fune pull monitor.burn-rate@1.0.0:python.

The whole function, every language, is one file too: monitor.burn-rate-1.0.0.fune, 10,928 bytes, sha256 46c18382d46a5017709173ffb79dffb5064f4708ea3cbc5a92acd65d672b4ccc. It installs into a project of any language.

Customise it in your app

The seams this capability offers. Put a marker directly above a function of your own and fune build wires it into the built code; the package on the registry is not changed, the built file’s header lists it under CUSTOMISED, and fune hooks lists every hook in the project. How hooks work.

before — your function gets the arguments and returns them, changed or not, or throws to refuse the call.

# fune: before monitor.burn-rate

after — your function gets the result and the arguments, and returns the final result.

# fune: after monitor.burn-rate

replace — it requires no other capability, so there is no dependency to replace.

step — your function runs at a numbered point inside the function’s body, receives the in-scope values it names as parameters, and may return replacements. List the points with fune show monitor.burn-rate --steps.

# fune: step monitor.burn-rate after <n|label>

Tests

A version published now needs at least 8 tests for every function, and one that expects the error for each function that throws; the registry refuses it otherwise. fune verify --all runs each case in TypeScript, Python and Rust, and a project runs them again with fune verify. This page lists the cases; it does not run them. The exact JSON is vectors.json.

CaseArgumentsExpected
0.1% errors against a 99.9% SLO is a burn rate of exactly 1x 99.9%, 1,000,000, 1,000 → 1,000
1.44% errors against 99.9% is the workbook's 14.4x fast-burn page threshold 99.9%, 10,000, 144 → 14,400
0.6% errors against 99.9% is the workbook's 6x page threshold 99.9%, 1,000, 6 → 6,000
an empty window burns nothing 99.9%, 0, 0 → 0
no errors burns nothing 99.9%, 50,000, 0 → 0
every request failing at 99.9% is 1000x 99.9%, 50, 50 → 1,000,000
1.5% errors against a 99% SLO is 1.5x 99%, 200, 3 → 1,500
rounds half up: 2.5 thousandths becomes 3 90%, 4,000, 1 → 3
one error in three requests at 99.9% rounds down: 333.333x 99.9%, 3, 1 → 333,333
two errors in three requests at 99.9% rounds up: 666.667x 99.9%, 3, 2 → 666,667
Show the other 7 tests
CaseArgumentsExpected
the loosest target, 0.01%: everything failing is barely over 1x 0.01%, 9,999, 9,999 → 1,000
a trillion requests at 99.99%: products pass 2^53 and stay exact 99.99%, 1,000,000,000,000, 1,234,567,891 → 12,346
a 100% target has no budget to burn and is an error 100%, 100, 1 → error: targetBasisPoints must be a whole number from 1 to 9999 (10000 leaves no error budget), received 10000
a 0% target is an error 0%, 100, 1 → error: targetBasisPoints must be a whole number from 1 to 9999
negative total is an error 99.9%, -5, 0 → error: totalEvents must be a whole number of at least 0, received -5
more bad events than events is an error 99.9%, 4, 5 → error: badEvents must not exceed totalEvents: 5 > 4
a fractional count is an error 99.9%, 10, 1.5 → error: badEvents must be a whole number of at least 0, received 1.5

More from the author

At 1x the budget lasts exactly the SLO period (30 days in the workbook); at 14.4x a 30-day budget is gone in 50 hours, and one hour at that rate spends 2% of it (14.4 x 1h / 720h). Budget spent in a window = burn x window / period.

Burn rate is what SLO alerts compare against a threshold: see `monitor.burn-rate-alert` for the workbook's multiwindow, multi-burn-rate rules. On its own it is the number for a dashboard ("burning at 3.2x").

## Decisions

- **Thousandths, half up.** 14.4x is `14400`. Integers keep the three languages identical. An alert that must not fire early on rounding should compare exactly, as `monitor.burn-rate-alert` does. - **An empty window is 0**, not an error: no traffic spends no budget, and a quiet night should not break the alerting. - **Exact arithmetic.** bad x 10000 x 1000 passes 2^53 below a billion bad events, so the division is exact (BigInt in TypeScript, i128 in Rust, Python's integers). The design pinned `math.round-div`; it is not used, because its integers stop at 2^53. - **It works on seconds too**: total = window seconds, bad = down seconds.

## Errors

- `targetBasisPoints must be a whole number from 1 to 9999 (10000 leaves no error budget), received X` - `totalEvents must be a whole number of at least 0, received X` - `badEvents must be a whole number of at least 0, received X` - `badEvents must not exceed totalEvents: B > T`

## Sources

Google SRE Workbook, chapter 5 "Alerting on SLOs", section "Alert on Burn Rate" (https://sre.google/workbook/alerting-on-slos/): burn rate is how fast, relative to the SLO, the service consumes the error budget; 1 consumes all of it in the 30-day window; Table 5-8 uses 14.4, 6 and 1.

Files

PathBytes
README.md1,926
impl/python.py1,396
impl/rust.rs2,087
impl/typescript.ts1,445
vectors.json2,093