ЛР3: балансировка HAProxy, 2 реплики API, идемпотентность, отказоустойчивость (на 4)
- X-Instance-Id в каждом ответе; обязательный Idempotency-Key, таблица idempotency_keys (миграция 0002, одна транзакция, конкурентные повторы через уникальный индекс) - graceful shutdown: SIGTERM -> ready=503 -> drain 3 с -> закрытие порта - compose: lb (HAProxy) + api x2 без портов + разовый migrate + postgres, лимиты CPU/RAM - хуки stop-one/restart/restore-replicas, scripts/experiments.py (failover, idempotency, rolling) - свои тесты: 44 (13 новых); evidence: smoke, pytest, persistence, failover, эксперименты
This commit is contained in:
+35
-11
@@ -1,13 +1,37 @@
|
||||
# Copy to .env for your LOCAL synthetic test environment; never commit .env.
|
||||
# These are logical interface suggestions; map actual framework names in REPORT.md.
|
||||
APP_HOST=0.0.0.0
|
||||
APP_PORT=8080
|
||||
APP_ENV=lab
|
||||
SESSION_TTL_SECONDS=3600
|
||||
# Choose credentials locally. File paths contain no secret values.
|
||||
DATABASE_URL_FILE=/run/secrets/database_url
|
||||
# Optional on 3, required use on 4 in lab2; Redis OR Valkey:
|
||||
SESSION_STORE=postgres
|
||||
CACHE_URL_FILE=/run/secrets/cache_url
|
||||
# Names follow pydantic-settings: prefix APP_CONFIG__, nesting via "__" (see app/core/config.py).
|
||||
# Mapping to the skeleton's logical names: APP_HOST -> APP_CONFIG__RUN__HOST, APP_PORT -> APP_CONFIG__RUN__PORT,
|
||||
# DATABASE_URL_FILE -> APP_CONFIG__DB__* (host/port/name/user + password file),
|
||||
# SESSION_TTL_SECONDS -> APP_CONFIG__JWT__SESSION_TTL_SECONDS, SESSION_STORE=postgres (sessions table),
|
||||
# IDEMPOTENCY_TTL_SECONDS -> APP_CONFIG__IDEMPOTENCY__TTL_SECONDS, API_REPLICAS -> API_REPLICAS (compose.yaml).
|
||||
APP_CONFIG__RUN__HOST=0.0.0.0
|
||||
APP_CONFIG__RUN__PORT=8080
|
||||
APP_CONFIG__LOGGING__LEVEL=INFO
|
||||
|
||||
# PostgreSQL. Values below are for running the API from the venv on the host;
|
||||
# inside Compose the defaults (host=postgres, /run/secrets/postgres_password) are used.
|
||||
APP_CONFIG__DB__HOST=127.0.0.1
|
||||
APP_CONFIG__DB__PORT=5432
|
||||
APP_CONFIG__DB__NAME=messenger
|
||||
APP_CONFIG__DB__USER=messenger
|
||||
# Path only, never the password itself. Relative paths are resolved from the project root.
|
||||
APP_CONFIG__DB__PASSWORD_FILE=secrets/postgres_password
|
||||
|
||||
# Sessions: JWT signed with a key from a secret file + server-side session row in PostgreSQL
|
||||
# (shared by all API replicas, so no sticky sessions are needed).
|
||||
APP_CONFIG__JWT__SECRET_FILE=secrets/jwt_secret
|
||||
APP_CONFIG__JWT__SESSION_TTL_SECONDS=3600
|
||||
|
||||
# Idempotency-Key: a repeat within this window returns the original message (contract: 24 h).
|
||||
APP_CONFIG__IDEMPOTENCY__TTL_SECONDS=86400
|
||||
|
||||
# Graceful shutdown: after SIGTERM /health/ready answers 503 for DRAIN seconds, then the port closes
|
||||
# and in-flight requests get GRACEFUL seconds. DRAIN must exceed the LB detection time (fall*inter + check timeout = 2.5 s).
|
||||
APP_CONFIG__RUN__DRAIN_SECONDS=3
|
||||
APP_CONFIG__RUN__GRACEFUL_TIMEOUT=5
|
||||
|
||||
# Used by compose.yaml.
|
||||
# Host port for PostgreSQL (bound to 127.0.0.1 only); API replicas publish no ports at all.
|
||||
POSTGRES_HOST_PORT=5432
|
||||
# Number of API replicas behind the load balancer.
|
||||
API_REPLICAS=2
|
||||
IDEMPOTENCY_TTL_SECONDS=86400
|
||||
|
||||
Reference in New Issue
Block a user