Expand description
§slokit
An SLO and error-budget engine for Rust.
slokit does two things:
-
Library core (always available): compute error budgets, burn rates, and the multi-window multi-burn-rate (MWMBR) alert model from the Google SRE Workbook. This core has no
serde, YAML, or CLI dependencies, so it embeds cleanly inside services (for example, an Axum handler that reports live budget status). -
Generator (the
specfeature, on by default viacli): parse asloth-compatible YAML spec and generate Prometheus recording rules, metadata rules, and MWMBR page/ticket alert rules.
§Library example
use slokit::{Objective, Slo, BurnRate, Window};
let slo = Slo::new(Objective::percent(99.9).unwrap(), Window::days(30));
// With a million events, 0.1% may fail: ~1,000 allowed failures.
let budget = slo.error_budget(1_000_000.0);
assert!((budget.allowed_bad_events() - 1_000.0).abs() < 1e-6);
// Observing a 1% error rate is a 10x burn against a 99.9% objective.
let burn = BurnRate::from_error_ratio(0.01, &slo);
assert!((burn.value() - 10.0).abs() < 1e-9);§Generating Prometheus rules
With the default features enabled:
ⓘ
use slokit::spec::Spec;
use slokit::generate::generate_rules;
let spec = Spec::from_yaml(yaml_str)?;
let ruleset = generate_rules(&spec)?;
println!("{}", ruleset.to_yaml()?);Re-exports§
pub use error::Result;pub use error::SlokitError;
Modules§
- check
check - Live checking against a Prometheus HTTP API.
- dashboard
dashboard - Generate a Grafana dashboard from a
Spec. - error
- Error type for the
slokitcrate. - generate
spec - Generate Prometheus rules from a
Spec. - spec
spec - The
slokitSLO spec: asloth-compatible YAML model plus small native extensions.
Structs§
- Alert
Window - One burn-rate condition: a long and short window that must both be burning
faster than
factortimes the budget for the alert to fire. - Burn
Rate - How fast an error budget is being consumed.
- Error
Budget - A concrete error budget: the allowable failures for a known event volume over an SLO period.
- Mwmbr
Config - A multi-window multi-burn-rate alert configuration: the set of burn-rate conditions that, OR-ed together per severity, form the page and ticket alerts.
- Objective
- A reliability target, stored as a ratio in the open interval
(0, 1). - Slo
- A Service Level Objective: an
Objectivemeasured over a rollingWindow(the SLO period, typically 30 days). - Window
- A non-zero span of time, stored as whole seconds.
Enums§
Constants§
- WINDOW_
TOKEN - The template token replaced with each lookback window when rendering
queries. Matches
sloth’s Go-template convention.