Skip to main content

Crate slokit

Crate slokit 

Source
Expand description

§slokit

An SLO and error-budget engine for Rust.

slokit does two things:

  1. 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).

  2. Generator (the spec feature, on by default via cli): parse a sloth-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§

checkcheck
Live checking against a Prometheus HTTP API.
dashboarddashboard
Generate a Grafana dashboard from a Spec.
error
Error type for the slokit crate.
generatespec
Generate Prometheus rules from a Spec.
specspec
The slokit SLO spec: a sloth-compatible YAML model plus small native extensions.

Structs§

AlertWindow
One burn-rate condition: a long and short window that must both be burning faster than factor times the budget for the alert to fire.
BurnRate
How fast an error budget is being consumed.
ErrorBudget
A concrete error budget: the allowable failures for a known event volume over an SLO period.
MwmbrConfig
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 Objective measured over a rolling Window (the SLO period, typically 30 days).
Window
A non-zero span of time, stored as whole seconds.

Enums§

Severity
Alert severity in the MWMBR scheme.
Sli
How an SLO’s error ratio is computed from Prometheus.

Constants§

WINDOW_TOKEN
The template token replaced with each lookback window when rendering queries. Matches sloth’s Go-template convention.