edge: backend health checks every 30s, staggered (default-server + spread-checks) #23

Merged
jknapp merged 2 commits from feat/health-check-interval into main 2026-11-25 15:04:34 +00:00
Owner

What

Backend health checks move from HAProxy's default 2 s to 30 s, set once and jittered.

templates/hap_header.tpl (rendered once per config; every backend template inherits it, no per-server change):

global
    spread-checks 50
defaults
    default-server          inter 30s fastinter 10s downinter 30s rise 2 fall 3

templates/hap_coraza_spoa_backend.tpl: the WAF agent keeps fast checks (check inter 2s fastinter 2s downinter 2s rise 2 fall 3), a single local server where detection speed matters and cost is nil.

WHP still supplies check ssl verify none per server (panel/internal/haproxy/site.go); that is untouched (check type is NOT changed here, per Josh).

Why (context: haproxy-nbthread / haproxy-watchdog-fleet notes, 2026-11-25)

whp01 has ~426 check ssl servers at 2 s = ~200+ TLS handshakes/s of pure health-check churn, which together with memory pressure preceded the watchdog aborts.

Why fastinter 10s, not 2s (deviation from the first suggestion, please review)

Verified in the 3.2 source/docs (src/check.c start_check_task, srv_getinter; configuration.txt inter/spread-checks):

  • HAProxy spreads the FIRST check of every server over the smallest interval in use, and a server not yet at full health (every server after a start or reload) uses fastinter. So fastinter 2s puts all first checks of every reload into a ~2 s window.
  • spread-checks N only randomises each later interval by +/- N% (max 50); it does not change the start offsets. Without it a fixed 30 s period keeps whatever phase clusters formed at start.

Measured with real haproxy 3.2.26 (image 2026.11.6 binary), 300 check servers, tcp-check sending a byte so the listener can count them, per-second connections to the backend:

config first 10 s (per s) steady 30-90 s max/s (avg 10 = 300/30)
old: inter 2s 150/s sustained 150
this PR: inter 30s fastinter 10s + spread-checks 50 26,32,32,31,29,36,23,17,16,14 17
same, no spread-checks 21,30,30,30,... (30/s lockstep) 31
inter 30s fastinter 2s + spread-checks 50 122,127,50,1,0,0... 24

On whp01 (426 servers) that is roughly 50/s peak after a reload vs ~180/s with fastinter 2s, and ~14/s steady vs ~213/s today.

Failure detection (justification of rise/fall)

rise 2 fall 3 are the HAProxy defaults, written explicitly. Dead backend: first failing check <= 45 s after it dies (30 s +50% jitter), then 2 more at fastinter (~10 s, jittered up to 15 s): marked DOWN in ~50 s typical, <= ~75 s worst. Recovery to UP the same (downinter 30 s then one more at fastinter). Inside the 1-2 minutes Josh accepted. test-health-check-timing.py computes this bound from the numbers and fails if it exceeds 120 s.

Tests

  • New scripts/test-health-check-timing.py (6 tests, added to the Dockerfile test RUN chain): exactly one default-server in defaults, spread-checks 50 in global, detection bound, no per-server inter/fastinter/downinter in customer templates, Coraza SPOA keeps 2 s, server line rendering unchanged.
  • scripts/validate-rendered-config.py: the real haproxy -c gate now also asserts the default-server and spread-checks lines in every scenario (default, full, splash-off, nbthread-1, nbthread-bad): all 5 scenarios accepted by HAProxy 3.2.26-1~bpo13+1.
  • Also green in the image: test-nbthread-knob, test-default-splash, test-waf-body-inspection, test-trusted-proxy-gate, test-wpadmin-gate. (test-config-rollback.py fails identically on the unmodified 2026.11.6 image when run via docker exec here; unrelated, it passes in the build.)

