code wiki / _hdl_build / nx_consul_health.nx

nx_consul_health.nx source

↩ module page · 24 lines · 1403 B

1// nx_consul_health.nx -- sovereign LIVE HEALTH CHECKS (HashiCorp Consul health-check-class; CONSUL-004). 2// Drives each instance's health (PASSING/CRITICAL in the CONSUL-001 registry) from a probe result -- in 3// production probe_ok = (nx_reach_probe(addr,port) == 0), real TCP reachability. FLAP PROTECTION: a single 4// failure does NOT flip a healthy node; it takes fail_thr CONSECUTIVE failures to go CRITICAL, and pass_thr 5// CONSECUTIVE successes to recover to PASSING -- so transient blips don't yank a node out of discovery/DNS. 6// The updated health array feeds cs_discover / csd_resolve directly = the loop is closed. Composes 7// nx_consul_registry. license_tier: ORIGINAL 8import "nx_consul_registry.nx" 9import "nx_syscalls.nx" 10 11// apply one probe result to instance idx's check state (mutates in place); return its (maybe-updated) health. 12// probe_ok=1 = reachable. fail_thr consecutive fails -> CRITICAL; pass_thr consecutive passes -> PASSING. 13func hc_tick(health: *i64, cfails: *i64, cpasses: *i64, idx: i64, probe_ok: i64, fail_thr: i64, pass_thr: i64) -> i64 { 14 if probe_ok == 1 { 15 cpasses[idx] = cpasses[idx] + 1 16 cfails[idx] = 0 17 if cpasses[idx] >= pass_thr { health[idx] = SVC_PASSING } 18 } else { 19 cfails[idx] = cfails[idx] + 1 20 cpasses[idx] = 0 21 if cfails[idx] >= fail_thr { health[idx] = SVC_CRITICAL } 22 } 23 return health[idx] 24}