SLO, error budget, and burn-rate evaluation primitives for MoonBit.
moon version --all///|
test {
let target = SloTarget::new("api", 9900, 30 * 24 * 60)
let window = RequestWindow::new("5m", 5, 1000, 980)
let burn = calculate_burn_rate(target, window)
assert_eq(burn.rate_label(), "2.00x")
}moon check --target all
moon test --target wasm
moon test --target wasm-gc
moon run cmd/mainmoon update
moon check --target all
moon test --target all
moon fmt && git diff --exit-code
moon info && git diff --exit-codemoon new slo-consumer
cd slo-consumer
moon add Zxy666668/moonslokit///|
import {
"Zxy666668/moonslokit" @slo,
}
///|
fn main {
let target = @slo.SloTarget::new("checkout-api", 9900, 30 * 24 * 60)
let window = @slo.RequestWindow::new("5m", 5, 1000, 980)
println(@slo.evaluate_budget(target, window).to_json())
}pub(all) struct AlertDecision {
level : AlertLevel
rule_name : String
burn_rate_x100 : Int
reason : String
} derive(Eq, Debug)pub(all) struct AlertRoute {
level : AlertLevel
channel : AlertChannel
destination : String
} derive(Eq, Debug)pub(all) struct AnnotatedWindow {
window : RequestWindow
annotations : Array[SloAnnotation]
} derive(Eq, Debug)pub(all) struct BudgetForecast {
report : BudgetReport
lookback_minutes : Int
bad_per_hour_x100 : Int
minutes_to_exhaustion : Int
state : String
} derive(Eq, Debug)pub(all) struct BudgetProjection {
target : SloTarget
current : BudgetReport
projected_bad : Int
projected_total : Int
projected_consumed_bp : Int
remaining_after_projection : Int
status : String
} derive(Eq, Debug)pub(all) struct BudgetReport {
target : SloTarget
window : RequestWindow
allowed_bad : Int
actual_bad : Int
consumed_bp : Int
remaining_bad : Int
} derive(Eq, Debug)pub(all) struct BurnReport {
window : RequestWindow
allowed_error_bp : Int
observed_error_bp : Int
burn_rate_x100 : Int
} derive(Eq, Debug)pub(all) struct EscalationPolicy {
name : String
routes : Array[AlertRoute]
default_route : AlertRoute
} derive(Eq, Debug)pub(all) struct GateDecision {
gate_name : String
allowed : Bool
reason : String
consumed_bp : Int
highest_level : AlertLevel
} derive(Eq, Debug)pub(all) struct HealthReport {
service : String
target : SloTarget
statistics : WindowStatistics
latest : BudgetReport
peak_burn_x100 : Int
incident_count : Int
severity : ReportSeverity
incidents : IncidentTimeline
} derive(Eq, Debug)fn HealthReport::from_windows(service : String, target : SloTarget, windows : Array[RequestWindow], incidents : IncidentTimeline) -> HealthReportpub(all) struct Incident {
id : String
started_minute : Int
ended_minute : Int
severity : IncidentSeverity
title : String
impact_bp : Int
} derive(Eq, Debug)fn Incident::new(id : String, started_minute : Int, ended_minute : Int, severity : IncidentSeverity, title : String, impact_bp : Int) -> Incidentfn IncidentTimeline::impact_average(self : IncidentTimeline, start_minute : Int, end_minute : Int) -> Intfn IncidentTimeline::overlap_count(self : IncidentTimeline, start_minute : Int, end_minute : Int) -> Intpub(all) struct MultiWindowReport {
target : SloTarget
reports : Array[BurnReport]
decisions : Array[AlertDecision]
} derive(Eq, Debug)pub(all) struct ObservationSeries {
name : String
window_minutes : Int
samples : Array[TrafficSample]
} derive(Eq, Debug)fn ObservationSeries::budget_reports(self : ObservationSeries, target : SloTarget) -> Array[BudgetReport]fn ObservationSeries::burn_reports(self : ObservationSeries, target : SloTarget) -> Array[BurnReport]fn ObservationSeries::from_samples(name : String, window_minutes : Int, samples : Array[TrafficSample]) -> ObservationSeriesfn ObservationSeries::window_from(self : ObservationSeries, start_minute : Int, end_minute : Int) -> RequestWindowpub(all) struct ReliabilityResult {
id : String
budget : BudgetReport
burn : BurnReport
label : String
recommendation : String
} derive(Eq, Debug)pub(all) struct ReliabilityRun {
id : String
target : SloTarget
window : RequestWindow
} derive(Eq, Debug)pub(all) struct ServiceEvaluation {
service : String
target_name : String
budget : BudgetReport
multi_window : MultiWindowReport
gate : GateDecision
} derive(Eq, Debug)fn ServiceObjective::new(service : String, target : SloTarget, burn_rules : Array[BurnRule]) -> ServiceObjectivepub(all) struct ValidationIssue {
code : String
message : String
kind : ValidationKind
} derive(Eq, Debug)pub(all) struct ValidationReport {
valid : Bool
checked : Int
issues : Array[ValidationIssue]
} derive(Eq, Debug)fn aggregate_recent_samples(name : String, now_minute : Int, window_minutes : Int, samples : Array[TrafficSample]) -> RequestWindowfn aggregate_samples(name : String, window_minutes : Int, samples : Array[TrafficSample]) -> RequestWindowfn annotate_window(window : RequestWindow, start_minute : Int, annotations : Array[SloAnnotation]) -> AnnotatedWindowfn evaluate_multi_window(target : SloTarget, windows : Array[RequestWindow], rules : Array[BurnRule]) -> MultiWindowReportfn evaluate_release_gate(gate : ReleaseGate, budget : BudgetReport, report : MultiWindowReport) -> GateDecisionfn evaluate_release_readiness(target : SloTarget, current : RequestWindow, recent : Array[RequestWindow]) -> ReliabilityResultfn evaluate_service_objective(objective : ServiceObjective, budget_window : RequestWindow, burn_windows : Array[RequestWindow], gate : ReleaseGate) -> ServiceEvaluationfn forecast_budget(target : SloTarget, window : RequestWindow, lookback_minutes : Int) -> BudgetForecastfn project_budget(target : SloTarget, current : RequestWindow, additional_total : Int, additional_bad : Int) -> BudgetProjectionSLO, error budget, and burn-rate evaluation primitives for MoonBit.