forked from mtusi2026/mtusi2026lab3
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d235255cf3 | ||
|
|
d7d1bbaff8 | ||
|
|
a0ca0af168 | ||
|
|
029bf9b377 |
+7
-20
@@ -1,20 +1,7 @@
|
|||||||
.git
|
*
|
||||||
.github
|
!pyproject.toml
|
||||||
.env
|
!uv.lock
|
||||||
.env.*
|
!src/
|
||||||
!.env.example
|
!src/**
|
||||||
secrets
|
!migrations/
|
||||||
certs
|
!migrations/**
|
||||||
volumes
|
|
||||||
data
|
|
||||||
backups
|
|
||||||
*.key
|
|
||||||
*.pem
|
|
||||||
*.p12
|
|
||||||
*.pfx
|
|
||||||
*.jks
|
|
||||||
.venv
|
|
||||||
__pycache__
|
|
||||||
node_modules
|
|
||||||
evidence
|
|
||||||
.DS_Store
|
|
||||||
|
|||||||
+11
-11
@@ -1,13 +1,13 @@
|
|||||||
# Copy to .env for your LOCAL synthetic test environment; never commit .env.
|
# Local synthetic Docker Compose configuration. make bootstrap creates .env
|
||||||
# These are logical interface suggestions; map actual framework names in REPORT.md.
|
# and private secrets once; never commit generated .env or secrets/.
|
||||||
APP_HOST=0.0.0.0
|
PUBLIC_PORT=8083
|
||||||
APP_PORT=8080
|
|
||||||
APP_ENV=lab
|
|
||||||
SESSION_TTL_SECONDS=3600
|
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
|
|
||||||
API_REPLICAS=2
|
API_REPLICAS=2
|
||||||
IDEMPOTENCY_TTL_SECONDS=86400
|
API_CPUS=0.5
|
||||||
|
API_MEMORY=256m
|
||||||
|
POOL_MAX_SIZE=8
|
||||||
|
PG_CPUS=1
|
||||||
|
PG_MEMORY=768m
|
||||||
|
# API_IMAGE defaults to mtusi-vasilev:lab3; set it for an already built rolling image.
|
||||||
|
# DATABASE_URL_FILE and CACHE_URL_FILE are fixed to /run/secrets/... in compose.yaml.
|
||||||
|
# Runtime binds 0.0.0.0:8080. Cache TTL60s and idempotency TTL24h are fixed policy.
|
||||||
|
|||||||
@@ -30,3 +30,5 @@ coverage/
|
|||||||
.vscode/
|
.vscode/
|
||||||
# Keep small, sanitized evidence summaries in evidence/ under version control.
|
# Keep small, sanitized evidence summaries in evidence/ under version control.
|
||||||
# Inspect git diff --cached: ignore rules are not a secret scanner.
|
# Inspect git diff --cached: ignore rules are not a secret scanner.
|
||||||
|
.pytest_cache/
|
||||||
|
.ruff_cache/
|
||||||
|
|||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
FROM python:3.12-slim@sha256:646fb0bca3dd3ea1bcc6feb72c17ed16eed6e10cffc732fcc1478bd3e7f02d7b AS build
|
||||||
|
COPY --from=ghcr.io/astral-sh/uv:0.11.7 /uv /usr/local/bin/uv
|
||||||
|
WORKDIR /app
|
||||||
|
COPY pyproject.toml uv.lock ./
|
||||||
|
RUN uv sync --locked --no-dev --no-install-project --python /usr/local/bin/python
|
||||||
|
|
||||||
|
FROM python:3.12-slim@sha256:646fb0bca3dd3ea1bcc6feb72c17ed16eed6e10cffc732fcc1478bd3e7f02d7b
|
||||||
|
ARG VCS_REF=uncommitted
|
||||||
|
LABEL org.opencontainers.image.revision=$VCS_REF
|
||||||
|
ENV PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=/app/src PATH=/app/.venv/bin:$PATH
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=build /app/.venv /app/.venv
|
||||||
|
COPY src ./src
|
||||||
|
COPY migrations ./migrations
|
||||||
|
USER 10001:10001
|
||||||
|
EXPOSE 8080
|
||||||
|
HEALTHCHECK --interval=3s --timeout=2s --start-period=5s --retries=5 CMD ["python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=1)"]
|
||||||
|
CMD ["python", "-m", "messenger"]
|
||||||
@@ -28,3 +28,27 @@ test-persistence:
|
|||||||
test-failover:
|
test-failover:
|
||||||
@test -n "$(ACTION_SCRIPT)" || (echo "Set ACTION_SCRIPT to your implemented executable stop-one hook"; exit 2)
|
@test -n "$(ACTION_SCRIPT)" || (echo "Set ACTION_SCRIPT to your implemented executable stop-one hook"; exit 2)
|
||||||
$(PYTHON) tests/resilience.py --mode failover --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS)
|
$(PYTHON) tests/resilience.py --mode failover --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||||||
|
|
||||||
|
# Student commands; original teacher targets above remain unchanged.
|
||||||
|
PUBLIC_PORT ?= 8083
|
||||||
|
BASE_URL = http://127.0.0.1:$(PUBLIC_PORT)
|
||||||
|
|
||||||
|
bootstrap:
|
||||||
|
python3 scripts/bootstrap.py
|
||||||
|
|
||||||
|
up: bootstrap
|
||||||
|
VCS_REF=$$(git rev-parse HEAD) docker compose up -d --build --wait
|
||||||
|
|
||||||
|
down:
|
||||||
|
docker compose down
|
||||||
|
|
||||||
|
migrate:
|
||||||
|
docker compose run --rm migrate
|
||||||
|
|
||||||
|
lint:
|
||||||
|
uv run --locked ruff check src student-tests research
|
||||||
|
|
||||||
|
student-test test-student:
|
||||||
|
BASE_URL=$(BASE_URL) uv run --locked pytest -q
|
||||||
|
|
||||||
|
.PHONY: bootstrap up down migrate lint student-test test-student
|
||||||
|
|||||||
@@ -1,37 +1,146 @@
|
|||||||
# Отчёт — лабораторная 3
|
# ЛР3: балансировка и отказ API-реплики
|
||||||
|
|
||||||
- Автор, группа: TODO
|
**Васильев Никита · БВТ2301 · цель:5 · трек1 «Цена масштабирования».**
|
||||||
- Целевая оценка; выбранный трек 5, если нужен: TODO
|
|
||||||
- Commit/PR: TODO после публикации
|
|
||||||
- Использованные источники, библиотеки и помощь ИИ: TODO
|
|
||||||
|
|
||||||
## Запуск из чистого clone
|
Реализация продолжает собственную ЛР2, адаптированную к исходному skeleton ЛР3. Контракты, публичные tests, README, COURSE и CONTRIBUTING не изменялись. Код и анализ подготовлены с помощью AI-ассистента; доказательства получены настоящими локальными запусками, а не из чужих PR. Публикация не выполнялась.
|
||||||
|
|
||||||
TODO: версии runtime/образов, prerequisites, команды создания локальных secrets/.env, build, миграций, запуска, ожидания готовности, тестов и остановки. Указать необходимые действия оператора. Не вставлять секреты. Отдельно указать безопасную остановку и команду намеренного удаления учебных данных.
|
## Воспроизводимый запуск
|
||||||
|
|
||||||
## Архитектура и решения
|
Нужны Docker с Compose и Python3.9+ для публичных скриптов. Для собственных тестов — uv и Python3.12.
|
||||||
|
|
||||||
TODO: схема процессов/хранилищ, источник истины, транзакционные границы, ограничения. Что перенесено из lab2, что изменено в этой работе. Соответствие переменных из .env.example реальной конфигурации.
|
```sh
|
||||||
|
make up
|
||||||
|
make check
|
||||||
|
make test
|
||||||
|
uv sync --locked --python 3.12
|
||||||
|
make validate PYTHON=.venv/bin/python
|
||||||
|
make lint
|
||||||
|
make student-test
|
||||||
|
```
|
||||||
|
|
||||||
## Доказательства критериев
|
`make up` создаёт локальные secrets/.env только при отсутствии, собирает образ, запускает PostgreSQL/Valkey, отдельную миграцию, две API и HAProxy. Единственная публикация — `127.0.0.1:8083`. API внутри слушают0.0.0.0:8080 и наружу порт не публикуют. `.env.example` описывает фактические параметры Compose.
|
||||||
|
|
||||||
| Критерий README | Команда/сценарий | Наблюдаемый результат | Файл доказательства |
|
Ручная сборка: `VCS_REF=$(git rev-parse HEAD) docker compose build`. Запуск: `docker compose up -d --wait`. Остановка с сохранением данных: `make down`. Не применяйте `down --volumes` для обычной остановки.
|
||||||
| --- | --- | --- | --- |
|
|
||||||
| Публичный smoke | make test | TODO | TODO |
|
|
||||||
| Остальные пункты уровня 3 | TODO | TODO | TODO |
|
|
||||||
| Все пункты уровня 4, если заявлен | TODO | TODO | TODO |
|
|
||||||
| Выбранный трек 5, если заявлен | TODO | TODO | TODO |
|
|
||||||
|
|
||||||
TODO: добавить отдельную строку для каждого заявленного критерия. PASS без команды и наблюдения не является доказательством. Проверка инфраструктурного hook требует подтверждения, какие реальные процессы/хранилища перезапущены.
|
## Архитектура и ресурсы
|
||||||
|
|
||||||
## Эксперименты и отказы
|
```text
|
||||||
|
Клиент → HAProxy → API ×2 → PostgreSQL
|
||||||
|
↘ Valkey: карточки пользователей TTL60s
|
||||||
|
```
|
||||||
|
|
||||||
TODO: гипотеза, hardware/лимиты, версии, объём данных, профиль нагрузки, concurrency/arrival rate, длительность/прогрев, повторы, успешные RPS, ошибки, p50/p95/p99, CPU/RAM. Сохранить raw summary без tokens и объяснить ограничения измерения.
|
Все API используют одну БД и сессии PostgreSQL. Sticky sessions нет. `X-Instance-Id` — случайный UUID, постоянный на время жизни процесса. `X-Request-Id` добавляется ко всем созданным API ответам, включая ошибки.
|
||||||
|
|
||||||
| Воздействие | Что ожидаем | Что наблюдали | Время восстановления / потеря данных |
|
Штатные ограничения:
|
||||||
| --- | --- | --- | --- |
|
|
||||||
| TODO | TODO | TODO | TODO |
|
|
||||||
|
|
||||||
## Ограничения и следующие шаги
|
|Сервис|CPU|RAM|
|
||||||
|
|---|---:|---:|
|
||||||
|
|Каждая API,2шт.|0.5|256MiB|
|
||||||
|
|PostgreSQL|1|768MiB|
|
||||||
|
|Valkey|0.5|128MiB|
|
||||||
|
|HAProxy|0.5|128MiB|
|
||||||
|
|migrate,однократный|0.5|256MiB|
|
||||||
|
|
||||||
TODO: какие отказы выдерживаются и какие нет; что не реализовано; где учебное упрощение; какое улучшение подтверждено, а какое пока гипотеза.
|
Нет container_name; один Compose-service API масштабируется. LB находится в frontend-сети, PostgreSQL/Valkey в backend, API в обеих. Хранилище PostgreSQL — именованный volume. API без root, read-only, cap_dropALL, no-new-privileges, tmpfs16MiB, pids96. Секреты передаются файлами, не входят в Git и Docker context.
|
||||||
|
|
||||||
|
Python3.12, зависимости закреплены uv.lock; базовый Python-образ и HAProxy закреплены digest. PostgreSQL17.10 и Valkey8.1.3 закреплены версиями. Базовый образ и runtime-пакеты унаследованы из проверенной собственной ЛР2. Дополнительные aiohttp и matplotlib нужны только исследовательским инструментам, в runtime image не устанавливаются.
|
||||||
|
|
||||||
|
## Идемпотентность
|
||||||
|
|
||||||
|
Для отправки сообщения обязателен ASCII Idempotency-Key длиной1..128. Область — пользователь, POST, чат и ключ. Под одной транзакцией выполняются ACL, advisory lock, поиск результата, вставка сообщения и сохранение исходного201-ответа. TTL24h. Разный валидный body с тем же ключом —409. Отсутствующий attachment_ids и[] эквивалентны. Неуспешные5xx не фиксируются как результат.
|
||||||
|
|
||||||
|
Повтор заново проверяет сессию и доступ. Одновременные запросы через разные API возвращают одно сообщение. Сбой до COMMIT откатывает сообщение вместе с ключом; после COMMIT клиент повторяет тот же ключ. LB не повторяет POST автоматически, включая создание чатов и пользователей.
|
||||||
|
|
||||||
|
Подробности структуры, bytea для losslessUnicode U+0000 и транзакционных границ — [SCHEMA.md](SCHEMA.md).
|
||||||
|
|
||||||
|
## Readiness, DNS и остановка
|
||||||
|
|
||||||
|
HAProxy server-template разрешает до8 API через DockerDNS127.0.0.11, обновляет адреса без фиксированных IP. Roundrobin, активная проверка `/health/ready`, inter1s, timeoutcheck1s, fall2, rise2. Оценка обнаружения устойчивого отказа — примерно до3s без учёта аномалий планировщика; фактические переходы измерены отдельно. Fallback без readiness нет.
|
||||||
|
|
||||||
|
Readiness выполняет дешёвую проверку обязательных таблиц и полей БД, а не только проверки процесса. Liveness отвечает независимо от БД. Если одна API теряет backend-сеть, она остаётся живой, но readiness503 исключает её из LB.
|
||||||
|
|
||||||
|
ConnecttimeoutLB1s, server8s, client10s, queuetimeout2s, transparent retries0. Uvicorn grace5s, Compose stop8s. ПулБД до8 соединений/API, очередь32, ожидание2s, подключение2s, SQL2.5s, lock1.5s. Дополнительный client-side I/Odeadline3s закрывает зависшее соединение, даже если PostgreSQL paused и серверный statement_timeout не исполняется. Эти бюджеты не складываются в обещание единогоHTTP SLA.
|
||||||
|
|
||||||
|
## Проверки уровней3–4
|
||||||
|
|
||||||
|
- [Публичный контракт и схема](evidence/contract-validation.txt):PASS.
|
||||||
|
- [Собственные тесты](evidence/tests-final.txt):124PASS, включая26HTTP-проверокJSONкодировкибезпобочныхзаписей,11unit-регрессий форматаcursor,10HTTP-регрессийcursorнаобоихмаршрутах,20конкурентных повторов через≥2API, bodyconflict, scopes, NUL, Unicode, malformedUTF8, Basicbody, cursor и заголовки.
|
||||||
|
- [JSONUTF-8](evidence/json-encoding.txt):8вариантовUTF-16/32/BOM/LE/BEна3маршрутахотклонены400беззаписи; validUTF-8иUTF-8BOM,UnicodeиescapedNULприняты.
|
||||||
|
- [Независимые HTTP-регрессии](evidence/independent-http.json):61PASS.
|
||||||
|
- [Независимые отказы](evidence/independent-faults.json):4PASS — ACLдоreplay, исчезновение обязательной таблицы, pausedPG с503примерно3.08s и восстановлением, logout под блокировкой с последующим отзывом.
|
||||||
|
- [LB без готовых API](evidence/lb-no-ready-api.json):503JSON, новыйX-Request-Idсовпадаетсerror.request_id, фиктивногоX-Instance-Idнет; прежняя сессия работает после восстановления.
|
||||||
|
- [КороткийTTL](evidence/independent-expiry.json):проверен отдельной API, рабочая конфигурация TTL3600не менялась.
|
||||||
|
- [Публичный persistence](evidence/persistence.txt):прежний токен и подтверждённые данные сохранились.
|
||||||
|
- [Публичный failover](evidence/failover-first.txt):123успешных записи,3неуспешных попытки, первое восстановление1.429s.
|
||||||
|
- [Отказ каждой реальной реплики](evidence/replica-failures.json):два отдельных прогона1419и1472успешных записей;83и62переходные ошибки соответственно. **Все подтверждённые записи каждого прогона найдены**, потерь нет. Target сопоставлен с настоящим containerID и оставлен остановленным; перед следующей проверкой предыдущий восстановлен.
|
||||||
|
- [Изоляция неготовой API](evidence/readiness-isolation.json):после потери backend-сети directready503;30/30последующих запросов черезLBуспешны и обслужены только другой API. После reconnect снова видны две.
|
||||||
|
- [Поочерёдная замена](evidence/rolling-update.json):3558успешных записей,257переходных ошибок, все подтверждённые сообщения сохранены. Обе API последовательно заменены, containerIDs и imageIDs изменились.
|
||||||
|
|
||||||
|
Команды проверки:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
make test-persistence ACTION_SCRIPT=scripts/restart.sh
|
||||||
|
make test-failover ACTION_SCRIPT=scripts/stop-one.sh
|
||||||
|
# Восстановить остановленную реплику перед следующими проверками:
|
||||||
|
docker compose up -d --no-recreate --wait
|
||||||
|
uv run --locked python scripts/verify_replicas.py
|
||||||
|
uv run --locked python scripts/verify_readiness.py
|
||||||
|
uv run --locked python scripts/verify_rolling.py
|
||||||
|
uv run --locked python scripts/verify_lb_unavailable.py
|
||||||
|
# Дополнительные независимые проверки, адаптированные для запуска из репозитория:
|
||||||
|
uv run --locked python scripts/verify_teacher_http.py --lab 3 --repo . --base-url http://127.0.0.1:8083 --output evidence/teacher-http-repeat.json
|
||||||
|
uv run --locked python scripts/verify_teacher_faults.py --output evidence/teacher-faults-repeat.json
|
||||||
|
```
|
||||||
|
|
||||||
|
Проверки отказов запускаются последовательно, не одновременно с нагрузочным исследованием. restart-hook сохраняет безопасные snapshots StartedAt/ID до и после, чтобы доказать перезапуск API,LB,PGиValkey. Все shellhooks executable100755. Cursorпринимает только собственный каноническийформатYYYY-MM-DDTHH:MM:SS(.1..6digits)?Z, с календарной проверкой и целойверсией1; PythonISO-расширения не доходят доSQL.
|
||||||
|
|
||||||
|
Rolling-target отличается revision-label, функциональный код и схема одинаковы. Этот опыт доказывает поочерёдную замену образа и процессов под трафиком, но не совместимость произвольного нового кода/схемы. Первоначальная миграция003с textнаbytea требует maintenancewindow со старой ЛР2; ограничения не скрываются.
|
||||||
|
|
||||||
|
## Исследование на5
|
||||||
|
|
||||||
|
Методика, параметры и ограничения — [research/README.md](research/README.md). Основной файл [scaling-final.json](evidence/scaling-final.json), итоговая [таблица](evidence/scaling-final-summary.md), [график](evidence/scaling-final.svg).
|
||||||
|
|
||||||
|
**Гипотеза:** рост API перестанет помогать при насыщении общей БД. Если активно ограничивает CPUquotaPostgreSQL, её увеличение при остальных неизменных ресурсах повысит успешный throughput.
|
||||||
|
|
||||||
|
Сравниваются фиксированный суммарный бюджет API1CPU/1024MiB для1/2/4реплик и растущий бюджет по0.5CPU/256MiB на реплику. PostgreSQL специально ограничена0.25CPU/768MiB в основной матрице. Контрольное улучшение:4APIпо0.5CPU/256MiB, только CPUБДувеличен0.25→0.5. Штатный стенд имеет другую квотуБД1CPU.
|
||||||
|
|
||||||
|
Предлагаемая нагрузка100/400/900уникальных POST/s,3повтора×6s,7конфигураций —63прогона. Генератор open-loop aiohttp, in-flightcap128; отдельно учитываются scheduled, attempts, successful201, errors и dropped. Процентили только успешных запросов; RPSпо реальному времени вместе с завершением начатых запросов. Actual CPU/RAM проверяются dockerinspect, samplesdockerstats сохраняются; CPUиRAM API сначала суммируются на каждомtimestamp.
|
||||||
|
|
||||||
|
Основная матрица: **114780 успешных HTTP-ответов,0 HTTP-ошибок,61620 неотправленных слотов** из176400запланированных. Все dropped связаны с in-flightcap128; scheduler-drops0. Максимальная загрузка процесса генератора —31.54% одногоhostCPU. Успешность отправленных запросов не означает выполнение всех предложенных слотов.
|
||||||
|
|
||||||
|
Медианы при900offeredPOST/s, по3повтора:
|
||||||
|
|
||||||
|
|Серия|API1|API2|API4|
|
||||||
|
|---|---:|---:|---:|
|
||||||
|
|Fixed-total1CPU/1024MiB, successfulRPS|391.81|363.47|378.74|
|
||||||
|
|Growth0.5CPU/256MiBнаAPI, successfulRPS|163.01|384.98|442.33|
|
||||||
|
|
||||||
|
При фиксированной сумме ресурсов увеличение числа процессов не дало выигрыша throughput. На900offered peak summed memoryAPIвfixedсерии составила96.91/159.57/304.92MiB для1/2/4процессов: у реплик есть собственные расходы.
|
||||||
|
|
||||||
|
В growthсерии переход2→4APIдал только≈14.9% throughput при удвоении APIресурсов. Дляgrowth4на900offered медианаCPUБД25.05%приquota25%,API107.08%приобщемbudget200%,LBоколо5%CPU: общая ограниченная PostgreSQL стала активным узким местом.
|
||||||
|
|
||||||
|
Контроль изменил **только CPUPostgreSQL0.25→0.5**, RAMБД768MiB и4APIпо0.5CPU/256MiB сохранены и проверены inspect:
|
||||||
|
|
||||||
|
|Метрика,900offered/s|PG0.25CPU|PG0.5CPU|
|
||||||
|
|---|---:|---:|
|
||||||
|
|МедианаsuccessfulRPS|442.33|881.06|
|
||||||
|
|Медианаp95успешных,ms|621.58|223.69|
|
||||||
|
|Droppedслотов,3повтора|8147|298|
|
||||||
|
|МедианаDBCPU%|25.05|42.86|
|
||||||
|
|МедианаAPI CPU%,сумма|107.08|179.65|
|
||||||
|
|
||||||
|
Подтверждённое улучшение:≈99.2%успешногоthroughput и≈64.0%сниженияp95вэтомопыте. После него [обратный контроль](evidence/scaling-reversal.json) вернулPG0.25CPU:411.104/471.464/465.411RPS,медиана465.411. Возврат производительности к исходному диапазону поддерживает причинное объяснение через квотуБД, хотя короткая серия и прогрев/checkpointоставляют шум.
|
||||||
|
|
||||||
|
881RPSне объявляется новым пределом: это близко к предложенным900/s, а CPUAPIподошёл к своему бюджету. Для установления следующего ограничения понадобился бы отдельный более высокий профиль. Мы доказали границу специально ограниченной0.25CPUБД, а не общий максимум PostgreSQL.
|
||||||
|
|
||||||
|
[Ресурсные графики](evidence/scaling-final-resources.svg) показывают CPUБД, CPUгенератора и droppedslots. Калибровочныеpilotфайлы сохранены отдельно и в63основных прогона не входят; обратный контроль —ещё3отдельныхпрогона.
|
||||||
|
|
||||||
|
Runtimeисследования соответствует commit029bf9b, sourceSHA256записаны в JSON. Форматирование runnerбез изменения поведения отражено в [manifest](evidence/research-runner-manifest.json). После измерений добавлены JSON503для случая отсутствия готовых backend и строгая валидация некорректногоcursor (ISOweek/basic/не-T,True/1.0вместоцелойверсии). Измеренный профиль отправки сообщений cursorне использует; прежняя конфигурация сохранена в [haproxy-benchmark.cfg](evidence/haproxy-benchmark.cfg). После повторного review также добавлен строгий UTF-8 encodingguard на обычном POSTпути users/chats/messages: UTF-16/32 и literalNULотклоняются до записи, escapedJSON\u0000 и UTF-8/BOM сохраняются. Binaryattachments этим guardне затрагиваются. Числа исследования относятся к зафиксированному snapshot029bf9bдо этого guard; его накладные расходы в исходной матрице не измерялись. Последующие исправления корректности не заявляются как измеренное улучшениеthroughput, rawданные не переписывались.
|
||||||
|
|
||||||
|
После опыта штатные2API и PostgreSQL1CPUвосстановлены. Копии результатов не содержат токенов и секретов.
|
||||||
|
|
||||||
|
## Ограничения и подготовка к защите
|
||||||
|
|
||||||
|
Один DockerDesktophost, один LB, одна PostgreSQL и её volume остаются точками отказа. Переживание отказа узла или потери диска не заявляется. Короткие синтетические прогоны не равны промышленному SLA; после неопределённой сетевой ошибки POST повторяется с исходным ключом. Retention старых idempotency-записей не выполняется фоновым GC: срок учитывается при replay, просроченный ключ удаляется при его повторном использовании; неиспользуемые просроченные строки потребуют эксплуатационной очистки.
|
||||||
|
|
||||||
|
Сначала на защите показать≥2разныхX-Instance-Id с одним токеном, затем конкурентный replay, остановку конкретного контейнера, сохранность прежних сообщений и таблицу/график исследования. [REVIEW_NOTES.md](REVIEW_NOTES.md) связывает учтённые ошибки с замечаниями преподавателя.
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
# Замечания преподавателя, учтённые до реализации
|
||||||
|
|
||||||
|
Проверены публичные замечания в чужих PR. Они используются как перечень регрессий; код и результаты чужих решений не заимствовались. Отсутствие комментариев само по себе не доказывает соответствие заданию.
|
||||||
|
|
||||||
|
| Источник | Что учтено |
|
||||||
|
|---|---|
|
||||||
|
| [PR2#233](https://gitea.privcloud.tech/mtusi2026/mtusi2026lab3/pulls/2#issuecomment-233) | Сообщение и результат идемпотентности в одной транзакции; корректный Unicode-пароль; обязательные заголовки |
|
||||||
|
| [PR4#236](https://gitea.privcloud.tech/mtusi2026/mtusi2026lab3/pulls/4#issuecomment-236) | Отсутствующий attachment_ids эквивалентен []; CPU/RAM у LB и migrate; успешный RPS отдельно от попыток |
|
||||||
|
| [PR8#354](https://gitea.privcloud.tech/mtusi2026/mtusi2026lab3/pulls/8#issuecomment-354) | Пустой cursor даёт 400 |
|
||||||
|
| [PR7#358](https://gitea.privcloud.tech/mtusi2026/mtusi2026lab3/pulls/7#issuecomment-358) | Неверный Bearer и UTF-8 JSON дают контрактную ошибку; readiness действительно управляет LB |
|
||||||
|
| [PR12#408](https://gitea.privcloud.tech/mtusi2026/mtusi2026lab3/pulls/12#issuecomment-408) | Нет прозрачного повтора неидемпотентных POST; ресурсы суммируются по репликам, фактические квоты сохраняются |
|
||||||
|
| [PR24#538](https://gitea.privcloud.tech/mtusi2026/mtusi2026lab3/pulls/24#issuecomment-538) | Basic login отклоняет тело; максимум 100 участников |
|
||||||
|
| [PR23#534](https://gitea.privcloud.tech/mtusi2026/mtusi2026lab3/pulls/23#issuecomment-534) | Logout не подтверждается при неудачном удалении; доступ проверяется перед replay |
|
||||||
|
|
||||||
|
Также в общих регрессиях проверены потеря доступа только одной API, зависшая PostgreSQL, отсутствие обязательной таблицы, Unicode U+0000 и область ключа по пользователю/чату. Подробные результаты находятся в evidence, автоматические HTTP-регрессии — student-tests.
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
# Схема и транзакционные границы ЛР3
|
||||||
|
|
||||||
|
Основные таблицы: users, chats, members, messages, sessions. PostgreSQL — источник истины. Valkey содержит только публичные карточки пользователей TTL60s, не историю и не сессии.
|
||||||
|
|
||||||
|
## Схема
|
||||||
|
|
||||||
|
- users: UUID PK, username UNIQUE, display_name UTF-8 bytea, password_hash Argon2id, created_at timestamptz.
|
||||||
|
- chats: UUID PK, title UTF-8 bytea, created_at.
|
||||||
|
- members: PK(chat_id,user_id), FK к users/chats, UNIQUE(chat_id,position).
|
||||||
|
- messages: UUID PK, chat_id, sender_id, text UTF-8 bytea, created_at; составной FK(chat_id,sender_id) к members.
|
||||||
|
- sessions: token_digest PK, user_id FK, expires_at; случайный token256bit хранится у клиента, только SHA256digest в БД.
|
||||||
|
- message_requests: PK(actor_id,chat_id,key), body_digest, response bytea, expires_at. HTTP-метод и маршрут фиксированы единственным поддерживаемым POST сообщения; область дополнительно включает actor и chat.
|
||||||
|
- schema_migrations: имя и SHA256 SQL-файла, контроль изменённых применённых миграций.
|
||||||
|
|
||||||
|
Индексы: messages(chat_id,created_at,id), members(user_id,chat_id), sessions(expires_at), message_requests(expires_at), автоматически созданные PK/UNIQUE.
|
||||||
|
|
||||||
|
## Unicode
|
||||||
|
|
||||||
|
PostgreSQL text не принимает U+0000. Контракт не разрешает терять или заменять этот символ. Поэтому display_name/title/message.text и сериализованный replay-ответ хранятся как UTF-8 bytes. API проверяет длину в Unicode code points, БД дополнительно ограничивает octet_length. Чтение lossless декодирует UTF-8. Username ограничен ASCII и остаётся text.
|
||||||
|
|
||||||
|
## Идемпотентность
|
||||||
|
|
||||||
|
Одна транзакция: текущий ACL → advisory lock на hash(actor,POST,chat,key) → действительный replay либо конфликт body → INSERT message → INSERT сохранённого ответа → COMMIT. Ключ живёт 24 часа. Сбой до COMMIT отменяет оба эффекта. После COMMIT повтор возвращает тот же Message и201. 5xx не сохраняется как результат. Старый ключ, сессия и ACL проверяются заново. Канонический digest учитывает text и attachment_ids=[]; отсутствие массива и пустой массив эквивалентны.
|
||||||
|
|
||||||
|
64-битная advisory hash-коллизия может только лишний раз сериализовать два разных запроса: чтение результата всё равно использует полный PK, поэтому не смешивает ответы.
|
||||||
|
|
||||||
|
## Миграции и обновление
|
||||||
|
|
||||||
|
Мигратор запускается отдельным service, берёт advisory transaction lock; API запускается после успеха. Повтор не дублирует объекты. Миграция003 меняет типы наbytea и **не совместима со старым runtime ЛР2**: первоначальный переход требует остановки старой версии. Проверенный rolling update заменяет реплики с одной и той же схемой. Автоматическую безопасную миграцию произвольных будущих схем мы не заявляем.
|
||||||
|
|
||||||
|
Транзакция создания чата включает всех участников. Неизвестный участник откатывает весь чат. UNIQUE username разрешает гонку регистрации в самой БД.
|
||||||
|
|
||||||
|
## Отказы и ограничения
|
||||||
|
|
||||||
|
Client-side wait deadline3s на закреплённой psycopg3.3.6 закрывает зависшее соединение. Пул1..8, очередь32, timeout2s; connect2s, SQL2.5s, lock1.5s. Это отдельные бюджеты, не единыйHTTPdeadline. При неопределённом POST клиент повторяет исходный Idempotency-Key.
|
||||||
|
|
||||||
|
Readiness проверяет доступность всех обязательных таблиц/полей; liveness — только жизнь процесса. API не имеют опубликованных портов. LB имеет доступ к frontend, PostgreSQL/Valkey — к backend, API — к обеим сетям. Один LB, одна PostgreSQL, storage и один host остаются SPOF.
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
name: mtusi-vasilev-lab3
|
||||||
|
x-application: &application
|
||||||
|
networks: [backend]
|
||||||
|
image: ${API_IMAGE:-mtusi-vasilev:lab3}
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
args:
|
||||||
|
VCS_REF: ${VCS_REF:-uncommitted}
|
||||||
|
environment:
|
||||||
|
DATABASE_URL_FILE: /run/secrets/database_url
|
||||||
|
CACHE_URL_FILE: /run/secrets/cache_url
|
||||||
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
||||||
|
POOL_MAX_SIZE: ${POOL_MAX_SIZE:-8}
|
||||||
|
secrets: [database_url, cache_url]
|
||||||
|
cpus: ${API_CPUS:-0.5}
|
||||||
|
mem_limit: ${API_MEMORY:-256m}
|
||||||
|
pids_limit: 96
|
||||||
|
read_only: true
|
||||||
|
tmpfs: ["/tmp:size=16m,noexec,nosuid"]
|
||||||
|
cap_drop: [ALL]
|
||||||
|
security_opt: [no-new-privileges:true]
|
||||||
|
stop_grace_period: 8s
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
networks: [backend]
|
||||||
|
image: postgres:17.10-alpine
|
||||||
|
environment:
|
||||||
|
POSTGRES_USER: messenger
|
||||||
|
POSTGRES_DB: messenger
|
||||||
|
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
||||||
|
secrets: [postgres_password]
|
||||||
|
volumes: [postgres_data:/var/lib/postgresql/data]
|
||||||
|
healthcheck:
|
||||||
|
test: [CMD-SHELL, "pg_isready -U messenger -d messenger"]
|
||||||
|
interval: 2s
|
||||||
|
timeout: 2s
|
||||||
|
retries: 15
|
||||||
|
cpus: ${PG_CPUS:-1}
|
||||||
|
mem_limit: ${PG_MEMORY:-768m}
|
||||||
|
command: [postgres, -c, fsync=on, -c, synchronous_commit=on, -c, full_page_writes=on]
|
||||||
|
cache:
|
||||||
|
networks: [backend]
|
||||||
|
image: valkey/valkey:8.1.3-alpine
|
||||||
|
command: [valkey-server, --save, "", --appendonly, "no", --maxmemory, 64mb, --maxmemory-policy, allkeys-lru]
|
||||||
|
healthcheck:
|
||||||
|
test: [CMD, valkey-cli, ping]
|
||||||
|
interval: 2s
|
||||||
|
timeout: 2s
|
||||||
|
retries: 15
|
||||||
|
cpus: 0.5
|
||||||
|
mem_limit: 128m
|
||||||
|
migrate:
|
||||||
|
<<: *application
|
||||||
|
command: [python, -m, messenger.migrate]
|
||||||
|
healthcheck:
|
||||||
|
disable: true
|
||||||
|
depends_on:
|
||||||
|
postgres: {condition: service_healthy}
|
||||||
|
api:
|
||||||
|
<<: *application
|
||||||
|
networks: [frontend, backend]
|
||||||
|
deploy:
|
||||||
|
replicas: ${API_REPLICAS:-2}
|
||||||
|
depends_on:
|
||||||
|
migrate: {condition: service_completed_successfully}
|
||||||
|
cache: {condition: service_healthy}
|
||||||
|
lb:
|
||||||
|
networks: [frontend]
|
||||||
|
image: haproxy:3.2-alpine@sha256:96ec3c75a9264ba94e733eeacb44051ed6e7b79bb77a73c2c36f236b6423f1f0
|
||||||
|
ports: ["127.0.0.1:${PUBLIC_PORT:-8083}:8080"]
|
||||||
|
volumes: ["./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro"]
|
||||||
|
depends_on:
|
||||||
|
api: {condition: service_healthy}
|
||||||
|
cpus: 0.5
|
||||||
|
mem_limit: 128m
|
||||||
|
read_only: true
|
||||||
|
tmpfs: ["/tmp:size=8m"]
|
||||||
|
cap_drop: [ALL]
|
||||||
|
security_opt: [no-new-privileges:true]
|
||||||
|
healthcheck:
|
||||||
|
test: [CMD-SHELL, "wget -q -O /dev/null http://127.0.0.1:8080/health/ready"]
|
||||||
|
interval: 2s
|
||||||
|
timeout: 2s
|
||||||
|
retries: 10
|
||||||
|
volumes:
|
||||||
|
postgres_data:
|
||||||
|
secrets:
|
||||||
|
postgres_password: {file: ./secrets/postgres_password}
|
||||||
|
database_url: {file: ./secrets/database_url}
|
||||||
|
cache_url: {file: ./secrets/cache_url}
|
||||||
|
|
||||||
|
networks:
|
||||||
|
frontend:
|
||||||
|
backend:
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
.venv/bin/python scripts/check_contract.py
|
||||||
|
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
|
||||||
|
.venv/bin/python scripts/validate_openapi.py
|
||||||
|
PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested.
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
........... [100%]
|
||||||
|
11 passed in 0.01s
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "http://127.0.0.1:8083"
|
||||||
|
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||||||
|
{"observed_instances_before": 2, "successful_writes": 123, "failed_attempts": 3, "first_recovery_seconds": 1.429}
|
||||||
|
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
global
|
||||||
|
log stdout format raw local0
|
||||||
|
maxconn 256
|
||||||
|
stats socket /tmp/haproxy.sock mode 600 level admin
|
||||||
|
|
||||||
|
defaults
|
||||||
|
mode http
|
||||||
|
log global
|
||||||
|
timeout connect 1s
|
||||||
|
timeout client 10s
|
||||||
|
timeout server 8s
|
||||||
|
timeout check 1s
|
||||||
|
timeout queue 2s
|
||||||
|
retries 0
|
||||||
|
option httplog
|
||||||
|
|
||||||
|
resolvers docker
|
||||||
|
nameserver dns 127.0.0.11:53
|
||||||
|
resolve_retries 3
|
||||||
|
timeout resolve 1s
|
||||||
|
timeout retry 1s
|
||||||
|
hold valid 1s
|
||||||
|
hold obsolete 1s
|
||||||
|
hold nx 1s
|
||||||
|
|
||||||
|
frontend public
|
||||||
|
bind :8080
|
||||||
|
default_backend apis
|
||||||
|
|
||||||
|
backend apis
|
||||||
|
balance roundrobin
|
||||||
|
option httpchk GET /health/ready
|
||||||
|
http-check expect status 200
|
||||||
|
default-server inter 1s fastinter 500ms downinter 1s fall 2 rise 2
|
||||||
|
server-template api 1-8 api:8080 check resolvers docker resolve-prefer ipv4 init-addr libc,none
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"lab": 3,
|
||||||
|
"status": "PASS",
|
||||||
|
"configured_ttl_s": 2,
|
||||||
|
"valid_before_restart": 200,
|
||||||
|
"same_token_after_restart_and_expiry": 401,
|
||||||
|
"elapsed_after_login_s": 2.3318688750150613,
|
||||||
|
"main_api_reconfigured": false
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
{
|
||||||
|
"tests": [
|
||||||
|
{
|
||||||
|
"case": "ACL precedes both replay and conflict",
|
||||||
|
"status": "PASS",
|
||||||
|
"detail": {
|
||||||
|
"same_body": 404,
|
||||||
|
"changed_body": 404
|
||||||
|
},
|
||||||
|
"elapsed_s": 0.09069112502038479
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "readiness detects missing mandatory table",
|
||||||
|
"status": "PASS",
|
||||||
|
"detail": [
|
||||||
|
{
|
||||||
|
"status": 503,
|
||||||
|
"elapsed_s": 0.08109846600564197,
|
||||||
|
"request_id": "b73d5368-2568-442a-b749-076a81e635b7",
|
||||||
|
"instance_id": "b5916273-3714-494a-9de5-dda6dc88b2e5",
|
||||||
|
"body": {
|
||||||
|
"error": {
|
||||||
|
"code": "unavailable",
|
||||||
|
"message": "Хранилище недоступно",
|
||||||
|
"request_id": "b73d5368-2568-442a-b749-076a81e635b7"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"status": 503,
|
||||||
|
"elapsed_s": 0.007741153007373214,
|
||||||
|
"request_id": "502d1bfd-7338-4a02-b11f-da70d96a6aaf",
|
||||||
|
"instance_id": "01e8e3d3-878e-4af2-9fdd-5c0085dbeb7f",
|
||||||
|
"body": {
|
||||||
|
"error": {
|
||||||
|
"code": "unavailable",
|
||||||
|
"message": "Хранилище недоступно",
|
||||||
|
"request_id": "502d1bfd-7338-4a02-b11f-da70d96a6aaf"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"elapsed_s": 0.8006304160226136
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "paused PostgreSQL bounded API error and recovery",
|
||||||
|
"status": "PASS",
|
||||||
|
"detail": {
|
||||||
|
"during_pause": [
|
||||||
|
{
|
||||||
|
"status": 503,
|
||||||
|
"elapsed_s": 3.084492939990014,
|
||||||
|
"request_id": "75c8f628-2e6b-48fd-8996-272a52a0f9cc",
|
||||||
|
"instance_id": "b5916273-3714-494a-9de5-dda6dc88b2e5",
|
||||||
|
"body": {
|
||||||
|
"error": {
|
||||||
|
"code": "unavailable",
|
||||||
|
"message": "Хранилище недоступно",
|
||||||
|
"request_id": "75c8f628-2e6b-48fd-8996-272a52a0f9cc"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"status": 503,
|
||||||
|
"elapsed_s": 3.083705213968642,
|
||||||
|
"request_id": "1f41f669-e5a7-4cb5-b4f4-5681f22edd55",
|
||||||
|
"instance_id": "b5916273-3714-494a-9de5-dda6dc88b2e5",
|
||||||
|
"body": {
|
||||||
|
"error": {
|
||||||
|
"code": "unavailable",
|
||||||
|
"message": "Хранилище временно недоступно",
|
||||||
|
"request_id": "1f41f669-e5a7-4cb5-b4f4-5681f22edd55"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"recovered_status": 200
|
||||||
|
},
|
||||||
|
"elapsed_s": 4.286921292019542
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "logout cannot falsely succeed under DB lock",
|
||||||
|
"status": "PASS",
|
||||||
|
"detail": {
|
||||||
|
"blocked_logout": 503,
|
||||||
|
"retry": 204,
|
||||||
|
"old_token": 401
|
||||||
|
},
|
||||||
|
"elapsed_s": 2.920123041025363
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,313 @@
|
|||||||
|
{
|
||||||
|
"lab": 3,
|
||||||
|
"base_url": "http://127.0.0.1:8083",
|
||||||
|
"tests": [
|
||||||
|
{
|
||||||
|
"case": "message rejects wrong types/extra {'text': None}",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0272
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "message rejects wrong types/extra {'text': 123}",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0026
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "message rejects wrong types/extra {'text': True}",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0027
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "message rejects wrong types/extra {'text': []}",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0036
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "message rejects wrong types/extra {'text': 'x', 'TEXT': 'y'}",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0024
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "message rejects wrong types/extra {'Text': 'x'}",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0026
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "message rejects wrong types/extra {'text': 'x', 'attachment_ids': None}",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0039
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "message rejects wrong types/extra {'text': 'x', 'attachment_ids': {}}",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0027
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "message rejects wrong types/extra {}",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0026
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "invalid idempotency key ''",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0025
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "invalid idempotency key 'contains space'",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0024
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "invalid idempotency key 'xxxxxxxxxxxxxxxxxxxx'",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0023
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "invalid idempotency key 'bad/key'",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0025
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "missing idempotency key",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0028
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "malformed UTF8/JSON b'{bad'",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.002
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "malformed UTF8/JSON b'\\xff'",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0017
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "malformed UTF8/JSON b'{\"text\":\"x\"}{}'",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0016
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "pagination /api/v1/chats?limit=",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0022
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "pagination /api/v1/chats?limit=0",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0025
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "pagination /api/v1/chats?limit=101",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0025
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "pagination /api/v1/chats?limit=abc",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.052
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "pagination /api/v1/chats?limit=1&limit=2",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0029
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "pagination /api/v1/chats?cursor=",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0031
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "pagination /api/v1/chats?cursor=W10",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0029
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "pagination /api/v1/chats?cursor=bnVsbA",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0028
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "pagination /api/v1/chats/fd2889fb-7506-4b39-af52-0cbaf333768d/messages?limit=",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0033
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "pagination /api/v1/chats/fd2889fb-7506-4b39-af52-0cbaf333768d/messages?limit=0",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0027
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "pagination /api/v1/chats/fd2889fb-7506-4b39-af52-0cbaf333768d/messages?limit=101",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0027
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "pagination /api/v1/chats/fd2889fb-7506-4b39-af52-0cbaf333768d/messages?limit=abc",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0023
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "pagination /api/v1/chats/fd2889fb-7506-4b39-af52-0cbaf333768d/messages?limit=1&limit=2",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0028
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "pagination /api/v1/chats/fd2889fb-7506-4b39-af52-0cbaf333768d/messages?cursor=",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0022
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "pagination /api/v1/chats/fd2889fb-7506-4b39-af52-0cbaf333768d/messages?cursor=W10",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0018
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "pagination /api/v1/chats/fd2889fb-7506-4b39-af52-0cbaf333768d/messages?cursor=bnVsbA",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0019
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "typed cursor (2, None)",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0034
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "typed cursor (2, 1)",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0031
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "typed cursor (2, '2026-13-01T00:00:00Z')",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0025
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "typed cursor (3, False)",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0035
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "typed cursor (3, [])",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0035
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "typed cursor (3, {})",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0033
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "typed cursor (3, 'not-a-uuid')",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0034
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "invalid UUID path",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0029
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "member UUID []",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0029
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "member UUID {}",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0031
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "member UUID 123",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.003
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "member UUID False",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0028
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "unknown member400",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0035
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "login rejects body b'{bad'",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0016
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "login rejects body b'{}'",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0525
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "login rejects body b'null'",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0021
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "login rejects body b' '",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0027
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "nonASCII Bearer401",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0025
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "username trailing whitespace",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0019
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "username trailing whitespace",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0017
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "blank password400",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.002
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "UTF8 colon128 password and NUL display name",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.2074
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "omitted attachment_ids equals [] and conflict",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0857
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "32 concurrent same key all201 same message",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.1192
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "key scope user and chat",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0135
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "outsider cannot send",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0028
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "NUL message exact post replay history",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.0105
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"case": "logout visible through all replicas",
|
||||||
|
"status": "PASS",
|
||||||
|
"elapsed_s": 0.2597
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"passed": 61,
|
||||||
|
"failed": 0
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"pass": true,
|
||||||
|
"api_count": 2,
|
||||||
|
"containers": [
|
||||||
|
"492e68cf4865e27c8d2a945ee2abd55b5f06b646070b2e2a97a22fd5327139da",
|
||||||
|
"d4670b5fd787a9b298fe6b56504a6b9f669961d6d25f638c16e43b4dc7c5cfe3"
|
||||||
|
],
|
||||||
|
"source_manifest": {
|
||||||
|
"src/messenger/__init__.py": "9a72a49106367ca514cc6147d0e727e62c4d33fefd61572d209a5c9494551a2c",
|
||||||
|
"src/messenger/__main__.py": "ba9a59ad44ee8884cd65cf88d5ea15cbd7051b10f7c729043ddd44ca2f34defe",
|
||||||
|
"src/messenger/app.py": "77c8defefc6316b2bf1f91f6129e3959a2ac0e3b9d45ff8978f051e9e942f1c8",
|
||||||
|
"src/messenger/config.py": "e4d4aaf674ede8b5abdc361f77c7793ee94d8d7856030c28834eb7c95291b193",
|
||||||
|
"src/messenger/domain.py": "7bf6f177ab5bdeea09b303dc886160335d348f64f47912b9bba45355db378bef",
|
||||||
|
"src/messenger/migrate.py": "eb5cad7ac6abe38dd40b2db307d298b297abe9543b3928c36bab8ef06283664e",
|
||||||
|
"src/messenger/models.py": "0ca8f9a3a43833ebf0c0b14e05d77c3e1ab48394d15c6b6d678689d40b4cd416",
|
||||||
|
"src/messenger/postgres.py": "449ac90643222e5e1437df2f33ed3584dc9ccb7579c10beae4e8d710a4aae052",
|
||||||
|
"migrations/001_initial.sql": "5d88cd12ef9fda008832dc0b886fa0cf5d886738fe9b77180cdc65adac50dfd9",
|
||||||
|
"migrations/002_idempotency.sql": "82b41be828ad55ec5c1d991775528e7fe6766c362fa58a2c4f46690459b2c00d",
|
||||||
|
"migrations/003_unicode_storage.sql": "7282a55da4aa081f7d3d99692e11eeb7a49feab9c9f829a09d3d72dc74009643"
|
||||||
|
},
|
||||||
|
"note": "Actual runtime sources match the UTF8-guard working tree before final source commit; full124 and encoding26 HTTP tests passed."
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
.......................... [100%]
|
||||||
|
26 passed in 2.12s
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"status": 503,
|
||||||
|
"body": {
|
||||||
|
"error": {
|
||||||
|
"code": "unavailable",
|
||||||
|
"message": "No ready API",
|
||||||
|
"request_id": "ec5c5343-c31f-4da7-be00-7f3849be9dbe"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"request_id": "ec5c5343-c31f-4da7-be00-7f3849be9dbe",
|
||||||
|
"instance_id": null,
|
||||||
|
"recovered_existing_session": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
Container mtusi-vasilev-lab3-api-3 Stopping
|
||||||
|
Container mtusi-vasilev-lab3-api-4 Stopping
|
||||||
|
Container mtusi-vasilev-lab3-api-4 Stopped
|
||||||
|
Container mtusi-vasilev-lab3-api-3 Stopped
|
||||||
|
Container mtusi-vasilev-lab3-postgres-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-postgres-1 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-migrate-1 Starting
|
||||||
|
Container mtusi-vasilev-lab3-migrate-1 Started
|
||||||
|
Container mtusi-vasilev-lab3-migrate-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-cache-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-cache-1 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-migrate-1 Exited
|
||||||
|
Container mtusi-vasilev-lab3-api-4 Starting
|
||||||
|
Container mtusi-vasilev-lab3-api-4 Started
|
||||||
|
Container mtusi-vasilev-lab3-api-3 Starting
|
||||||
|
Container mtusi-vasilev-lab3-api-3 Started
|
||||||
|
{
|
||||||
|
"status": 503,
|
||||||
|
"body": {
|
||||||
|
"error": {
|
||||||
|
"code": "unavailable",
|
||||||
|
"message": "No ready API",
|
||||||
|
"request_id": "ec5c5343-c31f-4da7-be00-7f3849be9dbe"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"request_id": "ec5c5343-c31f-4da7-be00-7f3849be9dbe",
|
||||||
|
"instance_id": null,
|
||||||
|
"recovered_existing_session": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
python3 tests/resilience.py --mode persistence --action-script "scripts/restart.sh" --base-url "http://127.0.0.1:8083"
|
||||||
|
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
|
||||||
|
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"target": "be9077fda25a10358650f9e60386e75b6cf8eb834756848ac73426a8c5e6cb44",
|
||||||
|
"failed_instance": "3a2b912b-b9d3-4884-b5a3-ef1ad50f3c66",
|
||||||
|
"direct_readiness": 503,
|
||||||
|
"seconds_until_verification": 7.425393832963891,
|
||||||
|
"lb_successful_requests": 30,
|
||||||
|
"lb_instances": [
|
||||||
|
"8df6f4db-808e-4d97-b341-0729fad5b95e"
|
||||||
|
],
|
||||||
|
"recovered_two_instances": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"target": "be9077fda25a10358650f9e60386e75b6cf8eb834756848ac73426a8c5e6cb44",
|
||||||
|
"failed_instance": "3a2b912b-b9d3-4884-b5a3-ef1ad50f3c66",
|
||||||
|
"direct_readiness": 503,
|
||||||
|
"seconds_until_verification": 7.425393832963891,
|
||||||
|
"lb_successful_requests": 30,
|
||||||
|
"lb_instances": [
|
||||||
|
"8df6f4db-808e-4d97-b341-0729fad5b95e"
|
||||||
|
],
|
||||||
|
"recovered_two_instances": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"real_instances_before": {
|
||||||
|
"607ae394e5d53a440ea76c2dfed0b2df0096a50a1a628e18322fdc1a7d44057b": "b5916273-3714-494a-9de5-dda6dc88b2e5",
|
||||||
|
"050f8e6d2c4c62fcbfd5be06a398d25a50b00a20abc06fb44212a7d96bc4d130": "fde77ccb-f644-4f3d-8bdc-9374f3537e63"
|
||||||
|
},
|
||||||
|
"runs": [
|
||||||
|
{
|
||||||
|
"target_container": "607ae394e5d53a440ea76c2dfed0b2df0096a50a1a628e18322fdc1a7d44057b",
|
||||||
|
"target_alias": "b5916273-3714-494a-9de5-dda6dc88b2e5",
|
||||||
|
"successful_writes": 1419,
|
||||||
|
"failed_attempts": 83,
|
||||||
|
"successful_rps": 240.92887504635945,
|
||||||
|
"recovery_seconds": 0.0023248750367201865,
|
||||||
|
"observed_after": [
|
||||||
|
"fde77ccb-f644-4f3d-8bdc-9374f3537e63"
|
||||||
|
],
|
||||||
|
"target_running_after_hook": false,
|
||||||
|
"all_confirmed_present": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"target_container": "050f8e6d2c4c62fcbfd5be06a398d25a50b00a20abc06fb44212a7d96bc4d130",
|
||||||
|
"target_alias": "fde77ccb-f644-4f3d-8bdc-9374f3537e63",
|
||||||
|
"successful_writes": 1472,
|
||||||
|
"failed_attempts": 62,
|
||||||
|
"successful_rps": 231.41351169464048,
|
||||||
|
"recovery_seconds": 0.0026418750057928264,
|
||||||
|
"observed_after": [
|
||||||
|
"fdf23b82-08f3-4a92-a03f-d5f1cab7cfef"
|
||||||
|
],
|
||||||
|
"target_running_after_hook": false,
|
||||||
|
"all_confirmed_present": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"pass": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
Container mtusi-vasilev-lab3-api-1 Running
|
||||||
|
Container mtusi-vasilev-lab3-lb-1 Running
|
||||||
|
Container mtusi-vasilev-lab3-postgres-1 Running
|
||||||
|
Container mtusi-vasilev-lab3-cache-1 Running
|
||||||
|
Container mtusi-vasilev-lab3-postgres-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-postgres-1 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-migrate-1 Starting
|
||||||
|
Container mtusi-vasilev-lab3-migrate-1 Started
|
||||||
|
Container mtusi-vasilev-lab3-cache-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-migrate-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-cache-1 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-migrate-1 Exited
|
||||||
|
Container mtusi-vasilev-lab3-api-2 Starting
|
||||||
|
Container mtusi-vasilev-lab3-api-2 Started
|
||||||
|
Container mtusi-vasilev-lab3-api-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-api-2 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-api-1 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-api-2 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-migrate-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-api-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-api-2 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-lb-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-postgres-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-cache-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-cache-1 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-lb-1 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-migrate-1 Exited
|
||||||
|
Container mtusi-vasilev-lab3-postgres-1 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-api-1 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-api-2 Healthy
|
||||||
|
{"stopped_container": "607ae394e5d53a440ea76c2dfed0b2df0096a50a1a628e18322fdc1a7d44057b", "instance_id": "b5916273-3714-494a-9de5-dda6dc88b2e5"}
|
||||||
|
{"stopped_container": "050f8e6d2c4c62fcbfd5be06a398d25a50b00a20abc06fb44212a7d96bc4d130", "instance_id": "fde77ccb-f644-4f3d-8bdc-9374f3537e63"}
|
||||||
|
{
|
||||||
|
"real_instances_before": {
|
||||||
|
"607ae394e5d53a440ea76c2dfed0b2df0096a50a1a628e18322fdc1a7d44057b": "b5916273-3714-494a-9de5-dda6dc88b2e5",
|
||||||
|
"050f8e6d2c4c62fcbfd5be06a398d25a50b00a20abc06fb44212a7d96bc4d130": "fde77ccb-f644-4f3d-8bdc-9374f3537e63"
|
||||||
|
},
|
||||||
|
"runs": [
|
||||||
|
{
|
||||||
|
"target_container": "607ae394e5d53a440ea76c2dfed0b2df0096a50a1a628e18322fdc1a7d44057b",
|
||||||
|
"target_alias": "b5916273-3714-494a-9de5-dda6dc88b2e5",
|
||||||
|
"successful_writes": 1419,
|
||||||
|
"failed_attempts": 83,
|
||||||
|
"successful_rps": 240.92887504635945,
|
||||||
|
"recovery_seconds": 0.0023248750367201865,
|
||||||
|
"observed_after": [
|
||||||
|
"fde77ccb-f644-4f3d-8bdc-9374f3537e63"
|
||||||
|
],
|
||||||
|
"target_running_after_hook": false,
|
||||||
|
"all_confirmed_present": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"target_container": "050f8e6d2c4c62fcbfd5be06a398d25a50b00a20abc06fb44212a7d96bc4d130",
|
||||||
|
"target_alias": "fde77ccb-f644-4f3d-8bdc-9374f3537e63",
|
||||||
|
"successful_writes": 1472,
|
||||||
|
"failed_attempts": 62,
|
||||||
|
"successful_rps": 231.41351169464048,
|
||||||
|
"recovery_seconds": 0.0026418750057928264,
|
||||||
|
"observed_after": [
|
||||||
|
"fdf23b82-08f3-4a92-a03f-d5f1cab7cfef"
|
||||||
|
],
|
||||||
|
"target_running_after_hook": false,
|
||||||
|
"all_confirmed_present": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"pass": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"executed_before_formatting": {
|
||||||
|
"research/run.py": "aba9205e2dc9847b13711019848b5b65d57a1c0840190aff6cfeee1708fc972d",
|
||||||
|
"research/load.py": "5bea62916f9d701b8dbe10c44bfae9bea0ea67789862f408593f43b91634143a"
|
||||||
|
},
|
||||||
|
"committed_after_formatting": {
|
||||||
|
"research/run.py": "6db58307302ba83576501c7761d9e8c08ff183cd1517b2ecb19c9b2dee46d778",
|
||||||
|
"research/load.py": "63857926d91c1c52a5ef19cbfc2a5a8c50df701e53386eacd55cd36dbe59bc77"
|
||||||
|
},
|
||||||
|
"note": "ruff format changed only source layout during measurement; no runtime container or benchmark behavior was changed."
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "28cfd13a04e9cb7efc426277afa1d51f297898b266ff14d25de06d4e4047059c",
|
||||||
|
"service": "api",
|
||||||
|
"image_id": "sha256:063daf6c19e2f71aa3de09aabf8f242a5ce1ef9e1a06e3d5084881b3d20df868",
|
||||||
|
"started_at": "2026-11-06T15:14:19.739138675Z",
|
||||||
|
"cpu_quota": 500000000,
|
||||||
|
"memory": 268435456
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "c07b53a5cb711745f634d4feb044e197e46923210e87d8d29a49a9736453d909",
|
||||||
|
"service": "api",
|
||||||
|
"image_id": "sha256:063daf6c19e2f71aa3de09aabf8f242a5ce1ef9e1a06e3d5084881b3d20df868",
|
||||||
|
"started_at": "2026-11-06T15:14:19.753008862Z",
|
||||||
|
"cpu_quota": 500000000,
|
||||||
|
"memory": 268435456
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "70f74d15b87ae6cb1da93075b8ad97bee9e84d1520bd8c02ea78c3e6561e79e6",
|
||||||
|
"service": "cache",
|
||||||
|
"image_id": "sha256:d827e7f7552cdee40cc7482dbae9da020f42bc47669af6f71182a4ef76a22773",
|
||||||
|
"started_at": "2026-11-06T15:14:19.460690889Z",
|
||||||
|
"cpu_quota": 500000000,
|
||||||
|
"memory": 134217728
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "b22fb4be1076ad3b5beff1fbb0108832ee91ac7aac4cc85afab33c502cfb3d04",
|
||||||
|
"service": "lb",
|
||||||
|
"image_id": "sha256:96ec3c75a9264ba94e733eeacb44051ed6e7b79bb77a73c2c36f236b6423f1f0",
|
||||||
|
"started_at": "2026-11-06T15:14:19.430244988Z",
|
||||||
|
"cpu_quota": 500000000,
|
||||||
|
"memory": 134217728
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "d72d342a99b838fc75686476cc1b0c5b2efe5b9ff002a3e12a3234d4adb4c613",
|
||||||
|
"service": "postgres",
|
||||||
|
"image_id": "sha256:742f40ea20b9ff2ff31db5458d127452988a2164df9e17441e191f3b72252193",
|
||||||
|
"started_at": "2026-11-06T15:14:19.445218459Z",
|
||||||
|
"cpu_quota": 1000000000,
|
||||||
|
"memory": 805306368
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "28cfd13a04e9cb7efc426277afa1d51f297898b266ff14d25de06d4e4047059c",
|
||||||
|
"service": "api",
|
||||||
|
"image_id": "sha256:063daf6c19e2f71aa3de09aabf8f242a5ce1ef9e1a06e3d5084881b3d20df868",
|
||||||
|
"started_at": "2026-11-06T15:13:08.172211608Z",
|
||||||
|
"cpu_quota": 500000000,
|
||||||
|
"memory": 268435456
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "c07b53a5cb711745f634d4feb044e197e46923210e87d8d29a49a9736453d909",
|
||||||
|
"service": "api",
|
||||||
|
"image_id": "sha256:063daf6c19e2f71aa3de09aabf8f242a5ce1ef9e1a06e3d5084881b3d20df868",
|
||||||
|
"started_at": "2026-11-06T15:13:08.077176252Z",
|
||||||
|
"cpu_quota": 500000000,
|
||||||
|
"memory": 268435456
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "70f74d15b87ae6cb1da93075b8ad97bee9e84d1520bd8c02ea78c3e6561e79e6",
|
||||||
|
"service": "cache",
|
||||||
|
"image_id": "sha256:d827e7f7552cdee40cc7482dbae9da020f42bc47669af6f71182a4ef76a22773",
|
||||||
|
"started_at": "2026-11-06T14:55:08.17509564Z",
|
||||||
|
"cpu_quota": 500000000,
|
||||||
|
"memory": 134217728
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "b22fb4be1076ad3b5beff1fbb0108832ee91ac7aac4cc85afab33c502cfb3d04",
|
||||||
|
"service": "lb",
|
||||||
|
"image_id": "sha256:96ec3c75a9264ba94e733eeacb44051ed6e7b79bb77a73c2c36f236b6423f1f0",
|
||||||
|
"started_at": "2026-11-06T15:13:01.454797957Z",
|
||||||
|
"cpu_quota": 500000000,
|
||||||
|
"memory": 134217728
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "d72d342a99b838fc75686476cc1b0c5b2efe5b9ff002a3e12a3234d4adb4c613",
|
||||||
|
"service": "postgres",
|
||||||
|
"image_id": "sha256:742f40ea20b9ff2ff31db5458d127452988a2164df9e17441e191f3b72252193",
|
||||||
|
"started_at": "2026-11-06T15:12:21.564759223Z",
|
||||||
|
"cpu_quota": 1000000000,
|
||||||
|
"memory": 805306368
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"before": [
|
||||||
|
{
|
||||||
|
"id": "28cfd13a04e9cb7efc426277afa1d51f297898b266ff14d25de06d4e4047059c",
|
||||||
|
"image_id": "sha256:063daf6c19e2f71aa3de09aabf8f242a5ce1ef9e1a06e3d5084881b3d20df868",
|
||||||
|
"started_at": "2026-11-06T15:14:19.739138675Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "c07b53a5cb711745f634d4feb044e197e46923210e87d8d29a49a9736453d909",
|
||||||
|
"image_id": "sha256:063daf6c19e2f71aa3de09aabf8f242a5ce1ef9e1a06e3d5084881b3d20df868",
|
||||||
|
"started_at": "2026-11-06T15:14:19.753008862Z"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"after": [
|
||||||
|
{
|
||||||
|
"id": "913f0e142dc7441c27cdb712499cd492ba92043e9e4a5e0be54a65b2fee72f28",
|
||||||
|
"image_id": "sha256:c2052979740ef0b96efd01ac24394ce61b09ae24dd7dcdffa69d6829c6053b71",
|
||||||
|
"started_at": "2026-11-06T15:14:29.20515981Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "184c4778883ed8e10bcbec05b69b2756b701bd6dd3976572d57e49255b806556",
|
||||||
|
"image_id": "sha256:c2052979740ef0b96efd01ac24394ce61b09ae24dd7dcdffa69d6829c6053b71",
|
||||||
|
"started_at": "2026-11-06T15:14:35.879897946Z"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"successful_writes": 3558,
|
||||||
|
"failed_attempts": 257,
|
||||||
|
"elapsed_seconds": 16.29884020803729,
|
||||||
|
"successful_rps": 218.29774110218455,
|
||||||
|
"observed_instances": [
|
||||||
|
"1ef45a61-bbe0-4bd9-904f-5bbd88593528",
|
||||||
|
"38f843bc-29a0-4544-aab6-edf2326f9ad9",
|
||||||
|
"5250815b-8d6a-435e-a200-d63dc46c0c51",
|
||||||
|
"cdb74aa3-b7d5-4e85-9152-70e9afa13c29"
|
||||||
|
],
|
||||||
|
"largest_success_gap_seconds": 1.0128310000291094,
|
||||||
|
"all_confirmed_present": true,
|
||||||
|
"note": "Target image differs by revision label; same API/schema. This verifies sequential replacement, not arbitrary schema compatibility."
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
#0 building with "colima" instance using docker driver
|
||||||
|
|
||||||
|
#1 [internal] load build definition from Dockerfile
|
||||||
|
#1 transferring dockerfile: 102B done
|
||||||
|
#1 DONE 0.0s
|
||||||
|
|
||||||
|
#2 [internal] load metadata for docker.io/library/mtusi-vasilev:lab3
|
||||||
|
#2 DONE 0.0s
|
||||||
|
|
||||||
|
#3 [internal] load .dockerignore
|
||||||
|
#3 transferring context: 2B done
|
||||||
|
#3 DONE 0.0s
|
||||||
|
|
||||||
|
#4 [1/1] FROM docker.io/library/mtusi-vasilev:lab3@sha256:063daf6c19e2f71aa3de09aabf8f242a5ce1ef9e1a06e3d5084881b3d20df868
|
||||||
|
#4 resolve docker.io/library/mtusi-vasilev:lab3@sha256:063daf6c19e2f71aa3de09aabf8f242a5ce1ef9e1a06e3d5084881b3d20df868 done
|
||||||
|
#4 CACHED
|
||||||
|
|
||||||
|
#5 exporting to image
|
||||||
|
#5 exporting layers done
|
||||||
|
#5 exporting manifest sha256:b40d4ac1452a5dc13cceaf50a551c9bc40bbc302dc1c3fe83e66afa0c55cf172 done
|
||||||
|
#5 exporting config sha256:123f1da685332b5c9d2a569f1934bf65b12007f1bacfb6fa92aaca33ddd6361d done
|
||||||
|
#5 exporting attestation manifest sha256:e457177f482340b3b7dbd0293bc41aa8b4b49505d8cbc9665e97de4d8c58edf6 done
|
||||||
|
#5 exporting manifest list sha256:c2052979740ef0b96efd01ac24394ce61b09ae24dd7dcdffa69d6829c6053b71 done
|
||||||
|
#5 naming to docker.io/library/mtusi-vasilev:lab3-rolling done
|
||||||
|
#5 unpacking to docker.io/library/mtusi-vasilev:lab3-rolling done
|
||||||
|
#5 DONE 0.0s
|
||||||
|
Container mtusi-vasilev-lab3-api-4 Running
|
||||||
|
Container mtusi-vasilev-lab3-api-5 Creating
|
||||||
|
Container mtusi-vasilev-lab3-api-5 Created
|
||||||
|
Container mtusi-vasilev-lab3-api-5 Starting
|
||||||
|
Container mtusi-vasilev-lab3-api-5 Started
|
||||||
|
Container mtusi-vasilev-lab3-api-5 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-api-4 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-api-5 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-api-4 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-api-5 Running
|
||||||
|
Container mtusi-vasilev-lab3-api-6 Creating
|
||||||
|
Container mtusi-vasilev-lab3-api-6 Created
|
||||||
|
Container mtusi-vasilev-lab3-api-6 Starting
|
||||||
|
Container mtusi-vasilev-lab3-api-6 Started
|
||||||
|
Container mtusi-vasilev-lab3-api-6 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-api-5 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-api-6 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-api-5 Healthy
|
||||||
|
{
|
||||||
|
"before": [
|
||||||
|
{
|
||||||
|
"id": "28cfd13a04e9cb7efc426277afa1d51f297898b266ff14d25de06d4e4047059c",
|
||||||
|
"image_id": "sha256:063daf6c19e2f71aa3de09aabf8f242a5ce1ef9e1a06e3d5084881b3d20df868",
|
||||||
|
"started_at": "2026-11-06T15:14:19.739138675Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "c07b53a5cb711745f634d4feb044e197e46923210e87d8d29a49a9736453d909",
|
||||||
|
"image_id": "sha256:063daf6c19e2f71aa3de09aabf8f242a5ce1ef9e1a06e3d5084881b3d20df868",
|
||||||
|
"started_at": "2026-11-06T15:14:19.753008862Z"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"after": [
|
||||||
|
{
|
||||||
|
"id": "913f0e142dc7441c27cdb712499cd492ba92043e9e4a5e0be54a65b2fee72f28",
|
||||||
|
"image_id": "sha256:c2052979740ef0b96efd01ac24394ce61b09ae24dd7dcdffa69d6829c6053b71",
|
||||||
|
"started_at": "2026-11-06T15:14:29.20515981Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "184c4778883ed8e10bcbec05b69b2756b701bd6dd3976572d57e49255b806556",
|
||||||
|
"image_id": "sha256:c2052979740ef0b96efd01ac24394ce61b09ae24dd7dcdffa69d6829c6053b71",
|
||||||
|
"started_at": "2026-11-06T15:14:35.879897946Z"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"successful_writes": 3558,
|
||||||
|
"failed_attempts": 257,
|
||||||
|
"elapsed_seconds": 16.29884020803729,
|
||||||
|
"successful_rps": 218.29774110218455,
|
||||||
|
"observed_instances": [
|
||||||
|
"1ef45a61-bbe0-4bd9-904f-5bbd88593528",
|
||||||
|
"38f843bc-29a0-4544-aab6-edf2326f9ad9",
|
||||||
|
"5250815b-8d6a-435e-a200-d63dc46c0c51",
|
||||||
|
"cdb74aa3-b7d5-4e85-9152-70e9afa13c29"
|
||||||
|
],
|
||||||
|
"largest_success_gap_seconds": 1.0128310000291094,
|
||||||
|
"all_confirmed_present": true,
|
||||||
|
"note": "Target image differs by revision label; same API/schema. This verifies sequential replacement, not arbitrary schema compatibility."
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 102 KiB |
File diff suppressed because it is too large
Load Diff
|
After Width: | Height: | Size: 86 KiB |
@@ -0,0 +1,338 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"configuration": "fixed-1",
|
||||||
|
"offered_rate": 100,
|
||||||
|
"repeats": 3,
|
||||||
|
"median_successful_rps": 100.061,
|
||||||
|
"median_p95_ms": 8.597,
|
||||||
|
"total_successful": 1800,
|
||||||
|
"total_errors": 0,
|
||||||
|
"total_dropped": 0,
|
||||||
|
"total_scheduler_dropped": 0,
|
||||||
|
"max_driver_cpu_fraction": 0.08843281826729238,
|
||||||
|
"total_scheduled": 1800,
|
||||||
|
"median_db_cpu_percent": 10.12,
|
||||||
|
"median_api_cpu_percent_sum": 31.896666666666665,
|
||||||
|
"max_api_memory_mib_sum": 92.3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"configuration": "fixed-1",
|
||||||
|
"offered_rate": 400,
|
||||||
|
"repeats": 3,
|
||||||
|
"median_successful_rps": 399.73,
|
||||||
|
"median_p95_ms": 98.167,
|
||||||
|
"total_successful": 7200,
|
||||||
|
"total_errors": 0,
|
||||||
|
"total_dropped": 0,
|
||||||
|
"total_scheduler_dropped": 0,
|
||||||
|
"max_driver_cpu_fraction": 0.2029229202321888,
|
||||||
|
"total_scheduled": 7200,
|
||||||
|
"median_db_cpu_percent": 16.189999999999998,
|
||||||
|
"median_api_cpu_percent_sum": 50.83333333333333,
|
||||||
|
"max_api_memory_mib_sum": 103.3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"configuration": "fixed-1",
|
||||||
|
"offered_rate": 900,
|
||||||
|
"repeats": 3,
|
||||||
|
"median_successful_rps": 391.81,
|
||||||
|
"median_p95_ms": 412.474,
|
||||||
|
"total_successful": 7324,
|
||||||
|
"total_errors": 0,
|
||||||
|
"total_dropped": 8876,
|
||||||
|
"total_scheduler_dropped": 0,
|
||||||
|
"max_driver_cpu_fraction": 0.20232546694036863,
|
||||||
|
"total_scheduled": 16200,
|
||||||
|
"median_db_cpu_percent": 19.99,
|
||||||
|
"median_api_cpu_percent_sum": 106.48,
|
||||||
|
"max_api_memory_mib_sum": 96.91
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"configuration": "fixed-2",
|
||||||
|
"offered_rate": 100,
|
||||||
|
"repeats": 3,
|
||||||
|
"median_successful_rps": 100.038,
|
||||||
|
"median_p95_ms": 10.166,
|
||||||
|
"total_successful": 1800,
|
||||||
|
"total_errors": 0,
|
||||||
|
"total_dropped": 0,
|
||||||
|
"total_scheduler_dropped": 0,
|
||||||
|
"max_driver_cpu_fraction": 0.08871829307849742,
|
||||||
|
"total_scheduled": 1800,
|
||||||
|
"median_db_cpu_percent": 8.273333333333333,
|
||||||
|
"median_api_cpu_percent_sum": 35.593333333333334,
|
||||||
|
"max_api_memory_mib_sum": 151.79000000000002
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"configuration": "fixed-2",
|
||||||
|
"offered_rate": 400,
|
||||||
|
"repeats": 3,
|
||||||
|
"median_successful_rps": 395.474,
|
||||||
|
"median_p95_ms": 195.18,
|
||||||
|
"total_successful": 7200,
|
||||||
|
"total_errors": 0,
|
||||||
|
"total_dropped": 0,
|
||||||
|
"total_scheduler_dropped": 0,
|
||||||
|
"max_driver_cpu_fraction": 0.20277991022584074,
|
||||||
|
"total_scheduled": 7200,
|
||||||
|
"median_db_cpu_percent": 17.583333333333336,
|
||||||
|
"median_api_cpu_percent_sum": 64.65333333333334,
|
||||||
|
"max_api_memory_mib_sum": 158.69
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"configuration": "fixed-2",
|
||||||
|
"offered_rate": 900,
|
||||||
|
"repeats": 3,
|
||||||
|
"median_successful_rps": 363.473,
|
||||||
|
"median_p95_ms": 600.226,
|
||||||
|
"total_successful": 7076,
|
||||||
|
"total_errors": 0,
|
||||||
|
"total_dropped": 9124,
|
||||||
|
"total_scheduler_dropped": 0,
|
||||||
|
"max_driver_cpu_fraction": 0.1818849475837354,
|
||||||
|
"total_scheduled": 16200,
|
||||||
|
"median_db_cpu_percent": 17.34,
|
||||||
|
"median_api_cpu_percent_sum": 76.5875,
|
||||||
|
"max_api_memory_mib_sum": 159.57
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"configuration": "fixed-4",
|
||||||
|
"offered_rate": 100,
|
||||||
|
"repeats": 3,
|
||||||
|
"median_successful_rps": 100.076,
|
||||||
|
"median_p95_ms": 59.538,
|
||||||
|
"total_successful": 1800,
|
||||||
|
"total_errors": 0,
|
||||||
|
"total_dropped": 0,
|
||||||
|
"total_scheduler_dropped": 0,
|
||||||
|
"max_driver_cpu_fraction": 0.08237912047279333,
|
||||||
|
"total_scheduled": 1800,
|
||||||
|
"median_db_cpu_percent": 9.053333333333333,
|
||||||
|
"median_api_cpu_percent_sum": 40.846666666666664,
|
||||||
|
"max_api_memory_mib_sum": 295.64
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"configuration": "fixed-4",
|
||||||
|
"offered_rate": 400,
|
||||||
|
"repeats": 3,
|
||||||
|
"median_successful_rps": 390.192,
|
||||||
|
"median_p95_ms": 383.246,
|
||||||
|
"total_successful": 7078,
|
||||||
|
"total_errors": 0,
|
||||||
|
"total_dropped": 122,
|
||||||
|
"total_scheduler_dropped": 0,
|
||||||
|
"max_driver_cpu_fraction": 0.19185405633444985,
|
||||||
|
"total_scheduled": 7200,
|
||||||
|
"median_db_cpu_percent": 18.94,
|
||||||
|
"median_api_cpu_percent_sum": 79.71666666666667,
|
||||||
|
"max_api_memory_mib_sum": 286.86
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"configuration": "fixed-4",
|
||||||
|
"offered_rate": 900,
|
||||||
|
"repeats": 3,
|
||||||
|
"median_successful_rps": 378.738,
|
||||||
|
"median_p95_ms": 718.332,
|
||||||
|
"total_successful": 7077,
|
||||||
|
"total_errors": 0,
|
||||||
|
"total_dropped": 9123,
|
||||||
|
"total_scheduler_dropped": 0,
|
||||||
|
"max_driver_cpu_fraction": 0.18088731292292065,
|
||||||
|
"total_scheduled": 16200,
|
||||||
|
"median_db_cpu_percent": 15.87,
|
||||||
|
"median_api_cpu_percent_sum": 86.33666666666667,
|
||||||
|
"max_api_memory_mib_sum": 304.92
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"configuration": "growth-1",
|
||||||
|
"offered_rate": 100,
|
||||||
|
"repeats": 3,
|
||||||
|
"median_successful_rps": 100.04,
|
||||||
|
"median_p95_ms": 68.874,
|
||||||
|
"total_successful": 1800,
|
||||||
|
"total_errors": 0,
|
||||||
|
"total_dropped": 0,
|
||||||
|
"total_scheduler_dropped": 0,
|
||||||
|
"max_driver_cpu_fraction": 0.09423092680755431,
|
||||||
|
"total_scheduled": 1800,
|
||||||
|
"median_db_cpu_percent": 9.836666666666666,
|
||||||
|
"median_api_cpu_percent_sum": 32.49333333333333,
|
||||||
|
"max_api_memory_mib_sum": 78.11
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"configuration": "growth-1",
|
||||||
|
"offered_rate": 400,
|
||||||
|
"repeats": 3,
|
||||||
|
"median_successful_rps": 167.785,
|
||||||
|
"median_p95_ms": 1406.105,
|
||||||
|
"total_successful": 3290,
|
||||||
|
"total_errors": 0,
|
||||||
|
"total_dropped": 3910,
|
||||||
|
"total_scheduler_dropped": 0,
|
||||||
|
"max_driver_cpu_fraction": 0.10820845725487749,
|
||||||
|
"total_scheduled": 7200,
|
||||||
|
"median_db_cpu_percent": 10.633333333333333,
|
||||||
|
"median_api_cpu_percent_sum": 51.35666666666667,
|
||||||
|
"max_api_memory_mib_sum": 91.02
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"configuration": "growth-1",
|
||||||
|
"offered_rate": 900,
|
||||||
|
"repeats": 3,
|
||||||
|
"median_successful_rps": 163.01,
|
||||||
|
"median_p95_ms": 1500.974,
|
||||||
|
"total_successful": 3166,
|
||||||
|
"total_errors": 0,
|
||||||
|
"total_dropped": 13034,
|
||||||
|
"total_scheduler_dropped": 0,
|
||||||
|
"max_driver_cpu_fraction": 0.11270218653839223,
|
||||||
|
"total_scheduled": 16200,
|
||||||
|
"median_db_cpu_percent": 10.005,
|
||||||
|
"median_api_cpu_percent_sum": 47.3475,
|
||||||
|
"max_api_memory_mib_sum": 90.62
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"configuration": "growth-2",
|
||||||
|
"offered_rate": 100,
|
||||||
|
"repeats": 3,
|
||||||
|
"median_successful_rps": 100.056,
|
||||||
|
"median_p95_ms": 10.563,
|
||||||
|
"total_successful": 1800,
|
||||||
|
"total_errors": 0,
|
||||||
|
"total_dropped": 0,
|
||||||
|
"total_scheduler_dropped": 0,
|
||||||
|
"max_driver_cpu_fraction": 0.07299362032286852,
|
||||||
|
"total_scheduled": 1800,
|
||||||
|
"median_db_cpu_percent": 9.376666666666667,
|
||||||
|
"median_api_cpu_percent_sum": 36.13666666666666,
|
||||||
|
"max_api_memory_mib_sum": 160.12
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"configuration": "growth-2",
|
||||||
|
"offered_rate": 400,
|
||||||
|
"repeats": 3,
|
||||||
|
"median_successful_rps": 399.789,
|
||||||
|
"median_p95_ms": 183.603,
|
||||||
|
"total_successful": 7093,
|
||||||
|
"total_errors": 0,
|
||||||
|
"total_dropped": 107,
|
||||||
|
"total_scheduler_dropped": 0,
|
||||||
|
"max_driver_cpu_fraction": 0.17175096821894723,
|
||||||
|
"total_scheduled": 7200,
|
||||||
|
"median_db_cpu_percent": 19.95,
|
||||||
|
"median_api_cpu_percent_sum": 73.05999999999999,
|
||||||
|
"max_api_memory_mib_sum": 165.43
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"configuration": "growth-2",
|
||||||
|
"offered_rate": 900,
|
||||||
|
"repeats": 3,
|
||||||
|
"median_successful_rps": 384.981,
|
||||||
|
"median_p95_ms": 477.664,
|
||||||
|
"total_successful": 7321,
|
||||||
|
"total_errors": 0,
|
||||||
|
"total_dropped": 8879,
|
||||||
|
"total_scheduler_dropped": 0,
|
||||||
|
"max_driver_cpu_fraction": 0.18570354381517867,
|
||||||
|
"total_scheduled": 16200,
|
||||||
|
"median_db_cpu_percent": 20.9525,
|
||||||
|
"median_api_cpu_percent_sum": 79.7275,
|
||||||
|
"max_api_memory_mib_sum": 166.75
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"configuration": "growth-4",
|
||||||
|
"offered_rate": 100,
|
||||||
|
"repeats": 3,
|
||||||
|
"median_successful_rps": 100.071,
|
||||||
|
"median_p95_ms": 7.386,
|
||||||
|
"total_successful": 1800,
|
||||||
|
"total_errors": 0,
|
||||||
|
"total_dropped": 0,
|
||||||
|
"total_scheduler_dropped": 0,
|
||||||
|
"max_driver_cpu_fraction": 0.0794899513187198,
|
||||||
|
"total_scheduled": 1800,
|
||||||
|
"median_db_cpu_percent": 7.6466666666666665,
|
||||||
|
"median_api_cpu_percent_sum": 43.79666666666667,
|
||||||
|
"max_api_memory_mib_sum": 287.78999999999996
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"configuration": "growth-4",
|
||||||
|
"offered_rate": 400,
|
||||||
|
"repeats": 3,
|
||||||
|
"median_successful_rps": 399.843,
|
||||||
|
"median_p95_ms": 18.634,
|
||||||
|
"total_successful": 7200,
|
||||||
|
"total_errors": 0,
|
||||||
|
"total_dropped": 0,
|
||||||
|
"total_scheduler_dropped": 0,
|
||||||
|
"max_driver_cpu_fraction": 0.19108340412160874,
|
||||||
|
"total_scheduled": 7200,
|
||||||
|
"median_db_cpu_percent": 18.136666666666667,
|
||||||
|
"median_api_cpu_percent_sum": 86.13000000000001,
|
||||||
|
"max_api_memory_mib_sum": 319.14
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"configuration": "growth-4",
|
||||||
|
"offered_rate": 900,
|
||||||
|
"repeats": 3,
|
||||||
|
"median_successful_rps": 442.326,
|
||||||
|
"median_p95_ms": 621.578,
|
||||||
|
"total_successful": 8053,
|
||||||
|
"total_errors": 0,
|
||||||
|
"total_dropped": 8147,
|
||||||
|
"total_scheduler_dropped": 0,
|
||||||
|
"max_driver_cpu_fraction": 0.20250008266902153,
|
||||||
|
"total_scheduled": 16200,
|
||||||
|
"median_db_cpu_percent": 25.053333333333335,
|
||||||
|
"median_api_cpu_percent_sum": 107.07666666666667,
|
||||||
|
"max_api_memory_mib_sum": 317.97999999999996
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"configuration": "db-improved",
|
||||||
|
"offered_rate": 100,
|
||||||
|
"repeats": 3,
|
||||||
|
"median_successful_rps": 100.064,
|
||||||
|
"median_p95_ms": 7.358,
|
||||||
|
"total_successful": 1800,
|
||||||
|
"total_errors": 0,
|
||||||
|
"total_dropped": 0,
|
||||||
|
"total_scheduler_dropped": 0,
|
||||||
|
"max_driver_cpu_fraction": 0.08305383954688951,
|
||||||
|
"total_scheduled": 1800,
|
||||||
|
"median_db_cpu_percent": 9.74,
|
||||||
|
"median_api_cpu_percent_sum": 44.056666666666665,
|
||||||
|
"max_api_memory_mib_sum": 313.15000000000003
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"configuration": "db-improved",
|
||||||
|
"offered_rate": 400,
|
||||||
|
"repeats": 3,
|
||||||
|
"median_successful_rps": 399.815,
|
||||||
|
"median_p95_ms": 5.889,
|
||||||
|
"total_successful": 7200,
|
||||||
|
"total_errors": 0,
|
||||||
|
"total_dropped": 0,
|
||||||
|
"total_scheduler_dropped": 0,
|
||||||
|
"max_driver_cpu_fraction": 0.17013195582514973,
|
||||||
|
"total_scheduled": 7200,
|
||||||
|
"median_db_cpu_percent": 17.783333333333335,
|
||||||
|
"median_api_cpu_percent_sum": 76.28999999999999,
|
||||||
|
"max_api_memory_mib_sum": 318.8
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"configuration": "db-improved",
|
||||||
|
"offered_rate": 900,
|
||||||
|
"repeats": 3,
|
||||||
|
"median_successful_rps": 881.057,
|
||||||
|
"median_p95_ms": 223.691,
|
||||||
|
"total_successful": 15902,
|
||||||
|
"total_errors": 0,
|
||||||
|
"total_dropped": 298,
|
||||||
|
"total_scheduler_dropped": 0,
|
||||||
|
"max_driver_cpu_fraction": 0.31538257716045937,
|
||||||
|
"total_scheduled": 16200,
|
||||||
|
"median_db_cpu_percent": 42.86333333333333,
|
||||||
|
"median_api_cpu_percent_sum": 179.64666666666668,
|
||||||
|
"max_api_memory_mib_sum": 316.5
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
# Scaling results
|
||||||
|
|
||||||
|
CPU%: 100% means one logical CPU. Memory is summed Docker MemUsage, not heap RSS.
|
||||||
|
|
||||||
|
|Configuration|Offered/s|Success/s median|p95 ms median|Errors total|Dropped total|DB CPU% median|API CPU% sum median|API peak MiB sum|
|
||||||
|
|---|---:|---:|---:|---:|---:|---:|---:|---:|
|
||||||
|
|fixed-1|100|100.06|8.60|0|0|10.12|31.90|92.30|
|
||||||
|
|fixed-1|400|399.73|98.17|0|0|16.19|50.83|103.30|
|
||||||
|
|fixed-1|900|391.81|412.47|0|8876|19.99|106.48|96.91|
|
||||||
|
|fixed-2|100|100.04|10.17|0|0|8.27|35.59|151.79|
|
||||||
|
|fixed-2|400|395.47|195.18|0|0|17.58|64.65|158.69|
|
||||||
|
|fixed-2|900|363.47|600.23|0|9124|17.34|76.59|159.57|
|
||||||
|
|fixed-4|100|100.08|59.54|0|0|9.05|40.85|295.64|
|
||||||
|
|fixed-4|400|390.19|383.25|0|122|18.94|79.72|286.86|
|
||||||
|
|fixed-4|900|378.74|718.33|0|9123|15.87|86.34|304.92|
|
||||||
|
|growth-1|100|100.04|68.87|0|0|9.84|32.49|78.11|
|
||||||
|
|growth-1|400|167.78|1406.11|0|3910|10.63|51.36|91.02|
|
||||||
|
|growth-1|900|163.01|1500.97|0|13034|10.01|47.35|90.62|
|
||||||
|
|growth-2|100|100.06|10.56|0|0|9.38|36.14|160.12|
|
||||||
|
|growth-2|400|399.79|183.60|0|107|19.95|73.06|165.43|
|
||||||
|
|growth-2|900|384.98|477.66|0|8879|20.95|79.73|166.75|
|
||||||
|
|growth-4|100|100.07|7.39|0|0|7.65|43.80|287.79|
|
||||||
|
|growth-4|400|399.84|18.63|0|0|18.14|86.13|319.14|
|
||||||
|
|growth-4|900|442.33|621.58|0|8147|25.05|107.08|317.98|
|
||||||
|
|db-improved|100|100.06|7.36|0|0|9.74|44.06|313.15|
|
||||||
|
|db-improved|400|399.81|5.89|0|0|17.78|76.29|318.80|
|
||||||
|
|db-improved|900|881.06|223.69|0|298|42.86|179.65|316.50|
|
||||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 104 KiB |
File diff suppressed because it is too large
Load Diff
|
After Width: | Height: | Size: 90 KiB |
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"profile": "open-loop unique POST messages, no automatic retries",
|
||||||
|
"offered_rate": 600,
|
||||||
|
"requested_duration_seconds": 6.0,
|
||||||
|
"elapsed_including_drain_seconds": 6.1991,
|
||||||
|
"scheduled": 3600,
|
||||||
|
"attempted": 2624,
|
||||||
|
"successful": 2624,
|
||||||
|
"errors": {},
|
||||||
|
"dropped": 976,
|
||||||
|
"dropped_scheduler": 0,
|
||||||
|
"dropped_concurrency": 976,
|
||||||
|
"driver_cpu_seconds": 1.237524,
|
||||||
|
"driver_cpu_fraction_one_core": 0.19963119577564414,
|
||||||
|
"successful_rps": 423.29,
|
||||||
|
"attempted_rps": 423.29,
|
||||||
|
"latency_success_ms": {
|
||||||
|
"p50": 280.202,
|
||||||
|
"p95": 396.953,
|
||||||
|
"p99": 483.614
|
||||||
|
},
|
||||||
|
"max_schedule_lag_ms": 4.839,
|
||||||
|
"instances": {
|
||||||
|
"02ae80f9-f61b-4964-ab16-b836523904d3": 1313,
|
||||||
|
"52e57fca-356b-4ffc-8446-60f6e871d1c8": 1311
|
||||||
|
},
|
||||||
|
"concurrency_cap": 128
|
||||||
|
}
|
||||||
@@ -0,0 +1,856 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"profile": "open-loop unique POST messages, no automatic retries",
|
||||||
|
"offered_rate": 900,
|
||||||
|
"requested_duration_seconds": 8,
|
||||||
|
"elapsed_including_drain_seconds": 8.2727,
|
||||||
|
"scheduled": 7200,
|
||||||
|
"attempted": 3148,
|
||||||
|
"successful": 3145,
|
||||||
|
"errors": {
|
||||||
|
"503": 3
|
||||||
|
},
|
||||||
|
"dropped": 4052,
|
||||||
|
"dropped_scheduler": 0,
|
||||||
|
"dropped_concurrency": 4052,
|
||||||
|
"driver_cpu_seconds": 1.437157,
|
||||||
|
"driver_cpu_fraction_one_core": 0.17372256610626258,
|
||||||
|
"successful_rps": 380.165,
|
||||||
|
"attempted_rps": 380.527,
|
||||||
|
"latency_success_ms": {
|
||||||
|
"p50": 282.476,
|
||||||
|
"p95": 676.027,
|
||||||
|
"p99": 1311.087
|
||||||
|
},
|
||||||
|
"max_schedule_lag_ms": 7.118,
|
||||||
|
"instances": {
|
||||||
|
"c0034232-3cda-4d6e-a3bf-7e649636f924": 787,
|
||||||
|
"b5395b66-8f7c-4f58-bb34-a04b9ad100d0": 786,
|
||||||
|
"ff56195f-409f-464a-a76b-7c01f9e08ad1": 784,
|
||||||
|
"4236ea3c-10a3-4d07-bf15-1cc5c719fb42": 788
|
||||||
|
},
|
||||||
|
"concurrency_cap": 128,
|
||||||
|
"pg_cpu": 0.25,
|
||||||
|
"actual_containers": [
|
||||||
|
{
|
||||||
|
"id": "7b230a73710c5a6a2ba381d102281ebdd211c4df7ecdbe859c62796e68180848",
|
||||||
|
"service": "api",
|
||||||
|
"image_id": "sha256:063daf6c19e2f71aa3de09aabf8f242a5ce1ef9e1a06e3d5084881b3d20df868",
|
||||||
|
"image": "mtusi-vasilev:lab3",
|
||||||
|
"nano_cpus": 500000000,
|
||||||
|
"memory_bytes": 268435456,
|
||||||
|
"started_at": "2026-11-06T15:03:04.540123598Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "466a9c57a700191613da1220099ba75caa787a64b4744611b8d09d04cd4ba5e4",
|
||||||
|
"service": "api",
|
||||||
|
"image_id": "sha256:063daf6c19e2f71aa3de09aabf8f242a5ce1ef9e1a06e3d5084881b3d20df868",
|
||||||
|
"image": "mtusi-vasilev:lab3",
|
||||||
|
"nano_cpus": 500000000,
|
||||||
|
"memory_bytes": 268435456,
|
||||||
|
"started_at": "2026-11-06T15:03:04.446553121Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "6295c582c2a0ca50e6fc93e17a84ed14a09919fbc46264d422fb83397b3a10fa",
|
||||||
|
"service": "api",
|
||||||
|
"image_id": "sha256:063daf6c19e2f71aa3de09aabf8f242a5ce1ef9e1a06e3d5084881b3d20df868",
|
||||||
|
"image": "mtusi-vasilev:lab3",
|
||||||
|
"nano_cpus": 500000000,
|
||||||
|
"memory_bytes": 268435456,
|
||||||
|
"started_at": "2026-11-06T15:03:04.612162729Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1b9796815fe30621cdc589ea8eb741e712dd354df8931ef74f9a2ef0f1928b3e",
|
||||||
|
"service": "api",
|
||||||
|
"image_id": "sha256:063daf6c19e2f71aa3de09aabf8f242a5ce1ef9e1a06e3d5084881b3d20df868",
|
||||||
|
"image": "mtusi-vasilev:lab3",
|
||||||
|
"nano_cpus": 500000000,
|
||||||
|
"memory_bytes": 268435456,
|
||||||
|
"started_at": "2026-11-06T15:03:04.698668707Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "70f74d15b87ae6cb1da93075b8ad97bee9e84d1520bd8c02ea78c3e6561e79e6",
|
||||||
|
"service": "cache",
|
||||||
|
"image_id": "sha256:d827e7f7552cdee40cc7482dbae9da020f42bc47669af6f71182a4ef76a22773",
|
||||||
|
"image": "valkey/valkey:8.1.3-alpine",
|
||||||
|
"nano_cpus": 500000000,
|
||||||
|
"memory_bytes": 134217728,
|
||||||
|
"started_at": "2026-11-06T14:55:08.17509564Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "b22fb4be1076ad3b5beff1fbb0108832ee91ac7aac4cc85afab33c502cfb3d04",
|
||||||
|
"service": "lb",
|
||||||
|
"image_id": "sha256:96ec3c75a9264ba94e733eeacb44051ed6e7b79bb77a73c2c36f236b6423f1f0",
|
||||||
|
"image": "haproxy:3.2-alpine@sha256:96ec3c75a9264ba94e733eeacb44051ed6e7b79bb77a73c2c36f236b6423f1f0",
|
||||||
|
"nano_cpus": 500000000,
|
||||||
|
"memory_bytes": 134217728,
|
||||||
|
"started_at": "2026-11-06T14:55:17.600378891Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "7f9fa5c30fc5026ff6329df8987f2d853d16f99c1dcbac0339f1909e227e8d6a",
|
||||||
|
"service": "postgres",
|
||||||
|
"image_id": "sha256:742f40ea20b9ff2ff31db5458d127452988a2164df9e17441e191f3b72252193",
|
||||||
|
"image": "postgres:17.10-alpine",
|
||||||
|
"nano_cpus": 250000000,
|
||||||
|
"memory_bytes": 805306368,
|
||||||
|
"started_at": "2026-11-06T15:01:12.408070528Z"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"resource_samples": [
|
||||||
|
{
|
||||||
|
"monotonic": 455452.363337958,
|
||||||
|
"containers": [
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "28.83%",
|
||||||
|
"Container": "7b230a73710c5a6a2ba381d102281ebdd211c4df7ecdbe859c62796e68180848",
|
||||||
|
"ID": "7b230a73710c",
|
||||||
|
"MemPerc": "23.58%",
|
||||||
|
"MemUsage": "60.37MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-3",
|
||||||
|
"NetIO": "301kB / 322kB",
|
||||||
|
"PIDs": "41"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "26.55%",
|
||||||
|
"Container": "466a9c57a700191613da1220099ba75caa787a64b4744611b8d09d04cd4ba5e4",
|
||||||
|
"ID": "466a9c57a700",
|
||||||
|
"MemPerc": "23.37%",
|
||||||
|
"MemUsage": "59.83MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-4",
|
||||||
|
"NetIO": "257kB / 267kB",
|
||||||
|
"PIDs": "45"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "27.54%",
|
||||||
|
"Container": "6295c582c2a0ca50e6fc93e17a84ed14a09919fbc46264d422fb83397b3a10fa",
|
||||||
|
"ID": "6295c582c2a0",
|
||||||
|
"MemPerc": "22.90%",
|
||||||
|
"MemUsage": "58.64MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-5",
|
||||||
|
"NetIO": "326kB / 361kB",
|
||||||
|
"PIDs": "35"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "27.22%",
|
||||||
|
"Container": "1b9796815fe30621cdc589ea8eb741e712dd354df8931ef74f9a2ef0f1928b3e",
|
||||||
|
"ID": "1b9796815fe3",
|
||||||
|
"MemPerc": "23.60%",
|
||||||
|
"MemUsage": "60.43MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-6",
|
||||||
|
"NetIO": "277kB / 289kB",
|
||||||
|
"PIDs": "45"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "1.18%",
|
||||||
|
"Container": "70f74d15b87ae6cb1da93075b8ad97bee9e84d1520bd8c02ea78c3e6561e79e6",
|
||||||
|
"ID": "70f74d15b87a",
|
||||||
|
"MemPerc": "2.61%",
|
||||||
|
"MemUsage": "3.34MiB / 128MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-cache-1",
|
||||||
|
"NetIO": "1.24MB / 2.35MB",
|
||||||
|
"PIDs": "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "3.62%",
|
||||||
|
"Container": "b22fb4be1076ad3b5beff1fbb0108832ee91ac7aac4cc85afab33c502cfb3d04",
|
||||||
|
"ID": "b22fb4be1076",
|
||||||
|
"MemPerc": "10.30%",
|
||||||
|
"MemUsage": "13.18MiB / 128MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-lb-1",
|
||||||
|
"NetIO": "13MB / 13.5MB",
|
||||||
|
"PIDs": "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 618kB",
|
||||||
|
"CPUPerc": "27.21%",
|
||||||
|
"Container": "7f9fa5c30fc5026ff6329df8987f2d853d16f99c1dcbac0339f1909e227e8d6a",
|
||||||
|
"ID": "7f9fa5c30fc5",
|
||||||
|
"MemPerc": "11.29%",
|
||||||
|
"MemUsage": "86.69MiB / 768MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-postgres-1",
|
||||||
|
"NetIO": "9.26MB / 7.37MB",
|
||||||
|
"PIDs": "35"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"monotonic": 455454.376392708,
|
||||||
|
"containers": [
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "25.48%",
|
||||||
|
"Container": "7b230a73710c5a6a2ba381d102281ebdd211c4df7ecdbe859c62796e68180848",
|
||||||
|
"ID": "7b230a73710c",
|
||||||
|
"MemPerc": "24.00%",
|
||||||
|
"MemUsage": "61.43MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-3",
|
||||||
|
"NetIO": "952kB / 1MB",
|
||||||
|
"PIDs": "41"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "24.75%",
|
||||||
|
"Container": "466a9c57a700191613da1220099ba75caa787a64b4744611b8d09d04cd4ba5e4",
|
||||||
|
"ID": "466a9c57a700",
|
||||||
|
"MemPerc": "24.01%",
|
||||||
|
"MemUsage": "61.46MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-4",
|
||||||
|
"NetIO": "894kB / 925kB",
|
||||||
|
"PIDs": "45"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "23.87%",
|
||||||
|
"Container": "6295c582c2a0ca50e6fc93e17a84ed14a09919fbc46264d422fb83397b3a10fa",
|
||||||
|
"ID": "6295c582c2a0",
|
||||||
|
"MemPerc": "23.35%",
|
||||||
|
"MemUsage": "59.78MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-5",
|
||||||
|
"NetIO": "973kB / 1.04MB",
|
||||||
|
"PIDs": "35"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "25.39%",
|
||||||
|
"Container": "1b9796815fe30621cdc589ea8eb741e712dd354df8931ef74f9a2ef0f1928b3e",
|
||||||
|
"ID": "1b9796815fe3",
|
||||||
|
"MemPerc": "24.16%",
|
||||||
|
"MemUsage": "61.86MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-6",
|
||||||
|
"NetIO": "920kB / 960kB",
|
||||||
|
"PIDs": "45"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "1.46%",
|
||||||
|
"Container": "70f74d15b87ae6cb1da93075b8ad97bee9e84d1520bd8c02ea78c3e6561e79e6",
|
||||||
|
"ID": "70f74d15b87a",
|
||||||
|
"MemPerc": "2.61%",
|
||||||
|
"MemUsage": "3.34MiB / 128MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-cache-1",
|
||||||
|
"NetIO": "1.38MB / 2.58MB",
|
||||||
|
"PIDs": "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "5.92%",
|
||||||
|
"Container": "b22fb4be1076ad3b5beff1fbb0108832ee91ac7aac4cc85afab33c502cfb3d04",
|
||||||
|
"ID": "b22fb4be1076",
|
||||||
|
"MemPerc": "10.31%",
|
||||||
|
"MemUsage": "13.19MiB / 128MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-lb-1",
|
||||||
|
"NetIO": "14MB / 14.7MB",
|
||||||
|
"PIDs": "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 618kB",
|
||||||
|
"CPUPerc": "25.37%",
|
||||||
|
"Container": "7f9fa5c30fc5026ff6329df8987f2d853d16f99c1dcbac0339f1909e227e8d6a",
|
||||||
|
"ID": "7f9fa5c30fc5",
|
||||||
|
"MemPerc": "13.54%",
|
||||||
|
"MemUsage": "104MiB / 768MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-postgres-1",
|
||||||
|
"NetIO": "11.9MB / 9.57MB",
|
||||||
|
"PIDs": "38"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"monotonic": 455456.391487458,
|
||||||
|
"containers": [
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "31.86%",
|
||||||
|
"Container": "7b230a73710c5a6a2ba381d102281ebdd211c4df7ecdbe859c62796e68180848",
|
||||||
|
"ID": "7b230a73710c",
|
||||||
|
"MemPerc": "24.58%",
|
||||||
|
"MemUsage": "62.93MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-3",
|
||||||
|
"NetIO": "1.67MB / 1.76MB",
|
||||||
|
"PIDs": "41"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "29.31%",
|
||||||
|
"Container": "466a9c57a700191613da1220099ba75caa787a64b4744611b8d09d04cd4ba5e4",
|
||||||
|
"ID": "466a9c57a700",
|
||||||
|
"MemPerc": "24.98%",
|
||||||
|
"MemUsage": "63.96MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-4",
|
||||||
|
"NetIO": "1.58MB / 1.63MB",
|
||||||
|
"PIDs": "45"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "27.08%",
|
||||||
|
"Container": "6295c582c2a0ca50e6fc93e17a84ed14a09919fbc46264d422fb83397b3a10fa",
|
||||||
|
"ID": "6295c582c2a0",
|
||||||
|
"MemPerc": "24.04%",
|
||||||
|
"MemUsage": "61.55MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-5",
|
||||||
|
"NetIO": "1.68MB / 1.78MB",
|
||||||
|
"PIDs": "36"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "33.68%",
|
||||||
|
"Container": "1b9796815fe30621cdc589ea8eb741e712dd354df8931ef74f9a2ef0f1928b3e",
|
||||||
|
"ID": "1b9796815fe3",
|
||||||
|
"MemPerc": "24.68%",
|
||||||
|
"MemUsage": "63.19MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-6",
|
||||||
|
"NetIO": "1.65MB / 1.73MB",
|
||||||
|
"PIDs": "45"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "1.60%",
|
||||||
|
"Container": "70f74d15b87ae6cb1da93075b8ad97bee9e84d1520bd8c02ea78c3e6561e79e6",
|
||||||
|
"ID": "70f74d15b87a",
|
||||||
|
"MemPerc": "2.63%",
|
||||||
|
"MemUsage": "3.371MiB / 128MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-cache-1",
|
||||||
|
"NetIO": "1.53MB / 2.83MB",
|
||||||
|
"PIDs": "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "6.42%",
|
||||||
|
"Container": "b22fb4be1076ad3b5beff1fbb0108832ee91ac7aac4cc85afab33c502cfb3d04",
|
||||||
|
"ID": "b22fb4be1076",
|
||||||
|
"MemPerc": "10.31%",
|
||||||
|
"MemUsage": "13.19MiB / 128MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-lb-1",
|
||||||
|
"NetIO": "15.1MB / 16MB",
|
||||||
|
"PIDs": "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 618kB",
|
||||||
|
"CPUPerc": "26.35%",
|
||||||
|
"Container": "7f9fa5c30fc5026ff6329df8987f2d853d16f99c1dcbac0339f1909e227e8d6a",
|
||||||
|
"ID": "7f9fa5c30fc5",
|
||||||
|
"MemPerc": "13.64%",
|
||||||
|
"MemUsage": "104.7MiB / 768MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-postgres-1",
|
||||||
|
"NetIO": "14MB / 11.4MB",
|
||||||
|
"PIDs": "38"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"monotonic": 455458.406224,
|
||||||
|
"containers": [
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "23.33%",
|
||||||
|
"Container": "7b230a73710c5a6a2ba381d102281ebdd211c4df7ecdbe859c62796e68180848",
|
||||||
|
"ID": "7b230a73710c",
|
||||||
|
"MemPerc": "25.14%",
|
||||||
|
"MemUsage": "64.35MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-3",
|
||||||
|
"NetIO": "2.4MB / 2.53MB",
|
||||||
|
"PIDs": "41"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "27.04%",
|
||||||
|
"Container": "466a9c57a700191613da1220099ba75caa787a64b4744611b8d09d04cd4ba5e4",
|
||||||
|
"ID": "466a9c57a700",
|
||||||
|
"MemPerc": "25.70%",
|
||||||
|
"MemUsage": "65.8MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-4",
|
||||||
|
"NetIO": "2.28MB / 2.37MB",
|
||||||
|
"PIDs": "45"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "24.01%",
|
||||||
|
"Container": "6295c582c2a0ca50e6fc93e17a84ed14a09919fbc46264d422fb83397b3a10fa",
|
||||||
|
"ID": "6295c582c2a0",
|
||||||
|
"MemPerc": "24.70%",
|
||||||
|
"MemUsage": "63.24MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-5",
|
||||||
|
"NetIO": "2.39MB / 2.52MB",
|
||||||
|
"PIDs": "36"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "25.13%",
|
||||||
|
"Container": "1b9796815fe30621cdc589ea8eb741e712dd354df8931ef74f9a2ef0f1928b3e",
|
||||||
|
"ID": "1b9796815fe3",
|
||||||
|
"MemPerc": "25.51%",
|
||||||
|
"MemUsage": "65.31MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-6",
|
||||||
|
"NetIO": "2.35MB / 2.45MB",
|
||||||
|
"PIDs": "45"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "1.60%",
|
||||||
|
"Container": "70f74d15b87ae6cb1da93075b8ad97bee9e84d1520bd8c02ea78c3e6561e79e6",
|
||||||
|
"ID": "70f74d15b87a",
|
||||||
|
"MemPerc": "2.63%",
|
||||||
|
"MemUsage": "3.371MiB / 128MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-cache-1",
|
||||||
|
"NetIO": "1.69MB / 3.09MB",
|
||||||
|
"PIDs": "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "5.92%",
|
||||||
|
"Container": "b22fb4be1076ad3b5beff1fbb0108832ee91ac7aac4cc85afab33c502cfb3d04",
|
||||||
|
"ID": "b22fb4be1076",
|
||||||
|
"MemPerc": "10.29%",
|
||||||
|
"MemUsage": "13.17MiB / 128MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-lb-1",
|
||||||
|
"NetIO": "16.2MB / 17.3MB",
|
||||||
|
"PIDs": "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 618kB",
|
||||||
|
"CPUPerc": "25.53%",
|
||||||
|
"Container": "7f9fa5c30fc5026ff6329df8987f2d853d16f99c1dcbac0339f1909e227e8d6a",
|
||||||
|
"ID": "7f9fa5c30fc5",
|
||||||
|
"MemPerc": "13.75%",
|
||||||
|
"MemUsage": "105.6MiB / 768MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-postgres-1",
|
||||||
|
"NetIO": "16.1MB / 13.2MB",
|
||||||
|
"PIDs": "38"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"profile": "open-loop unique POST messages, no automatic retries",
|
||||||
|
"offered_rate": 900,
|
||||||
|
"requested_duration_seconds": 8,
|
||||||
|
"elapsed_including_drain_seconds": 8.0146,
|
||||||
|
"scheduled": 7200,
|
||||||
|
"attempted": 7048,
|
||||||
|
"successful": 7048,
|
||||||
|
"errors": {},
|
||||||
|
"dropped": 152,
|
||||||
|
"dropped_scheduler": 0,
|
||||||
|
"dropped_concurrency": 152,
|
||||||
|
"driver_cpu_seconds": 2.5354680000000003,
|
||||||
|
"driver_cpu_fraction_one_core": 0.31635691038405095,
|
||||||
|
"successful_rps": 879.395,
|
||||||
|
"attempted_rps": 879.395,
|
||||||
|
"latency_success_ms": {
|
||||||
|
"p50": 7.316,
|
||||||
|
"p95": 185.956,
|
||||||
|
"p99": 250.607
|
||||||
|
},
|
||||||
|
"max_schedule_lag_ms": 11.95,
|
||||||
|
"instances": {
|
||||||
|
"ff56195f-409f-464a-a76b-7c01f9e08ad1": 1763,
|
||||||
|
"4236ea3c-10a3-4d07-bf15-1cc5c719fb42": 1761,
|
||||||
|
"c0034232-3cda-4d6e-a3bf-7e649636f924": 1763,
|
||||||
|
"b5395b66-8f7c-4f58-bb34-a04b9ad100d0": 1761
|
||||||
|
},
|
||||||
|
"concurrency_cap": 128,
|
||||||
|
"pg_cpu": 0.5,
|
||||||
|
"actual_containers": [
|
||||||
|
{
|
||||||
|
"id": "7b230a73710c5a6a2ba381d102281ebdd211c4df7ecdbe859c62796e68180848",
|
||||||
|
"service": "api",
|
||||||
|
"image_id": "sha256:063daf6c19e2f71aa3de09aabf8f242a5ce1ef9e1a06e3d5084881b3d20df868",
|
||||||
|
"image": "mtusi-vasilev:lab3",
|
||||||
|
"nano_cpus": 500000000,
|
||||||
|
"memory_bytes": 268435456,
|
||||||
|
"started_at": "2026-11-06T15:03:04.540123598Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "466a9c57a700191613da1220099ba75caa787a64b4744611b8d09d04cd4ba5e4",
|
||||||
|
"service": "api",
|
||||||
|
"image_id": "sha256:063daf6c19e2f71aa3de09aabf8f242a5ce1ef9e1a06e3d5084881b3d20df868",
|
||||||
|
"image": "mtusi-vasilev:lab3",
|
||||||
|
"nano_cpus": 500000000,
|
||||||
|
"memory_bytes": 268435456,
|
||||||
|
"started_at": "2026-11-06T15:03:04.446553121Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "6295c582c2a0ca50e6fc93e17a84ed14a09919fbc46264d422fb83397b3a10fa",
|
||||||
|
"service": "api",
|
||||||
|
"image_id": "sha256:063daf6c19e2f71aa3de09aabf8f242a5ce1ef9e1a06e3d5084881b3d20df868",
|
||||||
|
"image": "mtusi-vasilev:lab3",
|
||||||
|
"nano_cpus": 500000000,
|
||||||
|
"memory_bytes": 268435456,
|
||||||
|
"started_at": "2026-11-06T15:03:04.612162729Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1b9796815fe30621cdc589ea8eb741e712dd354df8931ef74f9a2ef0f1928b3e",
|
||||||
|
"service": "api",
|
||||||
|
"image_id": "sha256:063daf6c19e2f71aa3de09aabf8f242a5ce1ef9e1a06e3d5084881b3d20df868",
|
||||||
|
"image": "mtusi-vasilev:lab3",
|
||||||
|
"nano_cpus": 500000000,
|
||||||
|
"memory_bytes": 268435456,
|
||||||
|
"started_at": "2026-11-06T15:03:04.698668707Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "70f74d15b87ae6cb1da93075b8ad97bee9e84d1520bd8c02ea78c3e6561e79e6",
|
||||||
|
"service": "cache",
|
||||||
|
"image_id": "sha256:d827e7f7552cdee40cc7482dbae9da020f42bc47669af6f71182a4ef76a22773",
|
||||||
|
"image": "valkey/valkey:8.1.3-alpine",
|
||||||
|
"nano_cpus": 500000000,
|
||||||
|
"memory_bytes": 134217728,
|
||||||
|
"started_at": "2026-11-06T14:55:08.17509564Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "b22fb4be1076ad3b5beff1fbb0108832ee91ac7aac4cc85afab33c502cfb3d04",
|
||||||
|
"service": "lb",
|
||||||
|
"image_id": "sha256:96ec3c75a9264ba94e733eeacb44051ed6e7b79bb77a73c2c36f236b6423f1f0",
|
||||||
|
"image": "haproxy:3.2-alpine@sha256:96ec3c75a9264ba94e733eeacb44051ed6e7b79bb77a73c2c36f236b6423f1f0",
|
||||||
|
"nano_cpus": 500000000,
|
||||||
|
"memory_bytes": 134217728,
|
||||||
|
"started_at": "2026-11-06T14:55:17.600378891Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "959bdd509fa56040952c99c14d512c8a067fce18b2faeeae241f1ecde077743f",
|
||||||
|
"service": "postgres",
|
||||||
|
"image_id": "sha256:742f40ea20b9ff2ff31db5458d127452988a2164df9e17441e191f3b72252193",
|
||||||
|
"image": "postgres:17.10-alpine",
|
||||||
|
"nano_cpus": 500000000,
|
||||||
|
"memory_bytes": 805306368,
|
||||||
|
"started_at": "2026-11-06T15:03:20.188186411Z"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"resource_samples": [
|
||||||
|
{
|
||||||
|
"monotonic": 455466.379024125,
|
||||||
|
"containers": [
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "46.98%",
|
||||||
|
"Container": "7b230a73710c5a6a2ba381d102281ebdd211c4df7ecdbe859c62796e68180848",
|
||||||
|
"ID": "7b230a73710c",
|
||||||
|
"MemPerc": "31.01%",
|
||||||
|
"MemUsage": "79.38MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-3",
|
||||||
|
"NetIO": "3.57MB / 3.78MB",
|
||||||
|
"PIDs": "46"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "50.39%",
|
||||||
|
"Container": "466a9c57a700191613da1220099ba75caa787a64b4744611b8d09d04cd4ba5e4",
|
||||||
|
"ID": "466a9c57a700",
|
||||||
|
"MemPerc": "30.17%",
|
||||||
|
"MemUsage": "77.23MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-4",
|
||||||
|
"NetIO": "3.66MB / 3.89MB",
|
||||||
|
"PIDs": "46"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "52.91%",
|
||||||
|
"Container": "6295c582c2a0ca50e6fc93e17a84ed14a09919fbc46264d422fb83397b3a10fa",
|
||||||
|
"ID": "6295c582c2a0",
|
||||||
|
"MemPerc": "30.99%",
|
||||||
|
"MemUsage": "79.34MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-5",
|
||||||
|
"NetIO": "3.63MB / 3.86MB",
|
||||||
|
"PIDs": "46"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "50.81%",
|
||||||
|
"Container": "1b9796815fe30621cdc589ea8eb741e712dd354df8931ef74f9a2ef0f1928b3e",
|
||||||
|
"ID": "1b9796815fe3",
|
||||||
|
"MemPerc": "29.24%",
|
||||||
|
"MemUsage": "74.86MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-6",
|
||||||
|
"NetIO": "3.68MB / 3.92MB",
|
||||||
|
"PIDs": "46"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "2.30%",
|
||||||
|
"Container": "70f74d15b87ae6cb1da93075b8ad97bee9e84d1520bd8c02ea78c3e6561e79e6",
|
||||||
|
"ID": "70f74d15b87a",
|
||||||
|
"MemPerc": "2.63%",
|
||||||
|
"MemUsage": "3.367MiB / 128MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-cache-1",
|
||||||
|
"NetIO": "1.94MB / 3.55MB",
|
||||||
|
"PIDs": "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "10.12%",
|
||||||
|
"Container": "b22fb4be1076ad3b5beff1fbb0108832ee91ac7aac4cc85afab33c502cfb3d04",
|
||||||
|
"ID": "b22fb4be1076",
|
||||||
|
"MemPerc": "10.29%",
|
||||||
|
"MemUsage": "13.17MiB / 128MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-lb-1",
|
||||||
|
"NetIO": "17.3MB / 18.4MB",
|
||||||
|
"PIDs": "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 225kB",
|
||||||
|
"CPUPerc": "38.68%",
|
||||||
|
"Container": "959bdd509fa56040952c99c14d512c8a067fce18b2faeeae241f1ecde077743f",
|
||||||
|
"ID": "959bdd509fa5",
|
||||||
|
"MemPerc": "12.32%",
|
||||||
|
"MemUsage": "94.59MiB / 768MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-postgres-1",
|
||||||
|
"NetIO": "3.91MB / 3.15MB",
|
||||||
|
"PIDs": "38"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"monotonic": 455468.392502291,
|
||||||
|
"containers": [
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "46.79%",
|
||||||
|
"Container": "7b230a73710c5a6a2ba381d102281ebdd211c4df7ecdbe859c62796e68180848",
|
||||||
|
"ID": "7b230a73710c",
|
||||||
|
"MemPerc": "26.08%",
|
||||||
|
"MemUsage": "66.78MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-3",
|
||||||
|
"NetIO": "4.99MB / 5.33MB",
|
||||||
|
"PIDs": "45"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "43.23%",
|
||||||
|
"Container": "466a9c57a700191613da1220099ba75caa787a64b4744611b8d09d04cd4ba5e4",
|
||||||
|
"ID": "466a9c57a700",
|
||||||
|
"MemPerc": "26.09%",
|
||||||
|
"MemUsage": "66.79MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-4",
|
||||||
|
"NetIO": "4.98MB / 5.31MB",
|
||||||
|
"PIDs": "45"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "43.48%",
|
||||||
|
"Container": "6295c582c2a0ca50e6fc93e17a84ed14a09919fbc46264d422fb83397b3a10fa",
|
||||||
|
"ID": "6295c582c2a0",
|
||||||
|
"MemPerc": "25.95%",
|
||||||
|
"MemUsage": "66.42MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-5",
|
||||||
|
"NetIO": "4.98MB / 5.32MB",
|
||||||
|
"PIDs": "45"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "43.16%",
|
||||||
|
"Container": "1b9796815fe30621cdc589ea8eb741e712dd354df8931ef74f9a2ef0f1928b3e",
|
||||||
|
"ID": "1b9796815fe3",
|
||||||
|
"MemPerc": "26.01%",
|
||||||
|
"MemUsage": "66.59MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-6",
|
||||||
|
"NetIO": "4.99MB / 5.33MB",
|
||||||
|
"PIDs": "45"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "2.87%",
|
||||||
|
"Container": "70f74d15b87ae6cb1da93075b8ad97bee9e84d1520bd8c02ea78c3e6561e79e6",
|
||||||
|
"ID": "70f74d15b87a",
|
||||||
|
"MemPerc": "2.63%",
|
||||||
|
"MemUsage": "3.371MiB / 128MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-cache-1",
|
||||||
|
"NetIO": "2.2MB / 4.05MB",
|
||||||
|
"PIDs": "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "11.16%",
|
||||||
|
"Container": "b22fb4be1076ad3b5beff1fbb0108832ee91ac7aac4cc85afab33c502cfb3d04",
|
||||||
|
"ID": "b22fb4be1076",
|
||||||
|
"MemPerc": "9.92%",
|
||||||
|
"MemUsage": "12.69MiB / 128MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-lb-1",
|
||||||
|
"NetIO": "20.6MB / 22.1MB",
|
||||||
|
"PIDs": "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 225kB",
|
||||||
|
"CPUPerc": "44.61%",
|
||||||
|
"Container": "959bdd509fa56040952c99c14d512c8a067fce18b2faeeae241f1ecde077743f",
|
||||||
|
"ID": "959bdd509fa5",
|
||||||
|
"MemPerc": "12.54%",
|
||||||
|
"MemUsage": "96.34MiB / 768MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-postgres-1",
|
||||||
|
"NetIO": "8.14MB / 6.61MB",
|
||||||
|
"PIDs": "38"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"monotonic": 455470.405836208,
|
||||||
|
"containers": [
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "50.30%",
|
||||||
|
"Container": "7b230a73710c5a6a2ba381d102281ebdd211c4df7ecdbe859c62796e68180848",
|
||||||
|
"ID": "7b230a73710c",
|
||||||
|
"MemPerc": "27.32%",
|
||||||
|
"MemUsage": "69.93MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-3",
|
||||||
|
"NetIO": "6.23MB / 6.65MB",
|
||||||
|
"PIDs": "45"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "49.82%",
|
||||||
|
"Container": "466a9c57a700191613da1220099ba75caa787a64b4744611b8d09d04cd4ba5e4",
|
||||||
|
"ID": "466a9c57a700",
|
||||||
|
"MemPerc": "27.01%",
|
||||||
|
"MemUsage": "69.15MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-4",
|
||||||
|
"NetIO": "6.2MB / 6.6MB",
|
||||||
|
"PIDs": "44"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "52.91%",
|
||||||
|
"Container": "6295c582c2a0ca50e6fc93e17a84ed14a09919fbc46264d422fb83397b3a10fa",
|
||||||
|
"ID": "6295c582c2a0",
|
||||||
|
"MemPerc": "26.88%",
|
||||||
|
"MemUsage": "68.8MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-5",
|
||||||
|
"NetIO": "6.27MB / 6.71MB",
|
||||||
|
"PIDs": "45"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "47.40%",
|
||||||
|
"Container": "1b9796815fe30621cdc589ea8eb741e712dd354df8931ef74f9a2ef0f1928b3e",
|
||||||
|
"ID": "1b9796815fe3",
|
||||||
|
"MemPerc": "32.01%",
|
||||||
|
"MemUsage": "81.93MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-6",
|
||||||
|
"NetIO": "6.23MB / 6.64MB",
|
||||||
|
"PIDs": "46"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "2.19%",
|
||||||
|
"Container": "70f74d15b87ae6cb1da93075b8ad97bee9e84d1520bd8c02ea78c3e6561e79e6",
|
||||||
|
"ID": "70f74d15b87a",
|
||||||
|
"MemPerc": "2.64%",
|
||||||
|
"MemUsage": "3.379MiB / 128MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-cache-1",
|
||||||
|
"NetIO": "2.44MB / 4.51MB",
|
||||||
|
"PIDs": "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "9.61%",
|
||||||
|
"Container": "b22fb4be1076ad3b5beff1fbb0108832ee91ac7aac4cc85afab33c502cfb3d04",
|
||||||
|
"ID": "b22fb4be1076",
|
||||||
|
"MemPerc": "10.51%",
|
||||||
|
"MemUsage": "13.45MiB / 128MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-lb-1",
|
||||||
|
"NetIO": "22.7MB / 24.4MB",
|
||||||
|
"PIDs": "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 225kB",
|
||||||
|
"CPUPerc": "38.21%",
|
||||||
|
"Container": "959bdd509fa56040952c99c14d512c8a067fce18b2faeeae241f1ecde077743f",
|
||||||
|
"ID": "959bdd509fa5",
|
||||||
|
"MemPerc": "12.77%",
|
||||||
|
"MemUsage": "98.11MiB / 768MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-postgres-1",
|
||||||
|
"NetIO": "12MB / 9.75MB",
|
||||||
|
"PIDs": "38"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"monotonic": 455472.420390708,
|
||||||
|
"containers": [
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "41.74%",
|
||||||
|
"Container": "7b230a73710c5a6a2ba381d102281ebdd211c4df7ecdbe859c62796e68180848",
|
||||||
|
"ID": "7b230a73710c",
|
||||||
|
"MemPerc": "28.53%",
|
||||||
|
"MemUsage": "73.04MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-3",
|
||||||
|
"NetIO": "7.56MB / 8.08MB",
|
||||||
|
"PIDs": "45"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "38.87%",
|
||||||
|
"Container": "466a9c57a700191613da1220099ba75caa787a64b4744611b8d09d04cd4ba5e4",
|
||||||
|
"ID": "466a9c57a700",
|
||||||
|
"MemPerc": "28.56%",
|
||||||
|
"MemUsage": "73.11MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-4",
|
||||||
|
"NetIO": "7.56MB / 8.06MB",
|
||||||
|
"PIDs": "44"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "41.51%",
|
||||||
|
"Container": "6295c582c2a0ca50e6fc93e17a84ed14a09919fbc46264d422fb83397b3a10fa",
|
||||||
|
"ID": "6295c582c2a0",
|
||||||
|
"MemPerc": "28.46%",
|
||||||
|
"MemUsage": "72.85MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-5",
|
||||||
|
"NetIO": "7.55MB / 8.08MB",
|
||||||
|
"PIDs": "45"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "41.91%",
|
||||||
|
"Container": "1b9796815fe30621cdc589ea8eb741e712dd354df8931ef74f9a2ef0f1928b3e",
|
||||||
|
"ID": "1b9796815fe3",
|
||||||
|
"MemPerc": "28.19%",
|
||||||
|
"MemUsage": "72.16MiB / 256MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-api-6",
|
||||||
|
"NetIO": "7.56MB / 8.08MB",
|
||||||
|
"PIDs": "45"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "2.46%",
|
||||||
|
"Container": "70f74d15b87ae6cb1da93075b8ad97bee9e84d1520bd8c02ea78c3e6561e79e6",
|
||||||
|
"ID": "70f74d15b87a",
|
||||||
|
"MemPerc": "2.62%",
|
||||||
|
"MemUsage": "3.359MiB / 128MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-cache-1",
|
||||||
|
"NetIO": "2.69MB / 5MB",
|
||||||
|
"PIDs": "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 0B",
|
||||||
|
"CPUPerc": "9.60%",
|
||||||
|
"Container": "b22fb4be1076ad3b5beff1fbb0108832ee91ac7aac4cc85afab33c502cfb3d04",
|
||||||
|
"ID": "b22fb4be1076",
|
||||||
|
"MemPerc": "9.76%",
|
||||||
|
"MemUsage": "12.49MiB / 128MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-lb-1",
|
||||||
|
"NetIO": "25MB / 26.8MB",
|
||||||
|
"PIDs": "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BlockIO": "0B / 225kB",
|
||||||
|
"CPUPerc": "39.76%",
|
||||||
|
"Container": "959bdd509fa56040952c99c14d512c8a067fce18b2faeeae241f1ecde077743f",
|
||||||
|
"ID": "959bdd509fa5",
|
||||||
|
"MemPerc": "12.91%",
|
||||||
|
"MemUsage": "99.13MiB / 768MiB",
|
||||||
|
"Name": "mtusi-vasilev-lab3-postgres-1",
|
||||||
|
"NetIO": "16.1MB / 13.2MB",
|
||||||
|
"PIDs": "38"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"profile": "open-loop unique POST messages, no automatic retries",
|
||||||
|
"offered_rate": 300,
|
||||||
|
"requested_duration_seconds": 6.0,
|
||||||
|
"elapsed_including_drain_seconds": 6.123,
|
||||||
|
"scheduled": 1800,
|
||||||
|
"attempted": 1167,
|
||||||
|
"successful": 1167,
|
||||||
|
"errors": {},
|
||||||
|
"dropped": 633,
|
||||||
|
"successful_rps": 190.594,
|
||||||
|
"attempted_rps": 190.594,
|
||||||
|
"latency_success_ms": {
|
||||||
|
"p50": 53.814,
|
||||||
|
"p95": 240.729,
|
||||||
|
"p99": 288.121
|
||||||
|
},
|
||||||
|
"max_schedule_lag_ms": 312.744,
|
||||||
|
"instances": {
|
||||||
|
"02ae80f9-f61b-4964-ab16-b836523904d3": 583,
|
||||||
|
"52e57fca-356b-4ffc-8446-60f6e871d1c8": 584
|
||||||
|
},
|
||||||
|
"concurrency_cap": 128
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,91 @@
|
|||||||
|
Container mtusi-vasilev-lab3-cache-1 Running
|
||||||
|
Container mtusi-vasilev-lab3-api-3 Running
|
||||||
|
Container mtusi-vasilev-lab3-api-4 Running
|
||||||
|
Container mtusi-vasilev-lab3-lb-1 Running
|
||||||
|
Container mtusi-vasilev-lab3-api-6 Creating
|
||||||
|
Container mtusi-vasilev-lab3-api-5 Creating
|
||||||
|
Container mtusi-vasilev-lab3-postgres-1 Recreate
|
||||||
|
Container mtusi-vasilev-lab3-api-6 Created
|
||||||
|
Container mtusi-vasilev-lab3-api-5 Created
|
||||||
|
Container mtusi-vasilev-lab3-postgres-1 Recreated
|
||||||
|
Container mtusi-vasilev-lab3-postgres-1 Starting
|
||||||
|
Container mtusi-vasilev-lab3-postgres-1 Started
|
||||||
|
Container mtusi-vasilev-lab3-postgres-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-postgres-1 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-migrate-1 Starting
|
||||||
|
Container mtusi-vasilev-lab3-migrate-1 Started
|
||||||
|
Container mtusi-vasilev-lab3-migrate-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-cache-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-cache-1 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-migrate-1 Exited
|
||||||
|
Container mtusi-vasilev-lab3-api-6 Starting
|
||||||
|
Container mtusi-vasilev-lab3-api-6 Started
|
||||||
|
Container mtusi-vasilev-lab3-api-5 Starting
|
||||||
|
Container mtusi-vasilev-lab3-api-5 Started
|
||||||
|
Container mtusi-vasilev-lab3-api-6 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-api-5 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-api-4 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-api-3 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-api-6 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-api-5 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-api-4 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-api-3 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-postgres-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-cache-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-migrate-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-api-6 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-api-5 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-api-4 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-api-3 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-lb-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-cache-1 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-migrate-1 Exited
|
||||||
|
Container mtusi-vasilev-lab3-lb-1 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-postgres-1 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-api-6 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-api-5 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-api-4 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-api-3 Healthy
|
||||||
|
{"repeat": 1, "successful_rps": 411.104, "dropped": 2815, "errors": {"503": 5}}
|
||||||
|
{"repeat": 2, "successful_rps": 471.464, "dropped": 2449, "errors": {}}
|
||||||
|
{"repeat": 3, "successful_rps": 465.411, "dropped": 2472, "errors": {}}
|
||||||
|
Container mtusi-vasilev-lab3-cache-1 Running
|
||||||
|
Container mtusi-vasilev-lab3-api-3 Running
|
||||||
|
Container mtusi-vasilev-lab3-api-4 Running
|
||||||
|
Container mtusi-vasilev-lab3-lb-1 Running
|
||||||
|
Container mtusi-vasilev-lab3-api-5 Stopping
|
||||||
|
Container mtusi-vasilev-lab3-postgres-1 Recreate
|
||||||
|
Container mtusi-vasilev-lab3-api-6 Stopping
|
||||||
|
Container mtusi-vasilev-lab3-postgres-1 Recreated
|
||||||
|
Container mtusi-vasilev-lab3-api-5 Stopped
|
||||||
|
Container mtusi-vasilev-lab3-api-5 Removing
|
||||||
|
Container mtusi-vasilev-lab3-api-5 Removed
|
||||||
|
Container mtusi-vasilev-lab3-api-6 Stopped
|
||||||
|
Container mtusi-vasilev-lab3-api-6 Removing
|
||||||
|
Container mtusi-vasilev-lab3-api-6 Removed
|
||||||
|
Container mtusi-vasilev-lab3-postgres-1 Starting
|
||||||
|
Container mtusi-vasilev-lab3-postgres-1 Started
|
||||||
|
Container mtusi-vasilev-lab3-postgres-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-postgres-1 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-migrate-1 Starting
|
||||||
|
Container mtusi-vasilev-lab3-migrate-1 Started
|
||||||
|
Container mtusi-vasilev-lab3-migrate-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-cache-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-cache-1 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-migrate-1 Exited
|
||||||
|
Container mtusi-vasilev-lab3-api-4 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-api-3 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-api-4 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-api-3 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-cache-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-migrate-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-api-4 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-api-3 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-lb-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-postgres-1 Waiting
|
||||||
|
Container mtusi-vasilev-lab3-migrate-1 Exited
|
||||||
|
Container mtusi-vasilev-lab3-lb-1 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-cache-1 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-postgres-1 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-api-4 Healthy
|
||||||
|
Container mtusi-vasilev-lab3-api-3 Healthy
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
python3 tests/smoke.py --base-url "http://127.0.0.1:8083"
|
||||||
|
PASS: lab3 public API scenario; infrastructure and grading evidence remain separate.
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
BASE_URL=http://127.0.0.1:8083 uv run --locked pytest -q
|
||||||
|
........................................................................ [ 58%]
|
||||||
|
.................................................... [100%]
|
||||||
|
124 passed in 24.37s
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
global
|
||||||
|
log stdout format raw local0
|
||||||
|
maxconn 256
|
||||||
|
stats socket /tmp/haproxy.sock mode 600 level admin
|
||||||
|
|
||||||
|
defaults
|
||||||
|
mode http
|
||||||
|
log global
|
||||||
|
timeout connect 1s
|
||||||
|
timeout client 10s
|
||||||
|
timeout server 8s
|
||||||
|
timeout check 1s
|
||||||
|
timeout queue 2s
|
||||||
|
retries 0
|
||||||
|
option httplog
|
||||||
|
|
||||||
|
resolvers docker
|
||||||
|
nameserver dns 127.0.0.11:53
|
||||||
|
resolve_retries 3
|
||||||
|
timeout resolve 1s
|
||||||
|
timeout retry 1s
|
||||||
|
hold valid 1s
|
||||||
|
hold obsolete 1s
|
||||||
|
hold nx 1s
|
||||||
|
|
||||||
|
frontend public
|
||||||
|
bind :8080
|
||||||
|
http-request set-var(txn.lb_request_id) uuid()
|
||||||
|
http-request return status 503 content-type application/json lf-string '{"error":{"code":"unavailable","message":"No ready API","request_id":"%[var(txn.lb_request_id)]"}}' hdr X-Request-Id '%[var(txn.lb_request_id)]' if { nbsrv(apis) eq 0 }
|
||||||
|
default_backend apis
|
||||||
|
|
||||||
|
backend apis
|
||||||
|
balance roundrobin
|
||||||
|
option httpchk GET /health/ready
|
||||||
|
http-check expect status 200
|
||||||
|
default-server inter 1s fastinter 500ms downinter 1s fall 2 rise 2
|
||||||
|
server-template api 1-8 api:8080 check resolvers docker resolve-prefer ipv4 init-addr libc,none
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
CREATE TABLE users (
|
||||||
|
id uuid PRIMARY KEY,
|
||||||
|
username text NOT NULL UNIQUE CHECK (username ~ '^[a-z0-9_]{3,32}$'),
|
||||||
|
display_name text NOT NULL CHECK (char_length(display_name) BETWEEN 1 AND 100),
|
||||||
|
password_hash text NOT NULL,
|
||||||
|
created_at timestamptz NOT NULL
|
||||||
|
);
|
||||||
|
CREATE TABLE chats (
|
||||||
|
id uuid PRIMARY KEY,
|
||||||
|
title text NOT NULL CHECK (char_length(title) BETWEEN 1 AND 100),
|
||||||
|
created_at timestamptz NOT NULL
|
||||||
|
);
|
||||||
|
CREATE TABLE members (
|
||||||
|
chat_id uuid NOT NULL REFERENCES chats(id),
|
||||||
|
user_id uuid NOT NULL REFERENCES users(id),
|
||||||
|
position integer NOT NULL CHECK (position >= 0),
|
||||||
|
PRIMARY KEY(chat_id,user_id),
|
||||||
|
UNIQUE(chat_id,position)
|
||||||
|
);
|
||||||
|
CREATE INDEX members_user_idx ON members(user_id,chat_id);
|
||||||
|
CREATE TABLE messages (
|
||||||
|
id uuid PRIMARY KEY,
|
||||||
|
chat_id uuid NOT NULL,
|
||||||
|
sender_id uuid NOT NULL,
|
||||||
|
text text NOT NULL CHECK (char_length(text) BETWEEN 1 AND 4000),
|
||||||
|
created_at timestamptz NOT NULL,
|
||||||
|
FOREIGN KEY(chat_id,sender_id) REFERENCES members(chat_id,user_id)
|
||||||
|
);
|
||||||
|
CREATE INDEX messages_history_idx ON messages(chat_id,created_at,id);
|
||||||
|
CREATE TABLE sessions (
|
||||||
|
token_digest text PRIMARY KEY,
|
||||||
|
user_id uuid NOT NULL REFERENCES users(id),
|
||||||
|
expires_at timestamptz NOT NULL
|
||||||
|
);
|
||||||
|
CREATE INDEX sessions_expiry_idx ON sessions(expires_at);
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
CREATE TABLE message_requests (
|
||||||
|
actor_id uuid NOT NULL REFERENCES users(id),
|
||||||
|
chat_id uuid NOT NULL REFERENCES chats(id),
|
||||||
|
key text NOT NULL,
|
||||||
|
body_digest text NOT NULL,
|
||||||
|
response jsonb NOT NULL,
|
||||||
|
expires_at timestamptz NOT NULL,
|
||||||
|
PRIMARY KEY(actor_id,chat_id,key)
|
||||||
|
);
|
||||||
|
CREATE INDEX message_requests_expiry_idx ON message_requests(expires_at);
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
-- PostgreSQL text rejects U+0000, while the API accepts Unicode code points.
|
||||||
|
-- Preserve UTF-8 losslessly. API validation enforces code point limits; the DB
|
||||||
|
-- additionally bounds byte lengths, without stripping or replacing characters.
|
||||||
|
ALTER TABLE users DROP CONSTRAINT users_display_name_check;
|
||||||
|
ALTER TABLE users ALTER COLUMN display_name TYPE bytea USING convert_to(display_name,'UTF8');
|
||||||
|
ALTER TABLE users ADD CHECK (octet_length(display_name) BETWEEN 1 AND 400);
|
||||||
|
ALTER TABLE chats DROP CONSTRAINT chats_title_check;
|
||||||
|
ALTER TABLE chats ALTER COLUMN title TYPE bytea USING convert_to(title,'UTF8');
|
||||||
|
ALTER TABLE chats ADD CHECK (octet_length(title) BETWEEN 1 AND 400);
|
||||||
|
ALTER TABLE messages DROP CONSTRAINT messages_text_check;
|
||||||
|
ALTER TABLE messages ALTER COLUMN text TYPE bytea USING convert_to(text,'UTF8');
|
||||||
|
ALTER TABLE messages ADD CHECK (octet_length(text) BETWEEN 1 AND 16000);
|
||||||
|
ALTER TABLE message_requests ALTER COLUMN response TYPE bytea USING convert_to(response::text,'UTF8');
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
[project]
|
||||||
|
name = "mtusi-messenger"
|
||||||
|
version = "1.0.0"
|
||||||
|
requires-python = ">=3.12,<3.13"
|
||||||
|
dependencies = ["fastapi", "uvicorn", "psycopg[binary,pool]", "redis", "argon2-cffi"]
|
||||||
|
|
||||||
|
[dependency-groups]
|
||||||
|
dev = [
|
||||||
|
"pytest",
|
||||||
|
"httpx",
|
||||||
|
"ruff",
|
||||||
|
"openapi-spec-validator",
|
||||||
|
"jsonschema",
|
||||||
|
"matplotlib==3.10.8",
|
||||||
|
"aiohttp==3.13.3",
|
||||||
|
]
|
||||||
|
|
||||||
|
[tool.ruff]
|
||||||
|
target-version = "py312"
|
||||||
|
line-length = 100
|
||||||
|
include = ["src/**/*.py", "student-tests/**/*.py", "research/**/*.py"]
|
||||||
|
|
||||||
|
[tool.pytest.ini_options]
|
||||||
|
testpaths = ["student-tests"]
|
||||||
|
pythonpath = ["src", "tests"]
|
||||||
|
|
||||||
|
[tool.ruff.lint]
|
||||||
|
select = ["E4", "E7", "E9", "F", "I", "UP", "B"]
|
||||||
|
ignore = ["B008"] # FastAPI dependencies are declared in endpoint signatures.
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
# Трек1 — цена масштабирования
|
||||||
|
|
||||||
|
Гипотеза: при общей ограниченной PostgreSQL рост числа API не даёт линейного роста подтверждённых записей. Выделение CPU общей БД должно повысить пропускную способность, если именно её квота является активным ограничением.
|
||||||
|
|
||||||
|
## Повторение
|
||||||
|
|
||||||
|
Из корня отдельного репозитория, без других нагрузок на Docker-хосте:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
make up
|
||||||
|
uv sync --locked --python 3.12
|
||||||
|
uv run --locked python research/run.py --duration 6 --rates 100,400,900 --repeats 3 --output evidence/scaling-repeat.json
|
||||||
|
uv run --locked python research/analyze.py evidence/scaling-repeat.json
|
||||||
|
```
|
||||||
|
|
||||||
|
Скрипт создаёт синтетические данные. Существующие данные не удаляются. После опыта возвращает штатные2API,0.5CPU/256MiBкаждая, PostgreSQL1CPU/768MiB. Не запускайте одновременно тесты отказов, другие labs, backup или компиляцию. Сессия должна успеть остаться действительной на протяжении опыта.
|
||||||
|
|
||||||
|
## Матрица
|
||||||
|
|
||||||
|
1. Fixed-total: 1/2/4API, суммарно1CPU и1024MiB (1×1CPU/1024,2×0.5/512,4×0.25/256).
|
||||||
|
2. Growth: 1/2/4API, по0.5CPU/256MiB на процесс.
|
||||||
|
3. Controlled improvement: те же4API по0.5CPU/256MiB; CPU PostgreSQL0.25→0.5, RAM768MiB неизменна.
|
||||||
|
|
||||||
|
БД в исходной матрице **намеренно** ограничена0.25CPU, чтобы экспериментально установить её ресурсную границу. Это не утверждение о максимальной производительности PostgreSQL или штатного стенда.
|
||||||
|
|
||||||
|
Для каждой конфигурации offered rates100/400/900POST/s, три повтора по6s, порядок скоростей чередуется. Fresh chat на каждый прогон; одинаковые пользователь, авторизация, payload и семантика уникальных Idempotency-Key. Короткая история растёт внутри прогона; накопление строк в общей БД и checkpoint могут влиять на результат.
|
||||||
|
|
||||||
|
## Генератор и метрики
|
||||||
|
|
||||||
|
Собственный asyncio/aiohttp open-loop генератор с keepalive. Планирует определённое число запросов по времени, не ждёт окончания предыдущего. При128in-flight или отставании планировщика>250ms слот считается dropped, скрытая бесконечная очередь не создаётся. Таймаут6s; прозрачных повторов нет.
|
||||||
|
|
||||||
|
Сохраняются scheduled, attempted, successful201, ошибки по классам/HTTPкоду, dropped, schedulerlag, successfulRPS и attemptedRPS отдельно. RPS считается по реальному времени, включающему завершение отправленных запросов. Percentiles включают только успешные запросы, поэтому при ошибках/дропах их нельзя читать отдельно от этих счётчиков.
|
||||||
|
|
||||||
|
Docker inspect сохраняет actual CPU/RAM каждой API и БД, проверяются точные значения и число реплик. Docker stats сохраняет исходные временные samples всех сервисов. CPU складывается по API на одном timestamp, память тоже суммируется, затем агрегируется — не усредняется между репликами.
|
||||||
|
|
||||||
|
## Ограничения
|
||||||
|
|
||||||
|
Один Docker Desktop хост, короткие локальные серии и ограниченный генератор. Schedulerlag/drops ограничивают интерпретацию offered ceiling. Для вывода о DBquota нужны совместно: достигнутая CPUквота БД, плато при ростеAPI/нагрузки и контролируемое улучшение при изменении **только** CPU БД. Внешнюю сеть, отказ узла, репликацию БД, промышленный SLA и exactly-once доставку опыт не доказывает.
|
||||||
|
|
||||||
|
Первичные источники: [HAProxy3.2](https://docs.haproxy.org/3.2/configuration.html), [Compose service specification](https://docs.docker.com/reference/compose-file/services/).
|
||||||
|
|
||||||
|
## Калибровка генератора
|
||||||
|
|
||||||
|
HTTPxpilot при300offered/s показал schedulerlag312ms и633drops. Он исключён из основной матрицы. В окончательном генераторе aiohttp при900offered/s на4API driverCPU составлял0.174/0.316одногоядра, scheduler drops0; рост PGquota0.25→0.5 дал380.165→879.395successfulRPS. Это калибровка, отдельная от63измерений основной матрицы; сырые pilotфайлы сохранены.
|
||||||
|
|
||||||
|
## Дополнительный обратный контроль
|
||||||
|
|
||||||
|
После основной матрицы `uv run --locked python research/reversal.py` возвращает PostgreSQL0.25CPUпри техже4API, выполняет3×6sна900offered/s и восстанавливает штатный стенд. Результат отдельно в evidence/scaling-reversal.json, в63основных прогона он не включается. После основного опыта CPUконтроль далмедиану465.411RPSпротив881.06при0.5CPU, что снижает риск объяснить выигрыш только поздним прогревом.
|
||||||
|
|
||||||
|
## Snapshot и последующие исправления
|
||||||
|
|
||||||
|
Сохранённая матрица измерена на runtime029bf9b; его SHA256manifest присутствует в rawJSON. После измерений добавлены формат LB503, строгая валидация malformedcursor и UTF-8guard JSONPOST. Последний guard выполняется и на нормальном пути POST, поэтому опубликованные значения относятся именно к recorded snapshot, а не к замеру финального runtime после guard. Его отдельная накладная стоимость не измерялась; запуск runner на текущем HEAD даст новые измерения. Исходные JSON и графики исторического опыта не переписывались.
|
||||||
@@ -0,0 +1,166 @@
|
|||||||
|
"""Summarize successes separately from offered/attempted requests and sum replica resources."""
|
||||||
|
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
import statistics
|
||||||
|
import sys
|
||||||
|
from collections import defaultdict
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
def memory_bytes(text):
|
||||||
|
value, unit = re.fullmatch(r"([0-9.]+)([A-Za-z]+)", text.strip()).groups()
|
||||||
|
factors = {
|
||||||
|
"B": 1,
|
||||||
|
"KiB": 1024,
|
||||||
|
"MiB": 1024**2,
|
||||||
|
"GiB": 1024**3,
|
||||||
|
"kB": 1000,
|
||||||
|
"MB": 1000**2,
|
||||||
|
"GB": 1000**3,
|
||||||
|
}
|
||||||
|
return float(value) * factors[unit]
|
||||||
|
|
||||||
|
|
||||||
|
def resource_summary(run):
|
||||||
|
cpu, ram, db_cpu, lb_cpu = [], [], [], []
|
||||||
|
by_id = {c["id"][:12]: c["service"] for c in run["actual_containers"]}
|
||||||
|
for sample in run["resource_samples"]:
|
||||||
|
api_cpu = api_ram = 0
|
||||||
|
for row in sample["containers"]:
|
||||||
|
role = by_id.get(row["ID"][:12])
|
||||||
|
percent = float(row["CPUPerc"].rstrip("%"))
|
||||||
|
if role == "api":
|
||||||
|
api_cpu += percent
|
||||||
|
api_ram += memory_bytes(row["MemUsage"].split("/")[0].strip())
|
||||||
|
elif role == "postgres":
|
||||||
|
db_cpu.append(percent)
|
||||||
|
elif role == "lb":
|
||||||
|
lb_cpu.append(percent)
|
||||||
|
cpu.append(api_cpu)
|
||||||
|
ram.append(api_ram / 1024**2)
|
||||||
|
return {
|
||||||
|
"mean_api_cpu_percent_sum": statistics.mean(cpu) if cpu else None,
|
||||||
|
"max_api_memory_mib_sum": max(ram, default=0),
|
||||||
|
"mean_db_cpu_percent": statistics.mean(db_cpu) if db_cpu else None,
|
||||||
|
"mean_lb_cpu_percent": statistics.mean(lb_cpu) if lb_cpu else None,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
source = Path(sys.argv[1])
|
||||||
|
data = json.loads(source.read_text())
|
||||||
|
groups = defaultdict(list)
|
||||||
|
for run in data["runs"]:
|
||||||
|
assert run["scheduled"] == run["attempted"] + run["dropped"]
|
||||||
|
assert run["attempted"] == run["successful"] + sum(run["errors"].values())
|
||||||
|
run["resources"] = resource_summary(run)
|
||||||
|
groups[run["configuration"], run["offered_rate"]].append(run)
|
||||||
|
rows = []
|
||||||
|
for (name, rate), runs in groups.items():
|
||||||
|
row = {
|
||||||
|
"configuration": name,
|
||||||
|
"offered_rate": rate,
|
||||||
|
"repeats": len(runs),
|
||||||
|
"median_successful_rps": statistics.median(r["successful_rps"] for r in runs),
|
||||||
|
"median_p95_ms": statistics.median(r["latency_success_ms"]["p95"] for r in runs),
|
||||||
|
"total_successful": sum(r["successful"] for r in runs),
|
||||||
|
"total_errors": sum(sum(r["errors"].values()) for r in runs),
|
||||||
|
"total_dropped": sum(r["dropped"] for r in runs),
|
||||||
|
"total_scheduler_dropped": sum(r["dropped_scheduler"] for r in runs),
|
||||||
|
"max_driver_cpu_fraction": max(r["driver_cpu_fraction_one_core"] for r in runs),
|
||||||
|
"total_scheduled": sum(r["scheduled"] for r in runs),
|
||||||
|
"median_db_cpu_percent": statistics.median(
|
||||||
|
r["resources"]["mean_db_cpu_percent"] for r in runs
|
||||||
|
),
|
||||||
|
"median_api_cpu_percent_sum": statistics.median(
|
||||||
|
r["resources"]["mean_api_cpu_percent_sum"] for r in runs
|
||||||
|
),
|
||||||
|
"max_api_memory_mib_sum": max(r["resources"]["max_api_memory_mib_sum"] for r in runs),
|
||||||
|
}
|
||||||
|
rows.append(row)
|
||||||
|
dest = source.with_name(source.stem + "-summary.json")
|
||||||
|
dest.write_text(json.dumps(rows, indent=2) + "\n")
|
||||||
|
text = [
|
||||||
|
"# Scaling results",
|
||||||
|
"",
|
||||||
|
"CPU%: 100% means one logical CPU. Memory is summed Docker MemUsage, not heap RSS.",
|
||||||
|
"",
|
||||||
|
"|Configuration|Offered/s|Success/s median|p95 ms median|Errors total|Dropped total|DB CPU% median|API CPU% sum median|API peak MiB sum|",
|
||||||
|
"|---|---:|---:|---:|---:|---:|---:|---:|---:|",
|
||||||
|
]
|
||||||
|
for row in rows:
|
||||||
|
text.append(
|
||||||
|
"|{configuration}|{offered_rate}|{median_successful_rps:.2f}|{median_p95_ms:.2f}|{total_errors}|{total_dropped}|{median_db_cpu_percent:.2f}|{median_api_cpu_percent_sum:.2f}|{max_api_memory_mib_sum:.2f}|".format(
|
||||||
|
**row
|
||||||
|
)
|
||||||
|
)
|
||||||
|
source.with_name(source.stem + "-summary.md").write_text("\n".join(text) + "\n")
|
||||||
|
import matplotlib
|
||||||
|
|
||||||
|
matplotlib.use("Agg")
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
fig, axes = plt.subplots(1, 3, figsize=(15, 4), constrained_layout=True)
|
||||||
|
for ax, series in zip(axes[:2], ["fixed", "growth"], strict=True):
|
||||||
|
for name in [f"{series}-{n}" for n in [1, 2, 4]]:
|
||||||
|
points = sorted(
|
||||||
|
[r for r in rows if r["configuration"] == name], key=lambda r: r["offered_rate"]
|
||||||
|
)
|
||||||
|
ax.plot(
|
||||||
|
[p["offered_rate"] for p in points],
|
||||||
|
[p["median_successful_rps"] for p in points],
|
||||||
|
"o-",
|
||||||
|
label=name,
|
||||||
|
)
|
||||||
|
ax.set(
|
||||||
|
title=series + " API budgets",
|
||||||
|
xlabel="Offered requests/s",
|
||||||
|
ylabel="Successful requests/s",
|
||||||
|
)
|
||||||
|
ax.grid(alpha=0.3)
|
||||||
|
ax.legend()
|
||||||
|
for name in ["growth-4", "db-improved"]:
|
||||||
|
points = sorted(
|
||||||
|
[r for r in rows if r["configuration"] == name], key=lambda r: r["offered_rate"]
|
||||||
|
)
|
||||||
|
axes[2].plot(
|
||||||
|
[p["offered_rate"] for p in points],
|
||||||
|
[p["median_successful_rps"] for p in points],
|
||||||
|
"o-",
|
||||||
|
label=name,
|
||||||
|
)
|
||||||
|
axes[2].set(
|
||||||
|
title="Controlled PostgreSQL CPU change",
|
||||||
|
xlabel="Offered requests/s",
|
||||||
|
ylabel="Successful requests/s",
|
||||||
|
)
|
||||||
|
axes[2].grid(alpha=0.3)
|
||||||
|
axes[2].legend()
|
||||||
|
fig.savefig(source.with_name(source.stem + ".svg"))
|
||||||
|
fig.savefig(source.with_name(source.stem + ".png"), dpi=130)
|
||||||
|
plt.close(fig)
|
||||||
|
fig, axes = plt.subplots(1, 3, figsize=(15, 4), constrained_layout=True)
|
||||||
|
for name in ["growth-4", "db-improved"]:
|
||||||
|
points = sorted([r for r in rows if r["configuration"] == name], key=lambda r: r["offered_rate"])
|
||||||
|
xs = [p["offered_rate"] for p in points]
|
||||||
|
axes[0].plot(xs, [p["median_db_cpu_percent"] for p in points], "o-", label=name)
|
||||||
|
axes[1].plot(xs, [p["max_driver_cpu_fraction"] * 100 for p in points], "o-", label=name)
|
||||||
|
axes[2].plot(xs, [p["total_dropped"] / p["total_scheduled"] * 100 for p in points], "o-", label=name)
|
||||||
|
axes[0].axhline(25, linestyle="--", color="gray", label="baseline quota25%")
|
||||||
|
axes[0].axhline(50, linestyle=":", color="gray", label="improved quota50%")
|
||||||
|
axes[0].set(title="PostgreSQL CPU", ylabel="CPU% (100%=one core)")
|
||||||
|
axes[1].set(title="Driver process CPU, maximum repeat", ylabel="CPU% (100%=one core)")
|
||||||
|
axes[2].set(title="Dropped scheduling slots", ylabel="Dropped / scheduled %")
|
||||||
|
for ax in axes:
|
||||||
|
ax.set_xlabel("Offered requests/s")
|
||||||
|
ax.grid(alpha=.3)
|
||||||
|
ax.legend()
|
||||||
|
fig.savefig(source.with_name(source.stem + "-resources.svg"))
|
||||||
|
fig.savefig(source.with_name(source.stem + "-resources.png"), dpi=130)
|
||||||
|
plt.close(fig)
|
||||||
|
print("\n".join(text))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
"""Open-loop HTTP message writes; count attempts, successes, errors and drops separately."""
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
import json
|
||||||
|
import math
|
||||||
|
import time
|
||||||
|
import uuid
|
||||||
|
from collections import Counter
|
||||||
|
|
||||||
|
import aiohttp
|
||||||
|
|
||||||
|
|
||||||
|
async def run_load(base, actor, chat_id, *, rate, duration, concurrency=128):
|
||||||
|
latencies, errors, instances = [], Counter(), Counter()
|
||||||
|
pending = set()
|
||||||
|
dropped = 0
|
||||||
|
dropped_lag = dropped_concurrency = 0
|
||||||
|
lag = []
|
||||||
|
total_slots = int(rate * duration)
|
||||||
|
async with aiohttp.ClientSession(
|
||||||
|
base_url=base,
|
||||||
|
connector=aiohttp.TCPConnector(limit=concurrency),
|
||||||
|
timeout=aiohttp.ClientTimeout(total=6),
|
||||||
|
trust_env=False,
|
||||||
|
) as client:
|
||||||
|
started = time.perf_counter()
|
||||||
|
cpu_started = time.process_time()
|
||||||
|
|
||||||
|
async def request(index):
|
||||||
|
start = time.perf_counter()
|
||||||
|
try:
|
||||||
|
async with client.post(
|
||||||
|
f"/api/v1/chats/{chat_id}/messages",
|
||||||
|
headers={
|
||||||
|
"Authorization": "Bearer " + actor["token"],
|
||||||
|
"Idempotency-Key": f"study-{uuid.uuid4().hex}",
|
||||||
|
},
|
||||||
|
json={"text": f"synthetic-{index}"},
|
||||||
|
) as response:
|
||||||
|
await response.read()
|
||||||
|
if response.status == 201:
|
||||||
|
latencies.append(time.perf_counter() - start)
|
||||||
|
instances[response.headers.get("X-Instance-Id", "missing")] += 1
|
||||||
|
else:
|
||||||
|
errors[str(response.status)] += 1
|
||||||
|
except (aiohttp.ClientError, TimeoutError) as exc:
|
||||||
|
errors[type(exc).__name__] += 1
|
||||||
|
|
||||||
|
for index in range(total_slots):
|
||||||
|
scheduled = started + index / rate
|
||||||
|
await asyncio.sleep(max(0, scheduled - time.perf_counter()))
|
||||||
|
delay = time.perf_counter() - scheduled
|
||||||
|
lag.append(delay)
|
||||||
|
if delay > 0.25:
|
||||||
|
dropped += 1
|
||||||
|
dropped_lag += 1
|
||||||
|
continue
|
||||||
|
if len(pending) >= concurrency:
|
||||||
|
dropped += 1
|
||||||
|
dropped_concurrency += 1
|
||||||
|
continue
|
||||||
|
task = asyncio.create_task(request(index))
|
||||||
|
pending.add(task)
|
||||||
|
task.add_done_callback(pending.discard)
|
||||||
|
await asyncio.gather(*pending)
|
||||||
|
elapsed = time.perf_counter() - started
|
||||||
|
latencies.sort()
|
||||||
|
|
||||||
|
def percentile(p):
|
||||||
|
return (
|
||||||
|
round(1000 * latencies[max(0, math.ceil(p * len(latencies)) - 1)], 3)
|
||||||
|
if latencies
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"profile": "open-loop unique POST messages, no automatic retries",
|
||||||
|
"offered_rate": rate,
|
||||||
|
"requested_duration_seconds": duration,
|
||||||
|
"elapsed_including_drain_seconds": round(elapsed, 4),
|
||||||
|
"scheduled": total_slots,
|
||||||
|
"attempted": len(latencies) + sum(errors.values()),
|
||||||
|
"successful": len(latencies),
|
||||||
|
"errors": dict(errors),
|
||||||
|
"dropped": dropped,
|
||||||
|
"dropped_scheduler": dropped_lag,
|
||||||
|
"dropped_concurrency": dropped_concurrency,
|
||||||
|
"driver_cpu_seconds": time.process_time() - cpu_started,
|
||||||
|
"driver_cpu_fraction_one_core": (time.process_time() - cpu_started) / elapsed,
|
||||||
|
"successful_rps": round(len(latencies) / elapsed, 3),
|
||||||
|
"attempted_rps": round((len(latencies) + sum(errors.values())) / elapsed, 3),
|
||||||
|
"latency_success_ms": {
|
||||||
|
"p50": percentile(0.5),
|
||||||
|
"p95": percentile(0.95),
|
||||||
|
"p99": percentile(0.99),
|
||||||
|
},
|
||||||
|
"max_schedule_lag_ms": round(max(lag, default=0) * 1000, 3),
|
||||||
|
"instances": dict(instances),
|
||||||
|
"concurrency_cap": concurrency,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import argparse
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "tests"))
|
||||||
|
from client import Client
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("--rate", type=int, default=300)
|
||||||
|
parser.add_argument("--duration", type=float, default=8)
|
||||||
|
parser.add_argument("--output")
|
||||||
|
args = parser.parse_args()
|
||||||
|
c = Client("http://127.0.0.1:8083")
|
||||||
|
actor = c.user("research")
|
||||||
|
chat = c.call(
|
||||||
|
"POST",
|
||||||
|
"/api/v1/chats",
|
||||||
|
201,
|
||||||
|
actor=actor,
|
||||||
|
body={"title": "study", "member_ids": [actor["id"]]},
|
||||||
|
schema="Chat",
|
||||||
|
)["json"]
|
||||||
|
result = asyncio.run(
|
||||||
|
run_load(c.base, actor, chat["id"], rate=args.rate, duration=args.duration)
|
||||||
|
)
|
||||||
|
text = json.dumps(result, indent=2)
|
||||||
|
if args.output:
|
||||||
|
Path(args.output).write_text(text + "\n")
|
||||||
|
print(text)
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
"""Return PostgreSQL to the original quota to check time/warm-cache confounding."""
|
||||||
|
import asyncio
|
||||||
|
import json
|
||||||
|
import subprocess
|
||||||
|
import threading
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from load import run_load
|
||||||
|
from run import ROOT, Client, configure, sample_services
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
profile = {"name": "db-reverted", "replicas": 4, "api_cpu": .5,
|
||||||
|
"api_memory": "256m", "pg_cpu": .25}
|
||||||
|
rows = []
|
||||||
|
try:
|
||||||
|
actual = configure(profile)
|
||||||
|
c = Client("http://127.0.0.1:8083")
|
||||||
|
actor = c.user("reversal")
|
||||||
|
for repeat in range(3):
|
||||||
|
chat = c.call("POST", "/api/v1/chats", 201, actor=actor,
|
||||||
|
body={"title": "reversal", "member_ids": [actor["id"]]}, schema="Chat")["json"]
|
||||||
|
samples, stop = [], threading.Event()
|
||||||
|
thread = threading.Thread(target=sample_services, args=(stop, samples, actual))
|
||||||
|
thread.start()
|
||||||
|
result = asyncio.run(run_load(c.base, actor, chat["id"], rate=900, duration=6))
|
||||||
|
stop.set()
|
||||||
|
thread.join()
|
||||||
|
result.update(configuration="db-reverted", repeat=repeat + 1,
|
||||||
|
actual_containers=actual, resource_samples=samples)
|
||||||
|
rows.append(result)
|
||||||
|
print(json.dumps({k: result[k] for k in ["repeat", "successful_rps", "dropped", "errors"]}), flush=True)
|
||||||
|
finally:
|
||||||
|
subprocess.run(["docker", "compose", "up", "-d", "--scale", "api=2", "--wait"], cwd=ROOT, check=True,
|
||||||
|
stdout=subprocess.DEVNULL)
|
||||||
|
Path(ROOT / "evidence/scaling-reversal.json").write_text(json.dumps({"runs": rows}, indent=2) + "\n")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
+225
@@ -0,0 +1,225 @@
|
|||||||
|
"""Reproducible scaling matrix with actual quotas and service resource samples."""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import asyncio
|
||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import platform
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
from datetime import UTC, datetime
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from load import run_load
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parents[1]
|
||||||
|
sys.path.insert(0, str(ROOT / "tests"))
|
||||||
|
from client import Client # noqa: E402
|
||||||
|
|
||||||
|
|
||||||
|
def command(args, *, env=None):
|
||||||
|
return subprocess.check_output(args, cwd=ROOT, env=env, text=True)
|
||||||
|
|
||||||
|
|
||||||
|
def inventory():
|
||||||
|
ids = command(["docker", "compose", "ps", "-q"]).split()
|
||||||
|
result = []
|
||||||
|
for cid in ids:
|
||||||
|
raw = json.loads(command(["docker", "inspect", cid]))[0]
|
||||||
|
result.append(
|
||||||
|
{
|
||||||
|
"id": cid,
|
||||||
|
"service": raw["Config"]["Labels"]["com.docker.compose.service"],
|
||||||
|
"image_id": raw["Image"],
|
||||||
|
"image": raw["Config"]["Image"],
|
||||||
|
"nano_cpus": raw["HostConfig"]["NanoCpus"],
|
||||||
|
"memory_bytes": raw["HostConfig"]["Memory"],
|
||||||
|
"started_at": raw["State"]["StartedAt"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def sample_services(stop, samples, containers):
|
||||||
|
while not stop.is_set():
|
||||||
|
raw = command(
|
||||||
|
[
|
||||||
|
"docker",
|
||||||
|
"stats",
|
||||||
|
"--no-stream",
|
||||||
|
"--format",
|
||||||
|
"{{json .}}",
|
||||||
|
*[c["id"] for c in containers],
|
||||||
|
]
|
||||||
|
)
|
||||||
|
rows = [json.loads(line) for line in raw.splitlines() if line.strip()]
|
||||||
|
samples.append({"monotonic": time.monotonic(), "containers": rows})
|
||||||
|
stop.wait(0.5)
|
||||||
|
|
||||||
|
|
||||||
|
def configure(profile):
|
||||||
|
env = {
|
||||||
|
**os.environ,
|
||||||
|
"API_REPLICAS": str(profile["replicas"]),
|
||||||
|
"API_CPUS": str(profile["api_cpu"]),
|
||||||
|
"API_MEMORY": profile["api_memory"],
|
||||||
|
"PG_CPUS": str(profile["pg_cpu"]),
|
||||||
|
"PG_MEMORY": "768m",
|
||||||
|
}
|
||||||
|
subprocess.run(
|
||||||
|
["docker", "compose", "up", "-d", "--scale", "api=" + str(profile["replicas"]), "--wait"],
|
||||||
|
cwd=ROOT,
|
||||||
|
env=env,
|
||||||
|
check=True,
|
||||||
|
stdout=subprocess.DEVNULL,
|
||||||
|
)
|
||||||
|
subprocess.run(
|
||||||
|
[sys.executable, "scripts/wait_replicas.py", str(profile["replicas"])], cwd=ROOT, check=True
|
||||||
|
)
|
||||||
|
actual = inventory()
|
||||||
|
apis = [c for c in actual if c["service"] == "api"]
|
||||||
|
assert len(apis) == profile["replicas"]
|
||||||
|
assert all(c["nano_cpus"] == int(profile["api_cpu"] * 1e9) for c in apis)
|
||||||
|
assert all(c["memory_bytes"] == int(profile["api_memory"][:-1]) * 1024**2 for c in apis)
|
||||||
|
db = next(c for c in actual if c["service"] == "postgres")
|
||||||
|
assert db["nano_cpus"] == int(profile["pg_cpu"] * 1e9)
|
||||||
|
return actual
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("--duration", type=float, default=6)
|
||||||
|
parser.add_argument("--rates", default="100,300,600")
|
||||||
|
parser.add_argument("--repeats", type=int, default=3)
|
||||||
|
parser.add_argument("--output", default="evidence/scaling.json")
|
||||||
|
args = parser.parse_args()
|
||||||
|
profiles = []
|
||||||
|
for replicas in [1, 2, 4]:
|
||||||
|
profiles.append(
|
||||||
|
{
|
||||||
|
"name": f"fixed-{replicas}",
|
||||||
|
"series": "fixed",
|
||||||
|
"replicas": replicas,
|
||||||
|
"api_cpu": 1 / replicas,
|
||||||
|
"api_memory": f"{1024 // replicas}m",
|
||||||
|
"pg_cpu": 0.25,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
for replicas in [1, 2, 4]:
|
||||||
|
profiles.append(
|
||||||
|
{
|
||||||
|
"name": f"growth-{replicas}",
|
||||||
|
"series": "growth",
|
||||||
|
"replicas": replicas,
|
||||||
|
"api_cpu": 0.5,
|
||||||
|
"api_memory": "256m",
|
||||||
|
"pg_cpu": 0.25,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
profiles.append(
|
||||||
|
{
|
||||||
|
"name": "db-improved",
|
||||||
|
"series": "improvement",
|
||||||
|
"replicas": 4,
|
||||||
|
"api_cpu": 0.5,
|
||||||
|
"api_memory": "256m",
|
||||||
|
"pg_cpu": 0.5,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
source_manifest = {
|
||||||
|
str(p.relative_to(ROOT)): hashlib.sha256(p.read_bytes()).hexdigest()
|
||||||
|
for folder in ["src", "migrations"]
|
||||||
|
for p in sorted((ROOT / folder).rglob("*"))
|
||||||
|
if p.is_file() and "__pycache__" not in p.parts
|
||||||
|
}
|
||||||
|
report = {
|
||||||
|
"source_manifest": source_manifest,
|
||||||
|
"source_revision": command(["git", "rev-parse", "HEAD"]).strip(),
|
||||||
|
"started_at": datetime.now(UTC).isoformat(),
|
||||||
|
"host": platform.platform(),
|
||||||
|
"docker": json.loads(command(["docker", "info", "--format", "{{json .}}"])),
|
||||||
|
"profiles": profiles,
|
||||||
|
"runs": [],
|
||||||
|
"notes": [
|
||||||
|
"PostgreSQL intentionally constrained to 0.25CPU to expose its resource boundary.",
|
||||||
|
"Open-loop scheduler drops if concurrency cap128 or lag>250ms; no hidden backlog.",
|
||||||
|
"Only successes enter latency percentiles; wall time includes draining requests.",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
# Keep only non-sensitive engine inventory fields.
|
||||||
|
report["docker"] = {
|
||||||
|
k: report["docker"].get(k)
|
||||||
|
for k in ["ServerVersion", "NCPU", "MemTotal", "Architecture", "OperatingSystem"]
|
||||||
|
}
|
||||||
|
dest = ROOT / args.output
|
||||||
|
dest.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
try:
|
||||||
|
c = Client("http://127.0.0.1:8083")
|
||||||
|
actor = c.user("study")
|
||||||
|
for profile in profiles:
|
||||||
|
actual = configure(profile)
|
||||||
|
for repeat in range(args.repeats):
|
||||||
|
rates = [int(x) for x in args.rates.split(",")]
|
||||||
|
if repeat % 2:
|
||||||
|
rates.reverse()
|
||||||
|
for rate in rates:
|
||||||
|
chat = c.call(
|
||||||
|
"POST",
|
||||||
|
"/api/v1/chats",
|
||||||
|
201,
|
||||||
|
actor=actor,
|
||||||
|
body={"title": "synthetic-study", "member_ids": [actor["id"]]},
|
||||||
|
schema="Chat",
|
||||||
|
)["json"]
|
||||||
|
samples, stop = [], threading.Event()
|
||||||
|
thread = threading.Thread(
|
||||||
|
target=sample_services, args=(stop, samples, actual), daemon=True
|
||||||
|
)
|
||||||
|
thread.start()
|
||||||
|
result = asyncio.run(
|
||||||
|
run_load(c.base, actor, chat["id"], rate=rate, duration=args.duration)
|
||||||
|
)
|
||||||
|
stop.set()
|
||||||
|
thread.join()
|
||||||
|
result.update(
|
||||||
|
{
|
||||||
|
"configuration": profile["name"],
|
||||||
|
"repeat": repeat + 1,
|
||||||
|
"actual_containers": actual,
|
||||||
|
"resource_samples": samples,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
report["runs"].append(result)
|
||||||
|
dest.write_text(json.dumps(report, indent=2) + "\n")
|
||||||
|
print(
|
||||||
|
json.dumps(
|
||||||
|
{
|
||||||
|
k: result[k]
|
||||||
|
for k in [
|
||||||
|
"configuration",
|
||||||
|
"repeat",
|
||||||
|
"offered_rate",
|
||||||
|
"successful_rps",
|
||||||
|
"errors",
|
||||||
|
"dropped",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
),
|
||||||
|
flush=True,
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
subprocess.run(
|
||||||
|
["docker", "compose", "up", "-d", "--scale", "api=2", "--wait"],
|
||||||
|
cwd=ROOT,
|
||||||
|
check=True,
|
||||||
|
stdout=subprocess.DEVNULL,
|
||||||
|
)
|
||||||
|
report["ended_at"] = datetime.now(UTC).isoformat()
|
||||||
|
dest.write_text(json.dumps(report, indent=2) + "\n")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Create a private local secret directory once; never rotate existing volumes implicitly."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import secrets
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
root = Path(__file__).resolve().parents[1]
|
||||||
|
private = root / "secrets"
|
||||||
|
private.mkdir(mode=0o700, exist_ok=True)
|
||||||
|
os.chmod(private, 0o700)
|
||||||
|
password_file = private / "postgres_password"
|
||||||
|
if not password_file.exists():
|
||||||
|
password_file.write_text(secrets.token_urlsafe(32))
|
||||||
|
password = password_file.read_text().strip()
|
||||||
|
values = {
|
||||||
|
"database_url": "postgresql://messenger:" + password + "@postgres:5432/messenger",
|
||||||
|
"cache_url": "redis://cache:6379/0",
|
||||||
|
}
|
||||||
|
for name, value in values.items():
|
||||||
|
path = private / name
|
||||||
|
if not path.exists():
|
||||||
|
path.write_text(value)
|
||||||
|
# The parent directory is private on the host; files must be readable by non-root API
|
||||||
|
# through Compose's file-backed secret mount (uid/mode mapping is not portable).
|
||||||
|
for path in private.iterdir():
|
||||||
|
os.chmod(path, 0o644)
|
||||||
|
if not (root / ".env").exists():
|
||||||
|
(root / ".env").write_text("PUBLIC_PORT=8083\nSESSION_TTL_SECONDS=3600\n")
|
||||||
|
print("Local configuration ready; existing secret values preserved.")
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
"""Record non-secret container identity/lifecycle fields for restart evidence."""
|
||||||
|
|
||||||
|
import json
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
ids = subprocess.check_output(["docker", "compose", "ps", "-q"], text=True).split()
|
||||||
|
rows = []
|
||||||
|
for cid in ids:
|
||||||
|
raw = json.loads(subprocess.check_output(["docker", "inspect", cid], text=True))[0]
|
||||||
|
rows.append(
|
||||||
|
{
|
||||||
|
"id": cid,
|
||||||
|
"service": raw["Config"]["Labels"]["com.docker.compose.service"],
|
||||||
|
"image_id": raw["Image"],
|
||||||
|
"started_at": raw["State"]["StartedAt"],
|
||||||
|
"cpu_quota": raw["HostConfig"]["NanoCpus"],
|
||||||
|
"memory": raw["HostConfig"]["Memory"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
Path(sys.argv[1]).write_text(json.dumps(rows, indent=2) + "\n")
|
||||||
Executable
+7
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
cd "$(dirname "$0")/.."
|
||||||
|
python3 scripts/container_snapshot.py evidence/restart-before.json
|
||||||
|
docker compose restart postgres cache api lb
|
||||||
|
docker compose up -d --wait --no-recreate
|
||||||
|
python3 scripts/container_snapshot.py evidence/restart-after.json
|
||||||
Executable
+14
@@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Sequential replacement; never stop the surviving healthy replica.
|
||||||
|
set -eu
|
||||||
|
cd "$(dirname "$0")/.."
|
||||||
|
: "${API_IMAGE:?Set API_IMAGE to the already built target image}"
|
||||||
|
export API_IMAGE
|
||||||
|
ids=$(docker compose ps -q api)
|
||||||
|
for id in $ids; do
|
||||||
|
python3 scripts/wait_replicas.py 2
|
||||||
|
docker stop --time 8 "$id" >/dev/null
|
||||||
|
docker rm "$id" >/dev/null
|
||||||
|
docker compose up -d --no-deps --no-recreate --scale api=2 --wait api
|
||||||
|
python3 scripts/wait_replicas.py 2
|
||||||
|
done
|
||||||
Executable
+4
@@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
cd "$(dirname "$0")/.."
|
||||||
|
python3 scripts/stop_one.py
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
"""Map a process alias to its real container, then leave exactly it stopped."""
|
||||||
|
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
wanted = os.environ["TARGET_INSTANCE_ID"]
|
||||||
|
ids = subprocess.check_output(["docker", "compose", "ps", "-q", "api"], text=True).split()
|
||||||
|
for cid in ids:
|
||||||
|
result = subprocess.run(
|
||||||
|
[
|
||||||
|
"docker",
|
||||||
|
"exec",
|
||||||
|
cid,
|
||||||
|
"python",
|
||||||
|
"-c",
|
||||||
|
"import urllib.request; r=urllib.request.urlopen('http://127.0.0.1:8080/health/live'); print(r.headers['X-Instance-Id'])",
|
||||||
|
],
|
||||||
|
text=True,
|
||||||
|
capture_output=True,
|
||||||
|
check=False,
|
||||||
|
)
|
||||||
|
if result.returncode == 0 and result.stdout.strip() == wanted:
|
||||||
|
subprocess.run(
|
||||||
|
["docker", "stop", "--time", "8", cid], check=True, stdout=subprocess.DEVNULL
|
||||||
|
)
|
||||||
|
print(json.dumps({"stopped_container": cid, "instance_id": wanted}))
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
raise SystemExit("Target instance not found among this project's API containers")
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
"""Check the LB's own safe JSON error when every API is stopped, then recover."""
|
||||||
|
import json
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import urllib.error
|
||||||
|
import urllib.request
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parents[1]
|
||||||
|
sys.path.insert(0, str(ROOT / "tests"))
|
||||||
|
from client import Client
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
c = Client("http://127.0.0.1:8083")
|
||||||
|
actor = c.user("lbdown")
|
||||||
|
subprocess.run(["docker", "compose", "stop", "api"], cwd=ROOT, check=True)
|
||||||
|
try:
|
||||||
|
time.sleep(4)
|
||||||
|
request = urllib.request.Request(c.base + "/api/v1/users/me",
|
||||||
|
headers={"Authorization": "Bearer " + actor["token"]})
|
||||||
|
try:
|
||||||
|
response = urllib.request.urlopen(request, timeout=3)
|
||||||
|
except urllib.error.HTTPError as exc:
|
||||||
|
response = exc
|
||||||
|
with response:
|
||||||
|
body = json.loads(response.read())
|
||||||
|
result = {"status": response.code, "body": body,
|
||||||
|
"request_id": response.headers.get("X-Request-Id"),
|
||||||
|
"instance_id": response.headers.get("X-Instance-Id")}
|
||||||
|
assert result["status"] == 503
|
||||||
|
assert body["error"]["code"] == "unavailable"
|
||||||
|
assert result["request_id"] and body["error"]["request_id"] == result["request_id"]
|
||||||
|
assert result["instance_id"] is None
|
||||||
|
finally:
|
||||||
|
subprocess.run(["docker", "compose", "start", "api"], cwd=ROOT, check=True)
|
||||||
|
subprocess.run([sys.executable, "scripts/wait_replicas.py", "2"], cwd=ROOT, check=True)
|
||||||
|
c.call("GET", "/api/v1/users/me", actor=actor, schema="User")
|
||||||
|
result["recovered_existing_session"] = True
|
||||||
|
(ROOT / "evidence/lb-no-ready-api.json").write_text(json.dumps(result, indent=2) + "\n")
|
||||||
|
print(json.dumps(result, indent=2))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
"""A live process with lost DB network must be excluded by the LB."""
|
||||||
|
|
||||||
|
import json
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parents[1]
|
||||||
|
sys.path.insert(0, str(ROOT / "tests"))
|
||||||
|
from client import Client
|
||||||
|
|
||||||
|
|
||||||
|
def cmd(*args):
|
||||||
|
return subprocess.check_output(args, cwd=ROOT, text=True).strip()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
c = Client("http://127.0.0.1:8083")
|
||||||
|
actor = c.user("readiness")
|
||||||
|
target = cmd("docker", "compose", "ps", "-q", "api").split()[0]
|
||||||
|
raw = json.loads(cmd("docker", "inspect", target))[0]
|
||||||
|
backend = next(n for n in raw["NetworkSettings"]["Networks"] if n.endswith("_backend"))
|
||||||
|
probe = """import json,urllib.request,urllib.error
|
||||||
|
try: r=urllib.request.urlopen('http://127.0.0.1:8080/health/ready',timeout=8)
|
||||||
|
except urllib.error.HTTPError as e: r=e
|
||||||
|
print(json.dumps({'status':r.code,'alias':r.headers['X-Instance-Id']}))"""
|
||||||
|
initial = json.loads(cmd("docker", "exec", target, "python", "-c", probe))
|
||||||
|
assert initial["status"] == 200
|
||||||
|
started = time.monotonic()
|
||||||
|
cmd("docker", "network", "disconnect", backend, target)
|
||||||
|
try:
|
||||||
|
failed = json.loads(cmd("docker", "exec", target, "python", "-c", probe))
|
||||||
|
assert failed["status"] == 503
|
||||||
|
time.sleep(4)
|
||||||
|
observations = []
|
||||||
|
for _ in range(30):
|
||||||
|
response = c.call("GET", "/api/v1/users/me", actor=actor, schema="User")
|
||||||
|
alias = response["headers"]["X-Instance-Id"]
|
||||||
|
assert alias != initial["alias"]
|
||||||
|
observations.append(alias)
|
||||||
|
result = {
|
||||||
|
"target": target,
|
||||||
|
"failed_instance": initial["alias"],
|
||||||
|
"direct_readiness": 503,
|
||||||
|
"seconds_until_verification": time.monotonic() - started,
|
||||||
|
"lb_successful_requests": len(observations),
|
||||||
|
"lb_instances": sorted(set(observations)),
|
||||||
|
}
|
||||||
|
finally:
|
||||||
|
cmd("docker", "network", "connect", "--alias", "api", backend, target)
|
||||||
|
subprocess.run([sys.executable, "scripts/wait_replicas.py", "2"], cwd=ROOT, check=True)
|
||||||
|
result["recovered_two_instances"] = True
|
||||||
|
(ROOT / "evidence/readiness-isolation.json").write_text(json.dumps(result, indent=2) + "\n")
|
||||||
|
print(json.dumps(result, indent=2))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
"""Stop each real API process under traffic; retain confirmed writes and source aliases."""
|
||||||
|
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parents[1]
|
||||||
|
sys.path.insert(0, str(ROOT / "tests"))
|
||||||
|
from client import Client, Failure
|
||||||
|
|
||||||
|
|
||||||
|
def compose(*args):
|
||||||
|
return subprocess.check_output(["docker", "compose", *args], cwd=ROOT, text=True)
|
||||||
|
|
||||||
|
|
||||||
|
def aliases():
|
||||||
|
result = {}
|
||||||
|
for cid in compose("ps", "-q", "api").split():
|
||||||
|
alias = subprocess.check_output(
|
||||||
|
[
|
||||||
|
"docker",
|
||||||
|
"exec",
|
||||||
|
cid,
|
||||||
|
"python",
|
||||||
|
"-c",
|
||||||
|
"import urllib.request; print(urllib.request.urlopen('http://127.0.0.1:8080/health/live').headers['X-Instance-Id'])",
|
||||||
|
],
|
||||||
|
text=True,
|
||||||
|
).strip()
|
||||||
|
result[cid] = alias
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
compose("up", "-d", "--no-recreate", "--wait")
|
||||||
|
subprocess.run([sys.executable, "scripts/wait_replicas.py", "2"], cwd=ROOT, check=True)
|
||||||
|
c = Client("http://127.0.0.1:8083")
|
||||||
|
actor, _, _, chat = c.bootstrap()
|
||||||
|
initial = aliases()
|
||||||
|
runs = []
|
||||||
|
for target_container, target_alias in initial.items():
|
||||||
|
successful, errors = [], []
|
||||||
|
stop = threading.Event()
|
||||||
|
stopped_at = None
|
||||||
|
|
||||||
|
def traffic():
|
||||||
|
while not stop.is_set():
|
||||||
|
try:
|
||||||
|
response = c.message(actor, chat, "failover-proof")
|
||||||
|
successful.append(
|
||||||
|
{
|
||||||
|
"at": time.monotonic(),
|
||||||
|
"id": response["json"]["id"],
|
||||||
|
"instance": response["headers"]["X-Instance-Id"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
except Failure:
|
||||||
|
errors.append(time.monotonic())
|
||||||
|
|
||||||
|
started = time.monotonic()
|
||||||
|
thread = threading.Thread(target=traffic)
|
||||||
|
thread.start()
|
||||||
|
time.sleep(1)
|
||||||
|
stopped_at = time.monotonic()
|
||||||
|
subprocess.run(
|
||||||
|
["scripts/stop-one.sh"],
|
||||||
|
cwd=ROOT,
|
||||||
|
env={**os.environ, "TARGET_INSTANCE_ID": target_alias},
|
||||||
|
check=True,
|
||||||
|
)
|
||||||
|
time.sleep(4)
|
||||||
|
stop.set()
|
||||||
|
thread.join()
|
||||||
|
elapsed = time.monotonic() - started
|
||||||
|
after = [x for x in successful if x["at"] > stopped_at]
|
||||||
|
assert after and all(x["instance"] != target_alias for x in after[-5:])
|
||||||
|
assert min(x["at"] for x in after) - stopped_at <= 10
|
||||||
|
state = json.loads(
|
||||||
|
subprocess.check_output(["docker", "inspect", target_container], text=True)
|
||||||
|
)[0]["State"]
|
||||||
|
assert not state["Running"]
|
||||||
|
runs.append(
|
||||||
|
{
|
||||||
|
"target_container": target_container,
|
||||||
|
"target_alias": target_alias,
|
||||||
|
"successful_writes": len(successful),
|
||||||
|
"failed_attempts": len(errors),
|
||||||
|
"successful_rps": len(successful) / elapsed,
|
||||||
|
"recovery_seconds": min(x["at"] for x in after) - stopped_at,
|
||||||
|
"observed_after": sorted({x["instance"] for x in after[-5:]}),
|
||||||
|
"target_running_after_hook": state["Running"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
subprocess.run(["docker", "start", target_container], check=True, stdout=subprocess.DEVNULL)
|
||||||
|
subprocess.run([sys.executable, "scripts/wait_replicas.py", "2"], cwd=ROOT, check=True)
|
||||||
|
# Verify every acknowledged write, without assuming failed requests did not commit.
|
||||||
|
items, cursor = [], None
|
||||||
|
while True:
|
||||||
|
path = f"/api/v1/chats/{chat['id']}/messages?limit=100"
|
||||||
|
if cursor:
|
||||||
|
path += "&cursor=" + cursor
|
||||||
|
page = c.call("GET", path, actor=actor, schema="MessagePage")["json"]
|
||||||
|
items.extend(page["items"])
|
||||||
|
cursor = page["next_cursor"]
|
||||||
|
if cursor is None:
|
||||||
|
break
|
||||||
|
ids = {x["id"] for x in items}
|
||||||
|
assert all(x["id"] in ids for x in successful)
|
||||||
|
runs[-1]["all_confirmed_present"] = True
|
||||||
|
report = {"real_instances_before": initial, "runs": runs, "pass": True}
|
||||||
|
(ROOT / "evidence/replica-failures.json").write_text(json.dumps(report, indent=2) + "\n")
|
||||||
|
print(json.dumps(report, indent=2))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
"""Sequential real image replacement under message traffic."""
|
||||||
|
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parents[1]
|
||||||
|
sys.path.insert(0, str(ROOT / "tests"))
|
||||||
|
from client import Client, Failure
|
||||||
|
|
||||||
|
|
||||||
|
def snapshots():
|
||||||
|
ids = subprocess.check_output(
|
||||||
|
["docker", "compose", "ps", "-q", "api"], cwd=ROOT, text=True
|
||||||
|
).split()
|
||||||
|
rows = []
|
||||||
|
for cid in ids:
|
||||||
|
raw = json.loads(subprocess.check_output(["docker", "inspect", cid], text=True))[0]
|
||||||
|
rows.append({"id": cid, "image_id": raw["Image"], "started_at": raw["State"]["StartedAt"]})
|
||||||
|
return rows
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
subprocess.run(
|
||||||
|
["docker", "build", "-t", "mtusi-vasilev:lab3-rolling", "-"],
|
||||||
|
input="FROM mtusi-vasilev:lab3\nLABEL org.mtusi.rolling-proof=revision-2\n",
|
||||||
|
text=True,
|
||||||
|
check=True,
|
||||||
|
)
|
||||||
|
before = snapshots()
|
||||||
|
c = Client("http://127.0.0.1:8083")
|
||||||
|
actor, _, _, chat = c.bootstrap()
|
||||||
|
stop = threading.Event()
|
||||||
|
successes, errors = [], []
|
||||||
|
|
||||||
|
def traffic():
|
||||||
|
while not stop.is_set():
|
||||||
|
try:
|
||||||
|
response = c.message(actor, chat, "rolling-proof")
|
||||||
|
successes.append(
|
||||||
|
{
|
||||||
|
"id": response["json"]["id"],
|
||||||
|
"at": time.monotonic(),
|
||||||
|
"instance": response["headers"]["X-Instance-Id"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
except Failure:
|
||||||
|
errors.append(time.monotonic())
|
||||||
|
|
||||||
|
started = time.monotonic()
|
||||||
|
thread = threading.Thread(target=traffic)
|
||||||
|
thread.start()
|
||||||
|
try:
|
||||||
|
time.sleep(1)
|
||||||
|
subprocess.run(
|
||||||
|
["scripts/rolling-update.sh"],
|
||||||
|
cwd=ROOT,
|
||||||
|
env={**os.environ, "API_IMAGE": "mtusi-vasilev:lab3-rolling"},
|
||||||
|
check=True,
|
||||||
|
)
|
||||||
|
time.sleep(2)
|
||||||
|
finally:
|
||||||
|
stop.set()
|
||||||
|
thread.join()
|
||||||
|
elapsed = time.monotonic() - started
|
||||||
|
after = snapshots()
|
||||||
|
assert not {x["id"] for x in before} & {x["id"] for x in after}
|
||||||
|
assert {x["image_id"] for x in before} != {x["image_id"] for x in after}
|
||||||
|
items, cursor = [], None
|
||||||
|
while True:
|
||||||
|
path = f"/api/v1/chats/{chat['id']}/messages?limit=100"
|
||||||
|
if cursor:
|
||||||
|
path += "&cursor=" + cursor
|
||||||
|
page = c.call("GET", path, actor=actor, schema="MessagePage")["json"]
|
||||||
|
items.extend(page["items"])
|
||||||
|
cursor = page["next_cursor"]
|
||||||
|
if cursor is None:
|
||||||
|
break
|
||||||
|
assert {x["id"] for x in successes} <= {x["id"] for x in items}
|
||||||
|
times = [started, *[x["at"] for x in successes], started + elapsed]
|
||||||
|
result = {
|
||||||
|
"before": before,
|
||||||
|
"after": after,
|
||||||
|
"successful_writes": len(successes),
|
||||||
|
"failed_attempts": len(errors),
|
||||||
|
"elapsed_seconds": elapsed,
|
||||||
|
"successful_rps": len(successes) / elapsed,
|
||||||
|
"observed_instances": sorted({x["instance"] for x in successes}),
|
||||||
|
"largest_success_gap_seconds": max(b - a for a, b in zip(times, times[1:])),
|
||||||
|
"all_confirmed_present": True,
|
||||||
|
"note": "Target image differs by revision label; same API/schema. This verifies sequential replacement, not arbitrary schema compatibility.",
|
||||||
|
}
|
||||||
|
(ROOT / "evidence/rolling-update.json").write_text(json.dumps(result, indent=2) + "\n")
|
||||||
|
print(json.dumps(result, indent=2))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
import argparse
|
||||||
|
import concurrent.futures
|
||||||
|
import importlib.util
|
||||||
|
import json
|
||||||
|
import subprocess
|
||||||
|
import time
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
parser=argparse.ArgumentParser()
|
||||||
|
parser.add_argument('--lab',type=int,default=3)
|
||||||
|
parser.add_argument('--repo',type=Path)
|
||||||
|
parser.add_argument('--base-url')
|
||||||
|
parser.add_argument('--output',type=Path)
|
||||||
|
args=parser.parse_args()
|
||||||
|
repo=(args.repo or Path(__file__).resolve().parents[1]).resolve()
|
||||||
|
spec=importlib.util.spec_from_file_location('pub',repo/'tests/client.py')
|
||||||
|
m=importlib.util.module_from_spec(spec);spec.loader.exec_module(m)
|
||||||
|
c=m.Client(args.base_url or f'http://127.0.0.1:{8080+args.lab}',timeout=10)
|
||||||
|
rows=[]
|
||||||
|
def compose(*args):
|
||||||
|
return subprocess.check_output(['docker','compose',*args],cwd=repo,text=True).strip()
|
||||||
|
def sql(query):
|
||||||
|
return subprocess.check_output(['docker','exec',pg,'psql','-U','messenger','-d','messenger','-At','-c',query],text=True).strip()
|
||||||
|
def direct(cid,path,token=None):
|
||||||
|
code='''import json,sys,time,urllib.request,urllib.error
|
||||||
|
p=json.load(sys.stdin);start=time.monotonic()
|
||||||
|
r=urllib.request.Request('http://127.0.0.1:8080'+p['path'],headers={'Authorization':'Bearer '+p['token']} if p.get('token') else {})
|
||||||
|
try: response=urllib.request.urlopen(r,timeout=9)
|
||||||
|
except urllib.error.HTTPError as e: response=e
|
||||||
|
with response:
|
||||||
|
body=response.read();result={'status':response.code,'elapsed_s':time.monotonic()-start,'request_id':response.headers.get('X-Request-Id'),'instance_id':response.headers.get('X-Instance-Id'),'body':json.loads(body)}
|
||||||
|
print(json.dumps(result))'''
|
||||||
|
out=subprocess.check_output(['docker','exec','-i',cid,'python','-c',code],input=json.dumps({'path':path,'token':token}),text=True,timeout=15)
|
||||||
|
return json.loads(out)
|
||||||
|
def check(label,fn):
|
||||||
|
start=time.monotonic()
|
||||||
|
try: detail=fn(); row={'case':label,'status':'PASS','detail':detail}
|
||||||
|
except Exception as e: row={'case':label,'status':'FAIL','error':str(e)[:500]}
|
||||||
|
row['elapsed_s']=time.monotonic()-start; rows.append(row);print(row,flush=True)
|
||||||
|
pg=compose('ps','-q','postgres');apis=compose('ps','-q','api').split()
|
||||||
|
alice,bob,eve,chat=c.bootstrap()
|
||||||
|
path='/api/v1/chats/'+chat['id']+'/messages'
|
||||||
|
original=c.message(alice,chat,'fault replay',key='root-fault-replay')['json']
|
||||||
|
def acl_replay():
|
||||||
|
sql(f"SET session_replication_role=replica; DELETE FROM members WHERE chat_id='{chat['id']}' AND user_id='{alice['id']}';")
|
||||||
|
try:
|
||||||
|
for text in ('fault replay','different'):
|
||||||
|
c.call('POST',path,404,actor=alice,body={'text':text},headers={'Idempotency-Key':'root-fault-replay'})
|
||||||
|
finally: sql(f"INSERT INTO members VALUES ('{chat['id']}','{alice['id']}',0);")
|
||||||
|
return {'same_body':404,'changed_body':404}
|
||||||
|
def schema_ready():
|
||||||
|
sql('ALTER TABLE message_requests RENAME TO message_requests_root_probe;')
|
||||||
|
try:
|
||||||
|
values=[direct(cid,'/health/ready') for cid in apis]
|
||||||
|
assert all(x['status']==503 for x in values),values
|
||||||
|
return values
|
||||||
|
finally: sql('ALTER TABLE message_requests_root_probe RENAME TO message_requests;')
|
||||||
|
def paused_pg():
|
||||||
|
# Warm both pools before freezing the real server.
|
||||||
|
for cid in apis: assert direct(cid,'/api/v1/users/me',alice['token'])['status']==200
|
||||||
|
subprocess.run(['docker','pause',pg],check=True,capture_output=True)
|
||||||
|
try:
|
||||||
|
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as ex:
|
||||||
|
values=list(ex.map(lambda item:direct(apis[0],item,alice['token']),('/health/ready','/api/v1/users/me')))
|
||||||
|
assert all(x['status']==503 and x['elapsed_s']<8 for x in values),values
|
||||||
|
assert all(x['request_id']==x['body']['error']['request_id'] and x['instance_id'] for x in values)
|
||||||
|
finally: subprocess.run(['docker','unpause',pg],check=True,capture_output=True)
|
||||||
|
deadline=time.monotonic()+25
|
||||||
|
while time.monotonic()<deadline:
|
||||||
|
try:
|
||||||
|
recovered=direct(apis[0],'/api/v1/users/me',alice['token'])
|
||||||
|
if recovered['status']==200: break
|
||||||
|
except Exception: pass
|
||||||
|
time.sleep(.5)
|
||||||
|
else: raise AssertionError('API did not recover')
|
||||||
|
return {'during_pause':values,'recovered_status':recovered['status']}
|
||||||
|
def logout_lock():
|
||||||
|
deadline=time.monotonic()+20
|
||||||
|
while time.monotonic()<deadline:
|
||||||
|
try:
|
||||||
|
c.call('GET','/health/ready',schema='Health');break
|
||||||
|
except Exception: time.sleep(.3)
|
||||||
|
actor=c.user('lockout')
|
||||||
|
proc=subprocess.Popen(['docker','exec','-i',pg,'psql','-U','messenger','-d','messenger','-At'],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,text=True)
|
||||||
|
try:
|
||||||
|
proc.stdin.write("BEGIN; LOCK TABLE sessions IN SHARE MODE; SELECT 'ROOT_LOCKED';\n");proc.stdin.flush()
|
||||||
|
while True:
|
||||||
|
line=proc.stdout.readline()
|
||||||
|
if 'ROOT_LOCKED' in line: break
|
||||||
|
if not line: raise AssertionError('lock setup failed')
|
||||||
|
c.call('DELETE','/api/v1/auth/sessions/current',503,actor=actor)
|
||||||
|
c.call('GET','/api/v1/users/me',actor=actor,schema='User')
|
||||||
|
finally:
|
||||||
|
proc.stdin.write('ROLLBACK;\n\\q\n');proc.stdin.flush();proc.communicate(timeout=8)
|
||||||
|
c.call('DELETE','/api/v1/auth/sessions/current',204,actor=actor)
|
||||||
|
c.call('GET','/api/v1/users/me',401,actor=actor)
|
||||||
|
return {'blocked_logout':503,'retry':204,'old_token':401}
|
||||||
|
check('ACL precedes both replay and conflict',acl_replay)
|
||||||
|
check('readiness detects missing mandatory table',schema_ready)
|
||||||
|
check('paused PostgreSQL bounded API error and recovery',paused_pg)
|
||||||
|
check('logout cannot falsely succeed under DB lock',logout_lock)
|
||||||
|
out=args.output or repo/'evidence/teacher-faults-repeat.json';out.write_text(json.dumps({'tests':rows},ensure_ascii=False,indent=2)+'\n')
|
||||||
|
raise SystemExit(any(x['status']=='FAIL' for x in rows))
|
||||||
@@ -0,0 +1,193 @@
|
|||||||
|
"""Independent HTTP regressions derived from teacher review; no production mutation hooks."""
|
||||||
|
import argparse
|
||||||
|
import base64
|
||||||
|
import concurrent.futures
|
||||||
|
import hashlib
|
||||||
|
import importlib.util
|
||||||
|
import json
|
||||||
|
import struct
|
||||||
|
import subprocess
|
||||||
|
import time
|
||||||
|
import urllib.parse
|
||||||
|
import uuid
|
||||||
|
import zlib
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
def png_chunk(kind, content):
|
||||||
|
return struct.pack('!I',len(content))+kind+content+struct.pack('!I',zlib.crc32(kind+content)&0xffffffff)
|
||||||
|
|
||||||
|
|
||||||
|
def tiny_png(filter_byte=0, bad_idat=False, width=1, height=1):
|
||||||
|
return (b'\x89PNG\r\n\x1a\n'+png_chunk(b'IHDR',struct.pack('!IIBBBBB',width,height,8,2,0,0,0))
|
||||||
|
+png_chunk(b'IDAT',b'not-a-zlib-stream' if bad_idat else zlib.compress(bytes([filter_byte,0,0,0])))
|
||||||
|
+png_chunk(b'IEND',b''))
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
p=argparse.ArgumentParser()
|
||||||
|
p.add_argument('--lab',type=int,choices=(3,4,5),required=True)
|
||||||
|
p.add_argument('--repo',type=Path,required=True)
|
||||||
|
p.add_argument('--base-url',required=True)
|
||||||
|
p.add_argument('--output',type=Path,required=True)
|
||||||
|
a=p.parse_args()
|
||||||
|
spec=importlib.util.spec_from_file_location('public_client',a.repo/'tests/client.py')
|
||||||
|
mod=importlib.util.module_from_spec(spec)
|
||||||
|
spec.loader.exec_module(mod)
|
||||||
|
c=mod.Client(a.base_url,timeout=12)
|
||||||
|
results=[]
|
||||||
|
def case(label,fn):
|
||||||
|
started=time.monotonic()
|
||||||
|
try:
|
||||||
|
fn()
|
||||||
|
row={'case':label,'status':'PASS'}
|
||||||
|
except Exception as e:
|
||||||
|
row={'case':label,'status':'FAIL','error':str(e)[:700]}
|
||||||
|
row['elapsed_s']=round(time.monotonic()-started,4)
|
||||||
|
results.append(row)
|
||||||
|
print(row,flush=True)
|
||||||
|
alice,bob,eve,chat=c.bootstrap()
|
||||||
|
path='/api/v1/chats/'+chat['id']+'/messages'
|
||||||
|
def msg(body,key=None,actor=alice,status=201):
|
||||||
|
return c.call('POST',path,status,body=body,actor=actor,headers={'Idempotency-Key':uuid.uuid4().hex if key is None else key},schema='Message' if status==201 else None)
|
||||||
|
def equal(actual,expected):
|
||||||
|
assert actual==expected,'value did not match expected result'
|
||||||
|
for body in ({'text':None},{'text':123},{'text':True},{'text':[]},{'text':'x','TEXT':'y'},{'Text':'x'},{'text':'x','attachment_ids':None},{'text':'x','attachment_ids':{}},{}):
|
||||||
|
case('message rejects wrong types/extra '+str(body),lambda body=body:msg(body,status=400))
|
||||||
|
for key in ('','contains space','x'*129,'bad/key'):
|
||||||
|
case('invalid idempotency key '+repr(key[:20]),lambda key=key:msg({'text':'x'},key=key,status=400))
|
||||||
|
case('missing idempotency key',lambda:c.call('POST',path,400,body={'text':'x'},actor=alice))
|
||||||
|
for body in (b'{bad',b'\xff',b'{"text":"x"}{}'):
|
||||||
|
case('malformed UTF8/JSON '+repr(body),lambda body=body:c.call('POST',path,400,raw=body,actor=alice,headers={'Content-Type':'application/json','Idempotency-Key':uuid.uuid4().hex}))
|
||||||
|
for endpoint in ('/api/v1/chats',path):
|
||||||
|
for query in ('limit=','limit=0','limit=101','limit=abc','limit=1&limit=2','cursor=','cursor=W10','cursor=bnVsbA'):
|
||||||
|
case('pagination '+endpoint+'?'+query,lambda endpoint=endpoint,query=query:c.call('GET',endpoint+'?'+query,400,actor=alice))
|
||||||
|
c.message(alice,chat,'cursor1')
|
||||||
|
c.message(alice,chat,'cursor2')
|
||||||
|
cursor=c.call('GET',path+'?limit=1',actor=alice,schema='MessagePage')['json']['next_cursor']
|
||||||
|
decoded=json.loads(base64.urlsafe_b64decode(cursor+'='*(-len(cursor)%4)))
|
||||||
|
if isinstance(decoded,list) and len(decoded)==4:
|
||||||
|
for index,value in ((2,None),(2,1),(2,'2026-13-01T00:00:00Z'),(3,False),(3,[]),(3,{}),(3,'not-a-uuid')):
|
||||||
|
data=list(decoded); data[index]=value
|
||||||
|
corrupt=base64.urlsafe_b64encode(json.dumps(data).encode()).decode().rstrip('=')
|
||||||
|
case('typed cursor '+str((index,value)),lambda corrupt=corrupt:c.call('GET',path+'?cursor='+corrupt,400,actor=alice))
|
||||||
|
case('invalid UUID path',lambda:c.call('GET','/api/v1/chats/not-a-uuid',400,actor=alice))
|
||||||
|
for bad in ([],{},123,False):
|
||||||
|
case('member UUID '+str(bad),lambda bad=bad:c.call('POST','/api/v1/chats',400,actor=alice,body={'title':'x','member_ids':[alice['id'],bad]}))
|
||||||
|
case('unknown member400',lambda:c.call('POST','/api/v1/chats',400,actor=alice,body={'title':'x','member_ids':[alice['id'],str(uuid.uuid4())]}))
|
||||||
|
for body in (b'{bad',b'{}',b'null',b' '):
|
||||||
|
auth=base64.b64encode((alice['registration']['username']+':'+alice['registration']['password']).encode()).decode()
|
||||||
|
case('login rejects body '+repr(body),lambda body=body,auth=auth:c.call('POST','/api/v1/auth/sessions',400,raw=body,headers={'Authorization':'Basic '+auth,'Content-Type':'application/json'}))
|
||||||
|
case('nonASCII Bearer401',lambda:c.call('GET','/api/v1/users/me',401,headers={'Authorization':'Bearer é'}))
|
||||||
|
for suffix in ('\n',' '):
|
||||||
|
case('username trailing whitespace',lambda suffix=suffix:c.call('POST','/api/v1/users',400,body={'username':'review'+uuid.uuid4().hex[:8]+suffix,'display_name':'x','password':'Password123456'}))
|
||||||
|
case('blank password400',lambda:c.call('POST','/api/v1/users',400,body={'username':'r'+uuid.uuid4().hex[:15],'display_name':'x','password':' '*12}))
|
||||||
|
def unicode_login():
|
||||||
|
username='r'+uuid.uuid4().hex[:15]
|
||||||
|
password='я:'*64
|
||||||
|
user=c.call('POST','/api/v1/users',201,body={'username':username,'display_name':'Никита\0имя','password':password},schema='User')['json']
|
||||||
|
equal(user['display_name'],'Никита\0имя')
|
||||||
|
auth=base64.b64encode((username+':'+password).encode()).decode()
|
||||||
|
session=c.call('POST','/api/v1/auth/sessions',201,headers={'Authorization':'Basic '+auth},schema='Session')['json']
|
||||||
|
equal(session['user'],user)
|
||||||
|
case('UTF8 colon128 password and NUL display name',unicode_login)
|
||||||
|
def canonical_repeat():
|
||||||
|
key=uuid.uuid4().hex
|
||||||
|
original=msg({'text':'canonical'},key)['json']
|
||||||
|
equal(msg({'attachment_ids':[],'text':'canonical'},key)['json'],original)
|
||||||
|
msg({'text':'changed'},key,status=409)
|
||||||
|
case('omitted attachment_ids equals [] and conflict',canonical_repeat)
|
||||||
|
def concurrent_repeat():
|
||||||
|
key=uuid.uuid4().hex
|
||||||
|
with concurrent.futures.ThreadPoolExecutor(max_workers=16) as ex:
|
||||||
|
rows=list(ex.map(lambda _:msg({'text':'concurrent'},key)['json'],range(32)))
|
||||||
|
equal(len({x['id'] for x in rows}),1)
|
||||||
|
equal(len({json.dumps(x,sort_keys=True) for x in rows}),1)
|
||||||
|
case('32 concurrent same key all201 same message',concurrent_repeat)
|
||||||
|
def independent_scope():
|
||||||
|
key=uuid.uuid4().hex
|
||||||
|
one=msg({'text':'scope'},key)['json']
|
||||||
|
two=msg({'text':'scope'},key,actor=bob)['json']
|
||||||
|
assert one['id']!=two['id'] and two['sender_id']==bob['id']
|
||||||
|
another=c.call('POST','/api/v1/chats',201,actor=alice,body={'title':'another','member_ids':[alice['id']]},schema='Chat')['json']
|
||||||
|
three=c.message(alice,another,'scope',key=key)['json']
|
||||||
|
assert three['id']!=one['id'] and three['chat_id']==another['id']
|
||||||
|
case('key scope user and chat',independent_scope)
|
||||||
|
case('outsider cannot send',lambda:msg({'text':'outsider'},actor=eve,status=404))
|
||||||
|
def nul_message():
|
||||||
|
key=uuid.uuid4().hex
|
||||||
|
original=msg({'text':'abc\0def'},key)['json']
|
||||||
|
equal(original['text'],'abc\0def')
|
||||||
|
equal(msg({'text':'abc\0def'},key)['json'],original)
|
||||||
|
allrows=c.call('GET',path+'?limit=100',actor=bob,schema='MessagePage')['json']['items']
|
||||||
|
equal(next(x for x in allrows if x['id']==original['id']),original)
|
||||||
|
case('NUL message exact post replay history',nul_message)
|
||||||
|
def logout():
|
||||||
|
actor=c.user('logout')
|
||||||
|
c.call('GET','/api/v1/users/me',actor=actor,schema='User')
|
||||||
|
c.call('DELETE','/api/v1/auth/sessions/current',204,actor=actor)
|
||||||
|
for _ in range(4): c.call('GET','/api/v1/users/me',401,actor=actor)
|
||||||
|
case('logout visible through all replicas',logout)
|
||||||
|
if a.lab>=4:
|
||||||
|
fixture=(a.repo/'tests/fixtures/sample.png').read_bytes()
|
||||||
|
upload='/api/v1/chats/'+chat['id']+'/attachments'
|
||||||
|
def upl(raw=fixture,mime='image/png',name='sample.png',expected=None):
|
||||||
|
return c.call('POST',upload+'?filename='+urllib.parse.quote(name,safe=''),expected or (201 if a.lab==4 else 202),actor=alice,raw=raw,headers={'Content-Type':mime},schema='Attachment' if expected is None else None)
|
||||||
|
for label,raw,mime in (
|
||||||
|
('header only',fixture[:33],'image/png'),('bad IDAT',tiny_png(bad_idat=True),'image/png'),
|
||||||
|
('invalid filter',tiny_png(filter_byte=5),'image/png'),
|
||||||
|
('empty JPEG scan',bytes.fromhex('ffd8ffc0000b080001000101011100ffda0008010100003f00ffd9'),'image/jpeg'),
|
||||||
|
('MIME mismatch',fixture,'image/jpeg')):
|
||||||
|
case('image rejects '+label,lambda raw=raw,mime=mime:upl(raw=raw,mime=mime,expected=415))
|
||||||
|
jpeg_code="from PIL import Image; from io import BytesIO; import random,sys; im=Image.frombytes('RGB',(800,600),random.Random(42).randbytes(800*600*3)); b=BytesIO(); im.save(b,format='JPEG',quality=95); sys.stdout.buffer.write(b.getvalue())"
|
||||||
|
jpeg=subprocess.check_output([str(a.repo.absolute()/'.venv/bin/python'),'-c',jpeg_code])
|
||||||
|
case('valid real JPEG accepted',lambda:upl(raw=jpeg,mime='image/jpeg',name='real.jpg'))
|
||||||
|
case('half JPEG entropy with EOI rejected',lambda:upl(raw=jpeg[:len(jpeg)//2]+b'\xff\xd9',mime='image/jpeg',name='half.jpg',expected=415))
|
||||||
|
sos=jpeg.index(b'\xff\xda')
|
||||||
|
bad_sos=bytearray(jpeg);bad_sos[sos+5]=250
|
||||||
|
case('JPEG SOS unknown component rejected',lambda:upl(raw=bytes(bad_sos),mime='image/jpeg',name='sos.jpg',expected=415))
|
||||||
|
palette=(b'\x89PNG\r\n\x1a\n'+png_chunk(b'IHDR',struct.pack('!IIBBBBB',1,1,8,3,0,0,0))+png_chunk(b'PLTE',bytes(771))+png_chunk(b'IDAT',zlib.compress(b'\0\0'))+png_chunk(b'IEND',b''))
|
||||||
|
case('PNG invalid palette257 rejected',lambda:upl(raw=palette,expected=415))
|
||||||
|
for name in ('../x.png','a\\b.png','a\0b.png','a\x7fb.png','a\x85b.png',' '):
|
||||||
|
case('filename '+repr(name),lambda name=name:upl(name=name,expected=400))
|
||||||
|
case('filename missing',lambda:c.call('POST',upload,400,actor=alice,raw=fixture,headers={'Content-Type':'image/png'}))
|
||||||
|
case('pixel bomb413',lambda:upl(raw=tiny_png(width=20000,height=10000),expected=413))
|
||||||
|
case('too many bytes413',lambda:upl(raw=fixture+b'x'*(10485761-len(fixture)),expected=413))
|
||||||
|
attachments=[]
|
||||||
|
for _ in range(2):
|
||||||
|
att=upl()['json']
|
||||||
|
if a.lab==5: att=c.wait_ready(alice,att)
|
||||||
|
attachments.append(att)
|
||||||
|
def attachment_checks():
|
||||||
|
ids=[x['id'] for x in reversed(attachments)]
|
||||||
|
key=uuid.uuid4().hex
|
||||||
|
sent=msg({'text':'','attachment_ids':ids},key)['json']
|
||||||
|
equal(sent['attachment_ids'],ids)
|
||||||
|
equal(msg({'text':'','attachment_ids':ids},key)['json'],sent)
|
||||||
|
msg({'text':'','attachment_ids':list(reversed(ids))},key,status=409)
|
||||||
|
rows=c.call('GET',path+'?limit=100',actor=bob,schema='MessagePage')['json']['items']
|
||||||
|
equal(next(x for x in rows if x['id']==sent['id']),sent)
|
||||||
|
for att in attachments:
|
||||||
|
route='/api/v1/attachments/'+att['id']
|
||||||
|
for suffix in ('','/content'): c.call('GET',route+suffix,404,actor=eve)
|
||||||
|
content=c.call('GET',route+'/content',actor=bob)['bytes']
|
||||||
|
equal(hashlib.sha256(content).hexdigest(),att['sha256'])
|
||||||
|
msg({'text':'unknown','attachment_ids':[str(uuid.uuid4())]},status=404)
|
||||||
|
case('attachment order ACL original checksum',attachment_checks)
|
||||||
|
if a.lab==4:
|
||||||
|
case('ready missing thumbnail404',lambda:c.call('GET','/api/v1/attachments/'+attachments[0]['id']+'/content?variant=thumbnail',404,actor=alice))
|
||||||
|
# Valid PNG padded by a legal ancillary chunk, exactly 10 MiB.
|
||||||
|
def exact_limit():
|
||||||
|
base=tiny_png()
|
||||||
|
content=base[:-12]+png_chunk(b'tEXt',b'padding\0'+b'x'*(10485760-len(base)-12-8))+base[-12:]
|
||||||
|
equal(len(content),10485760)
|
||||||
|
att=upl(raw=content)['json']
|
||||||
|
equal(att['size_bytes'],10485760)
|
||||||
|
case('exact10MiB allowed through LB',exact_limit)
|
||||||
|
report={'lab':a.lab,'base_url':a.base_url,'tests':results,'passed':sum(x['status']=='PASS' for x in results),'failed':sum(x['status']=='FAIL' for x in results)}
|
||||||
|
a.output.parent.mkdir(parents=True,exist_ok=True)
|
||||||
|
a.output.write_text(json.dumps(report,ensure_ascii=False,indent=2)+'\n')
|
||||||
|
print('TOTAL',report['passed'],'PASS',report['failed'],'FAIL',flush=True)
|
||||||
|
return int(report['failed']>0)
|
||||||
|
|
||||||
|
if __name__=='__main__': raise SystemExit(main())
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import urllib.error
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
|
wanted = int(sys.argv[1])
|
||||||
|
url = "http://127.0.0.1:" + os.environ.get("PUBLIC_PORT", "8083") + "/health/ready"
|
||||||
|
deadline = time.monotonic() + 40
|
||||||
|
seen = set()
|
||||||
|
while time.monotonic() < deadline:
|
||||||
|
try:
|
||||||
|
with urllib.request.urlopen(url, timeout=2) as response:
|
||||||
|
seen.add(response.headers["X-Instance-Id"])
|
||||||
|
if len(seen) >= wanted:
|
||||||
|
break
|
||||||
|
except (urllib.error.URLError, TimeoutError):
|
||||||
|
seen.clear()
|
||||||
|
time.sleep(0.1)
|
||||||
|
else:
|
||||||
|
raise SystemExit("LB did not expose enough healthy replicas")
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
"""Учебный REST-мессенджер."""
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
import uvicorn
|
||||||
|
|
||||||
|
uvicorn.run(
|
||||||
|
"messenger.app:app",
|
||||||
|
host=os.getenv("APP_HOST", "0.0.0.0"),
|
||||||
|
port=int(os.getenv("APP_PORT", "8080")),
|
||||||
|
workers=1,
|
||||||
|
access_log=False,
|
||||||
|
timeout_graceful_shutdown=5,
|
||||||
|
)
|
||||||
@@ -0,0 +1,239 @@
|
|||||||
|
import base64
|
||||||
|
import binascii
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import time
|
||||||
|
from contextlib import asynccontextmanager
|
||||||
|
from uuid import uuid4
|
||||||
|
|
||||||
|
from fastapi import Depends, FastAPI, Request, Response
|
||||||
|
from fastapi.exceptions import RequestValidationError
|
||||||
|
from fastapi.responses import JSONResponse
|
||||||
|
from starlette.exceptions import HTTPException
|
||||||
|
|
||||||
|
from .domain import Failure, boundary, identifier, page
|
||||||
|
from .models import CreateChat, CreateMessage, CreateUser
|
||||||
|
from .postgres import PostgresStore
|
||||||
|
|
||||||
|
logger = logging.getLogger("messenger")
|
||||||
|
logging.basicConfig(level=os.getenv("LOG_LEVEL", "INFO"), format="%(message)s")
|
||||||
|
INSTANCE_ID = str(uuid4())
|
||||||
|
|
||||||
|
CODES = {
|
||||||
|
400: "invalid_request",
|
||||||
|
401: "unauthorized",
|
||||||
|
404: "not_found",
|
||||||
|
409: "conflict",
|
||||||
|
413: "payload_too_large",
|
||||||
|
415: "unsupported_media_type",
|
||||||
|
429: "rate_limited",
|
||||||
|
503: "unavailable",
|
||||||
|
500: "internal_error",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@asynccontextmanager
|
||||||
|
async def lifespan(app):
|
||||||
|
app.state.store = PostgresStore()
|
||||||
|
logger.info(json.dumps({"event": "started", "storage": "postgres"}))
|
||||||
|
yield
|
||||||
|
app.state.store.close()
|
||||||
|
logger.info(json.dumps({"event": "stopped"}))
|
||||||
|
|
||||||
|
|
||||||
|
app = FastAPI(lifespan=lifespan, docs_url=None, redoc_url=None, openapi_url=None)
|
||||||
|
|
||||||
|
|
||||||
|
def error(request, status, message, headers=None):
|
||||||
|
return JSONResponse(
|
||||||
|
{
|
||||||
|
"error": {
|
||||||
|
"code": CODES.get(status, "invalid_request"),
|
||||||
|
"message": message,
|
||||||
|
"request_id": request.state.request_id,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
status_code=status,
|
||||||
|
headers=headers,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def invalid_json_encoding(request: Request):
|
||||||
|
path = request.url.path
|
||||||
|
if request.method != "POST" or not (
|
||||||
|
path in {"/api/v1/users", "/api/v1/chats"}
|
||||||
|
or re.fullmatch(r"/api/v1/chats/[^/]+/messages", path)
|
||||||
|
):
|
||||||
|
return False
|
||||||
|
raw = await request.body()
|
||||||
|
try:
|
||||||
|
raw.decode("utf-8")
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
return True
|
||||||
|
# Literal NUL is invalid JSON; it also prevents json.loads(bytes) from
|
||||||
|
# autodetecting BOM-less UTF-16/32. Escaped JSON \u0000 remains valid.
|
||||||
|
return b"\x00" in raw
|
||||||
|
|
||||||
|
|
||||||
|
@app.middleware("http")
|
||||||
|
async def request_log(request: Request, call_next):
|
||||||
|
request.state.request_id = str(uuid4())
|
||||||
|
start = time.perf_counter()
|
||||||
|
try:
|
||||||
|
if request.method == "POST" and request.url.path == "/api/v1/auth/sessions" and await request.body():
|
||||||
|
response = error(request, 400, "Вход не принимает тело запроса")
|
||||||
|
elif await invalid_json_encoding(request):
|
||||||
|
response = error(request, 400, "JSON должен быть закодирован в UTF-8")
|
||||||
|
else:
|
||||||
|
response = await call_next(request)
|
||||||
|
except Exception:
|
||||||
|
logger.error(
|
||||||
|
json.dumps({"event": "unexpected_error", "request_id": request.state.request_id})
|
||||||
|
)
|
||||||
|
response = error(request, 500, "Внутренняя ошибка")
|
||||||
|
response.headers["X-Request-Id"] = request.state.request_id
|
||||||
|
response.headers["X-Instance-Id"] = INSTANCE_ID
|
||||||
|
route = request.scope.get("route")
|
||||||
|
logger.info(
|
||||||
|
json.dumps(
|
||||||
|
{
|
||||||
|
"event": "request",
|
||||||
|
"request_id": request.state.request_id,
|
||||||
|
"method": request.method,
|
||||||
|
"route": getattr(route, "path", "unknown"),
|
||||||
|
"status": response.status_code,
|
||||||
|
"duration_ms": round((time.perf_counter() - start) * 1000, 3),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
@app.exception_handler(Failure)
|
||||||
|
async def domain_error(request, exc):
|
||||||
|
return error(request, exc.status, exc.message, exc.headers)
|
||||||
|
|
||||||
|
|
||||||
|
@app.exception_handler(RequestValidationError)
|
||||||
|
async def validation_error(request, exc):
|
||||||
|
return error(request, 400, "Неверный JSON или поля запроса")
|
||||||
|
|
||||||
|
|
||||||
|
@app.exception_handler(HTTPException)
|
||||||
|
async def http_error(request, exc):
|
||||||
|
return error(request, exc.status_code, "Неверный запрос", exc.headers)
|
||||||
|
|
||||||
|
|
||||||
|
def bearer_failure():
|
||||||
|
return Failure(
|
||||||
|
401, "Требуется действующая сессия", {"WWW-Authenticate": 'Bearer realm="messenger"'}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def bearer(request):
|
||||||
|
parts = request.headers.get("Authorization", "").split()
|
||||||
|
if len(parts) != 2 or parts[0].lower() != "bearer":
|
||||||
|
raise bearer_failure()
|
||||||
|
return parts[1]
|
||||||
|
|
||||||
|
|
||||||
|
def actor(request: Request):
|
||||||
|
user = request.app.state.store.authenticate(bearer(request))
|
||||||
|
if user is None:
|
||||||
|
raise bearer_failure()
|
||||||
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/api/v1/auth/sessions", status_code=201)
|
||||||
|
def login(request: Request):
|
||||||
|
headers = {"WWW-Authenticate": 'Basic realm="messenger", charset="UTF-8"'}
|
||||||
|
parts = request.headers.get("Authorization", "").split()
|
||||||
|
try:
|
||||||
|
if len(parts) != 2 or parts[0].lower() != "basic" or len(parts[1]) > 2048:
|
||||||
|
raise ValueError
|
||||||
|
decoded = base64.b64decode(parts[1], validate=True).decode("utf-8")
|
||||||
|
username, password = decoded.split(":", 1)
|
||||||
|
if not re.fullmatch(r"[a-z0-9_]{3,32}", username) or not 12 <= len(password) <= 128:
|
||||||
|
raise ValueError
|
||||||
|
except (ValueError, UnicodeError, binascii.Error):
|
||||||
|
raise Failure(401, "Неверные учётные данные", headers) from None
|
||||||
|
session = request.app.state.store.login(username, password)
|
||||||
|
if session is None:
|
||||||
|
raise Failure(401, "Неверные учётные данные", headers)
|
||||||
|
return session
|
||||||
|
|
||||||
|
|
||||||
|
@app.delete("/api/v1/auth/sessions/current", status_code=204)
|
||||||
|
def logout(request: Request, user=Depends(actor)):
|
||||||
|
if not request.app.state.store.logout(bearer(request)):
|
||||||
|
raise bearer_failure()
|
||||||
|
return Response(status_code=204)
|
||||||
|
|
||||||
|
|
||||||
|
def pagination(request, scope):
|
||||||
|
allowed = {"limit", "cursor"}
|
||||||
|
if any(k not in allowed for k in request.query_params):
|
||||||
|
raise Failure(400, "Неизвестный параметр запроса")
|
||||||
|
if any(len(request.query_params.getlist(k)) > 1 for k in allowed):
|
||||||
|
raise Failure(400, "Повторный параметр запроса")
|
||||||
|
value = request.query_params.get("limit", "50")
|
||||||
|
if len(value) > 3 or not re.fullmatch(r"[0-9]+", value) or not 1 <= int(value) <= 100:
|
||||||
|
raise Failure(400, "limit должен быть целым от 1 до 100")
|
||||||
|
return int(value), boundary(scope, request.query_params.get("cursor"))
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/health/live")
|
||||||
|
def live():
|
||||||
|
return {"status": "ok"}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/health/ready")
|
||||||
|
def ready(request: Request):
|
||||||
|
if not request.app.state.store.ready():
|
||||||
|
raise Failure(503, "Хранилище недоступно")
|
||||||
|
return {"status": "ok"}
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/api/v1/users", status_code=201)
|
||||||
|
def register(data: CreateUser, request: Request):
|
||||||
|
return request.app.state.store.register(data.model_dump(mode="json"))
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/api/v1/users/me")
|
||||||
|
def me(user=Depends(actor)):
|
||||||
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/api/v1/chats", status_code=201)
|
||||||
|
def create_chat(data: CreateChat, request: Request, user=Depends(actor)):
|
||||||
|
return request.app.state.store.create_chat(user["id"], data.model_dump(mode="json"))
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/api/v1/chats")
|
||||||
|
def chats(request: Request, user=Depends(actor)):
|
||||||
|
scope = "chats:" + user["id"]
|
||||||
|
limit, after = pagination(request, scope)
|
||||||
|
return page(request.app.state.store.list_chats(user["id"], after, limit), limit, scope)
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/api/v1/chats/{chat_id}")
|
||||||
|
def chat(chat_id: str, request: Request, user=Depends(actor)):
|
||||||
|
return request.app.state.store.chat(user["id"], identifier(chat_id))
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/api/v1/chats/{chat_id}/messages", status_code=201)
|
||||||
|
def send(chat_id: str, data: CreateMessage, request: Request, user=Depends(actor)):
|
||||||
|
key = request.headers.get("Idempotency-Key", "")
|
||||||
|
if not re.fullmatch(r"[A-Za-z0-9._:-]{1,128}", key):
|
||||||
|
raise Failure(400, "Требуется корректный Idempotency-Key")
|
||||||
|
return request.app.state.store.send(user["id"], identifier(chat_id), data.text, key)
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/api/v1/chats/{chat_id}/messages")
|
||||||
|
def history(chat_id: str, request: Request, user=Depends(actor)):
|
||||||
|
cid = identifier(chat_id)
|
||||||
|
scope = "messages:" + cid
|
||||||
|
limit, after = pagination(request, scope)
|
||||||
|
return page(request.app.state.store.history(user["id"], cid, after, limit), limit, scope)
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
def secret(name: str) -> str:
|
||||||
|
filename = os.environ.get(name + "_FILE")
|
||||||
|
value = Path(filename).read_text().strip() if filename else os.environ.get(name, "")
|
||||||
|
if not value:
|
||||||
|
raise RuntimeError("Отсутствует настройка " + name)
|
||||||
|
return value
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import base64
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
from datetime import UTC, datetime
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
|
|
||||||
|
class Failure(Exception):
|
||||||
|
def __init__(self, status: int, message: str, headers: dict | None = None):
|
||||||
|
self.status = status
|
||||||
|
self.message = message
|
||||||
|
self.headers = headers or {}
|
||||||
|
|
||||||
|
|
||||||
|
def timestamp() -> str:
|
||||||
|
return datetime.now(UTC).isoformat(timespec="microseconds").replace("+00:00", "Z")
|
||||||
|
|
||||||
|
|
||||||
|
def identifier(value: str) -> str:
|
||||||
|
try:
|
||||||
|
return str(UUID(value))
|
||||||
|
except (ValueError, TypeError, AttributeError):
|
||||||
|
raise Failure(400, "Некорректный UUID") from None
|
||||||
|
|
||||||
|
|
||||||
|
def boundary(scope: str, cursor: str | None) -> tuple[str, str] | None:
|
||||||
|
if cursor is None:
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
if not cursor or len(cursor) > 1024 or not re.fullmatch(r"[A-Za-z0-9_-]+", cursor):
|
||||||
|
raise ValueError
|
||||||
|
data = json.loads(base64.urlsafe_b64decode(cursor + "=" * (-len(cursor) % 4)))
|
||||||
|
if (
|
||||||
|
not isinstance(data, list)
|
||||||
|
or len(data) != 4
|
||||||
|
or type(data[0]) is not int
|
||||||
|
or data[0] != 1
|
||||||
|
or data[1] != scope
|
||||||
|
):
|
||||||
|
raise ValueError
|
||||||
|
date, uid = data[2:]
|
||||||
|
if not isinstance(date, str) or not re.fullmatch(
|
||||||
|
r"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\.[0-9]{1,6})?Z",
|
||||||
|
date,
|
||||||
|
):
|
||||||
|
raise ValueError
|
||||||
|
datetime.fromisoformat(date.replace("Z", "+00:00"))
|
||||||
|
if not isinstance(uid, str) or str(UUID(uid)) != uid:
|
||||||
|
raise ValueError
|
||||||
|
return date, uid
|
||||||
|
except (ValueError, TypeError, KeyError, UnicodeError):
|
||||||
|
raise Failure(400, "Некорректный cursor или область запроса") from None
|
||||||
|
|
||||||
|
|
||||||
|
def page(items: list[dict], limit: int, scope: str) -> dict:
|
||||||
|
more = len(items) > limit
|
||||||
|
selected = items[:limit]
|
||||||
|
cursor = None
|
||||||
|
if more:
|
||||||
|
last = selected[-1]
|
||||||
|
payload = json.dumps([1, scope, last["created_at"], last["id"]], separators=(",", ":"))
|
||||||
|
cursor = base64.urlsafe_b64encode(payload.encode()).decode().rstrip("=")
|
||||||
|
return {"items": selected, "next_cursor": cursor}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import hashlib
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import psycopg
|
||||||
|
|
||||||
|
from .config import secret
|
||||||
|
|
||||||
|
|
||||||
|
def migrate():
|
||||||
|
with psycopg.connect(secret("DATABASE_URL")) as conn:
|
||||||
|
# Serialize independent migration processes without changing application data.
|
||||||
|
conn.execute("SELECT pg_advisory_xact_lock(2301002)")
|
||||||
|
conn.execute(
|
||||||
|
"CREATE TABLE IF NOT EXISTS schema_migrations "
|
||||||
|
"(name text PRIMARY KEY, checksum text NOT NULL)"
|
||||||
|
)
|
||||||
|
for path in sorted(Path("migrations").glob("*.sql")):
|
||||||
|
checksum = hashlib.sha256(path.read_bytes()).hexdigest()
|
||||||
|
old = conn.execute(
|
||||||
|
"SELECT checksum FROM schema_migrations WHERE name=%s", (path.name,)
|
||||||
|
).fetchone()
|
||||||
|
if old:
|
||||||
|
if old[0] != checksum:
|
||||||
|
raise RuntimeError("Изменена применённая миграция: " + path.name)
|
||||||
|
continue
|
||||||
|
conn.execute(path.read_text())
|
||||||
|
conn.execute("INSERT INTO schema_migrations VALUES (%s,%s)", (path.name, checksum))
|
||||||
|
print("Applied", path.name)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
migrate()
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import re
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
|
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
|
||||||
|
|
||||||
|
|
||||||
|
class RequestModel(BaseModel):
|
||||||
|
model_config = ConfigDict(extra="forbid")
|
||||||
|
|
||||||
|
@field_validator("*", mode="after")
|
||||||
|
@classmethod
|
||||||
|
def nonblank(cls, value):
|
||||||
|
if isinstance(value, str) and not value.strip():
|
||||||
|
raise ValueError("Строка не может состоять из пробелов")
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
class CreateUser(RequestModel):
|
||||||
|
username: StrictStr = Field(pattern=r"^[a-z0-9_]{3,32}$")
|
||||||
|
display_name: StrictStr = Field(min_length=1, max_length=100)
|
||||||
|
password: StrictStr = Field(min_length=12, max_length=128)
|
||||||
|
|
||||||
|
@field_validator("username")
|
||||||
|
@classmethod
|
||||||
|
def full_username(cls, value):
|
||||||
|
if not re.fullmatch(r"[a-z0-9_]{3,32}", value):
|
||||||
|
raise ValueError("Неверное имя пользователя")
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
class CreateChat(RequestModel):
|
||||||
|
title: StrictStr = Field(min_length=1, max_length=100)
|
||||||
|
member_ids: list[UUID] = Field(min_length=1, max_length=100)
|
||||||
|
|
||||||
|
@field_validator("member_ids", mode="before")
|
||||||
|
@classmethod
|
||||||
|
def string_ids(cls, value):
|
||||||
|
if not isinstance(value, list) or any(not isinstance(x, str) for x in value):
|
||||||
|
raise ValueError("Ожидается массив UUID-строк")
|
||||||
|
return value
|
||||||
|
|
||||||
|
@field_validator("member_ids")
|
||||||
|
@classmethod
|
||||||
|
def unique_ids(cls, value):
|
||||||
|
if len(set(value)) != len(value):
|
||||||
|
raise ValueError("Участники не должны повторяться")
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
class CreateMessage(RequestModel):
|
||||||
|
text: StrictStr = Field(min_length=1, max_length=4000)
|
||||||
|
attachment_ids: list[UUID] = Field(default_factory=list, max_length=0)
|
||||||
@@ -0,0 +1,292 @@
|
|||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import secrets
|
||||||
|
from contextlib import contextmanager
|
||||||
|
from datetime import UTC, datetime, timedelta
|
||||||
|
from threading import BoundedSemaphore
|
||||||
|
from uuid import UUID, uuid4
|
||||||
|
|
||||||
|
import psycopg
|
||||||
|
import redis
|
||||||
|
from argon2 import PasswordHasher
|
||||||
|
from argon2.exceptions import VerificationError
|
||||||
|
from psycopg.rows import dict_row
|
||||||
|
from psycopg_pool import ConnectionPool, PoolTimeout, TooManyRequests
|
||||||
|
|
||||||
|
from .config import secret
|
||||||
|
from .domain import Failure, timestamp
|
||||||
|
|
||||||
|
logger = logging.getLogger("messenger")
|
||||||
|
KDF_SLOTS = BoundedSemaphore(2)
|
||||||
|
KDF = PasswordHasher(time_cost=2, memory_cost=65536, parallelism=1)
|
||||||
|
DUMMY_HASH = KDF.hash("invalid-user-dummy-password")
|
||||||
|
|
||||||
|
|
||||||
|
class DeadlineConnection(psycopg.Connection):
|
||||||
|
def wait(self, gen, interval=0.1, timeout=None):
|
||||||
|
try:
|
||||||
|
return super().wait(gen, interval=interval, timeout=timeout or 3.0)
|
||||||
|
except psycopg.errors._WaitTimeout:
|
||||||
|
# A paused server cannot complete cancellation. Discard an uncertain
|
||||||
|
# connection instead of returning it to the pool or waiting forever.
|
||||||
|
self.pgconn.finish()
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
def public(row):
|
||||||
|
return {
|
||||||
|
k: (
|
||||||
|
str(v)
|
||||||
|
if isinstance(v, UUID)
|
||||||
|
else v.astimezone(UTC).isoformat(timespec="microseconds").replace("+00:00", "Z")
|
||||||
|
if isinstance(v, datetime)
|
||||||
|
else bytes(v).decode("utf-8")
|
||||||
|
if isinstance(v, (bytes, memoryview))
|
||||||
|
else v
|
||||||
|
)
|
||||||
|
for k, v in row.items()
|
||||||
|
if k not in {"password_hash", "token_digest"}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class PostgresStore:
|
||||||
|
def __init__(self):
|
||||||
|
self.pool = ConnectionPool(
|
||||||
|
secret("DATABASE_URL"),
|
||||||
|
connection_class=DeadlineConnection,
|
||||||
|
min_size=1,
|
||||||
|
max_size=int(os.getenv("POOL_MAX_SIZE", "8")),
|
||||||
|
timeout=2,
|
||||||
|
max_waiting=32,
|
||||||
|
kwargs={
|
||||||
|
"autocommit": True,
|
||||||
|
"row_factory": dict_row,
|
||||||
|
"connect_timeout": 2,
|
||||||
|
"options": "-c statement_timeout=2500 -c lock_timeout=1500",
|
||||||
|
},
|
||||||
|
check=ConnectionPool.check_connection,
|
||||||
|
)
|
||||||
|
self.pool.wait(timeout=15)
|
||||||
|
self.cache = redis.Redis.from_url(
|
||||||
|
secret("CACHE_URL"),
|
||||||
|
socket_connect_timeout=0.2,
|
||||||
|
socket_timeout=0.2,
|
||||||
|
decode_responses=True,
|
||||||
|
)
|
||||||
|
self.ttl = int(os.getenv("SESSION_TTL_SECONDS", "3600"))
|
||||||
|
if self.ttl < 1:
|
||||||
|
raise RuntimeError("SESSION_TTL_SECONDS должен быть положительным")
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def connection(self):
|
||||||
|
try:
|
||||||
|
with self.pool.connection() as conn:
|
||||||
|
yield conn
|
||||||
|
except (
|
||||||
|
psycopg.OperationalError,
|
||||||
|
psycopg.InterfaceError,
|
||||||
|
PoolTimeout,
|
||||||
|
TooManyRequests,
|
||||||
|
psycopg.errors.QueryCanceled,
|
||||||
|
psycopg.errors.LockNotAvailable,
|
||||||
|
):
|
||||||
|
raise Failure(503, "Хранилище временно недоступно") from None
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
self.cache.close()
|
||||||
|
self.pool.close()
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
try:
|
||||||
|
with self.connection() as conn:
|
||||||
|
conn.execute(
|
||||||
|
"SELECT u.id,c.id,m.chat_id,msg.id,s.token_digest,r.key "
|
||||||
|
"FROM users u,chats c,members m,messages msg,sessions s,message_requests r "
|
||||||
|
"WHERE false"
|
||||||
|
)
|
||||||
|
return True
|
||||||
|
except (Failure, psycopg.Error):
|
||||||
|
return False
|
||||||
|
|
||||||
|
def _cached_user(self, uid):
|
||||||
|
key = "user:v1:" + uid
|
||||||
|
try:
|
||||||
|
value = self.cache.get(key)
|
||||||
|
if value:
|
||||||
|
cached = json.loads(value)
|
||||||
|
if (
|
||||||
|
isinstance(cached, dict)
|
||||||
|
and cached.get("id") == uid
|
||||||
|
and set(cached) == {"id", "username", "display_name", "created_at"}
|
||||||
|
):
|
||||||
|
return cached
|
||||||
|
except (redis.RedisError, ValueError, TypeError):
|
||||||
|
logger.warning(json.dumps({"event": "cache_bypass"}))
|
||||||
|
user = self.user(uid)
|
||||||
|
if user:
|
||||||
|
try:
|
||||||
|
self.cache.setex(key, 60, json.dumps(user))
|
||||||
|
except redis.RedisError:
|
||||||
|
logger.warning(json.dumps({"event": "cache_bypass"}))
|
||||||
|
return user
|
||||||
|
|
||||||
|
def user(self, uid):
|
||||||
|
with self.connection() as conn:
|
||||||
|
row = conn.execute(
|
||||||
|
"SELECT id,username,display_name,created_at FROM users WHERE id=%s", (uid,)
|
||||||
|
).fetchone()
|
||||||
|
return public(row) if row else None
|
||||||
|
|
||||||
|
def register(self, data):
|
||||||
|
with KDF_SLOTS:
|
||||||
|
hashed = KDF.hash(data.pop("password"))
|
||||||
|
uid = str(uuid4())
|
||||||
|
try:
|
||||||
|
with self.connection() as conn:
|
||||||
|
row = conn.execute(
|
||||||
|
"INSERT INTO users VALUES (%s,%s,%s,%s,%s) "
|
||||||
|
"RETURNING id,username,display_name,created_at",
|
||||||
|
(uid, data["username"], data["display_name"].encode("utf-8"), hashed, timestamp()),
|
||||||
|
).fetchone()
|
||||||
|
return public(row)
|
||||||
|
except psycopg.errors.UniqueViolation:
|
||||||
|
raise Failure(409, "Имя пользователя занято") from None
|
||||||
|
|
||||||
|
def login(self, username, password):
|
||||||
|
with self.connection() as conn:
|
||||||
|
row = conn.execute("SELECT * FROM users WHERE username=%s", (username,)).fetchone()
|
||||||
|
try:
|
||||||
|
with KDF_SLOTS:
|
||||||
|
KDF.verify(row["password_hash"] if row else DUMMY_HASH, password)
|
||||||
|
except VerificationError:
|
||||||
|
return None
|
||||||
|
if row is None:
|
||||||
|
return None
|
||||||
|
token = secrets.token_urlsafe(32)
|
||||||
|
digest = hashlib.sha256(token.encode()).hexdigest()
|
||||||
|
expires = datetime.now(UTC) + timedelta(seconds=self.ttl)
|
||||||
|
with self.connection() as conn:
|
||||||
|
conn.execute("INSERT INTO sessions VALUES (%s,%s,%s)", (digest, row["id"], expires))
|
||||||
|
return {
|
||||||
|
"token": token,
|
||||||
|
"token_type": "Bearer",
|
||||||
|
"expires_at": public({"v": expires})["v"],
|
||||||
|
"user": public(row),
|
||||||
|
}
|
||||||
|
|
||||||
|
def authenticate(self, token):
|
||||||
|
if not token or len(token) > 512:
|
||||||
|
return None
|
||||||
|
digest = hashlib.sha256(token.encode()).hexdigest()
|
||||||
|
# Session validity always comes from PostgreSQL, including on a cache hit.
|
||||||
|
with self.connection() as conn:
|
||||||
|
row = conn.execute(
|
||||||
|
"SELECT s.user_id FROM sessions s WHERE s.token_digest=%s AND s.expires_at>now()",
|
||||||
|
(digest,),
|
||||||
|
).fetchone()
|
||||||
|
return self._cached_user(str(row["user_id"])) if row else None
|
||||||
|
|
||||||
|
def logout(self, token):
|
||||||
|
with self.connection() as conn:
|
||||||
|
row = conn.execute(
|
||||||
|
"DELETE FROM sessions WHERE token_digest=%s AND expires_at>now() RETURNING user_id",
|
||||||
|
(hashlib.sha256(token.encode()).hexdigest(),),
|
||||||
|
).fetchone()
|
||||||
|
return row is not None
|
||||||
|
|
||||||
|
def create_chat(self, actor, data):
|
||||||
|
if actor not in data["member_ids"]:
|
||||||
|
raise Failure(400, "Вызывающий должен входить в чат")
|
||||||
|
cid = str(uuid4())
|
||||||
|
try:
|
||||||
|
with self.connection() as conn, conn.transaction():
|
||||||
|
row = conn.execute(
|
||||||
|
"INSERT INTO chats VALUES (%s,%s,%s) RETURNING *",
|
||||||
|
(cid, data["title"].encode("utf-8"), timestamp()),
|
||||||
|
).fetchone()
|
||||||
|
for index, uid in enumerate(data["member_ids"]):
|
||||||
|
conn.execute("INSERT INTO members VALUES (%s,%s,%s)", (cid, uid, index))
|
||||||
|
return {**public(row), "member_ids": data["member_ids"]}
|
||||||
|
except psycopg.errors.ForeignKeyViolation:
|
||||||
|
raise Failure(400, "Неизвестный участник") from None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _chat(conn, actor, cid):
|
||||||
|
row = conn.execute(
|
||||||
|
"SELECT c.* FROM chats c JOIN members m ON m.chat_id=c.id "
|
||||||
|
"WHERE c.id=%s AND m.user_id=%s",
|
||||||
|
(cid, actor),
|
||||||
|
).fetchone()
|
||||||
|
if row is None:
|
||||||
|
raise Failure(404, "Объект не найден")
|
||||||
|
members = conn.execute(
|
||||||
|
"SELECT user_id FROM members WHERE chat_id=%s ORDER BY position", (cid,)
|
||||||
|
).fetchall()
|
||||||
|
return {**public(row), "member_ids": [str(m["user_id"]) for m in members]}
|
||||||
|
|
||||||
|
def chat(self, actor, cid):
|
||||||
|
with self.connection() as conn:
|
||||||
|
return self._chat(conn, actor, cid)
|
||||||
|
|
||||||
|
def list_chats(self, actor, after, limit):
|
||||||
|
with self.connection() as conn:
|
||||||
|
sql = "SELECT c.* FROM chats c JOIN members m ON m.chat_id=c.id WHERE m.user_id=%s"
|
||||||
|
params = [actor]
|
||||||
|
if after:
|
||||||
|
sql += " AND (c.created_at,c.id)>(%s,%s)"
|
||||||
|
params.extend(after)
|
||||||
|
sql += " ORDER BY c.created_at,c.id LIMIT %s"
|
||||||
|
params.append(limit + 1)
|
||||||
|
rows = conn.execute(sql, params).fetchall()
|
||||||
|
return [self._chat(conn, actor, str(row["id"])) for row in rows]
|
||||||
|
|
||||||
|
def send(self, actor, cid, text, key):
|
||||||
|
body_digest = hashlib.sha256(
|
||||||
|
json.dumps({"text": text, "attachment_ids": []}, sort_keys=True,
|
||||||
|
ensure_ascii=False, separators=(",", ":")).encode()
|
||||||
|
).hexdigest()
|
||||||
|
with self.connection() as conn, conn.transaction():
|
||||||
|
self._chat(conn, actor, cid)
|
||||||
|
# Serializes exactly this semantic key across all API processes. Hash
|
||||||
|
# collisions can only serialize unrelated requests, never mix results.
|
||||||
|
scope = json.dumps([actor, "POST", cid, key], separators=(",", ":"))
|
||||||
|
lock = int.from_bytes(hashlib.sha256(scope.encode()).digest()[:8], "big", signed=True)
|
||||||
|
conn.execute("SELECT pg_advisory_xact_lock(%s)", (lock,))
|
||||||
|
old = conn.execute(
|
||||||
|
"SELECT body_digest,response FROM message_requests "
|
||||||
|
"WHERE actor_id=%s AND chat_id=%s AND key=%s AND expires_at>now()",
|
||||||
|
(actor, cid, key),
|
||||||
|
).fetchone()
|
||||||
|
if old:
|
||||||
|
if old["body_digest"] != body_digest:
|
||||||
|
raise Failure(409, "Ключ уже использован для другого сообщения")
|
||||||
|
return json.loads(bytes(old["response"]).decode("utf-8"))
|
||||||
|
conn.execute(
|
||||||
|
"DELETE FROM message_requests WHERE actor_id=%s AND chat_id=%s AND key=%s",
|
||||||
|
(actor, cid, key),
|
||||||
|
)
|
||||||
|
row = conn.execute(
|
||||||
|
"INSERT INTO messages VALUES (%s,%s,%s,%s,%s) RETURNING *",
|
||||||
|
(str(uuid4()), cid, actor, text.encode("utf-8"), timestamp()),
|
||||||
|
).fetchone()
|
||||||
|
response = public(row)
|
||||||
|
conn.execute(
|
||||||
|
"INSERT INTO message_requests(actor_id,chat_id,key,body_digest,response,expires_at) "
|
||||||
|
"VALUES (%s,%s,%s,%s,%s,now()+interval '24 hours')",
|
||||||
|
(actor, cid, key, body_digest, json.dumps(response).encode("utf-8")),
|
||||||
|
)
|
||||||
|
return response
|
||||||
|
|
||||||
|
def history(self, actor, cid, after, limit):
|
||||||
|
with self.connection() as conn:
|
||||||
|
self._chat(conn, actor, cid)
|
||||||
|
sql = "SELECT * FROM messages WHERE chat_id=%s"
|
||||||
|
params = [cid]
|
||||||
|
if after:
|
||||||
|
sql += " AND (created_at,id)>(%s,%s)"
|
||||||
|
params.extend(after)
|
||||||
|
sql += " ORDER BY created_at,id LIMIT %s"
|
||||||
|
params.append(limit + 1)
|
||||||
|
return [public(row) for row in conn.execute(sql, params).fetchall()]
|
||||||
@@ -0,0 +1,194 @@
|
|||||||
|
import base64
|
||||||
|
import os
|
||||||
|
import threading
|
||||||
|
import uuid
|
||||||
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
from urllib.parse import quote
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from client import LAB, Client
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def scenario():
|
||||||
|
c = Client(os.environ.get("BASE_URL", "http://127.0.0.1:8081"))
|
||||||
|
return c, *c.bootstrap()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"body",
|
||||||
|
[
|
||||||
|
{"text": ""},
|
||||||
|
{"text": " \n\t"},
|
||||||
|
{"text": 1},
|
||||||
|
{"text": True},
|
||||||
|
{"text": None},
|
||||||
|
{"text": "x", "sender_id": str(uuid.uuid4())},
|
||||||
|
{"text": "x", "unknown": 1},
|
||||||
|
{"text": "x" * 4001},
|
||||||
|
{},
|
||||||
|
[],
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_invalid_message(scenario, body):
|
||||||
|
c, alice, _, _, chat = scenario
|
||||||
|
c.call("POST", f"/api/v1/chats/{chat['id']}/messages", 400, actor=alice, body=body)
|
||||||
|
|
||||||
|
|
||||||
|
def test_malformed_json(scenario):
|
||||||
|
c, alice, _, _, chat = scenario
|
||||||
|
c.call(
|
||||||
|
"POST",
|
||||||
|
f"/api/v1/chats/{chat['id']}/messages",
|
||||||
|
400,
|
||||||
|
actor=alice,
|
||||||
|
raw=b'{"text":',
|
||||||
|
headers={"Content-Type": "application/json"},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_acl_and_unknown_chat(scenario):
|
||||||
|
c, alice, _, eve, chat = scenario
|
||||||
|
for cid in [chat["id"], str(uuid.uuid4())]:
|
||||||
|
for suffix in ["", "/messages"]:
|
||||||
|
c.call("GET", f"/api/v1/chats/{cid}{suffix}", 404, actor=eve)
|
||||||
|
c.call(
|
||||||
|
"POST",
|
||||||
|
f"/api/v1/chats/{cid}/messages",
|
||||||
|
404,
|
||||||
|
actor=eve,
|
||||||
|
body={"text": "x"},
|
||||||
|
headers={"Idempotency-Key": str(uuid.uuid4())},
|
||||||
|
)
|
||||||
|
c.call("GET", "/api/v1/chats/not-a-uuid", 400, actor=alice)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("name", ["ab", "UPPER", "a-b", "a" * 33, "имя", "abc\n"])
|
||||||
|
def test_username_validation(scenario, name):
|
||||||
|
c, alice, *_ = scenario
|
||||||
|
body = {**alice["registration"], "username": name}
|
||||||
|
c.call("POST", "/api/v1/users", 400, body=body)
|
||||||
|
|
||||||
|
|
||||||
|
def test_unicode_and_limits(scenario):
|
||||||
|
c, alice, _, _, chat = scenario
|
||||||
|
text = "Ё👩💻漢字" * 500
|
||||||
|
assert c.message(alice, chat, text)["json"]["text"] == text
|
||||||
|
c.call(
|
||||||
|
"POST",
|
||||||
|
"/api/v1/users",
|
||||||
|
400,
|
||||||
|
body={
|
||||||
|
**alice["registration"],
|
||||||
|
"username": "u_" + uuid.uuid4().hex[:12],
|
||||||
|
"display_name": " ",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("value", ["0", "101", "1.5", "true", "-1", "", "1&limit=2"])
|
||||||
|
def test_invalid_limit(scenario, value):
|
||||||
|
c, alice, _, _, chat = scenario
|
||||||
|
c.call("GET", f"/api/v1/chats/{chat['id']}/messages?limit={value}", 400, actor=alice)
|
||||||
|
|
||||||
|
|
||||||
|
def test_pagination_and_cursor_scope(scenario):
|
||||||
|
c, alice, bob, _, chat = scenario
|
||||||
|
expected = [c.message(alice, chat, str(i))["json"] for i in range(13)]
|
||||||
|
path = f"/api/v1/chats/{chat['id']}/messages"
|
||||||
|
result, cursor, first = [], None, None
|
||||||
|
for i in range(20):
|
||||||
|
url = path + f"?limit={2 if i == 0 else 3}"
|
||||||
|
if cursor:
|
||||||
|
url += "&cursor=" + quote(cursor, safe="")
|
||||||
|
data = c.call("GET", url, actor=bob, schema="MessagePage")["json"]
|
||||||
|
result += data["items"]
|
||||||
|
cursor = data["next_cursor"]
|
||||||
|
first = first or cursor
|
||||||
|
if cursor is None:
|
||||||
|
break
|
||||||
|
assert result == sorted(expected, key=lambda m: (m["created_at"], m["id"]))
|
||||||
|
other = c.call(
|
||||||
|
"POST",
|
||||||
|
"/api/v1/chats",
|
||||||
|
201,
|
||||||
|
actor=alice,
|
||||||
|
body={"title": "другой", "member_ids": [alice["id"]]},
|
||||||
|
schema="Chat",
|
||||||
|
)["json"]
|
||||||
|
c.call("GET", f"/api/v1/chats/{other['id']}/messages?cursor={first}", 400, actor=alice)
|
||||||
|
c.call("GET", path + "?cursor=broken", 400, actor=alice)
|
||||||
|
|
||||||
|
|
||||||
|
def test_chat_validation_and_atomicity(scenario):
|
||||||
|
c, alice, bob, _, _ = scenario
|
||||||
|
before = c.call("GET", "/api/v1/chats?limit=100", actor=alice, schema="ChatPage")["json"]
|
||||||
|
for members in [
|
||||||
|
[bob["id"]],
|
||||||
|
[alice["id"], alice["id"]],
|
||||||
|
[alice["id"], str(uuid.uuid4())],
|
||||||
|
[],
|
||||||
|
[123],
|
||||||
|
]:
|
||||||
|
c.call(
|
||||||
|
"POST",
|
||||||
|
"/api/v1/chats",
|
||||||
|
400,
|
||||||
|
actor=alice,
|
||||||
|
body={"title": "не должен появиться", "member_ids": members},
|
||||||
|
)
|
||||||
|
after = c.call("GET", "/api/v1/chats?limit=100", actor=alice, schema="ChatPage")["json"]
|
||||||
|
assert before == after
|
||||||
|
|
||||||
|
|
||||||
|
def test_concurrent_messages(scenario):
|
||||||
|
c, alice, bob, _, chat = scenario
|
||||||
|
barrier = threading.Barrier(10)
|
||||||
|
|
||||||
|
def sender(i):
|
||||||
|
local = Client(c.base)
|
||||||
|
barrier.wait()
|
||||||
|
return [local.message(alice, chat, f"{i}:{j}")["json"] for j in range(10)]
|
||||||
|
|
||||||
|
with ThreadPoolExecutor(max_workers=10) as pool:
|
||||||
|
sent = [m for batch in pool.map(sender, range(10)) for m in batch]
|
||||||
|
data = c.call(
|
||||||
|
"GET", f"/api/v1/chats/{chat['id']}/messages?limit=100", actor=bob, schema="MessagePage"
|
||||||
|
)["json"]
|
||||||
|
assert len(sent) == len({m["id"] for m in sent}) == len(data["items"]) == 100
|
||||||
|
assert {m["id"] for m in sent} == {m["id"] for m in data["items"]}
|
||||||
|
assert data["next_cursor"] is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_registration_race(scenario):
|
||||||
|
c, alice, *_ = scenario
|
||||||
|
body = {**alice["registration"], "username": "race_" + uuid.uuid4().hex[:12]}
|
||||||
|
barrier = threading.Barrier(10)
|
||||||
|
|
||||||
|
def register(_):
|
||||||
|
local = Client(c.base)
|
||||||
|
barrier.wait()
|
||||||
|
return local.call("POST", "/api/v1/users", [201, 409], body=body)["status"]
|
||||||
|
|
||||||
|
with ThreadPoolExecutor(max_workers=10) as pool:
|
||||||
|
statuses = list(pool.map(register, range(10)))
|
||||||
|
assert statuses.count(201) == 1
|
||||||
|
assert statuses.count(409) == 9
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(LAB < 2, reason="Сессии появляются в ЛР2")
|
||||||
|
def test_sessions(scenario):
|
||||||
|
c, alice, _, eve, _ = scenario
|
||||||
|
credential = base64.b64encode(
|
||||||
|
(alice["registration"]["username"] + ":wrong-password").encode()
|
||||||
|
).decode()
|
||||||
|
c.call("POST", "/api/v1/auth/sessions", 401, headers={"Authorization": "Basic " + credential})
|
||||||
|
c.call("GET", "/api/v1/users/me", 401, headers={"X-User-Id": alice["id"]})
|
||||||
|
assert (
|
||||||
|
c.call(
|
||||||
|
"GET", "/api/v1/users/me", actor=alice, headers={"X-User-Id": eve["id"]}, schema="User"
|
||||||
|
)["json"]
|
||||||
|
== alice["user"]
|
||||||
|
)
|
||||||
|
c.call("DELETE", "/api/v1/auth/sessions/current", 204, actor=alice)
|
||||||
|
c.call("GET", "/api/v1/users/me", 401, actor=alice)
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import base64
|
||||||
|
import json
|
||||||
|
from uuid import uuid4
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from messenger.domain import Failure, boundary
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"version,date",
|
||||||
|
[
|
||||||
|
(True, "2026-01-01T00:00:00Z"),
|
||||||
|
(1.0, "2026-01-01T00:00:00Z"),
|
||||||
|
(1, "2026-W01-1T00:00:00Z"),
|
||||||
|
(1, "20260101T000000Z"),
|
||||||
|
(1, "2026-01-01 00:00:00Z"),
|
||||||
|
(1, "2026-01-01X00:00:00Z"),
|
||||||
|
(1, "2026-02-30T00:00:00Z"),
|
||||||
|
(1, "2026-01-01T00:00:00.1234567Z"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_boundary_rejects_python_iso_extensions(version, date):
|
||||||
|
payload = [version, "scope", date, str(uuid4())]
|
||||||
|
cursor = base64.urlsafe_b64encode(json.dumps(payload).encode()).decode().rstrip("=")
|
||||||
|
with pytest.raises(Failure) as error:
|
||||||
|
boundary("scope", cursor)
|
||||||
|
assert error.value.status == 400
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"date", ["2026-01-01T00:00:00Z", "2026-01-01T00:00:00.1Z", "2026-01-01T00:00:00.123456Z"]
|
||||||
|
)
|
||||||
|
def test_boundary_preserves_generated_format(date):
|
||||||
|
uid = str(uuid4())
|
||||||
|
cursor = (
|
||||||
|
base64.urlsafe_b64encode(json.dumps([1, "scope", date, uid]).encode()).decode().rstrip("=")
|
||||||
|
)
|
||||||
|
assert boundary("scope", cursor) == (date, uid)
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
import base64
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import uuid
|
||||||
|
from urllib.parse import quote
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from client import LAB, Client
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def edge_scenario():
|
||||||
|
client = Client(os.environ.get("BASE_URL", "http://127.0.0.1:8081"))
|
||||||
|
return client, *client.bootstrap()
|
||||||
|
|
||||||
|
|
||||||
|
def encoded_cursor(value):
|
||||||
|
return base64.urlsafe_b64encode(json.dumps(value).encode()).decode().rstrip("=")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("identity", ["missing", "malformed", "unknown"])
|
||||||
|
def test_invalid_identity(edge_scenario, identity):
|
||||||
|
client, _, _, _, chat = edge_scenario
|
||||||
|
headers = {}
|
||||||
|
if identity == "malformed":
|
||||||
|
headers["X-User-Id"] = "not-a-uuid"
|
||||||
|
elif identity == "unknown":
|
||||||
|
headers["X-User-Id"] = str(uuid.uuid4())
|
||||||
|
for path in ["/api/v1/users/me", "/api/v1/chats", f"/api/v1/chats/{chat['id']}/messages"]:
|
||||||
|
client.call("GET", path, 401, headers=headers)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("uid", [None, [], {}, 123, True, "not-a-uuid"])
|
||||||
|
def test_cursor_rejects_non_uuid_boundary(edge_scenario, uid):
|
||||||
|
client, alice, _, _, chat = edge_scenario
|
||||||
|
payload = [1, "messages:" + chat["id"], "2026-10-30T12:00:00.000000Z", uid]
|
||||||
|
cursor = quote(encoded_cursor(payload), safe="")
|
||||||
|
client.call("GET", f"/api/v1/chats/{chat['id']}/messages?cursor={cursor}", 400, actor=alice)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"payload", [None, {}, [], [1], [1, "wrong-scope", "2026-10-30T12:00:00Z", str(uuid.uuid4())]]
|
||||||
|
)
|
||||||
|
def test_cursor_rejects_wrong_shape(edge_scenario, payload):
|
||||||
|
client, alice, _, _, chat = edge_scenario
|
||||||
|
cursor = quote(encoded_cursor(payload), safe="")
|
||||||
|
client.call("GET", f"/api/v1/chats/{chat['id']}/messages?cursor={cursor}", 400, actor=alice)
|
||||||
|
|
||||||
|
|
||||||
|
def test_request_id_is_present_and_not_reused(edge_scenario):
|
||||||
|
client, alice, _, _, _ = edge_scenario
|
||||||
|
first = client.call("GET", "/health/live", schema="Health")
|
||||||
|
second = client.call("GET", "/health/ready", schema="Health")
|
||||||
|
error = client.call("GET", "/api/v1/chats/malformed", 400, actor=alice)
|
||||||
|
values = [r["headers"]["X-Request-Id"] for r in [first, second, error]]
|
||||||
|
assert len(set(values)) == 3
|
||||||
|
assert error["json"]["error"]["request_id"] == values[-1]
|
||||||
|
|
||||||
|
|
||||||
|
def test_unicode_codepoint_boundaries(edge_scenario):
|
||||||
|
client, alice, _, _, chat = edge_scenario
|
||||||
|
username = "unicode_" + uuid.uuid4().hex[:12]
|
||||||
|
registration = {"username": username, "display_name": "😀" * 100}
|
||||||
|
if LAB >= 2:
|
||||||
|
registration["password"] = "unicode-test-" + uuid.uuid4().hex
|
||||||
|
user = client.call(
|
||||||
|
"POST",
|
||||||
|
"/api/v1/users",
|
||||||
|
201,
|
||||||
|
body=registration,
|
||||||
|
schema="User",
|
||||||
|
)["json"]
|
||||||
|
assert user["display_name"] == "😀" * 100
|
||||||
|
client.call(
|
||||||
|
"POST", "/api/v1/users", 400, body={"username": username + "x", "display_name": "😀" * 101}
|
||||||
|
)
|
||||||
|
message = client.message(alice, chat, "😀" * 4000)["json"]
|
||||||
|
assert message["text"] == "😀" * 4000
|
||||||
|
client.call(
|
||||||
|
"POST", f"/api/v1/chats/{chat['id']}/messages", 400, actor=alice, body={"text": "😀" * 4001}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_empty_history_and_cursor_exhaustion(edge_scenario):
|
||||||
|
client, alice, _, _, chat = edge_scenario
|
||||||
|
path = f"/api/v1/chats/{chat['id']}/messages"
|
||||||
|
empty = client.call("GET", path, actor=alice, schema="MessagePage")["json"]
|
||||||
|
assert empty == {"items": [], "next_cursor": None}
|
||||||
|
message = client.message(alice, chat, "одна запись")["json"]
|
||||||
|
data = client.call("GET", path + "?limit=1", actor=alice, schema="MessagePage")["json"]
|
||||||
|
assert data == {"items": [message], "next_cursor": None}
|
||||||
|
|
||||||
|
|
||||||
|
def test_missing_chat_is_hidden_like_foreign_chat(edge_scenario):
|
||||||
|
client, _, _, eve, chat = edge_scenario
|
||||||
|
foreign = client.call("GET", f"/api/v1/chats/{chat['id']}", 404, actor=eve)["json"]
|
||||||
|
missing = client.call("GET", f"/api/v1/chats/{uuid.uuid4()}", 404, actor=eve)["json"]
|
||||||
|
assert foreign["error"]["code"] == missing["error"]["code"] == "not_found"
|
||||||
|
assert foreign["error"]["message"] == missing["error"]["message"]
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
import base64
|
||||||
|
import codecs
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from client import Client
|
||||||
|
|
||||||
|
ENCODINGS = [
|
||||||
|
"utf-16",
|
||||||
|
"utf-16-le",
|
||||||
|
"utf-16-be",
|
||||||
|
"utf-16-be-bom",
|
||||||
|
"utf-32",
|
||||||
|
"utf-32-le",
|
||||||
|
"utf-32-be",
|
||||||
|
"utf-32-be-bom",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def encoded(body, encoding):
|
||||||
|
text = json.dumps(body, ensure_ascii=False)
|
||||||
|
if encoding == "utf-16-be-bom":
|
||||||
|
return codecs.BOM_UTF16_BE + text.encode("utf-16-be")
|
||||||
|
if encoding == "utf-32-be-bom":
|
||||||
|
return codecs.BOM_UTF32_BE + text.encode("utf-32-be")
|
||||||
|
return text.encode(encoding)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="module")
|
||||||
|
def encoding_scenario():
|
||||||
|
c = Client(os.environ["BASE_URL"])
|
||||||
|
return c, *c.bootstrap()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("encoding", ENCODINGS)
|
||||||
|
def test_non_utf8_registration_has_no_write(encoding_scenario, encoding):
|
||||||
|
c, *_ = encoding_scenario
|
||||||
|
body = {
|
||||||
|
"username": "enc_" + uuid.uuid4().hex[:14],
|
||||||
|
"display_name": "Никита\u0000имя",
|
||||||
|
"password": "Пароль:тестовый-12345",
|
||||||
|
}
|
||||||
|
c.call(
|
||||||
|
"POST",
|
||||||
|
"/api/v1/users",
|
||||||
|
400,
|
||||||
|
raw=encoded(body, encoding),
|
||||||
|
headers={"Content-Type": "application/json"},
|
||||||
|
)
|
||||||
|
# UNIQUE username proves the rejected request did not insert a user.
|
||||||
|
created = c.call("POST", "/api/v1/users", 201, body=body, schema="User")["json"]
|
||||||
|
assert created["display_name"] == body["display_name"]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("encoding", ENCODINGS)
|
||||||
|
def test_non_utf8_chat_has_no_write(encoding_scenario, encoding):
|
||||||
|
c, alice, *_ = encoding_scenario
|
||||||
|
before = c.call("GET", "/api/v1/chats?limit=100", actor=alice, schema="ChatPage")["json"]
|
||||||
|
body = {"title": "Чат\u0000" + uuid.uuid4().hex, "member_ids": [alice["id"]]}
|
||||||
|
c.call(
|
||||||
|
"POST",
|
||||||
|
"/api/v1/chats",
|
||||||
|
400,
|
||||||
|
actor=alice,
|
||||||
|
raw=encoded(body, encoding),
|
||||||
|
headers={"Content-Type": "application/json"},
|
||||||
|
)
|
||||||
|
after = c.call("GET", "/api/v1/chats?limit=100", actor=alice, schema="ChatPage")["json"]
|
||||||
|
assert before == after
|
||||||
|
assert (
|
||||||
|
c.call("POST", "/api/v1/chats", 201, actor=alice, body=body, schema="Chat")["json"]["title"]
|
||||||
|
== body["title"]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("encoding", ENCODINGS)
|
||||||
|
def test_non_utf8_message_has_no_write(encoding_scenario, encoding):
|
||||||
|
c, alice, _, _, chat = encoding_scenario
|
||||||
|
path = f"/api/v1/chats/{chat['id']}/messages"
|
||||||
|
key = uuid.uuid4().hex
|
||||||
|
body = {"text": "Сообщение\u0000" + key}
|
||||||
|
c.call(
|
||||||
|
"POST",
|
||||||
|
path,
|
||||||
|
400,
|
||||||
|
actor=alice,
|
||||||
|
raw=encoded(body, encoding),
|
||||||
|
headers={"Content-Type": "application/json", "Idempotency-Key": key},
|
||||||
|
)
|
||||||
|
history = c.call("GET", path + "?limit=100", actor=alice, schema="MessagePage")["json"]["items"]
|
||||||
|
assert all(item["text"] != body["text"] for item in history)
|
||||||
|
good = c.call(
|
||||||
|
"POST",
|
||||||
|
path,
|
||||||
|
201,
|
||||||
|
actor=alice,
|
||||||
|
body=body,
|
||||||
|
headers={"Idempotency-Key": key},
|
||||||
|
schema="Message",
|
||||||
|
)["json"]
|
||||||
|
repeat = c.call(
|
||||||
|
"POST",
|
||||||
|
path,
|
||||||
|
201,
|
||||||
|
actor=alice,
|
||||||
|
body=body,
|
||||||
|
headers={"Idempotency-Key": key},
|
||||||
|
schema="Message",
|
||||||
|
)["json"]
|
||||||
|
assert good == repeat and good["text"] == body["text"]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("encoding", ["utf-8", "utf-8-sig"])
|
||||||
|
def test_valid_utf8_registration_and_login(encoding_scenario, encoding):
|
||||||
|
c, *_ = encoding_scenario
|
||||||
|
body = {
|
||||||
|
"username": "utf8_" + uuid.uuid4().hex[:14],
|
||||||
|
"display_name": "Юникод\u0000😀",
|
||||||
|
"password": "Пароль:тестовый-12345",
|
||||||
|
}
|
||||||
|
user = c.call(
|
||||||
|
"POST",
|
||||||
|
"/api/v1/users",
|
||||||
|
201,
|
||||||
|
raw=encoded(body, encoding),
|
||||||
|
headers={"Content-Type": "application/json"},
|
||||||
|
schema="User",
|
||||||
|
)["json"]
|
||||||
|
assert user["display_name"] == body["display_name"]
|
||||||
|
credential = base64.b64encode((body["username"] + ":" + body["password"]).encode()).decode()
|
||||||
|
session = c.call(
|
||||||
|
"POST",
|
||||||
|
"/api/v1/auth/sessions",
|
||||||
|
201,
|
||||||
|
headers={"Authorization": "Basic " + credential},
|
||||||
|
schema="Session",
|
||||||
|
)["json"]
|
||||||
|
assert session["user"] == user
|
||||||
@@ -0,0 +1,181 @@
|
|||||||
|
import base64
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import uuid
|
||||||
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from client import Client
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="module")
|
||||||
|
def shared():
|
||||||
|
c = Client(os.environ["BASE_URL"])
|
||||||
|
return c, *c.bootstrap()
|
||||||
|
|
||||||
|
|
||||||
|
def test_concurrent_idempotency_and_semantic_empty_attachments(shared):
|
||||||
|
c, alice, _, _, chat = shared
|
||||||
|
path = f"/api/v1/chats/{chat['id']}/messages"
|
||||||
|
key = uuid.uuid4().hex
|
||||||
|
|
||||||
|
def post(i):
|
||||||
|
return Client(os.environ["BASE_URL"]).call(
|
||||||
|
"POST",
|
||||||
|
path,
|
||||||
|
201,
|
||||||
|
schema="Message",
|
||||||
|
actor=alice,
|
||||||
|
body={"text": "same", **({"attachment_ids": []} if i % 2 else {})},
|
||||||
|
headers={"Idempotency-Key": key},
|
||||||
|
)
|
||||||
|
|
||||||
|
with ThreadPoolExecutor(max_workers=10) as pool:
|
||||||
|
results = list(pool.map(post, range(20)))
|
||||||
|
assert len({r["json"]["id"] for r in results}) == 1
|
||||||
|
assert len({r["headers"]["X-Instance-Id"] for r in results}) >= 2
|
||||||
|
assert all(r["json"] == results[0]["json"] for r in results)
|
||||||
|
c.call(
|
||||||
|
"POST", path, 409, actor=alice, body={"text": "different"}, headers={"Idempotency-Key": key}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_key_scope_and_acl(shared):
|
||||||
|
c, alice, bob, eve, chat = shared
|
||||||
|
path = f"/api/v1/chats/{chat['id']}/messages"
|
||||||
|
key = uuid.uuid4().hex
|
||||||
|
first = c.call(
|
||||||
|
"POST",
|
||||||
|
path,
|
||||||
|
201,
|
||||||
|
schema="Message",
|
||||||
|
actor=alice,
|
||||||
|
body={"text": "a"},
|
||||||
|
headers={"Idempotency-Key": key},
|
||||||
|
)["json"]
|
||||||
|
other = c.call(
|
||||||
|
"POST",
|
||||||
|
path,
|
||||||
|
201,
|
||||||
|
schema="Message",
|
||||||
|
actor=bob,
|
||||||
|
body={"text": "b"},
|
||||||
|
headers={"Idempotency-Key": key},
|
||||||
|
)["json"]
|
||||||
|
assert first["id"] != other["id"]
|
||||||
|
for _ in range(2):
|
||||||
|
c.call("POST", path, 404, actor=eve, body={"text": "a"}, headers={"Idempotency-Key": key})
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("key", [None, "", "x" * 129, "bad key", "bad/key", "é"])
|
||||||
|
def test_invalid_idempotency_key(shared, key):
|
||||||
|
c, alice, _, _, chat = shared
|
||||||
|
c.call(
|
||||||
|
"POST",
|
||||||
|
f"/api/v1/chats/{chat['id']}/messages",
|
||||||
|
400,
|
||||||
|
actor=alice,
|
||||||
|
body={"text": "x"},
|
||||||
|
headers={} if key is None else {"Idempotency-Key": key},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_lossless_nul_message_replay_and_history(shared):
|
||||||
|
c, alice, _, _, chat = shared
|
||||||
|
key = uuid.uuid4().hex
|
||||||
|
path = f"/api/v1/chats/{chat['id']}/messages"
|
||||||
|
body = {"text": "abc\u0000def"}
|
||||||
|
first = c.call(
|
||||||
|
"POST",
|
||||||
|
path,
|
||||||
|
201,
|
||||||
|
schema="Message",
|
||||||
|
actor=alice,
|
||||||
|
body=body,
|
||||||
|
headers={"Idempotency-Key": key},
|
||||||
|
)["json"]
|
||||||
|
repeat = c.call(
|
||||||
|
"POST",
|
||||||
|
path,
|
||||||
|
201,
|
||||||
|
schema="Message",
|
||||||
|
actor=alice,
|
||||||
|
body=body,
|
||||||
|
headers={"Idempotency-Key": key},
|
||||||
|
)["json"]
|
||||||
|
assert first == repeat
|
||||||
|
assert first["text"] == body["text"]
|
||||||
|
history = c.call("GET", path, 200, schema="MessagePage", actor=alice)["json"]["items"]
|
||||||
|
assert next(m for m in history if m["id"] == first["id"]) == first
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("uid", [[], {}, 123, False, None])
|
||||||
|
def test_typed_invalid_cursor(shared, uid):
|
||||||
|
c, alice, _, _, chat = shared
|
||||||
|
payload = [1, "messages:" + chat["id"], "2026-10-30T12:00:00Z", uid]
|
||||||
|
cursor = base64.urlsafe_b64encode(json.dumps(payload).encode()).decode().rstrip("=")
|
||||||
|
c.call("GET", f"/api/v1/chats/{chat['id']}/messages?cursor={cursor}", 400, actor=alice)
|
||||||
|
|
||||||
|
|
||||||
|
def test_empty_cursor_and_bad_utf8(shared):
|
||||||
|
c, alice, _, _, chat = shared
|
||||||
|
for path in ["/api/v1/chats", f"/api/v1/chats/{chat['id']}/messages"]:
|
||||||
|
c.call("GET", path + "?cursor=", 400, actor=alice)
|
||||||
|
response = c.call(
|
||||||
|
"POST", "/api/v1/users", 400, raw=b"\xff", headers={"Content-Type": "application/json"}
|
||||||
|
)
|
||||||
|
assert response["json"]["error"]["code"] == "invalid_request"
|
||||||
|
assert response["headers"]["X-Instance-Id"]
|
||||||
|
c.call("GET", "/api/v1/users/me", 401, headers={"Authorization": "Bearer é"})
|
||||||
|
|
||||||
|
|
||||||
|
def test_login_body_is_rejected(shared):
|
||||||
|
c, alice, *_ = shared
|
||||||
|
registration = alice["registration"]
|
||||||
|
basic = base64.b64encode(
|
||||||
|
(registration["username"] + ":" + registration["password"]).encode()
|
||||||
|
).decode()
|
||||||
|
for body in [b"{}", b"{bad", b"x"]:
|
||||||
|
c.call(
|
||||||
|
"POST",
|
||||||
|
"/api/v1/auth/sessions",
|
||||||
|
400,
|
||||||
|
raw=body,
|
||||||
|
headers={"Authorization": "Basic " + basic},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"date",
|
||||||
|
[
|
||||||
|
"2026-W01-1T00:00:00Z",
|
||||||
|
"20260101T000000Z",
|
||||||
|
"2026-01-01 00:00:00Z",
|
||||||
|
"2026-01-01X00:00:00Z",
|
||||||
|
"2026-01-01T00:00:00+00:00",
|
||||||
|
"2026-02-30T00:00:00Z",
|
||||||
|
"2026-01-01T24:00:00Z",
|
||||||
|
"2026-01-01T00:00:00.1234567Z",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_cursor_rejects_noncanonical_dates_over_http(shared, date):
|
||||||
|
c, alice, _, _, chat = shared
|
||||||
|
for path, scope in [
|
||||||
|
("/api/v1/chats", "chats:" + alice["id"]),
|
||||||
|
(f"/api/v1/chats/{chat['id']}/messages", "messages:" + chat["id"]),
|
||||||
|
]:
|
||||||
|
payload = [1, scope, date, str(uuid.uuid4())]
|
||||||
|
cursor = base64.urlsafe_b64encode(json.dumps(payload).encode()).decode().rstrip("=")
|
||||||
|
c.call("GET", path + "?cursor=" + cursor, 400, actor=alice)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("version", [True, 1.0])
|
||||||
|
def test_cursor_rejects_noninteger_version_over_http(shared, version):
|
||||||
|
c, alice, _, _, chat = shared
|
||||||
|
for path, scope in [
|
||||||
|
("/api/v1/chats", "chats:" + alice["id"]),
|
||||||
|
(f"/api/v1/chats/{chat['id']}/messages", "messages:" + chat["id"]),
|
||||||
|
]:
|
||||||
|
payload = [version, scope, "2026-01-01T00:00:00Z", str(uuid.uuid4())]
|
||||||
|
cursor = base64.urlsafe_b64encode(json.dumps(payload).encode()).decode().rstrip("=")
|
||||||
|
c.call("GET", path + "?cursor=" + cursor, 400, actor=alice)
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import base64
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from client import Client
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("password", ["x" * 11, "x" * 129, "😀" * 129, 123, None, True])
|
||||||
|
def test_password_contract(password):
|
||||||
|
import os
|
||||||
|
|
||||||
|
c = Client(os.environ["BASE_URL"])
|
||||||
|
c.call(
|
||||||
|
"POST",
|
||||||
|
"/api/v1/users",
|
||||||
|
400,
|
||||||
|
body={
|
||||||
|
"username": "pwd_" + uuid.uuid4().hex[:12],
|
||||||
|
"display_name": "Тест",
|
||||||
|
"password": password,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_full_unicode_password_and_colon():
|
||||||
|
import os
|
||||||
|
|
||||||
|
c = Client(os.environ["BASE_URL"])
|
||||||
|
username = "pwd_" + uuid.uuid4().hex[:12]
|
||||||
|
password = "😀" * 126 + ":Я"
|
||||||
|
user = c.call(
|
||||||
|
"POST",
|
||||||
|
"/api/v1/users",
|
||||||
|
201,
|
||||||
|
body={"username": username, "display_name": "Пароль128", "password": password},
|
||||||
|
schema="User",
|
||||||
|
)["json"]
|
||||||
|
good = base64.b64encode((username + ":" + password).encode()).decode()
|
||||||
|
session = c.call(
|
||||||
|
"POST",
|
||||||
|
"/api/v1/auth/sessions",
|
||||||
|
201,
|
||||||
|
headers={"Authorization": "bAsIc " + good},
|
||||||
|
schema="Session",
|
||||||
|
)["json"]
|
||||||
|
actor = {"id": user["id"], "token": session["token"]}
|
||||||
|
assert session["user"] == user
|
||||||
|
bad = base64.b64encode((username + ":" + password[:-1] + "Б").encode()).decode()
|
||||||
|
c.call("POST", "/api/v1/auth/sessions", 401, headers={"Authorization": "Basic " + bad})
|
||||||
|
c.call("GET", "/api/v1/users/me", 401, headers={"Authorization": "Basic " + good})
|
||||||
|
c.call("GET", "/api/v1/users/me", actor=actor, schema="User")
|
||||||
|
c.call("DELETE", "/api/v1/auth/sessions/current", 204, actor=actor)
|
||||||
|
c.call("GET", "/api/v1/users/me", 401, actor=actor)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("credential", ["Basic !invalid", "Basic", "Bearer abc", "", "Basic YTpi"])
|
||||||
|
def test_invalid_basic(credential):
|
||||||
|
import os
|
||||||
|
|
||||||
|
Client(os.environ["BASE_URL"]).call(
|
||||||
|
"POST", "/api/v1/auth/sessions", 401, headers={"Authorization": credential}
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user