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:
@@ -12,6 +12,11 @@ from api_client import Actor, Api
|
||||
from spec_coverage import COLLECTED, Collected
|
||||
|
||||
BASE_URL = os.environ.get("BASE_URL", "http://localhost:8080").rstrip("/")
|
||||
# сколько реплик API за BASE_URL: стенд с LB — API_REPLICAS (make
|
||||
# student_test), один процесс — 1 (make test_isolated, драйвер в консоли).
|
||||
# Режим задаётся явно, а не угадывается по ответам: иначе сломанный LB
|
||||
# давал бы пропуск вместо падения
|
||||
EXPECT_REPLICAS = int(os.environ.get("EXPECT_REPLICAS", "2"))
|
||||
# hook стенда отказов и «тесный» API задаёт make failure_checks
|
||||
FAULT_HOOK = os.environ.get("FAULT_HOOK", "")
|
||||
FAULT_TIGHT_BASE_URL = os.environ.get("FAULT_TIGHT_BASE_URL", "").rstrip("/")
|
||||
@@ -79,6 +84,26 @@ def base_url() -> str:
|
||||
return BASE_URL
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def expect_replicas() -> int:
|
||||
return EXPECT_REPLICAS
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def replicas() -> int:
|
||||
"""Тест реплик: нужны ≥ 2 реплики за балансировщиком.
|
||||
|
||||
Против одного процесса тест пропускается с причиной, а не считается
|
||||
пройденным.
|
||||
"""
|
||||
if EXPECT_REPLICAS < 2:
|
||||
pytest.skip(
|
||||
f"one API process (EXPECT_REPLICAS={EXPECT_REPLICAS}): "
|
||||
"replica checks need the stand with the load balancer",
|
||||
)
|
||||
return EXPECT_REPLICAS
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def api() -> Iterator[Api]:
|
||||
with Api(BASE_URL) as client:
|
||||
|
||||
Reference in New Issue
Block a user