feat: put API replicas behind HAProxy
HAProxy 3.4 is the only published entry point; api runs as API_REPLICAS replicas without ports, found through Docker DNS and checked on /health/ready. Retries only on connection failure, LB errors in the contract error format, resource limits and per-service secrets. Adds scripts/stop-one.sh, LB-aware restart.sh, make replicas / instances / lb_stats and replica tests driven by EXPECT_REPLICAS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import json
|
||||
import re
|
||||
from collections.abc import Iterable
|
||||
from datetime import datetime, timedelta
|
||||
from functools import cache
|
||||
from pathlib import Path
|
||||
@@ -165,6 +166,20 @@ def assert_instance_id(resp: httpx.Response) -> str:
|
||||
return instance_id
|
||||
|
||||
|
||||
def assert_replicas(values: Iterable[str], expected: int) -> set[str]:
|
||||
"""Ответы дали не меньше двух разных `X-Instance-Id`; возвращает их.
|
||||
|
||||
`expected` — `EXPECT_REPLICAS`: сколько реплик ждали за `BASE_URL`.
|
||||
"""
|
||||
seen = set(values)
|
||||
assert len(seen) >= 2, (
|
||||
f"saw {len(seen)} X-Instance-Id {sorted(seen)} behind BASE_URL, "
|
||||
f"EXPECT_REPLICAS={expected}: no load balancing across replicas; "
|
||||
"against one API process run with EXPECT_REPLICAS=1"
|
||||
)
|
||||
return seen
|
||||
|
||||
|
||||
def json_body(resp: httpx.Response) -> Any:
|
||||
"""JSON-тело в UTF-8, непустые `X-Request-Id` и `X-Instance-Id`."""
|
||||
request_id = resp.headers.get("X-Request-Id", "")
|
||||
|
||||
Reference in New Issue
Block a user