chore: port lab 6 solution into the lab 7 skeleton

Source: mtusi2026lab6-safronov, solution/bvt2301-safronov, 6c6a065.
Files follow AGENTS.md, "Переход в следующую лабу". Contracts, public
tests, README, REPORT and evidence of lab 6 are not carried over; infra
and scripts of the lab 7 skeleton stay as they are.
Makefile is the lab 6 one with the lab 7 skeleton part restored
(HTTPS BASE_URL on 8443, test-security); .gitignore and .dockerignore
are taken from lab 6 because both skeletons have the same files;
.env.example is the lab 6 one without changes.
The compose project, image and CI prefix are renamed to lab7, and
references to the previous lab now name lab6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 03:59:04 +03:00
co-authored by Claude Opus 5.5
parent 20afc2c790
commit 089d78609d
687 changed files with 178271 additions and 40 deletions
@@ -0,0 +1,52 @@
# MessengerNoReadyReplicas
Правило — `infra/otel/prometheus/rules.yml`, группа `messenger-alerts`; решения — design change
`slo-alerts`, решения 2, 4. `severity: critical`.
## Что значит и на что влияет
LB не видит ни одной реплики API, прошедшей проверку готовности (`/health/ready`), 30 секунд
подряд. Все запросы клиентов получают 503 от самого LB (формат ошибки контракта, без
`X-Instance-Id`). Срабатывает и без трафика. Все реплики сразу выходят из LB почти всегда из-за
PostgreSQL: `/health/ready` проверяет только его.
## Первые панели
1. «Load balancer» → «Ready replicas in LB», «5xx on LB and 5xx of API per second».
2. «SLO and alerts» → «Alert states» — `MessengerHighErrorRate` при трафике рядом.
## Диагностика (только по сохранённым наблюдениям)
```promql
max(haproxy_backend_active_servers{job="haproxy",proxy="api"})
sum by (code) (rate(haproxy_frontend_http_responses_total{job="haproxy",proxy="entry"}[2m]))
sum(rate(http_server_request_duration_seconds_count{job="messenger-api"}[2m]))
up{job="haproxy"}
```
- **PostgreSQL недоступен.** Готовых реплик 0, ответы LB — 5xx, запросов в метриках API почти нет
(реплики живы, но вне LB). Loki: `{service_name="messenger-api"} |= "Database is unavailable"` —
записи реплик в начале отказа; Tempo: `{ resource.service.name = "messenger-api" && status = error
&& span.db.system.name = "postgresql" }`. Состояние: `docker compose ps postgres`.
- **Реплики остановлены или падают.** Метрик реплик нет (`up` есть, а рядов
`http_server_request_duration_seconds_count` с их `instance` больше нет), `docker compose ps api`
— `exited` или `restarting`; журнал — `docker compose logs --no-log-prefix api`.
- **Ряд пропал совсем** — недоступен сам LB или Collector: тогда это оповещение молчит, а
срабатывает `TelemetryTargetDown` (`job="haproxy"` или `otel-collector`).
## Действия
- PostgreSQL: `docker compose start postgres` (или `make start_db`); реплики вернутся в LB сами за
≤ 1,5 с после готовности.
- Реплики: `make replicas`.
- `make lb_stats` — слоты `UP`.
## Восстановление
Оповещение снимается на первом вычислении после возврата реплики (≤ 30 с). Проверить: готовых
реплик `API_REPLICAS`, `make test` — `PASS`.
## Связанные оповещения
`MessengerHighErrorRate` (при трафике — те же 503 LB), `MessengerQueueMetricsMissing` (relay тоже не
читает PostgreSQL), `TelemetryTargetDown{job="haproxy"}`.