Compare commits

..
Author SHA1 Message Date
shadowdaoandClaude Sonnet 5.5 b6911fb63f release: 2026.11.9 (health check timing #23, HAPROXY_NBTHREAD)
HAProxy Manager Build and Push / Build-and-Push (push) Successful in 22m34s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
2026-11-25 08:01:31 -08:00
jknappandClaude Sonnet 5.5 24f4a5ebac Merge pull request 'edge: backend health checks every 30s, staggered' (#23) from feat/health-check-interval into main [skip ci]
Merged without publishing: the image release (VERSION bump, rc build, staged rollout) is a separate approved step.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
2026-11-25 15:04:33 +00:00
Claude 5ec7d9b6d3 edge: correct the dead-backend detection bound in comments (~75s worst case, matches the test's own arithmetic)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
2026-11-25 07:02:16 -08:00
shadowdaoandClaude Sonnet 5.5 06e5ad0ce7 edge: back-end health checks every 30s, staggered (default-server + spread-checks 50)
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
2026-11-25 06:41:41 -08:00
jknapp 2774399add Merge pull request 'arm64 base guard + HAPROXY_NBTHREAD per-host thread knob (2026.11.8)' (#22) from fix/multiarch-arm64-base-guard into main
HAProxy Manager Build and Push / Build-and-Push (push) Failing after 32m30s
2026-11-20 04:45:55 +00:00
7 changed files with 152 additions and 2 deletions

No files matched your search

+1
View File
@@ -16,6 +16,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
- **Multi-arch index assembly (coraza-spoa)**: `python3 scripts/test-assemble-multiarch-index.py` - offline (NOT run in the image build; it also reads `.gitea/workflows/build-push-coraza.yaml`); `scripts/assemble-multiarch-index.sh` turns the by-digest amd64 + arm64 pushes into the tag(s): arm64 is attached only if THIS run's arm64 step outcome is `success` (failure => amd64-only tag, never a stale arm64), a bad amd64 digest publishes nothing. `scripts/e2e-coraza-multiarch.sh` rehearses the whole thing against throwaway local registries (see coraza-spoa/README.md "Multi-arch"). - **Multi-arch index assembly (coraza-spoa)**: `python3 scripts/test-assemble-multiarch-index.py` - offline (NOT run in the image build; it also reads `.gitea/workflows/build-push-coraza.yaml`); `scripts/assemble-multiarch-index.sh` turns the by-digest amd64 + arm64 pushes into the tag(s): arm64 is attached only if THIS run's arm64 step outcome is `success` (failure => amd64-only tag, never a stale arm64), a bad amd64 digest publishes nothing. `scripts/e2e-coraza-multiarch.sh` rehearses the whole thing against throwaway local registries (see coraza-spoa/README.md "Multi-arch").
- **Publish verify gate**: `python3 scripts/test-verify-published-tags.py` - offline (needs `jq`; NOT run in the image build); `scripts/verify-published-tags.sh` is the last build-push.yaml step: every tag in every registry must resolve, carry the assembled platforms, and share ONE index digest. The digest is the sha256 of `imagetools inspect --raw` cross-checked against the text `Digest:` line / bare `--format` output (buildx 0.28 ignores `--format` and prints full text; CI run 5381). - **Publish verify gate**: `python3 scripts/test-verify-published-tags.py` - offline (needs `jq`; NOT run in the image build); `scripts/verify-published-tags.sh` is the last build-push.yaml step: every tag in every registry must resolve, carry the assembled platforms, and share ONE index digest. The digest is the sha256 of `imagetools inspect --raw` cross-checked against the text `Digest:` line / bare `--format` output (buildx 0.28 ignores `--format` and prints full text; CI run 5381).
- **Per-host thread count knob**: `python3 scripts/test-nbthread-knob.py` - runs in the image build; `HAPROXY_NBTHREAD` (container env, 1-64; invalid/unset = ignored) renders `nbthread N` in `global` ONLY when set, so every other host's config is byte-identical. Real `haproxy -c` of `nbthread 1` is the `nbthread-1` scenario in `scripts/validate-rendered-config.py`. WHP side: `/etc/whp/edge-nbthread` -> `lib-edge-container.sh` -> `docker run -e` at recreate. - **Per-host thread count knob**: `python3 scripts/test-nbthread-knob.py` - runs in the image build; `HAPROXY_NBTHREAD` (container env, 1-64; invalid/unset = ignored) renders `nbthread N` in `global` ONLY when set, so every other host's config is byte-identical. Real `haproxy -c` of `nbthread 1` is the `nbthread-1` scenario in `scripts/validate-rendered-config.py`. WHP side: `/etc/whp/edge-nbthread` -> `lib-edge-container.sh` -> `docker run -e` at recreate.
- **Health-check timing**: `python3 scripts/test-health-check-timing.py` - runs in the image build; one `default-server inter 30s fastinter 10s downinter 30s rise 2 fall 3` in `defaults` + `spread-checks 50` in `global` (hap_header.tpl), never per server line; the Coraza SPOA server keeps `inter 2s`. Pins that a dead backend is still detected in <= 2 min and that `fastinter` (which sizes the post-reload start-up stagger window) stays >= 5s. Real `haproxy -c` coverage: the `check-timing`/`spread-checks` assertions in `scripts/validate-rendered-config.py`.
- **Default splash**: `python3 scripts/test-default-splash.py` - offline (runs in the image build); unrouted hosts (server hostname, bare IP, unknown names) are answered by `http-request return ... file /haproxy/errors/default-splash.html` BEFORE the Coraza SPOE call, never for a routed host (`routed_hosts.list`/`routed_wildcards.list`, written by `generate_config()` from the routing rows and in the rollback set), never for ACME/blocked/suspended. Run it after touching the splash block, the routing ACL templates, or the domain loops in `generate_config()`. See README "Default Splash". - **Default splash**: `python3 scripts/test-default-splash.py` - offline (runs in the image build); unrouted hosts (server hostname, bare IP, unknown names) are answered by `http-request return ... file /haproxy/errors/default-splash.html` BEFORE the Coraza SPOE call, never for a routed host (`routed_hosts.list`/`routed_wildcards.list`, written by `generate_config()` from the routing rows and in the rollback set), never for ACME/blocked/suspended. Run it after touching the splash block, the routing ACL templates, or the domain loops in `generate_config()`. See README "Default Splash".
- **gunicorn access logging**: `python3 scripts/test-gunicorn-access-logging.py` - real gunicorn; :8080 has no access log, :8000 access goes to `/var/log/haproxy/api-access.log` (rotated by `scripts/gunicorn-access-rotate.py`), nothing per-request on stdout (journald rate-limit/Graylog flood), gunicorn errors stay on stderr. See docs/logging.md. Run after touching start-up.sh's gunicorn lines. - **gunicorn access logging**: `python3 scripts/test-gunicorn-access-logging.py` - real gunicorn; :8080 has no access log, :8000 access goes to `/var/log/haproxy/api-access.log` (rotated by `scripts/gunicorn-access-rotate.py`), nothing per-request on stdout (journald rate-limit/Graylog flood), gunicorn errors stay on stderr. See docs/logging.md. Run after touching start-up.sh's gunicorn lines.
- **Access log receiver**: `python3 scripts/test-access-log-receiver.py` - offline (runs in the image build); one datagram = one line (PRI stripped, control chars neutralised), size cap + gzip generations, write errors drop without raising, real UNIX-socket path. Run it after touching `haproxy-log-receiver.py` or the `log` line in `hap_header.tpl`. - **Access log receiver**: `python3 scripts/test-access-log-receiver.py` - offline (runs in the image build); one datagram = one line (PRI stripped, control chars neutralised), size cap + gzip generations, write errors drop without raising, real UNIX-socket path. Run it after touching `haproxy-log-receiver.py` or the `log` line in `hap_header.tpl`.
+1
View File
@@ -163,6 +163,7 @@ RUN python3 /haproxy/scripts/test-wpadmin-gate.py \
&& python3 /haproxy/scripts/test-xmlrpc-rate-limit.py \ && python3 /haproxy/scripts/test-xmlrpc-rate-limit.py \
&& python3 /haproxy/scripts/test-default-splash.py \ && python3 /haproxy/scripts/test-default-splash.py \
&& python3 /haproxy/scripts/test-nbthread-knob.py \ && python3 /haproxy/scripts/test-nbthread-knob.py \
&& python3 /haproxy/scripts/test-health-check-timing.py \
&& python3 /haproxy/scripts/test-access-log-receiver.py \ && python3 /haproxy/scripts/test-access-log-receiver.py \
&& python3 /haproxy/scripts/test-haproxy-stderr-relay.py \ && python3 /haproxy/scripts/test-haproxy-stderr-relay.py \
&& python3 /haproxy/scripts/test-haproxy-supervisor.py \ && python3 /haproxy/scripts/test-haproxy-supervisor.py \
+1 -1
View File
@@ -1 +1 @@
2026.11.8 2026.11.9
+110
View File
@@ -0,0 +1,110 @@
#!/usr/bin/env python3
"""Backend health-check timing: one `default-server` line, jittered, pinned.
WHP appends `check ssl verify none` to every backend server, and each check is
a full TLS handshake. On a host with ~426 checked servers the HAProxy default
(inter 2s) is ~200+ handshakes/s of health-check churn, which together with
memory pressure preceded the 2026-11-25 watchdog aborts. So the interval is
30s, set ONCE in `defaults` (never per server line), and the checks are
desynchronised with the global `spread-checks`.
What this pins (the real `haproxy -c` of the same config is the
`check-timing` assertions in scripts/validate-rendered-config.py):
* exactly one default-server line, in `defaults`, with the agreed timing;
* `spread-checks 50` in `global` (documented max, 0..50);
* the agreed timing detects a dead backend in <= ~75 s worst case (inside the 1-2
minutes Josh accepted) -- computed from the numbers, so changing one of
them without re-justifying the other fails here;
* no template puts inter/fastinter/downinter on a customer server line
(that would bypass the one knob), and the Coraza SPOA server keeps its
own fast timing.
python3 scripts/test-health-check-timing.py
"""
import os
import re
import sys
import unittest
MODULE_DIR = os.path.abspath(
os.environ.get('HAPROXY_MANAGER_DIR',
os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')))
sys.path.insert(0, MODULE_DIR)
import haproxy_manager as hm # noqa: E402
WANT = 'default-server inter 30s fastinter 10s downinter 30s rise 2 fall 3'
def header(**kw):
return hm.template_env.get_template('hap_header.tpl').render(
cluster_secret='s', syslog_target='/log.sock',
coraza_spoe_backend=kw.pop('coraza_spoe_backend', None), **kw)
def code(text):
return '\n'.join(l for l in text.splitlines() if not l.lstrip().startswith('#'))
def section(out, name):
m = re.search(r'^%s\b.*?(?=^\S|\Z)' % name, code(out), re.M | re.S)
assert m, name
return m.group(0)
class Timing(unittest.TestCase):
def test_one_default_server_in_defaults(self):
for kw in ({}, {'coraza_spoe_backend': '127.0.0.1:9000'}, {'nbthread': 1}):
out = header(**kw)
lines = re.findall(r'^\s*default-server\s.*$', code(out), re.M)
self.assertEqual(len(lines), 1, kw)
self.assertEqual(' '.join(lines[0].split()), WANT)
self.assertIn('default-server', section(out, 'defaults'))
self.assertNotIn('default-server', section(out, 'global'))
def test_spread_checks_in_global_at_documented_max(self):
out = header()
self.assertEqual(re.findall(r'^\s*spread-checks\s+(\d+)\s*$', section(out, 'global'), re.M),
['50'])
self.assertEqual(code(out).count('spread-checks'), 1)
def test_dead_backend_detected_within_two_minutes(self):
m = re.search(r'inter (\d+)s fastinter (\d+)s downinter (\d+)s rise (\d+) fall (\d+)', WANT)
inter, fast, down, rise, fall = map(int, m.groups())
jitter = 1.5 # spread-checks 50: each wait is up to +50%
# first failing check <= inter*1.5 after death, then fall-1 more at fastinter
mark_down = inter * jitter + (fall - 1) * fast * jitter
mark_up = down * jitter + (rise - 1) * fast * jitter
self.assertLessEqual(mark_down, 120)
self.assertLessEqual(mark_up, 120)
# start-up stagger window is the smallest interval in use (fastinter):
# 2s would recreate a whole-edge burst on every reload
self.assertGreaterEqual(fast, 5)
def test_no_per_server_timing_in_customer_templates(self):
tdir = os.path.join(MODULE_DIR, 'templates')
for name in sorted(os.listdir(tdir)):
if not name.endswith('.tpl') or name == 'hap_coraza_spoa_backend.tpl':
continue
with open(os.path.join(tdir, name)) as fh:
body = code(fh.read())
for line in body.splitlines():
if line.strip().startswith('server '):
self.assertNotRegex(line, r'\b(inter|fastinter|downinter)\b', name)
def test_coraza_spoa_keeps_fast_checks(self):
src = hm.template_env.get_template('hap_coraza_spoa_backend.tpl').render(agent_target='127.0.0.1:9000')
line = [l for l in code(src).splitlines() if l.strip().startswith('server coraza-spoa')]
self.assertEqual(len(line), 1)
for token in ('check', 'inter 2s', 'fastinter 2s', 'downinter 2s'):
self.assertIn(token, line[0])
def test_server_line_rendering_unchanged(self):
# the per-server options still come straight from WHP, untouched
out = hm.template_env.get_template('hap_backend.tpl').render(
name='x', servers=[{'server_name': 's', 'server_address': 'a',
'server_port': 443, 'server_options': 'check ssl verify none'}])
self.assertIn('server s a:443 check ssl verify none resolvers docker_dns init-addr last,libc,none', out)
if __name__ == '__main__':
unittest.main(verbosity=2)
+4
View File
@@ -355,6 +355,10 @@ def assert_scenario_branches(scenario_name, config_path, env_overrides):
env_overrides.get('HAPROXY_DEFAULT_SPLASH') != 'off'), env_overrides.get('HAPROXY_DEFAULT_SPLASH') != 'off'),
'nbthread': ('\n nbthread 1\n', 'nbthread': ('\n nbthread 1\n',
env_overrides.get('HAPROXY_NBTHREAD') == '1'), env_overrides.get('HAPROXY_NBTHREAD') == '1'),
# Health-check timing is unconditional: every scenario carries it.
'check-timing': ('\n default-server inter 30s fastinter 10s '
'downinter 30s rise 2 fall 3\n', True),
'spread-checks': ('\n spread-checks 50\n', True),
} }
for label, (needle, should_be_present) in expected.items(): for label, (needle, should_be_present) in expected.items():
present = needle in text present = needle in text
+1 -1
View File
@@ -13,4 +13,4 @@ backend coraza-spoa-backend
option spop-check option spop-check
timeout connect 5s timeout connect 5s
timeout server 30s timeout server 30s
server coraza-spoa {{ agent_target }} check server coraza-spoa {{ agent_target }} check inter 2s fastinter 2s downinter 2s rise 2 fall 3
+34
View File
@@ -54,6 +54,17 @@ global
nbthread {{ nbthread }} nbthread {{ nbthread }}
{%- endif %} {%- endif %}
# Health-check jitter. Every `check` interval (default-server below) is
# randomised by +/- 50% so the hundreds of checks on a big edge drift
# apart instead of re-forming one burst per interval. The start-up offsets
# alone do NOT do this: HAProxy spreads the FIRST check of every server
# over the smallest interval in use, and a server that has not yet
# reached full health (every server after a start or reload) counts as
# `fastinter`, so the whole fleet starts inside a few seconds and would
# stay in lockstep with a fixed 30s period. 50 is the documented
# maximum (configuration.txt "spread-checks": 0..50 percent, default 0).
spread-checks 50
# SSL and Performance # SSL and Performance
tune.ssl.default-dh-param 2048 tune.ssl.default-dh-param 2048
@@ -183,6 +194,29 @@ defaults
timeout server 10m timeout server 10m
timeout http-keep-alive 30s timeout http-keep-alive 30s
timeout check 10s timeout check 10s
# Backend health checks, set ONCE here for every `server ... check` line
# (WHP appends `check ssl verify none` per server; each check is a full
# TLS handshake, so on whp01 -- ~426 checked servers -- the old 2s default
# was ~200+ handshakes/s of pure health-check churn).
# inter 30s steady state: one check per server per ~30s (jittered
# 15-45s by `spread-checks` in global).
# fastinter 10s used while a server is transitioning (going down/up)
# AND for a server not yet at full health, i.e. every
# server after a start/reload. It also sizes the
# start-up stagger window (HAProxy spreads first checks
# over the smallest interval in use), so it is 10s, not
# 2s: 2s would put all first checks of a reload into a
# ~2s burst, the very churn this removes.
# downinter 30s a server already fully DOWN is re-tested at the same
# low rate.
# rise 2 fall 3 the HAProxy defaults, stated so they are pinned.
# A dead backend is marked DOWN in at most ~75s (first failing check
# <= 45s after it dies, then two more at fastinter, each <= 15s with the
# +50% jitter; ~50s typical); a recovered one is back UP in about the
# same (downinter <= 45s, then one more at fastinter). Servers without `check` are unaffected.
# The Coraza SPOA server sets its own fast timing (hap_coraza_spoa_backend.tpl).
default-server inter 30s fastinter 10s downinter 30s rise 2 fall 3
timeout tarpit 10s # Tarpit delay for low-level scanners (before silent-drop) timeout tarpit 10s # Tarpit delay for low-level scanners (before silent-drop)
maxconn 3000 maxconn 3000