code wiki / _hdl_build / nx_apistack_slo.nx
nx_apistack_slo.nx source
↩ module page · 24 lines · 1229 B
1// nx_apistack_slo.nx -- CAP-API-SLO: service-level objective + error budget for /api, computed from the deterministic
2// health snapshot counts. Pure INTEGER math (no float, no external SLO SaaS = the sovereign exceed): remaining error
3// budget = allowed_errors - actual_errors; negative = SLO BREACHED. target_permil is the availability target
4// (999 = 99.9%). license_tier: ORIGINAL
5import "nx_syscalls.nx"
6
7// allowed errors under the target over `total` requests.
8func slo_allowed_errors(total: i64, target_permil: i64) -> i64 {
9 return total * (1000 - target_permil) / 1000
10}
11// remaining error budget (allowed - actual); negative = breached.
12func slo_error_budget(total: i64, errors: i64, target_permil: i64) -> i64 {
13 return slo_allowed_errors(total, target_permil) - errors
14}
15// 1 if the SLO is breached (budget exhausted), else 0.
16func slo_breached(total: i64, errors: i64, target_permil: i64) -> i64 {
17 if slo_error_budget(total, errors, target_permil) < 0 { return 1 }
18 return 0
19}
20// measured availability in permil (successes/total*1000); empty window = 1000.
21func slo_availability_permil(total: i64, errors: i64) -> i64 {
22 if total <= 0 { return 1000 }
23 return (total - errors) * 1000 / total
24}