← Files Platform Engineering CopilotARCHIVED FILE
scripts/slo_math.py
793 Bytes · Nov 3, 2026 · 00:12 UTC
"""Basic math for event-based SLOs; never infer missing traffic counts."""
def calculate_slo(total: int, bad: int, objective: float) -> dict:
if isinstance(total,bool) or isinstance(bad,bool) or not isinstance(total,int) or not isinstance(bad,int):raise ValueError('counts must be integers')
if total<=0 or bad<0 or bad>total: raise ValueError('counts out of range')
if not isinstance(objective,(float,int)) or isinstance(objective,bool) or not 0<objective<1: raise ValueError('objective must be fraction between 0 and 1')
allowed=total*(1-objective)
good=total-bad
return {'total':total,'bad':bad,'good':good,'success_fraction':good/total,'target_fraction':float(objective),'allowed_bad_events':allowed,'remaining_bad_events':allowed-bad,'met':good/total>=objective}
SHA-256: 34d0dc9c6fc24d260431f889397671af3d98e2637339b4d672fd7d16ee9e474f