use sloburn; use budgetleft; fn plover_finite(values: vector) -> bool { let mut i = 0; while i < len(values) { let value = at(values, i); if !(value - value == 0.0) { return false; } i += 1; } true } fn plover_compute(fast_bad: f64, fast_total: f64, slow_bad: f64, slow_total: f64, allowed: f64, trigger: f64) -> vector { if fast_total > slow_total || fast_bad > slow_bad || fast_total - fast_bad > slow_total - slow_bad { return []; } let fast = sloburn_rate(fast_bad, fast_total, allowed); let slow = sloburn_rate(slow_bad, slow_total, allowed); let balance = budgetleft_events(slow_bad, slow_total, allowed); if len(fast) == 0 || len(slow) == 0 || len(balance) == 0 { return []; } let mut alert = 0; if at(fast, 1) >= trigger && at(slow, 1) >= trigger { alert = 1; } [alert, at(fast, 1), at(slow, 1), at(balance, 2)] } // Gate alerts on error-budget burn in both a short and a long window. // Returns [alert, short burn, long burn, long-window excess failures]. The short window must be a subset of the long window, including its good events. pub fn plover_alert(fast_bad: f64, fast_total: f64, slow_bad: f64, slow_total: f64, allowed: f64, trigger: f64) -> vector { if !(fast_bad >= 0.0 && fast_bad <= 9007199254740991.0 && fast_bad % 1.0 == 0.0) { return []; } if !(fast_total >= 1.0 && fast_total <= 9007199254740991.0 && fast_total % 1.0 == 0.0) { return []; } if !(slow_bad >= 0.0 && slow_bad <= 9007199254740991.0 && slow_bad % 1.0 == 0.0) { return []; } if !(slow_total >= 1.0 && slow_total <= 9007199254740991.0 && slow_total % 1.0 == 0.0) { return []; } if !(allowed > 0.0 && allowed - allowed == 0.0) { return []; } if !(trigger > 0.0 && trigger - trigger == 0.0) { return []; } let result = plover_compute(fast_bad, fast_total, slow_bad, slow_total, allowed, trigger); if !plover_finite(result) { return []; } result }