Rollout (needs an image build + edge recreate; nothing ships until then)

  1. Review/merge, build and publish the haproxy-manager-base image (VERSION bump is left to the release step; currently 2026.11.8, which already carries HAPROXY_NBTHREAD).
  2. Combine with the WHP image-pin move to 2026.11.8+ (see whp docs/go-port/edge-nbthread.md, PR #389).
  3. Staged edge recreate, canary first, then fleet. The check settings take effect at the recreate (the config is regenerated by the new image) or at the next config regeneration; no in-place change on running edges.
  4. Verify on the canary after recreate: echo '@1 show stat' | socat stdio /tmp/haproxy-cli shows servers UP, grep -c default-server /etc/haproxy/haproxy.cfg = 1, and the TLS handshake rate to backends drops (whp01 is the one that matters).
  5. Reload note: after any reload every server re-runs 2 fast checks (10 s spacing, spread over ~10 s); expected, bounded, ~4x lighter than before.

🤖 Generated with Claude Code

https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6

## What Backend health checks move from HAProxy's default 2 s to 30 s, set once and jittered. `templates/hap_header.tpl` (rendered once per config; every backend template inherits it, no per-server change): ``` global spread-checks 50 defaults default-server inter 30s fastinter 10s downinter 30s rise 2 fall 3 ``` `templates/hap_coraza_spoa_backend.tpl`: the WAF agent keeps fast checks (`check inter 2s fastinter 2s downinter 2s rise 2 fall 3`), a single local server where detection speed matters and cost is nil. WHP still supplies `check ssl verify none` per server (panel/internal/haproxy/site.go); that is untouched (check type is NOT changed here, per Josh). ## Why (context: haproxy-nbthread / haproxy-watchdog-fleet notes, 2026-11-25) whp01 has ~426 `check ssl` servers at 2 s = ~200+ TLS handshakes/s of pure health-check churn, which together with memory pressure preceded the watchdog aborts. ## Why fastinter 10s, not 2s (deviation from the first suggestion, please review) Verified in the 3.2 source/docs (src/check.c `start_check_task`, `srv_getinter`; configuration.txt `inter`/`spread-checks`): - HAProxy spreads the FIRST check of every server over the smallest interval in use, and a server not yet at full health (every server after a start or reload) uses `fastinter`. So `fastinter 2s` puts all first checks of every reload into a ~2 s window. - `spread-checks N` only randomises each later interval by +/- N% (max 50); it does not change the start offsets. Without it a fixed 30 s period keeps whatever phase clusters formed at start. Measured with real haproxy 3.2.26 (image 2026.11.6 binary), 300 `check` servers, tcp-check sending a byte so the listener can count them, per-second connections to the backend: | config | first 10 s (per s) | steady 30-90 s max/s (avg 10 = 300/30) | |---|---|---| | old: inter 2s | 150/s sustained | 150 | | this PR: inter 30s fastinter 10s + spread-checks 50 | 26,32,32,31,29,36,23,17,16,14 | 17 | | same, no spread-checks | 21,30,30,30,... (30/s lockstep) | 31 | | inter 30s fastinter 2s + spread-checks 50 | **122,127,50**,1,0,0... | 24 | On whp01 (426 servers) that is roughly 50/s peak after a reload vs ~180/s with fastinter 2s, and ~14/s steady vs ~213/s today. ## Failure detection (justification of rise/fall) `rise 2 fall 3` are the HAProxy defaults, written explicitly. Dead backend: first failing check <= 45 s after it dies (30 s +50% jitter), then 2 more at fastinter (~10 s, jittered up to 15 s): marked DOWN in ~50 s typical, <= ~75 s worst. Recovery to UP the same (downinter 30 s then one more at fastinter). Inside the 1-2 minutes Josh accepted. `test-health-check-timing.py` computes this bound from the numbers and fails if it exceeds 120 s. ## Tests - New `scripts/test-health-check-timing.py` (6 tests, added to the Dockerfile test RUN chain): exactly one default-server in `defaults`, `spread-checks 50` in `global`, detection bound, no per-server inter/fastinter/downinter in customer templates, Coraza SPOA keeps 2 s, server line rendering unchanged. - `scripts/validate-rendered-config.py`: the real `haproxy -c` gate now also asserts the default-server and spread-checks lines in every scenario (default, full, splash-off, nbthread-1, nbthread-bad): all 5 scenarios accepted by HAProxy 3.2.26-1~bpo13+1. - Also green in the image: test-nbthread-knob, test-default-splash, test-waf-body-inspection, test-trusted-proxy-gate, test-wpadmin-gate. (`test-config-rollback.py` fails identically on the unmodified 2026.11.6 image when run via docker exec here; unrelated, it passes in the build.) ## Rollout (needs an image build + edge recreate; nothing ships until then) 1. Review/merge, build and publish the haproxy-manager-base image (VERSION bump is left to the release step; currently 2026.11.8, which already carries HAPROXY_NBTHREAD). 2. Combine with the WHP image-pin move to 2026.11.8+ (see whp docs/go-port/edge-nbthread.md, PR #389). 3. Staged edge recreate, canary first, then fleet. The check settings take effect at the recreate (the config is regenerated by the new image) or at the next config regeneration; no in-place change on running edges. 4. Verify on the canary after recreate: `echo '@1 show stat' | socat stdio /tmp/haproxy-cli` shows servers UP, `grep -c default-server /etc/haproxy/haproxy.cfg` = 1, and the TLS handshake rate to backends drops (whp01 is the one that matters). 5. Reload note: after any reload every server re-runs 2 fast checks (10 s spacing, spread over ~10 s); expected, bounded, ~4x lighter than before. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
jknapp added 1 commit 2026-11-25 14:44:30 +00:00
whp01 runs ~426 `check ssl` servers at the HAProxy default 2s interval:
~200+ TLS handshakes/s of pure health-check churn, which with memory
pressure preceded the 2026-11-25 watchdog aborts.

global:   spread-checks 50
defaults: default-server inter 30s fastinter 10s downinter 30s rise 2 fall 3

fastinter is 10s, not 2s: HAProxy spreads the first check of every server
over the smallest interval in use and a not-yet-fully-healthy server (every
server after a start/reload) uses fastinter, so 2s would put every reload's
first checks into a ~2s burst. Dead backend still marked down in <= ~65s.
The Coraza SPOA server keeps its own 2s checks. No change to the server
lines WHP supplies (check ssl verify none).

Tests: scripts/test-health-check-timing.py (in the image build) and
check-timing assertions in validate-rendered-config.py (real haproxy -c).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
jknapp added 1 commit 2026-11-25 15:02:20 +00:00
Author
Owner

Independent review (not the author).

All 17 image-build gate suites pass against this branch (run in the 2026.11.8 image with haproxy 3.2.26).

Verified:

  • Section order: global, resolvers, defaults (hap_header.tpl) are emitted first by generate_config(), every frontend/backend template is appended after, so default-server in defaults reaches every later backend. Only one defaults section exists.
  • No other server line carries inter/fastinter/downinter/fall/rise/observe/error-limit/agent-check (grepped templates, haproxy_manager.py, WHP Go/sh). Per-server options WHP stores are check / check ssl verify none. The default-page and letsencrypt servers have no check, so they are unaffected. option httpchk (hap_backend_http_check.tpl) only changes the check type, not timing. The Coraza SPOA server keeps inter 2s fastinter 2s downinter 2s (spop-check), as intended.
  • Config validity: ran validate-rendered-config.py (all scenarios, real haproxy -c) against HAProxy 3.2.26 in the 2026.11.8 image with this branch's templates: all accepted. test-health-check-timing.py 6/6 OK.
  • Single-backend sites: there is no failover target, so slower detection only delays the status flip (503 vs a slower 503/connection error); no backup/maintenance servers or error pages in the templates depend on check speed. The edge watchdog curls http://localhost/ (default splash) and the manager /health and Docker healthcheck probe :8000/:80; nothing reads backend state. Reload behaviour: servers start from the fastinter window (10s) then settle to 30s jittered.
  • Fix pushed (5ec7d9b): the comments claimed "<= ~65s" to mark DOWN but the test's own arithmetic (and the jitter) gives 45 + 2x15 = 75s worst case (~50s typical). Comment/docstring corrected; no behaviour change.

Publish behaviour (IMPORTANT): .gitea/workflows/build-push.yaml runs on push to main and publishes :latest, :<VERSION> and :<sha>. VERSION is still 2026.11.8, so a plain merge would overwrite the existing :2026.11.8 tag (the current rollback target) with new bytes. Hosts pin /etc/whp/edge-image by digest (--pull=never for pins, so no auto-deploy), but a host without a pin file pulls :latest on recreate. Merging with [skip ci] in the merge commit so nothing is published; the release is a separate step (VERSION bump, rc build from release/*, staged rollout).

**Independent review (not the author).** All 17 image-build gate suites pass against this branch (run in the 2026.11.8 image with haproxy 3.2.26). Verified: - Section order: `global`, `resolvers`, `defaults` (hap_header.tpl) are emitted first by `generate_config()`, every frontend/backend template is appended after, so `default-server` in `defaults` reaches every later backend. Only one `defaults` section exists. - No other `server` line carries `inter/fastinter/downinter/fall/rise/observe/error-limit/agent-check` (grepped templates, haproxy_manager.py, WHP Go/sh). Per-server options WHP stores are `check` / `check ssl verify none`. The default-page and letsencrypt servers have no `check`, so they are unaffected. `option httpchk` (hap_backend_http_check.tpl) only changes the check type, not timing. The Coraza SPOA server keeps `inter 2s fastinter 2s downinter 2s` (spop-check), as intended. - Config validity: ran `validate-rendered-config.py` (all scenarios, real `haproxy -c`) against HAProxy 3.2.26 in the 2026.11.8 image with this branch's templates: all accepted. `test-health-check-timing.py` 6/6 OK. - Single-backend sites: there is no failover target, so slower detection only delays the status flip (503 vs a slower 503/connection error); no backup/maintenance servers or error pages in the templates depend on check speed. The edge watchdog curls `http://localhost/` (default splash) and the manager `/health` and Docker healthcheck probe :8000/:80; nothing reads backend state. Reload behaviour: servers start from the fastinter window (10s) then settle to 30s jittered. - Fix pushed (5ec7d9b): the comments claimed "<= ~65s" to mark DOWN but the test's own arithmetic (and the jitter) gives 45 + 2x15 = 75s worst case (~50s typical). Comment/docstring corrected; no behaviour change. Publish behaviour (IMPORTANT): `.gitea/workflows/build-push.yaml` runs on push to `main` and publishes `:latest`, `:<VERSION>` and `:<sha>`. VERSION is still 2026.11.8, so a plain merge would overwrite the existing `:2026.11.8` tag (the current rollback target) with new bytes. Hosts pin `/etc/whp/edge-image` by digest (`--pull=never` for pins, so no auto-deploy), but a host without a pin file pulls `:latest` on recreate. Merging with `[skip ci]` in the merge commit so nothing is published; the release is a separate step (VERSION bump, rc build from release/*, staged rollout).
jknapp merged commit 24f4a5ebac into main 2026-11-25 15:04:34 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: cloud-hosting-platform/haproxy-manager-base#23