code wiki / _hdl_build / nx_apistack_canary.nx

nx_apistack_canary.nx source

↩ module page · 24 lines · 1248 B

1// nx_apistack_canary.nx -- CAP-API-CANARY: canary / blue-green traffic splitting for /api deploys. Deterministic 2// per-key routing: a request key (shard id / session) hashes to a bucket 0..99; if bucket < pct it goes to the 3// canary, else stable. STICKY (same key -> same side) + reproducible (integer hash, no RNG) = the sovereign exceed 4// over probabilistic cloud canaries. pct=0 -> all stable (instant rollback); pct=100 -> full cutover. Pairs with the 5// self-safe deploy marker (nx_deploy_marker) for a per-shard atomic promote. license_tier: ORIGINAL 6import "nx_syscalls.nx" 7const K_MAGIC_3750763034362895579: i64 = 3750763034362895579 8const K_MAGIC_1099511628211: i64 = 1099511628211 9 10// FNV key-hash for a routing key. 11func cy_keyhash(s: *u8, n: i64) -> i64 { 12 var h: i64 = 0 - K_MAGIC_3750763034362895579; var i: i64 = 0 13 while i < n { h = (h ^ ((s[i] as i64) & 0xff)) * K_MAGIC_1099511628211; i = i + 1 } 14 return h 15} 16// route decision: 1 = canary, 0 = stable. Deterministic split by (key_hash mod 100) < pct. 17func cy_is_canary(pct: i64, key_hash: i64) -> i64 { 18 if pct <= 0 { return 0 } 19 if pct >= 100 { return 1 } 20 var m: i64 = key_hash % 100 21 if m < 0 { m = m + 100 } 22 if m < pct { return 1 } 23 return 0 24}