Fixes for mandatory level 3: 1. Reduce nginx proxy_connect_timeout to 1s for faster failover detection - Prevents 499 errors during failover (client timeout < connect timeout) 2. Set executable permissions on scripts (git update-index --chmod=+x) - restart.sh, stop-one.sh now 100755 3. Fix REPORT.md errors: - Correct test command: make test-failover (not py -3 tests\failover.py) - Fix health check explanation (nginx uses timeouts, not Docker healthcheck) - Fix line numbers: INSTANCE_ID=39, X-Instance-Id=88, message()=321 - Add note about nginx warmup period (~10s after startup) Additions for level 4: 4. Add scripts/measure-failover.sh - measure RPS, errors, recovery time - Sequential testing of api-1 and api-2 stops - Baseline, failover, and recovery measurements 5. Add scripts/rolling-update.sh - demonstrate rolling update under load - Generates load for 60s while updating replicas sequentially - Measures errors during rolling update 6. Update REPORT.md with sections 10-11 for level 4 requirements All changes address reviewer feedback and ensure tests pass consistently. Co-Authored-By: Claude <noreply@anthropic.com>
62 lines
2.4 KiB
Nginx Configuration File
62 lines
2.4 KiB
Nginx Configuration File
upstream api_backend {
|
|
# Балансировка между несколькими API-репликами с активными проверками.
|
|
# max_fails и fail_timeout обеспечивают пассивную проверку здоровья.
|
|
server api-1:8080 max_fails=3 fail_timeout=10s;
|
|
server api-2:8080 max_fails=3 fail_timeout=10s;
|
|
|
|
# Параметры балансировки для лучшей отказоустойчивости.
|
|
keepalive 32;
|
|
}
|
|
|
|
server {
|
|
listen 8080;
|
|
server_name localhost;
|
|
|
|
# Таймауты для предотвращения зависаний.
|
|
# proxy_connect_timeout 1s — быстрое обнаружение отказа backend.
|
|
proxy_connect_timeout 1s;
|
|
proxy_send_timeout 60s;
|
|
proxy_read_timeout 60s;
|
|
|
|
# Передача заголовков клиента в backend.
|
|
proxy_set_header Host $http_host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
# Основной location для API.
|
|
location / {
|
|
proxy_pass http://api_backend;
|
|
proxy_set_header Host $http_host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
# Повторная попытка на другой реплике при ошибке.
|
|
proxy_next_upstream error timeout http_503 non_idempotent;
|
|
proxy_next_upstream_tries 2;
|
|
proxy_next_upstream_timeout 10s;
|
|
|
|
# Поддержка keepalive соединений.
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Connection "";
|
|
}
|
|
|
|
# Health check endpoint для Nginx.
|
|
location /health/live {
|
|
proxy_pass http://api_backend/health/live;
|
|
proxy_set_header Host $http_host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
location /health/ready {
|
|
proxy_pass http://api_backend/health/ready;
|
|
proxy_set_header Host $http_host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
}
|