тесты и healthcheck устойчивее к медленному хосту: время пробы внутри контейнера, healthcheck timeout 5 с, дочитывание TLS-ответа, grace уборщика 15 с

This commit is contained in:
Alexey Bodanyuk
2026-11-28 16:22:52 +03:00
parent c5c9b5c9ab
commit 783aa35456
5 changed files with 77 additions and 21 deletions
+17 -8
View File
@@ -456,12 +456,21 @@ def attachment_row(attachment_id: str) -> dict | None:
return json.loads(out) if out else None
def probe_inside(replica: dict, path: str) -> int:
"""HTTP status of `path` asked inside the replica container itself (bypassing the LB) - lab 7: on
the loopback health listener (127.0.0.1:8081), the mTLS port needs the LB's client certificate."""
code = ("import urllib.request as u, urllib.error as e\n"
"try: print(u.urlopen('http://127.0.0.1:8081%s', timeout=3).status)\n"
"except e.HTTPError as x: print(x.code)") % path
def probe_inside_timed(replica: dict, path: str) -> tuple[int, float]:
"""(HTTP status, seconds) of `path` asked inside the replica container itself (bypassing the LB) -
lab 7: on the loopback health listener (127.0.0.1:8081), the mTLS port needs the LB's client
certificate. The time is measured INSIDE the container around the request only: `docker exec`
and the Python start-up (seconds on a loaded Windows host) are the test tool's cost, not the
replica's responsiveness."""
code = ("import time, urllib.request as u, urllib.error as e\n"
"t = time.perf_counter()\n"
"try: s = u.urlopen('http://127.0.0.1:8081%s', timeout=5).status\n"
"except e.HTTPError as x: s = x.code\n"
"print(s, round(time.perf_counter() - t, 3))") % path
out = subprocess.run(["docker", "exec", replica["id"], "python", "-c", code], capture_output=True, text=True,
timeout=30).stdout.strip()
return int(out or 0)
timeout=60).stdout.split()
return (int(out[0]), float(out[1])) if len(out) == 2 else (0, 99.0)
def probe_inside(replica: dict, path: str) -> int:
return probe_inside_timed(replica, path)[0]