From 4107ee27a3073a06704ca92920179af0ab31fe85 Mon Sep 17 00:00:00 2001 From: Ilya Date: Thu, 22 Oct 2026 22:24:06 +0300 Subject: [PATCH 01/15] =?UTF-8?q?lab4:=20=D1=81=D1=82=D0=B5=D0=BD=D0=B4=20?= =?UTF-8?q?MinIO,=20=D1=81=D0=B5=D0=BA=D1=80=D0=B5=D1=82=D1=8B,=20bootstra?= =?UTF-8?q?p,=20=D1=85=D1=83=D0=BA=D0=B8;=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=20=D0=BF=D1=80=D0=B8=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20lab3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 73 +- Dockerfile | 38 + Makefile | 43 +- app/.gitignore | 59 + app/.prettierrc | 6 + app/README.md | 314 + app/nest-cli.json | 15 + app/oxlint.json | 10 + app/package-lock.json | 7401 +++++++++++++++++ app/package.json | 66 + app/scripts/graph-modules.ts | 123 + app/src/app.module.ts | 33 + app/src/auth/auth.controller.ts | 79 + app/src/auth/auth.module.ts | 16 + app/src/auth/auth.service.ts | 63 + app/src/auth/session.repository.ts | 35 + app/src/chats/chat.ts | 6 + app/src/chats/chats.controller.ts | 49 + app/src/chats/chats.module.ts | 16 + app/src/chats/chats.repository.ts | 109 + app/src/chats/chats.service.ts | 61 + app/src/chats/dto/create-chat.dto.ts | 26 + app/src/common/auth/current-user.decorator.ts | 10 + app/src/common/auth/current-user.guard.ts | 85 + app/src/common/errors/api-error.ts | 7 + app/src/common/errors/api-exception.filter.ts | 168 + app/src/common/http/cursor.spec.ts | 85 + app/src/common/http/cursor.ts | 54 + app/src/common/http/page.ts | 4 + app/src/common/http/request-id.interceptor.ts | 59 + .../validation/code-point-length.spec.ts | 43 + .../common/validation/code-point-length.ts | 38 + app/src/config/app-config.module.ts | 16 + app/src/config/app-config.schema.ts | 101 + app/src/config/instance-id.ts | 14 + app/src/database/database.client.ts | 90 + app/src/database/database.module.ts | 10 + app/src/database/migration.runner.ts | 63 + app/src/database/migrations/001_initial.sql | 41 + .../migrations/002_timestamp_precision.sql | 5 + .../migrations/003_idempotency_keys.sql | 20 + .../migrations/004_pg_stat_statements.sql | 9 + app/src/health/health.controller.ts | 17 + app/src/health/health.module.ts | 12 + app/src/health/health.service.spec.ts | 91 + app/src/health/health.service.ts | 60 + app/src/main.ts | 63 + .../cache/messages-cache.metrics.spec.ts | 37 + .../messages/cache/messages-cache.module.ts | 11 + .../cache/messages-cache.service.spec.ts | 72 + .../messages/cache/messages-cache.service.ts | 205 + app/src/messages/dto/create-message.dto.ts | 8 + .../idempotency/idempotency-gc.cli.ts | 33 + .../idempotency/idempotency.module.ts | 10 + .../idempotency.repository.spec.ts | 19 + .../idempotency/idempotency.repository.ts | 119 + app/src/messages/idempotency/idempotency.ts | 18 + app/src/messages/message.ts | 7 + app/src/messages/messages.controller.ts | 53 + app/src/messages/messages.module.ts | 26 + app/src/messages/messages.repository.spec.ts | 47 + app/src/messages/messages.repository.ts | 128 + app/src/messages/messages.service.spec.ts | 115 + app/src/messages/messages.service.ts | 186 + app/src/metrics/metrics.controller.ts | 54 + app/src/metrics/metrics.module.ts | 10 + app/src/metrics/metrics.service.spec.ts | 62 + app/src/metrics/metrics.service.ts | 69 + app/src/redis/redis.client.ts | 145 + app/src/redis/redis.module.ts | 10 + app/src/types.d.ts | 7 + app/src/users/dto/create-user.dto.ts | 22 + app/src/users/user.ts | 6 + app/src/users/users.controller.ts | 22 + app/src/users/users.module.ts | 16 + app/src/users/users.repository.ts | 71 + app/src/users/users.service.ts | 31 + app/test/app.e2e-spec.ts | 674 ++ app/test/dependency-failures.e2e-spec.ts | 799 ++ app/tsconfig.build.json | 8 + app/tsconfig.json | 22 + app/vitest.config.e2e.ts | 14 + app/vitest.config.ts | 13 + compose.yaml | 227 + evidence/lab4/bootstrap-rerun.txt | 12 + infra/haproxy/haproxy.cfg | 61 + infra/minio/bootstrap.sh | 28 + scripts/app-e2e.sh | 22 + scripts/init-env.sh | 40 + scripts/restart.sh | 8 + scripts/start-replica.sh | 11 + scripts/stop-one.sh | 35 + 92 files changed, 13388 insertions(+), 11 deletions(-) create mode 100644 Dockerfile create mode 100644 app/.gitignore create mode 100644 app/.prettierrc create mode 100644 app/README.md create mode 100644 app/nest-cli.json create mode 100644 app/oxlint.json create mode 100644 app/package-lock.json create mode 100644 app/package.json create mode 100644 app/scripts/graph-modules.ts create mode 100644 app/src/app.module.ts create mode 100644 app/src/auth/auth.controller.ts create mode 100644 app/src/auth/auth.module.ts create mode 100644 app/src/auth/auth.service.ts create mode 100644 app/src/auth/session.repository.ts create mode 100644 app/src/chats/chat.ts create mode 100644 app/src/chats/chats.controller.ts create mode 100644 app/src/chats/chats.module.ts create mode 100644 app/src/chats/chats.repository.ts create mode 100644 app/src/chats/chats.service.ts create mode 100644 app/src/chats/dto/create-chat.dto.ts create mode 100644 app/src/common/auth/current-user.decorator.ts create mode 100644 app/src/common/auth/current-user.guard.ts create mode 100644 app/src/common/errors/api-error.ts create mode 100644 app/src/common/errors/api-exception.filter.ts create mode 100644 app/src/common/http/cursor.spec.ts create mode 100644 app/src/common/http/cursor.ts create mode 100644 app/src/common/http/page.ts create mode 100644 app/src/common/http/request-id.interceptor.ts create mode 100644 app/src/common/validation/code-point-length.spec.ts create mode 100644 app/src/common/validation/code-point-length.ts create mode 100644 app/src/config/app-config.module.ts create mode 100644 app/src/config/app-config.schema.ts create mode 100644 app/src/config/instance-id.ts create mode 100644 app/src/database/database.client.ts create mode 100644 app/src/database/database.module.ts create mode 100644 app/src/database/migration.runner.ts create mode 100644 app/src/database/migrations/001_initial.sql create mode 100644 app/src/database/migrations/002_timestamp_precision.sql create mode 100644 app/src/database/migrations/003_idempotency_keys.sql create mode 100644 app/src/database/migrations/004_pg_stat_statements.sql create mode 100644 app/src/health/health.controller.ts create mode 100644 app/src/health/health.module.ts create mode 100644 app/src/health/health.service.spec.ts create mode 100644 app/src/health/health.service.ts create mode 100644 app/src/main.ts create mode 100644 app/src/messages/cache/messages-cache.metrics.spec.ts create mode 100644 app/src/messages/cache/messages-cache.module.ts create mode 100644 app/src/messages/cache/messages-cache.service.spec.ts create mode 100644 app/src/messages/cache/messages-cache.service.ts create mode 100644 app/src/messages/dto/create-message.dto.ts create mode 100644 app/src/messages/idempotency/idempotency-gc.cli.ts create mode 100644 app/src/messages/idempotency/idempotency.module.ts create mode 100644 app/src/messages/idempotency/idempotency.repository.spec.ts create mode 100644 app/src/messages/idempotency/idempotency.repository.ts create mode 100644 app/src/messages/idempotency/idempotency.ts create mode 100644 app/src/messages/message.ts create mode 100644 app/src/messages/messages.controller.ts create mode 100644 app/src/messages/messages.module.ts create mode 100644 app/src/messages/messages.repository.spec.ts create mode 100644 app/src/messages/messages.repository.ts create mode 100644 app/src/messages/messages.service.spec.ts create mode 100644 app/src/messages/messages.service.ts create mode 100644 app/src/metrics/metrics.controller.ts create mode 100644 app/src/metrics/metrics.module.ts create mode 100644 app/src/metrics/metrics.service.spec.ts create mode 100644 app/src/metrics/metrics.service.ts create mode 100644 app/src/redis/redis.client.ts create mode 100644 app/src/redis/redis.module.ts create mode 100644 app/src/types.d.ts create mode 100644 app/src/users/dto/create-user.dto.ts create mode 100644 app/src/users/user.ts create mode 100644 app/src/users/users.controller.ts create mode 100644 app/src/users/users.module.ts create mode 100644 app/src/users/users.repository.ts create mode 100644 app/src/users/users.service.ts create mode 100644 app/test/app.e2e-spec.ts create mode 100644 app/test/dependency-failures.e2e-spec.ts create mode 100644 app/tsconfig.build.json create mode 100644 app/tsconfig.json create mode 100644 app/vitest.config.e2e.ts create mode 100644 app/vitest.config.ts create mode 100644 compose.yaml create mode 100644 evidence/lab4/bootstrap-rerun.txt create mode 100644 infra/haproxy/haproxy.cfg create mode 100755 infra/minio/bootstrap.sh create mode 100755 scripts/app-e2e.sh create mode 100755 scripts/init-env.sh create mode 100755 scripts/restart.sh create mode 100755 scripts/start-replica.sh create mode 100755 scripts/stop-one.sh diff --git a/.env.example b/.env.example index d99d26a2..87462e24 100644 --- a/.env.example +++ b/.env.example @@ -1,20 +1,75 @@ # Copy to .env for your LOCAL synthetic test environment; never commit .env. -# These are logical interface suggestions; map actual framework names in REPORT.md. +# Полный список переменных, которые читают приложение и стенд; значения-образцы +# не являются секретами. Соответствие «переменная -> фактическая конфигурация» +# описано в REPORT.md. +# +# Приложение (проверяется zod-схемой app/src/config/app-config.schema.ts): APP_HOST=0.0.0.0 APP_PORT=8080 APP_ENV=lab SESSION_TTL_SECONDS=3600 -# Choose credentials locally. File paths contain no secret values. -DATABASE_URL_FILE=/run/secrets/database_url -# Optional on 3, required use on 4 in lab2; Redis OR Valkey: -SESSION_STORE=postgres -CACHE_URL_FILE=/run/secrets/cache_url -API_REPLICAS=2 +DATABASE_URL=postgresql://messenger:change-me@postgres:5432/messenger +REDIS_URL=redis://redis:6379 +DATABASE_POOL_MAX=10 +DATABASE_CONNECTION_TIMEOUT_MS=5000 +DATABASE_STATEMENT_TIMEOUT_MS=5000 +CACHE_TTL_SECONDS=30 +CACHE_MODE=protected +CACHE_LOCK_TTL_MS=1000 +CACHE_MISS_DELAY_MS=0 +# Бюджет проверки зависимостей в /health/ready: LB пробует ту же ручку +# (timeout check 500 ms), поэтому проба обязана уложиться заметно раньше. +HEALTH_TIMEOUT_MS=400 +# Токен доступа к /internal/metrics; сгенерируйте свой. +METRICS_TOKEN=change-me +# Дрейн перед выходом по SIGTERM: реплика перестаёт проходить пробу LB, +# ждёт DRAIN_DELAY_MS (длиннее обнаружения отказа ~1 s) и только потом закрывается. +DRAIN_DELAY_MS=3000 +# Переопределяет X-Instance-Id; по умолчанию это hostname контейнера +# (= короткий ID контейнера, по нему работает scripts/stop-one.sh). +# INSTANCE_ID=api-1 IDEMPOTENCY_TTL_SECONDS=86400 + +# Стенд (compose.yaml и scripts/): +API_REPLICAS=2 +API_CPUS_PER_REPLICA=1.5 +API_MEMORY_PER_REPLICA=768m +PG_CPUS=1.5 +PG_MEMORY=512m +REDIS_CPUS=0.25 +REDIS_MEMORY=128m +LB_CPUS=0.25 +LB_MEMORY=128m +# Тег образа API; BUILD_ID отличает сборки при rolling update. +API_IMAGE=mtusi-messenger:lab4 +BUILD_ID=local +APP_PUBLIC_PORT=8080 +LB_STATS_PORT=8404 +# Loopback-порты PostgreSQL/Redis нужны только операторским проверкам с хоста +# (make test-e2e, psql). API-реплики портов не публикуют. +POSTGRES_PUBLISHED_PORT=5432 +REDIS_PUBLISHED_PORT=6379 + +# PostgreSQL (пароль подставьте свой; тот же, что в DATABASE_URL): +POSTGRES_DB=messenger +POSTGRES_USER=messenger +POSTGRES_PASSWORD=change-me + +# Объектное хранилище MinIO. Credentials — файлы ./secrets/* (scripts/init-env.sh), не здесь. S3_ENDPOINT=http://s3:9000 +S3_PUBLIC_ENDPOINT=http://localhost:9000 S3_REGION=us-east-1 S3_BUCKET=messenger-attachments -S3_ACCESS_KEY_ID_FILE=/run/secrets/s3_access_key_id -S3_SECRET_ACCESS_KEY_FILE=/run/secrets/s3_secret_access_key +S3_PUBLIC_BIND=127.0.0.1 +S3_PUBLIC_PORT=9000 +S3_CPUS=1.0 +S3_MEMORY=512m +S3_CONNECT_TIMEOUT_MS=1000 +S3_REQUEST_TIMEOUT_MS=15000 MAX_UPLOAD_BYTES=10485760 MAX_IMAGE_PIXELS=40000000 +UPLOAD_MAX_IN_FLIGHT=32 +DIRECT_UPLOAD_MAX_PENDING_PER_USER=10 +# UPLOAD_TIMEOUT_MS, DIRECT_UPLOAD_URL_TTL_SECONDS, ATTACHMENT_SWEEP_GRACE_SECONDS, +# ATTACHMENT_SWEEP_INTERVAL_MS задаются в compose.yaml (environment) с умолчаниями +# и переопределяются из shell только для экспериментов. diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..7f8f579d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +FROM node:25.7.0-slim AS build + +WORKDIR /usr/src/app + +RUN apt-get update \ + && apt-get install -y --no-install-recommends python3 make g++ \ + && rm -rf /var/lib/apt/lists/* + +COPY app/package.json app/package-lock.json ./ +RUN npm ci + +COPY app/ ./ +RUN npm run build && npm prune --omit=dev + +FROM node:25.7.0-slim AS runtime + +WORKDIR /usr/src/app + +# BUILD_ID доказывается через GET /internal/metrics и меняется при rolling +# update: он показывает, какая именно сборка отвечает на запрос. +ARG BUILD_ID=unknown +ENV BUILD_ID=$BUILD_ID + +ENV NODE_ENV=production +ENV APP_PORT=8080 +ENV DRAIN_DELAY_MS=5000 +COPY --from=build /usr/src/app/package.json /usr/src/app/package-lock.json ./ +COPY --from=build /usr/src/app/node_modules ./node_modules +COPY --from=build /usr/src/app/dist ./dist + +USER node + +EXPOSE 8080 + +HEALTHCHECK --interval=10s --timeout=3s --start-period=10s --retries=3 \ + CMD node -e "const port=process.env.APP_PORT||'8080'; fetch('http://127.0.0.1:'+port+'/health/ready').then((response) => { if (!response.ok) process.exit(1); }).catch(() => process.exit(1))" + +CMD ["node", "dist/main.js"] diff --git a/Makefile b/Makefile index 5d86d171..76c20a93 100644 --- a/Makefile +++ b/Makefile @@ -4,10 +4,10 @@ CA_FILE ?= ACTION_SCRIPT ?= TLS_ARGS = $(if $(CA_FILE),--ca-file "$(CA_FILE)",) -.PHONY: help check validate test load test-persistence test-failover +.PHONY: help check validate test load test-persistence test-failover test-dependencies stand-up stand-down stand-status wait-ready init-env test-e2e s3-security consistency bench help: - @echo "check: offline structure; validate: full OpenAPI (requirements-dev.txt); test: running API; load: synthetic writes" + @echo "check: offline structure; validate: full OpenAPI (requirements-dev.txt); test: running API; load: synthetic writes; init-env: .env + secrets; test-e2e: app e2e; s3-security; consistency; bench" check: $(PYTHON) scripts/check_contract.py @@ -28,3 +28,42 @@ test-persistence: test-failover: @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) + +COMPOSE_ENV_FILE ?= .env +COMPOSE = docker compose --env-file $(COMPOSE_ENV_FILE) + +test-dependencies: + cd app && E2E_COMPOSE_DIR="$(CURDIR)" E2E_COMPOSE_ENV_FILE="$(COMPOSE_ENV_FILE)" npm run test:dependencies + +stand-up: + $(COMPOSE) up -d --build --wait + +stand-down: + $(COMPOSE) down + +stand-status: + $(COMPOSE) ps + +wait-ready: + @for attempt in $$(seq 1 60); do \ + if curl -fsS "$(BASE_URL)/health/ready" >/dev/null 2>&1; then \ + echo "stand is ready ($(BASE_URL))"; exit 0; \ + fi; \ + sleep 1; \ + done; \ + echo "stand did not become ready within 60s" >&2; exit 1 + +init-env: + ./scripts/init-env.sh + +test-e2e: + scripts/app-e2e.sh + +s3-security: + scripts/lab4/check_s3_security.sh + +consistency: + scripts/lab4/consistency_check.sh + +bench: + scripts/lab4/run_matrix.sh diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 00000000..b266c548 --- /dev/null +++ b/app/.gitignore @@ -0,0 +1,59 @@ +# compiled output +/dist +/node_modules +/build + +# TypeScript build cache +*.tsbuildinfo + +# Logs +logs +*.log +npm-debug.log* +pnpm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# OS +.DS_Store + +# Tests +/coverage +/.nyc_output + +# IDEs and editors +/.idea +.project +.classpath +.c9/ +*.launch +.settings/ +*.sublime-workspace + +# IDE - VSCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# temp directory +.temp +.tmp + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json diff --git a/app/.prettierrc b/app/.prettierrc new file mode 100644 index 00000000..b6528392 --- /dev/null +++ b/app/.prettierrc @@ -0,0 +1,6 @@ +{ + "singleQuote": true, + "trailingComma": "all", + "tabWidth": 4, + "useTabs": true +} diff --git a/app/README.md b/app/README.md new file mode 100644 index 00000000..b285bd3e --- /dev/null +++ b/app/README.md @@ -0,0 +1,314 @@ +# app — API мессенджера + +NestJS 12 + Fastify, ESM TypeScript. PostgreSQL — источник истины бизнес-данных, +Redis — серверные Bearer-сессии и производный кэш истории сообщений. + +Общая документация (в корне репозитория): + +| Документ | Что содержит | +|---|---| +| [`../REPORT.md`](../REPORT.md) | архитектура, схема данных, транзакции, политика кэша, команды, результаты проверок и трека 1 | +| [`../evidence/README.md`](../evidence/README.md) | индекс доказательств: что подтверждено и как это воспроизвести | +| [`../contracts/openapi.json`](../contracts/openapi.json) | нормативный контракт API | +| [`../tests/README.md`](../tests/README.md) | публичные проверки репозитория (`make check`, `make test`, persistence) | + +## Что внутри + +```text +src/ + main.ts bootstrap: Fastify, ValidationPipe, shutdown hooks + app.module.ts сборка модулей приложения + config/ Zod-схема env + глобальный ConfigModule + database/ pg.Pool, транзакции, миграции (001..004) + redis/ клиент Redis (AOF-совместимый, без offline queue) + auth/ Basic-вход, Redis-сессии, logout + users/ регистрация (Argon2id), профиль + chats/ создание чата в транзакции, список и чтение + messages/ отправка сообщения, keyset-история + cache/ версионированный кэш истории + lock на страницу + idempotency/ журнал Idempotency-Key (claim/read/store/forget/GC) + metrics/ /internal/metrics и /internal/metrics/reset + health/ liveness/readiness с проверкой зависимостей (readiness — проба LB) + common/ + http/ cursor (формат+календарь), page (конверт {items,next_cursor}), request-id + errors/ exception filter и тип тела ошибки ApiErrorBody + validation/ декоратор CodePointLength (длины в Unicode code points) + auth/ guard и декоратор текущего пользователя +test/ + app.e2e-spec.ts black-box набор против запущенного API (PG + Redis) +scripts/ + graph-modules.ts генератор графа зависимостей (nestjs-spelunker) +``` + +Принципы: raw `pg.Pool` без ORM, параметризованные запросы, никаких in-memory +хранилищ в боевых путях; кэш — производное состояние и всегда допускает +восстановление из PostgreSQL; отказ зависимости даёт ограниченную ошибку +(`503`), а не аварийное завершение процесса; длины строк проверяются в Unicode +code points (свой декоратор `@CodePointLength`), как в JSON Schema, а не в +UTF-16-единицах; состояние, от которого зависит корректность (сессии, журнал +идемпотентности), живёт только в общих PostgreSQL/Redis — локальных сессий и +файлов на диске реплики нет, поэтому `N` взаимозаменяемых реплик за одним LB +дают один и тот же результат. + +## Быстрый старт + +Рекомендуемый путь — весь стенд из корня репозитория (PostgreSQL, Redis, миграции, API): + +```sh +cd .. +cp .env.example .env +password=$(openssl rand -hex 32) +sed -i "s/^POSTGRES_PASSWORD=.*/POSTGRES_PASSWORD=$password/" .env +sed -i "s|^DATABASE_URL=.*|DATABASE_URL=postgresql://messenger:$password@postgres:5432/messenger|" .env +sed -i "s/^METRICS_TOKEN=.*/METRICS_TOKEN=$(openssl rand -hex 16)/" .env +make stand-up # сборка + up -d --wait: migrate -> api x API_REPLICAS -> haproxy +make wait-ready +curl -fsS http://localhost:8080/health/ready +for i in 1 2 3 4; do curl -sD- -o /dev/null localhost:8080/health/live | grep -i x-instance-id; done +``` + +Публичной точкой входа служит HAProxy (`compose.yaml`): реплики API портов не +публикуют. `API_REPLICAS` задаёт их число, `API_TOTAL_CPUS` / `API_TOTAL_MEMORY_MB` +делятся между ними — это бюджет серии трека 1 (`../REPORT.md`). + +Локальный запуск без Docker (нужны доступные PostgreSQL и Redis): + +```sh +cd app +npm ci +npm run build + +export DATABASE_URL=postgresql://messenger:@127.0.0.1:5432/messenger +export REDIS_URL=redis://127.0.0.1:6379 +export APP_PORT=8080 +node dist/database/migration.runner.js # применяет миграции из dist/database/migrations + +npm run start:dev # или npm run start:prod после build +``` + +## Переменные окружения + +Читаются только через конфигурационный слой (`src/config`), типы и диапазоны +проверяет Zod-схема на старте — при некорректном значении приложение падает +с понятной ошибкой. + +| Переменная | По умолчанию | Назначение | +|---|---|---| +| `APP_HOST` / `APP_PORT` | `0.0.0.0` / `8080` | адрес прослушивания | +| `APP_ENV` | `lab` | метка окружения | +| `DATABASE_URL` | — (обязательна) | строка подключения PostgreSQL | +| `REDIS_URL` | — (обязательна) | строка подключения Redis | +| `DATABASE_POOL_MAX` | `10` | размер пула соединений | +| `DATABASE_CONNECTION_TIMEOUT_MS` | `5000` | таймаут установки соединения | +| `DATABASE_STATEMENT_TIMEOUT_MS` | `5000` | таймаут SQL-запроса | +| `SESSION_TTL_SECONDS` | `3600` | TTL сессии (минимум 2) | +| `HEALTH_TIMEOUT_MS` | `400` | бюджет проверки PostgreSQL/Redis внутри `/health/ready`; меньше `timeout check` HAProxy (500 ms) и `DATABASE_STATEMENT_TIMEOUT_MS` | +| `CACHE_TTL_SECONDS` | `30` | TTL страницы истории в Redis | +| `CACHE_MODE` | `protected` | `protected` (lock на страницу) или `naive` (только для эксперимента) | +| `CACHE_LOCK_TTL_MS` | `1000` | TTL lock-а страницы | +| `CACHE_MISS_DELAY_MS` | `0` | искусственная пауза на промахе; влияет только на `naive` | +| `METRICS_TOKEN` | — (необязательна) | токен доступа к `/internal/metrics*`; без него endpoint закрыт | +| `DRAIN_DELAY_MS` | `5000` (в стенде `3000`) | окно дрейна при `SIGTERM`: реплика сразу перестаёт проходить пробу LB, ждёт этот интервал и только затем закрывает сервер и пулы | +| `INSTANCE_ID` | hostname контейнера | значение `X-Instance-Id`; в Docker hostname = короткий ID контейнера, поэтому `scripts/stop-one.sh` находит реплику по нему | +| `IDEMPOTENCY_TTL_SECONDS` | `86400` | срок хранения журнала Idempotency-Key (минимум 60) | + +Поддерживаются также `DATABASE_URL_FILE` / `REDIS_URL_FILE`: если заданы, значение +читается из файла (docker secrets / Swarm). Подробности и компромиссы — +[`../REPORT.md`](../REPORT.md), раздел «Конфигурация и секреты». + +## Эндпоинты + +Публичный контракт — [`../contracts/openapi.json`](../contracts/openapi.json). + +| Метод и путь | Аутентификация | Назначение | +|---|---|---| +| `GET /health/live` | нет | процесс жив; не обращается к зависимостям, поэтому отвечает `200` и при их отказе | +| `GET /health/ready` | нет | готовность реплики: флаг дреина + PostgreSQL и Redis (бюджет `HEALTH_TIMEOUT_MS`), иначе `503`; эту же ручку пробует HAProxy | +| `POST /api/v1/users` | нет | регистрация с паролем (Argon2id) | +| `POST /api/v1/auth/sessions` | `Basic` | вход, выдаёт opaque Bearer-токен | +| `DELETE /api/v1/auth/sessions/current` | `Bearer` | отзыв текущей сессии, `204` | +| `GET /api/v1/users/me` | `Bearer` | текущий пользователь | +| `POST /api/v1/chats` | `Bearer` | создание чата (транзакция) | +| `GET /api/v1/chats` | `Bearer` | список доступных чатов | +| `GET /api/v1/chats/:chatId` | `Bearer` | чат по id (чужой — `404`) | +| `POST /api/v1/chats/:chatId/messages` | `Bearer` + обязательный `Idempotency-Key` | отправка сообщения (см. ниже) | +| `GET /api/v1/chats/:chatId/messages` | `Bearer` | история, keyset-пагинация `(created_at, id)` | +| `GET /internal/metrics` | `Bearer METRICS_TOKEN` | счётчики и агрегаты латентности | +| `POST /internal/metrics/reset` | `Bearer METRICS_TOKEN` | сброс счётчиков (`200`) | + +Правила: `Basic` принимается только на создании сессии, бизнес-запросы — только +`Bearer`; заголовок `X-User-Id` не аутентифицирует и не подменяет владельца +сессии; истёкший, отозванный или неизвестный токен — `401` с соответствующим +`WWW-Authenticate`. + +## npm-скрипты + +| Команда | Что делает | +|---|---| +| `npm run build` | сборка в `dist/` | +| `npm run start:dev` | watch-режим | +| `npm run start:prod` | запуск собранного приложения (`node dist/main`) | +| `npm test` / `npm run test:unit` | unit-тесты (vitest) | +| `npm run test:e2e` | black-box набор против запущенного API (см. ниже) | +| `npm run test:dependencies` | автоматическая проверка отказов Redis/PostgreSQL: останавливает и поднимает контейнеры Compose-стенда | +| `npm run idempotency:gc` | ручной прогон удаления просроченных записей Idempotency-Key | +| `npm run lint` | oxlint по `src/` и `test/` | +| `npm run format` | prettier | +| `npm run graph` | граф модулей и провайдеров через nestjs-spelunker (пишет `../docs/architecture/`) | + +## Тесты + +Unit-тесты не требуют инфраструктуры: + +```sh +npm test +``` + +Интеграционный набор работает по HTTP против запущенного стенда и дополнительно +подключается к PostgreSQL (очистка тестовых данных) и Redis: + +```sh +export API_BASE_URL=http://localhost:8080 +export DATABASE_URL=postgresql://messenger:@:5432/messenger +export REDIS_URL=redis://:6379 +npm run test:e2e +``` + +Название `API_BASE_URL` (а не `BASE_URL`) выбрано потому, что Vitest сам +устанавливает `process.env.BASE_URL` в значение Vite base. Кейс истечения сессии +включается переменной `SESSION_TTL_SECONDS=2` и у запущенного API, и у набора. + +## Отказы зависимостей + +Отдельный набор останавливает и поднимает контейнеры Compose-стенда и проверяет +ограниченные ошибки вместо 500: + +```sh +cd .. # из корня репозитория, стенд поднят через docker compose +make test-dependencies +``` + +Он включён по флагу `E2E_DEPENDENCY_FAULTS=1` (им же управляет цель Makefile), +потому что требует прав на управление Docker Compose-проектом; остальные +переменные — `E2E_COMPOSE_DIR`, `E2E_COMPOSE_ENV_FILE`, `E2E_REDIS_SERVICE`, +`E2E_POSTGRES_SERVICE`, `E2E_API_SERVICE`, `E2E_LB_STATS_URL`, +`E2E_POSTGRES_USER`, `E2E_POSTGRES_DB`, `E2E_PG_HBA_PATH`. + +Проверяются три топологии отказа: + +1. **Отказ Redis** (общая зависимость): `/health/live` реплики остаётся `200`, + `/health/ready` и бизнес-запросы — `503 unavailable` с `request_id` из + `X-Request-Id` и без деталей драйвера, запрос без сессии — по-прежнему `401`. + Неготовыми становятся все реплики, HAProxy исключает их из ротации и + отвечает собственным `503`; после старта Redis сессия и подтверждённое + сообщение живы. +2. **Отказ PostgreSQL** (общая зависимость): то же плюс проверка, что после + возврата зависимости данные на месте и новая запись проходит. +3. **Отказ PostgreSQL у одной реплики** (локальный путь к БД): для адреса + выбранной реплики временно ставится `reject`-строка в `pg_hba.conf` (первое + совпадение) и обрываются её соединения. Выбранная реплика отвечает `503` и её + слот уходит в `DOWN`, здоровая продолжает `200`/`UP` и обслуживает все чтения + через LB; `pg_hba.conf` восстанавливается в `finally`, после чего реплика + возвращается в ротацию и снова получает запросы. + +Реплики API портов не публикуют, поэтому отдельная реплика опрашивается изнутри +своего контейнера (loopback), а состояние слотов — из `stats;csv` HAProxy +(`127.0.0.1:8404`). Каждый запрос к остановленной БД ждёт +`DATABASE_CONNECTION_TIMEOUT_MS`, поэтому набор идёт около минуты. + +## Реплики, балансировка и остановка реплики + +Все реплики запускаются из одного образа и одного `compose.yaml`; API портов не +публикует, трафик идёт только через HAProxy. Состояние, от которого зависит +корректность, лежит в общих PostgreSQL и Redis, поэтому клиент с одним +Bearer-токеном обслуживается любой репликой: + +```sh +make test BASE_URL=http://localhost:8080 # сквозной сценарий через LB +python3 scripts/lab3/lab3.py check spread # распределение X-Instance-Id +make test-failover ACTION_SCRIPT=scripts/stop-one.sh # отказ одной реплики +scripts/start-replica.sh # вернуть остановленную реплику +``` + +- `X-Instance-Id` = `INSTANCE_ID` или hostname процесса, стабилен для процесса; + в Docker hostname контейнера — короткий ID, поэтому `scripts/stop-one.sh` + останавливает ровно ту реплику, которую обслужил запрос теста. Тот же заголовок + добавляется к ответам об ошибках, которые формируются фильтром до интерсептора. +- **Остановка (`SIGTERM`)** идёт в порядке «сначала дрейн, потом разбор ресурсов»: + реплика помечается not-ready (проба LB и `/health/ready` начинают отвечать + `503`), `DRAIN_DELAY_MS` ждёт, пока LB её исключит (обнаружение ≈1 s), и лишь + затем закрываются HTTP-сервер, пул PostgreSQL и соединение Redis. Если + полагаться на стандартный порядок Nest (`onModuleDestroy` вызывает закрытие + пулов раньше `beforeApplicationShutdown`), реплика какое-то время остаётся в + ротации уже без ресурсов — это и было причиной явной последовательности в + `src/main.ts`. +- **Проба LB — тот же `/health/ready`**, что и healthcheck контейнера: реплика, + потерявшая обязательную зависимость (свой путь к PostgreSQL или Redis), + выходит из ротации, и трафик уходит на здоровые реплики. Проба с зависимостями + ограничена общим дедлайном `HEALTH_TIMEOUT_MS=400` на реплику; проверка + PostgreSQL (`SELECT 1`) идёт по отдельному соединению, а не из общего пула + бизнес-запросов, а для `PING` Redis стоит `AbortSignal.timeout`, поэтому проба + укладывается в `timeout check 500ms` HAProxy и не реагирует на перегрузку. + Когда недоступна общая для всех зависимость, + неготовыми становятся все реплики, и клиент получает `503` от самого LB: это + честный ответ «готовых узлов нет» вместо маскировки отказа. +- `/health/live` зависимостей не касается: он отвечает `200`, пока жив процесс, + и по нему проверяют, что реплика не упала (в том числе при отказе PG/Redis). + +## Идемпотентность отправки сообщения + +`POST /api/v1/chats/{chatId}/messages` требует заголовок `Idempotency-Key` +(ASCII `[A-Za-z0-9._:-]{1,128}`). Область уникальности — пользователь + метод + +путь чата + ключ, поэтому одинаковый ключ у разных пользователей или в разных +чатах не конфликтует. Журнал — таблица `idempotency_keys` (миграция 003), то +есть общая для всех реплик. + +| Ситуация | Ответ | +|---|---| +| Заголовок отсутствует, пуст или не подходит под шаблон | `400 invalid_request` (до обращения к БД) | +| Первый запрос с ключом | `201` и сообщение; заявка, вставка сообщения, инкремент версии чата и тело ответа записываются **одним оператором SQL** (атомарность обеспечивает сам оператор) | +| Повтор того же тела с тем же ключом | тот же `201` и тот же JSON (включая `id` и `created_at`), новое сообщение не создаётся | +| Другое тело с тем же ключом | `409 conflict` | +| Повтор после `404` (нет доступа к чату) | `404`, ключ не занят: оператор вставляет заявку только при наличии членства, иначе не создаётся ничего | +| Ключ старше `IDEMPOTENCY_TTL_SECONDS` | запись удаляется, ключ считается свободным | +| Одновременные повторы через разные реплики | ровно одно сообщение: заявка берётся `INSERT ... ON CONFLICT DO NOTHING`, повтор читает сохранённый ответ | + +Путь записи — один round trip: `messages.createIdempotent` проверяет членство, +занимает ключ (`INSERT ... ON CONFLICT DO NOTHING`), вставляет сообщение, поднимает +`chats.message_version` и сохраняет тело ответа, а повтор читает сохранённый ответ +вместе с повторной проверкой доступа (`idempotency.read`). До оптимизации это были +8 обращений к БД в явной транзакции (см. REPORT.md, раздел «A/B улучшения»). + +Отпечаток тела считается по валидированному DTO с фиксированным порядком полей, +поэтому порядок ключей в JSON не влияет на результат. Транзиентные сбои +PostgreSQL (`57014`, `40001`, `40P01`) и обрывы соединения отдаются как +`503 unavailable` и не фиксируются как окончательный результат: клиент может +безопасно повторить запрос с тем же ключом. Просроченные записи удаляются +фоновым проходом (`idempotency.purged` в метриках) под +`pg_try_advisory_xact_lock`, а также вручную: `npm run idempotency:gc`. + +## Харнесс экспериментов + +Уровни 3/4 и трек 1 обслуживает `../scripts/lab3/lab3.py` (только stdlib) и +профили k6 в `../scripts/load/`: `run`, `sweep`, `track1-extras`, `failover`, +`rolling-update`, `ab`, `analyze`, `watch`, `check`, `quiesce`, `track1`. +Сырые результаты прогонов, манифесты условий измерения и графики складываются в +`../evidence/track1/`. Подробности — в `../REPORT.md` и +`../evidence/README.md`. + +## Метрики + +`GET /internal/metrics` возвращает `{counters, latency_ms, instance_id, build_id}`: именованные SQL-метки, +операции Redis, `cache_hit`/`cache_miss`/`cache_lock_wait`, `session_get/set/del`, +`request_count` и процентили латентности (буфер ограничен). Деградации +наблюдаемы отдельными счётчиками: `cache_fallback`, `cache_write_error`, +`cache_unlock_error`, `cache_lock_timeout`, `cache_corrupt_entry`, +`database.pool_error`, `database.rollback_error`, `redis.error`, а также +идемпотентность: `idempotency.claim`, `idempotency.replay`, `idempotency.conflict`, +`idempotency.claim_lost`, `idempotency.released`, `idempotency.purged`, +`idempotency.purge_error`, `messages.write`. + +Счётчики локальны процессу: при нескольких репликах их нельзя суммировать как +распределённый снимок, а рестарт API обнуляет их (данные PostgreSQL и Redis при +этом не затрагиваются). `instance_id` и `build_id` позволяют сопоставить ответ +конкретной реплике и сборке — этим пользуются rolling update и эксперименты. diff --git a/app/nest-cli.json b/app/nest-cli.json new file mode 100644 index 00000000..5a21707a --- /dev/null +++ b/app/nest-cli.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://json.schemastore.org/nest-cli", + "collection": "@nestjs/schematics", + "sourceRoot": "src", + "compilerOptions": { + "deleteOutDir": true, + "assets": [ + { + "include": "database/migrations/*.sql", + "outDir": "dist" + } + ], + "watchAssets": true + } +} diff --git a/app/oxlint.json b/app/oxlint.json new file mode 100644 index 00000000..07ec3bd5 --- /dev/null +++ b/app/oxlint.json @@ -0,0 +1,10 @@ +{ + "$schema": "https://raw.githubusercontent.com/oxc-project/oxc/main/crates/oxc_linter/src/rules.rs", + "rules": { + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-floating-promises": "warn" + }, + "env": { + "node": true + } +} diff --git a/app/package-lock.json b/app/package-lock.json new file mode 100644 index 00000000..b98212b8 --- /dev/null +++ b/app/package-lock.json @@ -0,0 +1,7401 @@ +{ + "name": "app", + "version": "0.0.1", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "app", + "version": "0.0.1", + "license": "UNLICENSED", + "dependencies": { + "@nestjs/common": "^12.0.1", + "@nestjs/config": "^12.0.0", + "@nestjs/core": "^12.0.1", + "@nestjs/platform-express": "^12.0.1", + "@nestjs/platform-fastify": "^12.0.3", + "argon2": "^0.45.1", + "class-transformer": "^0.5.1", + "class-validator": "^0.15.1", + "date-fns": "^4.4.0", + "fastify": "^5.12.5", + "pg": "^8.23.1", + "redis": "^6.3.0", + "reflect-metadata": "^0.2.2", + "rxjs": "^7.8.1", + "zod": "^4.6.5" + }, + "devDependencies": { + "@nestjs/cli": "^12.0.0", + "@nestjs/mau": "^0.2.6", + "@nestjs/schematics": "^12.0.0", + "@nestjs/testing": "^12.0.1", + "@types/express": "^5.0.0", + "@types/node": "^24.0.0", + "@types/pg": "^8.23.1", + "@types/supertest": "^7.0.0", + "@vitest/coverage-v8": "^4.1.2", + "dotenv": "^18.0.5", + "nestjs-spelunker": "^1.3.2", + "oxlint": "^1.58.0", + "prettier": "^3.4.2", + "source-map-support": "^0.5.21", + "supertest": "^7.2.2", + "tsx": "^4.23.15", + "typescript": "^6.0.3", + "vite-tsconfig-paths": "^5.1.4", + "vitest": "^4.1.2" + } + }, + "node_modules/@angular-devkit/core": { + "version": "22.1.8", + "resolved": "https://registry.npmjs.org/@angular-devkit/core/-/core-22.1.8.tgz", + "integrity": "sha512-34lsgg2FwMVBX7nR/ZqzRUcdvdYPvSB8XAEr2GudXAyZwLI9ehzfQlagAWR/gEb8p4uCFZW0r7uU0toxydq4Rw==", + "dev": true, + "license": "MIT", + "dependencies": { + "ajv": "8.20.0", + "ajv-formats": "3.0.1", + "jsonc-parser": "3.3.1", + "picomatch": "4.0.5", + "rxjs": "7.8.2", + "source-map": "0.7.6" + }, + "engines": { + "node": "^22.22.3 || ^24.15.0 || >=26.0.0", + "npm": "^6.11.0 || ^7.5.6 || >=8.0.0", + "yarn": ">= 1.13.0" + }, + "peerDependencies": { + "chokidar": "^5.0.0" + }, + "peerDependenciesMeta": { + "chokidar": { + "optional": true + } + } + }, + "node_modules/@angular-devkit/schematics": { + "version": "22.1.8", + "resolved": "https://registry.npmjs.org/@angular-devkit/schematics/-/schematics-22.1.8.tgz", + "integrity": "sha512-Pv3cPa/44kvEwYcqwx4Ns5dhIDmcFNSHhbpheqiEG1Z/u4e2t4zHKDtE3eHZB+8o+IcC7xJj+d+AqGR44RoZDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@angular-devkit/core": "22.1.8", + "jsonc-parser": "3.3.1", + "magic-string": "1.0.0", + "ora": "9.4.1", + "rxjs": "7.8.2" + }, + "engines": { + "node": "^22.22.3 || ^24.15.0 || >=26.0.0", + "npm": "^6.11.0 || ^7.5.6 || >=8.0.0", + "yarn": ">= 1.13.0" + } + }, + "node_modules/@angular-devkit/schematics-cli": { + "version": "22.1.8", + "resolved": "https://registry.npmjs.org/@angular-devkit/schematics-cli/-/schematics-cli-22.1.8.tgz", + "integrity": "sha512-SsGG8ompVzprmYE9sHi2L7DYZ+i1sD+YDfun6Rg2vkTCusejtD4SSGVxwuR6++dT22ZpN16OqUTmii/0bhE4xA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@angular-devkit/core": "22.1.8", + "@angular-devkit/schematics": "22.1.8", + "@inquirer/prompts": "8.5.2" + }, + "bin": { + "schematics": "bin/schematics.js" + }, + "engines": { + "node": "^22.22.3 || ^24.15.0 || >=26.0.0", + "npm": "^6.11.0 || ^7.5.6 || >=8.0.0", + "yarn": ">= 1.13.0" + } + }, + "node_modules/@angular-devkit/schematics-cli/node_modules/@inquirer/prompts": { + "version": "8.5.2", + "resolved": "https://registry.npmjs.org/@inquirer/prompts/-/prompts-8.5.2.tgz", + "integrity": "sha512-IYR/3C/paEVVQYQvdDlFZVjRCJVYHHON0XXMH91KO9GSxs0TdKYWlUdvfQl2EfAHDxUaN3IBffkE/BDTh5nJ6g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@inquirer/checkbox": "^5.2.1", + "@inquirer/confirm": "^6.1.1", + "@inquirer/editor": "^5.2.2", + "@inquirer/expand": "^5.1.1", + "@inquirer/input": "^5.1.2", + "@inquirer/number": "^4.1.1", + "@inquirer/password": "^5.1.1", + "@inquirer/rawlist": "^5.3.1", + "@inquirer/search": "^4.2.1", + "@inquirer/select": "^5.2.1" + }, + "engines": { + "node": ">=23.5.0 || ^22.13.0 || ^20.17.0" + }, + "peerDependencies": { + "@types/node": ">=18" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + } + } + }, + "node_modules/@babel/helper-string-parser": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.29.7.tgz", + "integrity": "sha512-Pb5ijPrZ89GDH8223L4UP8i6QApWxs04RbPQJTeWDV0/keR2E36MeKnyr6LYmUUvqRRI+Iv87SuF1W6ErINzYw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-validator-identifier": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.29.7.tgz", + "integrity": "sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/parser": { + "version": "7.29.8", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.29.8.tgz", + "integrity": "sha512-E8lTAYNB1KW+FH+VGJuZM1ioAx2E6oVlvQFRrf5P8ZZmsiJXYAD9vTFV7yyEURNzgh1dFqMZuO6tUwcARbqFCA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/types": "^7.29.8" + }, + "bin": { + "parser": "bin/babel-parser.js" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@babel/types": { + "version": "7.29.8", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.29.8.tgz", + "integrity": "sha512-Vj1jF3cPfxg7OAfoI7QnVKLoILlm2JF9pnVHrX8qx7AHMiYWT+NDAA7jChlNgRS4WTLc/fD1lXLmPixluj+3Gg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/helper-string-parser": "^7.29.7", + "@babel/helper-validator-identifier": "^7.29.7" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@bcoe/v8-coverage": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-1.0.2.tgz", + "integrity": "sha512-6zABk/ECA/QYSCQ1NGiVwwbQerUCZ+TQbp64Q3AgmfNvurHH0j8TtXa1qbShXA6qqkpAj4V5W8pP6mLe1mcMqA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/@borewit/text-codec": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/@borewit/text-codec/-/text-codec-0.2.2.tgz", + "integrity": "sha512-DDaRehssg1aNrH4+2hnj1B7vnUGEjU6OIlyRdkMd0aUdIUvKXrJfXsy8LVtXAy7DRvYVluWbMspsRhz2lcW0mQ==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Borewit" + } + }, + "node_modules/@colors/colors": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", + "integrity": "sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==", + "dev": true, + "license": "MIT", + "optional": true, + "engines": { + "node": ">=0.1.90" + } + }, + "node_modules/@epic-web/invariant": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@epic-web/invariant/-/invariant-1.0.0.tgz", + "integrity": "sha512-lrTPqgvfFQtR/eY/qkIzp98OGdNJu0m5ji3q/nJI8v3SXkRKEnWiOxMmbvcSoAIzv/cGiuvRy57k4suKQSAdwA==", + "license": "MIT" + }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.2.tgz", + "integrity": "sha512-XExcO+dvLKvVtNTibSTBej1NCAbaGhWn9Ww1ZPx80qsahhPFe/8jgWP0IchNe0F3HwkU7n8ejhH8bjonqht8mQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.28.2.tgz", + "integrity": "sha512-kXXoiPVVGQcnIYGOeaovwOURpniDBpSq4A03qkQ+BMQqtGG6HYap3xne9C1O1yo4TR3qxlCX5IqqmX6fFo2Lqg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.28.2.tgz", + "integrity": "sha512-5YfKeeI8qWfBZIX+u2xZC3Zlb3Os/gLS2sbEKM+I4ZOcsWmHS2WLysCcQZDAFRslDUU5Oiq44gf6PYN1vGwG5A==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.28.2.tgz", + "integrity": "sha512-O387ite7SzUyCcy3JQX4P4bLtEA7bLLkx+esve5JHnyYfNTxcVpXZo9jhdB0lTKN44gztELTdU7nS8Nr16Fs1Q==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.28.2.tgz", + "integrity": "sha512-n4KqkOQrraxHJcgjM1RvwbigfQKIKJVpM7xp+KsxiyUSrRdIXnt73VhrPAx0fV44hgfmIVKjxMN9J1t5jySVkw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.28.2.tgz", + "integrity": "sha512-uq6suIWYP37qzGddBKPw5QEQPi6HiLGsO7UmkpfyaYNQ3D+rN6w6WfwH+nuqcGXWvawGwxOEroO4YGnFh95azw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.28.2.tgz", + "integrity": "sha512-n+I0BTSRIoy+d6RPKnEVwql5UwBJolytvY4mAOIEJorKlqgPII8ix6slVVrfZ5Tnj7glIZvloylbB/EJPMWEXw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.28.2.tgz", + "integrity": "sha512-78XJTJkvPs0kz2w61301PJjXl4g7q3JqiYMZ/M/yVI73EHBrCRTgkhu9oqG7vPqq+a/yadEW8aD+agKlk5xrmg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.28.2.tgz", + "integrity": "sha512-XlDnu2q5yoqems+xay6wSAcg9DDD7K9RLKZEBOMZm3ckNpJBvOX20tSfby8KfrrhINDyv9V2YVZKY/SpoGJI8w==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.28.2.tgz", + "integrity": "sha512-pW4AC0P3it8c7do9MVM4p51FzHzdM/TZrerurgRcHJ2WTa1VQ1CIq18xncfpBJw4ojkiZZrKW2yIBWBP92j6Ug==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.28.2.tgz", + "integrity": "sha512-CYbnj78HsIeA+DhgUKgFCfvNsTHFhMMrinUrMZpDXJXKN8T3XViTZ/+wtHeVxEWY8ewSzTFN+nRmSwO2tZaLUQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.28.2.tgz", + "integrity": "sha512-buwkd8nsph4R+ajRvw0qM5Hja/TXQow3ptzWO2EbG/cqcIkHloRrdlBtQlshyYGTNFvfkfJ5tpPLVkY4DtsPfQ==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.28.2.tgz", + "integrity": "sha512-ZVykbDyk7519VwiNb9Lcj9m8XM6v5V9uKPvrEMkkEedVewf+0itkhahp4HDpgERXhwLRpWFypsGbG/J8s0QjJA==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.28.2.tgz", + "integrity": "sha512-CAXl+Dtd9UUuJd8pKKdwh6MLm3MUMiqMPmhZ3tTSXPqfyQ3vDl6R5hZdZ/kYojK4ofXtdfSv1tFq8XzWx3heNQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.28.2.tgz", + "integrity": "sha512-GeXCej4IQtU1B+QlDV8W/RRvbzI3O/Stss+/bCXv4lZls5WGRtu2a+3JkA3i4qIUlMXpcHebWpF8AkJhATowuA==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.28.2.tgz", + "integrity": "sha512-3H1weTYZPxt/WOhByszQZybS9w5lKzUn1FDMsgEChbHWQwHYQQRfBxgCcZvPhjHfKyJjIievvMmEUawJrdY9Dg==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.28.2.tgz", + "integrity": "sha512-4xTZr1FUmSoQW4XIWmit3tzQrUTZM+N3P0XV8xROKYF50XfI7xeO90+1bZvNwxIufQ9hDQVRJH5YhgPVF8A/HQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.28.2.tgz", + "integrity": "sha512-sSATRjPeDBg3pdgHoQfoYBob11Kk1FGa9lui5RIHZCoCkJa9QKlvl3/vKz2usCmYYjs7ymJR/2Nnsqe+Hjt5nw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.28.2.tgz", + "integrity": "sha512-lqnzCV+mM0gIADaKihiCg6ifgfU2L3h5E33rNQBN1Y4MaVGnzryzmvvf7UHxprpQdE8hpqLolJ9Rl+SkIRDpyw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.28.2.tgz", + "integrity": "sha512-AL2qJILH7lNjrDmCQDvdxMfAUIv8KMNZOvrwAQ8i8//ntL9FflhOyMJ8OZSMBb8/AWXe3/5v5S20y3zCoZWKoQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.28.2.tgz", + "integrity": "sha512-QtiuPytchRyC4rwUKhexJdQKvDuZ6hWloi3igqPQNUJCS1/v9EiO3UTOXR6A3FoMo4fnAKbWJdqaIwhOzh8qEw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openharmony-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.28.2.tgz", + "integrity": "sha512-WkhYDmpTjLvGlScA1rwjRUmhl4k8oXR3cIbtqWmELgU/dFeHHlEllxDvdWcNJV9rbzCexB5vz8gtNewWLgCT7Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.28.2.tgz", + "integrity": "sha512-GPMSkTOtMnv2U2F8gxe4Io6qmVs+YKyp832Etqqxr0hFngmXQ3rzwytelm3GIn7T4VviRUlf3sOgBOiTdvaf7g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.28.2.tgz", + "integrity": "sha512-PIhhEkE9uPBleRBrQEJpUn7MBnibZzbGzYWPmY3x+YoVg/95zbjB4CxPPOQ8l5tYYM4mMaCthF8/1DIfBQQyWQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.28.2.tgz", + "integrity": "sha512-YmJbfTlvU7Sdn9BB+4PRES4oB6pxgS37MAONj+hBr/cpXS1aBPKXxNnDbu+QCWPj0o9dgyxeq79g6c5P8KeuYA==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.28.2.tgz", + "integrity": "sha512-5ebpxr3nWMzrL/rnUI755Jkuee0bHL/Gq0WTF9lvcpv73wAp5eu8MfBUgWK9bhWvZjj7yX8etf/8tI8Ney695g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@fastify/ajv-compiler": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/@fastify/ajv-compiler/-/ajv-compiler-4.0.6.tgz", + "integrity": "sha512-NtuzM0SfaMJbGlnjr9LWQUN5LzgSrbB8tf/wRZNas+4E1O/Nmzl53e7ruT61HDZyRCJGC6FxIogmNZO1c5ETBA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT", + "dependencies": { + "ajv": "^8.12.0", + "ajv-formats": "^3.0.1", + "fast-uri": "^4.0.0" + } + }, + "node_modules/@fastify/ajv-compiler/node_modules/fast-uri": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-4.2.1.tgz", + "integrity": "sha512-TmHQgewjHtMq1E5QKA0tOE0yeYGQs25KZC/ziJpubRtWI15W92e6vPFydWOeZBVROSHBYw/QhD9d5OefdD6LDg==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "BSD-3-Clause" + }, + "node_modules/@fastify/cors": { + "version": "11.3.0", + "resolved": "https://registry.npmjs.org/@fastify/cors/-/cors-11.3.0.tgz", + "integrity": "sha512-ggQGua+xHv1MvePbPr0v//xLYEsCXbWspquXCJS9Ot5YoRXq8J8ZWzHnxDBVnbtXosvistXo6LtNzOJswf64Fw==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT", + "dependencies": { + "fastify-plugin": "^6.0.0", + "toad-cache": "^3.7.0" + } + }, + "node_modules/@fastify/error": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/@fastify/error/-/error-4.2.0.tgz", + "integrity": "sha512-RSo3sVDXfHskiBZKBPRgnQTtIqpi/7zhJOEmAxCiBcM7d0uwdGdxLlsCaLzGs8v8NnxIRlfG0N51p5yFaOentQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT" + }, + "node_modules/@fastify/fast-json-stringify-compiler": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@fastify/fast-json-stringify-compiler/-/fast-json-stringify-compiler-5.1.0.tgz", + "integrity": "sha512-PxcYtKLbQ8Z+yApiqjK8FwxIwvEj38k2OiLc17u8dkJSlmfi2wHHPaSnaoqBPQqtvF8YVsDgDpP2snDCfFrpfw==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT", + "dependencies": { + "fast-json-stringify": "^7.0.0" + } + }, + "node_modules/@fastify/formbody": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/@fastify/formbody/-/formbody-9.0.0.tgz", + "integrity": "sha512-T/af26CSrUARBCvsEmv+DJLPfZlrRKESzqironxP1j7qzuLyKcoZtj6MuTGShuKx1THXugoie2oFbUJxXfGFzA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT", + "dependencies": { + "fast-querystring": "^1.1.2", + "fastify-plugin": "^6.0.0" + } + }, + "node_modules/@fastify/forwarded": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@fastify/forwarded/-/forwarded-3.0.2.tgz", + "integrity": "sha512-NE8HgKLgYejV9lDpqkEFaDKMLYelJBVfHekhB0UKvX0ghagXRJqg68feg8er1NPXxG4N9i6vPxzt8E+3wHfcmA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT" + }, + "node_modules/@fastify/merge-json-schemas": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/@fastify/merge-json-schemas/-/merge-json-schemas-0.2.1.tgz", + "integrity": "sha512-OA3KGBCy6KtIvLf8DINC5880o5iBlDX4SxzLQS8HorJAbqluzLRn80UXU0bxZn7UOFhFgpRJDasfwn9nG4FG4A==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT", + "dependencies": { + "dequal": "^2.0.3" + } + }, + "node_modules/@fastify/middie": { + "version": "9.3.4", + "resolved": "https://registry.npmjs.org/@fastify/middie/-/middie-9.3.4.tgz", + "integrity": "sha512-dd8phTnVWzx3iKPBKSvtRUT8+Igvy/MP+P5HcY2tjejEyeVbyjkD4HgzKessUObue5RRM5J6PZdxtAqgbn84yw==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT", + "dependencies": { + "@fastify/error": "^4.0.0", + "fastify-plugin": "^6.0.0", + "find-my-way": "^9.5.0", + "path-to-regexp": "^8.1.0", + "reusify": "^1.0.4" + } + }, + "node_modules/@fastify/proxy-addr": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/@fastify/proxy-addr/-/proxy-addr-5.1.1.tgz", + "integrity": "sha512-zv07Y9GEuDsJPegZoDFd4SDWaZOW8N2pa0GSrYmKpId/tjt1Hgo3BjZBVjdVpfVrHaA+Qv5jawtS2O50J5xM9g==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT", + "dependencies": { + "@fastify/forwarded": "^3.0.0", + "ipaddr.js": "^2.1.0" + } + }, + "node_modules/@fastify/proxy-addr/node_modules/ipaddr.js": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-2.5.0.tgz", + "integrity": "sha512-aq+t5NAc+cS6rZQQVWC2x98CPqGtKKTMDd4Gaodv0wShnItdKg/51djkGJ1hqH+Oy0ivDftCbSLCQob8zso01w==", + "license": "MIT", + "engines": { + "node": ">= 10" + } + }, + "node_modules/@inquirer/ansi": { + "version": "2.0.8", + "resolved": "https://registry.npmjs.org/@inquirer/ansi/-/ansi-2.0.8.tgz", + "integrity": "sha512-WpQM+Ti6Z40EFwwt+uL2p4UabT+W179zHp6HhLVOzfbwnVn05IPO/eXIZXGNqcT1jbQ15SujNLzQ39k4QPPxBQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=23.5.0 || ^22.13.0 || ^20.17.0" + } + }, + "node_modules/@inquirer/checkbox": { + "version": "5.2.5", + "resolved": "https://registry.npmjs.org/@inquirer/checkbox/-/checkbox-5.2.5.tgz", + "integrity": "sha512-bRt8J8m+Fot9CXv+zNQGXUq2ET0MggR1fPz7v6edN6MFYmsbfGnMmkmWZJEegMKqrAC8ej/o1sqisHZXZJMAfQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@inquirer/ansi": "^2.0.8", + "@inquirer/core": "^12.0.3", + "@inquirer/figures": "^2.0.9", + "@inquirer/type": "4.1.1" + }, + "engines": { + "node": ">=23.5.0 || ^22.13.0 || ^20.17.0" + }, + "peerDependencies": { + "@types/node": ">=18" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + } + } + }, + "node_modules/@inquirer/confirm": { + "version": "6.3.2", + "resolved": "https://registry.npmjs.org/@inquirer/confirm/-/confirm-6.3.2.tgz", + "integrity": "sha512-Xvr/0HggjddPtGppuqVmxhTw+Hr8PvsZ/k0HmOEaAqQEt80OITNkFWnsdNmyT0/eM4Ab+iJLx2R8rctlEyfSVg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@inquirer/core": "^12.0.3", + "@inquirer/type": "4.1.1" + }, + "engines": { + "node": ">=23.5.0 || ^22.13.0 || ^20.17.0" + }, + "peerDependencies": { + "@types/node": ">=18" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + } + } + }, + "node_modules/@inquirer/core": { + "version": "12.0.3", + "resolved": "https://registry.npmjs.org/@inquirer/core/-/core-12.0.3.tgz", + "integrity": "sha512-wsSy0sznmXwkty+2PzZwx00Cazc/E0r0B7mAzdGROz2Ct+DFZXaK7WDjGZvgjRldxH5ZhFVfF2lgkYrqgOw2KA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@inquirer/ansi": "^2.0.8", + "@inquirer/figures": "^2.0.9", + "@inquirer/type": "4.1.1", + "cli-width": "^4.1.0", + "fast-wrap-ansi": "^0.2.0", + "mute-stream": "^3.0.0", + "signal-exit": "^4.1.0" + }, + "engines": { + "node": ">=23.5.0 || ^22.13.0 || ^20.17.0" + }, + "peerDependencies": { + "@types/node": ">=18" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + } + } + }, + "node_modules/@inquirer/editor": { + "version": "5.3.3", + "resolved": "https://registry.npmjs.org/@inquirer/editor/-/editor-5.3.3.tgz", + "integrity": "sha512-YsKkS2q63IiLtaDK/9nqzdComN97SDQrmKiyNggN+ceP4ty+Z6VwyTz3FpjeUWeW1Efss2xHFKCC9sx7hnrsxg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@inquirer/core": "^12.0.3", + "@inquirer/external-editor": "^3.0.5", + "@inquirer/type": "4.1.1" + }, + "engines": { + "node": ">=23.5.0 || ^22.13.0 || ^20.17.0" + }, + "peerDependencies": { + "@types/node": ">=18" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + } + } + }, + "node_modules/@inquirer/expand": { + "version": "5.1.5", + "resolved": "https://registry.npmjs.org/@inquirer/expand/-/expand-5.1.5.tgz", + "integrity": "sha512-uHuXLmXW+TtIfT/9vSBotypAkqn1n34Ul+CLGPos/xANyO4Ff5xZzkYhbKR4NEcfVK4a9mHQOpwVZzluSHFRGw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@inquirer/core": "^12.0.3", + "@inquirer/type": "4.1.1" + }, + "engines": { + "node": ">=23.5.0 || ^22.13.0 || ^20.17.0" + }, + "peerDependencies": { + "@types/node": ">=18" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + } + } + }, + "node_modules/@inquirer/external-editor": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/@inquirer/external-editor/-/external-editor-3.0.5.tgz", + "integrity": "sha512-f3QQJRIX5ZEneBHNUIuPjmbdzHnmRFJA8r2dkcb8q+OM5Uv5KtnuAttQumnrjcBVBM3mcTX1CkmtAkU58VRZxg==", + "dev": true, + "license": "MIT", + "dependencies": { + "chardet": "^2.1.1", + "iconv-lite": "^0.7.2" + }, + "engines": { + "node": ">=23.5.0 || ^22.13.0 || ^20.17.0" + }, + "peerDependencies": { + "@types/node": ">=18" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + } + } + }, + "node_modules/@inquirer/figures": { + "version": "2.0.9", + "resolved": "https://registry.npmjs.org/@inquirer/figures/-/figures-2.0.9.tgz", + "integrity": "sha512-EAWgUTGQ/Umgga51dE3B2PUHbufuXarDfg86uVgoSgNHNNQnyFKcOrQLWVqYMghuSyHh8+2HUH0Js9cTC1WAdg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=23.5.0 || ^22.13.0 || ^20.17.0" + } + }, + "node_modules/@inquirer/input": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/@inquirer/input/-/input-5.1.6.tgz", + "integrity": "sha512-HtcJhB2QFVXbLuJ5S3syhNbTUVxYvwqV4VRBDkQceBloC9bmTViUoRFP5PbSaDZb3HzfPmpuU/gG4ybVBz4FHA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@inquirer/core": "^12.0.3", + "@inquirer/type": "4.1.1" + }, + "engines": { + "node": ">=23.5.0 || ^22.13.0 || ^20.17.0" + }, + "peerDependencies": { + "@types/node": ">=18" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + } + } + }, + "node_modules/@inquirer/number": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/@inquirer/number/-/number-4.2.3.tgz", + "integrity": "sha512-6Yuwh1NGSbu1Lo4N1EWjXs1jKRntLg/ZCwhmeorEHde90v1XxAozdbd4Iu30eOQLW+6h1hp2O9ujNfLSbTPJnA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@inquirer/core": "^12.0.3", + "@inquirer/type": "4.1.1" + }, + "engines": { + "node": ">=23.5.0 || ^22.13.0 || ^20.17.0" + }, + "peerDependencies": { + "@types/node": ">=18" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + } + } + }, + "node_modules/@inquirer/password": { + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/@inquirer/password/-/password-5.2.2.tgz", + "integrity": "sha512-W9zYdyzogK+6110mqwaSJWCBu2yA5Q/OfnGSjjZB1bNpHlmUozXxTl0+QOZBNeVd6Qo81/qT75gW05gLAtITxw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@inquirer/ansi": "^2.0.8", + "@inquirer/core": "^12.0.3", + "@inquirer/type": "4.1.1" + }, + "engines": { + "node": ">=23.5.0 || ^22.13.0 || ^20.17.0" + }, + "peerDependencies": { + "@types/node": ">=18" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + } + } + }, + "node_modules/@inquirer/prompts": { + "version": "8.7.2", + "resolved": "https://registry.npmjs.org/@inquirer/prompts/-/prompts-8.7.2.tgz", + "integrity": "sha512-QoRB4wFIjgH5iOhSjoIKMkTvSHDuV+O3OITlIqAYO0oK5x364GJILXiMBvlPiE+klg7Xx9tq5XVqQHcGUDYYPA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@inquirer/checkbox": "^5.2.5", + "@inquirer/confirm": "^6.3.2", + "@inquirer/editor": "^5.3.3", + "@inquirer/expand": "^5.1.5", + "@inquirer/input": "^5.1.6", + "@inquirer/number": "^4.2.3", + "@inquirer/password": "^5.2.2", + "@inquirer/rawlist": "^5.3.5", + "@inquirer/search": "^4.3.3", + "@inquirer/select": "^5.2.5" + }, + "engines": { + "node": ">=23.5.0 || ^22.13.0 || ^20.17.0" + }, + "peerDependencies": { + "@types/node": ">=18" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + } + } + }, + "node_modules/@inquirer/rawlist": { + "version": "5.3.5", + "resolved": "https://registry.npmjs.org/@inquirer/rawlist/-/rawlist-5.3.5.tgz", + "integrity": "sha512-1oHky1ONfCOwNrnkQGDE1oaSij/3fI6HFMSf2H/WsGO2lEyDX9My82iggITSy9ddSZ8yk8j9v41OI0fVoSIoaA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@inquirer/core": "^12.0.3", + "@inquirer/type": "4.1.1" + }, + "engines": { + "node": ">=23.5.0 || ^22.13.0 || ^20.17.0" + }, + "peerDependencies": { + "@types/node": ">=18" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + } + } + }, + "node_modules/@inquirer/search": { + "version": "4.3.3", + "resolved": "https://registry.npmjs.org/@inquirer/search/-/search-4.3.3.tgz", + "integrity": "sha512-fyuIU1Nbpvwlikjg3gXwJFDI11+EFjqQ7P+iByfmivIKQ1vmaykNrD/vy5unHuUqUpsOsnvJ25//tPF7E/RBRA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@inquirer/core": "^12.0.3", + "@inquirer/figures": "^2.0.9", + "@inquirer/type": "4.1.1" + }, + "engines": { + "node": ">=23.5.0 || ^22.13.0 || ^20.17.0" + }, + "peerDependencies": { + "@types/node": ">=18" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + } + } + }, + "node_modules/@inquirer/select": { + "version": "5.2.5", + "resolved": "https://registry.npmjs.org/@inquirer/select/-/select-5.2.5.tgz", + "integrity": "sha512-9kc15hr8r/kI+3DO/xLog5nOzTz1jqsHXa6JBFzmQKhkoJ8Slda1I1L/uD8ZSZ9tF1yp79wwXe7mclvX1rqR2Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@inquirer/ansi": "^2.0.8", + "@inquirer/core": "^12.0.3", + "@inquirer/figures": "^2.0.9", + "@inquirer/type": "4.1.1" + }, + "engines": { + "node": ">=23.5.0 || ^22.13.0 || ^20.17.0" + }, + "peerDependencies": { + "@types/node": ">=18" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + } + } + }, + "node_modules/@inquirer/type": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/@inquirer/type/-/type-4.1.1.tgz", + "integrity": "sha512-yJoHYrMnxIsJZCY+0Vb66Dy3he3kL3e2wOBKhoSwWWAzZAY82emlxwgprCtp6yRixvNRNq9ztfRWQYPNr3Go7A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=23.5.0 || ^22.13.0 || ^20.17.0" + }, + "peerDependencies": { + "@types/node": ">=18" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + } + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", + "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz", + "integrity": "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.31", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz", + "integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/resolve-uri": "^3.1.0", + "@jridgewell/sourcemap-codec": "^1.4.14" + } + }, + "node_modules/@lukeed/csprng": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@lukeed/csprng/-/csprng-1.1.0.tgz", + "integrity": "sha512-Z7C/xXCiGWsg0KuKsHTKJxbWhpI3Vs5GwLfOean7MGyVFGqdRgBbAjOCh6u4bbjPc/8MJ2pZmK/0DLdCbivLDA==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/@nestjs/cli": { + "version": "12.0.3", + "resolved": "https://registry.npmjs.org/@nestjs/cli/-/cli-12.0.3.tgz", + "integrity": "sha512-HofsPoiWsx6gZ7/IivaZJrgsq/3CTCb4FkCQzFu/Q3J2V+4xC7GYnit/HNB66EfuY8j3gWJCzasMKmF5VugmOA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@angular-devkit/core": "22.1.8", + "@angular-devkit/schematics": "22.1.8", + "@angular-devkit/schematics-cli": "22.1.8", + "@inquirer/prompts": "8.7.2", + "@nestjs/schematics": "^12.0.0", + "ansis": "4.4.0", + "chokidar": "5.0.0", + "cli-table3": "0.6.5", + "commander": "15.0.0", + "minimatch": "10.2.6", + "node-emoji": "2.2.0", + "ora": "9.4.1", + "tsconfig-paths": "4.2.0", + "typescript": "~6.0.2" + }, + "bin": { + "nest": "bin/nest.js" + }, + "engines": { + "node": ">= 20.11" + }, + "peerDependencies": { + "@rspack/core": "^1.7.7 || ^2.1.10", + "@swc/cli": "^0.8.0", + "@swc/core": "^1.15.18", + "fork-ts-checker-webpack-plugin": "^9.1.0", + "ts-loader": "^9.5.4", + "tsconfig-paths-webpack-plugin": "^4.2.0", + "webpack": "^5.105.4", + "webpack-node-externals": "^3.0.0" + }, + "peerDependenciesMeta": { + "@rspack/core": { + "optional": true + }, + "@swc/cli": { + "optional": true + }, + "@swc/core": { + "optional": true + }, + "fork-ts-checker-webpack-plugin": { + "optional": true + }, + "ts-loader": { + "optional": true + }, + "tsconfig-paths-webpack-plugin": { + "optional": true + }, + "webpack": { + "optional": true + }, + "webpack-node-externals": { + "optional": true + } + } + }, + "node_modules/@nestjs/common": { + "version": "12.0.3", + "resolved": "https://registry.npmjs.org/@nestjs/common/-/common-12.0.3.tgz", + "integrity": "sha512-Fosz6lHc9OagZNcF0LTrVHyJS8W7mtuNFBOo9RRccGwyeICBd0hiutjAi9zxnzBcP45RkYXeNB+idA/52jZhBQ==", + "license": "MIT", + "dependencies": { + "@standard-schema/spec": "1.1.0", + "file-type": "22.1.0", + "iterare": "1.2.1", + "load-esm": "1.0.3", + "tslib": "2.8.1", + "uid": "2.0.2" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/nest" + }, + "peerDependencies": { + "class-transformer": ">=0.4.1", + "class-validator": ">=0.13.2", + "reflect-metadata": "^0.1.12 || ^0.2.0", + "rxjs": "^7.1.0" + }, + "peerDependenciesMeta": { + "class-transformer": { + "optional": true + }, + "class-validator": { + "optional": true + } + } + }, + "node_modules/@nestjs/config": { + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/@nestjs/config/-/config-12.0.0.tgz", + "integrity": "sha512-pG5+fFfCo3cdgVkLJLvvhUGfxEjwzv9hIAQ1aJVHvHlHVniDWfwX5pR/utgoAkJzSikv2oTR1BmIF03FXdi42Q==", + "license": "MIT", + "dependencies": { + "@standard-schema/spec": "1.1.0", + "dotenv": "17.4.2", + "dotenv-expand": "13.0.0", + "es-toolkit": "1.51.0" + }, + "peerDependencies": { + "@nestjs/common": "^11.0.0 || ^12.0.0", + "rxjs": "^7.1.0" + } + }, + "node_modules/@nestjs/config/node_modules/dotenv": { + "version": "17.4.2", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.4.2.tgz", + "integrity": "sha512-nI4U3TottKAcAD9LLud4Cb7b2QztQMUEfHbvhTH09bqXTxnSie8WnjPALV/WMCrJZ6UV/qHJ6L03OqO3LcdYZw==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, + "node_modules/@nestjs/core": { + "version": "12.0.3", + "resolved": "https://registry.npmjs.org/@nestjs/core/-/core-12.0.3.tgz", + "integrity": "sha512-Ouv++gAXOL50S8K8n6AN19QGmw51rnIo6v7y9AqUYoaf0NcZlufTu5XTDeC2RtpMz8oXRr9nykBngRjflcoQKA==", + "license": "MIT", + "dependencies": { + "fast-safe-stringify": "2.1.1", + "iterare": "1.2.1", + "path-to-regexp": "8.4.2", + "tslib": "2.8.1", + "uid": "2.0.2" + }, + "engines": { + "node": ">= 20" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/nest" + }, + "peerDependencies": { + "@nestjs/common": "^12.0.0", + "@nestjs/microservices": "^12.0.0", + "@nestjs/platform-express": "^12.0.0", + "@nestjs/websockets": "^12.0.0", + "reflect-metadata": "^0.1.12 || ^0.2.0", + "rxjs": "^7.1.0" + }, + "peerDependenciesMeta": { + "@nestjs/microservices": { + "optional": true + }, + "@nestjs/platform-express": { + "optional": true + }, + "@nestjs/websockets": { + "optional": true + } + } + }, + "node_modules/@nestjs/mau": { + "version": "0.2.8", + "resolved": "https://registry.npmjs.org/@nestjs/mau/-/mau-0.2.8.tgz", + "integrity": "sha512-nIb0i3c/KhKEbxZfYMEKv9Mcvk5miBdZcexnvkgnAUhoMO2BUjOGT+Khf2cZzu7B51Y7v01NG2JVl/HdQEUQ6w==", + "dev": true, + "license": "MIT", + "dependencies": { + "chalk": "4.1.2", + "cli-progress": "3.12.0", + "commander": "4.1.1", + "inquirer": "8.2.6", + "node-emoji": "2.1.3", + "ora": "5.4.1", + "undici": "6.20.1" + }, + "bin": { + "mau": "bin/mau.js" + }, + "engines": { + "node": ">= 20.0.0" + } + }, + "node_modules/@nestjs/mau/node_modules/cli-spinners": { + "version": "2.9.2", + "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.2.tgz", + "integrity": "sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@nestjs/mau/node_modules/commander": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz", + "integrity": "sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 6" + } + }, + "node_modules/@nestjs/mau/node_modules/is-interactive": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-interactive/-/is-interactive-1.0.0.tgz", + "integrity": "sha512-2HvIEKRoqS62guEC+qBjpvRubdX910WCMuJTZ+I9yvqKU2/12eSL549HMwtabb4oupdj2sMP50k+XJfB/8JE6w==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/@nestjs/mau/node_modules/is-unicode-supported": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz", + "integrity": "sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@nestjs/mau/node_modules/log-symbols": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", + "integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==", + "dev": true, + "license": "MIT", + "dependencies": { + "chalk": "^4.1.0", + "is-unicode-supported": "^0.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@nestjs/mau/node_modules/node-emoji": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/node-emoji/-/node-emoji-2.1.3.tgz", + "integrity": "sha512-E2WEOVsgs7O16zsURJ/eH8BqhF029wGpEOnv7Urwdo2wmQanOACwJQh0devF9D9RhoZru0+9JXIS0dBXIAz+lA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@sindresorhus/is": "^4.6.0", + "char-regex": "^1.0.2", + "emojilib": "^2.4.0", + "skin-tone": "^2.0.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@nestjs/mau/node_modules/ora": { + "version": "5.4.1", + "resolved": "https://registry.npmjs.org/ora/-/ora-5.4.1.tgz", + "integrity": "sha512-5b6Y85tPxZZ7QytO+BQzysW31HJku27cRIlkbAXaNx+BdcVi+LlRFmVXzeF6a7JCwJpyw5c4b+YSVImQIrBpuQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "bl": "^4.1.0", + "chalk": "^4.1.0", + "cli-cursor": "^3.1.0", + "cli-spinners": "^2.5.0", + "is-interactive": "^1.0.0", + "is-unicode-supported": "^0.1.0", + "log-symbols": "^4.1.0", + "strip-ansi": "^6.0.0", + "wcwidth": "^1.0.1" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@nestjs/platform-express": { + "version": "12.0.3", + "resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-12.0.3.tgz", + "integrity": "sha512-q9ImjCMjbYYgqvRHHro6sAypNwhjspIAHad0RTL2ww5wYd9gwUGWMss7Q+ACCw5Sksu7Q8S/3rjSLhB+W6B6bg==", + "license": "MIT", + "dependencies": { + "cors": "2.8.6", + "express": "5.2.1", + "multer": "2.4.0", + "path-to-regexp": "8.4.2", + "tslib": "2.8.1" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/nest" + }, + "peerDependencies": { + "@nestjs/common": "^12.0.0", + "@nestjs/core": "^12.0.0" + } + }, + "node_modules/@nestjs/platform-fastify": { + "version": "12.0.3", + "resolved": "https://registry.npmjs.org/@nestjs/platform-fastify/-/platform-fastify-12.0.3.tgz", + "integrity": "sha512-Cn8jR8jwPJBk7ftkzunplz0LHDahnq7urAO9VjOV0OWkk1YCwaFMm4CElSk3BwBiDwP177anJjJUbVxTlASk4A==", + "license": "MIT", + "dependencies": { + "@fastify/cors": "11.3.0", + "@fastify/formbody": "9.0.0", + "@fastify/middie": "9.3.4", + "fast-querystring": "1.1.2", + "fastify": "5.12.4", + "find-my-way": "9.9.0", + "light-my-request": "6.6.0", + "path-to-regexp": "8.4.2", + "tslib": "2.8.1" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/nest" + }, + "peerDependencies": { + "@fastify/static": "^10.1.2", + "@fastify/view": "^10.0.0 || ^11.0.0 || ^12.0.0", + "@nestjs/common": "^12.0.0", + "@nestjs/core": "^12.0.0" + }, + "peerDependenciesMeta": { + "@fastify/static": { + "optional": true + }, + "@fastify/view": { + "optional": true + } + } + }, + "node_modules/@nestjs/platform-fastify/node_modules/fastify": { + "version": "5.12.4", + "resolved": "https://registry.npmjs.org/fastify/-/fastify-5.12.4.tgz", + "integrity": "sha512-zATD676fP6tBMsn+jQ7Q5/cO/Qo+149TXH0dUqUKel+1/hcZxwIbnflqtPa9EjlrvpY8eCZcL3M1UYrMc31Y7g==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT", + "dependencies": { + "@fastify/ajv-compiler": "^4.0.5", + "@fastify/error": "^4.0.0", + "@fastify/fast-json-stringify-compiler": "^5.0.0", + "@fastify/proxy-addr": "^5.0.0", + "abstract-logging": "^2.0.1", + "avvio": "^9.0.0", + "fast-json-stringify": "^7.0.0", + "find-my-way": "^9.6.0", + "light-my-request": "^6.0.0", + "pino": "^9.14.0 || ^10.1.0", + "process-warning": "^5.1.0", + "rfdc": "^1.3.1", + "secure-json-parse": "^4.0.0", + "semver": "^7.6.0", + "toad-cache": "^3.7.0" + } + }, + "node_modules/@nestjs/schematics": { + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/@nestjs/schematics/-/schematics-12.0.0.tgz", + "integrity": "sha512-ilsxam7i+SWd2psr12faLVSk86FYKnxRUGO6jAGNi1P9+O0kRaYVOScyrKeIj97W9T9UJoJF38fg+7KgjY/nOg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@angular-devkit/core": "22.1.5", + "@angular-devkit/schematics": "22.1.5", + "comment-json": "5.0.0", + "jsonc-parser": "3.3.1", + "pluralize": "8.0.0" + }, + "engines": { + "node": ">=22.12.0" + }, + "peerDependencies": { + "prettier": "^3.0.0", + "typescript": ">=6.0.0" + }, + "peerDependenciesMeta": { + "prettier": { + "optional": true + } + } + }, + "node_modules/@nestjs/schematics/node_modules/@angular-devkit/core": { + "version": "22.1.5", + "resolved": "https://registry.npmjs.org/@angular-devkit/core/-/core-22.1.5.tgz", + "integrity": "sha512-HiY6d5dkIdJs5grP9OHvgkf14QOcDIo+hbuT7YKuLItQ++ZxCwUabJMLCCJ5R0KrstE5NqED0dNcyk5WD01t5Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "ajv": "8.20.0", + "ajv-formats": "3.0.1", + "jsonc-parser": "3.3.1", + "picomatch": "4.0.5", + "rxjs": "7.8.2", + "source-map": "0.7.6" + }, + "engines": { + "node": "^22.22.3 || ^24.15.0 || >=26.0.0", + "npm": "^6.11.0 || ^7.5.6 || >=8.0.0", + "yarn": ">= 1.13.0" + }, + "peerDependencies": { + "chokidar": "^5.0.0" + }, + "peerDependenciesMeta": { + "chokidar": { + "optional": true + } + } + }, + "node_modules/@nestjs/schematics/node_modules/@angular-devkit/schematics": { + "version": "22.1.5", + "resolved": "https://registry.npmjs.org/@angular-devkit/schematics/-/schematics-22.1.5.tgz", + "integrity": "sha512-HTmo9y8wjXKtJGVTYomTjZsjWzhirpu1pPRAzsVob3eiYOuxv1qDRAgWiHXNGp5CpnbHunZweXY/WffNGOFRyA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@angular-devkit/core": "22.1.5", + "jsonc-parser": "3.3.1", + "magic-string": "1.0.0", + "ora": "9.4.1", + "rxjs": "7.8.2" + }, + "engines": { + "node": "^22.22.3 || ^24.15.0 || >=26.0.0", + "npm": "^6.11.0 || ^7.5.6 || >=8.0.0", + "yarn": ">= 1.13.0" + } + }, + "node_modules/@nestjs/testing": { + "version": "12.0.3", + "resolved": "https://registry.npmjs.org/@nestjs/testing/-/testing-12.0.3.tgz", + "integrity": "sha512-TYDvBI8HvYeldNCmsuSaE4XqSs1Mg7IekSPlJf+zbrVt3+s5sqt4ySMUhbTs8JpMTFMyqCwtPTGVHIcFVuTBbQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "tslib": "2.8.1" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/nest" + }, + "peerDependencies": { + "@nestjs/common": "^12.0.0", + "@nestjs/core": "^12.0.0", + "@nestjs/microservices": "^12.0.0", + "@nestjs/platform-express": "^12.0.0" + }, + "peerDependenciesMeta": { + "@nestjs/microservices": { + "optional": true + }, + "@nestjs/platform-express": { + "optional": true + } + } + }, + "node_modules/@noble/hashes": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.8.0.tgz", + "integrity": "sha512-jCs9ldd7NwzpgXDIf6P3+NrHh9/sD6CQdxHyjQI+h/6rDNo88ypBxxz45UDuZHz9r3tNz7N/VInSVoVdtXEI4A==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^14.21.3 || >=16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@ogma/common": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@ogma/common/-/common-1.2.0.tgz", + "integrity": "sha512-y2GHkT4t3B9CoI7ELfgZXeMHiiOC/X4XvdeqYLbP5A3keop7fANzjd5pQdtyYQvdQ0lPzcHJiMvOGkIINZHZHQ==", + "dev": true + }, + "node_modules/@ogma/styler": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@ogma/styler/-/styler-1.1.0.tgz", + "integrity": "sha512-OtwJ8Ump3sKEAv2DIUi+R2G2Y5v3cEzqRO/sH11MTWikAhac31GZR/xzU+3BoPRT0u8oIob7N5dtOKTdPhqq3w==", + "dev": true, + "dependencies": { + "@ogma/common": "^1.1.1" + } + }, + "node_modules/@oxc-project/types": { + "version": "0.150.0", + "resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.150.0.tgz", + "integrity": "sha512-rDS5/31E9HfPl/CIzGrn0DOlvBbXFseQ5URJ9sYMfstbKLD/c6Gm9vmRzRGDdAXyOIL4zmO37lc9RIwYqVruZw==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/oxc-project" + } + }, + "node_modules/@oxlint/binding-android-arm-eabi": { + "version": "1.83.0", + "resolved": "https://registry.npmjs.org/@oxlint/binding-android-arm-eabi/-/binding-android-arm-eabi-1.83.0.tgz", + "integrity": "sha512-0yGY24EwsLk5YDe6F+VkmZyRHSwJDALa3nIrPpq7FXmp2lV2d0TzvBCGeZk+wgiULRGr5blhyr4QMp5KCXJUqA==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxlint/binding-android-arm64": { + "version": "1.83.0", + "resolved": "https://registry.npmjs.org/@oxlint/binding-android-arm64/-/binding-android-arm64-1.83.0.tgz", + "integrity": "sha512-hHfJ0vc17A4iUjH5p9BsTUPYbYRNxGpvD2lbu1aBRk54bzNIx9o5TtYF39QPZcV95DagZd+4DEAw2RH3G2ZsMg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxlint/binding-darwin-arm64": { + "version": "1.83.0", + "resolved": "https://registry.npmjs.org/@oxlint/binding-darwin-arm64/-/binding-darwin-arm64-1.83.0.tgz", + "integrity": "sha512-hsOjYjszLb/3zym/TkzUMPAoQlTJcuzSyEPOAyA+skXJIX9M0o+4JfOtqopX/Vf4hSLrJ98j0nvFo23gzk8auQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxlint/binding-darwin-x64": { + "version": "1.83.0", + "resolved": "https://registry.npmjs.org/@oxlint/binding-darwin-x64/-/binding-darwin-x64-1.83.0.tgz", + "integrity": "sha512-mjh5oH2EA+wl5yRJYT9K9G61O2zFlpuv+yf2JwZOi0+dq2FnTUtm1h8i+5Ik0fXPWIu/k84I1psZR9aQsLAnyA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxlint/binding-freebsd-x64": { + "version": "1.83.0", + "resolved": "https://registry.npmjs.org/@oxlint/binding-freebsd-x64/-/binding-freebsd-x64-1.83.0.tgz", + "integrity": "sha512-fNHr64/YaO8YssuoDVC8+F4Uk5enR86q5uxfHkQrjAPs1dbAILOrD2uaud+J7MO8Fx774g44ERLD0IGIvZE48w==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxlint/binding-linux-arm-gnueabihf": { + "version": "1.83.0", + "resolved": "https://registry.npmjs.org/@oxlint/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-1.83.0.tgz", + "integrity": "sha512-Qpwy3zzAwMj+8/lyYItHmkSMwbkprFNWTK7jPYDOxSyxEhaSLOWYUTCMkjF334J8/WD0nznCCsoBbIH6hpsuIw==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxlint/binding-linux-arm-musleabihf": { + "version": "1.83.0", + "resolved": "https://registry.npmjs.org/@oxlint/binding-linux-arm-musleabihf/-/binding-linux-arm-musleabihf-1.83.0.tgz", + "integrity": "sha512-s+BirYLFq7JL2k9sP0XI3ZXJ9dYvJ8sX3jLCLoag7tt+zrSHpZxP0jqznfL+Gdgwu7ay0dYgGYJXrQvq3iWloA==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxlint/binding-linux-arm64-gnu": { + "version": "1.83.0", + "resolved": "https://registry.npmjs.org/@oxlint/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-1.83.0.tgz", + "integrity": "sha512-7lihXt3vKr+GIyapNbHrnFHm/biiW30le6Zv/DExbAFPF6YwCQXVFlONPFehxs0CpGO4CBfYPM9rdDT+XMoIlg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxlint/binding-linux-arm64-musl": { + "version": "1.83.0", + "resolved": "https://registry.npmjs.org/@oxlint/binding-linux-arm64-musl/-/binding-linux-arm64-musl-1.83.0.tgz", + "integrity": "sha512-q63JalLYVkZiZvls1z3PPUnpmQluOMXp0khqQMznCeAPLGydfNY8JhvuA4WlK57JfrvikU8wB5lPVveqpIXvew==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxlint/binding-linux-ppc64-gnu": { + "version": "1.83.0", + "resolved": "https://registry.npmjs.org/@oxlint/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-1.83.0.tgz", + "integrity": "sha512-krQmDF+dRbxvdqVPV88ZuOoPPu8X5BuqDA8Hd+qcS4YMRQCb+nexA57DazgGsc/rGdKBe3QmV0mnv0bdpW/p5g==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxlint/binding-linux-riscv64-gnu": { + "version": "1.83.0", + "resolved": "https://registry.npmjs.org/@oxlint/binding-linux-riscv64-gnu/-/binding-linux-riscv64-gnu-1.83.0.tgz", + "integrity": "sha512-MmOl8Y6txEAXZU1RG8Rr264jQ6D7VPmqFsU/45x/FeWsGe32hklTqGrLE6UxHzp5Rjt0wP+20tY8YXKgSFB3mw==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxlint/binding-linux-riscv64-musl": { + "version": "1.83.0", + "resolved": "https://registry.npmjs.org/@oxlint/binding-linux-riscv64-musl/-/binding-linux-riscv64-musl-1.83.0.tgz", + "integrity": "sha512-u1rMymh0W3JZkq370kzQsYPULGWqhE09pZRqnZvUSoYaI9pVO5yVX+iYIslmWuEgwuzH9YAaOsScJiobWCHoOw==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxlint/binding-linux-s390x-gnu": { + "version": "1.83.0", + "resolved": "https://registry.npmjs.org/@oxlint/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-1.83.0.tgz", + "integrity": "sha512-y0zK3HNwGysu7rqtE+BQG/d0bx5gh/KwlOtghN8oWeK1KcWzeaLqtZrbm8owqdma1lFyrce/hTO5ismuNu+INQ==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxlint/binding-linux-x64-gnu": { + "version": "1.83.0", + "resolved": "https://registry.npmjs.org/@oxlint/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.83.0.tgz", + "integrity": "sha512-rS5gM0NgD7ngmuJmbIehsidtrOwKkLFwCQbKEeb9KuyQrrWNq5Zkn0uV6AYdXOMJ0grrWEiLwBuvMxt8w5vsNw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxlint/binding-linux-x64-musl": { + "version": "1.83.0", + "resolved": "https://registry.npmjs.org/@oxlint/binding-linux-x64-musl/-/binding-linux-x64-musl-1.83.0.tgz", + "integrity": "sha512-W2IH4EtpcPaWcvNGCA95YoDg4vxqE/ZiPCi3arrxEEpsK7+JQN9WYwrlYFx9pcdP6KPXqRqkv3zdQPHcx7b6YQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxlint/binding-openharmony-arm64": { + "version": "1.83.0", + "resolved": "https://registry.npmjs.org/@oxlint/binding-openharmony-arm64/-/binding-openharmony-arm64-1.83.0.tgz", + "integrity": "sha512-6LyKkUyoajssTPLlZmDbZIbu4IZ5B4bGuRUnBgCGpEvHP3FQMaYITncHA/unPUo7q+Z+pIu2HhdkQ+8d1SG7iA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxlint/binding-win32-arm64-msvc": { + "version": "1.83.0", + "resolved": "https://registry.npmjs.org/@oxlint/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.83.0.tgz", + "integrity": "sha512-Uz/fObEtF0jmNJQJ8CGRBKfefYstS0/wjD3s6IGzP8nUwsJykHQJBiN3npHwKiGRGn/vvBEgNr4B3cCzmmatvg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxlint/binding-win32-ia32-msvc": { + "version": "1.83.0", + "resolved": "https://registry.npmjs.org/@oxlint/binding-win32-ia32-msvc/-/binding-win32-ia32-msvc-1.83.0.tgz", + "integrity": "sha512-u7XcvPW6Bk58tY5iWs2ESb0vJjoE/kuSpHxopbwp/p3ZtWVQXZ6wor5w3ssVTHOqd/v8b+QdhSFWQ4grEUNWpA==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxlint/binding-win32-x64-msvc": { + "version": "1.83.0", + "resolved": "https://registry.npmjs.org/@oxlint/binding-win32-x64-msvc/-/binding-win32-x64-msvc-1.83.0.tgz", + "integrity": "sha512-LZRubd7ph13QmAg4fFecTYVZkiYbROR2Htaxh/ufWRkDhPOm2wrwaEYR89e0YpPFD3dqBrPoxS7myBw5hmYA7Q==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@paralleldrive/cuid2": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/@paralleldrive/cuid2/-/cuid2-2.3.1.tgz", + "integrity": "sha512-XO7cAxhnTZl0Yggq6jOgjiOHhbgcO4NqFqwSmQpjK3b6TEE6Uj/jfSk6wzYyemh3+I0sHirKSetjQwn5cZktFw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@noble/hashes": "^1.1.5" + } + }, + "node_modules/@phc/format": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@phc/format/-/format-1.0.0.tgz", + "integrity": "sha512-m7X9U6BG2+J+R1lSOdCiITLLrxm+cWlNI3HUFA92oLO77ObGNzaKdh8pMLqdZcshtkKuV84olNNXDfMc4FezBQ==", + "license": "MIT", + "engines": { + "node": ">=10" + } + }, + "node_modules/@pinojs/redact": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@pinojs/redact/-/redact-0.4.0.tgz", + "integrity": "sha512-k2ENnmBugE/rzQfEcdWHcCY+/FM3VLzH9cYEsbdsoqrvzAKRhUZeRNhAZvB8OitQJ1TBed3yqWtdjzS6wJKBwg==", + "license": "MIT" + }, + "node_modules/@redis/bloom": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/@redis/bloom/-/bloom-6.3.0.tgz", + "integrity": "sha512-NQ5poYpZr0jv6zazN1cy6JY5kIipKFZ3R9GTL4kOUTX3a9YAfY29U8bsE4lWhVQEM+G4V0BXVC57mubIdDijeA==", + "license": "MIT", + "engines": { + "node": ">= 20.0.0" + }, + "peerDependencies": { + "@redis/client": "^6.3.0" + } + }, + "node_modules/@redis/client": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/@redis/client/-/client-6.3.0.tgz", + "integrity": "sha512-fHrjwGCBvAANGi+TuRuwKi83sIOzgHr8eh+Uf48w3fSX7Hhrz174NrWqfJhAC2vnN0d/tfaZpdr6+o6JC3QHwg==", + "license": "MIT", + "engines": { + "node": ">= 20.0.0" + }, + "peerDependencies": { + "@node-rs/xxhash": "^1.1.0", + "@opentelemetry/api": ">=1 <2" + }, + "peerDependenciesMeta": { + "@node-rs/xxhash": { + "optional": true + }, + "@opentelemetry/api": { + "optional": true + } + } + }, + "node_modules/@redis/json": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/@redis/json/-/json-6.3.0.tgz", + "integrity": "sha512-yt6vRfPBXtW/3qm53cF81TSQpLMjWdW4/2E9WQ2GgbvsKkuCKCFQIcMiKlil1ZMnezK+IQuS795xKU5psbaegw==", + "license": "MIT", + "engines": { + "node": ">= 20.0.0" + }, + "peerDependencies": { + "@redis/client": "^6.3.0" + } + }, + "node_modules/@redis/search": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/@redis/search/-/search-6.3.0.tgz", + "integrity": "sha512-RPXAZmKjZZG7Tm7m1w9keFdXzbL91PiSHQBfQRe9xwW40jNsTRbG0FwhIz4QlHPU4gKDAsCy8IQHj4yZl4H9rw==", + "license": "MIT", + "engines": { + "node": ">= 20.0.0" + }, + "peerDependencies": { + "@redis/client": "^6.3.0" + } + }, + "node_modules/@redis/time-series": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/@redis/time-series/-/time-series-6.3.0.tgz", + "integrity": "sha512-+fJOB8mN1z5WRakCJNh5lVdz1KqvHGSOistsKeitD24QsCtPwyRQXWC0iq6T/i/ubLE/YcguZqPm8F598MKk4A==", + "license": "MIT", + "engines": { + "node": ">= 20.0.0" + }, + "peerDependencies": { + "@redis/client": "^6.3.0" + } + }, + "node_modules/@rolldown/binding-android-arm-eabi": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm-eabi/-/binding-android-arm-eabi-1.2.9.tgz", + "integrity": "sha512-tNISae1QEf/vkb3xkRcjV5SEdzPE97We5IVaa2Z8jSszQPZ8U60B/YCYpw4QI7VidYsBtKavczXf+DyDs9WGxw==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-android-arm64": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm64/-/binding-android-arm64-1.2.9.tgz", + "integrity": "sha512-YC8YsI30o606GTZi0VyzYlsDKFP8W61i/QzayHDkLbNEz/IShqAmTa+hsJRj13xTHA0H+6fk4b2UmGn+Q/cMlg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-darwin-arm64": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-arm64/-/binding-darwin-arm64-1.2.9.tgz", + "integrity": "sha512-IwhlH3qK5urrY8hZiEgGkHKEFN901p/p2bjxCxJlr4GyNnF7wYpUvK+Y43uaRYuC4hpfjzbR3SJC3arX1jGvmw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-darwin-x64": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-x64/-/binding-darwin-x64-1.2.9.tgz", + "integrity": "sha512-XxpJfVzFh+jilRxIXUqcfYAYcunIc/XEzIizsOL1fcJee5Sf7H3mH8WlLmfHfluz5amqR88QQo9izKtmMlavAw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-freebsd-x64": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/@rolldown/binding-freebsd-x64/-/binding-freebsd-x64-1.2.9.tgz", + "integrity": "sha512-kSfvhmgeWyfkbT3p/1s5vSgboogoah2zkm9fX2zjg2hHxSV7T4KhMWRUUaRk4OXNqoD3QAUeRqLcs1aZOK4U1g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm-gnueabihf": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-1.2.9.tgz", + "integrity": "sha512-1RVzG17pxqbTfYLC352JlLt6kKLG+6Hr30n8DlIJqsnV5luUDd2Qdx9Ayw1Cabfyb1K9k0jXEZ7evxkRoT+uiw==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm64-gnu": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-1.2.9.tgz", + "integrity": "sha512-BXqPvZ2drqVD+/Z8UpKwcs4Mp7grM+eGFku4CAEKrEtcbAsUpzREphK1sogCRZGreVPiMkiiBtw0n3TPteuqvw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm64-musl": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-musl/-/binding-linux-arm64-musl-1.2.9.tgz", + "integrity": "sha512-11vWvo8YDwLzukt27J3aYDWU+gg2P7J+ZOmiJ0hkF5BXZDW7pVya7r40MXDy6ya0i9KamoENSVKIugvJNgFXIA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-ppc64-gnu": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-1.2.9.tgz", + "integrity": "sha512-a1tijMkdwsIARtc0F39ApURROkf3NwqinI6TOiSSWCTR7dT96dffNvMUtDHnq64wKNTIZOIlzKrFvvFUznJiyw==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-s390x-gnu": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-1.2.9.tgz", + "integrity": "sha512-x6SQNdAvv4c3hWqTMaWuawzMX9myaCs/yEmlGsxJzkdClnHW7FbrjQuSiRDhuSYzEYoEMhsaJy9qHG/XNemJPQ==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-x64-gnu": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.2.9.tgz", + "integrity": "sha512-9s0AZ8BFK5/n7B/TBoa2yJE3gI3KURrbXcPBlsAsvjU4VeJKgE90y1YtNxyEUIcHPQkg6/yfF3qihUrcM/Kf0Q==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-x64-musl": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-musl/-/binding-linux-x64-musl-1.2.9.tgz", + "integrity": "sha512-P7VWAmV+WdJluH7ovnRGoiv2i8To7GAZ+kGzfGup635cyL7SyYl3lSUaA3Gp5THf0n/Co5EyEqb2zbqq+nMOHQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-openharmony-arm64": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/@rolldown/binding-openharmony-arm64/-/binding-openharmony-arm64-1.2.9.tgz", + "integrity": "sha512-1qixtsE4BK8h+yS3BfmZ09UhA7O/N4IACva6YBr7EBvCJraByTuRcgOTaiA62Tm0vey3UcKXLOaoGHtYmNGEVg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-win32-arm64-msvc": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.2.9.tgz", + "integrity": "sha512-ok8IQjcEPs1AKZfuEUznVBrJw+gK4soq+bx8b1X2XoMqVClarc1q5JDmVtWXY1xfr6ZuHTAsPXHTgTrqKTZeww==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-win32-x64-msvc": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-x64-msvc/-/binding-win32-x64-msvc-1.2.9.tgz", + "integrity": "sha512-Ip2mXoU0hM0boq3Rf+ekuT653OROSo6aSYcPT1VHE4q52KvyxgFkQgrgb/IEsxOuvQ2fZZbs8khJAyCEPM24/g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/pluginutils": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.1.tgz", + "integrity": "sha512-2j9bGt5Jh8hj+vPtgzPtl72j0yRxHAyumoo6TNfAjsLB04UtpSvPbPcDcBMxz7n+9CYB0c1GxQFxYRg2jimqGw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@sindresorhus/is": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz", + "integrity": "sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sindresorhus/is?sponsor=1" + } + }, + "node_modules/@standard-schema/spec": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.1.0.tgz", + "integrity": "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==", + "license": "MIT" + }, + "node_modules/@tokenizer/inflate": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/@tokenizer/inflate/-/inflate-0.4.1.tgz", + "integrity": "sha512-2mAv+8pkG6GIZiF1kNg1jAjh27IDxEPKwdGul3snfztFerfPGI1LjDezZp3i7BElXompqEtPmoPx6c2wgtWsOA==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.3", + "token-types": "^6.1.1" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Borewit" + } + }, + "node_modules/@tokenizer/token": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@tokenizer/token/-/token-0.3.0.tgz", + "integrity": "sha512-OvjF+z51L3ov0OyAU0duzsYuvO01PH7x4t6DJx+guahgTnBHkhJdG7soQeTSFLWN3efnHyibZ4Z8l2EuWwJN3A==", + "license": "MIT" + }, + "node_modules/@types/body-parser": { + "version": "1.19.6", + "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.6.tgz", + "integrity": "sha512-HLFeCYgz89uk22N5Qg3dvGvsv46B8GLvKKo1zKG4NybA8U2DiEO3w9lqGg29t/tfLRJpJ6iQxnVw4OnB7MoM9g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/connect": "*", + "@types/node": "*" + } + }, + "node_modules/@types/chai": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", + "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/deep-eql": "*", + "assertion-error": "^2.0.1" + } + }, + "node_modules/@types/connect": { + "version": "3.4.38", + "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz", + "integrity": "sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/cookiejar": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/@types/cookiejar/-/cookiejar-2.1.5.tgz", + "integrity": "sha512-he+DHOWReW0nghN24E1WUqM0efK4kI9oTqDm6XmK8ZPe2djZ90BSNdGnIyCLzCPw7/pogPlGbzI2wHGGmi4O/Q==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/deep-eql": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz", + "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/estree": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.9.tgz", + "integrity": "sha512-GhdPgy1el4/ImP05X05Uw4cw2/M93BCUmnEvWZNStlCzEKME4Fkk+YpoA5OiHNQmoS7Cafb8Xa3Pya8m1Qrzeg==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/express": { + "version": "5.0.6", + "resolved": "https://registry.npmjs.org/@types/express/-/express-5.0.6.tgz", + "integrity": "sha512-sKYVuV7Sv9fbPIt/442koC7+IIwK5olP1KWeD88e/idgoJqDm3JV/YUiPwkoKK92ylff2MGxSz1CSjsXelx0YA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/body-parser": "*", + "@types/express-serve-static-core": "^5.0.0", + "@types/serve-static": "^2" + } + }, + "node_modules/@types/express-serve-static-core": { + "version": "5.1.3", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-5.1.3.tgz", + "integrity": "sha512-dPfW8NFiOF4wOHc7+N/QSxlY9cfSsenewGbAz8C8U/MULPd/YZ27LvJUIlzaXie7e6Ove9YunJGgC9tbHD2cKw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*", + "@types/qs": "*", + "@types/range-parser": "*", + "@types/send": "*" + } + }, + "node_modules/@types/http-errors": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@types/http-errors/-/http-errors-2.0.5.tgz", + "integrity": "sha512-r8Tayk8HJnX0FztbZN7oVqGccWgw98T/0neJphO91KkmOzug1KkofZURD4UaD5uH8AqcFLfdPErnBod0u71/qg==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/methods": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@types/methods/-/methods-1.1.4.tgz", + "integrity": "sha512-ymXWVrDiCxTBE3+RIrrP533E70eA+9qu7zdWoHuOmGujkYtzf4HQF96b8nwHLqhuf4ykX61IGRIB38CC6/sImQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/node": { + "version": "24.13.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-24.13.5.tgz", + "integrity": "sha512-TXyindR+lBr22aJIdMQzCFHPHR6cR4js838mRDCSz5hOKWZvZwsXSSiXDmjRj4iJmgl+sR9O+1mkoVBSMadNug==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~7.18.0" + } + }, + "node_modules/@types/pg": { + "version": "8.23.1", + "resolved": "https://registry.npmjs.org/@types/pg/-/pg-8.23.1.tgz", + "integrity": "sha512-fKVHpikPdg4GKks3JuLEhvwSyvwzF23hnabPy6DD8ljVbC7+6J5dQzdv4arV6jqq57djnMgs1HKBxX4P8aBI3A==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*", + "pg-protocol": "*", + "pg-types": "^2.2.0" + } + }, + "node_modules/@types/qs": { + "version": "6.15.1", + "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.15.1.tgz", + "integrity": "sha512-GZHUBZR9hckSUhrxmp1nG6NwdpM9fCunJwyThLW1X3AyHgd9IlHb6VANpQQqDr2o/qQp6McZ3y/IA2rVzKzSbw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/range-parser": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.7.tgz", + "integrity": "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/send": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@types/send/-/send-1.2.1.tgz", + "integrity": "sha512-arsCikDvlU99zl1g69TcAB3mzZPpxgw0UQnaHeC1Nwb015xp8bknZv5rIfri9xTOcMuaVgvabfIRA7PSZVuZIQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/serve-static": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-2.2.0.tgz", + "integrity": "sha512-8mam4H1NHLtu7nmtalF7eyBH14QyOASmcxHhSfEoRyr0nP/YdoesEtU+uSRvMe96TW/HPTtkoKqQLl53N7UXMQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/http-errors": "*", + "@types/node": "*" + } + }, + "node_modules/@types/superagent": { + "version": "8.1.11", + "resolved": "https://registry.npmjs.org/@types/superagent/-/superagent-8.1.11.tgz", + "integrity": "sha512-KA7srSW/HENDtOw9DOqaFLgWuMqN9WgjEw62lh9dpvRaZDkhdOkazASd7X7i2eMUYLHa1U37ZttnePsH5zTDHw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/cookiejar": "^2.1.5", + "@types/methods": "^1.1.4", + "@types/node": "*", + "form-data": "^4.0.0" + } + }, + "node_modules/@types/supertest": { + "version": "7.2.1", + "resolved": "https://registry.npmjs.org/@types/supertest/-/supertest-7.2.1.tgz", + "integrity": "sha512-4CbBvoYVLHL7+yhbYrZET0vsvuyXTC05aRe7dNQkwMzm56auceoy6Yu3K50uZmwfHna1os3CMSgM/3QVkUtPTw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/methods": "^1.1.4", + "@types/superagent": "^8.1.0" + } + }, + "node_modules/@types/validator": { + "version": "13.15.10", + "resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.15.10.tgz", + "integrity": "sha512-T8L6i7wCuyoK8A/ZeLYt1+q0ty3Zb9+qbSSvrIVitzT3YjZqkTZ40IbRsPanlB4h1QB3JVL1SYCdR6ngtFYcuA==", + "license": "MIT" + }, + "node_modules/@vitest/coverage-v8": { + "version": "4.1.11", + "resolved": "https://registry.npmjs.org/@vitest/coverage-v8/-/coverage-v8-4.1.11.tgz", + "integrity": "sha512-8MVGEFnJIcdGjcbfKmeq8z0pZHH0JlVtoVZH9Q/qwUp6wyFnEJUBMrw9DCaj+ra3vShGmhavjalMIhPNxZAUcw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@bcoe/v8-coverage": "^1.0.2", + "@vitest/utils": "4.1.11", + "ast-v8-to-istanbul": "^1.0.0", + "istanbul-lib-coverage": "^3.2.2", + "istanbul-lib-report": "^3.0.1", + "istanbul-reports": "^3.2.0", + "magicast": "^0.5.2", + "obug": "^2.1.1", + "std-env": "^4.0.0-rc.1", + "tinyrainbow": "^3.1.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "@vitest/browser": "4.1.11", + "vitest": "4.1.11" + }, + "peerDependenciesMeta": { + "@vitest/browser": { + "optional": true + } + } + }, + "node_modules/@vitest/expect": { + "version": "4.1.11", + "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-4.1.11.tgz", + "integrity": "sha512-VX2x5vNJXET47KAFzwERI+KRMtTTCSWTfSMKsW7JsUsXV4psq++e3DvZpuTDOpHcxytiDs6p2nhVb2tVDiiUYw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@standard-schema/spec": "^1.1.0", + "@types/chai": "^5.2.2", + "@vitest/spy": "4.1.11", + "@vitest/utils": "4.1.11", + "chai": "^6.2.2", + "tinyrainbow": "^3.1.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/mocker": { + "version": "4.1.11", + "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-4.1.11.tgz", + "integrity": "sha512-2XJVD55d1o5AZous5CCGKS74g/riOj9odEt2bQpCVZeblHyHdnMeFl4jl0XjU21stf4mbjUkew2eXQZt65g5CQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/spy": "4.1.11", + "estree-walker": "^3.0.3", + "magic-string": "^0.30.21" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "msw": "^2.4.9", + "vite": "^6.0.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "msw": { + "optional": true + }, + "vite": { + "optional": true + } + } + }, + "node_modules/@vitest/mocker/node_modules/magic-string": { + "version": "0.30.21", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz", + "integrity": "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.5.5" + } + }, + "node_modules/@vitest/pretty-format": { + "version": "4.1.11", + "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-4.1.11.tgz", + "integrity": "sha512-yiZzPbGTS9Sr/JpFl8zHrcIkAofNbFV6k21vIgQN/cY/oxZeXhJv5sc/MBJ5jFKWmWs+oJHw0UXLZjmf931+Vw==", + "dev": true, + "license": "MIT", + "dependencies": { + "tinyrainbow": "^3.1.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/runner": { + "version": "4.1.11", + "resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-4.1.11.tgz", + "integrity": "sha512-LztvUgdwMNJMIkj3hQnnxiC2Xy1zNxq928W/xhjCLaNCzqTZOudjwbQf6v9IntZGPw132i2Lq2rgTRZHD3JHNw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/utils": "4.1.11", + "pathe": "^2.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/snapshot": { + "version": "4.1.11", + "resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-4.1.11.tgz", + "integrity": "sha512-pN7ikn1ON7h8ee4gIAp4AzyK+zBtJPzVbqOgu5LCEh4VaJVbPQcgYQYJIMGQPXVeJJq1fnfazis7a5pFNPahog==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/pretty-format": "4.1.11", + "@vitest/utils": "4.1.11", + "magic-string": "^0.30.21", + "pathe": "^2.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/snapshot/node_modules/magic-string": { + "version": "0.30.21", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz", + "integrity": "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.5.5" + } + }, + "node_modules/@vitest/spy": { + "version": "4.1.11", + "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-4.1.11.tgz", + "integrity": "sha512-apNa/prQy2qCeywhnixOHPRCgGNhvg7T4Dapfl1GahLp/R+uhBm5cPyFoNVyqsNd2h1nJxL6BqqdIjiABL60YA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/utils": { + "version": "4.1.11", + "resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-4.1.11.tgz", + "integrity": "sha512-zTCVGpyFsGWBhllOyKlTw/vnr6D9qxsfSDyfbyZmTyjHw5N/VuvzHpHoQjm2ZJzn4RJgx5w4r7V0er69CmLgPQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/pretty-format": "4.1.11", + "convert-source-map": "^2.0.0", + "tinyrainbow": "^3.1.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/abstract-logging": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/abstract-logging/-/abstract-logging-2.0.1.tgz", + "integrity": "sha512-2BjRTZxTPvheOvGbBslFSYOUkr+SjPtOnrLP33f+VIWLzezQpZcqVg7ja3L4dBXmzzgwT+a029jRx5PCi3JuiA==", + "license": "MIT" + }, + "node_modules/accepts": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz", + "integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==", + "license": "MIT", + "dependencies": { + "mime-types": "^3.0.0", + "negotiator": "^1.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/ajv": { + "version": "8.20.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz", + "integrity": "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==", + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/ajv-formats": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz", + "integrity": "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==", + "license": "MIT", + "dependencies": { + "ajv": "^8.0.0" + }, + "peerDependencies": { + "ajv": "^8.0.0" + }, + "peerDependenciesMeta": { + "ajv": { + "optional": true + } + } + }, + "node_modules/ansi-escapes": { + "version": "4.3.2", + "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz", + "integrity": "sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "type-fest": "^0.21.3" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "license": "MIT", + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/ansis": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/ansis/-/ansis-4.4.0.tgz", + "integrity": "sha512-9k3v7xcHwgdO/DruxGIg4HtjvlAZlcnsX/mzqUb1t3NkYnl9kK2UJ+Gq0io+vQf7iT//BD/HB/NBkUR1LWxoeA==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=14" + } + }, + "node_modules/append-field": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz", + "integrity": "sha512-klpgFSWLW1ZEs8svjfb7g4qWY0YS5imI82dTg+QahUvJ8YqAY0P10Uk8tTyh9ZGuYEZEMaeJYCF5BFuX552hsw==", + "license": "MIT" + }, + "node_modules/argon2": { + "version": "0.45.1", + "resolved": "https://registry.npmjs.org/argon2/-/argon2-0.45.1.tgz", + "integrity": "sha512-skm+/WCjkGqCQxF7FG1LuZXM5yvbFjgbfiCGsud2oLgaDhh6b6dbH0b1EkghbM+xx4Bj8Ape+KKgixoIlWZicQ==", + "hasInstallScript": true, + "license": "MIT", + "dependencies": { + "@phc/format": "^1.0.0", + "cross-env": "^10.1.0", + "node-addon-api": "^8.9.0", + "node-gyp-build": "^4.8.4" + }, + "engines": { + "node": ">=16.17.0" + } + }, + "node_modules/array-timsort": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/array-timsort/-/array-timsort-1.0.3.tgz", + "integrity": "sha512-/+3GRL7dDAGEfM6TseQk/U+mi18TU2Ms9I3UlLdUMhz2hbvGNTKdj9xniwXfUqgYhHxRx0+8UnKkvlNwVU+cWQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/asap": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", + "integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==", + "dev": true, + "license": "MIT" + }, + "node_modules/assertion-error": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz", + "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + } + }, + "node_modules/ast-v8-to-istanbul": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/ast-v8-to-istanbul/-/ast-v8-to-istanbul-1.0.6.tgz", + "integrity": "sha512-fvpl29helSO2w/z7utIbrkNXILdrLwDwAMH2I/zPKlGf5244+gf+B4cyS1sANcrPY2h+hWCGSgC8N61s/+AF9A==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/trace-mapping": "^0.3.31", + "estree-walker": "^3.0.3", + "js-tokens": "^10.0.0" + } + }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "dev": true, + "license": "MIT" + }, + "node_modules/atomic-sleep": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/atomic-sleep/-/atomic-sleep-1.0.0.tgz", + "integrity": "sha512-kNOjDqAh7px0XWNI+4QbzoiR/nTkHAWNud2uvnJquD1/x5a7EQZMJT0AczqK0Qn67oY/TTQ1LbUKajZpp3I9tQ==", + "license": "MIT", + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/avvio": { + "version": "9.3.0", + "resolved": "https://registry.npmjs.org/avvio/-/avvio-9.3.0.tgz", + "integrity": "sha512-g2tQ7LE7oOSqDfwEm3M+ZCMTJc7KiZCdJ4UwyZJb5ckTKyYu50OYmvv0mCFXPuYXoM4zkSt8zM9XQ9KCvxA74A==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT", + "dependencies": { + "@fastify/error": "^4.0.0", + "fastq": "^1.17.1" + } + }, + "node_modules/balanced-match": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", + "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "18 || 20 || >=22" + } + }, + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/bl": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz", + "integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==", + "dev": true, + "license": "MIT", + "dependencies": { + "buffer": "^5.5.0", + "inherits": "^2.0.4", + "readable-stream": "^3.4.0" + } + }, + "node_modules/body-parser": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.3.0.tgz", + "integrity": "sha512-2cGmJupaNgg+QUwVLAucDuWuoMZ6EX9iHDRswZ5lsNYEmwPaRknMPCLZz07yTzVq/83p4o/wzbDZbBrTvGGTIw==", + "license": "MIT", + "dependencies": { + "bytes": "^3.1.2", + "content-type": "^2.0.0", + "debug": "^4.4.3", + "http-errors": "^2.0.1", + "iconv-lite": "^0.7.2", + "on-finished": "^2.4.1", + "qs": "^6.15.2", + "raw-body": "^3.0.2", + "type-is": "^2.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/body-parser/node_modules/content-type": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz", + "integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/brace-expansion": { + "version": "5.0.12", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.12.tgz", + "integrity": "sha512-YovQ3rzhaLMIrDjNDMkNS01tea93qhEhG5xy8f6+R0l+dw3Ki+5sCoIoI942iuLZTHWogWktgwVDhU09iNEimQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^4.0.2" + }, + "engines": { + "node": "20 || >=22" + } + }, + "node_modules/buffer": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", + "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT", + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.1.13" + } + }, + "node_modules/buffer-from": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", + "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/busboy": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", + "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==", + "dependencies": { + "streamsearch": "^1.1.0" + }, + "engines": { + "node": ">=10.16.0" + } + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/chai": { + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/chai/-/chai-6.2.2.tgz", + "integrity": "sha512-NUPRluOfOiTKBKvWPtSD4PhFvWCqOi0BGStNWs57X9js7XGTprSmFoz5F0tWhR4WPjNeR9jXqdC7/UpSJTnlRg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/char-regex": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/char-regex/-/char-regex-1.0.2.tgz", + "integrity": "sha512-kWWXztvZ5SBQV+eRgKFeh8q5sLuZY2+8WUIzlxWVTg+oGwY14qylx1KbKzHd8P6ZYkAg0xyIDU9JMHhyJMZ1jw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10" + } + }, + "node_modules/chardet": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/chardet/-/chardet-2.2.0.tgz", + "integrity": "sha512-rddelWYNPRrXq6PtNEN2S3f6t9ILzvqaN5pVgi4kqt9jHQaXIial9PznB5iSPVlQSLNaaH22ItWz3EJtQ10+OA==", + "dev": true, + "license": "MIT" + }, + "node_modules/chokidar": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-5.0.0.tgz", + "integrity": "sha512-TQMmc3w+5AxjpL8iIiwebF73dRDF4fBIieAqGn9RGCWaEVwQ6Fb2cGe31Yns0RRIzii5goJ1Y7xbMwo1TxMplw==", + "dev": true, + "license": "MIT", + "dependencies": { + "readdirp": "^5.0.0" + }, + "engines": { + "node": ">= 20.19.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/class-transformer": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.5.1.tgz", + "integrity": "sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw==", + "license": "MIT" + }, + "node_modules/class-validator": { + "version": "0.15.1", + "resolved": "https://registry.npmjs.org/class-validator/-/class-validator-0.15.1.tgz", + "integrity": "sha512-LqoS80HBBSCVhz/3KloUly0ovokxpdOLR++Al3J3+dHXWt9sTKlKd4eYtoxhxyUjoe5+UcIM+5k9MIxyBWnRTw==", + "license": "MIT", + "dependencies": { + "@types/validator": "^13.15.3", + "libphonenumber-js": "^1.11.1", + "validator": "^13.15.22" + } + }, + "node_modules/cli-cursor": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", + "integrity": "sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==", + "dev": true, + "license": "MIT", + "dependencies": { + "restore-cursor": "^3.1.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/cli-progress": { + "version": "3.12.0", + "resolved": "https://registry.npmjs.org/cli-progress/-/cli-progress-3.12.0.tgz", + "integrity": "sha512-tRkV3HJ1ASwm19THiiLIXLO7Im7wlTuKnvkYaTkyoAPefqjNg7W7DHKUlGRxy9vxDvbyCYQkQozvptuMkGCg8A==", + "dev": true, + "license": "MIT", + "dependencies": { + "string-width": "^4.2.3" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/cli-spinners": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-3.4.0.tgz", + "integrity": "sha512-bXfOC4QcT1tKXGorxL3wbJm6XJPDqEnij2gQ2m7ESQuE+/z9YFIWnl/5RpTiKWbMq3EVKR4fRLJGn6DVfu0mpw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18.20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/cli-table3": { + "version": "0.6.5", + "resolved": "https://registry.npmjs.org/cli-table3/-/cli-table3-0.6.5.tgz", + "integrity": "sha512-+W/5efTR7y5HRD7gACw9yQjqMVvEMLBHmboM/kPWam+H+Hmyrgjh6YncVKK122YZkXrLudzTuAukUw9FnMf7IQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "string-width": "^4.2.0" + }, + "engines": { + "node": "10.* || >= 12.*" + }, + "optionalDependencies": { + "@colors/colors": "1.5.0" + } + }, + "node_modules/cli-width": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-4.1.0.tgz", + "integrity": "sha512-ouuZd4/dm2Sw5Gmqy6bGyNNNe1qt9RpmxveLSO7KcgsTnU7RXfsw+/bukWGo1abgBiMAic068rclZsO4IWmmxQ==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">= 12" + } + }, + "node_modules/clone": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz", + "integrity": "sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.8" + } + }, + "node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true, + "license": "MIT" + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, + "license": "MIT", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/commander": { + "version": "15.0.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-15.0.0.tgz", + "integrity": "sha512-z67u4ZhzCL/Tydu1lJARtEZYWbWaN7oYLHbsuzocr6y4N6WZAagG3RQ4FW61V1/0+jImpj293XfrcYnd1qxtPg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=22.12.0" + } + }, + "node_modules/comment-json": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/comment-json/-/comment-json-5.0.0.tgz", + "integrity": "sha512-uiqLcOiVDJtBP8WGkZHEP+FZIhTzP1dxvn59EfoYUi9gqupjrBWVQkO2atDrbnKPwLeotFYDsuNb26uBMqB+hw==", + "dev": true, + "license": "MIT", + "dependencies": { + "array-timsort": "^1.0.3", + "esprima": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/component-emitter": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.1.tgz", + "integrity": "sha512-T0+barUSQRTUQASh8bx02dl+DhF54GtIDY13Y3m9oWTklKbb3Wv974meRpeZ3lp1JpLVECWWNHC4vaG2XHXouQ==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/content-disposition": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-1.1.0.tgz", + "integrity": "sha512-5jRCH9Z/+DRP7rkvY83B+yGIGX96OYdJmzngqnw2SBSxqCFPd0w2km3s5iawpGX8krnwSGmF0FW5Nhr0Hfai3g==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/convert-source-map": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz", + "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==", + "dev": true, + "license": "MIT" + }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz", + "integrity": "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==", + "license": "MIT", + "engines": { + "node": ">=6.6.0" + } + }, + "node_modules/cookiejar": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.4.tgz", + "integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==", + "dev": true, + "license": "MIT" + }, + "node_modules/cors": { + "version": "2.8.6", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz", + "integrity": "sha512-tJtZBBHA6vjIAaF6EnIaq6laBBP9aq/Y3ouVJjEfoHbRBcHBAHYcMh/w8LDrk2PvIMMq8gmopa5D4V8RmbrxGw==", + "license": "MIT", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/cross-env": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-10.1.0.tgz", + "integrity": "sha512-GsYosgnACZTADcmEyJctkJIoqAhHjttw7RsFrVoJNXbsWWqaq6Ym+7kZjq6mS45O0jij6vtiReppKQEtqWy6Dw==", + "license": "MIT", + "dependencies": { + "@epic-web/invariant": "^1.0.0", + "cross-spawn": "^7.0.6" + }, + "bin": { + "cross-env": "dist/bin/cross-env.js", + "cross-env-shell": "dist/bin/cross-env-shell.js" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/cross-spawn": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "license": "MIT", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/date-fns": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-4.4.0.tgz", + "integrity": "sha512-+1UMbeh68lH1SegH83CGWwpb6OHHbpSgr3+s5Eww5M4CAgswBpoWS0AjTOfEJ33HiYKz1hdj/KTFprzXHmq/6w==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/kossnocorp" + } + }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/defaults": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/defaults/-/defaults-1.0.4.tgz", + "integrity": "sha512-eFuaLoy/Rxalv2kr+lqMlUnrDWV+3j4pljOIJgLIhI058IQfWJ7vXhyEIHu+HtC738klGALYxOKDO0bQP3tg8A==", + "dev": true, + "license": "MIT", + "dependencies": { + "clone": "^1.0.2" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/dequal": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", + "integrity": "sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/detect-libc": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", + "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=8" + } + }, + "node_modules/dezalgo": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.4.tgz", + "integrity": "sha512-rXSP0bf+5n0Qonsb+SVVfNfIsimO4HEtmnIpPHY8Q1UCzKlQrDMfdobr8nJOOsRgWCyMRqeSBQzmWUMq7zvVig==", + "dev": true, + "license": "ISC", + "dependencies": { + "asap": "^2.0.0", + "wrappy": "1" + } + }, + "node_modules/dotenv": { + "version": "18.0.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-18.0.5.tgz", + "integrity": "sha512-aBrGvt6KhjxbEnatqMWOMidftwsrCiCvqh1yNIGB9QyF0J+VcWkKDMsvYOEm7ZS82oiV+BT1sTOtIlAmUlTpwQ==", + "dev": true, + "license": "BSD-2-Clause", + "bin": { + "dotenv": "dist/index.cjs" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, + "node_modules/dotenv-expand": { + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-13.0.0.tgz", + "integrity": "sha512-aBfBS8eYIeXmpHI9ThIlA7/WLq+SLt18iXUZhb52rW89QLKQFoIpPG1bPeewoPZsTyjSSO3T7234FBVUM1V2rA==", + "license": "BSD-2-Clause", + "dependencies": { + "dotenv": "^17.4.2" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, + "node_modules/dotenv-expand/node_modules/dotenv": { + "version": "17.4.2", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.4.2.tgz", + "integrity": "sha512-nI4U3TottKAcAD9LLud4Cb7b2QztQMUEfHbvhTH09bqXTxnSie8WnjPALV/WMCrJZ6UV/qHJ6L03OqO3LcdYZw==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "license": "MIT" + }, + "node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true, + "license": "MIT" + }, + "node_modules/emojilib": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/emojilib/-/emojilib-2.4.0.tgz", + "integrity": "sha512-5U0rVMU5Y2n2+ykNLQqMoqklN9ICBT/KsvC1Gz6vqHbz2AXXGkG+Pm5rMWk/8Vjrr/mY9985Hi8DYzn1F09Nyw==", + "dev": true, + "license": "MIT" + }, + "node_modules/encodeurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-module-lexer": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-2.3.2.tgz", + "integrity": "sha512-poHGpORABojJJucnV9KbOavETW8lBVnphkW77ER5/BQ5Fz7oXSoCNek7IH3vR5nRjdsEz926ibFYX8KtLQmdyw==", + "dev": true, + "license": "MIT" + }, + "node_modules/es-object-atoms": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.2.tgz", + "integrity": "sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-set-tostringtag": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", + "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", + "dev": true, + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.6", + "has-tostringtag": "^1.0.2", + "hasown": "^2.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-toolkit": { + "version": "1.51.0", + "resolved": "https://registry.npmjs.org/es-toolkit/-/es-toolkit-1.51.0.tgz", + "integrity": "sha512-zC2lQGkM7QX+Gm6iM3+WIdZJzthsEd14LvRNJneSO2hzyz/zNBENR8+YXWo1cKxgPBtV6ksPYHELbcwBRzmdCw==", + "license": "MIT", + "workspaces": [ + "docs", + "benchmarks", + "tests/types", + "tests/browser-compat" + ] + }, + "node_modules/esbuild": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.2.tgz", + "integrity": "sha512-HKVLS8dvII+xoKW9kmqxbRKrnWEXfJJr/FZhhJmiqIB0e053QNYFqOBouTMO/k5sID4MvCiUCvv8b9M4h32wIA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.28.2", + "@esbuild/android-arm": "0.28.2", + "@esbuild/android-arm64": "0.28.2", + "@esbuild/android-x64": "0.28.2", + "@esbuild/darwin-arm64": "0.28.2", + "@esbuild/darwin-x64": "0.28.2", + "@esbuild/freebsd-arm64": "0.28.2", + "@esbuild/freebsd-x64": "0.28.2", + "@esbuild/linux-arm": "0.28.2", + "@esbuild/linux-arm64": "0.28.2", + "@esbuild/linux-ia32": "0.28.2", + "@esbuild/linux-loong64": "0.28.2", + "@esbuild/linux-mips64el": "0.28.2", + "@esbuild/linux-ppc64": "0.28.2", + "@esbuild/linux-riscv64": "0.28.2", + "@esbuild/linux-s390x": "0.28.2", + "@esbuild/linux-x64": "0.28.2", + "@esbuild/netbsd-arm64": "0.28.2", + "@esbuild/netbsd-x64": "0.28.2", + "@esbuild/openbsd-arm64": "0.28.2", + "@esbuild/openbsd-x64": "0.28.2", + "@esbuild/openharmony-arm64": "0.28.2", + "@esbuild/sunos-x64": "0.28.2", + "@esbuild/win32-arm64": "0.28.2", + "@esbuild/win32-ia32": "0.28.2", + "@esbuild/win32-x64": "0.28.2" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" + }, + "node_modules/escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.8.0" + } + }, + "node_modules/esprima": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", + "dev": true, + "license": "BSD-2-Clause", + "bin": { + "esparse": "bin/esparse.js", + "esvalidate": "bin/esvalidate.js" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/estree-walker": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", + "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.0" + } + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/expect-type": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.4.0.tgz", + "integrity": "sha512-KfYbmpRm0VbLjEvVa9yGwCi9GI34xvi7A/HXYWQO65CSD2u3MczUJSuwXKFIxlGsgBQizV9q5J9NHj4VG0n+pA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/express": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/express/-/express-5.2.1.tgz", + "integrity": "sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==", + "license": "MIT", + "dependencies": { + "accepts": "^2.0.0", + "body-parser": "^2.2.1", + "content-disposition": "^1.0.0", + "content-type": "^1.0.5", + "cookie": "^0.7.1", + "cookie-signature": "^1.2.1", + "debug": "^4.4.0", + "depd": "^2.0.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "finalhandler": "^2.1.0", + "fresh": "^2.0.0", + "http-errors": "^2.0.0", + "merge-descriptors": "^2.0.0", + "mime-types": "^3.0.0", + "on-finished": "^2.4.1", + "once": "^1.4.0", + "parseurl": "^1.3.3", + "proxy-addr": "^2.0.7", + "qs": "^6.14.0", + "range-parser": "^1.2.1", + "router": "^2.2.0", + "send": "^1.1.0", + "serve-static": "^2.2.0", + "statuses": "^2.0.1", + "type-is": "^2.0.1", + "vary": "^1.1.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/external-editor": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.1.0.tgz", + "integrity": "sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew==", + "dev": true, + "license": "MIT", + "dependencies": { + "chardet": "^0.7.0", + "iconv-lite": "^0.4.24", + "tmp": "^0.0.33" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/external-editor/node_modules/chardet": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz", + "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==", + "dev": true, + "license": "MIT" + }, + "node_modules/external-editor/node_modules/iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "dev": true, + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/fast-decode-uri-component": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/fast-decode-uri-component/-/fast-decode-uri-component-1.0.1.tgz", + "integrity": "sha512-WKgKWg5eUxvRZGwW8FvfbaH7AXSh2cL+3j5fMGzUMCxWBJ3dV3a7Wz8y2f/uQ0e3B6WmodD3oS54jTQ9HVTIIg==", + "license": "MIT" + }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "license": "MIT" + }, + "node_modules/fast-json-stringify": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fast-json-stringify/-/fast-json-stringify-7.0.1.tgz", + "integrity": "sha512-eRSayARSbbwlBjpP4vnTTIRD5QPcIrmihPxDeN1DtKnHPg66UuJLx+8hlK1kaFdjvzyQ/dzALoi4vwAQ+T+iZA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT", + "dependencies": { + "@fastify/merge-json-schemas": "^0.2.0", + "ajv": "^8.12.0", + "ajv-formats": "^3.0.1", + "fast-uri": "^4.0.0", + "json-schema-ref-resolver": "^3.0.0", + "rfdc": "^1.2.0" + } + }, + "node_modules/fast-json-stringify/node_modules/fast-uri": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-4.2.1.tgz", + "integrity": "sha512-TmHQgewjHtMq1E5QKA0tOE0yeYGQs25KZC/ziJpubRtWI15W92e6vPFydWOeZBVROSHBYw/QhD9d5OefdD6LDg==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "BSD-3-Clause" + }, + "node_modules/fast-querystring": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/fast-querystring/-/fast-querystring-1.1.2.tgz", + "integrity": "sha512-g6KuKWmFXc0fID8WWH0jit4g0AGBoJhCkJMb1RmbsSEUNvQ+ZC8D6CUZ+GtF8nMzSPXnhiePyyqqipzNNEnHjg==", + "license": "MIT", + "dependencies": { + "fast-decode-uri-component": "^1.0.1" + } + }, + "node_modules/fast-safe-stringify": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz", + "integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==", + "license": "MIT" + }, + "node_modules/fast-string-truncated-width": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/fast-string-truncated-width/-/fast-string-truncated-width-3.0.3.tgz", + "integrity": "sha512-0jjjIEL6+0jag3l2XWWizO64/aZVtpiGE3t0Zgqxv0DPuxiMjvB3M24fCyhZUO4KomJQPj3LTSUnDP3GpdwC0g==", + "dev": true, + "license": "MIT" + }, + "node_modules/fast-string-width": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/fast-string-width/-/fast-string-width-3.0.2.tgz", + "integrity": "sha512-gX8LrtNEI5hq8DVUfRQMbr5lpaS4nMIWV+7XEbXk2b8kiQIizgnlr12B4dA3ZEx3308ze0O4Q1R+cHts8kyUJg==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-string-truncated-width": "^3.0.2" + } + }, + "node_modules/fast-uri": { + "version": "3.1.8", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.8.tgz", + "integrity": "sha512-GZMtZUTNRpOVIECoXwLNZS5xUGE+mVNbTB8h/7Rwh2TFWcBQiPzTgyZi05BF9UMZKkLJv8XBRJTlU7zg8+ZfMg==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "BSD-3-Clause" + }, + "node_modules/fast-wrap-ansi": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/fast-wrap-ansi/-/fast-wrap-ansi-0.2.2.tgz", + "integrity": "sha512-7F2Fl+TjRSenLqlU3UjSH0iyqopqoZIu7eZVpEirP2g1GtWa2G/ecEmBdgz31+Mxr+ELclgg6sokpSFIQiZ02Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-string-width": "^3.0.2" + } + }, + "node_modules/fastify": { + "version": "5.12.5", + "resolved": "https://registry.npmjs.org/fastify/-/fastify-5.12.5.tgz", + "integrity": "sha512-OB2k1dlxs5/NAABqeKV2FUHkSD2BbENsCak8yULVcymn3fHIPDVa9TI3SDnJSWYSllZmSYuZXy2gTnsT+Sut1A==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT", + "dependencies": { + "@fastify/ajv-compiler": "^4.0.5", + "@fastify/error": "^4.0.0", + "@fastify/fast-json-stringify-compiler": "^5.0.0", + "@fastify/proxy-addr": "^5.0.0", + "abstract-logging": "^2.0.1", + "avvio": "^9.0.0", + "fast-json-stringify": "^7.0.0", + "find-my-way": "^9.6.0", + "light-my-request": "^6.0.0", + "pino": "^9.14.0 || ^10.1.0", + "process-warning": "^5.1.0", + "rfdc": "^1.3.1", + "secure-json-parse": "^4.0.0", + "semver": "^7.6.0", + "toad-cache": "^3.7.0" + } + }, + "node_modules/fastify-plugin": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/fastify-plugin/-/fastify-plugin-6.0.0.tgz", + "integrity": "sha512-fZOty7z3O7vOliF6d8bHE3wiEh1KcNnKEQensSgTk9C1DvN6nRLS++XVd86v33Hw/8u9Un8A1zDrQ8ujcQDHEg==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT" + }, + "node_modules/fastq": { + "version": "1.20.3", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.20.3.tgz", + "integrity": "sha512-XKv5nnLs6nLF71NgiKJLIZFLkPyIEuOselLG7ujZnGrRfQK8HpvY+WqKhAJUAdLomwVHErVS4LfxFlPq0/FTAw==", + "license": "ISC", + "dependencies": { + "reusify": "^1.0.4" + } + }, + "node_modules/fdir": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", + "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, + "node_modules/figures": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", + "integrity": "sha512-yaduQFRKLXYOGgEn6AZau90j3ggSOyiqXU0F9JZfeXYhNa+Jk4X+s45A2zg5jns87GAFa34BBm2kXw4XpNcbdg==", + "dev": true, + "license": "MIT", + "dependencies": { + "escape-string-regexp": "^1.0.5" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/file-type": { + "version": "22.1.0", + "resolved": "https://registry.npmjs.org/file-type/-/file-type-22.1.0.tgz", + "integrity": "sha512-fbvf9u6jnHWr1EP6V8R99E9iLMhNLXgZkUzWBiPpJ5/89UJ/Atuxjn5YXR+XaZWo2hc2/8mGfTez+NDAgOcpLA==", + "license": "MIT", + "dependencies": { + "@tokenizer/inflate": "^0.4.1", + "strtok3": "^10.3.5", + "token-types": "^6.1.2", + "uint8array-extras": "^1.5.0" + }, + "engines": { + "node": ">=22" + }, + "funding": { + "url": "https://github.com/sindresorhus/file-type?sponsor=1" + } + }, + "node_modules/finalhandler": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.1.tgz", + "integrity": "sha512-S8KoZgRZN+a5rNwqTxlZZePjT/4cnm0ROV70LedRHZ0p8u9fRID0hJUZQpkKLzro8LfmC8sx23bY6tVNxv8pQA==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "on-finished": "^2.4.1", + "parseurl": "^1.3.3", + "statuses": "^2.0.1" + }, + "engines": { + "node": ">= 18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/find-my-way": { + "version": "9.9.0", + "resolved": "https://registry.npmjs.org/find-my-way/-/find-my-way-9.9.0.tgz", + "integrity": "sha512-sJsgZ1sQH2UDuowPuMKg8az7Qc8F0jnj+SKkFWU/+T0xcFlgV5skgXOGUqmQzOdmW6ALA7AhJINWx3qFBkbLHA==", + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-querystring": "^1.0.0", + "safe-regex2": "^5.0.0" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/form-data": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.6.tgz", + "integrity": "sha512-vKatAh4SlVfgbv+YtmhiRjhEMJsYpsG1Y2rMQtR+SVSbytsSD1YGzDIcrAJmdFec88u/+VoGmxnl+80gL1tRCQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "es-set-tostringtag": "^2.1.0", + "hasown": "^2.0.4", + "mime-types": "^2.1.35" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/form-data/node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/form-data/node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dev": true, + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/formidable": { + "version": "3.5.4", + "resolved": "https://registry.npmjs.org/formidable/-/formidable-3.5.4.tgz", + "integrity": "sha512-YikH+7CUTOtP44ZTnUhR7Ic2UASBPOqmaRkRKxRbywPTe5VxF7RRCck4af9wutiZ/QKM5nME9Bie2fFaPz5Gug==", + "dev": true, + "license": "MIT", + "dependencies": { + "@paralleldrive/cuid2": "^2.2.2", + "dezalgo": "^1.0.4", + "once": "^1.4.0" + }, + "engines": { + "node": ">=14.0.0" + }, + "funding": { + "url": "https://ko-fi.com/tunnckoCore/commissions" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz", + "integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-east-asian-width": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/get-east-asian-width/-/get-east-asian-width-1.7.0.tgz", + "integrity": "sha512-XjH1AECxf0giL2V1aU8vKyRR2ppRUb5c0EvT7zuJTokQ74bNo52zOtghqdWIqrhUD79fo3x0WfKZdOqxF6LG1Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/globrex": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/globrex/-/globrex-0.1.2.tgz", + "integrity": "sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==", + "dev": true, + "license": "MIT" + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-tostringtag": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", + "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", + "dev": true, + "license": "MIT", + "dependencies": { + "has-symbols": "^1.0.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz", + "integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/html-escaper": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", + "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", + "dev": true, + "license": "MIT" + }, + "node_modules/http-errors": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", + "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", + "license": "MIT", + "dependencies": { + "depd": "~2.0.0", + "inherits": "~2.0.4", + "setprototypeof": "~1.2.0", + "statuses": "~2.0.2", + "toidentifier": "~1.0.1" + }, + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/iconv-lite": { + "version": "0.7.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.3.tgz", + "integrity": "sha512-IKXpvIzjnC9XTAUbVBcMfGS0EPaIXtW6v+zr+RRp+hqULEpo0owZax6wyRwPOJbWbzjYspQwusTsfVr0ifh4uQ==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "BSD-3-Clause" + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" + }, + "node_modules/inquirer": { + "version": "8.2.6", + "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-8.2.6.tgz", + "integrity": "sha512-M1WuAmb7pn9zdFRtQYk26ZBoY043Sse0wVDdk4Bppr+JOXyQYybdtvK+l9wUibhtjdjvtoiNy8tk+EgsYIUqKg==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-escapes": "^4.2.1", + "chalk": "^4.1.1", + "cli-cursor": "^3.1.0", + "cli-width": "^3.0.0", + "external-editor": "^3.0.3", + "figures": "^3.0.0", + "lodash": "^4.17.21", + "mute-stream": "0.0.8", + "ora": "^5.4.1", + "run-async": "^2.4.0", + "rxjs": "^7.5.5", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0", + "through": "^2.3.6", + "wrap-ansi": "^6.0.1" + }, + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/inquirer/node_modules/cli-spinners": { + "version": "2.9.2", + "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.2.tgz", + "integrity": "sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/inquirer/node_modules/cli-width": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-3.0.0.tgz", + "integrity": "sha512-FxqpkPPwu1HjuN93Omfm4h8uIanXofW0RxVEW3k5RKx+mJJYSthzNhp32Kzxxy3YAEZ/Dc/EWN1vZRY0+kOhbw==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">= 10" + } + }, + "node_modules/inquirer/node_modules/is-interactive": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-interactive/-/is-interactive-1.0.0.tgz", + "integrity": "sha512-2HvIEKRoqS62guEC+qBjpvRubdX910WCMuJTZ+I9yvqKU2/12eSL549HMwtabb4oupdj2sMP50k+XJfB/8JE6w==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/inquirer/node_modules/is-unicode-supported": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz", + "integrity": "sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/inquirer/node_modules/log-symbols": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", + "integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==", + "dev": true, + "license": "MIT", + "dependencies": { + "chalk": "^4.1.0", + "is-unicode-supported": "^0.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/inquirer/node_modules/mute-stream": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz", + "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==", + "dev": true, + "license": "ISC" + }, + "node_modules/inquirer/node_modules/ora": { + "version": "5.4.1", + "resolved": "https://registry.npmjs.org/ora/-/ora-5.4.1.tgz", + "integrity": "sha512-5b6Y85tPxZZ7QytO+BQzysW31HJku27cRIlkbAXaNx+BdcVi+LlRFmVXzeF6a7JCwJpyw5c4b+YSVImQIrBpuQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "bl": "^4.1.0", + "chalk": "^4.1.0", + "cli-cursor": "^3.1.0", + "cli-spinners": "^2.5.0", + "is-interactive": "^1.0.0", + "is-unicode-supported": "^0.1.0", + "log-symbols": "^4.1.0", + "strip-ansi": "^6.0.0", + "wcwidth": "^1.0.1" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/is-interactive": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-interactive/-/is-interactive-2.0.0.tgz", + "integrity": "sha512-qP1vozQRI+BMOPcjFzrjXuQvdak2pHNUMZoeG2eRbiSqyvbEf/wQtEOTOX1guk6E3t36RkaqiSt8A/6YElNxLQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/is-promise": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz", + "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", + "license": "MIT" + }, + "node_modules/is-unicode-supported": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-2.1.0.tgz", + "integrity": "sha512-mE00Gnza5EEB3Ds0HfMyllZzbBrmLOX3vfWoj9A9PEnTfratQ/BcaJOuMhnkhjXvb2+FkY3VuHqtAGpTPmglFQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "license": "ISC" + }, + "node_modules/istanbul-lib-coverage": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.2.tgz", + "integrity": "sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=8" + } + }, + "node_modules/istanbul-lib-report": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/istanbul-lib-report/-/istanbul-lib-report-3.0.1.tgz", + "integrity": "sha512-GCfE1mtsHGOELCU8e/Z7YWzpmybrx/+dSTfLrvY8qRmaY6zXTKWn6WQIjaAFw069icm6GVMNkgu0NzI4iPZUNw==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "istanbul-lib-coverage": "^3.0.0", + "make-dir": "^4.0.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/istanbul-reports": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-3.2.0.tgz", + "integrity": "sha512-HGYWWS/ehqTV3xN10i23tkPkpH46MLCIMFNCaaKNavAXTF1RkqxawEPtnjnGZ6XKSInBKkiOA5BKS+aZiY3AvA==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "html-escaper": "^2.0.0", + "istanbul-lib-report": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/iterare": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/iterare/-/iterare-1.2.1.tgz", + "integrity": "sha512-RKYVTCjAnRthyJes037NX/IiqeidgN1xc3j1RjFfECFp28A1GVwK9nA+i0rJPaHqSZwygLzRnFlzUuHFoWWy+Q==", + "license": "ISC", + "engines": { + "node": ">=6" + } + }, + "node_modules/js-tokens": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-10.0.0.tgz", + "integrity": "sha512-lM/UBzQmfJRo9ABXbPWemivdCW8V2G8FHaHdypQaIy523snUjog0W71ayWXTjiR+ixeMyVHN2XcpnTd/liPg/Q==", + "dev": true, + "license": "MIT" + }, + "node_modules/json-schema-ref-resolver": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/json-schema-ref-resolver/-/json-schema-ref-resolver-3.0.0.tgz", + "integrity": "sha512-hOrZIVL5jyYFjzk7+y7n5JDzGlU8rfWDuYyHwGa2WA8/pcmMHezp2xsVwxrebD/Q9t8Nc5DboieySDpCp4WG4A==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT", + "dependencies": { + "dequal": "^2.0.3" + } + }, + "node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "license": "MIT" + }, + "node_modules/json5": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "dev": true, + "license": "MIT", + "bin": { + "json5": "lib/cli.js" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/jsonc-parser": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.3.1.tgz", + "integrity": "sha512-HUgH65KyejrUFPvHFPbqOY0rsFip3Bo5wb4ngvdi1EpCYWUQDC5V+Y7mZws+DLkr4M//zQJoanu1SP+87Dv1oQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/libphonenumber-js": { + "version": "1.13.13", + "resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.13.13.tgz", + "integrity": "sha512-hV6SmWnyQ8U1QXhhqbqYBHIStNnscG7A5XbGodgdHhf/8N5PwhYpJA5U/yHDjYwPYTd8uNGXqq416XctuvK2PA==", + "license": "MIT" + }, + "node_modules/light-my-request": { + "version": "6.6.0", + "resolved": "https://registry.npmjs.org/light-my-request/-/light-my-request-6.6.0.tgz", + "integrity": "sha512-CHYbu8RtboSIoVsHZ6Ye4cj4Aw/yg2oAFimlF7mNvfDV192LR7nDiKtSIfCuLT7KokPSTn/9kfVLm5OGN0A28A==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "BSD-3-Clause", + "dependencies": { + "cookie": "^1.0.1", + "process-warning": "^4.0.0", + "set-cookie-parser": "^2.6.0" + } + }, + "node_modules/light-my-request/node_modules/cookie": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-1.1.1.tgz", + "integrity": "sha512-ei8Aos7ja0weRpFzJnEA9UHJ/7XQmqglbRwnf2ATjcB9Wq874VKH9kfjjirM6UhU2/E5fFYadylyhFldcqSidQ==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/light-my-request/node_modules/process-warning": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/process-warning/-/process-warning-4.0.1.tgz", + "integrity": "sha512-3c2LzQ3rY9d0hc1emcsHhfT9Jwz0cChib/QN89oME2R451w5fy3f0afAhERFZAwrbDU43wk12d0ORBpDVME50Q==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT" + }, + "node_modules/lightningcss": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.33.0.tgz", + "integrity": "sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA==", + "dev": true, + "license": "MPL-2.0", + "dependencies": { + "detect-libc": "^2.0.3" + }, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + }, + "optionalDependencies": { + "lightningcss-android-arm64": "1.33.0", + "lightningcss-darwin-arm64": "1.33.0", + "lightningcss-darwin-x64": "1.33.0", + "lightningcss-freebsd-x64": "1.33.0", + "lightningcss-linux-arm-gnueabihf": "1.33.0", + "lightningcss-linux-arm64-gnu": "1.33.0", + "lightningcss-linux-arm64-musl": "1.33.0", + "lightningcss-linux-x64-gnu": "1.33.0", + "lightningcss-linux-x64-musl": "1.33.0", + "lightningcss-win32-arm64-msvc": "1.33.0", + "lightningcss-win32-x64-msvc": "1.33.0" + } + }, + "node_modules/lightningcss-android-arm64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-android-arm64/-/lightningcss-android-arm64-1.33.0.tgz", + "integrity": "sha512-gEpRTalKdosp4Bb8qWtc2iOgE5SeIHlpS1up9bFq2wAyYhl1UdTObYiHe98zEM9SQvSoqQZ1IQD0JNpg3Ml5pg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-darwin-arm64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.33.0.tgz", + "integrity": "sha512-Sciaz8eenNTKn9b3t7+xr0ipTp9YxKQY4npwQ3mrRuL0BAVHBLyZxofhaKBAVtzmtRZ/zTyo0/to4B1uWG/Djg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-darwin-x64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.33.0.tgz", + "integrity": "sha512-Z5UPAxzrjlWNNyGy6i65cJzzvgJ5D3T6wMvs+gWpY9d7qRhANrxqAp6LhxIgZhWEw18RfJTGcRxjuLIBr+m8XQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-freebsd-x64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.33.0.tgz", + "integrity": "sha512-QQM/Ti/hQajJwCY+RiWuCZ9sdtI/XQk7nDK5vC8kkdwixezOlDgvDx7+RT+QjK6FcFT4MpsuoBnHIo/O3StRRg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm-gnueabihf": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.33.0.tgz", + "integrity": "sha512-N7FVBe6iS24MlM6R/4RBTxGhQheZGs7tiQ9U32UtF75NzP5Q7xWPRqLBCKxlRQRk3rY1jCIPLzx7WzOhuUIRLQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm64-gnu": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.33.0.tgz", + "integrity": "sha512-j2v/itmy4HlNxlc6voKXYgBqNi0Ng2LShg4z7GufpEgs05P+2suBVyi9I6YHq5uoVFx9ETin3eCEhLVyXGQnKg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm64-musl": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.33.0.tgz", + "integrity": "sha512-yiO5ROMuYQgXbC60yjZU5CYSFZGKXL0HFATXt9mHJn1+zW55oCtMI9NfcVhYLMFDL7gV7oBPon/EmMMGg2OvtQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-x64-gnu": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.33.0.tgz", + "integrity": "sha512-ar+Ju7LmcN0Jo4FpL4hpFybwNG9/3A/Br5KW2n2jyODg3MEZXaDYADdemoNS+BDNfMgKvylJLj4S5tyRActuAg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-x64-musl": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.33.0.tgz", + "integrity": "sha512-RYiYbkokw0trfKqqzfF55lginwEPrD3OJDfTuJzFs1MK6iFnDenaz1fqLLtX4ITG3OktJQXOeTaw1awrBAlZPw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-win32-arm64-msvc": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.33.0.tgz", + "integrity": "sha512-1K+MPfLSFVpphzpdbfkhlWk6wBrTObBzS2T6db10PNOZgR9GoVsAWzwNyuhUYYbTp23j+4RrncfujZ4uAzXvwA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-win32-x64-msvc": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.33.0.tgz", + "integrity": "sha512-OlEICDx/Xl0FqSp4bry8zFnCvGpig3Gl4gCquvYwHuqJKEC1+n9NgDniFvqHGmMv1ZkqDJrDqKKSykTDX+ehuA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/load-esm": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/load-esm/-/load-esm-1.0.3.tgz", + "integrity": "sha512-v5xlu8eHD1+6r8EHTg6hfmO97LN8ugKtiXcy5e6oN72iD2r6u0RPfLl6fxM+7Wnh2ZRq15o0russMst44WauPA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/Borewit" + }, + { + "type": "buymeacoffee", + "url": "https://buymeacoffee.com/borewit" + } + ], + "license": "MIT", + "engines": { + "node": ">=13.2.0" + } + }, + "node_modules/lodash": { + "version": "4.18.1", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.18.1.tgz", + "integrity": "sha512-dMInicTPVE8d1e5otfwmmjlxkZoUpiVLwyeTdUsi/Caj/gfzzblBcCE5sRHV/AsjuCmxWrte2TNGSYuCeCq+0Q==", + "dev": true, + "license": "MIT" + }, + "node_modules/log-symbols": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-7.0.1.tgz", + "integrity": "sha512-ja1E3yCr9i/0hmBVaM0bfwDjnGy8I/s6PP4DFp+yP+a+mrHO4Rm7DtmnqROTUkHIkqffC84YY7AeqX6oFk0WFg==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-unicode-supported": "^2.0.0", + "yoctocolors": "^2.1.1" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/magic-string": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-1.0.0.tgz", + "integrity": "sha512-CGvjzMN08iv6w1mm4/x3Gh1hLb4VnyRUA15FFpl6CsCIGGoe36k7kY5KNz9QDbSBN5I/fWHM6ZlIkUTa5xdUEA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.5.5" + } + }, + "node_modules/magicast": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/magicast/-/magicast-0.5.5.tgz", + "integrity": "sha512-UicdXN8zQ3JHlxVq+28afMXPr1z7WNY6+7EJnzTdQWkTAlMLF5fNCCKxJHBQwGaNGR11581EiQmQzx73+MvszA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/parser": "^7.29.7", + "@babel/types": "^7.29.7", + "source-map-js": "^1.2.1" + } + }, + "node_modules/make-dir": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-4.0.0.tgz", + "integrity": "sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw==", + "dev": true, + "license": "MIT", + "dependencies": { + "semver": "^7.5.3" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/media-typer": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.1.tgz", + "integrity": "sha512-yz3xRaG20c6/BOzvYoDaGtPmGscs7YivItZEEqe6GbwNfHuxu9YNmvnEkMzKldAGY4/80pRcQRZSEnhquk9XuQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/merge-descriptors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz", + "integrity": "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz", + "integrity": "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==", + "dev": true, + "license": "MIT", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/mime-db": { + "version": "1.54.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz", + "integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz", + "integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==", + "license": "MIT", + "dependencies": { + "mime-db": "^1.54.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/mimic-fn": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", + "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/mimic-function": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/mimic-function/-/mimic-function-5.0.1.tgz", + "integrity": "sha512-VP79XUPxV2CigYP3jWwAUFSku2aKqBH7uTAapFWCBqutsbmDo96KY5o8uh6U+/YSIn5OxJnXp73beVkpqMIGhA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/minimatch": { + "version": "10.2.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.6.tgz", + "integrity": "sha512-vpLQEs+VLCr1nU0BXS07maYoFwlDAH0gngQuuttxIwutDFEMHq2blX+8vpgxDdK3J1PwjCJiep77OitTZ4Ll1A==", + "dev": true, + "license": "BlueOak-1.0.0", + "dependencies": { + "brace-expansion": "^5.0.8" + }, + "engines": { + "node": "18 || 20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/multer": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/multer/-/multer-2.4.0.tgz", + "integrity": "sha512-7dqa0ZcFfzbefdTuIkzOSMvZWC0J7FLqBOjJUZvDCXShIURWKxAyTT1wHhnE5q19c7jOJf43IYYKjBmZVZmvhg==", + "license": "MIT", + "dependencies": { + "append-field": "^1.0.0", + "busboy": "^1.6.0", + "type-is": "^1.6.18" + }, + "engines": { + "node": ">= 10.16.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/multer/node_modules/media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/multer/node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/multer/node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/multer/node_modules/type-is": { + "version": "1.6.18", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", + "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "license": "MIT", + "dependencies": { + "media-typer": "0.3.0", + "mime-types": "~2.1.24" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mute-stream": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-3.0.0.tgz", + "integrity": "sha512-dkEJPVvun4FryqBmZ5KhDo0K9iDXAwn08tMLDinNdRBNPcYEDiWYysLcc6k3mjTMlbP9KyylvRpd4wFtwrT9rw==", + "dev": true, + "license": "ISC", + "engines": { + "node": "^20.17.0 || >=22.9.0" + } + }, + "node_modules/nanoid": { + "version": "3.3.19", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.19.tgz", + "integrity": "sha512-Y2tUNy4ouw6tq5oDSKeQYGOyhkUBhNOcGV/02KC+6kd9eDGqdZd++mjMiIDilrBYvjEnCYvVtsuHCuP+okSfug==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, + "node_modules/negotiator": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.1.0.tgz", + "integrity": "sha512-NMPBRMJgiQHjbd8phG3Vebdx4kZ1H121rbl5IkMqeOsahptB9BKo/d7oJ3zTXqTgagn2bWlNSXkh0QUGM31RYg==", + "license": "MIT", + "dependencies": { + "content-type": "^2.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/negotiator/node_modules/content-type": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz", + "integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/nestjs-spelunker": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/nestjs-spelunker/-/nestjs-spelunker-1.3.2.tgz", + "integrity": "sha512-tVQZvPvlYNRW9PFkl2dj/hCEzUjC/NbJdayhnr/0dBuebFu4fqJNICPQF1BWJgK8GxJARe1kvDAw/GoyvINvOA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@ogma/styler": "^1.0.0" + }, + "peerDependencies": { + "@nestjs/common": ">6.11.0", + "@nestjs/core": ">6.11.0" + } + }, + "node_modules/node-addon-api": { + "version": "8.9.2", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-8.9.2.tgz", + "integrity": "sha512-VijLXbi3UACN69I0JVXJsX4tjACjNoQDgv2gTF6sx2wWEi8tkSg2eX8p5gSIFi8z2+DL3oHmY6OyKce38SDolg==", + "license": "MIT", + "engines": { + "node": "^18 || ^20 || >= 21" + } + }, + "node_modules/node-emoji": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/node-emoji/-/node-emoji-2.2.0.tgz", + "integrity": "sha512-Z3lTE9pLaJF47NyMhd4ww1yFTAP8YhYI8SleJiHzM46Fgpm5cnNzSl9XfzFNqbaz+VlJrIj3fXQ4DeN1Rjm6cw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@sindresorhus/is": "^4.6.0", + "char-regex": "^1.0.2", + "emojilib": "^2.4.0", + "skin-tone": "^2.0.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/node-gyp-build": { + "version": "4.8.4", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.4.tgz", + "integrity": "sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==", + "license": "MIT", + "bin": { + "node-gyp-build": "bin.js", + "node-gyp-build-optional": "optional.js", + "node-gyp-build-test": "build-test.js" + } + }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/object-inspect": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/obug": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/obug/-/obug-2.2.1.tgz", + "integrity": "sha512-XrsrhT5sybtKI6wakr2SPOlGZWWYbUXZ7a0jT8/QOeAPau+1X/bSegNe5YR75oJmEZQbKningirmGOEJCIk61Q==", + "dev": true, + "funding": [ + "https://github.com/sponsors/sxzz", + "https://opencollective.com/debug" + ], + "license": "MIT", + "engines": { + "node": ">=12.20.0" + } + }, + "node_modules/on-exit-leak-free": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/on-exit-leak-free/-/on-exit-leak-free-2.1.2.tgz", + "integrity": "sha512-0eJJY6hXLGf1udHwfNftBqH+g73EU4B504nZeKpz1sYRKafAghwxEJunB2O7rDZkL4PGfsMVnTXZ2EjibbqcsA==", + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/onetime": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", + "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==", + "dev": true, + "license": "MIT", + "dependencies": { + "mimic-fn": "^2.1.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/ora": { + "version": "9.4.1", + "resolved": "https://registry.npmjs.org/ora/-/ora-9.4.1.tgz", + "integrity": "sha512-6VlU9MLXbjVQD04AZCMX28hVtA5bUoadvUqO76MUCVA0ilwJbMiHsITRPfyVm6p/BC0Av/BXMujx39WCe1LEqw==", + "dev": true, + "license": "MIT", + "dependencies": { + "chalk": "^5.6.2", + "cli-cursor": "^5.0.0", + "cli-spinners": "^3.2.0", + "is-interactive": "^2.0.0", + "is-unicode-supported": "^2.1.0", + "log-symbols": "^7.0.1", + "stdin-discarder": "^0.3.2", + "string-width": "^8.1.0" + }, + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/ora/node_modules/ansi-regex": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.3.0.tgz", + "integrity": "sha512-WpDfL7NO6j7tH88IDBNVdUJxDh9nmCteAVW9dsep846XdwF4naCBK+/tGLX3KJgcpgMRXCFlTM2hKGoK9FsdrQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" + } + }, + "node_modules/ora/node_modules/chalk": { + "version": "5.6.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.6.2.tgz", + "integrity": "sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.17.0 || ^14.13 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/ora/node_modules/cli-cursor": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-5.0.0.tgz", + "integrity": "sha512-aCj4O5wKyszjMmDT4tZj93kxyydN/K5zPWSCe6/0AV/AA1pqe5ZBIw0a2ZfPQV7lL5/yb5HsUreJ6UFAF1tEQw==", + "dev": true, + "license": "MIT", + "dependencies": { + "restore-cursor": "^5.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/ora/node_modules/onetime": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-7.0.0.tgz", + "integrity": "sha512-VXJjc87FScF88uafS3JllDgvAm+c/Slfz06lorj2uAY34rlUu0Nt+v8wreiImcrgAjjIHp1rXpTDlLOGw29WwQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "mimic-function": "^5.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/ora/node_modules/restore-cursor": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-5.1.0.tgz", + "integrity": "sha512-oMA2dcrw6u0YfxJQXm342bFKX/E4sG9rbTzO9ptUcR/e8A33cHuvStiYOwH7fszkZlZ1z/ta9AAoPk2F4qIOHA==", + "dev": true, + "license": "MIT", + "dependencies": { + "onetime": "^7.0.0", + "signal-exit": "^4.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/ora/node_modules/string-width": { + "version": "8.2.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-8.2.2.tgz", + "integrity": "sha512-GaPUh5gfdrYzqeVNZvUfT23vYYxXzKYidUcnMtJg/3rxRV63EFZy3k6xfKlmfeJD0176lnUV/Usr3XcwSvFzpg==", + "dev": true, + "license": "MIT", + "dependencies": { + "get-east-asian-width": "^1.5.0", + "strip-ansi": "^7.1.2" + }, + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/ora/node_modules/strip-ansi": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.2.0.tgz", + "integrity": "sha512-yDPMNjp4WyfYBkHnjIRLfca1i6KMyGCtsVgoKe/z1+6vukgaENdgGBZt+ZmKPc4gavvEZ5OgHfHdrazhgNyG7w==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-regex": "^6.2.2" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" + } + }, + "node_modules/os-tmpdir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "integrity": "sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/oxlint": { + "version": "1.83.0", + "resolved": "https://registry.npmjs.org/oxlint/-/oxlint-1.83.0.tgz", + "integrity": "sha512-cyDzSzaw3uzP0TeCeq3lLRPPoaUxkbB4ZOXj+kn+5r+BX9V+4bNVGk9lxer+WrgcpebH4JxLlJ3KQjveVztOLQ==", + "dev": true, + "license": "MIT", + "bin": { + "oxlint": "bin/oxlint" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "funding": { + "url": "https://github.com/sponsors/oxc-project" + }, + "optionalDependencies": { + "@oxlint/binding-android-arm-eabi": "1.83.0", + "@oxlint/binding-android-arm64": "1.83.0", + "@oxlint/binding-darwin-arm64": "1.83.0", + "@oxlint/binding-darwin-x64": "1.83.0", + "@oxlint/binding-freebsd-x64": "1.83.0", + "@oxlint/binding-linux-arm-gnueabihf": "1.83.0", + "@oxlint/binding-linux-arm-musleabihf": "1.83.0", + "@oxlint/binding-linux-arm64-gnu": "1.83.0", + "@oxlint/binding-linux-arm64-musl": "1.83.0", + "@oxlint/binding-linux-ppc64-gnu": "1.83.0", + "@oxlint/binding-linux-riscv64-gnu": "1.83.0", + "@oxlint/binding-linux-riscv64-musl": "1.83.0", + "@oxlint/binding-linux-s390x-gnu": "1.83.0", + "@oxlint/binding-linux-x64-gnu": "1.83.0", + "@oxlint/binding-linux-x64-musl": "1.83.0", + "@oxlint/binding-openharmony-arm64": "1.83.0", + "@oxlint/binding-win32-arm64-msvc": "1.83.0", + "@oxlint/binding-win32-ia32-msvc": "1.83.0", + "@oxlint/binding-win32-x64-msvc": "1.83.0" + }, + "peerDependencies": { + "oxlint-tsgolint": ">=7.0.2001", + "vite-plus": "*" + }, + "peerDependenciesMeta": { + "oxlint-tsgolint": { + "optional": true + }, + "vite-plus": { + "optional": true + } + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/path-to-regexp": { + "version": "8.4.2", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.4.2.tgz", + "integrity": "sha512-qRcuIdP69NPm4qbACK+aDogI5CBDMi1jKe0ry5rSQJz8JVLsC7jV8XpiJjGRLLol3N+R5ihGYcrPLTno6pAdBA==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/pathe": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz", + "integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==", + "dev": true, + "license": "MIT" + }, + "node_modules/pg": { + "version": "8.23.1", + "resolved": "https://registry.npmjs.org/pg/-/pg-8.23.1.tgz", + "integrity": "sha512-aL96AHANtWjPLDOLqnhx+ngp9+UK7ETEU8VJrDCGvsSSi/mGLcWYsS6Herg7lmaBJe4uwrfqsa7gTEFaSizDoQ==", + "license": "MIT", + "dependencies": { + "pg-connection-string": "^2.14.1", + "pg-pool": "^3.14.0", + "pg-protocol": "^1.16.1", + "pg-types": "2.2.0", + "pgpass": "1.0.5" + }, + "engines": { + "node": ">= 16.0.0" + }, + "optionalDependencies": { + "pg-cloudflare": "^1.4.1" + }, + "peerDependencies": { + "pg-native": ">=3.0.1" + }, + "peerDependenciesMeta": { + "pg-native": { + "optional": true + } + } + }, + "node_modules/pg-cloudflare": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/pg-cloudflare/-/pg-cloudflare-1.4.1.tgz", + "integrity": "sha512-6PQbsFWZcp9EmJEwy5cGQ2La+AMWpP46lgbb8X+U/XsHIUweYDNCpeuKck5RxL2MdVFi7krbbEi5nX4Zh7JhrQ==", + "license": "MIT", + "optional": true + }, + "node_modules/pg-connection-string": { + "version": "2.14.1", + "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.14.1.tgz", + "integrity": "sha512-qR3kGNPBLpCNtz0evbKA0Y/MRFXwSSdT+pTJvYp/bXTcReZbvX1kzF0IyTc1QnxqF7AZbOeBhNL8R5mYQZV/MA==", + "license": "MIT" + }, + "node_modules/pg-int8": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz", + "integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==", + "license": "ISC", + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/pg-pool": { + "version": "3.14.0", + "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.14.0.tgz", + "integrity": "sha512-gKtPkFdQPU3DksooVLi9LsjZxrsBUZIpa+7aVx+LV5pNh0KzP4Zleud2po+ConrxbuXGBJ6Hfer6hdgpIBpBaw==", + "license": "MIT", + "peerDependencies": { + "pg": ">=8.0" + } + }, + "node_modules/pg-protocol": { + "version": "1.16.1", + "resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.16.1.tgz", + "integrity": "sha512-p9VOFMiHB/ZbJATetbg+99PxssTVSQRnyuPSQ67mN1+1KBOjZaZ83ZQzltnxPhJwSsC3nwVjJ10DVJlerbFzLg==", + "license": "MIT" + }, + "node_modules/pg-types": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz", + "integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==", + "license": "MIT", + "dependencies": { + "pg-int8": "1.0.1", + "postgres-array": "~2.0.0", + "postgres-bytea": "~1.0.0", + "postgres-date": "~1.0.4", + "postgres-interval": "^1.1.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/pgpass": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz", + "integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==", + "license": "MIT", + "dependencies": { + "split2": "^4.1.0" + } + }, + "node_modules/picocolors": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", + "dev": true, + "license": "ISC" + }, + "node_modules/picomatch": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.5.tgz", + "integrity": "sha512-RvwwcruNjI1ncT5xRakeyS9Lf8lcItv34KD+aif+VH9kduAyfYBipGh12274xtenIPZ119/R9BdTBa8gAwSh0A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/pino": { + "version": "10.3.1", + "resolved": "https://registry.npmjs.org/pino/-/pino-10.3.1.tgz", + "integrity": "sha512-r34yH/GlQpKZbU1BvFFqOjhISRo1MNx1tWYsYvmj6KIRHSPMT2+yHOEb1SG6NMvRoHRF0a07kCOox/9yakl1vg==", + "license": "MIT", + "dependencies": { + "@pinojs/redact": "^0.4.0", + "atomic-sleep": "^1.0.0", + "on-exit-leak-free": "^2.1.0", + "pino-abstract-transport": "^3.0.0", + "pino-std-serializers": "^7.0.0", + "process-warning": "^5.0.0", + "quick-format-unescaped": "^4.0.3", + "real-require": "^0.2.0", + "safe-stable-stringify": "^2.3.1", + "sonic-boom": "^4.0.1", + "thread-stream": "^4.0.0" + }, + "bin": { + "pino": "bin.js" + } + }, + "node_modules/pino-abstract-transport": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/pino-abstract-transport/-/pino-abstract-transport-3.0.0.tgz", + "integrity": "sha512-wlfUczU+n7Hy/Ha5j9a/gZNy7We5+cXp8YL+X+PG8S0KXxw7n/JXA3c46Y0zQznIJ83URJiwy7Lh56WLokNuxg==", + "license": "MIT", + "dependencies": { + "split2": "^4.0.0" + } + }, + "node_modules/pino-std-serializers": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/pino-std-serializers/-/pino-std-serializers-7.1.0.tgz", + "integrity": "sha512-BndPH67/JxGExRgiX1dX0w1FvZck5Wa4aal9198SrRhZjH3GxKQUKIBnYJTdj2HDN3UQAS06HlfcSbQj2OHmaw==", + "license": "MIT" + }, + "node_modules/pluralize": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/pluralize/-/pluralize-8.0.0.tgz", + "integrity": "sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/postcss": { + "version": "8.5.28", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.28.tgz", + "integrity": "sha512-RRuzqDtt5Y9h3quz5hWhK+TPnsmVs6WwSU6LkJMeY4HstUEDuYTG8UJSdawMRzmzAtV+KEoG8N3Qg2qLy5vM/A==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "nanoid": "^3.3.18", + "picocolors": "^1.1.1", + "source-map-js": "^1.2.1" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, + "node_modules/postgres-array": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz", + "integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==", + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/postgres-bytea": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.1.tgz", + "integrity": "sha512-5+5HqXnsZPE65IJZSMkZtURARZelel2oXUEO8rH83VS/hxH5vv1uHquPg5wZs8yMAfdv971IU+kcPUczi7NVBQ==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/postgres-date": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz", + "integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/postgres-interval": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz", + "integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==", + "license": "MIT", + "dependencies": { + "xtend": "^4.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/prettier": { + "version": "3.9.8", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.9.8.tgz", + "integrity": "sha512-WRFq3Wn3WId7LLROfMLdH7xaFr2jR62wU8nLO6rQUOLOxNZUviyJQs1M0iIhLexSFy+L+w0ch66wtoO2jRjG0A==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, + "node_modules/process-warning": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/process-warning/-/process-warning-5.1.0.tgz", + "integrity": "sha512-jQSaVHsPgtyw60e1rQ/A+/ArPEj/S8pS/vFnyGa/gYFXrKk/6RuDkoqVDQ5NI5MmS01698ltlAk0NoDBNLujRw==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT" + }, + "node_modules/proxy-addr": { + "version": "2.0.8", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.8.tgz", + "integrity": "sha512-5nnx0yGyVUcY6t9RnWcARWtwT9F1D8O9rt08htPvnd49W1IgZtmLkhu9WfMzQj1cFxjHIO6connUNVW5k7AVyQ==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/qs": { + "version": "6.16.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.16.0.tgz", + "integrity": "sha512-h6fhOIaRrID2CbEY2fqs+7t+UXZo+MLAnU5gRIq85uFtdiUPCdsApMlHhXogKVM4HM2DVbIjGNTTYH2OcmP1vA==", + "license": "BSD-3-Clause", + "dependencies": { + "es-define-property": "^1.0.1", + "side-channel": "^1.1.1" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/quick-format-unescaped": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/quick-format-unescaped/-/quick-format-unescaped-4.0.4.tgz", + "integrity": "sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg==", + "license": "MIT" + }, + "node_modules/range-parser": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.3.0.tgz", + "integrity": "sha512-hek2mFQpPuI4E1BBKrSto+BU3e3x4xuarsbiwr3+lf7p44juvFMV0XFWQAP3xUyqXA4RrXLIoaSUGbSt056ZMw==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/raw-body": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.2.tgz", + "integrity": "sha512-K5zQjDllxWkf7Z5xJdV0/B0WTNqx6vxG70zJE4N0kBs4LovmEYWJzQGxC9bS9RAKu3bgM40lrd5zoLJ12MQ5BA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "http-errors": "~2.0.1", + "iconv-lite": "~0.7.0", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "dev": true, + "license": "MIT", + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/readdirp": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-5.1.1.tgz", + "integrity": "sha512-Kko+Y5XQ6fM+Ce3dq3m9YGxnacYZYl9cA1wZjaF3Vbry2L3i1qVg8+CAgNPsXRArPMUMCaOR7oa9Nqntc43JKA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 20.19.0" + }, + "funding": { + "type": "individual", + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/real-require": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/real-require/-/real-require-0.2.0.tgz", + "integrity": "sha512-57frrGM/OCTLqLOAh0mhVA9VBMHd+9U7Zb2THMGdBUoZVOtGbJzjxsYGDJ3A9AYYCP4hn6y1TVbaOfzWtm5GFg==", + "license": "MIT", + "engines": { + "node": ">= 12.13.0" + } + }, + "node_modules/redis": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/redis/-/redis-6.3.0.tgz", + "integrity": "sha512-XFQbPie1lGpKeUZ8ySYY43yLnQy/iIQtHNvIr/1XdaABpb96rUSdm3Mfl+98FEVbv9ZJIzINMno5s0Nh8E5LEw==", + "license": "MIT", + "dependencies": { + "@redis/bloom": "6.3.0", + "@redis/client": "6.3.0", + "@redis/json": "6.3.0", + "@redis/search": "6.3.0", + "@redis/time-series": "6.3.0" + }, + "engines": { + "node": ">= 20.0.0" + } + }, + "node_modules/reflect-metadata": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.2.2.tgz", + "integrity": "sha512-urBwgfrvVP/eAyXx4hluJivBKzuEbSQs9rKWCrCkbSxNv8mxPcUZKeuoF3Uy4mJl3Lwprp6yy5/39VWigZ4K6Q==", + "license": "Apache-2.0" + }, + "node_modules/require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/restore-cursor": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-3.1.0.tgz", + "integrity": "sha512-l+sSefzHpj5qimhFSE5a8nufZYAM3sBSVMAPtYkmC+4EH2anSGaEMXSD0izRQbu9nfyQ9y5JrVmp7E8oZrUjvA==", + "dev": true, + "license": "MIT", + "dependencies": { + "onetime": "^5.1.0", + "signal-exit": "^3.0.2" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/restore-cursor/node_modules/signal-exit": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", + "dev": true, + "license": "ISC" + }, + "node_modules/ret": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/ret/-/ret-0.5.0.tgz", + "integrity": "sha512-I1XxrZSQ+oErkRR4jYbAyEEu2I0avBvvMM5JN+6EBprOGRCs63ENqZ3vjavq8fBw2+62G5LF5XelKwuJpcvcxw==", + "license": "MIT", + "engines": { + "node": ">=10" + } + }, + "node_modules/reusify": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.1.0.tgz", + "integrity": "sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw==", + "license": "MIT", + "engines": { + "iojs": ">=1.0.0", + "node": ">=0.10.0" + } + }, + "node_modules/rfdc": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.4.1.tgz", + "integrity": "sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==", + "license": "MIT" + }, + "node_modules/rolldown": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.2.9.tgz", + "integrity": "sha512-hx/Pv0N1haXRb11qkfnK5MXB/iqr7i0yjWQqmO9uHqZpBgQSqzc8UsSnEpalsh+j1I8qQ2CkXAkJC8Br3dKSlg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@oxc-project/types": "=0.150.0", + "@rolldown/pluginutils": "^1.0.0" + }, + "bin": { + "rolldown": "bin/cli.mjs" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "optionalDependencies": { + "@rolldown/binding-android-arm-eabi": "1.2.9", + "@rolldown/binding-android-arm64": "1.2.9", + "@rolldown/binding-darwin-arm64": "1.2.9", + "@rolldown/binding-darwin-x64": "1.2.9", + "@rolldown/binding-freebsd-x64": "1.2.9", + "@rolldown/binding-linux-arm-gnueabihf": "1.2.9", + "@rolldown/binding-linux-arm64-gnu": "1.2.9", + "@rolldown/binding-linux-arm64-musl": "1.2.9", + "@rolldown/binding-linux-ppc64-gnu": "1.2.9", + "@rolldown/binding-linux-s390x-gnu": "1.2.9", + "@rolldown/binding-linux-x64-gnu": "1.2.9", + "@rolldown/binding-linux-x64-musl": "1.2.9", + "@rolldown/binding-openharmony-arm64": "1.2.9", + "@rolldown/binding-win32-arm64-msvc": "1.2.9", + "@rolldown/binding-win32-x64-msvc": "1.2.9" + } + }, + "node_modules/router": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz", + "integrity": "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "depd": "^2.0.0", + "is-promise": "^4.0.0", + "parseurl": "^1.3.3", + "path-to-regexp": "^8.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/run-async": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.1.tgz", + "integrity": "sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.12.0" + } + }, + "node_modules/rxjs": { + "version": "7.8.2", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.2.tgz", + "integrity": "sha512-dhKf903U/PQZY6boNNtAGdWbG85WAbjT/1xYoZIC7FAY0yWapOBQVsVrDl58W86//e1VpMNBtRV4MaXfdMySFA==", + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.1.0" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/safe-regex2": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/safe-regex2/-/safe-regex2-5.1.1.tgz", + "integrity": "sha512-mOSBvHGDZMuIEZMdOz/aCEYDCv0E7nfcNsIhUF+/P+xC7Hyf3FkvymqgPbg9D1EdSGu+uKbJgy09K/RKKc7kJA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT", + "dependencies": { + "ret": "~0.5.0" + }, + "bin": { + "safe-regex2": "bin/safe-regex2.js" + } + }, + "node_modules/safe-stable-stringify": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/safe-stable-stringify/-/safe-stable-stringify-2.5.0.tgz", + "integrity": "sha512-b3rppTKm9T+PsVCBEOUR46GWI7fdOs00VKZ1+9c1EWDaDMvjQc6tUwuFyIprgGgTcWoVHSKrU8H31ZHA2e0RHA==", + "license": "MIT", + "engines": { + "node": ">=10" + } + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/secure-json-parse": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/secure-json-parse/-/secure-json-parse-4.1.0.tgz", + "integrity": "sha512-l4KnYfEyqYJxDwlNVyRfO2E4NTHfMKAWdUuA8J0yve2Dz/E/PdBepY03RvyJpssIpRFwJoCD55wA+mEDs6ByWA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "BSD-3-Clause" + }, + "node_modules/semver": { + "version": "7.8.5", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz", + "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==", + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/send": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/send/-/send-1.2.1.tgz", + "integrity": "sha512-1gnZf7DFcoIcajTjTwjwuDjzuz4PPcY2StKPlsGAQ1+YH20IRVrBaXSWmdjowTJ6u8Rc01PoYOGHXfP1mYcZNQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.3", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "fresh": "^2.0.0", + "http-errors": "^2.0.1", + "mime-types": "^3.0.2", + "ms": "^2.1.3", + "on-finished": "^2.4.1", + "range-parser": "^1.2.1", + "statuses": "^2.0.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/serve-static": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.1.tgz", + "integrity": "sha512-xRXBn0pPqQTVQiC8wyQrKs2MOlX24zQ0POGaj0kultvoOCstBQM5yvOhAVSUwOMjQtTvsPWoNCHfPGwaaQJhTw==", + "license": "MIT", + "dependencies": { + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "parseurl": "^1.3.3", + "send": "^1.2.0" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/set-cookie-parser": { + "version": "2.7.2", + "resolved": "https://registry.npmjs.org/set-cookie-parser/-/set-cookie-parser-2.7.2.tgz", + "integrity": "sha512-oeM1lpU/UvhTxw+g3cIfxXHyJRc/uidd3yK1P242gzHds0udQBYzs3y8j4gCCW+ZJ7ad0yctld8RYO+bdurlvw==", + "license": "MIT" + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" + }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "license": "MIT", + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/side-channel": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.1.tgz", + "integrity": "sha512-6x6dK6zJdpTzF4sQeNYxwtvBzf6Eg4GtlesS94HOvTudUeyK2WXAaIfmDgsyslYrRBeFIlsi54AYsFGUuhmvrQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.4", + "side-channel-list": "^1.0.1", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.1.tgz", + "integrity": "sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.4" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/siginfo": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/siginfo/-/siginfo-2.0.0.tgz", + "integrity": "sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==", + "dev": true, + "license": "ISC" + }, + "node_modules/signal-exit": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", + "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/skin-tone": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/skin-tone/-/skin-tone-2.0.0.tgz", + "integrity": "sha512-kUMbT1oBJCpgrnKoSr0o6wPtvRWT9W9UKvGLwfJYO2WuahZRHOpEyL1ckyMGgMWh0UdpmaoFqKKD29WTomNEGA==", + "dev": true, + "license": "MIT", + "dependencies": { + "unicode-emoji-modifier-base": "^1.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/sonic-boom": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-4.2.1.tgz", + "integrity": "sha512-w6AxtubXa2wTXAUsZMMWERrsIRAdrK0Sc+FUytWvYAhBJLyuI4llrMIC1DtlNSdI99EI86KZum2MMq3EAZlF9Q==", + "license": "MIT", + "dependencies": { + "atomic-sleep": "^1.0.0" + } + }, + "node_modules/source-map": { + "version": "0.7.6", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.6.tgz", + "integrity": "sha512-i5uvt8C3ikiWeNZSVZNWcfZPItFQOsYTUAOkcUPGd8DqDy1uOUikjt5dG+uRlwyvR108Fb9DOd4GvXfT0N2/uQ==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">= 12" + } + }, + "node_modules/source-map-js": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz", + "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/source-map-support": { + "version": "0.5.21", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", + "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", + "dev": true, + "license": "MIT", + "dependencies": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + }, + "node_modules/source-map-support/node_modules/source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/split2": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", + "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==", + "license": "ISC", + "engines": { + "node": ">= 10.x" + } + }, + "node_modules/stackback": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz", + "integrity": "sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==", + "dev": true, + "license": "MIT" + }, + "node_modules/statuses": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", + "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/std-env": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/std-env/-/std-env-4.2.0.tgz", + "integrity": "sha512-oCUKSupKTHX53EyjDtuZQ64pjLJ6yYCtpmEw0goYxtjG9KpbRe8KAsl2tBUGU9DyMcJ0RwJ8GqJAFzMXcXW1Rw==", + "dev": true, + "license": "MIT" + }, + "node_modules/stdin-discarder": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/stdin-discarder/-/stdin-discarder-0.3.2.tgz", + "integrity": "sha512-eCPu1qRxPVkl5605OTWF8Wz40b4Mf45NY5LQmVPQ599knfs5QhASUm9GbJ5BDMDOXgrnh0wyEdvzmL//YMlw0A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/streamsearch": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", + "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==", + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "dev": true, + "license": "MIT", + "dependencies": { + "safe-buffer": "~5.2.0" + } + }, + "node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, + "license": "MIT", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-bom": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", + "integrity": "sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/strtok3": { + "version": "10.3.5", + "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-10.3.5.tgz", + "integrity": "sha512-ki4hZQfh5rX0QDLLkOCj+h+CVNkqmp/CMf8v8kZpkNVK6jGQooMytqzLZYUVYIZcFZ6yDB70EfD8POcFXiF5oA==", + "license": "MIT", + "dependencies": { + "@tokenizer/token": "^0.3.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Borewit" + } + }, + "node_modules/superagent": { + "version": "10.3.0", + "resolved": "https://registry.npmjs.org/superagent/-/superagent-10.3.0.tgz", + "integrity": "sha512-B+4Ik7ROgVKrQsXTV0Jwp2u+PXYLSlqtDAhYnkkD+zn3yg8s/zjA2MeGayPoY/KICrbitwneDHrjSotxKL+0XQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "component-emitter": "^1.3.1", + "cookiejar": "^2.1.4", + "debug": "^4.3.7", + "fast-safe-stringify": "^2.1.1", + "form-data": "^4.0.5", + "formidable": "^3.5.4", + "methods": "^1.1.2", + "mime": "2.6.0", + "qs": "^6.14.1" + }, + "engines": { + "node": ">=14.18.0" + } + }, + "node_modules/supertest": { + "version": "7.2.2", + "resolved": "https://registry.npmjs.org/supertest/-/supertest-7.2.2.tgz", + "integrity": "sha512-oK8WG9diS3DlhdUkcFn4tkNIiIbBx9lI2ClF8K+b2/m8Eyv47LSawxUzZQSNKUrVb2KsqeTDCcjAAVPYaSLVTA==", + "dev": true, + "license": "MIT", + "dependencies": { + "cookie-signature": "^1.2.2", + "methods": "^1.1.2", + "superagent": "^10.3.0" + }, + "engines": { + "node": ">=14.18.0" + } + }, + "node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "license": "MIT", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/thread-stream": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/thread-stream/-/thread-stream-4.2.0.tgz", + "integrity": "sha512-e2zZ96wSChazBsbENf/Pcm/4swHt2cEKQ92rhUjkL9GCKiTDJIaTBenjE/m9DXi0QBmTMDkFDdOomUy20A1tDQ==", + "license": "MIT", + "dependencies": { + "real-require": "^1.0.0" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/thread-stream/node_modules/real-require": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/real-require/-/real-require-1.0.0.tgz", + "integrity": "sha512-P4nbQYQfePJxRSmY+v/KINxVucm4NF3p3s7pJveMTtom52FR4YGltUQLB8idDXwDDWW+eYrWDFbuzUnjoWHF7g==", + "license": "MIT" + }, + "node_modules/through": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", + "integrity": "sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==", + "dev": true, + "license": "MIT" + }, + "node_modules/tinybench": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz", + "integrity": "sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==", + "dev": true, + "license": "MIT" + }, + "node_modules/tinyexec": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.3.1.tgz", + "integrity": "sha512-GCvB3aoys96IuDFBMcTB46JOR6mdMtAToqwiW8JlWhsoh1mhHi/xn9ss/Dg7N555GiJyEt2qzoG/NHCwM6h1EA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/tinyglobby": { + "version": "0.2.17", + "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz", + "integrity": "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==", + "dev": true, + "license": "MIT", + "dependencies": { + "fdir": "^6.5.0", + "picomatch": "^4.0.4" + }, + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/SuperchupuDev" + } + }, + "node_modules/tinyrainbow": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-3.1.1.tgz", + "integrity": "sha512-yau8yJdTt989Mm0Bd/236QnzEiPf2xLLTqUZRUJOo/3CB078LSwzei343DgtJVmfJKJE3TMINY1u42SQsP6mXw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/tmp": { + "version": "0.0.33", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", + "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", + "dev": true, + "license": "MIT", + "dependencies": { + "os-tmpdir": "~1.0.2" + }, + "engines": { + "node": ">=0.6.0" + } + }, + "node_modules/toad-cache": { + "version": "3.7.4", + "resolved": "https://registry.npmjs.org/toad-cache/-/toad-cache-3.7.4.tgz", + "integrity": "sha512-m1TdR/rvT7kgGJZhspNtXdsdYk0fddFpJJFlG5s+UkPFo6lkLoZ3YLOaovPYjq1R75NP5JfeTlSHaOsE09peCg==", + "license": "MIT", + "engines": { + "node": ">=20" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "license": "MIT", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/token-types": { + "version": "6.1.2", + "resolved": "https://registry.npmjs.org/token-types/-/token-types-6.1.2.tgz", + "integrity": "sha512-dRXchy+C0IgK8WPC6xvCHFRIWYUbqqdEIKPaKo/AcTUNzwLTK6AH7RjdLWsEZcAN/TBdtfUw3PYEgPr5VPr6ww==", + "license": "MIT", + "dependencies": { + "@borewit/text-codec": "^0.2.1", + "@tokenizer/token": "^0.3.0", + "ieee754": "^1.2.1" + }, + "engines": { + "node": ">=14.16" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Borewit" + } + }, + "node_modules/tsconfig-paths": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-4.2.0.tgz", + "integrity": "sha512-NoZ4roiN7LnbKn9QqE1amc9DJfzvZXxF4xDavcOWt1BPkdx+m+0gJuPM+S0vCe7zTJMYUP0R8pO2XMr+Y8oLIg==", + "dev": true, + "license": "MIT", + "dependencies": { + "json5": "^2.2.2", + "minimist": "^1.2.6", + "strip-bom": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/tslib": { + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", + "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", + "license": "0BSD" + }, + "node_modules/tsx": { + "version": "4.23.15", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.23.15.tgz", + "integrity": "sha512-Yiex1Ovn8z2xPpOWckIiysV1SSyRMY9BkLF++q0yKiDxCqRhosKfMg3janKkiLBwZ5c/YryloKwGZcrEmtwxKw==", + "dev": true, + "license": "MIT", + "dependencies": { + "esbuild": "~0.28.0" + }, + "bin": { + "tsx": "dist/cli.mjs" + }, + "engines": { + "node": ">=18.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + } + }, + "node_modules/type-fest": { + "version": "0.21.3", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.21.3.tgz", + "integrity": "sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==", + "dev": true, + "license": "(MIT OR CC0-1.0)", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/type-is": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-2.1.0.tgz", + "integrity": "sha512-faYHw0anBbc/kWF3zFTEnxSFOAGUX9GFbOBthvDdLsIlEoWOFOtS0zgCiQYwIskL9iGXZL3kAXD8OoZ4GmMATA==", + "license": "MIT", + "dependencies": { + "content-type": "^2.0.0", + "media-typer": "^1.1.0", + "mime-types": "^3.0.0" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/type-is/node_modules/content-type": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz", + "integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/typescript": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz", + "integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/uid": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/uid/-/uid-2.0.2.tgz", + "integrity": "sha512-u3xV3X7uzvi5b1MncmZo3i2Aw222Zk1keqLA1YkHldREkAhAqi65wuPfe7lHx8H/Wzy+8CE7S7uS3jekIM5s8g==", + "license": "MIT", + "dependencies": { + "@lukeed/csprng": "^1.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/uint8array-extras": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/uint8array-extras/-/uint8array-extras-1.5.0.tgz", + "integrity": "sha512-rvKSBiC5zqCCiDZ9kAOszZcDvdAHwwIKJG33Ykj43OKcWsnmcBRL09YTU4nOeHZ8Y2a7l1MgTd08SBe9A8Qj6A==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/undici": { + "version": "6.20.1", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.20.1.tgz", + "integrity": "sha512-AjQF1QsmqfJys+LXfGTNum+qw4S88CojRInG/6t31W/1fk6G59s92bnAvGz5Cmur+kQv2SURXEvvudLmbrE8QA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18.17" + } + }, + "node_modules/undici-types": { + "version": "7.18.2", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.18.2.tgz", + "integrity": "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w==", + "dev": true, + "license": "MIT" + }, + "node_modules/unicode-emoji-modifier-base": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unicode-emoji-modifier-base/-/unicode-emoji-modifier-base-1.0.0.tgz", + "integrity": "sha512-yLSH4py7oFH3oG/9K+XWrz1pSi3dfUrWEnInbxMfArOfc1+33BlGPQtLsOYwvdMy11AwUBetYuaRxSPqgkq+8g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", + "dev": true, + "license": "MIT" + }, + "node_modules/validator": { + "version": "13.15.35", + "resolved": "https://registry.npmjs.org/validator/-/validator-13.15.35.tgz", + "integrity": "sha512-TQ5pAGhd5whStmqWvYF4OjQROlmv9SMFVt37qoCBdqRffuuklWYQlCNnEs2ZaIBD1kZRNnikiZOS1eqgkar0iw==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/vite": { + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/vite/-/vite-8.3.0.tgz", + "integrity": "sha512-lhZBVvEHefgE+HQZC9O7EBJgCU/nVzFNl7vkS4RE0APtWLP02/8QVIkQtzBxPquh7lq5/78NHipTj7ODQ6XuyQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "lightningcss": "^1.33.0", + "picomatch": "^4.0.7", + "postcss": "^8.5.28", + "rolldown": "~1.2.6", + "tinyglobby": "^0.2.17" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "funding": { + "url": "https://github.com/vitejs/vite?sponsor=1" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + }, + "peerDependencies": { + "@types/node": "^20.19.0 || >=22.12.0", + "@vitejs/devtools": "^0.7.1", + "esbuild": "^0.27.0 || ^0.28.0", + "jiti": ">=1.21.0", + "less": "^4.0.0", + "sass": "^1.70.0", + "sass-embedded": "^1.70.0", + "stylus": ">=0.54.8", + "sugarss": "^5.0.0", + "terser": "^5.16.0", + "tsx": "^4.8.1", + "yaml": "^2.4.2" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + }, + "@vitejs/devtools": { + "optional": true + }, + "esbuild": { + "optional": true + }, + "jiti": { + "optional": true + }, + "less": { + "optional": true + }, + "sass": { + "optional": true + }, + "sass-embedded": { + "optional": true + }, + "stylus": { + "optional": true + }, + "sugarss": { + "optional": true + }, + "terser": { + "optional": true + }, + "tsx": { + "optional": true + }, + "yaml": { + "optional": true + } + } + }, + "node_modules/vite-tsconfig-paths": { + "version": "5.1.4", + "resolved": "https://registry.npmjs.org/vite-tsconfig-paths/-/vite-tsconfig-paths-5.1.4.tgz", + "integrity": "sha512-cYj0LRuLV2c2sMqhqhGpaO3LretdtMn/BVX4cPLanIZuwwrkVl+lK84E/miEXkCHWXuq65rhNN4rXsBcOB3S4w==", + "dev": true, + "license": "MIT", + "dependencies": { + "debug": "^4.1.1", + "globrex": "^0.1.2", + "tsconfck": "^3.0.3" + }, + "peerDependencies": { + "vite": "*" + }, + "peerDependenciesMeta": { + "vite": { + "optional": true + } + } + }, + "node_modules/vite-tsconfig-paths/node_modules/tsconfck": { + "version": "3.1.6", + "resolved": "https://registry.npmjs.org/tsconfck/-/tsconfck-3.1.6.tgz", + "integrity": "sha512-ks6Vjr/jEw0P1gmOVwutM3B7fWxoWBL2KRDb1JfqGVawBmO5UsvmWOQFGHBPl5yxYz4eERr19E6L7NMv+Fej4w==", + "deprecated": "unmaintained", + "dev": true, + "license": "MIT", + "bin": { + "tsconfck": "bin/tsconfck.js" + }, + "engines": { + "node": "^18 || >=20" + }, + "peerDependencies": { + "typescript": "^5.0.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/vite/node_modules/picomatch": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz", + "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/vitest": { + "version": "4.1.11", + "resolved": "https://registry.npmjs.org/vitest/-/vitest-4.1.11.tgz", + "integrity": "sha512-fhACrNXUidIbGSBr5FlbuBkO7VWC1ZyLl0DO4CU2DrQoAPxX84Ysxs+HeGQpii5lZWV1Q4gBZTTu49mF+A6Edw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/expect": "4.1.11", + "@vitest/mocker": "4.1.11", + "@vitest/pretty-format": "4.1.11", + "@vitest/runner": "4.1.11", + "@vitest/snapshot": "4.1.11", + "@vitest/spy": "4.1.11", + "@vitest/utils": "4.1.11", + "es-module-lexer": "^2.0.0", + "expect-type": "^1.3.0", + "magic-string": "^0.30.21", + "obug": "^2.1.1", + "pathe": "^2.0.3", + "picomatch": "^4.0.3", + "std-env": "^4.0.0-rc.1", + "tinybench": "^2.9.0", + "tinyexec": "^1.0.2", + "tinyglobby": "^0.2.15", + "tinyrainbow": "^3.1.0", + "vite": "^6.0.0 || ^7.0.0 || ^8.0.0", + "why-is-node-running": "^2.3.0" + }, + "bin": { + "vitest": "vitest.mjs" + }, + "engines": { + "node": "^20.0.0 || ^22.0.0 || >=24.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "@edge-runtime/vm": "*", + "@opentelemetry/api": "^1.9.0", + "@types/node": "^20.0.0 || ^22.0.0 || >=24.0.0", + "@vitest/browser-playwright": "4.1.11", + "@vitest/browser-preview": "4.1.11", + "@vitest/browser-webdriverio": "4.1.11", + "@vitest/coverage-istanbul": "4.1.11", + "@vitest/coverage-v8": "4.1.11", + "@vitest/ui": "4.1.11", + "happy-dom": "*", + "jsdom": "*", + "vite": "^6.0.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "@edge-runtime/vm": { + "optional": true + }, + "@opentelemetry/api": { + "optional": true + }, + "@types/node": { + "optional": true + }, + "@vitest/browser-playwright": { + "optional": true + }, + "@vitest/browser-preview": { + "optional": true + }, + "@vitest/browser-webdriverio": { + "optional": true + }, + "@vitest/coverage-istanbul": { + "optional": true + }, + "@vitest/coverage-v8": { + "optional": true + }, + "@vitest/ui": { + "optional": true + }, + "happy-dom": { + "optional": true + }, + "jsdom": { + "optional": true + }, + "vite": { + "optional": false + } + } + }, + "node_modules/vitest/node_modules/magic-string": { + "version": "0.30.21", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz", + "integrity": "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.5.5" + } + }, + "node_modules/wcwidth": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/wcwidth/-/wcwidth-1.0.1.tgz", + "integrity": "sha512-XHPEwS0q6TaxcvG85+8EYkbiCux2XtWG2mkc47Ng2A77BQu9+DqIOJldST4HgPkuea7dvKSj5VgX3P1d4rW8Tg==", + "dev": true, + "license": "MIT", + "dependencies": { + "defaults": "^1.0.3" + } + }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/why-is-node-running": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-2.3.0.tgz", + "integrity": "sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==", + "dev": true, + "license": "MIT", + "dependencies": { + "siginfo": "^2.0.0", + "stackback": "0.0.2" + }, + "bin": { + "why-is-node-running": "cli.js" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/wrap-ansi": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", + "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "license": "ISC" + }, + "node_modules/xtend": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", + "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", + "license": "MIT", + "engines": { + "node": ">=0.4" + } + }, + "node_modules/yoctocolors": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/yoctocolors/-/yoctocolors-2.2.0.tgz", + "integrity": "sha512-xYqdZFUK/VYazNl/oCDYN+3WloWQwMfZxBoiNt6qNyk+xfOdi598muWE42rNZFp1kNOiqW936q5RhUdnpqElSg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/zod": { + "version": "4.6.5", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.6.5.tgz", + "integrity": "sha512-v5l/aFXZQeai4awLbOpSoHecE9UiMrnfx75tEXLjNonXVARxQ5mOeipTjROUchszUNCqnE+hqAMujRsRHsut2Q==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + } + } +} diff --git a/app/package.json b/app/package.json new file mode 100644 index 00000000..2014015d --- /dev/null +++ b/app/package.json @@ -0,0 +1,66 @@ +{ + "name": "app", + "version": "0.0.1", + "description": "", + "author": "", + "private": true, + "license": "UNLICENSED", + "type": "module", + "scripts": { + "build": "nest build", + "deploy": "nest deploy", + "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", + "start": "nest start", + "start:dev": "nest start --watch", + "start:debug": "nest start --debug --watch", + "start:prod": "node dist/main", + "lint": "oxlint src/ test/", + "test": "vitest run", + "test:unit": "vitest run --include 'src/**/*.spec.ts'", + "test:watch": "vitest", + "test:cov": "vitest run --coverage", + "test:debug": "vitest --inspect-brk --no-file-parallelism", + "graph": "npm run build && DATABASE_URL=postgresql://graph-only.invalid/messenger REDIS_URL=redis://graph-only.invalid:6379 tsx scripts/graph-modules.ts", + "test:e2e": "vitest run --config ./vitest.config.e2e.ts", + "test:dependencies": "E2E_DEPENDENCY_FAULTS=1 vitest run --config ./vitest.config.e2e.ts dependency-failures", + "idempotency:gc": "tsx src/messages/idempotency/idempotency-gc.cli.ts" + }, + "dependencies": { + "@nestjs/common": "^12.0.1", + "@nestjs/config": "^12.0.0", + "@nestjs/core": "^12.0.1", + "@nestjs/platform-express": "^12.0.1", + "@nestjs/platform-fastify": "^12.0.3", + "argon2": "^0.45.1", + "class-transformer": "^0.5.1", + "class-validator": "^0.15.1", + "date-fns": "^4.4.0", + "fastify": "^5.12.5", + "pg": "^8.23.1", + "redis": "^6.3.0", + "reflect-metadata": "^0.2.2", + "rxjs": "^7.8.1", + "zod": "^4.6.5" + }, + "devDependencies": { + "@nestjs/cli": "^12.0.0", + "@nestjs/mau": "^0.2.6", + "@nestjs/schematics": "^12.0.0", + "@nestjs/testing": "^12.0.1", + "@types/express": "^5.0.0", + "@types/node": "^24.0.0", + "@types/pg": "^8.23.1", + "@types/supertest": "^7.0.0", + "@vitest/coverage-v8": "^4.1.2", + "dotenv": "^18.0.5", + "nestjs-spelunker": "^1.3.2", + "oxlint": "^1.58.0", + "prettier": "^3.4.2", + "source-map-support": "^0.5.21", + "supertest": "^7.2.2", + "tsx": "^4.23.15", + "typescript": "^6.0.3", + "vite-tsconfig-paths": "^5.1.4", + "vitest": "^4.1.2" + } +} diff --git a/app/scripts/graph-modules.ts b/app/scripts/graph-modules.ts new file mode 100644 index 00000000..5e8e6d86 --- /dev/null +++ b/app/scripts/graph-modules.ts @@ -0,0 +1,123 @@ +import { mkdir, writeFile } from 'node:fs/promises'; +import 'reflect-metadata'; +import { SpelunkerModule, type DebuggedTree } from 'nestjs-spelunker'; +import { AppModule } from '../dist/app.module.js'; + +function mermaidId(name: string): string { + return name.replace(/[^a-zA-Z0-9_]/gu, '_'); +} + +function findDependencyModule( + tree: DebuggedTree[], + dependency: string, +): DebuggedTree | undefined { + return tree.find( + (candidate) => + candidate.providers.some((item) => item.name === dependency) || + candidate.controllers.some((item) => item.name === dependency), + ); +} + +function renderMermaid(tree: DebuggedTree[]): string { + const lines = [ + 'flowchart LR', + ' %% Generated by scripts/graph-modules.ts', + ' %% Solid arrows: module imports; dotted arrows: constructor dependencies', + ]; + const moduleNames = tree.map((module) => module.name); + + for (const module of tree) { + const moduleId = mermaidId(module.name); + lines.push(` subgraph ${moduleId}["${module.name}"]`); + for (const provider of module.providers) { + lines.push( + ` ${moduleId}_${mermaidId(provider.name)}["provider: ${provider.name}"]`, + ); + } + for (const controller of module.controllers) { + lines.push( + ` ${moduleId}_${mermaidId(controller.name)}["controller: ${controller.name}"]`, + ); + } + lines.push(' end'); + } + + for (const module of tree) { + for (const imported of module.imports) { + if (moduleNames.includes(imported)) { + lines.push( + ` ${mermaidId(module.name)} -->|imports| ${mermaidId(imported)}`, + ); + } + } + for (const item of [...module.providers, ...module.controllers]) { + for (const dependency of item.dependencies) { + const targetModule = findDependencyModule(tree, dependency); + if (targetModule) { + const source = `${mermaidId(module.name)}_${mermaidId(item.name)}`; + const target = `${mermaidId(targetModule.name)}_${mermaidId(dependency)}`; + lines.push(` ${source} -.->|injects| ${target}`); + } + } + } + } + + return `${lines.join('\n')}\n`; +} + +function renderMarkdown(tree: DebuggedTree[], mermaid: string): string { + const lines = [ + '# NestJS dependency graph', + '', + 'Generated from `AppModule` with `nestjs-spelunker` static module debugging.', + '', + '- Solid arrows: module imports.', + '- Dotted arrows: constructor dependencies.', + '- The generator does not boot PostgreSQL or Redis.', + '', + '```mermaid', + mermaid.trim(), + '```', + '', + '## Module details', + '', + ]; + + for (const module of tree) { + lines.push( + `### ${module.name}`, + '', + `- Imports: ${module.imports.join(', ') || 'none'}`, + ); + lines.push( + `- Exports: ${module.exports.map((item) => `${item.name} (${item.type})`).join(', ') || 'none'}`, + ); + lines.push('', '| Kind | Name | Dependencies |', '| --- | --- | --- |'); + for (const provider of module.providers) { + lines.push( + `| provider | ${provider.name} | ${provider.dependencies.join(', ') || 'none'} |`, + ); + } + for (const controller of module.controllers) { + lines.push( + `| controller | ${controller.name} | ${controller.dependencies.join(', ') || 'none'} |`, + ); + } + lines.push(''); + } + + return lines.join('\n'); +} + +const tree = await SpelunkerModule.debug(AppModule); +const mermaid = renderMermaid(tree); +await mkdir('../docs/architecture', { recursive: true }); +await writeFile( + '../docs/architecture/nest-module-details.json', + JSON.stringify(tree, null, 2), +); +await writeFile('../docs/architecture/nest-module-graph.mmd', mermaid); +await writeFile( + '../docs/architecture/nest-dependency-graph.md', + renderMarkdown(tree, mermaid), +); diff --git a/app/src/app.module.ts b/app/src/app.module.ts new file mode 100644 index 00000000..c731b7a4 --- /dev/null +++ b/app/src/app.module.ts @@ -0,0 +1,33 @@ +import { Module } from '@nestjs/common'; +import { AppConfigModule } from './config/app-config.module.js'; +import { DatabaseModule } from './database/database.module.js'; +import { RedisModule } from './redis/redis.module.js'; +import { AuthModule } from './auth/auth.module.js'; +import { ChatsModule } from './chats/chats.module.js'; +import { HealthModule } from './health/health.module.js'; +import { MessagesModule } from './messages/messages.module.js'; +import { MetricsModule } from './metrics/metrics.module.js'; +import { UsersModule } from './users/users.module.js'; +import { APP_FILTER } from '@nestjs/core'; +import { ApiExceptionFilter } from './common/errors/api-exception.filter.js'; + +@Module({ + imports: [ + AppConfigModule, + DatabaseModule, + RedisModule, + UsersModule, + AuthModule, + HealthModule, + ChatsModule, + MessagesModule, + MetricsModule, + ], + providers: [ + { + provide: APP_FILTER, + useClass: ApiExceptionFilter, + }, + ], +}) +export class AppModule {} diff --git a/app/src/auth/auth.controller.ts b/app/src/auth/auth.controller.ts new file mode 100644 index 00000000..265696d9 --- /dev/null +++ b/app/src/auth/auth.controller.ts @@ -0,0 +1,79 @@ +import { + BadRequestException, + Body, + Controller, + Delete, + Headers, + HttpCode, + HttpStatus, + Post, + UnauthorizedException, + UseGuards, +} from '@nestjs/common'; +import { TextDecoder } from 'node:util'; +import { AuthService } from './auth.service.js'; +import { CurrentUserGuard } from '../common/auth/current-user.guard.js'; + +const BASE64 = + /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u; +const BASIC_CHALLENGE = 'Basic realm="messenger", charset="UTF-8"'; + +function basicUnauthorized(): UnauthorizedException { + return new UnauthorizedException({ + message: 'Unauthorized', + challenge: BASIC_CHALLENGE, + }); +} + +function bearerUnauthorized(): UnauthorizedException { + return new UnauthorizedException({ + message: 'Unauthorized', + challenge: 'Bearer realm="messenger"', + }); +} + +function parseBasic(value: string | undefined): [string, string] { + if (typeof value !== 'string') throw basicUnauthorized(); + const match = /^Basic[ \t]+([^ \t]+)$/iu.exec(value); + if (!match || !BASE64.test(match[1])) throw basicUnauthorized(); + const bytes = Buffer.from(match[1], 'base64'); + if (bytes.toString('base64') !== match[1]) throw basicUnauthorized(); + let decoded: string; + try { + decoded = new TextDecoder('utf-8', { fatal: true }).decode(bytes); + } catch { + throw basicUnauthorized(); + } + const separator = decoded.indexOf(':'); + if (separator < 1) throw basicUnauthorized(); + return [decoded.slice(0, separator), decoded.slice(separator + 1)]; +} + +@Controller('api/v1/auth/sessions') +export class AuthController { + constructor(private readonly auth: AuthService) {} + + @Post() + create( + @Headers('authorization') authorization: string | undefined, + @Body() body: unknown, + ) { + const [username, password] = parseBasic(authorization); + if (body !== undefined) + throw new BadRequestException( + 'Session creation does not accept a body', + ); + return this.auth.createSession(username, password); + } + + @Delete('current') + @UseGuards(CurrentUserGuard) + @HttpCode(HttpStatus.NO_CONTENT) + async delete( + @Headers('authorization') authorization: string | undefined, + ): Promise { + if (!authorization || !/^Bearer\s+[^\s]+$/iu.test(authorization)) + throw bearerUnauthorized(); + await this.auth.deleteSession(authorization.slice(7).trim()); + } +} diff --git a/app/src/auth/auth.module.ts b/app/src/auth/auth.module.ts new file mode 100644 index 00000000..c29483bd --- /dev/null +++ b/app/src/auth/auth.module.ts @@ -0,0 +1,16 @@ +import { Module } from '@nestjs/common'; +import { DatabaseModule } from '../database/database.module.js'; +import { RedisModule } from '../redis/redis.module.js'; +import { UsersModule } from '../users/users.module.js'; +import { AuthController } from './auth.controller.js'; +import { AuthService } from './auth.service.js'; +import { SessionRepository } from './session.repository.js'; +import { MetricsModule } from '../metrics/metrics.module.js'; + +@Module({ + imports: [UsersModule, DatabaseModule, RedisModule, MetricsModule], + controllers: [AuthController], + providers: [AuthService, SessionRepository], + exports: [AuthService, SessionRepository], +}) +export class AuthModule {} diff --git a/app/src/auth/auth.service.ts b/app/src/auth/auth.service.ts new file mode 100644 index 00000000..f9833586 --- /dev/null +++ b/app/src/auth/auth.service.ts @@ -0,0 +1,63 @@ +import { + Injectable, + ServiceUnavailableException, + UnauthorizedException, +} from '@nestjs/common'; +import argon2 from 'argon2'; +import type { User } from '../users/user.js'; +import { UsersService } from '../users/users.service.js'; +import { SessionRepository } from './session.repository.js'; + +export type SessionResponse = { + token: string; + token_type: 'Bearer'; + expires_at: string; + user: User; +}; + +@Injectable() +export class AuthService { + constructor( + private readonly users: UsersService, + private readonly sessions: SessionRepository, + ) {} + + async createSession( + username: string, + password: string, + ): Promise { + const storedUser = await this.users.findByUsername(username); + if ( + !storedUser || + !(await argon2.verify(storedUser.password_hash, password)) + ) { + throw new UnauthorizedException(); + } + const user: User = { + id: storedUser.id, + username: storedUser.username, + display_name: storedUser.display_name, + created_at: storedUser.created_at, + }; + let session: { token: string; expiresAt: string }; + try { + session = await this.sessions.create(user.id); + } catch { + throw new ServiceUnavailableException('Session store unavailable'); + } + return { + token: session.token, + token_type: 'Bearer', + expires_at: session.expiresAt, + user, + }; + } + + async deleteSession(token: string): Promise { + try { + await this.sessions.delete(token); + } catch { + throw new ServiceUnavailableException('Session store unavailable'); + } + } +} diff --git a/app/src/auth/session.repository.ts b/app/src/auth/session.repository.ts new file mode 100644 index 00000000..57eb2827 --- /dev/null +++ b/app/src/auth/session.repository.ts @@ -0,0 +1,35 @@ +import { Injectable } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; +import { randomBytes } from 'node:crypto'; +import type { AppConfig } from '../config/app-config.schema.js'; +import { RedisClient } from '../redis/redis.client.js'; +import { MetricsService } from '../metrics/metrics.service.js'; + +@Injectable() +export class SessionRepository { + constructor( + private readonly redis: RedisClient, + private readonly config: ConfigService, + private readonly metrics: MetricsService, + ) {} + + async create( + userId: string, + ): Promise<{ token: string; expiresAt: string }> { + const token = randomBytes(32).toString('base64url'); + const ttl = this.config.getOrThrow('SESSION_TTL_SECONDS'); + const expiresAt = new Date(Date.now() + ttl * 1000).toISOString(); + this.metrics.increment('session_set'); + await this.redis.set( + `session:${token}`, + JSON.stringify({ user_id: userId, expires_at: expiresAt }), + { EX: ttl }, + ); + return { token, expiresAt }; + } + + delete(token: string): Promise { + this.metrics.increment('session_del'); + return this.redis.del(`session:${token}`); + } +} diff --git a/app/src/chats/chat.ts b/app/src/chats/chat.ts new file mode 100644 index 00000000..fb2e262e --- /dev/null +++ b/app/src/chats/chat.ts @@ -0,0 +1,6 @@ +export type Chat = { + id: string; + title: string; + member_ids: string[]; + created_at: string; +}; diff --git a/app/src/chats/chats.controller.ts b/app/src/chats/chats.controller.ts new file mode 100644 index 00000000..53dcd865 --- /dev/null +++ b/app/src/chats/chats.controller.ts @@ -0,0 +1,49 @@ +import { + BadRequestException, + Body, + Controller, + DefaultValuePipe, + Get, + Param, + ParseIntPipe, + ParseUUIDPipe, + Post, + Query, + UseGuards, +} from '@nestjs/common'; +import { CurrentUser } from '../common/auth/current-user.decorator.js'; +import { CurrentUserGuard } from '../common/auth/current-user.guard.js'; +import { ChatsService } from './chats.service.js'; +import { CreateChatDto } from './dto/create-chat.dto.js'; +import type { User } from '../users/user.js'; + +@Controller('api/v1/chats') +@UseGuards(CurrentUserGuard) +export class ChatsController { + constructor(private readonly chatsService: ChatsService) {} + + @Post() + create(@Body() body: CreateChatDto, @CurrentUser() currentUser: User) { + return this.chatsService.create(body, currentUser); + } + + @Get() + list( + @CurrentUser() currentUser: User, + @Query('limit', new DefaultValuePipe(50), new ParseIntPipe()) + limit: number, + @Query('cursor') cursor?: string, + ) { + if (limit < 1 || limit > 100) + throw new BadRequestException('limit must be between 1 and 100'); + return this.chatsService.listForUser(currentUser, limit, cursor); + } + + @Get(':chatId') + get( + @Param('chatId', new ParseUUIDPipe()) chatId: string, + @CurrentUser() currentUser: User, + ) { + return this.chatsService.getForUser(chatId, currentUser); + } +} diff --git a/app/src/chats/chats.module.ts b/app/src/chats/chats.module.ts new file mode 100644 index 00000000..5bc65a34 --- /dev/null +++ b/app/src/chats/chats.module.ts @@ -0,0 +1,16 @@ +import { Module } from '@nestjs/common'; +import { DatabaseModule } from '../database/database.module.js'; +import { RedisModule } from '../redis/redis.module.js'; +import { MetricsModule } from '../metrics/metrics.module.js'; +import { UsersModule } from '../users/users.module.js'; +import { ChatsController } from './chats.controller.js'; +import { ChatsRepository } from './chats.repository.js'; +import { ChatsService } from './chats.service.js'; + +@Module({ + imports: [UsersModule, DatabaseModule, RedisModule, MetricsModule], + controllers: [ChatsController], + providers: [ChatsRepository, ChatsService], + exports: [ChatsService], +}) +export class ChatsModule {} diff --git a/app/src/chats/chats.repository.ts b/app/src/chats/chats.repository.ts new file mode 100644 index 00000000..7f724bcb --- /dev/null +++ b/app/src/chats/chats.repository.ts @@ -0,0 +1,109 @@ +import { BadRequestException, Injectable } from '@nestjs/common'; +import { randomUUID } from 'node:crypto'; +import { DatabaseClient } from '../database/database.client.js'; +import type { Cursor } from '../common/http/cursor.js'; +import type { User } from '../users/user.js'; +import type { Chat } from './chat.js'; + +type ChatRow = { + id: string; + title: string; + created_at: Date | string; + member_ids: string[]; +}; + +function toChat(row: ChatRow): Chat { + return { + id: row.id, + title: row.title, + created_at: new Date(row.created_at).toISOString(), + member_ids: row.member_ids, + }; +} + +@Injectable() +export class ChatsRepository { + constructor(private readonly database: DatabaseClient) {} + + async create(title: string, memberIds: string[]): Promise { + const id = randomUUID(); + return this.database.withTransaction(async (client) => { + const users = await client.query<{ id: string }>({ + name: 'chats.validateMembers', + text: 'SELECT id FROM users WHERE id = ANY($1::uuid[])', + values: [memberIds], + }); + if (users.rowCount !== memberIds.length) + throw new BadRequestException('Chat member does not exist'); + const inserted = await client.query({ + name: 'chats.insert', + text: 'INSERT INTO chats (id, title) VALUES ($1, $2) RETURNING id, title, created_at', + values: [id, title], + }); + for (const memberId of memberIds) { + await client.query({ + name: 'chats.insertMember', + text: 'INSERT INTO chat_members (chat_id, user_id) VALUES ($1, $2)', + values: [id, memberId], + }); + } + return { + ...toChat({ ...inserted.rows[0], member_ids: memberIds }), + member_ids: memberIds, + }; + }); + } + + async findForUser(id: string, user: User): Promise { + const result = await this.database.query( + 'chats.findForUser', + `SELECT c.id, c.title, c.created_at, + COALESCE(array_agg(cm.user_id ORDER BY cm.user_id) + FILTER (WHERE cm.user_id IS NOT NULL), '{}') AS member_ids + FROM chats c + LEFT JOIN chat_members cm ON cm.chat_id = c.id + WHERE c.id = $1 + AND EXISTS ( + SELECT 1 FROM chat_members own + WHERE own.chat_id = c.id AND own.user_id = $2 + ) + GROUP BY c.id`, + [id, user.id], + ); + return result.rows[0] ? toChat(result.rows[0]) : undefined; + } + + async findPageForUser( + user: User, + limit: number, + cursor?: Cursor, + ): Promise<{ items: Chat[]; hasMore: boolean }> { + const values: unknown[] = [user.id]; + let predicate = ''; + if (cursor) { + values.push(cursor.created_at, cursor.id); + predicate = + 'AND (c.created_at, c.id) > ($2::timestamptz, $3::uuid)'; + } + values.push(limit + 1); + const result = await this.database.query( + 'chats.listForUser', + `SELECT c.id, c.title, c.created_at, + COALESCE(array_agg(cm.user_id ORDER BY cm.user_id) + FILTER (WHERE cm.user_id IS NOT NULL), '{}') AS member_ids + FROM chats c + LEFT JOIN chat_members cm ON cm.chat_id = c.id + WHERE EXISTS ( + SELECT 1 FROM chat_members own + WHERE own.chat_id = c.id AND own.user_id = $1 + ) + ${predicate} + GROUP BY c.id ORDER BY c.created_at, c.id LIMIT $${values.length}`, + values, + ); + return { + items: result.rows.slice(0, limit).map(toChat), + hasMore: result.rows.length > limit, + }; + } +} diff --git a/app/src/chats/chats.service.ts b/app/src/chats/chats.service.ts new file mode 100644 index 00000000..2a78c65e --- /dev/null +++ b/app/src/chats/chats.service.ts @@ -0,0 +1,61 @@ +import { + BadRequestException, + Injectable, + NotFoundException, +} from '@nestjs/common'; +import { encodeCursor, decodeCursor } from '../common/http/cursor.js'; +import type { Page } from '../common/http/page.js'; +import type { User } from '../users/user.js'; +import type { CreateChatDto } from './dto/create-chat.dto.js'; +import type { Chat } from './chat.js'; +import { ChatsRepository } from './chats.repository.js'; + +@Injectable() +export class ChatsService { + constructor(private readonly chatsRepository: ChatsRepository) {} + + create(input: CreateChatDto, currentUser: User): Promise { + if (!input.member_ids.includes(currentUser.id)) + throw new BadRequestException('Current user must be a chat member'); + if (new Set(input.member_ids).size !== input.member_ids.length) + throw new BadRequestException('Duplicate chat member'); + return this.chatsRepository.create(input.title, input.member_ids); + } + + async getForUser(chatId: string, currentUser: User): Promise { + const chat = await this.chatsRepository.findForUser( + chatId, + currentUser, + ); + if (!chat) throw new NotFoundException(); + return chat; + } + + async listForUser( + currentUser: User, + limit: number, + cursorValue?: string, + ): Promise> { + const scope = `chats:${currentUser.id}`; + const cursor = cursorValue + ? decodeCursor(cursorValue, scope) + : undefined; + const page = await this.chatsRepository.findPageForUser( + currentUser, + limit, + cursor, + ); + const last = page.items.at(-1); + return { + items: page.items, + next_cursor: + page.hasMore && last + ? encodeCursor({ + scope, + created_at: last.created_at, + id: last.id, + }) + : null, + }; + } +} diff --git a/app/src/chats/dto/create-chat.dto.ts b/app/src/chats/dto/create-chat.dto.ts new file mode 100644 index 00000000..37ff853d --- /dev/null +++ b/app/src/chats/dto/create-chat.dto.ts @@ -0,0 +1,26 @@ +import { + ArrayMaxSize, + ArrayMinSize, + ArrayUnique, + IsArray, + IsString, + IsUUID, + Matches, +} from 'class-validator'; +import { CodePointLength } from '../../common/validation/code-point-length.js'; + +export class CreateChatDto { + @IsString() + @CodePointLength(1, 100) + @Matches(/\S/, { + message: 'title must contain a non-whitespace character', + }) + title: string; + + @IsArray() + @ArrayMinSize(1) + @ArrayMaxSize(100) + @ArrayUnique() + @IsUUID('4', { each: true }) + member_ids: string[]; +} diff --git a/app/src/common/auth/current-user.decorator.ts b/app/src/common/auth/current-user.decorator.ts new file mode 100644 index 00000000..dc054212 --- /dev/null +++ b/app/src/common/auth/current-user.decorator.ts @@ -0,0 +1,10 @@ +import { createParamDecorator, ExecutionContext } from '@nestjs/common'; +import type { User } from '../../users/user.js'; +import { FastifyRequest } from 'fastify'; + +export const CurrentUser = createParamDecorator( + (_data: unknown, context: ExecutionContext): User => { + const request = context.switchToHttp().getRequest(); + return request.currentUser!; + }, +); diff --git a/app/src/common/auth/current-user.guard.ts b/app/src/common/auth/current-user.guard.ts new file mode 100644 index 00000000..ae400b1f --- /dev/null +++ b/app/src/common/auth/current-user.guard.ts @@ -0,0 +1,85 @@ +import { + CanActivate, + ExecutionContext, + Injectable, + ServiceUnavailableException, + UnauthorizedException, +} from '@nestjs/common'; +import type { FastifyRequest } from 'fastify'; +import type { User } from '../../users/user.js'; +import { RedisClient } from '../../redis/redis.client.js'; +import { UsersService } from '../../users/users.service.js'; +import { MetricsService } from '../../metrics/metrics.service.js'; + +@Injectable() +export class CurrentUserGuard implements CanActivate { + constructor( + private readonly redis: RedisClient, + private readonly users: UsersService, + private readonly metrics: MetricsService, + ) {} + + async canActivate(context: ExecutionContext): Promise { + const request = context.switchToHttp().getRequest(); + const authorization = request.headers.authorization; + if ( + typeof authorization !== 'string' || + !/^Bearer\s+[^\s]+$/u.test(authorization) + ) { + throw new UnauthorizedException({ + message: 'Unauthorized', + challenge: 'Bearer realm="messenger"', + }); + } + let session: string | null; + try { + this.metrics.increment('session_get'); + session = await this.redis.get( + `session:${authorization.slice(7).trim()}`, + ); + } catch { + throw new ServiceUnavailableException('Session store unavailable'); + } + if (!session) + throw new UnauthorizedException({ + message: 'Unauthorized', + challenge: 'Bearer realm="messenger"', + }); + let userId: string; + try { + const parsed: unknown = JSON.parse(session); + if ( + typeof parsed !== 'object' || + parsed === null || + !('user_id' in parsed) || + typeof parsed.user_id !== 'string' || + !('expires_at' in parsed) || + typeof parsed.expires_at !== 'string' || + !/^(?:\d{4})-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/u.test( + parsed.expires_at, + ) + ) + throw new Error('invalid session'); + const expiresAt = Date.parse(parsed.expires_at); + if (!Number.isFinite(expiresAt) || Date.now() >= expiresAt) + throw new Error('expired session'); + userId = parsed.user_id; + } catch { + throw new UnauthorizedException({ + message: 'Unauthorized', + challenge: 'Bearer realm="messenger"', + }); + } + let user: User | undefined; + try { + user = await this.users.findById(userId); + } catch { + throw new ServiceUnavailableException( + 'Authentication service unavailable', + ); + } + if (!user) throw new UnauthorizedException(); + request.currentUser = user; + return true; + } +} diff --git a/app/src/common/errors/api-error.ts b/app/src/common/errors/api-error.ts new file mode 100644 index 00000000..b26ece9b --- /dev/null +++ b/app/src/common/errors/api-error.ts @@ -0,0 +1,7 @@ +export type ApiErrorBody = { + error: { + code: string; + message: string; + request_id: string; + }; +}; diff --git a/app/src/common/errors/api-exception.filter.ts b/app/src/common/errors/api-exception.filter.ts new file mode 100644 index 00000000..a1384238 --- /dev/null +++ b/app/src/common/errors/api-exception.filter.ts @@ -0,0 +1,168 @@ +import { + ArgumentsHost, + Catch, + ExceptionFilter, + HttpException, + HttpStatus, + Logger, +} from '@nestjs/common'; +import { HttpAdapterHost } from '@nestjs/core'; +import { ConfigService } from '@nestjs/config'; +import { randomUUID } from 'node:crypto'; +import type { AppConfig } from '../../config/app-config.schema.js'; +import { resolveInstanceId } from '../../config/instance-id.js'; +import type { ApiErrorBody } from './api-error.js'; + +type RequestWithId = { requestId?: string; method?: string; url?: string }; +type ExceptionBody = { message?: unknown; challenge?: unknown }; + +// Connection/session loss codes reported by node-postgres and the network layer. +const UNAVAILABLE_ERROR_CODES: Record = { + ECONNREFUSED: true, + ECONNRESET: true, + ENOTFOUND: true, + ETIMEDOUT: true, + EPIPE: true, + '08000': true, + '08001': true, + '08003': true, + '08004': true, + '08006': true, + '57P01': true, + '57P02': true, + '57P03': true, + '53300': true, + // Transient aborts: the statement was cancelled by statement_timeout, the + // transaction was rolled back by a serialization failure or a deadlock. The + // work was never confirmed, so callers see a retryable 503 instead of an + // internal error. Without this, such an abort would be recorded as the final + // result of an idempotent operation. + '57014': true, + '40001': true, + '40P01': true, +}; + +// Some driver failures carry no `code` at all: node-postgres raises plain errors +// when a connection dies or its pool attempt times out, and node-redis reports a +// closed socket the same way. Without these patterns a stopped database would +// surface as an internal fault instead of a bounded outage. +const UNAVAILABLE_ERROR_MESSAGES = [ + 'Connection terminated unexpectedly', + 'Connection terminated due to connection timeout', + 'timeout exceeded when trying to connect', + 'Client has encountered a connection error and is not queryable', + 'Socket closed unexpectedly', + 'Connection is closed', +]; + +function isDependencyOutage(exception: unknown): boolean { + if (typeof exception !== 'object' || exception === null) return false; + const code = (exception as { code?: unknown }).code; + if (typeof code === 'string' && UNAVAILABLE_ERROR_CODES[code] === true) + return true; + const message = (exception as { message?: unknown }).message; + return ( + typeof message === 'string' && + UNAVAILABLE_ERROR_MESSAGES.some((pattern) => message.includes(pattern)) + ); +} + +function errorCodeForStatus(status: number): string { + const codes: Record = { + [HttpStatus.BAD_REQUEST]: 'invalid_request', + [HttpStatus.UNAUTHORIZED]: 'unauthorized', + [HttpStatus.NOT_FOUND]: 'not_found', + [HttpStatus.CONFLICT]: 'conflict', + [HttpStatus.PAYLOAD_TOO_LARGE]: 'payload_too_large', + [HttpStatus.UNSUPPORTED_MEDIA_TYPE]: 'unsupported_media_type', + [HttpStatus.TOO_MANY_REQUESTS]: 'rate_limited', + [HttpStatus.SERVICE_UNAVAILABLE]: 'unavailable', + }; + return codes[status] ?? 'internal_error'; +} + +@Catch() +export class ApiExceptionFilter implements ExceptionFilter { + private readonly logger = new Logger(ApiExceptionFilter.name); + // Guards and pipes run before interceptors, so an error response may be the + // first thing the filter writes: it must carry the replica identity too. + private readonly instanceId: string; + + constructor( + private readonly adapterHost: HttpAdapterHost, + config: ConfigService, + ) { + this.instanceId = resolveInstanceId(config); + } + + catch(exception: unknown, host: ArgumentsHost): void { + const http = host.switchToHttp(); + const request = http.getRequest(); + const response = http.getResponse(); + const adapter = this.adapterHost.httpAdapter; + const requestId = request.requestId ?? randomUUID(); + request.requestId = requestId; + + let status = HttpStatus.INTERNAL_SERVER_ERROR; + let message = 'Internal server error'; + let challenge: string | undefined; + if (exception instanceof HttpException) { + status = exception.getStatus(); + const body = exception.getResponse(); + const details: ExceptionBody = + typeof body === 'object' && body !== null + ? (body as ExceptionBody) + : {}; + const rawMessage = + 'message' in details ? details.message : undefined; + challenge = + typeof details.challenge === 'string' + ? details.challenge + : undefined; + message = Array.isArray(rawMessage) + ? rawMessage.join('; ') + : typeof rawMessage === 'string' + ? rawMessage + : 'Request failed'; + if (status === HttpStatus.NOT_FOUND) message = 'Resource not found'; + if (status >= HttpStatus.INTERNAL_SERVER_ERROR) + message = + status === HttpStatus.SERVICE_UNAVAILABLE + ? 'Service unavailable' + : 'Internal server error'; + } else if (isDependencyOutage(exception)) { + // A dropped dependency is a bounded outage, not an internal fault. + status = HttpStatus.SERVICE_UNAVAILABLE; + message = 'Service unavailable'; + this.logger.warn( + `Dependency outage on ${request.method ?? ''} ${request.url ?? ''}: ${exception instanceof Error ? exception.message : 'unknown error'}`, + ); + } else { + this.logger.error( + `Unhandled exception on ${request.method ?? ''} ${request.url ?? ''}`, + exception instanceof Error + ? exception.stack + : String(exception), + ); + } + if (status === HttpStatus.UNAUTHORIZED) { + const authChallenge = + challenge ?? + (request.method === 'POST' && + request.url?.startsWith('/api/v1/auth/sessions') + ? 'Basic realm="messenger", charset="UTF-8"' + : 'Bearer realm="messenger"'); + adapter.setHeader(response, 'WWW-Authenticate', authChallenge); + } + adapter.setHeader(response, 'X-Request-Id', requestId); + adapter.setHeader(response, 'X-Instance-Id', this.instanceId); + const payload: ApiErrorBody = { + error: { + code: errorCodeForStatus(status), + message, + request_id: requestId, + }, + }; + adapter.reply(response, payload, status); + } +} diff --git a/app/src/common/http/cursor.spec.ts b/app/src/common/http/cursor.spec.ts new file mode 100644 index 00000000..f4e7823b --- /dev/null +++ b/app/src/common/http/cursor.spec.ts @@ -0,0 +1,85 @@ +import { BadRequestException } from '@nestjs/common'; +import { randomUUID } from 'node:crypto'; +import { describe, expect, it } from 'vitest'; +import { decodeCursor, encodeCursor } from './cursor.js'; + +const scope = 'messages:6f1c2a3e-1111-4222-8333-444455556666'; + +function encode(createdAt: string, cursorScope = scope): string { + return encodeCursor({ + scope: cursorScope, + created_at: createdAt, + id: randomUUID(), + }); +} + +describe('decodeCursor', () => { + it('accepts valid instants and normalizes them to canonical milliseconds', () => { + const accepted: Array<[string, string]> = [ + ['2026-01-01T00:00:00.000Z', '2026-01-01T00:00:00.000Z'], + ['2026-01-01T00:00:00Z', '2026-01-01T00:00:00.000Z'], + ['2026-01-01T00:00:00.999999Z', '2026-01-01T00:00:00.999Z'], + ['2024-02-29T23:59:59.000Z', '2024-02-29T23:59:59.000Z'], + ['2026-12-31T23:59:59.999Z', '2026-12-31T23:59:59.999Z'], + ]; + for (const [createdAt, expected] of accepted) { + const decoded = decodeCursor(encode(createdAt), scope); + expect(decoded.created_at).toBe(expected); + expect(decoded.scope).toBe(scope); + } + }); + + it('rejects calendar dates that the platform parser rolls over', () => { + // 2026-02-31 would silently become 2026-03-03 and then fail inside SQL. + for (const createdAt of [ + '2026-02-31T00:00:00.000Z', + '2025-02-29T00:00:00.000Z', + '2026-04-31T00:00:00.000Z', + '2026-06-31T12:00:00.000Z', + ]) { + expect(() => decodeCursor(encode(createdAt), scope)).toThrow( + BadRequestException, + ); + } + }); + + it('rejects out-of-range and malformed timestamps', () => { + for (const createdAt of [ + '2026-01-01T24:00:00.000Z', + '2026-01-01T00:00:60.000Z', + '2026-13-01T00:00:00.000Z', + '2026-00-01T00:00:00.000Z', + '2026-01-01T00:00:00', + '2026-01-01T00:00:00+02:00', + '2026-1-1T00:00:00.000Z', + '2026-01-01', + 'not-a-timestamp', + ]) { + expect(() => decodeCursor(encode(createdAt), scope)).toThrow( + BadRequestException, + ); + } + }); + + it('rejects a cursor from another scope, a malformed id, and non-cursor input', () => { + expect(() => + decodeCursor( + encode('2026-01-01T00:00:00.000Z', 'messages:other'), + scope, + ), + ).toThrow(BadRequestException); + expect(() => + decodeCursor( + encodeCursor({ + scope, + created_at: '2026-01-01T00:00:00.000Z', + id: 'not-a-uuid', + }), + scope, + ), + ).toThrow(BadRequestException); + expect(() => decodeCursor('not-a-cursor', scope)).toThrow( + BadRequestException, + ); + }); +}); diff --git a/app/src/common/http/cursor.ts b/app/src/common/http/cursor.ts new file mode 100644 index 00000000..037d4a4d --- /dev/null +++ b/app/src/common/http/cursor.ts @@ -0,0 +1,54 @@ +import { BadRequestException } from '@nestjs/common'; +import { isValid, parseISO } from 'date-fns'; + +export type Cursor = { + scope: string; + created_at: string; + id: string; +}; + +// Format check for the canonical API shape: `Date.prototype.toISOString()` with +// optional fractional seconds. Explicit ranges reject values such as 24:00:00. +// Calendar validity (2026-02-31, 2025-02-29, 2026-04-31) is checked by +// date-fns `parseISO`, which refuses impossible dates that the platform parser +// would silently roll over into another day. +const CURSOR_TIMESTAMP = + /^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?Z$/u; + +export function encodeCursor(cursor: Cursor): string { + return Buffer.from(JSON.stringify(cursor), 'utf8').toString('base64url'); +} + +export function decodeCursor(value: string, expectedScope: string): Cursor { + try { + const parsed: unknown = JSON.parse( + Buffer.from(value, 'base64url').toString('utf8'), + ); + if ( + typeof parsed !== 'object' || + parsed === null || + !('scope' in parsed) || + !('created_at' in parsed) || + !('id' in parsed) || + typeof parsed.scope !== 'string' || + typeof parsed.created_at !== 'string' || + typeof parsed.id !== 'string' || + parsed.scope !== expectedScope || + !/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu.test( + parsed.id, + ) || + !CURSOR_TIMESTAMP.test(parsed.created_at) + ) + throw new Error('invalid cursor'); + const instant = parseISO(parsed.created_at); + if (!isValid(instant)) throw new Error('invalid cursor'); + + return { + scope: parsed.scope, + created_at: instant.toISOString(), + id: parsed.id, + }; + } catch { + throw new BadRequestException('Invalid cursor'); + } +} diff --git a/app/src/common/http/page.ts b/app/src/common/http/page.ts new file mode 100644 index 00000000..55c9ff8a --- /dev/null +++ b/app/src/common/http/page.ts @@ -0,0 +1,4 @@ +export type Page = { + items: T[]; + next_cursor: string | null; +}; diff --git a/app/src/common/http/request-id.interceptor.ts b/app/src/common/http/request-id.interceptor.ts new file mode 100644 index 00000000..e1ed4d83 --- /dev/null +++ b/app/src/common/http/request-id.interceptor.ts @@ -0,0 +1,59 @@ +import { + CallHandler, + ExecutionContext, + Injectable, + NestInterceptor, +} from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; +import { HttpAdapterHost } from '@nestjs/core'; +import { randomUUID } from 'node:crypto'; +import { finalize, Observable } from 'rxjs'; +import type { AppConfig } from '../../config/app-config.schema.js'; +import { resolveInstanceId } from '../../config/instance-id.js'; +import { MetricsService } from '../../metrics/metrics.service.js'; + +type RequestWithId = { requestId?: string }; + +@Injectable() +export class RequestIdInterceptor implements NestInterceptor { + // Resolved once: the identity must be stable for the whole process lifetime, + // otherwise a client cannot tell whether it moved to another replica. + private readonly instanceId: string; + + constructor( + private readonly adapterHost: HttpAdapterHost, + private readonly metrics: MetricsService, + config: ConfigService, + ) { + this.instanceId = resolveInstanceId(config); + } + + intercept( + context: ExecutionContext, + next: CallHandler, + ): Observable { + const request = context.switchToHttp().getRequest(); + const response = context.switchToHttp().getResponse(); + const requestId = randomUUID(); + const startedAt = performance.now(); + request.requestId = requestId; + this.adapterHost.httpAdapter.setHeader( + response, + 'X-Request-Id', + requestId, + ); + this.adapterHost.httpAdapter.setHeader( + response, + 'X-Instance-Id', + this.instanceId, + ); + this.metrics.increment('request_count'); + return next + .handle() + .pipe( + finalize(() => + this.metrics.observeLatency(performance.now() - startedAt), + ), + ); + } +} diff --git a/app/src/common/validation/code-point-length.spec.ts b/app/src/common/validation/code-point-length.spec.ts new file mode 100644 index 00000000..2daa8306 --- /dev/null +++ b/app/src/common/validation/code-point-length.spec.ts @@ -0,0 +1,43 @@ +import { validate } from 'class-validator'; +import { describe, expect, it } from 'vitest'; +import { CodePointLength } from './code-point-length.js'; + +class Sample { + @CodePointLength(3, 5) + value!: string; +} + +async function fails(value: unknown): Promise { + const sample = new Sample(); + (sample as { value: unknown }).value = value; + const errors = await validate(sample); + return errors.length > 0; +} + +describe('CodePointLength', () => { + it('counts Unicode code points instead of UTF-16 units', async () => { + // '🔐' is one code point but two UTF-16 units. + expect(await fails('🔐🔐')).toBe(true); + expect(await fails('🔐🔐🔐')).toBe(false); + expect(await fails('🔐🔐🔐🔐🔐')).toBe(false); + expect(await fails('🔐🔐🔐🔐🔐🔐')).toBe(true); + // Combining marks are separate code points, not grapheme clusters: + // three 'é' sequences are six code points and exceed the maximum. + expect(await fails('e\u0301e\u0301')).toBe(false); + expect(await fails('e\u0301e\u0301e\u0301')).toBe(true); + }); + + it('applies to BMP text boundaries', async () => { + expect(await fails('ab')).toBe(true); + expect(await fails('abc')).toBe(false); + expect(await fails('abcde')).toBe(false); + expect(await fails('abcdef')).toBe(true); + }); + + it('rejects empty and non-string values', async () => { + expect(await fails('')).toBe(true); + expect(await fails(undefined)).toBe(true); + expect(await fails(12345)).toBe(true); + expect(await fails(['a', 'b', 'c'])).toBe(true); + }); +}); diff --git a/app/src/common/validation/code-point-length.ts b/app/src/common/validation/code-point-length.ts new file mode 100644 index 00000000..5b3fa3ae --- /dev/null +++ b/app/src/common/validation/code-point-length.ts @@ -0,0 +1,38 @@ +import { + registerDecorator, + ValidatorConstraint, + type ValidationArguments, + type ValidatorConstraintInterface, +} from 'class-validator'; + +// JSON Schema (and the course contract) measure string lengths in Unicode code +// points, while String.prototype.length counts UTF-16 units: one emoji outside +// the BMP is two units. `@Length` therefore accepted an 11-emoji password +// (22 units) and rejected 4000 emoji (8000 units), so these fields use an +// explicit code-point validator instead. +@ValidatorConstraint({ name: 'codePointLength', async: false }) +class CodePointLengthConstraint implements ValidatorConstraintInterface { + validate(value: unknown, args: ValidationArguments): boolean { + const [min, max] = args.constraints as [number, number]; + if (typeof value !== 'string') return false; + const length = [...value].length; + return length >= min && length <= max; + } + + defaultMessage(args: ValidationArguments): string { + const [min, max] = args.constraints as [number, number]; + return `${args.property} must be between ${min} and ${max} code points`; + } +} + +export function CodePointLength(min: number, max: number): PropertyDecorator { + return (target, propertyKey) => { + registerDecorator({ + name: 'codePointLength', + target: target.constructor, + propertyName: String(propertyKey), + constraints: [min, max], + validator: CodePointLengthConstraint, + }); + }; +} diff --git a/app/src/config/app-config.module.ts b/app/src/config/app-config.module.ts new file mode 100644 index 00000000..567ea6a7 --- /dev/null +++ b/app/src/config/app-config.module.ts @@ -0,0 +1,16 @@ +import { Global, Module } from '@nestjs/common'; +import { ConfigModule } from '@nestjs/config'; +import { parseAppConfig } from './app-config.schema.js'; + +@Global() +@Module({ + imports: [ + ConfigModule.forRoot({ + isGlobal: true, + cache: true, + validate: parseAppConfig, + }), + ], + exports: [ConfigModule], +}) +export class AppConfigModule {} diff --git a/app/src/config/app-config.schema.ts b/app/src/config/app-config.schema.ts new file mode 100644 index 00000000..2a686f55 --- /dev/null +++ b/app/src/config/app-config.schema.ts @@ -0,0 +1,101 @@ +import { readFileSync } from 'node:fs'; +import { z } from 'zod'; + +function numeric( + name: string, + minimum: number, + maximum: number | undefined, + fallback: number, +) { + let schema = z + .number({ message: `${name} must be a number` }) + .int() + .min(minimum); + if (maximum !== undefined) schema = schema.max(maximum); + return z.preprocess( + (value) => + typeof value === 'string' && value.trim() !== '' + ? Number(value) + : value, + schema.default(fallback), + ); +} + +function requiredString(name: string) { + return z + .string({ message: `${name} is required` }) + .min(1, `${name} is required`); +} + +export const appConfigSchema = z + .object({ + APP_HOST: z.string().min(1).default('0.0.0.0'), + APP_PORT: numeric('APP_PORT', 1, 65535, 8080), + APP_ENV: z.string().min(1).default('lab'), + SESSION_TTL_SECONDS: numeric('SESSION_TTL_SECONDS', 2, undefined, 3600), + DATABASE_URL: requiredString('DATABASE_URL'), + REDIS_URL: requiredString('REDIS_URL'), + DATABASE_POOL_MAX: numeric('DATABASE_POOL_MAX', 1, 100, 10), + DATABASE_CONNECTION_TIMEOUT_MS: numeric( + 'DATABASE_CONNECTION_TIMEOUT_MS', + 1, + undefined, + 5000, + ), + DATABASE_STATEMENT_TIMEOUT_MS: numeric( + 'DATABASE_STATEMENT_TIMEOUT_MS', + 1, + undefined, + 5000, + ), + // Бюджет зависимостей в /health/ready: LB проверяет ту же ручку, поэтому + // проба готовности обязана уложиться в timeout check HAProxy (500 ms). + HEALTH_TIMEOUT_MS: numeric('HEALTH_TIMEOUT_MS', 1, undefined, 400), + CACHE_TTL_SECONDS: numeric('CACHE_TTL_SECONDS', 1, undefined, 30), + CACHE_MODE: z.enum(['protected', 'naive']).default('protected'), + CACHE_LOCK_TTL_MS: numeric('CACHE_LOCK_TTL_MS', 1, undefined, 1000), + CACHE_MISS_DELAY_MS: numeric('CACHE_MISS_DELAY_MS', 0, undefined, 0), + METRICS_TOKEN: z.string().min(1).optional(), + DRAIN_DELAY_MS: numeric('DRAIN_DELAY_MS', 0, undefined, 5000), + INSTANCE_ID: z.string().min(1).optional(), + IDEMPOTENCY_TTL_SECONDS: numeric( + 'IDEMPOTENCY_TTL_SECONDS', + 60, + undefined, + 86400, + ), + }) + .strip(); + +export type AppConfig = z.infer; +export type AppConfigKey = keyof AppConfig; + +function resolveSecret( + raw: Record, + key: 'DATABASE_URL' | 'REDIS_URL', +): unknown { + const fileKey = `${key}_FILE`; + const path = raw[fileKey]; + if (typeof path !== 'string' || path.length === 0) return raw[key]; + try { + const value = readFileSync(path, 'utf8').trim(); + if (value.length === 0) + throw new Error(`${fileKey} contains an empty value`); + return value; + } catch (error) { + if ( + error instanceof Error && + error.message.includes('contains an empty value') + ) + throw error; + throw new Error(`${fileKey} could not be read`); + } +} + +export function parseAppConfig(raw: Record): AppConfig { + return appConfigSchema.parse({ + ...raw, + DATABASE_URL: resolveSecret(raw, 'DATABASE_URL'), + REDIS_URL: resolveSecret(raw, 'REDIS_URL'), + }); +} diff --git a/app/src/config/instance-id.ts b/app/src/config/instance-id.ts new file mode 100644 index 00000000..e42f2f48 --- /dev/null +++ b/app/src/config/instance-id.ts @@ -0,0 +1,14 @@ +import { randomUUID } from 'node:crypto'; +import { hostname } from 'node:os'; +import type { ConfigService } from '@nestjs/config'; +import type { AppConfig } from './app-config.schema.js'; + +// A replica must be identifiable from the outside. Inside Docker the hostname is +// the short container ID, so X-Instance-Id can be mapped back to exactly one +// container; INSTANCE_ID exists for platforms where that mapping is not useful. +export function resolveInstanceId(config: ConfigService): string { + const configured = config.get('INSTANCE_ID'); + if (configured) return configured; + const host = hostname(); + return host.length > 0 ? host : randomUUID(); +} diff --git a/app/src/database/database.client.ts b/app/src/database/database.client.ts new file mode 100644 index 00000000..34413d95 --- /dev/null +++ b/app/src/database/database.client.ts @@ -0,0 +1,90 @@ +import { Injectable, Logger, OnModuleDestroy } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; +import pg from 'pg'; +import { MetricsService } from '../metrics/metrics.service.js'; +import type { AppConfig } from '../config/app-config.schema.js'; + +@Injectable() +export class DatabaseClient implements OnModuleDestroy { + readonly pool: pg.Pool; + private readonly healthPool: pg.Pool; + private readonly logger = new Logger(DatabaseClient.name); + + constructor( + private readonly config: ConfigService, + private readonly metrics: MetricsService, + ) { + this.pool = new pg.Pool({ + connectionString: this.config.getOrThrow('DATABASE_URL'), + max: this.config.getOrThrow('DATABASE_POOL_MAX'), + connectionTimeoutMillis: this.config.getOrThrow( + 'DATABASE_CONNECTION_TIMEOUT_MS', + ), + statement_timeout: this.config.getOrThrow( + 'DATABASE_STATEMENT_TIMEOUT_MS', + ), + }); + // Idle clients emit 'error' on the pool when the database drops; without a + // listener Node treats it as uncaught and terminates the process. + this.pool.on('error', (error: Error) => { + this.metrics.increment('database.pool_error'); + this.logger.warn(`PostgreSQL pool error: ${error.message}`); + }); + // Проба готовности не должна стоять в очереди за бизнес-запросами: занятый + // общий пул — это перегрузка, а не потеря зависимости. + this.healthPool = new pg.Pool({ + connectionString: this.config.getOrThrow('DATABASE_URL'), + max: 1, + idleTimeoutMillis: 0, + connectionTimeoutMillis: this.config.getOrThrow('HEALTH_TIMEOUT_MS'), + query_timeout: this.config.getOrThrow('HEALTH_TIMEOUT_MS'), + }); + this.healthPool.on('error', (error: Error) => { + this.metrics.increment('database.health_pool_error'); + this.logger.warn(`PostgreSQL health connection error: ${error.message}`); + }); + } + + query( + label: string, + text: string, + values: readonly unknown[] = [], + ): Promise> { + this.metrics.increment(label); + return this.pool.query({ text, values: [...values] }); + } + + async health(): Promise { + this.metrics.increment('health.database'); + await this.healthPool.query('SELECT 1'); + } + + async withTransaction( + work: (client: pg.PoolClient) => Promise, + ): Promise { + const client = await this.pool.connect(); + try { + await client.query('BEGIN'); + const result = await work(client); + await client.query('COMMIT'); + return result; + } catch (error) { + try { + await client.query('ROLLBACK'); + } catch (rollbackError) { + this.metrics.increment('database.rollback_error'); + this.logger.warn( + `Rollback failed: ${rollbackError instanceof Error ? rollbackError.message : 'unknown error'}`, + ); + } + // Callers must see the operation error, not the rollback error. + throw error; + } finally { + client.release(); + } + } + + async onModuleDestroy(): Promise { + await Promise.all([this.pool.end(), this.healthPool.end()]); + } +} diff --git a/app/src/database/database.module.ts b/app/src/database/database.module.ts new file mode 100644 index 00000000..fe9f0b76 --- /dev/null +++ b/app/src/database/database.module.ts @@ -0,0 +1,10 @@ +import { Module } from '@nestjs/common'; +import { MetricsModule } from '../metrics/metrics.module.js'; +import { DatabaseClient } from './database.client.js'; + +@Module({ + imports: [MetricsModule], + providers: [DatabaseClient], + exports: [DatabaseClient], +}) +export class DatabaseModule {} diff --git a/app/src/database/migration.runner.ts b/app/src/database/migration.runner.ts new file mode 100644 index 00000000..dfcd5070 --- /dev/null +++ b/app/src/database/migration.runner.ts @@ -0,0 +1,63 @@ +import { readdir, readFile } from 'node:fs/promises'; +import { dirname, join } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { DatabaseClient } from './database.client.js'; +import { MetricsService } from '../metrics/metrics.service.js'; +import { parseAppConfig } from '../config/app-config.schema.js'; + +const migrationsDirectory = join( + dirname(fileURLToPath(import.meta.url)), + 'migrations', +); + +async function migrationFiles(): Promise { + const files = await readdir(migrationsDirectory); + return files.filter((file) => /^\d+_.+\.sql$/u.test(file)).sort(); +} + +export async function runMigrations(database: DatabaseClient): Promise { + await database.query( + 'migrations.ensure_table', + `CREATE TABLE IF NOT EXISTS schema_migrations ( + version text PRIMARY KEY, + applied_at timestamptz NOT NULL DEFAULT now() + )`, + ); + + for (const version of await migrationFiles()) { + await database.withTransaction(async (client) => { + const applied = await client.query({ + text: 'SELECT version FROM schema_migrations WHERE version = $1', + values: [version], + }); + if (applied.rowCount) return; + + const sql = await readFile( + join(migrationsDirectory, version), + 'utf8', + ); + await client.query(sql); + await client.query({ + text: 'INSERT INTO schema_migrations (version) VALUES ($1)', + values: [version], + }); + }); + } +} + +async function main(): Promise { + const config = parseAppConfig(process.env as Record); + const database = new DatabaseClient( + { + getOrThrow: (key: keyof typeof config) => config[key], + } as never, + new MetricsService(), + ); + try { + await runMigrations(database); + } finally { + await database.onModuleDestroy(); + } +} + +if (process.argv[1] === fileURLToPath(import.meta.url)) await main(); diff --git a/app/src/database/migrations/001_initial.sql b/app/src/database/migrations/001_initial.sql new file mode 100644 index 00000000..19225298 --- /dev/null +++ b/app/src/database/migrations/001_initial.sql @@ -0,0 +1,41 @@ +CREATE TABLE IF NOT EXISTS schema_migrations ( + version text PRIMARY KEY, + applied_at timestamptz NOT NULL DEFAULT now() +); + +CREATE TABLE IF NOT EXISTS users ( + id uuid PRIMARY KEY, + username text NOT NULL UNIQUE, + display_name text NOT NULL, + password_hash text NOT NULL, + created_at timestamptz NOT NULL DEFAULT now() +); + +CREATE TABLE IF NOT EXISTS chats ( + id uuid PRIMARY KEY, + title text NOT NULL, + created_at timestamptz NOT NULL DEFAULT now(), + message_version bigint NOT NULL DEFAULT 0 +); + +CREATE TABLE IF NOT EXISTS chat_members ( + chat_id uuid NOT NULL REFERENCES chats(id) ON DELETE CASCADE, + user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE, + PRIMARY KEY (chat_id, user_id) +); + +CREATE TABLE IF NOT EXISTS messages ( + id uuid PRIMARY KEY, + chat_id uuid NOT NULL REFERENCES chats(id) ON DELETE CASCADE, + sender_id uuid NOT NULL REFERENCES users(id) ON DELETE RESTRICT, + text text NOT NULL, + created_at timestamptz NOT NULL DEFAULT now(), + CONSTRAINT messages_sender_member_fk + FOREIGN KEY (chat_id, sender_id) REFERENCES chat_members(chat_id, user_id) + ON DELETE RESTRICT +); + +CREATE INDEX IF NOT EXISTS messages_chat_created_id_idx + ON messages (chat_id, created_at, id); +CREATE INDEX IF NOT EXISTS chat_members_user_chat_idx + ON chat_members (user_id, chat_id); diff --git a/app/src/database/migrations/002_timestamp_precision.sql b/app/src/database/migrations/002_timestamp_precision.sql new file mode 100644 index 00000000..e084dc68 --- /dev/null +++ b/app/src/database/migrations/002_timestamp_precision.sql @@ -0,0 +1,5 @@ +-- HTTP timestamps and keyset cursors use JavaScript millisecond precision. +-- Store the same precision so a returned cursor cannot point before its own row. +ALTER TABLE users ALTER COLUMN created_at TYPE timestamptz(3); +ALTER TABLE chats ALTER COLUMN created_at TYPE timestamptz(3); +ALTER TABLE messages ALTER COLUMN created_at TYPE timestamptz(3); diff --git a/app/src/database/migrations/003_idempotency_keys.sql b/app/src/database/migrations/003_idempotency_keys.sql new file mode 100644 index 00000000..aad214df --- /dev/null +++ b/app/src/database/migrations/003_idempotency_keys.sql @@ -0,0 +1,20 @@ +-- Shared idempotency ledger for POST /api/v1/chats/{id}/messages. +-- The key scope is (user, method, path, key): the same key from another user or +-- another chat is independent, as the contract requires. +-- claim + response are committed in one transaction, so a committed row always +-- carries status_code and response_body (there is no "poisoned" intermediate state). +CREATE TABLE IF NOT EXISTS idempotency_keys ( + user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE, + method text NOT NULL, + path text NOT NULL, + key text NOT NULL, + request_fingerprint text NOT NULL, + status_code integer, + response_body jsonb, + message_id uuid, + created_at timestamptz NOT NULL DEFAULT now(), + PRIMARY KEY (user_id, method, path, key) +); + +CREATE INDEX IF NOT EXISTS idempotency_keys_created_at_idx + ON idempotency_keys (created_at); diff --git a/app/src/database/migrations/004_pg_stat_statements.sql b/app/src/database/migrations/004_pg_stat_statements.sql new file mode 100644 index 00000000..c70da499 --- /dev/null +++ b/app/src/database/migrations/004_pg_stat_statements.sql @@ -0,0 +1,9 @@ +-- Instrumentation for the scaling experiments. pg_stat_statements only works +-- when the server is started with shared_preload_libraries=pg_stat_statements +-- (compose.yaml does that); without the preload the CREATE fails with a plain +-- notice, so a database started without the preload still migrates cleanly. +DO $$ BEGIN + CREATE EXTENSION IF NOT EXISTS pg_stat_statements; +EXCEPTION WHEN OTHERS THEN + RAISE NOTICE 'pg_stat_statements unavailable: %', SQLERRM; +END $$; diff --git a/app/src/health/health.controller.ts b/app/src/health/health.controller.ts new file mode 100644 index 00000000..f297b64c --- /dev/null +++ b/app/src/health/health.controller.ts @@ -0,0 +1,17 @@ +import { Controller, Get } from '@nestjs/common'; +import { HealthService } from './health.service.js'; + +@Controller('health') +export class HealthController { + constructor(private readonly healthService: HealthService) {} + + @Get('live') + getLive() { + return this.healthService.getLiveness(); + } + + @Get('ready') + async getReady() { + return this.healthService.getReadiness(); + } +} diff --git a/app/src/health/health.module.ts b/app/src/health/health.module.ts new file mode 100644 index 00000000..f5bbe7a6 --- /dev/null +++ b/app/src/health/health.module.ts @@ -0,0 +1,12 @@ +import { Module } from '@nestjs/common'; +import { HealthController } from './health.controller.js'; +import { HealthService } from './health.service.js'; +import { DatabaseModule } from '../database/database.module.js'; +import { RedisModule } from '../redis/redis.module.js'; + +@Module({ + imports: [DatabaseModule, RedisModule], + controllers: [HealthController], + providers: [HealthService], +}) +export class HealthModule {} diff --git a/app/src/health/health.service.spec.ts b/app/src/health/health.service.spec.ts new file mode 100644 index 00000000..91f3e435 --- /dev/null +++ b/app/src/health/health.service.spec.ts @@ -0,0 +1,91 @@ +import { describe, expect, it, vi } from 'vitest'; +import { ServiceUnavailableException } from '@nestjs/common'; +import { HealthService } from './health.service.js'; + +describe('HealthService', () => { + it('reports liveness and readiness when dependencies are healthy', async () => { + const database = { health: vi.fn().mockResolvedValue(undefined) }; + const redis = { health: vi.fn().mockResolvedValue(undefined) }; + const service = new HealthService( + database as never, + redis as never, + { getOrThrow: () => 50 } as never, + ); + expect(service.getLiveness()).toEqual({ status: 'ok' }); + await expect(service.getReadiness()).resolves.toEqual({ status: 'ok' }); + }); + + it('rejects readiness when a dependency is unavailable', async () => { + const database = { + health: vi.fn().mockRejectedValue(new Error('down')), + }; + const redis = { health: vi.fn().mockResolvedValue(undefined) }; + const service = new HealthService( + database as never, + redis as never, + { getOrThrow: () => 50 } as never, + ); + await expect(service.getReadiness()).rejects.toBeInstanceOf( + ServiceUnavailableException, + ); + }); + + it('rejects readiness when Redis alone is unavailable', async () => { + const database = { health: vi.fn().mockResolvedValue(undefined) }; + const redis = { + health: vi.fn().mockRejectedValue(new Error('down')), + }; + const service = new HealthService( + database as never, + redis as never, + { getOrThrow: () => 50 } as never, + ); + await expect(service.getReadiness()).rejects.toBeInstanceOf( + ServiceUnavailableException, + ); + }); + + it('keeps liveness healthy while draining', async () => { + const service = new HealthService( + { health: vi.fn() } as never, + { health: vi.fn() } as never, + { getOrThrow: () => 50 } as never, + ); + service.setDraining(); + expect(service.getLiveness()).toEqual({ status: 'ok' }); + await expect(service.getReadiness()).rejects.toThrow( + 'Service is shutting down', + ); + }); + + it('answers not-ready during drain without probing dependencies', async () => { + const database = { health: vi.fn().mockResolvedValue(undefined) }; + const redis = { health: vi.fn().mockResolvedValue(undefined) }; + const service = new HealthService( + database as never, + redis as never, + { getOrThrow: () => 50 } as never, + ); + service.setDraining(); + await expect(service.getReadiness()).rejects.toThrow( + 'Service is shutting down', + ); + // Дрейн обязан отвечать сразу: проба LB не должна ждать зависимости, + // когда реплика уже выходит из ротации. + expect(database.health).not.toHaveBeenCalled(); + expect(redis.health).not.toHaveBeenCalled(); + }); + + it('fails readiness within the budget when a dependency hangs', async () => { + const database = { health: vi.fn(() => new Promise(() => {})) }; + const redis = { health: vi.fn().mockResolvedValue(undefined) }; + const service = new HealthService( + database as never, + redis as never, + { getOrThrow: () => 20 } as never, + ); + await expect(service.getReadiness()).rejects.toBeInstanceOf( + ServiceUnavailableException, + ); + }); +}); diff --git a/app/src/health/health.service.ts b/app/src/health/health.service.ts new file mode 100644 index 00000000..b2e56402 --- /dev/null +++ b/app/src/health/health.service.ts @@ -0,0 +1,60 @@ +import { + Global, + Injectable, + Module, + ServiceUnavailableException, +} from '@nestjs/common'; +import { DatabaseClient } from '../database/database.client.js'; +import { RedisClient } from '../redis/redis.client.js'; +import { ConfigService } from '@nestjs/config'; +import type { AppConfig } from '../config/app-config.schema.js'; + +@Injectable() +export class HealthService { + private ready = true; + constructor( + private readonly database: DatabaseClient, + private readonly redis: RedisClient, + private readonly config: ConfigService, + ) {} + getLiveness() { + return { status: 'ok' as const }; + } + async getReadiness() { + if (!this.ready) + throw new ServiceUnavailableException('Service is shutting down'); + const dependencies = Promise.all([ + this.database.health(), + this.redis.health(), + ]); + // Поздний отказ после дедлайна не должен стать unhandled rejection. + dependencies.catch(() => undefined); + let timer: NodeJS.Timeout | undefined; + const deadline = new Promise((_, reject) => { + timer = setTimeout( + () => reject(new Error('readiness budget exceeded')), + this.config.getOrThrow('HEALTH_TIMEOUT_MS'), + ); + }); + try { + await Promise.race([dependencies, deadline]); + } catch { + throw new ServiceUnavailableException('Dependencies unavailable'); + } finally { + clearTimeout(timer); + } + return { status: 'ok' as const }; + } + // Called on SIGTERM before the drain delay: the replica turns not-ready while + // it finishes in-flight requests, so the load balancer stops probing it + // successfully and removes it from rotation. The delay itself lives in + // main.ts, because Nest destroys providers (closing the pools) before this + // class could serve anyone. + setDraining() { + this.ready = false; + } +} + +@Global() +@Module({ providers: [HealthService], exports: [HealthService] }) +export class HealthServiceModule {} diff --git a/app/src/main.ts b/app/src/main.ts new file mode 100644 index 00000000..1421e99f --- /dev/null +++ b/app/src/main.ts @@ -0,0 +1,63 @@ +import { NestFactory } from '@nestjs/core'; +import { HttpAdapterHost } from '@nestjs/core'; +import { ConfigService } from '@nestjs/config'; +import { ValidationPipe } from '@nestjs/common'; +import { + FastifyAdapter, + NestFastifyApplication, +} from '@nestjs/platform-fastify'; +import { AppModule } from './app.module.js'; +import { HealthService } from './health/health.service.js'; +import { MetricsService } from './metrics/metrics.service.js'; +import { RequestIdInterceptor } from './common/http/request-id.interceptor.js'; + +async function bootstrap(): Promise { + const app = await NestFactory.create( + AppModule, + new FastifyAdapter({ logger: true }), + ); + app.useGlobalInterceptors( + new RequestIdInterceptor( + app.get(HttpAdapterHost), + app.get(MetricsService), + app.get(ConfigService), + ), + ); + app.useGlobalPipes( + new ValidationPipe({ + whitelist: true, + forbidNonWhitelisted: true, + transform: true, + }), + ); + + const config = app.get(ConfigService); + const port = config.getOrThrow('APP_PORT'); + const host = config.getOrThrow('APP_HOST'); + await app.listen(port, host); + + // Drain before teardown. Nest's own shutdown sequence destroys providers + // (closing the database pool and Redis) before `beforeApplicationShutdown` + // runs, so relying on it would keep the replica listed in the load balancer + // while it can no longer serve: SIGTERM must first turn the replica + // not-ready for the LB probe, then wait DRAIN_DELAY_MS, and only then close + // the server and the pools. + const health = app.get(HealthService); + const drainDelayMs = config.getOrThrow('DRAIN_DELAY_MS'); + let shuttingDown = false; + const shutdown = async (): Promise => { + if (shuttingDown) return; + shuttingDown = true; + health.setDraining(); + if (drainDelayMs > 0) + await new Promise((resolve) => setTimeout(resolve, drainDelayMs)); + await app.close(); + process.exit(0); + }; + for (const signal of ['SIGTERM', 'SIGINT', 'SIGHUP'] as const) + process.once(signal, () => { + void shutdown(); + }); +} + +await bootstrap(); diff --git a/app/src/messages/cache/messages-cache.metrics.spec.ts b/app/src/messages/cache/messages-cache.metrics.spec.ts new file mode 100644 index 00000000..13da19e1 --- /dev/null +++ b/app/src/messages/cache/messages-cache.metrics.spec.ts @@ -0,0 +1,37 @@ +import { ConfigService } from '@nestjs/config'; +import { describe, expect, it, vi } from 'vitest'; +import { MetricsService } from '../../metrics/metrics.service.js'; +import { MessagesCacheService } from './messages-cache.service.js'; + +describe('MessagesCacheService metrics', () => { + it('records a miss and a hit for a protected page fill', async () => { + const metrics = new MetricsService(); + const page = { items: [], next_cursor: null }; + const redis = { + get: vi + .fn() + .mockResolvedValueOnce(null) + .mockResolvedValueOnce(null) + .mockResolvedValue(JSON.stringify(page)), + setNxPx: vi.fn().mockResolvedValue(true), + set: vi.fn().mockResolvedValue('OK'), + unlock: vi.fn().mockResolvedValue(1), + }; + const config = new ConfigService({ + CACHE_MODE: 'protected', + CACHE_LOCK_TTL_MS: 1000, + CACHE_TTL_SECONDS: 30, + }); + const service = new MessagesCacheService( + redis as never, + config, + metrics, + ); + await service.getOrLoad('chat', 1n, undefined, 50, async () => page); + await service.getOrLoad('chat', 1n, undefined, 50, async () => page); + expect(metrics.snapshot().counters).toMatchObject({ + cache_miss: 1, + cache_hit: 1, + }); + }); +}); diff --git a/app/src/messages/cache/messages-cache.module.ts b/app/src/messages/cache/messages-cache.module.ts new file mode 100644 index 00000000..f1cfddfe --- /dev/null +++ b/app/src/messages/cache/messages-cache.module.ts @@ -0,0 +1,11 @@ +import { Module } from '@nestjs/common'; +import { MessagesCacheService } from './messages-cache.service.js'; +import { MetricsModule } from '../../metrics/metrics.module.js'; +import { RedisModule } from '../../redis/redis.module.js'; + +@Module({ + imports: [RedisModule, MetricsModule], + providers: [MessagesCacheService], + exports: [MessagesCacheService], +}) +export class MessagesCacheModule {} diff --git a/app/src/messages/cache/messages-cache.service.spec.ts b/app/src/messages/cache/messages-cache.service.spec.ts new file mode 100644 index 00000000..c4053491 --- /dev/null +++ b/app/src/messages/cache/messages-cache.service.spec.ts @@ -0,0 +1,72 @@ +import { ConfigService } from '@nestjs/config'; +import { describe, expect, it, vi } from 'vitest'; +import type { AppConfig } from '../../config/app-config.schema.js'; +import type { RedisClient } from '../../redis/redis.client.js'; +import { MessagesCacheService } from './messages-cache.service.js'; +import { MetricsService } from '../../metrics/metrics.service.js'; + +function serviceWithRedis(redis: Partial): MessagesCacheService { + const config = new ConfigService({ + CACHE_MODE: 'protected', + CACHE_LOCK_TTL_MS: 1000, + CACHE_TTL_SECONDS: 30, + CACHE_MISS_DELAY_MS: 0, + }); + return new MessagesCacheService( + redis as RedisClient, + config, + new MetricsService(), + ); +} + +describe('MessagesCacheService fallback', () => { + it('loads from the authoritative source when Redis read fails', async () => { + const load = vi + .fn() + .mockResolvedValue({ items: [{ id: 'db' }], next_cursor: null }); + const service = serviceWithRedis({ + get: vi.fn().mockRejectedValue(new Error('redis down')), + }); + + await expect( + service.getOrLoad('chat', 1n, undefined, 50, load), + ).resolves.toEqual({ + items: [{ id: 'db' }], + next_cursor: null, + }); + expect(load).toHaveBeenCalledOnce(); + }); + + it('falls back after bounded lock contention', async () => { + const load = vi + .fn() + .mockResolvedValue({ items: [{ id: 'db' }], next_cursor: null }); + const service = serviceWithRedis({ + get: vi.fn().mockResolvedValue(null), + setNxPx: vi.fn().mockResolvedValue(false), + }); + + await expect( + service.getOrLoad('chat', 1n, undefined, 50, load), + ).resolves.toEqual({ + items: [{ id: 'db' }], + next_cursor: null, + }); + expect(load).toHaveBeenCalledOnce(); + }); + + it('returns the authoritative page when cache write fails', async () => { + const page = { items: [{ id: 'db' }], next_cursor: null }; + const load = vi.fn().mockResolvedValue(page); + const service = serviceWithRedis({ + get: vi.fn().mockResolvedValue(null), + setNxPx: vi.fn().mockResolvedValue(true), + set: vi.fn().mockRejectedValue(new Error('redis down')), + unlock: vi.fn().mockResolvedValue(1), + }); + + await expect( + service.getOrLoad('chat', 1n, undefined, 50, load), + ).resolves.toEqual(page); + }); +}); diff --git a/app/src/messages/cache/messages-cache.service.ts b/app/src/messages/cache/messages-cache.service.ts new file mode 100644 index 00000000..565c17c4 --- /dev/null +++ b/app/src/messages/cache/messages-cache.service.ts @@ -0,0 +1,205 @@ +import { Injectable, Logger } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; +import { setTimeout as delay } from 'node:timers/promises'; +import type { AppConfig } from '../../config/app-config.schema.js'; +import { RedisClient } from '../../redis/redis.client.js'; +import type { Page } from '../../common/http/page.js'; +import { MetricsService } from '../../metrics/metrics.service.js'; + +const LOCK_RETRY_COUNT = 4; +const LOCK_RETRY_DELAY_MS = 25; + +export type CachePage = Page; + +@Injectable() +export class MessagesCacheService { + private readonly logger = new Logger(MessagesCacheService.name); + + constructor( + private readonly redis: RedisClient, + private readonly config: ConfigService, + private readonly metrics: MetricsService, + ) {} + + async getOrLoad( + chatId: string, + version: bigint, + cursor: string | undefined, + limit: number, + loader: () => Promise, + ): Promise { + const key = this.cacheKey(chatId, version, cursor, limit); + if (this.config.getOrThrow('CACHE_MODE') === 'naive') { + return this.loadNaively(key, loader); + } + + let cached: string | null; + try { + cached = await this.redis.get(key); + } catch (error) { + return this.fallbackToDatabase('read', error, loader); + } + const cachedPage = this.parsePage(cached); + if (cachedPage) { + this.metrics.increment('cache_hit'); + return cachedPage; + } + this.metrics.increment('cache_miss'); + + const lockKey = `lock:${key}`; + const owner = `${process.pid}:${Math.random().toString(36).slice(2)}`; + for (let attempt = 0; attempt < LOCK_RETRY_COUNT; attempt += 1) { + let locked: boolean; + try { + locked = await this.redis.setNxPx( + lockKey, + owner, + this.config.getOrThrow('CACHE_LOCK_TTL_MS'), + ); + } catch (error) { + return this.fallbackToDatabase('lock', error, loader); + } + if (locked) return this.fillLocked(key, lockKey, owner, loader); + + if (attempt === 0) this.metrics.increment('cache_lock_wait'); + try { + const waitedPage = this.parsePage(await this.redis.get(key)); + if (waitedPage) { + this.metrics.increment('cache_hit'); + return waitedPage; + } + } catch (error) { + return this.fallbackToDatabase('waiting read', error, loader); + } + await delay(LOCK_RETRY_DELAY_MS); + } + + // The owner did not publish the page within the bounded wait: serve the + // authoritative result instead of blocking the request further. + this.metrics.increment('cache_lock_timeout'); + return loader(); + } + + private async fillLocked( + key: string, + lockKey: string, + owner: string, + loader: () => Promise, + ): Promise { + try { + let secondCheck: string | null; + try { + secondCheck = await this.redis.get(key); + } catch (error) { + return this.fallbackToDatabase('double-check', error, loader); + } + const secondPage = this.parsePage(secondCheck); + if (secondPage) { + this.metrics.increment('cache_hit'); + return secondPage; + } + + const page = await loader(); + try { + await this.redis.set(key, JSON.stringify(page), { + EX: this.config.getOrThrow('CACHE_TTL_SECONDS'), + }); + } catch (error) { + // Redis is derived state: the page is still valid for this response, + // but the failure must stay visible in metrics and logs. + this.metrics.increment('cache_write_error'); + this.logger.warn( + `Cache fill failed: ${error instanceof Error ? error.message : 'unknown error'}`, + ); + } + return page; + } finally { + try { + await this.redis.unlock(lockKey, owner); + } catch (error) { + // The lock has a TTL, so a stale lock expires on its own; a successful + // response must not be replaced by an unlock failure. + this.metrics.increment('cache_unlock_error'); + this.logger.warn( + `Cache unlock failed: ${error instanceof Error ? error.message : 'unknown error'}`, + ); + } + } + } + + private cacheKey( + chatId: string, + version: bigint, + cursor: string | undefined, + limit: number, + ): string { + return `messages:${chatId}:v${version.toString()}:c${cursor ?? 'start'}:l${limit}`; + } + + private async loadNaively( + key: string, + loader: () => Promise, + ): Promise { + let cached: string | null; + try { + cached = await this.redis.get(key); + } catch (error) { + return this.fallbackToDatabase('naive read', error, loader); + } + const cachedPage = this.parsePage(cached); + if (cachedPage) { + this.metrics.increment('cache_hit'); + return cachedPage; + } + this.metrics.increment('cache_miss'); + + const cacheMissDelay = this.config.getOrThrow('CACHE_MISS_DELAY_MS'); + if (cacheMissDelay > 0) await delay(cacheMissDelay); + const page = await loader(); + try { + await this.redis.set(key, JSON.stringify(page), { + EX: this.config.getOrThrow('CACHE_TTL_SECONDS'), + }); + } catch (error) { + this.metrics.increment('cache_write_error'); + this.logger.warn( + `Cache fill failed: ${error instanceof Error ? error.message : 'unknown error'}`, + ); + } + return page; + } + + private async fallbackToDatabase( + stage: string, + error: unknown, + loader: () => Promise, + ): Promise { + this.metrics.increment('cache_fallback'); + this.logger.warn( + `Cache ${stage} failed, serving PostgreSQL: ${error instanceof Error ? error.message : 'unknown error'}`, + ); + return loader(); + } + + private parsePage(value: string | null): CachePage | undefined { + if (!value) return undefined; + try { + const parsed: unknown = JSON.parse(value); + if ( + typeof parsed !== 'object' || + parsed === null || + !('items' in parsed) || + !('next_cursor' in parsed) || + !Array.isArray(parsed.items) || + (parsed.next_cursor !== null && + typeof parsed.next_cursor !== 'string') + ) + return undefined; + return { items: parsed.items, next_cursor: parsed.next_cursor }; + } catch { + // A malformed entry is treated as a miss and overwritten by the owner fill. + this.metrics.increment('cache_corrupt_entry'); + return undefined; + } + } +} diff --git a/app/src/messages/dto/create-message.dto.ts b/app/src/messages/dto/create-message.dto.ts new file mode 100644 index 00000000..57e5be26 --- /dev/null +++ b/app/src/messages/dto/create-message.dto.ts @@ -0,0 +1,8 @@ +import { IsString } from 'class-validator'; +import { CodePointLength } from '../../common/validation/code-point-length.js'; + +export class CreateMessageDto { + @IsString() + @CodePointLength(1, 4000) + text!: string; +} diff --git a/app/src/messages/idempotency/idempotency-gc.cli.ts b/app/src/messages/idempotency/idempotency-gc.cli.ts new file mode 100644 index 00000000..7ab0da55 --- /dev/null +++ b/app/src/messages/idempotency/idempotency-gc.cli.ts @@ -0,0 +1,33 @@ +import { fileURLToPath } from 'node:url'; +import { parseAppConfig } from '../../config/app-config.schema.js'; +import { DatabaseClient } from '../../database/database.client.js'; +import { MetricsService } from '../../metrics/metrics.service.js'; +import { IdempotencyRepository } from './idempotency.repository.js'; + +// Manual operator pass over the idempotency ledger: the API also purges expired +// claims in the background, but an operator must be able to reclaim space +// without waiting for traffic. It never touches unexpired claims. +// in the stand: docker compose exec api node dist/messages/idempotency/idempotency-gc.cli.js +// on the host: npm run idempotency:gc (needs a reachable DATABASE_URL) +async function main(): Promise { + const config = parseAppConfig(process.env as Record); + const database = new DatabaseClient( + { + getOrThrow: (key: keyof typeof config) => config[key], + } as never, + new MetricsService(), + ); + try { + const repository = new IdempotencyRepository(database); + const purged = await repository.purgeExpired( + config.IDEMPOTENCY_TTL_SECONDS, + ); + process.stdout.write( + `Purged ${purged} idempotency key(s) older than ${config.IDEMPOTENCY_TTL_SECONDS} seconds\n`, + ); + } finally { + await database.onModuleDestroy(); + } +} + +if (process.argv[1] === fileURLToPath(import.meta.url)) await main(); diff --git a/app/src/messages/idempotency/idempotency.module.ts b/app/src/messages/idempotency/idempotency.module.ts new file mode 100644 index 00000000..33c8a329 --- /dev/null +++ b/app/src/messages/idempotency/idempotency.module.ts @@ -0,0 +1,10 @@ +import { Module } from '@nestjs/common'; +import { DatabaseModule } from '../../database/database.module.js'; +import { IdempotencyRepository } from './idempotency.repository.js'; + +@Module({ + imports: [DatabaseModule], + providers: [IdempotencyRepository], + exports: [IdempotencyRepository], +}) +export class IdempotencyModule {} diff --git a/app/src/messages/idempotency/idempotency.repository.spec.ts b/app/src/messages/idempotency/idempotency.repository.spec.ts new file mode 100644 index 00000000..f6784dca --- /dev/null +++ b/app/src/messages/idempotency/idempotency.repository.spec.ts @@ -0,0 +1,19 @@ +import { describe, expect, it, vi } from 'vitest'; +import { IdempotencyRepository } from './idempotency.repository.js'; + +describe('IdempotencyRepository expired-key cleanup', () => { + it('deletes only rows older than the configured TTL', async () => { + const query = vi.fn().mockResolvedValue({ rowCount: 0, rows: [] }); + const repository = new IdempotencyRepository({ query } as never); + + await repository.forget('user', '/api/v1/chats/chat/messages', 'key', 86400); + + expect(query).toHaveBeenCalledWith( + 'idempotency.forget', + expect.stringContaining( + 'created_at < now() - make_interval(secs => $4::double precision)', + ), + ['user', '/api/v1/chats/chat/messages', 'key', 86400], + ); + }); +}); diff --git a/app/src/messages/idempotency/idempotency.repository.ts b/app/src/messages/idempotency/idempotency.repository.ts new file mode 100644 index 00000000..79ba9f8e --- /dev/null +++ b/app/src/messages/idempotency/idempotency.repository.ts @@ -0,0 +1,119 @@ +import { Injectable } from '@nestjs/common'; +import pg from 'pg'; +import { DatabaseClient } from '../../database/database.client.js'; +import type { Message } from '../message.js'; + +// A committed row always carries the response: the claim and the stored response +// are written by one statement, so there is no poisoned intermediate state to +// re-check at replay time. +export type IdempotencyRecord = { + request_fingerprint: string; + status_code: number; + response_body: Message; + created_at: Date | string; + expired: boolean; + is_member: boolean; +}; + +const PURGE_BATCH_LIMIT = 1000; +const PURGE_BATCHES = 10; + +@Injectable() +export class IdempotencyRepository { + constructor(private readonly database: DatabaseClient) {} + + /** + * Reads the stored result and re-checks access in the same round trip: a + * replay must still prove that the caller may read this chat. + */ + async read( + userId: string, + path: string, + key: string, + chatId: string, + ttlSeconds: number, + ): Promise { + const result = await this.database.query( + 'idempotency.read', + `SELECT k.request_fingerprint, k.status_code, k.response_body, k.created_at, + k.created_at < now() - make_interval(secs => $4::double precision) AS expired, + EXISTS ( + SELECT 1 FROM chat_members WHERE chat_id = $5 AND user_id = $1 + ) AS is_member + FROM idempotency_keys k + WHERE k.user_id = $1 AND k.method = 'POST' AND k.path = $2 AND k.key = $3`, + [userId, path, key, ttlSeconds, chatId], + ); + return result.rows[0]; + } + + async forget( + userId: string, + path: string, + key: string, + ttlSeconds: number, + ): Promise { + await this.database.query( + 'idempotency.forget', + `DELETE FROM idempotency_keys + WHERE user_id = $1 AND method = 'POST' AND path = $2 AND key = $3 + AND created_at < now() - make_interval(secs => $4::double precision)`, + [userId, path, key, ttlSeconds], + ); + } + + async isMember(chatId: string, userId: string): Promise { + const result = await this.database.query<{ is_member: boolean }>( + 'messages.checkMembership', + `SELECT EXISTS ( + SELECT 1 FROM chat_members WHERE chat_id = $1 AND user_id = $2 + ) AS is_member`, + [chatId, userId], + ); + return result.rows[0]?.is_member === true; + } + + /** + * Deletes expired claims in bounded batches. The transaction-scoped advisory + * lock makes the pass single-flight across replicas without risking a lock + * leaking back into the pool with a released connection. Returns the number + * of deleted rows (0 when another replica is purging). + */ + async purgeExpired(ttlSeconds: number): Promise { + const client: pg.PoolClient = await this.database.pool.connect(); + try { + await client.query('BEGIN'); + try { + const lock = await client.query<{ locked: boolean }>( + "SELECT pg_try_advisory_xact_lock(hashtext('idempotency_gc')) AS locked", + ); + if (lock.rows[0]?.locked !== true) { + await client.query('ROLLBACK'); + return 0; + } + let purged = 0; + for (let batch = 0; batch < PURGE_BATCHES; batch += 1) { + const result = await client.query( + `DELETE FROM idempotency_keys + WHERE ctid IN ( + SELECT ctid FROM idempotency_keys + WHERE created_at < now() - make_interval(secs => $1::double precision) + LIMIT ${PURGE_BATCH_LIMIT} + )`, + [ttlSeconds], + ); + const deleted = result.rowCount ?? 0; + purged += deleted; + if (deleted < PURGE_BATCH_LIMIT) break; + } + await client.query('COMMIT'); + return purged; + } catch (error) { + await client.query('ROLLBACK').catch(() => undefined); + throw error; + } + } finally { + client.release(); + } + } +} diff --git a/app/src/messages/idempotency/idempotency.ts b/app/src/messages/idempotency/idempotency.ts new file mode 100644 index 00000000..9c3d0474 --- /dev/null +++ b/app/src/messages/idempotency/idempotency.ts @@ -0,0 +1,18 @@ +import { createHash } from 'node:crypto'; +import type { CreateMessageDto } from '../dto/create-message.dto.js'; + +// Contract: ASCII [A-Za-z0-9._:-]{1,128}. Anything else (including a duplicated +// header, which Fastify joins with ", ") is rejected as a client error. +export const IDEMPOTENCY_KEY_PATTERN = /^[A-Za-z0-9._:-]{1,128}$/; + +export function messagesPath(chatId: string): string { + return `/api/v1/chats/${chatId}/messages`; +} + +// The fingerprint is derived from the validated payload with a fixed field +// order, so neither JSON key order nor an absent optional field can change it. +export function idempotencyFingerprint(input: CreateMessageDto): string { + return createHash('sha256') + .update(JSON.stringify({ text: input.text })) + .digest('hex'); +} diff --git a/app/src/messages/message.ts b/app/src/messages/message.ts new file mode 100644 index 00000000..1fd5bfe8 --- /dev/null +++ b/app/src/messages/message.ts @@ -0,0 +1,7 @@ +export type Message = { + id: string; + chat_id: string; + sender_id: string; + text: string; + created_at: string; +}; diff --git a/app/src/messages/messages.controller.ts b/app/src/messages/messages.controller.ts new file mode 100644 index 00000000..a4fcdb14 --- /dev/null +++ b/app/src/messages/messages.controller.ts @@ -0,0 +1,53 @@ +import { + BadRequestException, + Body, + Controller, + DefaultValuePipe, + Get, + Headers, + Param, + ParseIntPipe, + ParseUUIDPipe, + Post, + Query, + UseGuards, +} from '@nestjs/common'; +import { CurrentUser } from '../common/auth/current-user.decorator.js'; +import { CurrentUserGuard } from '../common/auth/current-user.guard.js'; +import type { User } from '../users/user.js'; +import { CreateMessageDto } from './dto/create-message.dto.js'; +import { MessagesService } from './messages.service.js'; + +@Controller('api/v1/chats/:chatId/messages') +@UseGuards(CurrentUserGuard) +export class MessagesController { + constructor(private readonly messagesService: MessagesService) {} + + @Post() + create( + @Param('chatId', new ParseUUIDPipe()) chatId: string, + @Body() body: CreateMessageDto, + @CurrentUser() currentUser: User, + @Headers('idempotency-key') idempotencyKey?: string | string[], + ) { + return this.messagesService.create( + chatId, + body, + currentUser, + idempotencyKey, + ); + } + + @Get() + list( + @Param('chatId', new ParseUUIDPipe()) chatId: string, + @CurrentUser() currentUser: User, + @Query('limit', new DefaultValuePipe(50), new ParseIntPipe()) + limit: number, + @Query('cursor') cursor?: string, + ) { + if (limit < 1 || limit > 100) + throw new BadRequestException('limit must be between 1 and 100'); + return this.messagesService.list(chatId, currentUser, limit, cursor); + } +} diff --git a/app/src/messages/messages.module.ts b/app/src/messages/messages.module.ts new file mode 100644 index 00000000..df803a01 --- /dev/null +++ b/app/src/messages/messages.module.ts @@ -0,0 +1,26 @@ +import { Module } from '@nestjs/common'; +import { DatabaseModule } from '../database/database.module.js'; +import { ChatsModule } from '../chats/chats.module.js'; +import { MessagesController } from './messages.controller.js'; +import { MessagesRepository } from './messages.repository.js'; +import { MessagesService } from './messages.service.js'; +import { MessagesCacheModule } from './cache/messages-cache.module.js'; +import { IdempotencyModule } from './idempotency/idempotency.module.js'; +import { UsersModule } from '../users/users.module.js'; +import { RedisModule } from '../redis/redis.module.js'; +import { MetricsModule } from '../metrics/metrics.module.js'; + +@Module({ + imports: [ + ChatsModule, + MessagesCacheModule, + IdempotencyModule, + DatabaseModule, + UsersModule, + RedisModule, + MetricsModule, + ], + controllers: [MessagesController], + providers: [MessagesRepository, MessagesService], +}) +export class MessagesModule {} diff --git a/app/src/messages/messages.repository.spec.ts b/app/src/messages/messages.repository.spec.ts new file mode 100644 index 00000000..ff217026 --- /dev/null +++ b/app/src/messages/messages.repository.spec.ts @@ -0,0 +1,47 @@ +import { describe, expect, it, vi } from 'vitest'; +import type { Cursor } from '../common/http/cursor.js'; +import type { Message } from './message.js'; +import { MessagesRepository } from './messages.repository.js'; + +const message = (id: string, created_at: string): Message => ({ + id, + chat_id: 'chat', + sender_id: 'sender', + text: id, + created_at, +}); + +describe('MessagesRepository', () => { + it('uses named SQL history and a keyset cursor', async () => { + const query = vi.fn().mockResolvedValue({ rows: [], rowCount: 0 }); + const repository = new MessagesRepository({ + query, + withTransaction: vi.fn(), + } as never); + const cursor: Cursor = { + scope: 'messages:chat', + created_at: '2026-01-01T00:00:01.000Z', + id: '1', + }; + await repository.findPage('chat', 10, cursor); + expect(query).toHaveBeenCalledWith( + 'messages.history', + expect.stringContaining('(created_at, id) >'), + expect.arrayContaining(['chat', cursor.created_at, cursor.id, 11]), + ); + }); + + it('returns rows in response shape', async () => { + const query = vi + .fn() + .mockResolvedValue({ + rows: [message('1', '2026-01-01T00:00:00.000Z')], + rowCount: 1, + }); + const repository = new MessagesRepository({ query } as never); + await expect(repository.findPage('chat', 1)).resolves.toEqual({ + items: [message('1', '2026-01-01T00:00:00.000Z')], + hasMore: false, + }); + }); +}); diff --git a/app/src/messages/messages.repository.ts b/app/src/messages/messages.repository.ts new file mode 100644 index 00000000..d6673afe --- /dev/null +++ b/app/src/messages/messages.repository.ts @@ -0,0 +1,128 @@ +import { Injectable, NotFoundException } from '@nestjs/common'; +import { randomUUID } from 'node:crypto'; +import { DatabaseClient } from '../database/database.client.js'; +import type { Cursor } from '../common/http/cursor.js'; +import type { Message } from './message.js'; + +type MessageRow = { + id: string; + chat_id: string; + sender_id: string; + text: string; + created_at: Date | string; +}; + +export type CreateOnceRequest = { + userId: string; + chatId: string; + path: string; + key: string; + fingerprint: string; + text: string; +}; + +function toMessage(row: MessageRow): Message { + return { + id: row.id, + chat_id: row.chat_id, + sender_id: row.sender_id, + text: row.text, + created_at: new Date(row.created_at).toISOString(), + }; +} + +// Один оператор делает всё, что нужно пути записи: проверяет членство, занимает +// ключ идемпотентности, вставляет сообщение, увеличивает версию чата (якорь +// инвалидации кэша истории) и сохраняет тело ответа. Атомарность даёт сам +// оператор, поэтому явная транзакция и отдельные round trip'ы не нужны; тело +// ответа строится в SQL и служит единственным источником истины и для первого +// ответа, и для повторов. +// +// Зависимости CTE задают порядок выполнения: claim -> inserted -> bumped. +const CREATE_ONCE_SQL = ` +WITH claim AS ( + INSERT INTO idempotency_keys (user_id, method, path, key, request_fingerprint, + status_code, response_body, message_id) + SELECT $1, 'POST', $2, $3, $4, 201, + jsonb_build_object( + 'id', $5::uuid, + 'chat_id', $7::uuid, + 'sender_id', $1::uuid, + 'text', $6::text, + 'created_at', to_char(date_trunc('milliseconds', now()) AT TIME ZONE 'UTC', + 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"')), + $5::uuid + WHERE EXISTS ( + SELECT 1 FROM chat_members WHERE chat_id = $7::uuid AND user_id = $1 + ) + ON CONFLICT DO NOTHING + RETURNING response_body +), inserted AS ( + INSERT INTO messages (id, chat_id, sender_id, text, created_at) + SELECT $5::uuid, $7::uuid, $1::uuid, $6::text, date_trunc('milliseconds', now()) + FROM claim + RETURNING id +), bumped AS ( + UPDATE chats SET message_version = message_version + 1 + WHERE id = $7::uuid AND EXISTS (SELECT 1 FROM inserted) +) +SELECT response_body FROM claim`; + +@Injectable() +export class MessagesRepository { + constructor(private readonly database: DatabaseClient) {} + + /** + * Returns the created message, or undefined when the key is already taken or + * the caller is not a member of the chat (both leave no side effect). + */ + async createOnce(request: CreateOnceRequest): Promise { + const result = await this.database.query<{ response_body: Message }>( + 'messages.createIdempotent', + CREATE_ONCE_SQL, + [ + request.userId, + request.path, + request.key, + request.fingerprint, + randomUUID(), + request.text, + request.chatId, + ], + ); + return result.rows[0]?.response_body; + } + + async getVersion(chatId: string, userId: string): Promise { + const result = await this.database.query<{ message_version: string }>( + 'messages.version', + 'SELECT c.message_version FROM chats c WHERE c.id = $1 AND EXISTS (SELECT 1 FROM chat_members WHERE chat_id = c.id AND user_id = $2)', + [chatId, userId], + ); + if (!result.rows[0]) throw new NotFoundException(); + return BigInt(result.rows[0].message_version); + } + + async findPage( + chatId: string, + limit: number, + cursor?: Cursor, + ): Promise<{ items: Message[]; hasMore: boolean }> { + const values: unknown[] = [chatId]; + let predicate = ''; + if (cursor) { + values.push(cursor.created_at, cursor.id); + predicate = 'AND (created_at, id) > ($2::timestamptz, $3::uuid)'; + } + values.push(limit + 1); + const result = await this.database.query( + 'messages.history', + `SELECT id, chat_id, sender_id, text, created_at FROM messages WHERE chat_id = $1 ${predicate} ORDER BY created_at, id LIMIT $${values.length}`, + values, + ); + return { + items: result.rows.slice(0, limit).map(toMessage), + hasMore: result.rows.length > limit, + }; + } +} diff --git a/app/src/messages/messages.service.spec.ts b/app/src/messages/messages.service.spec.ts new file mode 100644 index 00000000..6893a2a1 --- /dev/null +++ b/app/src/messages/messages.service.spec.ts @@ -0,0 +1,115 @@ +import { describe, expect, it, vi } from 'vitest'; +import { MessagesService } from './messages.service.js'; +import { idempotencyFingerprint } from './idempotency/idempotency.js'; +import type { Message } from './message.js'; + +type StoredRow = { + request_fingerprint: string; + response_body: Message; + created_at: Date; + expired: boolean; + is_member: boolean; +}; + +function deferred(): { promise: Promise; resolve: () => void } { + let resolve!: () => void; + const promise = new Promise((done) => { + resolve = done; + }); + return { promise, resolve }; +} + +describe('MessagesService idempotency expiry race', () => { + it('does not let a stale expiry decision delete a replacement claim', async () => { + const oldCreatedAt = new Date('2020-01-01T00:00:00.000Z'); + const newMessage: Message = { + id: 'message-new', + chat_id: 'chat', + sender_id: 'user', + text: 'hello', + created_at: '2026-01-01T00:00:00.000Z', + }; + let row: StoredRow | undefined = { + request_fingerprint: idempotencyFingerprint({ text: 'hello' }), + response_body: { + ...newMessage, + id: 'message-old', + text: 'old', + }, + created_at: oldCreatedAt, + expired: true, + is_member: true, + }; + let createCalls = 0; + let readCalls = 0; + let forgetCalls = 0; + let messageWrites = 0; + const bothInitialClaims = deferred(); + const bothInitialReads = deferred(); + const replacementCreated = deferred(); + + const messagesRepository = { + createOnce: vi.fn(async () => { + createCalls += 1; + if (createCalls === 2) bothInitialClaims.resolve(); + if (createCalls <= 2) { + await bothInitialClaims.promise; + return undefined; + } + if (row) return undefined; + messageWrites += 1; + row = { + request_fingerprint: idempotencyFingerprint({ text: 'hello' }), + response_body: newMessage, + created_at: new Date('2026-01-01T00:00:00.000Z'), + expired: false, + is_member: true, + }; + replacementCreated.resolve(); + return newMessage; + }), + }; + const idempotency = { + read: vi.fn(async () => { + readCalls += 1; + if (readCalls === 2) bothInitialReads.resolve(); + if (readCalls <= 2) await bothInitialReads.promise; + return row; + }), + forget: vi.fn(async (...args: unknown[]) => { + forgetCalls += 1; + if (args.length !== 4) { + row = undefined; + return; + } + if (forgetCalls === 2) await replacementCreated.promise; + if (!row || row.created_at >= new Date('2026-01-01T00:00:00.000Z')) return; + row = undefined; + }), + isMember: vi.fn().mockResolvedValue(true), + }; + const makeService = () => + new MessagesService( + messagesRepository as never, + {} as never, + {} as never, + idempotency as never, + { getOrThrow: vi.fn().mockReturnValue(60) } as never, + { increment: vi.fn() } as never, + ); + const input = { text: 'hello' } as never; + const user = { id: 'user' } as never; + + const results = await Promise.all([ + makeService().create('chat', input, user, 'same-key'), + makeService().create('chat', input, user, 'same-key'), + ]); + + expect(results).toEqual([newMessage, newMessage]); + expect(new Set(results.map((message) => message.id))).toEqual( + new Set(['message-new']), + ); + expect(messageWrites).toBe(1); + expect(forgetCalls).toBe(2); + }); +}); diff --git a/app/src/messages/messages.service.ts b/app/src/messages/messages.service.ts new file mode 100644 index 00000000..0777957e --- /dev/null +++ b/app/src/messages/messages.service.ts @@ -0,0 +1,186 @@ +import { + BadRequestException, + ConflictException, + Injectable, + Logger, + NotFoundException, + ServiceUnavailableException, +} from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; +import { decodeCursor, encodeCursor } from '../common/http/cursor.js'; +import type { Page } from '../common/http/page.js'; +import type { AppConfig } from '../config/app-config.schema.js'; +import type { User } from '../users/user.js'; +import { ChatsService } from '../chats/chats.service.js'; +import { MetricsService } from '../metrics/metrics.service.js'; +import type { CreateMessageDto } from './dto/create-message.dto.js'; +import type { Message } from './message.js'; +import { MessagesRepository } from './messages.repository.js'; +import { MessagesCacheService } from './cache/messages-cache.service.js'; +import { + IDEMPOTENCY_KEY_PATTERN, + idempotencyFingerprint, + messagesPath, +} from './idempotency/idempotency.js'; +import { IdempotencyRepository } from './idempotency/idempotency.repository.js'; + +// Один повтор нужен только для просроченного ключа: запись удаляется, и тот же +// оператор занимает ключ заново. Больше трёх кругов означает, что ключ +// перехватывают параллельные запросы, и честнее вернуть 503, чем крутиться. +const MAX_CLAIM_ATTEMPTS = 3; +const PURGE_EVERY_REQUESTS = 512; + +@Injectable() +export class MessagesService { + private readonly logger = new Logger(MessagesService.name); + private requestsSincePurge = 0; + + constructor( + private readonly messagesRepository: MessagesRepository, + private readonly chatsService: ChatsService, + private readonly cache: MessagesCacheService, + private readonly idempotency: IdempotencyRepository, + private readonly config: ConfigService, + private readonly metrics: MetricsService, + ) {} + + async create( + chatId: string, + input: CreateMessageDto, + currentUser: User, + rawKey: string | string[] | undefined, + ): Promise { + // Ключ и тело проверяются до обращения к БД: клиентская ошибка не должна + // создавать заявку и не должна зависеть от состояния хранилища. + if (typeof rawKey !== 'string' || !IDEMPOTENCY_KEY_PATTERN.test(rawKey)) + throw new BadRequestException( + 'Idempotency-Key header is required', + ); + if ([...input.text].every((character) => /\s/u.test(character))) + throw new BadRequestException('Message text cannot be blank'); + + const path = messagesPath(chatId); + const fingerprint = idempotencyFingerprint(input); + const ttl = this.config.getOrThrow('IDEMPOTENCY_TTL_SECONDS'); + for (let attempt = 1; attempt <= MAX_CLAIM_ATTEMPTS; attempt += 1) { + const created = await this.messagesRepository.createOnce({ + userId: currentUser.id, + chatId, + path, + key: rawKey, + fingerprint, + text: input.text, + }); + if (created) { + this.metrics.increment('idempotency.claim'); + this.metrics.increment('messages.write'); + this.scheduleExpiredPurge(); + return created; + } + + const stored = await this.idempotency.read( + currentUser.id, + path, + rawKey, + chatId, + ttl, + ); + if (!stored) { + // Заявки нет: либо запрос не имеет доступа к чату (404), либо + // чужую заявку сняли между нашими двумя запросами (503). + if (!(await this.idempotency.isMember(chatId, currentUser.id))) + throw new NotFoundException(); + this.metrics.increment('idempotency.claim_lost'); + throw new ServiceUnavailableException( + 'Idempotency key could not be claimed', + ); + } + if (stored.expired) { + this.metrics.increment('idempotency.released'); + await this.idempotency.forget( + currentUser.id, + path, + rawKey, + ttl, + ); + continue; + } + if (stored.request_fingerprint !== fingerprint) { + this.metrics.increment('idempotency.conflict'); + throw new ConflictException( + 'Idempotency key reused with a different body', + ); + } + if (!stored.is_member) throw new NotFoundException(); + this.metrics.increment('idempotency.replay'); + return stored.response_body; + } + throw new ServiceUnavailableException( + 'Idempotency key could not be claimed', + ); + } + + // Expired claims are storage hygiene, not part of the request: the pass runs + // outside the request path, at most once per PURGE_EVERY_REQUESTS successful + // writes, and its failure never changes the client's result. + private scheduleExpiredPurge(): void { + this.requestsSincePurge += 1; + if (this.requestsSincePurge < PURGE_EVERY_REQUESTS) return; + this.requestsSincePurge = 0; + const ttl = this.config.getOrThrow('IDEMPOTENCY_TTL_SECONDS'); + void this.idempotency + .purgeExpired(ttl) + .then((purged) => { + if (purged > 0) this.metrics.increment('idempotency.purged'); + }) + .catch((error: unknown) => { + this.metrics.increment('idempotency.purge_error'); + this.logger.warn( + `Idempotency purge failed: ${error instanceof Error ? error.message : 'unknown error'}`, + ); + }); + } + + async list( + chatId: string, + currentUser: User, + limit: number, + cursorValue?: string, + ): Promise> { + await this.chatsService.getForUser(chatId, currentUser); + const scope = `messages:${chatId}`; + const cursor = cursorValue + ? decodeCursor(cursorValue, scope) + : undefined; + const version = await this.messagesRepository.getVersion( + chatId, + currentUser.id, + ); + const page = await this.cache.getOrLoad( + chatId, + version, + cursorValue, + limit, + async () => { + const loaded = await this.messagesRepository.findPage( + chatId, + limit, + cursor, + ); + const lastLoaded = loaded.items.at(-1); + return { + items: loaded.items, + next_cursor: + loaded.hasMore && lastLoaded + ? encodeCursor({ + scope, + created_at: lastLoaded.created_at, + id: lastLoaded.id, + }) + : null, + }; + }, + ); + return page as Page; + } +} diff --git a/app/src/metrics/metrics.controller.ts b/app/src/metrics/metrics.controller.ts new file mode 100644 index 00000000..9c2100d5 --- /dev/null +++ b/app/src/metrics/metrics.controller.ts @@ -0,0 +1,54 @@ +import { + Controller, + Get, + Headers, + HttpCode, + HttpStatus, + Post, + UnauthorizedException, +} from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; +import type { AppConfig } from '../config/app-config.schema.js'; +import { resolveInstanceId } from '../config/instance-id.js'; +import { MetricsService } from './metrics.service.js'; + +@Controller('internal') +export class MetricsController { + private readonly instanceId: string; + private readonly buildId: string; + + constructor( + private readonly config: ConfigService, + private readonly metrics: MetricsService, + ) { + this.instanceId = resolveInstanceId(config); + this.buildId = process.env.BUILD_ID ?? 'unknown'; + } + + @Get('metrics') + get(@Headers('authorization') authorization?: string) { + this.requireToken(authorization); + return { + ...this.metrics.snapshot(), + instance_id: this.instanceId, + build_id: this.buildId, + }; + } + + @Post('metrics/reset') + @HttpCode(HttpStatus.OK) + reset(@Headers('authorization') authorization?: string): { status: 'ok' } { + this.requireToken(authorization); + this.metrics.reset(); + return { status: 'ok' }; + } + + private requireToken(authorization?: string): void { + const token = this.config.get('METRICS_TOKEN'); + if (!token || authorization !== `Bearer ${token}`) + throw new UnauthorizedException({ + message: 'Unauthorized', + challenge: 'Bearer realm="metrics"', + }); + } +} diff --git a/app/src/metrics/metrics.module.ts b/app/src/metrics/metrics.module.ts new file mode 100644 index 00000000..3e945a56 --- /dev/null +++ b/app/src/metrics/metrics.module.ts @@ -0,0 +1,10 @@ +import { Module } from '@nestjs/common'; +import { MetricsController } from './metrics.controller.js'; +import { MetricsService } from './metrics.service.js'; + +@Module({ + controllers: [MetricsController], + providers: [MetricsService], + exports: [MetricsService], +}) +export class MetricsModule {} diff --git a/app/src/metrics/metrics.service.spec.ts b/app/src/metrics/metrics.service.spec.ts new file mode 100644 index 00000000..2b5e5017 --- /dev/null +++ b/app/src/metrics/metrics.service.spec.ts @@ -0,0 +1,62 @@ +import { describe, expect, it } from 'vitest'; +import { MetricsService } from './metrics.service.js'; + +describe('MetricsService', () => { + it('computes nearest-rank percentiles from observed latencies', () => { + const metrics = new MetricsService(); + metrics.increment('cache_hit'); + metrics.increment('cache_hit'); + metrics.observeLatency(30); + metrics.observeLatency(10); + metrics.observeLatency(20); + expect(metrics.snapshot()).toEqual({ + counters: { cache_hit: 2 }, + latency_ms: { + count: 3, + sample_count: 3, + p50: 20, + p95: 30, + p99: 30, + max: 30, + }, + }); + }); + + it('keeps snapshots isolated from callers and later observations', () => { + const metrics = new MetricsService(); + metrics.increment('cache_hit'); + const snapshot = metrics.snapshot(); + snapshot.counters.cache_hit = 99; + metrics.increment('cache_hit'); + expect(metrics.snapshot().counters.cache_hit).toBe(2); + expect(snapshot.latency_ms.count).toBe(0); + }); + + it('bounds retained samples but keeps cumulative count and maximum', () => { + const metrics = new MetricsService(); + metrics.observeLatency(9000); + for (let index = 0; index < 4096; index += 1) + metrics.observeLatency(10); + expect(metrics.snapshot().latency_ms).toEqual({ + count: 4097, + sample_count: 4096, + p50: 10, + p95: 10, + p99: 10, + max: 9000, + }); + }); + + it('ignores invalid latency observations', () => { + const metrics = new MetricsService(); + for (const value of [-1, NaN, Infinity]) metrics.observeLatency(value); + expect(metrics.snapshot().latency_ms).toEqual({ + count: 0, + sample_count: 0, + p50: 0, + p95: 0, + p99: 0, + max: 0, + }); + }); +}); diff --git a/app/src/metrics/metrics.service.ts b/app/src/metrics/metrics.service.ts new file mode 100644 index 00000000..bf54a994 --- /dev/null +++ b/app/src/metrics/metrics.service.ts @@ -0,0 +1,69 @@ +import { Injectable } from '@nestjs/common'; + +const LATENCY_SAMPLE_CAPACITY = 4096; + +type LatencySnapshot = { + count: number; + sample_count: number; + p50: number; + p95: number; + p99: number; + max: number; +}; + +@Injectable() +export class MetricsService { + private readonly counters: Record = {}; + private readonly latencies: number[] = []; + private latencyCount = 0; + private maximumLatency = 0; + private nextSample = 0; + + increment(name: string): void { + this.counters[name] = (this.counters[name] ?? 0) + 1; + } + + observeLatency(milliseconds: number): void { + if (!Number.isFinite(milliseconds) || milliseconds < 0) return; + this.latencyCount += 1; + this.maximumLatency = Math.max(this.maximumLatency, milliseconds); + this.latencies[this.nextSample] = milliseconds; + this.nextSample = (this.nextSample + 1) % LATENCY_SAMPLE_CAPACITY; + } + + snapshot(): { + counters: Record; + latency_ms: LatencySnapshot; + } { + const sorted = [...this.latencies].sort((left, right) => left - right); + return { + counters: { ...this.counters }, + latency_ms: { + count: this.latencyCount, + sample_count: sorted.length, + p50: this.percentile(sorted, 0.5), + p95: this.percentile(sorted, 0.95), + p99: this.percentile(sorted, 0.99), + max: this.maximumLatency, + }, + }; + } + + reset(): void { + for (const name of Object.keys(this.counters)) + delete this.counters[name]; + this.latencies.length = 0; + this.latencyCount = 0; + this.maximumLatency = 0; + this.nextSample = 0; + } + + private percentile(sorted: number[], percentile: number): number { + if (sorted.length === 0) return 0; + const index = Math.min( + sorted.length - 1, + Math.ceil(sorted.length * percentile) - 1, + ); + return sorted[index]; + } +} diff --git a/app/src/redis/redis.client.ts b/app/src/redis/redis.client.ts new file mode 100644 index 00000000..220a6fbc --- /dev/null +++ b/app/src/redis/redis.client.ts @@ -0,0 +1,145 @@ +import { + Injectable, + Logger, + OnModuleDestroy, + OnModuleInit, +} from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; +import { createClient, type RedisClientType } from 'redis'; +import type { AppConfig } from '../config/app-config.schema.js'; +import { MetricsService } from '../metrics/metrics.service.js'; + +const UNLOCK_SCRIPT = + 'if redis.call("get", KEYS[1]) == ARGV[1] then return redis.call("del", KEYS[1]) else return 0 end'; +type Client = RedisClientType; + +@Injectable() +export class RedisClient implements OnModuleInit, OnModuleDestroy { + readonly client: Client; + private readonly logger = new Logger(RedisClient.name); + + constructor( + private readonly config: ConfigService, + private readonly metrics: MetricsService, + ) { + this.client = createClient({ + url: this.config.getOrThrow('REDIS_URL'), + disableOfflineQueue: true, + socket: { + reconnectStrategy: (attempt) => + Math.min(1000 + attempt * 250, 5000), + connectTimeout: 5000, + }, + }) as Client; + // Reconnect failures must be visible; the readiness probe pings Redis. + this.client.on('error', (error: Error) => { + this.metrics.increment('redis.error'); + this.logger.warn(`Redis error: ${error.message}`); + }); + } + + async onModuleInit(): Promise { + await this.client.connect(); + } + + async onModuleDestroy(): Promise { + if (this.client.isOpen) await this.client.quit(); + } + + async health(): Promise { + this.metrics.increment('redis.ping'); + // AbortSignal.timeout ограничивает именно пробу: обычные GET/SET остаются + // без командного таймаута, а замороженный Redis проваливает готовность + // в бюджет, который короче timeout check балансировщика. + const timeout = AbortSignal.timeout( + this.config.getOrThrow('HEALTH_TIMEOUT_MS'), + ); + await this.client.withAbortSignal(timeout).ping(); + } + + async get(key: string): Promise { + this.metrics.increment('redis.get'); + return this.client.get(key); + } + + async set( + key: string, + value: string, + options?: { EX?: number; PX?: number; NX?: boolean }, + ): Promise { + this.metrics.increment('redis.set'); + return this.client.set(key, value, options); + } + + async setNxEx( + key: string, + value: string, + seconds: number, + ): Promise { + this.metrics.increment('redis.set'); + return ( + (await this.client.set(key, value, { NX: true, EX: seconds })) === + 'OK' + ); + } + + async setNxPx( + key: string, + value: string, + milliseconds: number, + ): Promise { + this.metrics.increment('redis.set'); + return ( + (await this.client.set(key, value, { + NX: true, + PX: milliseconds, + })) === 'OK' + ); + } + + async del(key: string): Promise { + this.metrics.increment('redis.del'); + return this.client.del(key); + } + + async incr(key: string): Promise { + this.metrics.increment('redis.incr'); + return this.client.incr(key); + } + + async expire(key: string, seconds: number): Promise { + this.metrics.increment('redis.expire'); + return (await this.client.expire(key, seconds)) === 1; + } + + async scan( + cursor: number, + pattern?: string, + count = 100, + ): Promise<{ cursor: number; keys: string[] }> { + this.metrics.increment('redis.scan'); + const result = await this.client.scan(String(cursor), { + MATCH: pattern, + COUNT: count, + }); + return { cursor: Number(result.cursor), keys: result.keys }; + } + + async unlock(key: string, owner: string): Promise { + this.metrics.increment('redis.unlock'); + return Number( + await this.client.eval(UNLOCK_SCRIPT, { + keys: [key], + arguments: [owner], + }), + ); + } + + pipeline(commands: Array<[string, ...string[]]>): Promise { + this.metrics.increment('redis.pipeline'); + const multi = this.client.multi(); + for (const [command, ...args] of commands) + multi.addCommand([command, ...args]); + return multi.exec(); + } +} diff --git a/app/src/redis/redis.module.ts b/app/src/redis/redis.module.ts new file mode 100644 index 00000000..74464f56 --- /dev/null +++ b/app/src/redis/redis.module.ts @@ -0,0 +1,10 @@ +import { Module } from '@nestjs/common'; +import { MetricsModule } from '../metrics/metrics.module.js'; +import { RedisClient } from './redis.client.js'; + +@Module({ + imports: [MetricsModule], + providers: [RedisClient], + exports: [RedisClient], +}) +export class RedisModule {} diff --git a/app/src/types.d.ts b/app/src/types.d.ts new file mode 100644 index 00000000..6a215a66 --- /dev/null +++ b/app/src/types.d.ts @@ -0,0 +1,7 @@ +import { User } from './users/user.ts'; + +declare module 'fastify' { + interface FastifyRequest { + currentUser?: User; + } +} diff --git a/app/src/users/dto/create-user.dto.ts b/app/src/users/dto/create-user.dto.ts new file mode 100644 index 00000000..8e82f58e --- /dev/null +++ b/app/src/users/dto/create-user.dto.ts @@ -0,0 +1,22 @@ +import { IsString, Matches } from 'class-validator'; +import { CodePointLength } from '../../common/validation/code-point-length.js'; + +export class CreateUserDTO { + @IsString() + @Matches(/^[a-z0-9_]{3,32}$/) + username!: string; + + @IsString() + @CodePointLength(1, 100) + @Matches(/\S/u, { + message: 'display_name must contain a non-whitespace character', + }) + display_name!: string; + + @IsString() + @CodePointLength(12, 128) + @Matches(/\S/u, { + message: 'password must contain a non-whitespace character', + }) + password!: string; +} diff --git a/app/src/users/user.ts b/app/src/users/user.ts new file mode 100644 index 00000000..9c91d9e7 --- /dev/null +++ b/app/src/users/user.ts @@ -0,0 +1,6 @@ +export type User = { + id: string; + username: string; + display_name: string; + created_at: string; +}; diff --git a/app/src/users/users.controller.ts b/app/src/users/users.controller.ts new file mode 100644 index 00000000..1ab8c777 --- /dev/null +++ b/app/src/users/users.controller.ts @@ -0,0 +1,22 @@ +import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common'; +import { CurrentUser } from '../common/auth/current-user.decorator.js'; +import { CurrentUserGuard } from '../common/auth/current-user.guard.js'; +import type { User } from './user.js'; +import { CreateUserDTO } from './dto/create-user.dto.js'; +import { UsersService } from './users.service.js'; + +@Controller('api/v1/users') +export class UsersController { + constructor(private readonly usersService: UsersService) {} + + @Post() + create(@Body() body: CreateUserDTO) { + return this.usersService.create(body); + } + + @Get('/me') + @UseGuards(CurrentUserGuard) + getMe(@CurrentUser() currentUser: User) { + return currentUser; + } +} diff --git a/app/src/users/users.module.ts b/app/src/users/users.module.ts new file mode 100644 index 00000000..55a73289 --- /dev/null +++ b/app/src/users/users.module.ts @@ -0,0 +1,16 @@ +import { Module } from '@nestjs/common'; +import { UsersController } from './users.controller.js'; +import { UsersRepository } from './users.repository.js'; +import { UsersService } from './users.service.js'; +import { CurrentUserGuard } from '../common/auth/current-user.guard.js'; +import { RedisModule } from '../redis/redis.module.js'; +import { MetricsModule } from '../metrics/metrics.module.js'; +import { DatabaseModule } from '../database/database.module.js'; + +@Module({ + imports: [DatabaseModule, RedisModule, MetricsModule], + controllers: [UsersController], + providers: [UsersRepository, UsersService, CurrentUserGuard], + exports: [UsersService, CurrentUserGuard, RedisModule, MetricsModule], +}) +export class UsersModule {} diff --git a/app/src/users/users.repository.ts b/app/src/users/users.repository.ts new file mode 100644 index 00000000..4fbbe865 --- /dev/null +++ b/app/src/users/users.repository.ts @@ -0,0 +1,71 @@ +import { ConflictException, Injectable } from '@nestjs/common'; +import { DatabaseClient } from '../database/database.client.js'; +import type { User } from './user.js'; + +type UserRow = { + id: string; + username: string; + display_name: string; + password_hash: string; + created_at: Date | string; +}; + +function toUser(row: UserRow): User { + return { + id: row.id, + username: row.username, + display_name: row.display_name, + created_at: new Date(row.created_at).toISOString(), + }; +} + +@Injectable() +export class UsersRepository { + constructor(private readonly database: DatabaseClient) {} + + async findById(id: string): Promise { + const result = await this.database.query( + 'users.findById', + 'SELECT id, username, display_name, password_hash, created_at FROM users WHERE id = $1', + [id], + ); + const row = result.rows[0]; + return row ? toUser(row) : undefined; + } + + async findByUsername( + username: string, + ): Promise<(User & { password_hash: string }) | undefined> { + const result = await this.database.query( + 'users.findByUsername', + 'SELECT id, username, display_name, password_hash, created_at FROM users WHERE username = $1', + [username], + ); + const row = result.rows[0]; + return row + ? { ...toUser(row), password_hash: row.password_hash } + : undefined; + } + + async create(user: { + id: string; + username: string; + display_name: string; + password_hash: string; + }): Promise { + try { + const result = await this.database.query( + 'users.insert', + `INSERT INTO users (id, username, display_name, password_hash) + VALUES ($1, $2, $3, $4) + RETURNING id, username, display_name, password_hash, created_at`, + [user.id, user.username, user.display_name, user.password_hash], + ); + return toUser(result.rows[0]); + } catch (error) { + if ((error as { code?: string }).code === '23505') + throw new ConflictException('Username already exists'); + throw error; + } + } +} diff --git a/app/src/users/users.service.ts b/app/src/users/users.service.ts new file mode 100644 index 00000000..e4ac35df --- /dev/null +++ b/app/src/users/users.service.ts @@ -0,0 +1,31 @@ +import { Injectable } from '@nestjs/common'; +import argon2 from 'argon2'; +import { randomUUID } from 'node:crypto'; +import { CreateUserDTO } from './dto/create-user.dto.js'; +import { User } from './user.js'; +import { UsersRepository } from './users.repository.js'; + +@Injectable() +export class UsersService { + constructor(private readonly usersRepository: UsersRepository) {} + + async create(input: CreateUserDTO): Promise { + const passwordHash = await argon2.hash(input.password, { + type: argon2.argon2id, + }); + return this.usersRepository.create({ + id: randomUUID(), + username: input.username, + display_name: input.display_name, + password_hash: passwordHash, + }); + } + + findById(id: string): Promise { + return this.usersRepository.findById(id); + } + + findByUsername(username: string) { + return this.usersRepository.findByUsername(username); + } +} diff --git a/app/test/app.e2e-spec.ts b/app/test/app.e2e-spec.ts new file mode 100644 index 00000000..5d7cedca --- /dev/null +++ b/app/test/app.e2e-spec.ts @@ -0,0 +1,674 @@ +import { afterAll, beforeAll, describe, expect, it } from 'vitest'; +import { randomUUID } from 'node:crypto'; +import { setTimeout as sleep } from 'node:timers/promises'; +import { Pool } from 'pg'; +import { createClient } from 'redis'; +import type { SessionResponse } from '../src/auth/auth.service.js'; +import type { Chat } from '../src/chats/chat.js'; +import type { ApiErrorBody } from '../src/common/errors/api-error.js'; +import type { Page } from '../src/common/http/page.js'; +import type { Message } from '../src/messages/message.js'; +import type { User } from '../src/users/user.js'; + +// The suite is black-box: run it against the compiled application process. +// Vitest sets process.env.BASE_URL itself (Vite base), so the API URL uses its own name. +const baseUrl = (process.env.API_BASE_URL ?? 'http://localhost:8080').replace( + /\/+$/u, + '', +); +const basicChallenge = 'Basic realm="messenger", charset="UTF-8"'; +const bearerChallenge = 'Bearer realm="messenger"'; +const password = 'integration:пароль🔐'; +const runId = randomUUID().replaceAll('-', '').slice(0, 12); +const usernames: string[] = []; +const tokens: string[] = []; +let sequence = 0; +let database: Pool; +let redis: ReturnType; + +type Actor = { user: User; password: string; token: string }; +type HttpResult = { body: T; response: Response }; + +async function http( + path: string, + init: RequestInit = {}, +): Promise> { + const response = await fetch(`${baseUrl}${path}`, init); + const text = await response.text(); + let body: unknown = undefined; + if (text) { + try { + body = JSON.parse(text); + } catch { + body = text; + } + } + return { body: body as T, response }; +} + +function json( + body: unknown, + headers: Record = {}, +): RequestInit { + return { + method: 'POST', + headers: { 'content-type': 'application/json', ...headers }, + body: JSON.stringify(body), + }; +} + +function basic(username: string, secret: string): string { + return `Basic ${Buffer.from(`${username}:${secret}`, 'utf8').toString('base64')}`; +} + +function bearer(token: string): Record { + return { authorization: `Bearer ${token}` }; +} + +function idempotencyKey(): Record { + return { 'idempotency-key': randomUUID().replaceAll('-', '') }; +} + +function messageHeaders(token: string): Record { + return { ...bearer(token), ...idempotencyKey() }; +} + +async function register( + displayName = 'Интеграционный пользователь', + secret = password, +): Promise { + const username = `e2e_${runId}_${sequence++}`.slice(0, 32); + usernames.push(username); + const result = await http( + '/api/v1/users', + json({ username, display_name: displayName, password: secret }), + ); + expect(result.response.status).toBe(201); + return result.body; +} + +async function login(user: User, secret = password): Promise { + const result = await http('/api/v1/auth/sessions', { + method: 'POST', + headers: { authorization: basic(user.username, secret) }, + }); + expect(result.response.status).toBe(201); + tokens.push(result.body.token); + return result.body; +} + +async function actor(displayName?: string): Promise { + const user = await register(displayName); + const session = await login(user); + return { user, password, token: session.token }; +} + +function expectError( + result: HttpResult, + status: number, + code: string, +): void { + expect(result.response.status).toBe(status); + expect(result.body.error.code).toBe(code); + expect(result.body.error.request_id).toBe( + result.response.headers.get('x-request-id'), + ); +} + +describe('HTTP integration contract', () => { + beforeAll(async () => { + database = new Pool({ + connectionString: process.env.DATABASE_URL, + connectionTimeoutMillis: 5000, + }); + redis = createClient({ + url: process.env.REDIS_URL, + socket: { reconnectStrategy: false }, + }); + redis.on('error', () => {}); + await redis.connect(); + }); + + afterAll(async () => { + if (usernames.length) { + await database.query('BEGIN'); + try { + await database.query( + `DELETE FROM messages WHERE sender_id IN (SELECT id FROM users WHERE username = ANY($1::text[]))`, + [usernames], + ); + await database.query( + `DELETE FROM chats WHERE id IN (SELECT chat_id FROM chat_members WHERE user_id IN (SELECT id FROM users WHERE username = ANY($1::text[])))`, + [usernames], + ); + await database.query( + 'DELETE FROM users WHERE username = ANY($1::text[])', + [usernames], + ); + await database.query('COMMIT'); + } catch (error) { + await database.query('ROLLBACK'); + throw error; + } + } + if (redis.isOpen) redis.destroy(); + await database.end(); + }); + + it('serves liveness and requires real session authentication', async () => { + const live = await http<{ status: string }>('/health/live'); + expect(live.response.status).toBe(200); + expect(live.body).toEqual({ status: 'ok' }); + const denied = await http('/api/v1/users/me'); + expectError(denied, 401, 'unauthorized'); + expect(denied.response.headers.get('www-authenticate')).toBe( + bearerChallenge, + ); + }); + + it('measures string lengths in Unicode code points', async () => { + const emoji = '🔐'; + const username = (suffix: string) => + `e2e_${runId}_${suffix}`.slice(0, 32); + const rejected = await http( + '/api/v1/users', + json({ + username: username('cp_short'), + display_name: 'Code points', + password: emoji.repeat(11), + }), + ); + expectError(rejected, 400, 'invalid_request'); + const tooLongPassword = await http( + '/api/v1/users', + json({ + username: username('cp_long'), + display_name: 'Code points', + password: emoji.repeat(129), + }), + ); + expectError(tooLongPassword, 400, 'invalid_request'); + const tooLongName = await http( + '/api/v1/users', + json({ + username: username('cp_name'), + display_name: emoji.repeat(101), + password, + }), + ); + expectError(tooLongName, 400, 'invalid_request'); + + const shortUsername = username('cp_ok'); + usernames.push(shortUsername); + const boundaryPassword = emoji.repeat(12); + const created = await http( + '/api/v1/users', + json({ + username: shortUsername, + display_name: emoji.repeat(100), + password: boundaryPassword, + }), + ); + expect(created.response.status).toBe(201); + expect([...created.body.display_name].length).toBe(100); + // The stored password keeps all 12 code points: authentication works. + const session = await http('/api/v1/auth/sessions', { + method: 'POST', + headers: { + authorization: basic(shortUsername, boundaryPassword), + }, + }); + expect(session.response.status).toBe(201); + tokens.push(session.body.token); + + const longTitleRejected = await http( + '/api/v1/chats', + json( + { title: emoji.repeat(101), member_ids: [created.body.id] }, + bearer(session.body.token), + ), + ); + expectError(longTitleRejected, 400, 'invalid_request'); + const longTitle = await http( + '/api/v1/chats', + json( + { title: emoji.repeat(100), member_ids: [created.body.id] }, + bearer(session.body.token), + ), + ); + expect(longTitle.response.status).toBe(201); + const tooLongText = await http( + `/api/v1/chats/${longTitle.body.id}/messages`, + json({ text: emoji.repeat(4001) }, messageHeaders(session.body.token)), + ); + expectError(tooLongText, 400, 'invalid_request'); + const boundaryText = await http( + `/api/v1/chats/${longTitle.body.id}/messages`, + json({ text: emoji.repeat(4000) }, messageHeaders(session.body.token)), + ); + expect(boundaryText.response.status).toBe(201); + expect([...boundaryText.body.text].length).toBe(4000); + }); + + it('rejects whitespace-only and too-short credentials', async () => { + const username = `e2e_${runId}_${sequence++}`.slice(0, 32); + usernames.push(username); + const cases = [ + { password: ' '.repeat(12), display_name: 'Пользователь' }, + { password: '\t'.repeat(16), display_name: 'Пользователь' }, + { password: 'short-pass', display_name: 'Пользователь' }, + { password, display_name: ' ' }, + ]; + for (const body of cases) { + const result = await http( + '/api/v1/users', + json({ username, ...body }), + ); + expectError(result, 400, 'invalid_request'); + } + const accepted = await http( + '/api/v1/users', + json({ username, display_name: 'Пользователь', password }), + ); + expect(accepted.response.status).toBe(201); + }); + + it('registers, logs in with Unicode/colon password, and challenges malformed Basic', async () => { + const user = await register(); + const session = await login(user); + expect(session.user.id).toBe(user.id); + expect(session.token_type).toBe('Bearer'); + const me = await http('/api/v1/users/me', { + headers: bearer(session.token), + }); + expect(me.response.status).toBe(200); + expect(me.body.id).toBe(user.id); + for (const authorization of [ + 'Basic !!!', + 'Basic YWJj', + 'Bearer nope', + ]) { + const result = await http('/api/v1/auth/sessions', { + method: 'POST', + headers: { authorization }, + }); + expectError(result, 401, 'unauthorized'); + expect(result.response.headers.get('www-authenticate')).toBe( + basicChallenge, + ); + } + const bodyResult = await http('/api/v1/auth/sessions', { + ...json({ unexpected: true }), + headers: { authorization: basic(user.username, password) }, + }); + expectError(bodyResult, 400, 'invalid_request'); + }); + + it('returns conflict for concurrent duplicate registration', async () => { + const username = `e2e_${runId}_race`.slice(0, 32); + usernames.push(username); + const results = await Promise.all([ + http( + '/api/v1/users', + json({ username, display_name: 'Race A', password }), + ), + http( + '/api/v1/users', + json({ username, display_name: 'Race B', password }), + ), + ]); + expect( + results.filter((item) => item.response.status === 201), + 'duplicate registration must create exactly one user', + ).toHaveLength(1); + expect( + results.filter((item) => item.response.status === 409), + 'loser of the race must receive 409, not 500', + ).toHaveLength(1); + // The database unique index is the race-proof guard, so verify its effect. + const persisted = await database.query<{ count: string }>( + 'SELECT count(*)::text AS count FROM users WHERE username = $1', + [username], + ); + expect(persisted.rows[0]?.count).toBe('1'); + }); + + it('uses Bearer only, ignores X-User-Id spoofing, and prevents logout replay', async () => { + const alice = await actor('Алиса'); + const bob = await actor('Боб'); + const spoof = await http('/api/v1/users/me', { + headers: { ...bearer(alice.token), 'x-user-id': bob.user.id }, + }); + expect(spoof.response.status).toBe(200); + expect((spoof.body as unknown as User).id).toBe(alice.user.id); + const basicBusiness = await http('/api/v1/users/me', { + headers: { authorization: basic(alice.user.username, password) }, + }); + expectError(basicBusiness, 401, 'unauthorized'); + expect(basicBusiness.response.headers.get('www-authenticate')).toBe( + bearerChallenge, + ); + const logout = await http('/api/v1/auth/sessions/current', { + method: 'DELETE', + headers: bearer(alice.token), + }); + expect(logout.response.status).toBe(204); + const replay = await http('/api/v1/users/me', { + headers: bearer(alice.token), + }); + expectError(replay, 401, 'unauthorized'); + }); + + it('rejects unknown and duplicate chat members and hides chats from outsiders', async () => { + const alice = await actor(); + const bob = await actor(); + const outsider = await actor(); + const unknown = await http( + '/api/v1/chats', + json( + { title: 'unknown', member_ids: [alice.user.id, randomUUID()] }, + bearer(alice.token), + ), + ); + expectError(unknown, 400, 'invalid_request'); + const leaked = await http(`/api/v1/chats?limit=100`, { + headers: bearer(alice.token), + }); + expect(leaked.response.status).toBe(200); + expect( + (leaked.body as unknown as Page).items.some( + (item) => item.title === 'unknown', + ), + ).toBe(false); + const duplicate = await http( + '/api/v1/chats', + json( + { + title: 'duplicate', + member_ids: [alice.user.id, alice.user.id], + }, + bearer(alice.token), + ), + ); + expectError(duplicate, 400, 'invalid_request'); + const created = await http( + '/api/v1/chats', + json( + { + title: `chat-${runId}`, + member_ids: [alice.user.id, bob.user.id], + }, + bearer(alice.token), + ), + ); + expect(created.response.status).toBe(201); + const hidden = await http( + `/api/v1/chats/${created.body.id}`, + { headers: bearer(outsider.token) }, + ); + expectError(hidden, 404, 'not_found'); + }); + + it('keeps sender server-owned and makes writes visible to a second session', async () => { + const alice = await actor(); + const secondSession = (await login(alice.user)).token; + const chat = await http( + '/api/v1/chats', + json( + { title: `messages-${runId}`, member_ids: [alice.user.id] }, + bearer(alice.token), + ), + ); + expect(chat.response.status).toBe(201); + const blank = await http( + `/api/v1/chats/${chat.body.id}/messages`, + json( + { text: ' \n\t', sender_id: randomUUID() }, + messageHeaders(alice.token), + ), + ); + expectError(blank, 400, 'invalid_request'); + const spoof = await http( + `/api/v1/chats/${chat.body.id}/messages`, + json( + { text: 'hello', sender_id: randomUUID() }, + messageHeaders(alice.token), + ), + ); + expectError(spoof, 400, 'invalid_request'); + await http(`/api/v1/chats/${chat.body.id}/messages?limit=50`, { + headers: bearer(secondSession), + }); + const sent = await http( + `/api/v1/chats/${chat.body.id}/messages`, + json({ text: 'hello' }, messageHeaders(alice.token)), + ); + expect(sent.response.status).toBe(201); + expect(sent.body.sender_id).toBe(alice.user.id); + const page = await http>( + `/api/v1/chats/${chat.body.id}/messages?limit=50`, + { headers: bearer(secondSession) }, + ); + expect(page.response.status).toBe(200); + expect(page.body.items.map((item) => item.id)).toContain(sent.body.id); + }); + + it('validates cursor, limits, malformed JSON, and paginates without repeats', async () => { + const alice = await actor(); + const chat = await http( + '/api/v1/chats', + json( + { title: `pages-${runId}`, member_ids: [alice.user.id] }, + bearer(alice.token), + ), + ); + for (const text of ['one', 'two', 'three']) { + const sent = await http( + `/api/v1/chats/${chat.body.id}/messages`, + json({ text }, messageHeaders(alice.token)), + ); + expect(sent.response.status).toBe(201); + } + const invalidLimit = await http( + `/api/v1/chats/${chat.body.id}/messages?limit=101`, + { headers: bearer(alice.token) }, + ); + expectError(invalidLimit, 400, 'invalid_request'); + const invalidCursor = await http( + `/api/v1/chats/${chat.body.id}/messages?cursor=not-a-cursor`, + { headers: bearer(alice.token) }, + ); + expectError(invalidCursor, 400, 'invalid_request'); + const rolledOver = http( + `/api/v1/chats/${chat.body.id}/messages?cursor=${encodeURIComponent( + Buffer.from( + JSON.stringify({ + scope: `messages:${chat.body.id}`, + created_at: '2026-02-31T00:00:00.000Z', + id: randomUUID(), + }), + 'utf8', + ).toString('base64url'), + )}`, + { headers: bearer(alice.token) }, + ); + expectError(await rolledOver, 400, 'invalid_request'); + const malformed = await http('/api/v1/users', { + method: 'POST', + headers: { 'content-type': 'application/json' }, + body: '{', + }); + expectError(malformed, 400, 'invalid_request'); + const first = await http>( + `/api/v1/chats/${chat.body.id}/messages?limit=2`, + { headers: bearer(alice.token) }, + ); + expect(first.body.items).toHaveLength(2); + const second = await http>( + `/api/v1/chats/${chat.body.id}/messages?limit=2&cursor=${encodeURIComponent(first.body.next_cursor!)}`, + { headers: bearer(alice.token) }, + ); + expect(second.body.items).toHaveLength(1); + expect( + new Set( + [...first.body.items, ...second.body.items].map( + (item) => item.id, + ), + ).size, + ).toBe(3); + }); + + it.skipIf(process.env.SESSION_TTL_SECONDS !== '2')( + 'expires sessions with TTL=2', + async () => { + const user = await register(); + const session = await login(user); + await sleep(2300); + const expired = await http('/api/v1/users/me', { + headers: bearer(session.token), + }); + expectError(expired, 401, 'unauthorized'); + }, + ); +}); + +// lab3: the Idempotency-Key contract of POST /chats/{id}/messages. The suite is +// black-box, so these assertions hold for one replica and for a load-balanced +// fleet alike. +describe('message idempotency', () => { + async function chatFor(token: string, memberIds: string[]): Promise { + const created = await http( + '/api/v1/chats', + json({ title: `idempotency-${runId}`, member_ids: memberIds }, bearer(token)), + ); + expect(created.response.status).toBe(201); + return created.body.id; + } + + async function textsIn(chatId: string, token: string): Promise { + const page = await http>( + `/api/v1/chats/${chatId}/messages?limit=100`, + { headers: bearer(token) }, + ); + expect(page.response.status).toBe(200); + return page.body.items.map((item) => item.text); + } + + it('requires a well-formed Idempotency-Key', async () => { + const alice = await actor(); + const chatId = await chatFor(alice.token, [alice.user.id]); + const path = `/api/v1/chats/${chatId}/messages`; + const missing = await http( + path, + json({ text: 'без ключа' }, bearer(alice.token)), + ); + expectError(missing, 400, 'invalid_request'); + for (const key of ['has space', 'comma,separated', 'x'.repeat(129)]) { + const malformed = await http( + path, + json({ text: 'плохой ключ' }, { ...bearer(alice.token), 'idempotency-key': key }), + ); + expectError(malformed, 400, 'invalid_request'); + } + }); + + it('replays the stored response and conflicts on a different body', async () => { + const alice = await actor(); + const chatId = await chatFor(alice.token, [alice.user.id]); + const path = `/api/v1/chats/${chatId}/messages`; + const key = randomUUID().replaceAll('-', ''); + const headers = { ...bearer(alice.token), 'idempotency-key': key }; + const text = `повтор ${runId}`; + + const first = await http(path, json({ text }, headers)); + expect(first.response.status).toBe(201); + const replayed = await http(path, json({ text }, headers)); + expect(replayed.response.status).toBe(201); + expect(replayed.body).toEqual(first.body); + + const conflict = await http( + path, + json({ text: 'другой body' }, headers), + ); + expectError(conflict, 409, 'conflict'); + + expect(await textsIn(chatId, alice.token)).toEqual([text]); + }); + + it('creates exactly one message for concurrent requests with one key', async () => { + const alice = await actor(); + const chatId = await chatFor(alice.token, [alice.user.id]); + const path = `/api/v1/chats/${chatId}/messages`; + const headers = { ...bearer(alice.token), ...idempotencyKey() }; + const text = `конкурентный повтор ${runId}`; + + const results = await Promise.all( + Array.from({ length: 8 }, () => http(path, json({ text }, headers))), + ); + for (const result of results) expect(result.response.status).toBe(201); + const ids = new Set(results.map((result) => result.body.id)); + expect( + ids.size, + 'one key must resolve to exactly one message across replicas', + ).toBe(1); + expect(await textsIn(chatId, alice.token)).toEqual([text]); + }); + + it('replays a key created by another replica', async () => { + // lab3: повтор с тем же ключом может прийти на любую реплику, поэтому + // проверяем не только сам повтор, но и то, что его обслужила другая реплика + // (иначе тест не отличал бы общий журнал от локального состояния процесса). + const alice = await actor(); + const chatId = await chatFor(alice.token, [alice.user.id]); + const path = `/api/v1/chats/${chatId}/messages`; + const key = randomUUID().replaceAll('-', ''); + const headers = { ...bearer(alice.token), 'idempotency-key': key }; + + const first = await http(path, json({ text: 'переключение реплики' }, headers)); + expect(first.response.status).toBe(201); + const firstInstance = first.response.headers.get('x-instance-id'); + expect(firstInstance).toBeTruthy(); + + let replay = first; + let replayInstance = firstInstance; + for (let attempt = 0; attempt < 12 && replayInstance === firstInstance; attempt += 1) { + replay = await http(path, json({ text: 'переключение реплики' }, headers)); + expect(replay.response.status).toBe(201); + replayInstance = replay.response.headers.get('x-instance-id'); + } + expect( + replayInstance, + 'повтор должен был прийти на другую реплику (round-robin за LB)', + ).not.toBe(firstInstance); + expect(replay.body).toEqual(first.body); + expect(await textsIn(chatId, alice.token)).toEqual(['переключение реплики']); + }); + + it('scopes the key per user and per chat path', async () => { + const alice = await actor(); + const bob = await actor(); + const outsider = await actor(); + const chatId = await chatFor(alice.token, [alice.user.id, bob.user.id]); + const path = `/api/v1/chats/${chatId}/messages`; + const key = randomUUID().replaceAll('-', ''); + const foreignChatId = await chatFor(outsider.token, [outsider.user.id]); + + const denied = await http( + `/api/v1/chats/${foreignChatId}/messages`, + json({ text: 'чужое' }, { ...bearer(alice.token), 'idempotency-key': key }), + ); + expectError(denied, 404, 'not_found'); + + const mine = await http( + path, + json({ text: 'своё' }, { ...bearer(alice.token), 'idempotency-key': key }), + ); + expect(mine.response.status).toBe(201); + const other = await http( + path, + json({ text: 'своё' }, { ...bearer(bob.token), 'idempotency-key': key }), + ); + expect(other.response.status).toBe(201); + expect(other.body.id).not.toBe(mine.body.id); + }); +}); diff --git a/app/test/dependency-failures.e2e-spec.ts b/app/test/dependency-failures.e2e-spec.ts new file mode 100644 index 00000000..fd2a4d88 --- /dev/null +++ b/app/test/dependency-failures.e2e-spec.ts @@ -0,0 +1,799 @@ +import { execFile } from 'node:child_process'; +import { randomUUID } from 'node:crypto'; +import { setTimeout as sleep } from 'node:timers/promises'; +import { fileURLToPath } from 'node:url'; +import { promisify } from 'node:util'; +import { afterAll, beforeAll, describe, expect, it } from 'vitest'; +import type { SessionResponse } from '../src/auth/auth.service.js'; +import type { Chat } from '../src/chats/chat.js'; +import type { ApiErrorBody } from '../src/common/errors/api-error.js'; +import type { Page } from '../src/common/http/page.js'; +import type { Message } from '../src/messages/message.js'; +import type { User } from '../src/users/user.js'; + +// Automated counterpart of the manual Redis/PostgreSQL outage checks. Four +// topologies, because the load balancer probes /health/ready (the same route as +// the container healthcheck): +// 1. Redis outage — shared dependency: every replica turns not-ready, HAProxy +// removes all backends and answers 503 itself, while the replica's own +// readiness stays a bounded API 503 with request_id. +// 2. PostgreSQL outage — same shared-dependency topology, confirmed data and +// the session survive the restart. +// 3. Per-replica PostgreSQL fault — only the selected replica loses its own +// path to the database (temporary pg_hba reject entry for its address plus +// connection termination): that slot leaves rotation, the healthy replica +// keeps serving, and the fault is always undone. +// 4. Pool saturation — a busy shared pool is overload, not a lost dependency: +// the replicas stay in rotation because the probe uses its own connection. +// +// It is opt-in because it needs control over the Docker Compose project: +// make test-dependencies +// cd app && E2E_DEPENDENCY_FAULTS=1 npm run test:dependencies +const enabled = process.env.E2E_DEPENDENCY_FAULTS === '1'; +const baseUrl = (process.env.API_BASE_URL ?? 'http://localhost:8080').replace( + /\/+$/u, + '', +); +const composeDir = + process.env.E2E_COMPOSE_DIR ?? + fileURLToPath(new URL('../..', import.meta.url)); +const composeEnvFile = process.env.E2E_COMPOSE_ENV_FILE ?? '.env'; +const redisService = process.env.E2E_REDIS_SERVICE ?? 'redis'; +const postgresService = process.env.E2E_POSTGRES_SERVICE ?? 'postgres'; +const apiService = process.env.E2E_API_SERVICE ?? 'api'; +const lbStatsUrl = + process.env.E2E_LB_STATS_URL ?? 'http://127.0.0.1:8404/stats;csv'; +// PostgreSQL superuser of the stand (compose.yaml, .env); psql runs over the +// container's local socket, so no password is needed here. +const postgresUser = process.env.E2E_POSTGRES_USER ?? 'messenger'; +const postgresDatabase = process.env.E2E_POSTGRES_DB ?? 'messenger'; +const pgHbaPath = + process.env.E2E_PG_HBA_PATH ?? '/var/lib/postgresql/data/pg_hba.conf'; +const pgHbaBackup = `${pgHbaPath}.lab3-partial-fault.bak`; +const password = 'outage-check:пароль🔐'; +const runId = randomUUID().replaceAll('-', '').slice(0, 12); +// A request that reaches a stopped database waits for the pool connection +// timeout, so every outage step costs up to DATABASE_CONNECTION_TIMEOUT_MS. +const outagedRequestBudgetMs = 180_000; +const slotBudgetMs = 20_000; +const readyReads = 16; +const saturatingWrites = 60; // больше, чем replicas × DATABASE_POOL_MAX (2 × 10) + +const execFileAsync = promisify(execFile); + +type Result = { body: T; text: string; response: Response }; +type ReplicaProbe = { + instanceId: string | null; + requestId: string | null; + status: number; + text: string; +}; +type LbSlot = { addr: string; check: string; name: string; status: string }; + +async function compose(...args: string[]): Promise { + const result = await execFileAsync( + 'docker', + ['compose', '--env-file', composeEnvFile, ...args], + { cwd: composeDir, timeout: 120_000 }, + ); + return result.stdout.trim(); +} + +async function docker(...args: string[]): Promise { + const result = await execFileAsync('docker', args, { + cwd: composeDir, + timeout: 60_000, + }); + return result.stdout.trim(); +} + +async function request( + path: string, + init: RequestInit = {}, +): Promise> { + const response = await fetch(`${baseUrl}${path}`, init); + const text = await response.text(); + // With every backend out of rotation the answer is the LB's own HTML 503, + // so a body is not guaranteed to be JSON (it always is for API answers). + let body: T | undefined; + try { + body = text ? (JSON.parse(text) as T) : undefined; + } catch { + body = undefined; + } + return { body: body as T, text, response }; +} + +function json( + body: unknown, + headers: Record = {}, +): RequestInit { + return { + method: 'POST', + headers: { 'content-type': 'application/json', ...headers }, + body: JSON.stringify(body), + }; +} + +function bearer(token: string): Record { + return { authorization: `Bearer ${token}` }; +} + +// POST messages needs a unique Idempotency-Key in lab3+; outage checks only +// need the write path, not replay semantics. +function messageHeaders(token: string): Record { + return { + ...bearer(token), + 'idempotency-key': randomUUID().replaceAll('-', ''), + }; +} + +function basic(username: string, secret: string): string { + return `Basic ${Buffer.from(`${username}:${secret}`, 'utf8').toString('base64')}`; +} + +// The dependencies recover asynchronously, so readiness is polled instead of +// asserted right after docker compose returns. +async function waitForReadiness( + expected: number, + timeoutMs = 90_000, +): Promise { + const deadline = Date.now() + timeoutMs; + let last: number | string = 'no response'; + for (;;) { + try { + const probe = await request('/health/ready'); + last = probe.response.status; + if (probe.response.status === expected) return; + } catch (error) { + last = error instanceof Error ? error.message : 'request failed'; + } + if (Date.now() > deadline) + throw new Error( + `readiness never became ${expected} within ${timeoutMs}ms (last: ${String(last)})`, + ); + await sleep(250); + } +} + +async function waitFor( + condition: () => Promise, + describe: () => Promise, + timeoutMs: number, +): Promise { + const deadline = Date.now() + timeoutMs; + for (;;) { + if (await condition()) return; + if (Date.now() > deadline) + throw new Error( + `condition not reached within ${timeoutMs}ms: ${await describe()}`, + ); + await sleep(250); + } +} + +function expectBoundedError( + status: number, + text: string, + requestId: string | null, +): void { + expect(status).toBe(503); + const body = JSON.parse(text) as ApiErrorBody; + expect(body.error.code).toBe('unavailable'); + expect(body.error.message).toBe('Service unavailable'); + expect(body.error.request_id).toBe(requestId); + // A bounded error must not leak driver details, SQL text or a stack trace. + expect(text).not.toMatch( + /ECONNREFUSED|ECONNRESET|Connection terminated|pg\.|node_modules|at .*\(.+:\d+:\d+\)/u, + ); +} + +function expectBoundedOutage(result: Result): void { + expectBoundedError( + result.response.status, + result.text, + result.response.headers.get('x-request-id'), + ); +} + +// With every backend out of rotation the last hop is the load balancer itself: +// it answers with its own 503 page, so there is no API error body and no +// X-Instance-Id — the request never reached a replica. +function expectLbOutage(result: Result): void { + expect(result.response.status).toBe(503); + expect(result.response.headers.get('x-instance-id')).toBeNull(); +} + +// What a client sees while a shared dependency is down: either the bounded 503 +// of a replica that is still in rotation (identified by X-Instance-Id), or the +// LB's own 503 once every replica has left rotation. Never a success. +function expectUnavailableThroughLb(result: Result): void { + expect(result.response.status).toBe(503); + if (result.response.headers.get('x-instance-id') === null) return; + expectBoundedOutage(result); +} + +async function historyOf( + chatId: string, + token: string, +): Promise>> { + return request>( + `/api/v1/chats/${chatId}/messages?limit=100`, + { + headers: bearer(token), + }, + ); +} + +async function apiContainers(): Promise { + const stdout = await compose('ps', '-q', apiService); + return stdout + .split('\n') + .map((line) => line.trim()) + .filter((line) => line.length > 0) + .sort(); +} + +async function containerIp(container: string): Promise { + return docker( + 'inspect', + '-f', + '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}', + container, + ); +} + +// The replicas publish no ports, so a single replica is probed from inside its +// own network namespace (loopback). +const probeScript = ` +const params = JSON.parse(process.env.LAB3_PROBE); +const port = process.env.APP_PORT || 8080; +const response = await fetch('http://127.0.0.1:' + port + params.path, { + method: params.method || 'GET', + headers: params.headers || {}, + body: params.body, +}); +const text = await response.text(); +console.log(JSON.stringify({ + status: response.status, + text, + instanceId: response.headers.get('x-instance-id'), + requestId: response.headers.get('x-request-id'), +})); +`; + +type ProbeInit = { + body?: string; + headers?: Record; + method?: string; +}; + +async function probeReplica( + container: string, + path: string, + init: ProbeInit = {}, +): Promise { + const stdout = await docker( + 'exec', + '-e', + `LAB3_PROBE=${JSON.stringify({ path, ...init })}`, + container, + 'node', + '--input-type=module', + '-e', + probeScript, + ); + return JSON.parse(stdout) as ReplicaProbe; +} + +async function waitForReplicaReadiness( + container: string, + expected: number, + timeoutMs: number, +): Promise { + let last = 'no probe'; + await waitFor( + async () => { + try { + const probe = await probeReplica(container, '/health/ready'); + last = `${probe.status} ${probe.text}`; + return probe.status === expected; + } catch (error) { + last = error instanceof Error ? error.message : 'probe failed'; + return false; + } + }, + async () => last, + timeoutMs, + ); +} + +function parseCsvLine(line: string): string[] { + const values: string[] = []; + let current = ''; + let quoted = false; + for (const character of line) { + if (character === '"') quoted = !quoted; + else if (character === ',' && !quoted) { + values.push(current); + current = ''; + } else current += character; + } + values.push(current.replace(/\r$/u, '')); + return values; +} + +// Resolved backend slots of the api backend: the unused slots of the +// server-template have no address and are ignored. +async function lbSlots(): Promise { + const response = await fetch(lbStatsUrl); + const lines = (await response.text()).trim().split('\n'); + const header = parseCsvLine(lines[0].replace(/^#\s*/u, '')).map((name) => + name.trim(), + ); + const column = (name: string): number => header.indexOf(name); + return lines + .slice(1) + .map(parseCsvLine) + .filter( + (columns) => + columns[column('pxname')] === 'api' && + /^api\d+$/u.test(columns[column('svname')] ?? '') && + (columns[column('addr')] ?? '').length > 0, + ) + .map((columns) => ({ + addr: columns[column('addr')], + check: columns[column('check_status')], + name: columns[column('svname')], + status: columns[column('status')], + })); +} + +async function waitForSlot( + predicate: (slots: LbSlot[]) => boolean, + describe: string, + timeoutMs = slotBudgetMs, +): Promise { + let last = 'no stats'; + await waitFor( + async () => { + try { + const slots = await lbSlots(); + last = slots + .map( + (slot) => + `${slot.name}@${slot.addr} ${slot.status}/${slot.check}`, + ) + .join(', '); + return slots.length > 0 && predicate(slots); + } catch (error) { + last = error instanceof Error ? error.message : 'stats failed'; + return false; + } + }, + async () => `${describe} (last: ${last})`, + timeoutMs, + ); + return lbSlots(); +} + +function upSlots(slots: LbSlot[]): LbSlot[] { + return slots.filter((slot) => slot.status === 'UP'); +} + +async function psql(query: string): Promise { + return dockerExecService( + postgresService, + 'psql', + '-U', + postgresUser, + '-d', + postgresDatabase, + '-tA', + '-c', + query, + ); +} + +// docker exec needs a container, while the suite is configured with Compose +// service names, so the container of the service is resolved first. +async function dockerExecService( + service: string, + ...args: string[] +): Promise { + const container = (await compose('ps', '-q', service)) + .split('\n')[0] + ?.trim(); + if (!container) throw new Error(`no container for service ${service}`); + return docker('exec', container, ...args); +} + +// Takes away the replica's own path to PostgreSQL without touching the shared +// database: a reject entry for the replica's address becomes the first matching +// line of pg_hba.conf, so its new connections fail while the server stays up +// for everyone else. The file is rewritten through the existing inode (`cat > +// file`) to preserve the owner and mode the server needs to reload it. +async function applyReplicaDatabaseReject(address: string): Promise { + const script = [ + `test -f ${pgHbaBackup} || cat ${pgHbaPath} > ${pgHbaBackup}`, + `printf 'host all all ${address}/32 reject\\n' > /tmp/lab3-pg-hba`, + `cat ${pgHbaPath} >> /tmp/lab3-pg-hba`, + `cat /tmp/lab3-pg-hba > ${pgHbaPath}`, + 'rm -f /tmp/lab3-pg-hba', + ].join('; '); + await dockerExecService(postgresService, 'sh', '-c', script); + await psql('select pg_reload_conf()'); + await psql( + `select count(pg_terminate_backend(pid)) from pg_stat_activity where client_addr = '${address}'`, + ); +} + +// Idempotent restore: also runs from afterAll, so an assertion that failed +// mid-fault cannot leave the stand rejecting one replica. +async function restoreDatabaseAccess(): Promise { + await dockerExecService( + postgresService, + 'sh', + '-c', + `if [ -f ${pgHbaBackup} ]; then cat ${pgHbaBackup} > ${pgHbaPath}; rm -f ${pgHbaBackup}; fi`, + ); + await psql('select pg_reload_conf()'); +} + +describe.skipIf(!enabled)('dependency outages', () => { + let user: User; + let token: string; + let chat: Chat; + let message: Message; + let replicas: string[]; + + beforeAll(async () => { + await compose('up', '-d'); + await waitForReadiness(200); + const username = `outage_${runId}`; + const registered = await request( + '/api/v1/users', + json({ username, display_name: 'Отказ зависимости', password }), + ); + expect(registered.response.status).toBe(201); + user = registered.body; + const session = await request( + '/api/v1/auth/sessions', + { + method: 'POST', + headers: { authorization: basic(username, password) }, + }, + ); + expect(session.response.status).toBe(201); + token = session.body.token; + const created = await request( + '/api/v1/chats', + json( + { title: `outage-${runId}`, member_ids: [user.id] }, + bearer(token), + ), + ); + expect(created.response.status).toBe(201); + chat = created.body; + const sent = await request( + `/api/v1/chats/${chat.id}/messages`, + json({ text: 'Сообщение до отказа' }, messageHeaders(token)), + ); + expect(sent.response.status).toBe(201); + message = sent.body; + replicas = await apiContainers(); + expect(replicas.length).toBeGreaterThanOrEqual(2); + await waitForSlot( + (slots) => upSlots(slots).length === replicas.length, + 'not every replica is UP', + 30_000, + ); + }, outagedRequestBudgetMs); + + afterAll(async () => { + // Always restore the stand, even when an assertion failed mid-outage: + // first the services (pg_hba is only reachable in a running container), + // then the temporary per-replica rule, then rotation. + await compose('start', redisService); + await compose('start', postgresService); + await waitForReadiness(200); + await restoreDatabaseAccess(); + const expected = (await apiContainers()).length; + await waitForSlot( + (slots) => upSlots(slots).length === expected, + 'backends did not return to rotation', + 30_000, + ); + }, outagedRequestBudgetMs); + + it( + 'keeps every replica in rotation while the database pool is saturated', + async () => { + // A row lock on the chat parks every write in the shared pool; the + // readiness probe uses its own connection and must keep answering. + const lock = psql( + `begin; select id from chats where id = '${chat.id}' for update; select pg_sleep(4); commit;`, + ); + await sleep(300); + const statuses = new Set(); + let sampling = true; + const sampler = (async () => { + while (sampling) { + for (const slot of await lbSlots()) statuses.add(slot.status); + await sleep(200); + } + })(); + const writes = await Promise.all( + Array.from({ length: saturatingWrites }, () => + request( + `/api/v1/chats/${chat.id}/messages`, + json({ text: 'saturation' }, messageHeaders(token)), + ), + ), + ); + await lock; + await sleep(1000); + sampling = false; + await sampler; + expect([...statuses]).toEqual(['UP']); + expect( + writes + .map((write) => write.response.status) + .filter((status) => status !== 201), + ).toEqual([]); + }, + outagedRequestBudgetMs, + ); + + it( + 'serves bounded 503 for the Redis outage and recovers the session', + async () => { + await compose('stop', redisService); + const replica = replicas[0]; + + expect((await probeReplica(replica, '/health/live')).status).toBe( + 200, + ); + await waitForReplicaReadiness(replica, 503, 30_000); + const readiness = await probeReplica(replica, '/health/ready'); + expectBoundedError( + readiness.status, + readiness.text, + readiness.requestId, + ); + + const me = await probeReplica(replica, '/api/v1/users/me', { + headers: bearer(token), + }); + expectBoundedError(me.status, me.text, me.requestId); + + // A request without a session must stay unauthorized during an outage: + // the outage may not turn an anonymous caller into a trusted one. + const anonymous = await probeReplica(replica, '/api/v1/chats', { + headers: { 'x-user-id': user.id }, + }); + expect(anonymous.status).toBe(401); + expect( + (JSON.parse(anonymous.text) as ApiErrorBody).error.code, + ).toBe('unauthorized'); + + expectUnavailableThroughLb( + await request('/api/v1/users/me', { + headers: bearer(token), + }), + ); + await waitForSlot( + // 'UP 1/2' is still in rotation: wait for DOWN itself. + (slots) => slots.every((slot) => slot.status === 'DOWN'), + 'not every slot left rotation', + ); + expectLbOutage( + await request('/api/v1/users/me', { headers: bearer(token) }), + ); + + await compose('start', redisService); + await waitForReadiness(200); + await waitForSlot( + (slots) => upSlots(slots).length === replicas.length, + 'backends did not return to rotation', + 30_000, + ); + + // Sessions live in Redis with persistence, so the old token still works. + const recovered = await request('/api/v1/users/me', { + headers: bearer(token), + }); + expect(recovered.response.status).toBe(200); + expect(recovered.body.id).toBe(user.id); + + const history = await historyOf(chat.id, token); + expect(history.response.status).toBe(200); + expect(history.body.items.map((item) => item.id)).toContain( + message.id, + ); + }, + outagedRequestBudgetMs, + ); + + it( + 'serves bounded 503 for the PostgreSQL outage and keeps confirmed data', + async () => { + await compose('stop', postgresService); + const replica = replicas[0]; + + expect((await probeReplica(replica, '/health/live')).status).toBe( + 200, + ); + await waitForReplicaReadiness(replica, 503, 30_000); + const readiness = await probeReplica(replica, '/health/ready'); + expectBoundedError( + readiness.status, + readiness.text, + readiness.requestId, + ); + + // Redis still answers, so these requests reach the database layer and + // must fail with the bounded 503, not an unhandled 500. + const me = await probeReplica(replica, '/api/v1/users/me', { + headers: bearer(token), + }); + expectBoundedError(me.status, me.text, me.requestId); + + const chats = await probeReplica(replica, '/api/v1/chats', { + headers: bearer(token), + }); + expectBoundedError(chats.status, chats.text, chats.requestId); + + const history = await probeReplica( + replica, + `/api/v1/chats/${chat.id}/messages?limit=100`, + { headers: bearer(token) }, + ); + expectBoundedError(history.status, history.text, history.requestId); + + const registration = await probeReplica(replica, '/api/v1/users', { + method: 'POST', + headers: { 'content-type': 'application/json' }, + body: JSON.stringify({ + username: `outage_${runId}_late`, + display_name: 'Отказ зависимости', + password, + }), + }); + expectBoundedError( + registration.status, + registration.text, + registration.requestId, + ); + + expectUnavailableThroughLb( + await request('/api/v1/users/me', { + headers: bearer(token), + }), + ); + await waitForSlot( + // 'UP 1/2' is still in rotation: wait for DOWN itself. + (slots) => slots.every((slot) => slot.status === 'DOWN'), + 'not every slot left rotation', + ); + expectLbOutage( + await request('/api/v1/users/me', { headers: bearer(token) }), + ); + + await compose('start', postgresService); + await waitForReadiness(200); + await waitForSlot( + (slots) => upSlots(slots).length === replicas.length, + 'backends did not return to rotation', + 30_000, + ); + + const recovered = await request('/api/v1/users/me', { + headers: bearer(token), + }); + expect(recovered.response.status).toBe(200); + expect(recovered.body.id).toBe(user.id); + + const after = await historyOf(chat.id, token); + expect(after.response.status).toBe(200); + expect(after.body.items.map((item) => item.id)).toContain( + message.id, + ); + + const sent = await request( + `/api/v1/chats/${chat.id}/messages`, + json({ text: 'Сообщение после отказа' }, messageHeaders(token)), + ); + expect(sent.response.status).toBe(201); + }, + outagedRequestBudgetMs, + ); + + it( + 'excludes only the replica that lost its own database path', + async () => { + const selected = replicas[0]; + const healthy = replicas[1]; + const selectedIp = await containerIp(selected); + const selectedAddress = `${selectedIp}:8080`; + const selectedInstance = ( + await probeReplica(selected, '/health/live') + ).instanceId; + expect(selectedInstance).not.toBeNull(); + const healthyInstance = ( + await probeReplica(healthy, '/health/live') + ).instanceId; + + try { + await applyReplicaDatabaseReject(selectedIp); + const faultAt = Date.now(); + + await waitForReplicaReadiness(selected, 503, 30_000); + expect( + (await probeReplica(healthy, '/health/ready')).status, + ).toBe(200); + + // Only the affected slot leaves rotation. While `fall 2` counts the + // failed checks the slot passes through "UP 1/2 (L7STS)", so the + // wait is for DOWN itself, not for "no longer plain UP". + const slots = await waitForSlot( + (candidates) => + upSlots(candidates).length === replicas.length - 1 && + candidates.some( + (slot) => + slot.addr === selectedAddress && + slot.status === 'DOWN', + ), + `selected slot ${selectedAddress} did not go down`, + 30_000, + ); + // inter 500 ms × fall 2 + timeout check 500 ms + polling step 250 ms. + expect(Date.now() - faultAt).toBeLessThan(3_000); + expect( + slots.find((slot) => slot.addr === selectedAddress)?.status, + ).toBe('DOWN'); + + const served = new Set(); + for (let index = 0; index < readyReads; index += 1) { + const read = await historyOf(chat.id, token); + expect(read.response.status).toBe(200); + served.add( + read.response.headers.get('x-instance-id') ?? 'unknown', + ); + } + expect(served.has(selectedInstance as string)).toBe(false); + expect(served.has(healthyInstance as string)).toBe(true); + } finally { + await restoreDatabaseAccess(); + } + + await waitForReplicaReadiness(selected, 200, 30_000); + await waitForSlot( + (slots) => + upSlots(slots).length === replicas.length && + slots.some( + (slot) => + slot.addr === selectedAddress && + slot.status === 'UP', + ), + 'restored replica did not return to rotation', + 30_000, + ); + + let servedAgain = false; + for ( + let index = 0; + index < readyReads * 2 && !servedAgain; + index += 1 + ) { + const read = await historyOf(chat.id, token); + expect(read.response.status).toBe(200); + servedAgain = + read.response.headers.get('x-instance-id') === + selectedInstance; + } + expect(servedAgain).toBe(true); + }, + outagedRequestBudgetMs, + ); +}); diff --git a/app/tsconfig.build.json b/app/tsconfig.build.json new file mode 100644 index 00000000..2eafee0e --- /dev/null +++ b/app/tsconfig.build.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "rootDir": "./src" + }, + "include": ["src"], + "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] +} diff --git a/app/tsconfig.json b/app/tsconfig.json new file mode 100644 index 00000000..8109c41f --- /dev/null +++ b/app/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "nodenext", + "moduleResolution": "nodenext", + "resolvePackageJsonExports": true, + "esModuleInterop": true, + "isolatedModules": true, + "declaration": true, + "removeComments": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "allowSyntheticDefaultImports": true, + "target": "ES2023", + "sourceMap": true, + "outDir": "./dist", + "incremental": true, + "skipLibCheck": true, + "strict": true, + "strictPropertyInitialization": false, + "types": ["vitest/globals", "node"] + } +} diff --git a/app/vitest.config.e2e.ts b/app/vitest.config.e2e.ts new file mode 100644 index 00000000..a7d63173 --- /dev/null +++ b/app/vitest.config.e2e.ts @@ -0,0 +1,14 @@ +import { defineConfig } from 'vitest/config'; +import tsconfigPaths from 'vite-tsconfig-paths'; + +export default defineConfig({ + plugins: [tsconfigPaths()], + test: { + globals: true, + root: './', + include: ['test/*.e2e-spec.ts'], + testTimeout: 30_000, + hookTimeout: 30_000, + sequence: { concurrent: false }, + }, +}); diff --git a/app/vitest.config.ts b/app/vitest.config.ts new file mode 100644 index 00000000..9384f47b --- /dev/null +++ b/app/vitest.config.ts @@ -0,0 +1,13 @@ +import { defineConfig } from 'vitest/config'; +import tsconfigPaths from 'vite-tsconfig-paths'; + +export default defineConfig({ + // Resolves the path aliases declared in tsconfig.json, including the ones + // added by `nest g library`. + plugins: [tsconfigPaths()], + test: { + globals: true, + root: './', + include: ['**/*.spec.ts'], + }, +}); diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 00000000..139d436b --- /dev/null +++ b/compose.yaml @@ -0,0 +1,227 @@ +# Стенд lab4: клиент -> HAProxy -> API x N -> PostgreSQL + Redis + MinIO. +# Одна команда запуска: make stand-up (docker compose --env-file .env up -d --build --wait) +# +# Проект запинен именем, чтобы имена контейнеров и labels были предсказуемы для +# scripts/stop-one.sh; container_name нигде не задан, иначе масштабирование +# одного Compose-service стало бы невозможным. +name: mtusi-lab4 + +services: + postgres: + image: postgres:16.4-alpine + # pg_stat_statements включён для трека 1 (агрегаты SQL по репликам); + # max_connections поднят под N x DATABASE_POOL_MAX. + command: + [ + 'postgres', + '-c', + 'shared_preload_libraries=pg_stat_statements', + '-c', + 'max_connections=120', + '-c', + 'shared_buffers=128MB', + '-c', + 'effective_cache_size=384MB', + ] + environment: + POSTGRES_DB: ${POSTGRES_DB:-messenger} + POSTGRES_USER: ${POSTGRES_USER:-messenger} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env} + # Только loopback: операторские проверки (host-side npm run test:e2e, + # psql в evidence). API-реплики портов не публикуют вовсе. + ports: + - '127.0.0.1:${POSTGRES_PUBLISHED_PORT:-5432}:5432' + volumes: + - postgres-data:/var/lib/postgresql/data + deploy: + resources: + limits: + cpus: '${PG_CPUS:-1.5}' + memory: ${PG_MEMORY:-512m} + healthcheck: + test: + [ + 'CMD-SHELL', + 'pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}', + ] + interval: 5s + timeout: 3s + retries: 20 + + redis: + image: redis:7.4.2-alpine + # appendonly: сессии и кэш переживают рестарт контейнера (проверка + # сохранности с неизменным токеном). volatile-lru вытесняет только + # ключи с TTL; в стенде у них ограниченный набор и объём. + command: + [ + 'redis-server', + '--appendonly', + 'yes', + '--appendfsync', + 'everysec', + '--maxmemory', + '96mb', + '--maxmemory-policy', + 'volatile-lru', + ] + ports: + - '127.0.0.1:${REDIS_PUBLISHED_PORT:-6379}:6379' + volumes: + - redis-data:/data + deploy: + resources: + limits: + cpus: '${REDIS_CPUS:-0.25}' + memory: ${REDIS_MEMORY:-128m} + healthcheck: + test: ['CMD', 'redis-cli', 'ping'] + interval: 5s + timeout: 3s + retries: 20 + + s3: + image: minio/minio:RELEASE.2025-09-07T16-13-09Z@sha256:14cea493d9a34af32f524e538b8346cf79f3321eff8e708c1e2960462bd8936e + command: ['server', '/data', '--address', ':9000'] + environment: + MINIO_ROOT_USER_FILE: minio_root_user + MINIO_ROOT_PASSWORD_FILE: minio_root_password + MINIO_BROWSER: 'off' + secrets: [minio_root_user, minio_root_password] + # Консольный порт 9001 не публикуется, консоль отключена (MINIO_BROWSER=off). + ports: + - '${S3_PUBLIC_BIND:-127.0.0.1}:${S3_PUBLIC_PORT:-9000}:9000' + volumes: + - s3-data:/data + deploy: + resources: + limits: + cpus: '${S3_CPUS:-1.0}' + memory: ${S3_MEMORY:-512m} + healthcheck: + test: ['CMD', 'mc', 'ready', 'local'] + interval: 5s + timeout: 3s + retries: 20 + + # Идемпотентный bootstrap: bucket, политика, пользователь API. + s3-init: + image: minio/mc:RELEASE.2025-08-13T08-35-41Z@sha256:a7fe349ef4bd8521fb8497f55c6042871b2ae640607cf99d9bede5e9bdf11727 + entrypoint: ['/bin/sh', '/bootstrap/bootstrap.sh'] + environment: + S3_BUCKET: '${S3_BUCKET:-messenger-attachments}' + volumes: + - ./infra/minio:/bootstrap:ro + secrets: + - minio_root_user + - minio_root_password + - s3_api_access_key_id + - s3_api_secret_access_key + depends_on: + s3: { condition: service_healthy } + restart: 'no' + deploy: + resources: + limits: + cpus: '0.25' + memory: 128m + + # Миграции выполняются один раз отдельным сервисом, а не гонкой реплик: + # api стартует только после его успешного завершения. + migrate: + build: + context: . + dockerfile: Dockerfile + image: ${API_IMAGE:-mtusi-messenger:lab4} + command: ['node', 'dist/database/migration.runner.js'] + env_file: [.env] + deploy: + resources: + limits: + cpus: '0.5' + memory: 192m + depends_on: + postgres: { condition: service_healthy } + redis: { condition: service_healthy } + restart: 'no' + + api: + build: + context: . + dockerfile: Dockerfile + args: + BUILD_ID: ${BUILD_ID:-unknown} + image: ${API_IMAGE:-mtusi-messenger:lab4} + # Портов нет намеренно: единственная точка входа — HAProxy. + env_file: [.env] + environment: + DATABASE_POOL_MAX: ${DATABASE_POOL_MAX:-10} + CACHE_MODE: ${CACHE_MODE:-protected} + CACHE_MISS_DELAY_MS: ${CACHE_MISS_DELAY_MS:-0} + SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} + # Бюджет пробы готовности; LB проверяет ту же ручку с timeout check 500 ms. + HEALTH_TIMEOUT_MS: ${HEALTH_TIMEOUT_MS:-400} + # Дрейн длиннее обнаружения отказа LB (500 ms x fall 2 ≈ 1 s). + DRAIN_DELAY_MS: ${DRAIN_DELAY_MS:-3000} + S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_api_access_key_id + S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_api_secret_access_key + UPLOAD_TIMEOUT_MS: ${UPLOAD_TIMEOUT_MS:-25000} + DIRECT_UPLOAD_URL_TTL_SECONDS: ${DIRECT_UPLOAD_URL_TTL_SECONDS:-300} + ATTACHMENT_SWEEP_GRACE_SECONDS: ${ATTACHMENT_SWEEP_GRACE_SECONDS:-900} + ATTACHMENT_SWEEP_INTERVAL_MS: ${ATTACHMENT_SWEEP_INTERVAL_MS:-60000} + secrets: [s3_api_access_key_id, s3_api_secret_access_key] + # Корневая ФС только для чтения: локального файла оригинала на API нет. + read_only: true + tmpfs: ['/tmp:size=16m'] + deploy: + replicas: ${API_REPLICAS:-2} + resources: + limits: + cpus: '${API_CPUS_PER_REPLICA:-1.5}' + memory: ${API_MEMORY_PER_REPLICA:-768m} + stop_grace_period: 20s + restart: unless-stopped + depends_on: + migrate: { condition: service_completed_successfully } + postgres: { condition: service_healthy } + redis: { condition: service_healthy } + s3-init: { condition: service_completed_successfully } + healthcheck: + test: + [ + 'CMD', + 'node', + '-e', + "fetch('http://127.0.0.1:'+ (process.env.APP_PORT||8080) + '/health/ready').then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))", + ] + interval: 5s + timeout: 3s + retries: 20 + + haproxy: + image: haproxy:3.2-alpine + ports: + - '${APP_PUBLIC_PORT:-8080}:8080' + # Страница статистики — интерфейс LB, публикуется только на loopback. + - '127.0.0.1:${LB_STATS_PORT:-8404}:8404' + volumes: + - ./infra/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro + deploy: + resources: + limits: + cpus: '${LB_CPUS:-0.25}' + memory: ${LB_MEMORY:-128m} + depends_on: + api: { condition: service_healthy } + + +secrets: + minio_root_user: { file: ./secrets/minio_root_user } + minio_root_password: { file: ./secrets/minio_root_password } + s3_api_access_key_id: { file: ./secrets/s3_api_access_key_id } + s3_api_secret_access_key: { file: ./secrets/s3_api_secret_access_key } + +volumes: + postgres-data: + redis-data: + s3-data: diff --git a/evidence/lab4/bootstrap-rerun.txt b/evidence/lab4/bootstrap-rerun.txt new file mode 100644 index 00000000..2fdd01c4 --- /dev/null +++ b/evidence/lab4/bootstrap-rerun.txt @@ -0,0 +1,12 @@ +Bucket created successfully `stand/messenger-attachments`. +Access permission for `stand/messenger-attachments` is set to `private` +Created policy `messenger-api` successfully. +Added user `api-` successfully. +Attached Policies: [messenger-api] +To User: api- +bootstrap ok: bucket=messenger-attachments policy=messenger-api +Bucket created successfully `stand/messenger-attachments`. +Access permission for `stand/messenger-attachments` is set to `private` +Created policy `messenger-api` successfully. +Added user `api-` successfully. +bootstrap ok: bucket=messenger-attachments policy=messenger-api diff --git a/infra/haproxy/haproxy.cfg b/infra/haproxy/haproxy.cfg new file mode 100644 index 00000000..a31e1f7c --- /dev/null +++ b/infra/haproxy/haproxy.cfg @@ -0,0 +1,61 @@ +# HAProxy — единственная точка входа lab4. +# +# Проверка готовности backend: GET /health/ready — та же ручка, что у +# healthcheck контейнера. Реплика, потерявшая обязательную зависимость (свой +# путь к общей БД или Redis), исключается из ротации, и трафик уходит на +# здоровые; при отказе общей зависимости неготовыми становятся все реплики, и +# клиент получает 503 от балансировщика — это честный признак того, что +# готовых узлов нет. +# Проба с зависимостями ограничена на стороне API: бюджет пробы 400 ms (общий +# дедлайн /health/ready, проверка БД — по отдельному соединению, не из общего +# пула) меньше timeout check 500 ms, который равен интервалу inter. Обнаружение +# отказа (inter 500 ms × fall 2 ≈ 1 s) короче окна дреина API +# (DRAIN_DELAY_MS=3000): узел уходит из ротации раньше, чем перестаёт +# обслуживать. +# +# Реплики не перечислены статически: server-template + DNS Docker обновляет +# список адресов при масштабировании (init-addr none — стартовать без адресов +# и дождаться DNS, а не падать при пустом ответе). + +global + maxconn 8192 + log stdout format raw local0 + +defaults + mode http + option httplog + timeout connect 500ms + timeout client 35s + timeout server 30s + timeout queue 2s + retries 3 + option redispatch + retry-on conn-failure + +resolvers docker + nameserver dns1 127.0.0.11:53 + resolve_retries 3 + timeout resolve 1s + timeout retry 1s + hold valid 500ms + hold nx 500ms + hold other 1s + +frontend http + bind *:8080 + default_backend api + +backend api + balance roundrobin + option httpchk GET /health/ready + http-check expect status 200 + timeout check 500ms + default-server check inter 500ms fastinter 250ms downinter 1s fall 2 rise 2 maxconn 200 + server-template api 1-8 api:8080 resolvers docker init-addr none + +listen stats + bind *:8404 + stats enable + stats uri /stats + stats refresh 1s + stats show-legends diff --git a/infra/minio/bootstrap.sh b/infra/minio/bootstrap.sh new file mode 100755 index 00000000..17baad98 --- /dev/null +++ b/infra/minio/bootstrap.sh @@ -0,0 +1,28 @@ +#!/bin/sh +# Идемпотентная инициализация MinIO: приватный bucket, ограниченная политика и +# отдельный пользователь API. Выполняется в контейнере minio/mc. +set -eu + +IFS= read -r root_user < /run/secrets/minio_root_user || [ -n "$root_user" ] +IFS= read -r root_password < /run/secrets/minio_root_password || [ -n "$root_password" ] +IFS= read -r api_key < /run/secrets/s3_api_access_key_id || [ -n "$api_key" ] +IFS= read -r api_secret < /run/secrets/s3_api_secret_access_key || [ -n "$api_secret" ] +bucket="${S3_BUCKET:?}" + +export MC_CONFIG_DIR=/tmp/.mc +export MC_HOST_stand="http://${root_user}:${root_password}@s3:9000" + +mc mb --ignore-existing "stand/$bucket" +mc anonymous set none "stand/$bucket" + +printf '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["s3:GetObject","s3:PutObject","s3:DeleteObject"],"Resource":["arn:aws:s3:::%s/attachments/*"]},{"Effect":"Allow","Action":["s3:ListBucket"],"Resource":["arn:aws:s3:::%s"]}]}' "$bucket" "$bucket" > /tmp/messenger-api-policy.json +mc admin policy create stand messenger-api /tmp/messenger-api-policy.json + +mc admin user add stand "$api_key" "$api_secret" +info=$(mc admin user info stand "$api_key" --json) +case "$info" in +*'"messenger-api"'*) ;; +*) mc admin policy attach stand messenger-api --user "$api_key" ;; +esac + +echo "bootstrap ok: bucket=$bucket policy=messenger-api" diff --git a/scripts/app-e2e.sh b/scripts/app-e2e.sh new file mode 100755 index 00000000..3931d1c0 --- /dev/null +++ b/scripts/app-e2e.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# Black-box набор приложения (app/test/*.e2e-spec.ts) против поднятого стенда. +# Требует loopback-портов PostgreSQL, Redis и MinIO из compose.yaml. +set -eu + +env_file="${COMPOSE_ENV_FILE:-.env}" +compose_dir="$(pwd)" +# shellcheck disable=SC1090 +set -a +. "./$env_file" +set +a + +export API_BASE_URL="${API_BASE_URL:-http://127.0.0.1:${APP_PUBLIC_PORT:-8080}}" +export DATABASE_URL="postgresql://${POSTGRES_USER:-messenger}:${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in $env_file}@127.0.0.1:${POSTGRES_PUBLISHED_PORT:-5432}/${POSTGRES_DB:-messenger}" +export REDIS_URL="redis://127.0.0.1:${REDIS_PUBLISHED_PORT:-6379}" +export E2E_S3_PUBLIC_ENDPOINT="${S3_PUBLIC_ENDPOINT:-http://localhost:9000}" +export E2E_S3_BUCKET="${S3_BUCKET:-messenger-attachments}" +export E2E_COMPOSE_DIR="$compose_dir" +export E2E_COMPOSE_ENV_FILE="$env_file" + +cd "$(dirname "$0")/../app" +exec npm run test:e2e -- "$@" diff --git a/scripts/init-env.sh b/scripts/init-env.sh new file mode 100755 index 00000000..f0ce71c4 --- /dev/null +++ b/scripts/init-env.sh @@ -0,0 +1,40 @@ +#!/bin/sh +# Идемпотентно создаёт .env и secrets/* для локального стенда. Значения не печатает. +set -eu +cd "$(dirname "$0")/.." + +if [ ! -f .env ]; then + ( + umask 077 + pg=$(openssl rand -hex 24) + mt=$(openssl rand -hex 16) + sed \ + -e "s|^POSTGRES_PASSWORD=.*|POSTGRES_PASSWORD=${pg}|" \ + -e "s|^DATABASE_URL=.*|DATABASE_URL=postgresql://messenger:${pg}@postgres:5432/messenger|" \ + -e "s|^METRICS_TOKEN=.*|METRICS_TOKEN=${mt}|" \ + .env.example > .env + ) + echo "created .env" +else + echo "kept .env" +fi + +mkdir -p secrets +chmod 700 secrets + +write_secret() { + name=$1 + value=$2 + if [ -s "secrets/$name" ]; then + echo "kept secrets/$name" + return + fi + (umask 133; printf '%s' "$value" > "secrets/$name") + chmod 0644 "secrets/$name" + echo "created secrets/$name" +} + +write_secret minio_root_user "root-$(openssl rand -hex 6)" +write_secret minio_root_password "$(openssl rand -hex 24)" +write_secret s3_api_access_key_id "api-$(openssl rand -hex 8)" +write_secret s3_api_secret_access_key "$(openssl rand -hex 24)" diff --git a/scripts/restart.sh b/scripts/restart.sh new file mode 100755 index 00000000..36e74518 --- /dev/null +++ b/scripts/restart.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# Restart hook for `make test-persistence ACTION_SCRIPT=scripts/restart.sh`. +# Semantic and evidence notes: tests/README.md ("Проверка сохранности") and REPORT.md. +set -euo pipefail + +compose=(docker compose --env-file .env) +"${compose[@]}" restart postgres redis s3 api haproxy +"${compose[@]}" up -d --no-recreate --no-deps --wait postgres redis s3 api haproxy diff --git a/scripts/start-replica.sh b/scripts/start-replica.sh new file mode 100755 index 00000000..bf24b821 --- /dev/null +++ b/scripts/start-replica.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# Восстанавливает недостающую API-реплику до объявленного числа реплик. +set -eu + +env_file="${COMPOSE_ENV_FILE:-.env}" +replicas="${API_REPLICAS:-}" +if [ -z "$replicas" ] && [ -f "$env_file" ]; then + replicas=$(sed -n 's/^API_REPLICAS=//p' "$env_file" | tail -n 1) +fi +replicas="${replicas:-2}" +exec docker compose --env-file "$env_file" up -d --no-deps --scale "api=${replicas}" api diff --git a/scripts/stop-one.sh b/scripts/stop-one.sh new file mode 100755 index 00000000..18b1552d --- /dev/null +++ b/scripts/stop-one.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# Останавливает ровно одну API-реплику стенда — ту, которую обслужила текущая +# сессия. TARGET_INSTANCE_ID приходит из теста (значение X-Instance-Id ответа), +# а в Docker hostname контейнера равен его короткому ID, поэтому сопоставление +# однозначно. Ничего, кроме этой реплики, скрипт не трогает: ни LB, ни БД, ни +# тома. Возврат управления — быстрый (SIGTERM -> дрейн DRAIN_DELAY_MS=3s -> +# выход), останавливать реплику "навсегда" не требуется. +set -eu + +: "${TARGET_INSTANCE_ID:?test provides target API instance alias}" +project="${LAB4_PROJECT:-mtusi-lab4}" + +target='' +for container in $( + docker ps \ + --filter "label=com.docker.compose.project=${project}" \ + --filter 'label=com.docker.compose.service=api' \ + --format '{{.ID}}' +); do + case "$container" in + "$TARGET_INSTANCE_ID"*) + target="$container" + break + ;; + esac +done + +if [ -z "$target" ]; then + printf 'stop-one: no running api replica of project %s whose id starts with %s\n' \ + "$project" "$TARGET_INSTANCE_ID" >&2 + exit 1 +fi + +printf 'stop-one: stopping api replica %s\n' "$target" >&2 +docker stop --time 10 "$target" >/dev/null -- 2.54.0 From 89787861ffe8d86c0fc03fb4602594115d07ea91 Mon Sep 17 00:00:00 2001 From: Ilya Date: Thu, 22 Oct 2026 22:24:57 +0300 Subject: [PATCH 02/15] =?UTF-8?q?lab4:=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8?= =?UTF-8?q?=D0=B3=D1=83=D1=80=D0=B0=D1=86=D0=B8=D1=8F=20S3,=20ObjectStorag?= =?UTF-8?q?e,=20=D0=BC=D0=B5=D1=82=D1=80=D0=B8=D0=BA=D0=B8=20=D0=BF=D0=B0?= =?UTF-8?q?=D0=BC=D1=8F=D1=82=D0=B8=20=D0=B8=20=D0=B1=D0=B0=D0=B9=D1=82?= =?UTF-8?q?=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/package-lock.json | 415 ++++++++++++++++++ app/package.json | 3 + app/src/common/errors/api-exception.filter.ts | 15 +- app/src/config/app-config.schema.ts | 90 +++- app/src/database/migration.runner.ts | 4 +- .../idempotency/idempotency-gc.cli.ts | 4 +- app/src/metrics/metrics.service.spec.ts | 35 +- app/src/metrics/metrics.service.ts | 58 ++- app/src/storage/object-storage.ts | 184 ++++++++ app/src/storage/storage.module.ts | 5 + 10 files changed, 795 insertions(+), 18 deletions(-) create mode 100644 app/src/storage/object-storage.ts create mode 100644 app/src/storage/storage.module.ts diff --git a/app/package-lock.json b/app/package-lock.json index b98212b8..4338b4b9 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -9,11 +9,14 @@ "version": "0.0.1", "license": "UNLICENSED", "dependencies": { + "@aws-sdk/client-s3": "^3.1156.0", + "@aws-sdk/s3-request-presigner": "^3.1156.0", "@nestjs/common": "^12.0.1", "@nestjs/config": "^12.0.0", "@nestjs/core": "^12.0.1", "@nestjs/platform-express": "^12.0.1", "@nestjs/platform-fastify": "^12.0.3", + "@smithy/node-http-handler": "^4.12.1", "argon2": "^0.45.1", "class-transformer": "^0.5.1", "class-validator": "^0.15.1", @@ -144,6 +147,331 @@ } } }, + "node_modules/@aws-sdk/checksums": { + "version": "3.1001.5", + "resolved": "https://registry.npmjs.org/@aws-sdk/checksums/-/checksums-3.1001.5.tgz", + "integrity": "sha512-6erto9nK2OZO/woEgmFIaPh5gChgdNd7nL6jgAf8TAXz3/QHC8Pan2TFe9GYp3IxOIKCCGWPylSjtOHKfNzQlw==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "^3.978.5", + "@aws-sdk/types": "^3.975.0", + "@smithy/core": "^3.36.1", + "@smithy/types": "^4.19.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/client-s3": { + "version": "3.1156.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/client-s3/-/client-s3-3.1156.0.tgz", + "integrity": "sha512-Z2PqQqKMDVX56tNZ6ggmjoI5o/8+4+8ArmjLwE5ktYsEzs1BrvklBT1ZzI+s0Vcf3wfPguoEMD7EkMswmEta/A==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/checksums": "^3.1001.5", + "@aws-sdk/core": "^3.978.5", + "@aws-sdk/credential-provider-node": "^3.972.88", + "@aws-sdk/middleware-sdk-s3": "^3.972.81", + "@aws-sdk/signature-v4-multi-region": "^3.996.49", + "@aws-sdk/types": "^3.975.0", + "@smithy/core": "^3.36.1", + "@smithy/fetch-http-handler": "^5.8.0", + "@smithy/node-http-handler": "^4.12.1", + "@smithy/types": "^4.19.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/core": { + "version": "3.978.5", + "resolved": "https://registry.npmjs.org/@aws-sdk/core/-/core-3.978.5.tgz", + "integrity": "sha512-ruI0AWqcrfL20XDS6SwZIJFPOBZ6N0ADa9nLzWlBhxk1aoUjbUX3JkTR9vEmk7o35XpAHi68ahZ4T6RE2U9XyA==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/types": "^3.975.0", + "@aws-sdk/xml-builder": "^3.972.41", + "@aws/lambda-invoke-store": "^0.3.0", + "@smithy/core": "^3.36.1", + "@smithy/signature-v4": "^5.7.4", + "@smithy/types": "^4.19.0", + "bowser": "^2.11.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-env": { + "version": "3.972.76", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-env/-/credential-provider-env-3.972.76.tgz", + "integrity": "sha512-YxmL1Ar7bV9ZkJvtv+lj+MF6le76NnZnbmgySyZuxpZaCv0/1lZ3KxKy6RIj1h9ui2hWnVjZxbmTMeO0y/NrQA==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "^3.978.5", + "@aws-sdk/types": "^3.975.0", + "@smithy/core": "^3.36.1", + "@smithy/types": "^4.19.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-http": { + "version": "3.972.78", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-http/-/credential-provider-http-3.972.78.tgz", + "integrity": "sha512-3VHknDRngoebsaqyT1iR75b5cBT2zfEtODK6yYmYltljkK1HEAQLs2FEd1IpWqAeOYdMGaG9wikngWLTufY7RA==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "^3.978.5", + "@aws-sdk/types": "^3.975.0", + "@smithy/core": "^3.36.1", + "@smithy/fetch-http-handler": "^5.8.0", + "@smithy/node-http-handler": "^4.12.1", + "@smithy/types": "^4.19.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-ini": { + "version": "3.973.21", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-ini/-/credential-provider-ini-3.973.21.tgz", + "integrity": "sha512-aLx9hbCX6mGAyv4ZZd8UagJ4RASHVJw6BFDSIyuKmLkqNL6H47EjBPK6qaJ4B5TDV6mc+vMa0SJFYyo4mkvVQg==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "^3.978.5", + "@aws-sdk/credential-provider-env": "^3.972.76", + "@aws-sdk/credential-provider-http": "^3.972.78", + "@aws-sdk/credential-provider-login": "^3.972.83", + "@aws-sdk/credential-provider-process": "^3.972.76", + "@aws-sdk/credential-provider-sso": "^3.973.20", + "@aws-sdk/credential-provider-web-identity": "^3.972.82", + "@aws-sdk/nested-clients": "^3.997.50", + "@aws-sdk/types": "^3.975.0", + "@smithy/core": "^3.36.1", + "@smithy/credential-provider-imds": "^4.5.2", + "@smithy/types": "^4.19.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-login": { + "version": "3.972.83", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-login/-/credential-provider-login-3.972.83.tgz", + "integrity": "sha512-9bJU6FjRacF4FK/QHf8Dyxhur7B1grRj8C1Yh4IkpoFW2exQflPdCv0VrbemLW9ZctLNle+AE7TETs9KNvuLYg==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "^3.978.5", + "@aws-sdk/nested-clients": "^3.997.50", + "@aws-sdk/types": "^3.975.0", + "@smithy/core": "^3.36.1", + "@smithy/types": "^4.19.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-node": { + "version": "3.972.88", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-node/-/credential-provider-node-3.972.88.tgz", + "integrity": "sha512-AG0KID5qhQPzrFkh5b0Cws1Amytvzo0L0Xj6hMgJXEwD6ZXAqninDhSNAWJiN5zU4YVVZnuidnqwPwYJ04IamA==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/credential-provider-env": "^3.972.76", + "@aws-sdk/credential-provider-http": "^3.972.78", + "@aws-sdk/credential-provider-ini": "^3.973.21", + "@aws-sdk/credential-provider-process": "^3.972.76", + "@aws-sdk/credential-provider-sso": "^3.973.20", + "@aws-sdk/credential-provider-web-identity": "^3.972.82", + "@aws-sdk/types": "^3.975.0", + "@smithy/core": "^3.36.1", + "@smithy/credential-provider-imds": "^4.5.2", + "@smithy/types": "^4.19.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-process": { + "version": "3.972.76", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-process/-/credential-provider-process-3.972.76.tgz", + "integrity": "sha512-pdhKFTXv1zPYhh92MTlp0jVbLWvUEV9v+rziuEkoskGGQ2iJskxHTO38nA8UAbT/N4IM3n8OZJ9rIY5IBO15/A==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "^3.978.5", + "@aws-sdk/types": "^3.975.0", + "@smithy/core": "^3.36.1", + "@smithy/types": "^4.19.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-sso": { + "version": "3.973.20", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-sso/-/credential-provider-sso-3.973.20.tgz", + "integrity": "sha512-DlxrAB3MnjNLx/da7b89W+3DyJQYso/q7Ns15MsST2IV2nkAYQOYTUCaffNSjgrpMP99Dm2mV2jxzcbyF94ZfA==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "^3.978.5", + "@aws-sdk/nested-clients": "^3.997.50", + "@aws-sdk/token-providers": "3.1155.0", + "@aws-sdk/types": "^3.975.0", + "@smithy/core": "^3.36.1", + "@smithy/types": "^4.19.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-web-identity": { + "version": "3.972.82", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-web-identity/-/credential-provider-web-identity-3.972.82.tgz", + "integrity": "sha512-LUo46IqPTJ4xKBsrLuoaxiv/D2GTBCcFDMD1y3jKIqPR/p7Rw14RJFZ0iRWftqZtyLPQX9JMGnSi3mBu4y/pNA==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "^3.978.5", + "@aws-sdk/nested-clients": "^3.997.50", + "@aws-sdk/types": "^3.975.0", + "@smithy/core": "^3.36.1", + "@smithy/types": "^4.19.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/middleware-sdk-s3": { + "version": "3.972.81", + "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-sdk-s3/-/middleware-sdk-s3-3.972.81.tgz", + "integrity": "sha512-jfanv1pV0sJFZw6/DPiNjvK7B478god0zOum5yIWo+/+1Gy+CSXWpGBWx+3nBJyDvjcu/2kUMr4ADUp9BHH34Q==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "^3.978.5", + "@aws-sdk/signature-v4-multi-region": "^3.996.49", + "@aws-sdk/types": "^3.975.0", + "@smithy/core": "^3.36.1", + "@smithy/types": "^4.19.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/nested-clients": { + "version": "3.997.50", + "resolved": "https://registry.npmjs.org/@aws-sdk/nested-clients/-/nested-clients-3.997.50.tgz", + "integrity": "sha512-nKb8qu4QsnpZTq/6JIXc72mzuzfh7BK4sUQkpQznPec2z4W7Ob2xYkcM4i5e1yGTBnbJVeFv/0sf3jcz85hclA==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "^3.978.5", + "@aws-sdk/signature-v4-multi-region": "^3.996.49", + "@aws-sdk/types": "^3.975.0", + "@smithy/core": "^3.36.1", + "@smithy/fetch-http-handler": "^5.8.0", + "@smithy/node-http-handler": "^4.12.1", + "@smithy/types": "^4.19.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/s3-request-presigner": { + "version": "3.1156.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/s3-request-presigner/-/s3-request-presigner-3.1156.0.tgz", + "integrity": "sha512-M4yj4HmAPydhIMxKK90eTcnHr5FHBl000d2oFMAWpt+XPX86c2kmNJpiYbKrPLIe8jyK9sweRt5CDdWrhq/QTg==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "^3.978.5", + "@aws-sdk/signature-v4-multi-region": "^3.996.49", + "@aws-sdk/types": "^3.975.0", + "@smithy/core": "^3.36.1", + "@smithy/types": "^4.19.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/signature-v4-multi-region": { + "version": "3.996.49", + "resolved": "https://registry.npmjs.org/@aws-sdk/signature-v4-multi-region/-/signature-v4-multi-region-3.996.49.tgz", + "integrity": "sha512-nvuAZNRrRRVCiARRKsYlQ0VnXiEQiq7vXPH+UA+LSo+kN3Djl9eo/V2r0udkw85PnsNshmv2Em1clld5M3j67w==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/types": "^3.975.0", + "@smithy/signature-v4": "^5.7.4", + "@smithy/types": "^4.19.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/token-providers": { + "version": "3.1155.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/token-providers/-/token-providers-3.1155.0.tgz", + "integrity": "sha512-iIcQnYLhWuq9qOLQbIWFrxF3PF0svVeZvHnUS4DUnO4zUFmFHIyGyjqrntXG+e/5PUgfavV0pYfDIKHxTzN2LA==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "^3.978.5", + "@aws-sdk/nested-clients": "^3.997.50", + "@aws-sdk/types": "^3.975.0", + "@smithy/core": "^3.36.1", + "@smithy/types": "^4.19.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/types": { + "version": "3.975.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/types/-/types-3.975.0.tgz", + "integrity": "sha512-WQlhs6juByzWOzj5fwxOx0mPJaEqMcG/sDpl3Id61B3XhKE63xY+0QWcnG+sWR/sCfprmreyUo1lM7IKZmHMzw==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^4.19.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/xml-builder": { + "version": "3.972.41", + "resolved": "https://registry.npmjs.org/@aws-sdk/xml-builder/-/xml-builder-3.972.41.tgz", + "integrity": "sha512-ctjVSyCMegrWfXlx6VqzSBFI6UqmQ5ZlnfMhdLIiWmhoH8UAQxSCP5N3OpG7X3k4LnS7ou74C4mt20+bfTW2aQ==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^4.19.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws/lambda-invoke-store": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@aws/lambda-invoke-store/-/lambda-invoke-store-0.3.0.tgz", + "integrity": "sha512-sl4Bm6yiMNYrZKkqqDFWN0UfnWhlS8ivKxrYl+6t0gCLrqr8y3B2IqZZbFRkfaVVp7C/baApyh71P+LeE1A2sQ==", + "license": "Apache-2.0", + "engines": { + "node": ">=18.0.0" + } + }, "node_modules/@babel/helper-string-parser": { "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.29.7.tgz", @@ -2462,6 +2790,87 @@ "url": "https://github.com/sindresorhus/is?sponsor=1" } }, + "node_modules/@smithy/core": { + "version": "3.36.2", + "resolved": "https://registry.npmjs.org/@smithy/core/-/core-3.36.2.tgz", + "integrity": "sha512-oRw0rB9QSUiCZfEs23G5F4Af+b2rQt1lItIICWu5IejFNd+uPM8SWqiKLMpQ6bX1Q7slsLbjuoE2niErFtkVPQ==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^4.19.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/credential-provider-imds": { + "version": "4.5.2", + "resolved": "https://registry.npmjs.org/@smithy/credential-provider-imds/-/credential-provider-imds-4.5.2.tgz", + "integrity": "sha512-A9uSdn72ozbRUSit0eib0TW7nXuNPlaeM0zcGkJ+nE6tFcSDbnmtwoxbTCFBukVQcszDAyvsd7+rTduPTXpygg==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/core": "^3.33.2", + "@smithy/types": "^4.17.2", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/fetch-http-handler": { + "version": "5.8.0", + "resolved": "https://registry.npmjs.org/@smithy/fetch-http-handler/-/fetch-http-handler-5.8.0.tgz", + "integrity": "sha512-ycSJu3tFAQ4v04CBB0agqFMVsSQ1iG3yw+SpgxRqKfaURpQD4CZ8Wn0zPMmSnOuTpTh65Vz+EA0rMrw089wvkA==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/core": "^3.33.3", + "@smithy/types": "^4.18.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/node-http-handler": { + "version": "4.12.1", + "resolved": "https://registry.npmjs.org/@smithy/node-http-handler/-/node-http-handler-4.12.1.tgz", + "integrity": "sha512-ThMkboGeONWXAelq9FvGsuJC4rOi+qyC4/zhUF58xYpxUg5sQKx2VXZYJmtNjr4dSuBJ1HeJXETQILCz3wOHvw==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/core": "^3.33.3", + "@smithy/types": "^4.18.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/signature-v4": { + "version": "5.7.4", + "resolved": "https://registry.npmjs.org/@smithy/signature-v4/-/signature-v4-5.7.4.tgz", + "integrity": "sha512-tHy0K0VtqNd5Y7Y41h0a0Lhh0L1GzC08dTWg0F7vRJWFtTENg7IZikf3wQkanYIRdb7ngoIPMTmqgUi401fEeQ==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/core": "^3.35.0", + "@smithy/types": "^4.19.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/types": { + "version": "4.19.0", + "resolved": "https://registry.npmjs.org/@smithy/types/-/types-4.19.0.tgz", + "integrity": "sha512-r7jh49VJxGerfAcTQA6gXcKc+98zOp/tqRwzYjgOE+iSQsP6cEU1hq2QzbuipmP68QtYdY9wKEhiCQZIzHgZ4Q==", + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, "node_modules/@standard-schema/spec": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.1.0.tgz", @@ -3112,6 +3521,12 @@ "url": "https://opencollective.com/express" } }, + "node_modules/bowser": { + "version": "2.14.1", + "resolved": "https://registry.npmjs.org/bowser/-/bowser-2.14.1.tgz", + "integrity": "sha512-tzPjzCxygAKWFOJP011oxFHs57HzIhOEracIgAePE4pqB3LikALKnSzUyU4MGs9/iCEUuHlAJTjTc5M+u7YEGg==", + "license": "MIT" + }, "node_modules/brace-expansion": { "version": "5.0.12", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.12.tgz", diff --git a/app/package.json b/app/package.json index 2014015d..c308530d 100644 --- a/app/package.json +++ b/app/package.json @@ -26,11 +26,14 @@ "idempotency:gc": "tsx src/messages/idempotency/idempotency-gc.cli.ts" }, "dependencies": { + "@aws-sdk/client-s3": "^3.1156.0", + "@aws-sdk/s3-request-presigner": "^3.1156.0", "@nestjs/common": "^12.0.1", "@nestjs/config": "^12.0.0", "@nestjs/core": "^12.0.1", "@nestjs/platform-express": "^12.0.1", "@nestjs/platform-fastify": "^12.0.3", + "@smithy/node-http-handler": "^4.12.1", "argon2": "^0.45.1", "class-transformer": "^0.5.1", "class-validator": "^0.15.1", diff --git a/app/src/common/errors/api-exception.filter.ts b/app/src/common/errors/api-exception.filter.ts index a1384238..e8e01b76 100644 --- a/app/src/common/errors/api-exception.filter.ts +++ b/app/src/common/errors/api-exception.filter.ts @@ -14,7 +14,11 @@ import { resolveInstanceId } from '../../config/instance-id.js'; import type { ApiErrorBody } from './api-error.js'; type RequestWithId = { requestId?: string; method?: string; url?: string }; -type ExceptionBody = { message?: unknown; challenge?: unknown }; +type ExceptionBody = { + message?: unknown; + challenge?: unknown; + retryAfter?: unknown; +}; // Connection/session loss codes reported by node-postgres and the network layer. const UNAVAILABLE_ERROR_CODES: Record = { @@ -106,6 +110,7 @@ export class ApiExceptionFilter implements ExceptionFilter { let status = HttpStatus.INTERNAL_SERVER_ERROR; let message = 'Internal server error'; let challenge: string | undefined; + let retryAfter = 1; if (exception instanceof HttpException) { status = exception.getStatus(); const body = exception.getResponse(); @@ -119,6 +124,12 @@ export class ApiExceptionFilter implements ExceptionFilter { typeof details.challenge === 'string' ? details.challenge : undefined; + if ( + typeof details.retryAfter === 'number' && + Number.isFinite(details.retryAfter) && + details.retryAfter >= 1 + ) + retryAfter = Math.ceil(details.retryAfter); message = Array.isArray(rawMessage) ? rawMessage.join('; ') : typeof rawMessage === 'string' @@ -154,6 +165,8 @@ export class ApiExceptionFilter implements ExceptionFilter { : 'Bearer realm="messenger"'); adapter.setHeader(response, 'WWW-Authenticate', authChallenge); } + if (status === HttpStatus.TOO_MANY_REQUESTS) + adapter.setHeader(response, 'Retry-After', String(retryAfter)); adapter.setHeader(response, 'X-Request-Id', requestId); adapter.setHeader(response, 'X-Instance-Id', this.instanceId); const payload: ApiErrorBody = { diff --git a/app/src/config/app-config.schema.ts b/app/src/config/app-config.schema.ts index 2a686f55..031055d1 100644 --- a/app/src/config/app-config.schema.ts +++ b/app/src/config/app-config.schema.ts @@ -64,15 +64,91 @@ export const appConfigSchema = z undefined, 86400, ), + S3_ENDPOINT: requiredString('S3_ENDPOINT'), + S3_PUBLIC_ENDPOINT: requiredString('S3_PUBLIC_ENDPOINT'), + S3_REGION: z.string().min(1).default('us-east-1'), + S3_BUCKET: requiredString('S3_BUCKET'), + S3_ACCESS_KEY_ID: requiredString('S3_ACCESS_KEY_ID'), + S3_SECRET_ACCESS_KEY: requiredString('S3_SECRET_ACCESS_KEY'), + S3_CONNECT_TIMEOUT_MS: numeric( + 'S3_CONNECT_TIMEOUT_MS', + 1, + undefined, + 1000, + ), + S3_REQUEST_TIMEOUT_MS: numeric( + 'S3_REQUEST_TIMEOUT_MS', + 1, + undefined, + 15000, + ), + MAX_UPLOAD_BYTES: numeric( + 'MAX_UPLOAD_BYTES', + 1, + 10485760, + 10485760, + ), + MAX_IMAGE_PIXELS: numeric( + 'MAX_IMAGE_PIXELS', + 1, + 40000000, + 40000000, + ), + UPLOAD_TIMEOUT_MS: numeric( + 'UPLOAD_TIMEOUT_MS', + 1000, + undefined, + 25000, + ), + UPLOAD_MAX_IN_FLIGHT: numeric('UPLOAD_MAX_IN_FLIGHT', 1, 1024, 32), + // 0 отключает фоновый проход уборщика (остаётся ручной CLI). + ATTACHMENT_SWEEP_INTERVAL_MS: numeric( + 'ATTACHMENT_SWEEP_INTERVAL_MS', + 0, + undefined, + 60000, + ), + ATTACHMENT_SWEEP_GRACE_SECONDS: numeric( + 'ATTACHMENT_SWEEP_GRACE_SECONDS', + 0, + undefined, + 900, + ), + DIRECT_UPLOAD_URL_TTL_SECONDS: numeric( + 'DIRECT_UPLOAD_URL_TTL_SECONDS', + 1, + 3600, + 300, + ), + DIRECT_UPLOAD_MAX_PENDING_PER_USER: numeric( + 'DIRECT_UPLOAD_MAX_PENDING_PER_USER', + 1, + 1000, + 10, + ), }) .strip(); +export const databaseConfigSchema = appConfigSchema.pick({ + DATABASE_URL: true, + DATABASE_POOL_MAX: true, + DATABASE_CONNECTION_TIMEOUT_MS: true, + DATABASE_STATEMENT_TIMEOUT_MS: true, + HEALTH_TIMEOUT_MS: true, + IDEMPOTENCY_TTL_SECONDS: true, +}); +export type DatabaseConfig = z.infer; + export type AppConfig = z.infer; export type AppConfigKey = keyof AppConfig; function resolveSecret( raw: Record, - key: 'DATABASE_URL' | 'REDIS_URL', + key: + | 'DATABASE_URL' + | 'REDIS_URL' + | 'S3_ACCESS_KEY_ID' + | 'S3_SECRET_ACCESS_KEY', ): unknown { const fileKey = `${key}_FILE`; const path = raw[fileKey]; @@ -97,5 +173,17 @@ export function parseAppConfig(raw: Record): AppConfig { ...raw, DATABASE_URL: resolveSecret(raw, 'DATABASE_URL'), REDIS_URL: resolveSecret(raw, 'REDIS_URL'), + S3_ACCESS_KEY_ID: resolveSecret(raw, 'S3_ACCESS_KEY_ID'), + S3_SECRET_ACCESS_KEY: resolveSecret(raw, 'S3_SECRET_ACCESS_KEY'), + }); +} + +// Для процессов, которым нужна только БД (миграции, GC идемпотентности). +export function parseDatabaseConfig( + raw: Record, +): DatabaseConfig { + return databaseConfigSchema.parse({ + ...raw, + DATABASE_URL: resolveSecret(raw, 'DATABASE_URL'), }); } diff --git a/app/src/database/migration.runner.ts b/app/src/database/migration.runner.ts index dfcd5070..5e101c35 100644 --- a/app/src/database/migration.runner.ts +++ b/app/src/database/migration.runner.ts @@ -3,7 +3,7 @@ import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; import { DatabaseClient } from './database.client.js'; import { MetricsService } from '../metrics/metrics.service.js'; -import { parseAppConfig } from '../config/app-config.schema.js'; +import { parseDatabaseConfig } from '../config/app-config.schema.js'; const migrationsDirectory = join( dirname(fileURLToPath(import.meta.url)), @@ -46,7 +46,7 @@ export async function runMigrations(database: DatabaseClient): Promise { } async function main(): Promise { - const config = parseAppConfig(process.env as Record); + const config = parseDatabaseConfig(process.env as Record); const database = new DatabaseClient( { getOrThrow: (key: keyof typeof config) => config[key], diff --git a/app/src/messages/idempotency/idempotency-gc.cli.ts b/app/src/messages/idempotency/idempotency-gc.cli.ts index 7ab0da55..4e473bcc 100644 --- a/app/src/messages/idempotency/idempotency-gc.cli.ts +++ b/app/src/messages/idempotency/idempotency-gc.cli.ts @@ -1,5 +1,5 @@ import { fileURLToPath } from 'node:url'; -import { parseAppConfig } from '../../config/app-config.schema.js'; +import { parseDatabaseConfig } from '../../config/app-config.schema.js'; import { DatabaseClient } from '../../database/database.client.js'; import { MetricsService } from '../../metrics/metrics.service.js'; import { IdempotencyRepository } from './idempotency.repository.js'; @@ -10,7 +10,7 @@ import { IdempotencyRepository } from './idempotency.repository.js'; // in the stand: docker compose exec api node dist/messages/idempotency/idempotency-gc.cli.js // on the host: npm run idempotency:gc (needs a reachable DATABASE_URL) async function main(): Promise { - const config = parseAppConfig(process.env as Record); + const config = parseDatabaseConfig(process.env as Record); const database = new DatabaseClient( { getOrThrow: (key: keyof typeof config) => config[key], diff --git a/app/src/metrics/metrics.service.spec.ts b/app/src/metrics/metrics.service.spec.ts index 2b5e5017..0316e946 100644 --- a/app/src/metrics/metrics.service.spec.ts +++ b/app/src/metrics/metrics.service.spec.ts @@ -9,16 +9,15 @@ describe('MetricsService', () => { metrics.observeLatency(30); metrics.observeLatency(10); metrics.observeLatency(20); - expect(metrics.snapshot()).toEqual({ - counters: { cache_hit: 2 }, - latency_ms: { - count: 3, - sample_count: 3, - p50: 20, - p95: 30, - p99: 30, - max: 30, - }, + const snapshot = metrics.snapshot(); + expect(snapshot.counters).toEqual({ cache_hit: 2 }); + expect(snapshot.latency_ms).toEqual({ + count: 3, + sample_count: 3, + p50: 20, + p95: 30, + p99: 30, + max: 30, }); }); @@ -59,4 +58,20 @@ describe('MetricsService', () => { max: 0, }); }); + + it('adds byte counters and ignores invalid amounts', () => { + const metrics = new MetricsService(); + metrics.add('bytes', 100); + metrics.add('bytes', 28); + for (const value of [-1, NaN, Infinity]) metrics.add('bytes', value); + expect(metrics.snapshot().counters.bytes).toBe(128); + }); + + it('tracks memory peaks until reset', () => { + const metrics = new MetricsService(); + const ballast = Buffer.alloc(32 * 1024 * 1024, 1); + const during = metrics.snapshot().memory_peak_bytes.array_buffers; + expect(during).toBeGreaterThanOrEqual(ballast.length); + ballast.fill(0); + }); }); diff --git a/app/src/metrics/metrics.service.ts b/app/src/metrics/metrics.service.ts index bf54a994..9087b09a 100644 --- a/app/src/metrics/metrics.service.ts +++ b/app/src/metrics/metrics.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@nestjs/common'; +import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common'; const LATENCY_SAMPLE_CAPACITY = 4096; @@ -11,14 +11,53 @@ type LatencySnapshot = { max: number; }; +const MEMORY_SAMPLE_INTERVAL_MS = 50; + +type MemoryUsage = { + rss: number; + heap_used: number; + external: number; + array_buffers: number; +}; + +function currentMemory(): MemoryUsage { + const usage = process.memoryUsage(); + return { + rss: usage.rss, + heap_used: usage.heapUsed, + external: usage.external, + array_buffers: usage.arrayBuffers, + }; +} + @Injectable() -export class MetricsService { +export class MetricsService implements OnModuleInit, OnModuleDestroy { + private memoryPeak: MemoryUsage = currentMemory(); + private memoryTimer: NodeJS.Timeout | undefined; private readonly counters: Record = {}; private readonly latencies: number[] = []; private latencyCount = 0; private maximumLatency = 0; private nextSample = 0; + onModuleInit(): void { + this.memoryTimer = setInterval( + () => this.sampleMemory(), + MEMORY_SAMPLE_INTERVAL_MS, + ); + this.memoryTimer.unref(); + } + + onModuleDestroy(): void { + if (this.memoryTimer) clearInterval(this.memoryTimer); + this.memoryTimer = undefined; + } + + add(name: string, amount: number): void { + if (!Number.isFinite(amount) || amount < 0) return; + this.counters[name] = (this.counters[name] ?? 0) + amount; + } + increment(name: string): void { this.counters[name] = (this.counters[name] ?? 0) + 1; } @@ -34,7 +73,10 @@ export class MetricsService { snapshot(): { counters: Record; latency_ms: LatencySnapshot; + memory_bytes: MemoryUsage; + memory_peak_bytes: MemoryUsage; } { + this.sampleMemory(); const sorted = [...this.latencies].sort((left, right) => left - right); return { counters: { ...this.counters }, @@ -46,6 +88,8 @@ export class MetricsService { p99: this.percentile(sorted, 0.99), max: this.maximumLatency, }, + memory_bytes: currentMemory(), + memory_peak_bytes: { ...this.memoryPeak }, }; } @@ -56,6 +100,16 @@ export class MetricsService { this.latencyCount = 0; this.maximumLatency = 0; this.nextSample = 0; + this.memoryPeak = currentMemory(); + } + + private sampleMemory(): void { + const now = currentMemory(); + const peak = this.memoryPeak; + peak.rss = Math.max(peak.rss, now.rss); + peak.heap_used = Math.max(peak.heap_used, now.heap_used); + peak.external = Math.max(peak.external, now.external); + peak.array_buffers = Math.max(peak.array_buffers, now.array_buffers); } private percentile(sorted: number[], percentile: number): number { diff --git a/app/src/storage/object-storage.ts b/app/src/storage/object-storage.ts new file mode 100644 index 00000000..f6448742 --- /dev/null +++ b/app/src/storage/object-storage.ts @@ -0,0 +1,184 @@ +import { + DeleteObjectCommand, + GetObjectCommand, + HeadObjectCommand, + PutObjectCommand, + S3Client, +} from '@aws-sdk/client-s3'; +import { getSignedUrl } from '@aws-sdk/s3-request-presigner'; +import { NodeHttpHandler } from '@smithy/node-http-handler'; +import { + Injectable, + Logger, + ServiceUnavailableException, +} from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; +import http from 'node:http'; +import { Readable } from 'node:stream'; +import type { AppConfig } from '../config/app-config.schema.js'; + +export class ObjectStorageUnavailableError extends ServiceUnavailableException { + constructor() { + super('Object storage unavailable'); + } +} + +export type PresignPutOptions = { + contentType: string; + contentLength: number; + checksumSha256Base64: string; + expiresInSeconds: number; +}; + +function isMissingKey(error: unknown): boolean { + const candidate = error as { + name?: string; + $metadata?: { httpStatusCode?: number }; + }; + return ( + candidate?.name === 'NoSuchKey' || + candidate?.name === 'NotFound' || + candidate?.$metadata?.httpStatusCode === 404 + ); +} + +@Injectable() +export class ObjectStorage { + private readonly logger = new Logger(ObjectStorage.name); + private readonly bucket: string; + private readonly internal: S3Client; + private readonly presign: S3Client; + + constructor(config: ConfigService) { + this.bucket = config.getOrThrow('S3_BUCKET'); + const common = { + region: config.getOrThrow('S3_REGION'), + forcePathStyle: true, + credentials: { + accessKeyId: config.getOrThrow('S3_ACCESS_KEY_ID'), + secretAccessKey: config.getOrThrow('S3_SECRET_ACCESS_KEY'), + }, + // Поток нельзя повторить: повтор — решение клиента API. + maxAttempts: 1, + requestChecksumCalculation: 'WHEN_REQUIRED' as const, + responseChecksumValidation: 'WHEN_REQUIRED' as const, + requestHandler: new NodeHttpHandler({ + connectionTimeout: config.getOrThrow('S3_CONNECT_TIMEOUT_MS'), + requestTimeout: config.getOrThrow('S3_REQUEST_TIMEOUT_MS'), + httpAgent: new http.Agent({ keepAlive: true, maxSockets: 64 }), + }), + }; + this.internal = new S3Client({ + ...common, + endpoint: config.getOrThrow('S3_ENDPOINT'), + }); + // Сеть не использует: только подпись URL для клиента. + this.presign = new S3Client({ + ...common, + endpoint: config.getOrThrow('S3_PUBLIC_ENDPOINT'), + }); + } + + objectKey(attachmentId: string): string { + return `attachments/${attachmentId}/original`; + } + + async putStream( + key: string, + body: Readable, + contentLength: number, + contentType: string, + signal: AbortSignal, + ): Promise { + try { + await this.internal.send( + new PutObjectCommand({ + Bucket: this.bucket, + Key: key, + Body: body, + ContentLength: contentLength, + ContentType: contentType, + }), + { abortSignal: signal }, + ); + } catch (error) { + throw this.fail('put', error); + } + } + + async getStream(key: string, range?: string): Promise { + try { + const result = await this.internal.send( + new GetObjectCommand({ + Bucket: this.bucket, + Key: key, + Range: range, + }), + ); + return result.Body as Readable; + } catch (error) { + if (isMissingKey(error)) return null; + throw this.fail('get', error); + } + } + + async head( + key: string, + ): Promise<{ size: number; checksumSha256?: string } | null> { + try { + const result = await this.internal.send( + new HeadObjectCommand({ + Bucket: this.bucket, + Key: key, + ChecksumMode: 'ENABLED', + }), + ); + return { + size: Number(result.ContentLength ?? 0), + checksumSha256: result.ChecksumSHA256, + }; + } catch (error) { + if (isMissingKey(error)) return null; + throw this.fail('head', error); + } + } + + async delete(key: string): Promise { + try { + await this.internal.send( + new DeleteObjectCommand({ Bucket: this.bucket, Key: key }), + ); + } catch (error) { + if (isMissingKey(error)) return; + throw this.fail('delete', error); + } + } + + async presignPut(key: string, options: PresignPutOptions): Promise { + return getSignedUrl( + this.presign, + new PutObjectCommand({ + Bucket: this.bucket, + Key: key, + ContentType: options.contentType, + ContentLength: options.contentLength, + ChecksumSHA256: options.checksumSha256Base64, + }), + { + expiresIn: options.expiresInSeconds, + signableHeaders: new Set([ + 'content-type', + 'content-length', + 'x-amz-checksum-sha256', + ]), + unhoistableHeaders: new Set(['x-amz-checksum-sha256']), + }, + ); + } + + private fail(operation: string, error: unknown): Error { + const name = (error as { name?: string })?.name ?? 'UnknownError'; + this.logger.warn(`S3 ${operation} failed: ${name}`); + return new ObjectStorageUnavailableError(); + } +} diff --git a/app/src/storage/storage.module.ts b/app/src/storage/storage.module.ts new file mode 100644 index 00000000..6cdffb6e --- /dev/null +++ b/app/src/storage/storage.module.ts @@ -0,0 +1,5 @@ +import { Module } from '@nestjs/common'; +import { ObjectStorage } from './object-storage.js'; + +@Module({ providers: [ObjectStorage], exports: [ObjectStorage] }) +export class StorageModule {} -- 2.54.0 From ec4e9fb6086f9d61667f4731b5b91a12d037a118 Mon Sep 17 00:00:00 2001 From: Ilya Date: Thu, 22 Oct 2026 22:26:22 +0300 Subject: [PATCH 03/15] =?UTF-8?q?lab4:=20=D1=81=D1=85=D0=B5=D0=BC=D0=B0=20?= =?UTF-8?q?=D0=B2=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8=D0=B9,=20=D0=BF?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=BA=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=B2=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D0=B4=D0=B0=D1=82=D0=BE=D1=80=20=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../attachments/image/image-inspector.spec.ts | 109 +++++ app/src/attachments/image/image-inspector.ts | 387 ++++++++++++++++++ .../database/migrations/005_attachments.sql | 42 ++ app/test/fixtures/sample-progressive.jpg | Bin 0 -> 4891 bytes app/test/fixtures/sample.jpg | Bin 0 -> 4726 bytes app/test/support/png.ts | 95 +++++ 6 files changed, 633 insertions(+) create mode 100644 app/src/attachments/image/image-inspector.spec.ts create mode 100644 app/src/attachments/image/image-inspector.ts create mode 100644 app/src/database/migrations/005_attachments.sql create mode 100644 app/test/fixtures/sample-progressive.jpg create mode 100644 app/test/fixtures/sample.jpg create mode 100644 app/test/support/png.ts diff --git a/app/src/attachments/image/image-inspector.spec.ts b/app/src/attachments/image/image-inspector.spec.ts new file mode 100644 index 00000000..9e749592 --- /dev/null +++ b/app/src/attachments/image/image-inspector.spec.ts @@ -0,0 +1,109 @@ +import { readFileSync } from 'node:fs'; +import { dirname, join } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { describe, expect, it } from 'vitest'; +import { noisePng, pixelBombPng } from '../../../test/support/png.js'; +import { ImageInspector, ImageRejectedError } from './image-inspector.js'; + +const here = dirname(fileURLToPath(import.meta.url)); +const png = readFileSync(join(here, '../../../../tests/fixtures/sample.png')); +const jpeg = readFileSync(join(here, '../../../test/fixtures/sample.jpg')); +const progressive = readFileSync( + join(here, '../../../test/fixtures/sample-progressive.jpg'), +); +const MAX = 40_000_000; + +function inspect(data: Buffer, step = data.length, max = MAX) { + const inspector = new ImageInspector(max); + for (let offset = 0; offset < data.length; offset += step) + inspector.push(data.subarray(offset, offset + step)); + return inspector.finish(); +} + +function rejection(action: () => unknown): ImageRejectedError { + try { + action(); + } catch (error) { + expect(error).toBeInstanceOf(ImageRejectedError); + return error as ImageRejectedError; + } + throw new Error('expected rejection'); +} + +describe('ImageInspector', () => { + it.each([ + ['png', png, 'image/png'], + ['jpeg', jpeg, 'image/jpeg'], + ['progressive jpeg', progressive, 'image/jpeg'], + ])('accepts %s and reports its size', (_name, data, contentType) => { + const expected = { contentType, width: 320, height: 200 }; + expect(inspect(data)).toEqual(expected); + expect(inspect(data, 1)).toEqual(expected); + expect(inspect(data, 7)).toEqual(expected); + }); + + it('rejects truncated files on finish', () => { + for (const data of [png, jpeg, progressive]) + for (const cut of [10, 40, data.length - 100, data.length - 1]) { + const reason = rejection(() => + inspect(data.subarray(0, cut)), + ).reason; + expect(reason).toBe('unsupported_media_type'); + } + }); + + it('rejects a flipped byte inside IDAT by checksum', () => { + const damaged = Buffer.from(png); + damaged[Math.floor(png.length / 2)] ^= 0xff; + expect(rejection(() => inspect(damaged)).reason).toBe( + 'unsupported_media_type', + ); + }); + + it('rejects a pixel bomb right after IHDR, before any IDAT', () => { + const bomb = pixelBombPng(); + const inspector = new ImageInspector(MAX); + // signature + IHDR chunk = 8 + 25 bytes + const reason = rejection(() => + inspector.push(bomb.subarray(0, 33)), + ).reason; + expect(reason).toBe('too_many_pixels'); + expect(inspector.header).toBeUndefined(); + }); + + it('applies the pixel limit to JPEG frame headers', () => { + expect(rejection(() => inspect(jpeg, jpeg.length, 63_999)).reason).toBe( + 'too_many_pixels', + ); + expect(inspect(jpeg, jpeg.length, 64_000).width).toBe(320); + }); + + it('rejects foreign formats and trailing data after IEND', () => { + for (const data of [ + Buffer.from('GIF89a' + 'x'.repeat(40)), + Buffer.from('plain text, not an image'), + Buffer.alloc(0), + ]) + expect(rejection(() => inspect(data)).reason).toBe( + 'unsupported_media_type', + ); + expect( + rejection(() => inspect(Buffer.concat([png, Buffer.from([0])]))) + .reason, + ).toBe('unsupported_media_type'); + }); + + it('accepts padded and noise PNGs of exact sizes', () => { + for (const size of [131_072, 1_048_576]) { + const data = noisePng(size); + expect(data.length).toBe(size); + expect(inspect(data).width).toBe(1024); + } + }); + + it('tolerates trailing data after JPEG EOI', () => { + expect( + inspect(Buffer.concat([jpeg, Buffer.from('MPF trailer')])).height, + ).toBe(200); + }); +}); diff --git a/app/src/attachments/image/image-inspector.ts b/app/src/attachments/image/image-inspector.ts new file mode 100644 index 00000000..eb041265 --- /dev/null +++ b/app/src/attachments/image/image-inspector.ts @@ -0,0 +1,387 @@ +import { crc32 } from 'node:zlib'; + +export const IMAGE_HEADER_MAX_BYTES = 1_048_576; + +export type ImageHeader = { + contentType: 'image/png' | 'image/jpeg'; + width: number; + height: number; +}; + +export class ImageRejectedError extends Error { + constructor( + readonly reason: 'unsupported_media_type' | 'too_many_pixels', + message: string, + ) { + super(message); + this.name = 'ImageRejectedError'; + } +} + +const PNG_SIGNATURE = Buffer.from([ + 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, +]); +const PNG_MAX_DIMENSION = 2 ** 31 - 1; +const PNG_BIT_DEPTHS: Record = { + 0: [1, 2, 4, 8, 16], + 2: [8, 16], + 3: [1, 2, 4, 8], + 4: [8, 16], + 6: [8, 16], +}; +const SOF_MARKERS = new Set([ + 0xc0, 0xc1, 0xc2, 0xc3, 0xc5, 0xc6, 0xc7, 0xc9, 0xca, 0xcb, 0xcd, 0xce, + 0xcf, +]); + +type State = + | 'start' + // PNG + | 'png_chunk_head' + | 'png_ihdr' + | 'png_skip' + | 'png_crc' + | 'png_done' + // JPEG + | 'jpeg_marker' + | 'jpeg_code' + | 'jpeg_length' + | 'jpeg_sof' + | 'jpeg_skip' + | 'jpeg_entropy' + | 'jpeg_entropy_ff' + | 'jpeg_trailer'; + +function unsupported(message: string): ImageRejectedError { + return new ImageRejectedError('unsupported_media_type', message); +} + +/** + * Streaming structural validator for PNG and JPEG. It never buffers the body: + * only fixed-size fields (chunk headers, IHDR, SOF) are accumulated, and + * nothing is decompressed. + */ +export class ImageInspector { + private state: State = 'start'; + private imageHeader: ImageHeader | undefined; + + // Accumulator for fixed-length fields. + private field = Buffer.alloc(16); + private fieldNeed = 0; + private fieldLength = 0; + + // Remaining bytes to skip in png_skip / jpeg_skip. + private skip = 0; + + // PNG + private chunkType = ''; + private chunkLength = 0; + private crc = 0; + private firstChunk = true; + private seenIdat = false; + + // JPEG + private marker = 0; + private scans = 0; + private afterSkip: State = 'jpeg_marker'; + + constructor(private readonly maxPixels: number) {} + + get header(): ImageHeader | undefined { + return this.imageHeader; + } + + push(chunk: Buffer): void { + let offset = 0; + while (offset < chunk.length) offset = this.step(chunk, offset); + } + + finish(): ImageHeader { + const done = this.state === 'png_done' || this.state === 'jpeg_trailer'; + if (!done || this.imageHeader === undefined) + throw unsupported('Image data is incomplete'); + return this.imageHeader; + } + + private collect(need: number): void { + this.fieldNeed = need; + this.fieldLength = 0; + } + + /** Copies up to fieldNeed bytes; returns new offset and whether complete. */ + private fill(chunk: Buffer, offset: number): [number, boolean] { + const take = Math.min( + this.fieldNeed - this.fieldLength, + chunk.length - offset, + ); + chunk.copy(this.field, this.fieldLength, offset, offset + take); + this.fieldLength += take; + return [offset + take, this.fieldLength === this.fieldNeed]; + } + + private step(chunk: Buffer, offset: number): number { + switch (this.state) { + case 'start': + return this.stepStart(chunk, offset); + case 'png_chunk_head': + case 'png_ihdr': + case 'png_crc': + case 'jpeg_length': + case 'jpeg_sof': { + const [next, complete] = this.fill(chunk, offset); + if (complete) this.fieldDone(); + return next; + } + case 'png_skip': + case 'jpeg_skip': { + const take = Math.min(this.skip, chunk.length - offset); + if (this.state === 'png_skip') + this.crc = crc32( + chunk.subarray(offset, offset + take), + this.crc, + ); + this.skip -= take; + if (this.skip === 0) this.skipDone(); + return offset + take; + } + case 'png_done': + throw unsupported('Data after the PNG end chunk'); + case 'jpeg_marker': + if (chunk[offset] !== 0xff) + throw unsupported('Unexpected byte between JPEG segments'); + this.state = 'jpeg_code'; + return offset + 1; + case 'jpeg_code': + this.onMarkerCode(chunk[offset]); + return offset + 1; + case 'jpeg_entropy': { + const next = chunk.indexOf(0xff, offset); + if (next === -1) return chunk.length; + this.state = 'jpeg_entropy_ff'; + return next + 1; + } + case 'jpeg_entropy_ff': { + const byte = chunk[offset]; + if (byte === 0xff) return offset + 1; + if (byte === 0x00 || (byte >= 0xd0 && byte <= 0xd7)) { + this.state = 'jpeg_entropy'; + return offset + 1; + } + this.onMarkerCode(byte); + return offset + 1; + } + case 'jpeg_trailer': + return chunk.length; + } + } + + private stepStart(chunk: Buffer, offset: number): number { + // Accumulate until the type is certain: 3 bytes for JPEG, 8 for PNG. + if (this.fieldLength === 0 && this.fieldNeed === 0) this.collect(8); + const have = this.fieldLength; + const take = Math.min(this.fieldNeed - have, chunk.length - offset); + chunk.copy(this.field, have, offset, offset + take); + this.fieldLength += take; + const first = this.field[0]; + if (first === 0xff) { + if (this.fieldLength >= 3) { + if (this.field[1] !== 0xd8 || this.field[2] !== 0xff) + throw unsupported('Not a JPEG file'); + // The third byte opens the next marker. + this.state = 'jpeg_code'; + this.fieldNeed = 0; + this.fieldLength = 0; + return offset + (3 - have); + } + return offset + take; + } + if (first === PNG_SIGNATURE[0]) { + for (let index = 0; index < this.fieldLength; index += 1) + if (this.field[index] !== PNG_SIGNATURE[index]) + throw unsupported('Not a PNG file'); + if (this.fieldLength === 8) { + this.state = 'png_chunk_head'; + this.collect(8); + } + return offset + take; + } + throw unsupported('Unsupported image format'); + } + + private fieldDone(): void { + switch (this.state) { + case 'png_chunk_head': + this.onPngChunkHead(); + return; + case 'png_ihdr': + this.crc = crc32(this.field.subarray(0, 13), this.crc); + this.parseIhdr(); + this.state = 'png_crc'; + this.collect(4); + return; + case 'png_crc': { + const expected = this.field.readUInt32BE(0); + if (this.crc >>> 0 !== expected) + throw unsupported('PNG chunk checksum mismatch'); + this.onPngChunkEnd(); + return; + } + case 'jpeg_length': + this.onJpegLength(); + return; + case 'jpeg_sof': + this.onJpegSof(); + return; + default: + return; + } + } + + private skipDone(): void { + if (this.state === 'png_skip') { + this.state = 'png_crc'; + this.collect(4); + } else { + this.state = this.afterSkip; + } + } + + // ---- PNG ---- + + private onPngChunkHead(): void { + const length = this.field.readUInt32BE(0); + const type = this.field.toString('latin1', 4, 8); + if (length > PNG_MAX_DIMENSION) + throw unsupported('PNG chunk is too long'); + if (!/^[A-Za-z]{4}$/u.test(type)) + throw unsupported('PNG chunk type is invalid'); + if (this.firstChunk) { + if (type !== 'IHDR' || length !== 13) + throw unsupported('PNG must start with IHDR'); + this.firstChunk = false; + } else if (type === 'IHDR') { + throw unsupported('Duplicate PNG IHDR'); + } + if (type === 'IEND') { + if (length !== 0 || !this.seenIdat) + throw unsupported('PNG IEND is invalid'); + } + if (type === 'IDAT') this.seenIdat = true; + this.chunkType = type; + this.chunkLength = length; + this.crc = crc32(this.field.subarray(4, 8), 0); + if (type === 'IHDR') { + this.state = 'png_ihdr'; + this.collect(13); + } else if (length === 0) { + this.state = 'png_crc'; + this.collect(4); + } else { + this.state = 'png_skip'; + this.skip = length; + } + } + + private parseIhdr(): void { + const width = this.field.readUInt32BE(0); + const height = this.field.readUInt32BE(4); + const bitDepth = this.field[8]; + const colorType = this.field[9]; + if (width < 1 || width > PNG_MAX_DIMENSION) + throw unsupported('PNG width is invalid'); + if (height < 1 || height > PNG_MAX_DIMENSION) + throw unsupported('PNG height is invalid'); + if (!PNG_BIT_DEPTHS[colorType]?.includes(bitDepth)) + throw unsupported('PNG color type / bit depth is invalid'); + if (this.field[10] !== 0 || this.field[11] !== 0) + throw unsupported('PNG compression/filter method is invalid'); + if (this.field[12] > 1) + throw unsupported('PNG interlace method is invalid'); + this.pendingHeader = { contentType: 'image/png', width, height }; + } + + private pendingHeader: ImageHeader | undefined; + + private onPngChunkEnd(): void { + if (this.chunkType === 'IHDR' && this.pendingHeader) { + const { width, height } = this.pendingHeader; + if (width * height > this.maxPixels) + throw new ImageRejectedError( + 'too_many_pixels', + 'Image has too many pixels', + ); + this.imageHeader = this.pendingHeader; + } + if (this.chunkType === 'IEND') { + this.state = 'png_done'; + return; + } + this.state = 'png_chunk_head'; + this.collect(8); + } + + // ---- JPEG ---- + + private onMarkerCode(code: number): void { + if (code === 0xff) return; // fill byte + this.marker = code; + if (code === 0x00 || code === 0xd8) + throw unsupported('Unexpected JPEG marker'); + if (code === 0x01 || (code >= 0xd0 && code <= 0xd7)) { + this.state = 'jpeg_marker'; + return; + } + if (code === 0xd9) { + if (this.imageHeader === undefined || this.scans === 0) + throw unsupported('JPEG ended before image data'); + this.state = 'jpeg_trailer'; + return; + } + if (code === 0xda && this.imageHeader === undefined) + throw unsupported('JPEG scan before frame header'); + this.state = 'jpeg_length'; + this.collect(2); + } + + private onJpegLength(): void { + const length = this.field.readUInt16BE(0); + if (length < 2) throw unsupported('JPEG segment length is invalid'); + const dataLength = length - 2; + if (SOF_MARKERS.has(this.marker)) { + if (this.imageHeader !== undefined || this.pendingHeader) + throw unsupported('Duplicate JPEG frame header'); + if (dataLength < 6) throw unsupported('JPEG frame header is short'); + this.skip = dataLength - 6; + this.afterSkip = 'jpeg_marker'; + this.state = 'jpeg_sof'; + this.collect(6); + return; + } + if (this.marker === 0xda) { + this.scans += 1; + this.afterSkip = 'jpeg_entropy'; + } else { + this.afterSkip = 'jpeg_marker'; + } + if (dataLength === 0) this.state = this.afterSkip; + else { + this.skip = dataLength; + this.state = 'jpeg_skip'; + } + } + + private onJpegSof(): void { + const height = this.field.readUInt16BE(1); + const width = this.field.readUInt16BE(3); + if (width === 0 || height === 0 || this.field[5] === 0) + throw unsupported('JPEG dimensions are invalid'); + if (width * height > this.maxPixels) + throw new ImageRejectedError( + 'too_many_pixels', + 'Image has too many pixels', + ); + this.imageHeader = { contentType: 'image/jpeg', width, height }; + if (this.skip === 0) this.state = 'jpeg_marker'; + else this.state = 'jpeg_skip'; + } +} diff --git a/app/src/database/migrations/005_attachments.sql b/app/src/database/migrations/005_attachments.sql new file mode 100644 index 00000000..a6c9d811 --- /dev/null +++ b/app/src/database/migrations/005_attachments.sql @@ -0,0 +1,42 @@ +ALTER TABLE messages ADD CONSTRAINT messages_id_chat_key UNIQUE (id, chat_id); + +CREATE TABLE attachments ( + id uuid PRIMARY KEY, + chat_id uuid NOT NULL REFERENCES chats(id) ON DELETE CASCADE, + owner_id uuid NOT NULL REFERENCES users(id) ON DELETE RESTRICT, + filename text NOT NULL CHECK (char_length(filename) BETWEEN 1 AND 255), + content_type text NOT NULL CHECK (content_type IN ('image/png', 'image/jpeg')), + upload_mode text NOT NULL CHECK (upload_mode IN ('proxy', 'direct')), + status text NOT NULL CHECK (status IN ('pending', 'ready', 'deleting')), + object_key text NOT NULL UNIQUE, + size_bytes bigint CHECK (size_bytes BETWEEN 1 AND 10485760), + sha256 text CHECK (sha256 ~ '^[a-f0-9]{64}$'), + width integer CHECK (width > 0), + height integer CHECK (height > 0), + expires_at timestamptz(3), + created_at timestamptz(3) NOT NULL DEFAULT now(), + updated_at timestamptz(3) NOT NULL DEFAULT now(), + CONSTRAINT attachments_id_chat_key UNIQUE (id, chat_id), + CONSTRAINT attachments_owner_member_fk FOREIGN KEY (chat_id, owner_id) + REFERENCES chat_members (chat_id, user_id), + CONSTRAINT attachments_ready_complete CHECK (status <> 'ready' OR + (size_bytes IS NOT NULL AND sha256 IS NOT NULL AND width IS NOT NULL AND height IS NOT NULL)), + CONSTRAINT attachments_unfinished_expiry CHECK (status = 'ready' OR expires_at IS NOT NULL) +); +CREATE INDEX attachments_unfinished_idx ON attachments (expires_at) WHERE status <> 'ready'; +CREATE INDEX attachments_owner_direct_pending_idx ON attachments (owner_id) + WHERE status = 'pending' AND upload_mode = 'direct'; + +CREATE TABLE message_attachments ( + message_id uuid NOT NULL, + chat_id uuid NOT NULL, + attachment_id uuid NOT NULL, + ordinal smallint NOT NULL CHECK (ordinal BETWEEN 1 AND 10), + PRIMARY KEY (message_id, attachment_id), + CONSTRAINT message_attachments_ordinal_key UNIQUE (message_id, ordinal), + CONSTRAINT message_attachments_message_fk FOREIGN KEY (message_id, chat_id) + REFERENCES messages (id, chat_id) ON DELETE CASCADE, + CONSTRAINT message_attachments_attachment_fk FOREIGN KEY (attachment_id, chat_id) + REFERENCES attachments (id, chat_id) +); +CREATE INDEX message_attachments_attachment_idx ON message_attachments (attachment_id); diff --git a/app/test/fixtures/sample-progressive.jpg b/app/test/fixtures/sample-progressive.jpg new file mode 100644 index 0000000000000000000000000000000000000000..eed80152996e3a0dca2a2178deb7e430065cd816 GIT binary patch literal 4891 zcmbVP3n0|l8lUl+sVU8bX&UmFbR!Kt4CB$25k;3w8S*wOkMSJBhT1L}B;=85CuwI0 zJ2g^5Atf!ci#(c4Elct$ZA`mLTe;^yUU9cw?fIYi&-Z=jobUX;*Eutjos&H{!QkM5O+JB{!K5Xnq@*OJ!An|NS_ZKUi2!W{3bkYzX2r^tm=zd|99C(SoIG9u zgTblc@N3qnsHn)TBB&FT)s>W0lp!T>uoNMKkVPV8mE|$=%3s_j@4_%hSOa{!B%A<~ zz`!Lj@X32HJb)^0u$d+Smz09ZAi$U+93~+N24_ZK5Gy4k4MR*mhAoo>qi9Jqu=733 zNVv-y6=v;QrA6u175H^CI6>vRxiMkfZYzObX9X4FMr~>%wa;t~aMdWc6C`c5HapaQ z^Bi55*hAi}KEdYUdGAx`F<>#QWjumFeMXjGMXM zXLO0pzjsug{=JiNlN)quf6&)OoS(~!YOR_xbsal{8|+JuDkyM**ZFS^u;)~CX(vgy zotWBqqrTm*Cu$6d&uj()<3{wwC{Tym9WO=ZvnmAF-M}imKPkYTbz7eQ;INaHIp42x zYtlorNSce*Iy>#JX~J;_+VX)?CV#hWY1b9M&`N4B$${lfGjH;bcDwIyUe(yGP{_xY z@?P3#*%9BO+TF*BqT9`@ul=l>g6)e6M7-`kCo9qu<^||0Jh=I4z;&r2#=dDU=Y}?` z<>;0n+gE$}?2Be0xAb#9Mz_t|}~Gke1`QuZGPl z3c{Fj-0s~Me|oaYiuiEKlX(BF!MYv#I|ND6zRq>*pPn?4mcRW$JM-y7E8?Z_R_*W# z?CZjt5yo8XL{P=L=5or&Mwd$L56jEBzoAgA<~Q8kTu&UKm;L4zLyyuZm)6m4+FR?_ z6^1$=#JUZS*z;DP@3q{%n-le9`Cw%?DLZH!f9A^G!?);FFZ}CDl7wb{qUWdFDBWJy z`h+zBEZ#)8&!YzCmI#+8T6wx}i9qC}=5P6R zl^>IM0s++dkdVmr}0y$h-;$zzftzGUrh-!f-UrO8P^*A+DBbwEZq=@3wA}Q$G zH9Fik?FBZOu}qsKHH#qX2iz4tXsE`@Y)+0vs(RuY7Lt_FvNBd_o*L4Lf=w%9^&fsT z=#Kr|yP6g*9 zbW&o(E(QKJfs^nl7P-{I4!`+CURYvkdKz|uk>j@mX#J-a+YiSguWtXJ(g^zK!tb z?1C--#Xs=ya#9M0%JmaiJ2e!xD&YT0luNnpYk%C*QBzA-%Yx;5Dk~$S;DlSo1=Ka2?G)MysU?bfo}ON2UKT$E2vcUKko!_U=_eM-6Dt)SAz#(L!hExS-#o{_a3KakRjwYaI7OP39Ng(5p1au4# zsqTAShFt zCvFD;1?XZxxLsHcpyTe;$!yvzCS78Zmw9+f;ubaVMZsJ!`R@Yvry-sf&G|+y%;h<^ zPAAb=Lb5TvPnj|GtiT1GzF<&ldn^bnP>Ml9(NzV61QfTJ*#WfaOnyNS z!Sq?!puQ5pY;j(IU_gT)5TL+Jt{_txKJhnr zy!GU+TcUIo!`1qDCm>gxm3sYaZ5j zPeKw>Iz1!nbHX3}0*M~z2VU!8q}0RBDCw3Tu)rBU-i{U$Pb;B zkYK`(2U?P5S>VFYNW4m1`g1c;-pRcx6lfBUf4W)lqmRE=N$EA=V_`tKbAeJK$zcjPPg5=i7lq|{DCEk z)0WI#w!o6~)-g`+>^+P2cM_EHr(cgY_Ma~)3vFKg#K=cXGMgPCvKL6_&D-ht@t6U5 zk7!A&;AmmX=#r17CJ%hxB~QZ8+1cygB@ewYAlul;4RU2y1?)L6g3`Bp*7q7;xH$gJ8R3_ZGvGs~z)zVZwxfTZ`a2)S51Je~f8O{) z`m@1znnp z(&_KD60&M*VpzwHp-_?tt(cf&r)q0i#}XuM7)=HR#M3`|l`N7fZxH9x+>6WOae3_& zw)}&9R`%t7A1#A@|A3hgHqO9hqY`;PZvTE9 znOV&2@$l%WY4q@*gHHG8seS8!5Iv-Uy+EVV9O~S*jGalY>K$A`j;#F$Og*S~bA>77 z%+a3SJGHejF)UV0LW1N9tpwok6*4l)N=js$i9`?GgWhvz88MC;!c(ez&x}Uk}8q@(RIL U;KSoBC2*5A6n@7`Iyx!*AA%PG5dZ)H literal 0 HcmV?d00001 diff --git a/app/test/fixtures/sample.jpg b/app/test/fixtures/sample.jpg new file mode 100644 index 0000000000000000000000000000000000000000..708a5aeef83f6f6e4dc9df6944d19622739dabf0 GIT binary patch literal 4726 zcmb7I4LH>479U2~TTIgwF_;WH*{!tAPgd#!|A|3+|VPOH*Nx6Pfrg&0X`;7n4oVk$lMfOA3WTGNsy5t!yo?I1OK(bCCVYi3S&6h~0DWoO`+PmmPY~828JTZO-wjP{Ru}R@M zx;0^B>trg|kIEh1x>_K?wj$If>EwmxiTnRUW9^`^G8eig?gN4Z%s7m?Z3GpcEmwqK zP+!~RD6~|_xWf=RnFP1zVg8CgfEEC#p_~;!W07GiUze%KKaH!~ExqYzH8Xv}!F+cI z(V-m)(z4dpH2lU!9xTOmtXY^LS2Gno3~^1`!0#7=`7yQgvzm9mpLclqo#RbC^x3ao z6-F@LJ-HS)Af~V#KIvyjTDj5r@!%}qZWJ$=`78HLyiJfrrW;3i78wwZNRvzV?3m{g4+|B8V&hEf3(hn{wqq|{TJdn%& zxL7PR-!~w|!m0u9Vx`W-PFkPq(Ru2GY}!J zR(h-=fK-Hw@3(SK3?X#|Q+bvnsJ4BxHK>cvNOmp*8V1DSiKwbWGr7@_Z6zQwJlxt+ z{kmLZr&rEwzBkMzg)nYv#il0{>9dIRIcwCNtGHCA;yhCkS69t-vE>{n<_H2VG;b1-8vQ*nW*$Z-m~%$}gV|hjI{3Y$dd`|qALLNUj@@ihx%ZHGfwk< z#vzbw&q}WQD1J1%F?p;N-|YD9$(X?KCD{mAdK7Ww66yALTH6qcIFQj5v|!!Zh3^@gQ4Uo879RTc?s=#$J-I`;)N#~TVMsrRFPZS7p;nNR z66H^0DrAV1U-x+BY%F>nBH0RJa-!>paCf5@XG{C(SV)?*`IOP^o}jcPR|oT#ZAQw2 z5E{g5)kg(t<(bKLuU00;o^`tYdbfXRQ^4|loCJ%k&5gWS^}8=n+|IptPy3N& zD4nYGyWGk6>9woRjTpa*Zijy)LS&hdfv-6&W%cq6gxu#bRw98*@u)El(PUq(J6Oy) zfWV~Xy~k!nRfY8P1+u}ZRIaa!|AS(Lihq^6x5#^iymX8jjdRN%B+4m>g)9=d6Ic8% zVup_wjfLcKUc@Y)?2bvKv=skUL|3Nb)Q-Z_f;0&H%HH0rl$KNvl@@Uo(n&a0(=}-1 zB_ookEk~z+@Le#k_pAZRSeYzfS@@{&_+IzgAKSM%+V-)$K0|1uY5a7YG&)gQ211+U z;qRe}T(0Gnglo^EL7-1^GZ8B2*=B7`(c_4}(%vF6akZic?kVifn`{G>4_2mbE0tL* zoCmQgG#{%%sHR<;f}MB=;)+7V}^`30+V29z_B*6eA9nhLh~4EO^)TAH60VN)~SwW*=N${1F$ zP#GhXCWVznxD;6y3nZHfsgK`w7ZHRu0|_q&q8LXyA1{Govn8VF{(!l-%O-QMhXFrf zaQjbe?0z3xbbm=*77agY_PH^4`RPZ4WYK}HZve6qKuAd$reE~`q8!3~*>O?a6{|H* z`P?Eh3}e%m4Wus<{$8yV{$6ukAc>qSeDGWE5N@eW!1cq%qjq**p?i8*_cq5_clM2F z8;fiMYL#JS;Z&}tmM+9Yku(YrNf;M6Eiz1FXUhK0VGaW#(* zEx}_+Qpr)0j&wG7WBD|-*UB3O{=1sT0MC488!a`tE&Dc@$NpIP?p}RMl}P5=KQE1c zigmH&samQk%E5!R6pVIolUrq-wyVD?EqA8KDb`}9vs@bj`M=-H`(3K zFW)?Vu`~2CZflo`2Bk;IADk?@9rNksjH-h~^aAFAiLt<`_nT<)`svlY^iK_Y=yNS( zA&oph&QB?C{e97GSs8jeJAsC_Lv${IGV5G}k+ao*TC26UAZfN3n6-YuM#Nf!V z_Qx@hz6!f4cMcE5R1YQvBvv*Yy|IU{O-(oCj^x6wDXBpTG`6Im^E{I3VXd8TDABnr zaGwLMC+dPV^#W^M*T^o_(?=WP{h2h>nr0U0YZ~f|$qUI?Lyfv*)cQh~3}63m>kADz z*7{;pSU;@=UHI2QF9urcBGpXe(k5%gcuM1&PBu2wN>hYU{+ppATRI>Ny!Bzw{qubX zkSW9zJ~m0{GrqM}cib4lu`^~^+OI#_C%ykd{Zx30sW`TmR>XVFpTw?kIsIh{k57xd zwkxXfH@IA!Zf)t!%KBBV4)*HY)>c_jQjj$trU2i5<0`?2LCbwY1Rd-@r(sVfv^WFt zfyIL#MP7>*tSea9$v9b&Q=ml;=`GT?2}-*SrXmuy8VNProwOl0mT$zappU?uU@FdT zQ0#JD{Hej*TiI zt|N6Yz4lpkXwGN5uk3so1Q|+&hV-OHWzsE{5TaqsHFWFX0qmkT8;4#Wc%qvOe*g0dX(rCz>}tB_73XgS!u;l2K)nd)*X_v>W_ z+2M@1_H}F8z&GcL5`T}0znV?O2v)6uh5BRFKnE4!ryAdTo2}JmD^j-P0K0Kl@7xL`Jxbl+d zJNZJCKaOxI;L{+72^QSeK_m96O;qkz9!9UEkgvN9g=w)VIo)e*;eF(js~BKEY^8Ls zsH=-^-3n2(C`gcgc~;LlM|t^X*-&4O1<==!2yZ` zG$O`}%8)lWFA%kif3K5?*g6$EUL)7WVIJ9{7E4`G=%(x zgg)0l$5Fl2C{ZAZ?l#JnpW0~%`@gmc?IN3%!D3vVgVAC5&w%KjR7c=Ui=g(jIsySy g64*8iZ6j$-0nRU3Z4Wm+nv;=@q@iuT9z*K?0+^xq^#A|> literal 0 HcmV?d00001 diff --git a/app/test/support/png.ts b/app/test/support/png.ts new file mode 100644 index 00000000..9dd29a41 --- /dev/null +++ b/app/test/support/png.ts @@ -0,0 +1,95 @@ +import { randomBytes } from 'node:crypto'; +import { crc32, deflateSync } from 'node:zlib'; + +const SIGNATURE = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]); + +function chunk(type: string, data: Buffer): Buffer { + const head = Buffer.alloc(8); + head.writeUInt32BE(data.length, 0); + head.write(type, 4, 'latin1'); + const crc = Buffer.alloc(4); + crc.writeUInt32BE(crc32(Buffer.concat([head.subarray(4), data])) >>> 0, 0); + return Buffer.concat([head, data, crc]); +} + +export function buildPng(options: { + width: number; + height: number; + colorType: number; + bitDepth: number; + idat: Buffer; +}): Buffer { + const ihdr = Buffer.alloc(13); + ihdr.writeUInt32BE(options.width, 0); + ihdr.writeUInt32BE(options.height, 4); + ihdr[8] = options.bitDepth; + ihdr[9] = options.colorType; + return Buffer.concat([ + SIGNATURE, + chunk('IHDR', ihdr), + chunk('IDAT', options.idat), + chunk('IEND', Buffer.alloc(0)), + ]); +} + +/** Inserts a private ancillary chunk before IEND to reach exactly `size` bytes. */ +export function padPngTo(png: Buffer, size: number): Buffer { + const extra = size - png.length; + if (extra === 0) return png; + if (extra < 12) throw new Error('PNG padding needs at least 12 bytes'); + const iend = png.length - 12; + return Buffer.concat([ + png.subarray(0, iend), + chunk('prVt', Buffer.alloc(extra - 12)), + png.subarray(iend), + ]); +} + +/** 8000x5001 grayscale 1-bit, all-zero rows: tiny file, 40 008 000 pixels. */ +export function pixelBombPng(): Buffer { + const width = 8000; + const height = 5001; + const row = Buffer.alloc(1 + Math.ceil(width / 8)); + const raw = Buffer.alloc(row.length * height); + return buildPng({ + width, + height, + colorType: 0, + bitDepth: 1, + idat: deflateSync(raw, { level: 9 }), + }); +} + +const NOISE_WIDTH = 1024; +const NOISE_ROW = 1 + NOISE_WIDTH * 3; + +function noiseOfHeight(height: number): Buffer { + const raw = randomBytes(NOISE_ROW * height); + for (let row = 0; row < height; row += 1) raw[row * NOISE_ROW] = 0; + return buildPng({ + width: NOISE_WIDTH, + height, + colorType: 2, + bitDepth: 8, + idat: deflateSync(raw, { level: 0 }), + }); +} + +/** Incompressible, structurally valid PNG of exactly `size` bytes. */ +export function noisePng(size: number): Buffer { + let height = Math.max(1, Math.floor(size / NOISE_ROW)); + for (;;) { + const png = noiseOfHeight(height); + if (png.length > size) { + height -= 1; + if (height < 1) throw new Error('size is too small for noisePng'); + continue; + } + const extra = size - png.length; + if (extra > 0 && extra < 12) { + height -= 1; + continue; + } + return padPngTo(png, size); + } +} -- 2.54.0 From 6fcc623447d002b3a73d3e31ee9c2836c12b93e8 Mon Sep 17 00:00:00 2001 From: Ilya Date: Thu, 22 Oct 2026 22:28:54 +0300 Subject: [PATCH 04/15] =?UTF-8?q?lab4:=20=D0=B2=D0=BB=D0=BE=D0=B6=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20(proxy=20upload,=20download,=20=D1=83?= =?UTF-8?q?=D0=B1=D0=BE=D1=80=D1=89=D0=B8=D0=BA),=20attachment=5Fids=20?= =?UTF-8?q?=D0=B2=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/package.json | 1 + app/src/app.module.ts | 2 + .../attachments/attachment-sweeper.service.ts | 78 +++++ app/src/attachments/attachment.ts | 49 +++ app/src/attachments/attachments-sweep.cli.ts | 42 +++ app/src/attachments/attachments.controller.ts | 89 +++++ app/src/attachments/attachments.module.ts | 26 ++ app/src/attachments/attachments.repository.ts | 156 +++++++++ app/src/attachments/attachments.service.ts | 325 ++++++++++++++++++ app/src/attachments/filename.ts | 34 ++ app/src/config/app-config.schema.ts | 21 +- app/src/database/database.client.ts | 7 +- app/src/main.ts | 16 +- app/src/messages/dto/create-message.dto.ts | 19 +- .../idempotency.repository.spec.ts | 9 +- .../idempotency/idempotency.repository.ts | 36 +- app/src/messages/idempotency/idempotency.ts | 14 +- app/src/messages/message.ts | 1 + app/src/messages/messages.module.ts | 2 + app/src/messages/messages.repository.spec.ts | 31 +- app/src/messages/messages.repository.ts | 22 +- app/src/messages/messages.service.spec.ts | 56 +-- app/src/messages/messages.service.ts | 29 +- 23 files changed, 959 insertions(+), 106 deletions(-) create mode 100644 app/src/attachments/attachment-sweeper.service.ts create mode 100644 app/src/attachments/attachment.ts create mode 100644 app/src/attachments/attachments-sweep.cli.ts create mode 100644 app/src/attachments/attachments.controller.ts create mode 100644 app/src/attachments/attachments.module.ts create mode 100644 app/src/attachments/attachments.repository.ts create mode 100644 app/src/attachments/attachments.service.ts create mode 100644 app/src/attachments/filename.ts diff --git a/app/package.json b/app/package.json index c308530d..3b58c6c2 100644 --- a/app/package.json +++ b/app/package.json @@ -23,6 +23,7 @@ "graph": "npm run build && DATABASE_URL=postgresql://graph-only.invalid/messenger REDIS_URL=redis://graph-only.invalid:6379 tsx scripts/graph-modules.ts", "test:e2e": "vitest run --config ./vitest.config.e2e.ts", "test:dependencies": "E2E_DEPENDENCY_FAULTS=1 vitest run --config ./vitest.config.e2e.ts dependency-failures", + "attachments:sweep": "tsx src/attachments/attachments-sweep.cli.ts", "idempotency:gc": "tsx src/messages/idempotency/idempotency-gc.cli.ts" }, "dependencies": { diff --git a/app/src/app.module.ts b/app/src/app.module.ts index c731b7a4..220c60aa 100644 --- a/app/src/app.module.ts +++ b/app/src/app.module.ts @@ -5,6 +5,7 @@ import { RedisModule } from './redis/redis.module.js'; import { AuthModule } from './auth/auth.module.js'; import { ChatsModule } from './chats/chats.module.js'; import { HealthModule } from './health/health.module.js'; +import { AttachmentsModule } from './attachments/attachments.module.js'; import { MessagesModule } from './messages/messages.module.js'; import { MetricsModule } from './metrics/metrics.module.js'; import { UsersModule } from './users/users.module.js'; @@ -21,6 +22,7 @@ import { ApiExceptionFilter } from './common/errors/api-exception.filter.js'; HealthModule, ChatsModule, MessagesModule, + AttachmentsModule, MetricsModule, ], providers: [ diff --git a/app/src/attachments/attachment-sweeper.service.ts b/app/src/attachments/attachment-sweeper.service.ts new file mode 100644 index 00000000..83b429c9 --- /dev/null +++ b/app/src/attachments/attachment-sweeper.service.ts @@ -0,0 +1,78 @@ +import { + Injectable, + Logger, + OnModuleDestroy, + OnModuleInit, +} from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; +import type { AppConfig } from '../config/app-config.schema.js'; +import { MetricsService } from '../metrics/metrics.service.js'; +import { ObjectStorage } from '../storage/object-storage.js'; +import { AttachmentsRepository } from './attachments.repository.js'; + +const SWEEP_BATCH = 100; + +/** + * Removes unfinished uploads (pending past expiry + grace) and rows whose + * deletion was claimed but never finished. A live upload is never touched: + * its expiry is a hard request deadline and the grace period is far longer. + */ +@Injectable() +export class AttachmentSweeper implements OnModuleInit, OnModuleDestroy { + private readonly logger = new Logger(AttachmentSweeper.name); + private timer: NodeJS.Timeout | undefined; + private running = false; + + constructor( + private readonly config: ConfigService, + private readonly repository: AttachmentsRepository, + private readonly storage: ObjectStorage, + private readonly metrics: MetricsService, + ) {} + + onModuleInit(): void { + const interval = this.config.getOrThrow('ATTACHMENT_SWEEP_INTERVAL_MS'); + if (interval <= 0) return; + this.timer = setInterval(() => { + if (this.running) return; + this.running = true; + this.sweepOnce() + .catch((error: unknown) => { + this.logger.warn( + `Sweep failed: ${error instanceof Error ? error.message : 'unknown error'}`, + ); + }) + .finally(() => { + this.running = false; + }); + }, interval); + this.timer.unref(); + } + + onModuleDestroy(): void { + if (this.timer) clearInterval(this.timer); + this.timer = undefined; + } + + async sweepOnce(): Promise<{ claimed: number; deleted: number }> { + const claimed = await this.repository.claimExpired( + this.config.getOrThrow('ATTACHMENT_SWEEP_GRACE_SECONDS'), + SWEEP_BATCH, + ); + let deleted = 0; + for (const item of claimed) { + try { + await this.storage.delete(item.object_key); + await this.repository.deleteClaimed(item.id); + deleted += 1; + this.metrics.increment('attachments.sweep.deleted'); + } catch (error) { + this.metrics.increment('attachments.sweep.error'); + this.logger.warn( + `Sweep of attachment ${item.id} failed: ${error instanceof Error ? error.message : 'unknown error'}`, + ); + } + } + return { claimed: claimed.length, deleted }; + } +} diff --git a/app/src/attachments/attachment.ts b/app/src/attachments/attachment.ts new file mode 100644 index 00000000..86a0733d --- /dev/null +++ b/app/src/attachments/attachment.ts @@ -0,0 +1,49 @@ +export type Attachment = { + id: string; + chat_id: string; + owner_id: string; + filename: string; + content_type: 'image/png' | 'image/jpeg'; + size_bytes: number; + sha256: string; + status: 'ready'; + variants: never[]; + error_code: null; + created_at: string; + updated_at: string; +}; + +export type AttachmentRow = { + id: string; + chat_id: string; + owner_id: string; + filename: string; + content_type: 'image/png' | 'image/jpeg'; + upload_mode: 'proxy' | 'direct'; + status: 'pending' | 'ready' | 'deleting'; + object_key: string; + size_bytes: string | number | null; + sha256: string | null; + width: number | null; + height: number | null; + expires_at: Date | null; + created_at: Date; + updated_at: Date; +}; + +export function toAttachment(row: AttachmentRow): Attachment { + return { + id: row.id, + chat_id: row.chat_id, + owner_id: row.owner_id, + filename: row.filename, + content_type: row.content_type, + size_bytes: Number(row.size_bytes), + sha256: row.sha256 as string, + status: 'ready', + variants: [], + error_code: null, + created_at: row.created_at.toISOString(), + updated_at: row.updated_at.toISOString(), + }; +} diff --git a/app/src/attachments/attachments-sweep.cli.ts b/app/src/attachments/attachments-sweep.cli.ts new file mode 100644 index 00000000..91d0c36f --- /dev/null +++ b/app/src/attachments/attachments-sweep.cli.ts @@ -0,0 +1,42 @@ +import { fileURLToPath } from 'node:url'; +import { parseAppConfig } from '../config/app-config.schema.js'; +import { DatabaseClient } from '../database/database.client.js'; +import { MetricsService } from '../metrics/metrics.service.js'; +import { ObjectStorage } from '../storage/object-storage.js'; +import { AttachmentSweeper } from './attachment-sweeper.service.js'; +import { AttachmentsRepository } from './attachments.repository.js'; + +// Manual operator pass over unfinished uploads (the API also sweeps in the +// background). Never touches rows before expiry + ATTACHMENT_SWEEP_GRACE_SECONDS. +// in the stand: docker compose exec api node dist/attachments/attachments-sweep.cli.js +// on the host: npm run attachments:sweep (needs reachable DATABASE_URL and S3) +async function main(): Promise { + const config = parseAppConfig(process.env as Record); + const configService = { + getOrThrow: (key: keyof typeof config) => config[key], + } as never; + const metrics = new MetricsService(); + const database = new DatabaseClient(configService, metrics); + try { + const sweeper = new AttachmentSweeper( + configService, + new AttachmentsRepository(database), + new ObjectStorage(configService), + metrics, + ); + let total = 0; + for (;;) { + const { claimed, deleted } = await sweeper.sweepOnce(); + total += deleted; + // A pass that claimed rows but could not delete any would loop forever. + if (claimed === 0 || deleted === 0) break; + } + process.stdout.write( + `Swept ${total} attachment(s) older than ${config.ATTACHMENT_SWEEP_GRACE_SECONDS} seconds past expiry\n`, + ); + } finally { + await database.onModuleDestroy(); + } +} + +if (process.argv[1] === fileURLToPath(import.meta.url)) await main(); diff --git a/app/src/attachments/attachments.controller.ts b/app/src/attachments/attachments.controller.ts new file mode 100644 index 00000000..51db0352 --- /dev/null +++ b/app/src/attachments/attachments.controller.ts @@ -0,0 +1,89 @@ +import { + Controller, + Get, + Headers, + HttpCode, + Param, + ParseUUIDPipe, + Post, + Query, + Req, + Res, + StreamableFile, + UseGuards, +} from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; +import type { FastifyReply, FastifyRequest } from 'fastify'; +import type { Readable } from 'node:stream'; +import { CurrentUser } from '../common/auth/current-user.decorator.js'; +import { CurrentUserGuard } from '../common/auth/current-user.guard.js'; +import type { AppConfig } from '../config/app-config.schema.js'; +import type { User } from '../users/user.js'; +import { AttachmentsService } from './attachments.service.js'; +import { contentDisposition } from './filename.js'; + +@Controller('api/v1') +@UseGuards(CurrentUserGuard) +export class AttachmentsController { + private readonly maxUploadBytes: number; + + constructor( + private readonly attachments: AttachmentsService, + config: ConfigService, + ) { + this.maxUploadBytes = config.getOrThrow('MAX_UPLOAD_BYTES'); + } + + @Post('chats/:chatId/attachments') + @HttpCode(201) + upload( + @Param('chatId', new ParseUUIDPipe()) chatId: string, + @CurrentUser() user: User, + @Query('filename') filename: unknown, + @Headers('content-type') contentType: string | undefined, + @Headers('content-length') contentLength: string | undefined, + @Req() request: FastifyRequest, + @Res({ passthrough: true }) reply: FastifyReply, + ) { + // A gigantic body is not worth draining: close the connection after the answer. + if (Number(contentLength) > 2 * this.maxUploadBytes) + reply.header('Connection', 'close'); + return this.attachments.uploadProxy( + chatId, + user, + filename, + contentType, + contentLength, + request.body as Readable | undefined, + ); + } + + @Get('attachments/:attachmentId') + metadata( + @Param('attachmentId', new ParseUUIDPipe()) attachmentId: string, + @CurrentUser() user: User, + ) { + return this.attachments.getMetadata(attachmentId, user); + } + + @Get('attachments/:attachmentId/content') + async content( + @Param('attachmentId', new ParseUUIDPipe()) attachmentId: string, + @CurrentUser() user: User, + @Res({ passthrough: true }) reply: FastifyReply, + @Query('variant') variant?: string, + ) { + const { row, stream } = await this.attachments.openContent( + attachmentId, + user, + variant, + ); + reply.header('X-Content-Type-Options', 'nosniff'); + reply.header('Cache-Control', 'private, no-store'); + return new StreamableFile(stream, { + type: row.content_type, + length: Number(row.size_bytes), + disposition: contentDisposition(row.filename), + }); + } +} diff --git a/app/src/attachments/attachments.module.ts b/app/src/attachments/attachments.module.ts new file mode 100644 index 00000000..e1d1c1fc --- /dev/null +++ b/app/src/attachments/attachments.module.ts @@ -0,0 +1,26 @@ +import { Module } from '@nestjs/common'; +import { DatabaseModule } from '../database/database.module.js'; +import { ChatsModule } from '../chats/chats.module.js'; +import { UsersModule } from '../users/users.module.js'; +import { RedisModule } from '../redis/redis.module.js'; +import { MetricsModule } from '../metrics/metrics.module.js'; +import { StorageModule } from '../storage/storage.module.js'; +import { AttachmentSweeper } from './attachment-sweeper.service.js'; +import { AttachmentsController } from './attachments.controller.js'; +import { AttachmentsRepository } from './attachments.repository.js'; +import { AttachmentsService } from './attachments.service.js'; + +@Module({ + imports: [ + DatabaseModule, + ChatsModule, + UsersModule, + RedisModule, + MetricsModule, + StorageModule, + ], + controllers: [AttachmentsController], + providers: [AttachmentsRepository, AttachmentsService, AttachmentSweeper], + exports: [AttachmentsRepository], +}) +export class AttachmentsModule {} diff --git a/app/src/attachments/attachments.repository.ts b/app/src/attachments/attachments.repository.ts new file mode 100644 index 00000000..f846ed0e --- /dev/null +++ b/app/src/attachments/attachments.repository.ts @@ -0,0 +1,156 @@ +import { Injectable } from '@nestjs/common'; +import { DatabaseClient } from '../database/database.client.js'; +import type { AttachmentRow } from './attachment.js'; + +export type InsertPending = { + id: string; + chatId: string; + ownerId: string; + filename: string; + contentType: string; + uploadMode: 'proxy' | 'direct'; + objectKey: string; + sizeBytes: number | null; + sha256: string | null; + ttlMs: number; +}; + +export type ReadyFields = { + sizeBytes: number; + sha256: string; + width: number; + height: number; +}; + +const VISIBLE_MEMBER = `JOIN chat_members m ON m.chat_id = a.chat_id AND m.user_id = $2`; + +@Injectable() +export class AttachmentsRepository { + constructor(private readonly database: DatabaseClient) {} + + async insertPending(input: InsertPending): Promise { + await this.database.query( + 'attachments.insert_pending', + `INSERT INTO attachments + (id, chat_id, owner_id, filename, content_type, upload_mode, status, + object_key, size_bytes, sha256, expires_at) + VALUES ($1, $2, $3, $4, $5, $6, 'pending', $7, $8, $9, + now() + make_interval(secs => $10::double precision / 1000.0))`, + [ + input.id, + input.chatId, + input.ownerId, + input.filename, + input.contentType, + input.uploadMode, + input.objectKey, + input.sizeBytes, + input.sha256, + input.ttlMs, + ], + ); + } + + async markReady( + id: string, + fields: ReadyFields, + ): Promise { + const result = await this.database.query( + 'attachments.mark_ready', + `UPDATE attachments + SET status = 'ready', size_bytes = $2, sha256 = $3, width = $4, + height = $5, expires_at = NULL, updated_at = now() + WHERE id = $1 AND status = 'pending' + RETURNING *`, + [id, fields.sizeBytes, fields.sha256, fields.width, fields.height], + ); + return result.rows[0]; + } + + async deletePending(id: string): Promise { + await this.database.query( + 'attachments.delete_pending', + `DELETE FROM attachments WHERE id = $1 AND status = 'pending'`, + [id], + ); + } + + async findVisible( + id: string, + userId: string, + ): Promise { + const result = await this.database.query( + 'attachments.find_visible', + `SELECT a.* FROM attachments a ${VISIBLE_MEMBER} + WHERE a.id = $1 AND a.status = 'ready'`, + [id, userId], + ); + return result.rows[0]; + } + + async findForComplete( + id: string, + userId: string, + ): Promise { + const result = await this.database.query( + 'attachments.find_for_complete', + `SELECT a.* FROM attachments a ${VISIBLE_MEMBER} + WHERE a.id = $1 AND a.upload_mode = 'direct' AND a.owner_id = $2 + AND a.status IN ('pending', 'ready')`, + [id, userId], + ); + return result.rows[0]; + } + + async countPendingDirect(ownerId: string): Promise { + const result = await this.database.query<{ count: string }>( + 'attachments.count_pending_direct', + `SELECT count(*) AS count FROM attachments + WHERE owner_id = $1 AND status = 'pending' AND upload_mode = 'direct'`, + [ownerId], + ); + return Number(result.rows[0].count); + } + + async allLinkable(chatId: string, ids: string[]): Promise { + const result = await this.database.query<{ count: string }>( + 'attachments.all_linkable', + `SELECT count(*) AS count FROM attachments + WHERE chat_id = $1 AND status = 'ready' AND id = ANY($2::uuid[])`, + [chatId, ids], + ); + return Number(result.rows[0].count) === ids.length; + } + + async claimExpired( + graceSeconds: number, + limit: number, + ): Promise<{ id: string; object_key: string }[]> { + const result = await this.database.query<{ + id: string; + object_key: string; + }>( + 'attachments.claim_expired', + `UPDATE attachments SET status = 'deleting', updated_at = now() + WHERE id IN ( + SELECT id FROM attachments + WHERE (status = 'pending' + AND expires_at < now() - make_interval(secs => $1::double precision)) + OR (status = 'deleting' AND updated_at < now() - interval '1 minute') + ORDER BY expires_at NULLS FIRST + LIMIT $2 + FOR UPDATE SKIP LOCKED) + RETURNING id, object_key`, + [graceSeconds, limit], + ); + return result.rows; + } + + async deleteClaimed(id: string): Promise { + await this.database.query( + 'attachments.delete_claimed', + `DELETE FROM attachments WHERE id = $1 AND status = 'deleting'`, + [id], + ); + } +} diff --git a/app/src/attachments/attachments.service.ts b/app/src/attachments/attachments.service.ts new file mode 100644 index 00000000..7db590ee --- /dev/null +++ b/app/src/attachments/attachments.service.ts @@ -0,0 +1,325 @@ +import { + BadRequestException, + HttpException, + Injectable, + InternalServerErrorException, + Logger, + NotFoundException, + PayloadTooLargeException, + ServiceUnavailableException, + UnsupportedMediaTypeException, +} from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; +import { createHash, randomUUID } from 'node:crypto'; +import { pipeline, Readable, Transform } from 'node:stream'; +import type { AppConfig } from '../config/app-config.schema.js'; +import { ChatsService } from '../chats/chats.service.js'; +import { MetricsService } from '../metrics/metrics.service.js'; +import { ObjectStorage } from '../storage/object-storage.js'; +import type { User } from '../users/user.js'; +import { + toAttachment, + type Attachment, + type AttachmentRow, +} from './attachment.js'; +import { validateFilename } from './filename.js'; +import { + IMAGE_HEADER_MAX_BYTES, + ImageHeader, + ImageInspector, + ImageRejectedError, +} from './image/image-inspector.js'; +import { AttachmentsRepository } from './attachments.repository.js'; + +const MEDIA_TYPES = new Set(['image/png', 'image/jpeg']); + +export function mediaType(header: unknown): string | undefined { + if (typeof header !== 'string') return undefined; + return header.split(';', 1)[0].trim().toLowerCase(); +} + +export function imageRejection(error: ImageRejectedError): HttpException { + return error.reason === 'too_many_pixels' + ? new PayloadTooLargeException(error.message) + : new UnsupportedMediaTypeException(error.message); +} + +class UploadInterruptedError extends Error {} + +@Injectable() +export class AttachmentsService { + private readonly logger = new Logger(AttachmentsService.name); + private inFlight = 0; + private readonly maxUploadBytes: number; + private readonly maxPixels: number; + private readonly uploadTimeoutMs: number; + private readonly maxInFlight: number; + + constructor( + config: ConfigService, + private readonly repository: AttachmentsRepository, + private readonly storage: ObjectStorage, + private readonly chats: ChatsService, + private readonly metrics: MetricsService, + ) { + this.maxUploadBytes = config.getOrThrow('MAX_UPLOAD_BYTES'); + this.maxPixels = config.getOrThrow('MAX_IMAGE_PIXELS'); + this.uploadTimeoutMs = config.getOrThrow('UPLOAD_TIMEOUT_MS'); + this.maxInFlight = config.getOrThrow('UPLOAD_MAX_IN_FLIGHT'); + } + + async uploadProxy( + chatId: string, + user: User, + rawFilename: unknown, + contentTypeHeader: unknown, + contentLengthHeader: unknown, + body: Readable | undefined, + ): Promise { + const filename = validateFilename(rawFilename); + const declared = mediaType(contentTypeHeader); + if (declared === undefined || !MEDIA_TYPES.has(declared)) + throw new UnsupportedMediaTypeException( + 'Content-Type must be image/png or image/jpeg', + ); + if ( + typeof contentLengthHeader !== 'string' || + !/^\d{1,15}$/u.test(contentLengthHeader) + ) + throw new BadRequestException('Content-Length is required'); + const contentLength = Number(contentLengthHeader); + if (contentLength === 0 || body === undefined) + throw new UnsupportedMediaTypeException('Image body is empty'); + if (contentLength > this.maxUploadBytes) + throw new PayloadTooLargeException('Image is too large'); + + if (this.inFlight >= this.maxInFlight) + throw new HttpException( + { message: 'Too many concurrent uploads', retryAfter: 1 }, + 429, + ); + this.inFlight += 1; + try { + await this.chats.getForUser(chatId, user); + return await this.receive( + chatId, + user, + filename, + declared, + contentLength, + body, + ); + } finally { + this.inFlight -= 1; + } + } + + private async receive( + chatId: string, + user: User, + filename: string, + declared: string, + contentLength: number, + body: Readable, + ): Promise { + const controller = new AbortController(); + let timedOut = false; + const timer = setTimeout(() => { + timedOut = true; + body.destroy(new Error('upload timeout')); + controller.abort(); + }, this.uploadTimeoutMs); + const iterator = body[Symbol.asyncIterator]() as AsyncIterator; + const next = async (): Promise> => { + try { + return await iterator.next(); + } catch { + throw new UploadInterruptedError('Upload was interrupted'); + } + }; + + const inspector = new ImageInspector(this.maxPixels); + const head: Buffer[] = []; + let id: string | undefined; + let key = ''; + let rejection: unknown; + try { + // Header phase: nothing exists in the database or S3 yet. + let headBytes = 0; + try { + while (inspector.header === undefined) { + const step = await next(); + if (step.done) { + inspector.finish(); + throw new ImageRejectedError( + 'unsupported_media_type', + 'Image header is missing', + ); + } + head.push(step.value); + headBytes += step.value.length; + inspector.push(step.value); + if ( + inspector.header === undefined && + headBytes > IMAGE_HEADER_MAX_BYTES + ) + throw new ImageRejectedError( + 'unsupported_media_type', + 'Image header is missing', + ); + } + } catch (error) { + throw this.mapUploadError(error, timedOut); + } + const header = inspector.header as ImageHeader; + if (header.contentType !== declared) + throw new UnsupportedMediaTypeException( + 'Image content does not match Content-Type', + ); + + id = randomUUID(); + key = this.storage.objectKey(id); + await this.repository.insertPending({ + id, + chatId, + ownerId: user.id, + filename, + contentType: declared, + uploadMode: 'proxy', + objectKey: key, + sizeBytes: null, + sha256: null, + ttlMs: this.uploadTimeoutMs, + }); + + const sha256 = createHash('sha256'); + let total = 0; + const account = (chunk: Buffer, inspect: boolean): void => { + total += chunk.length; + if (total > contentLength) + throw new UploadInterruptedError( + 'Body exceeds Content-Length', + ); + if (inspect) inspector.push(chunk); + sha256.update(chunk); + this.metrics.add('attachments.proxy.bytes_in', chunk.length); + // Validate before the last bytes reach S3: it cannot commit an + // object whose body is incomplete. + if (total === contentLength) inspector.finish(); + }; + async function* generate(): AsyncGenerator { + for (const chunk of head) { + account(chunk, false); + yield chunk; + } + for (;;) { + const step = await next(); + if (step.done) break; + account(step.value, true); + yield step.value; + } + if (total < contentLength) + throw new UploadInterruptedError('Upload was interrupted'); + } + const readable = Readable.from( + (async function* () { + try { + yield* generate(); + } catch (error) { + rejection = error; + throw error; + } + })(), + ); + + let claimed = false; + try { + await this.storage.putStream( + key, + readable, + contentLength, + declared, + controller.signal, + ); + this.metrics.add( + 'attachments.proxy.bytes_to_s3', + contentLength, + ); + const row = await this.repository.markReady(id, { + sizeBytes: total, + sha256: sha256.digest('hex'), + width: header.width, + height: header.height, + }); + if (row === undefined) { + claimed = true; + throw new ServiceUnavailableException(); + } + this.metrics.increment('attachments.upload.created'); + return toAttachment(row); + } catch (error) { + if (!claimed) await this.compensate(id, key); + throw this.mapUploadError(rejection ?? error, timedOut); + } + } finally { + clearTimeout(timer); + } + } + + private mapUploadError(error: unknown, timedOut: boolean): unknown { + if (error instanceof ImageRejectedError) return imageRejection(error); + if (error instanceof UploadInterruptedError || timedOut) + return new BadRequestException('Upload was interrupted'); + return error; + } + + private async compensate(id: string, key: string): Promise { + try { + await this.storage.delete(key); + await this.repository.deletePending(id); + this.metrics.increment('attachments.compensated'); + } catch (error) { + this.metrics.increment('attachments.compensation_deferred'); + this.logger.warn( + `Compensation of attachment ${id} deferred: ${error instanceof Error ? error.message : 'unknown error'}`, + ); + } + } + + async getMetadata(id: string, user: User): Promise { + const row = await this.repository.findVisible(id, user.id); + if (!row) throw new NotFoundException(); + return toAttachment(row); + } + + async openContent( + id: string, + user: User, + variant: string | undefined, + ): Promise<{ row: AttachmentRow; stream: Readable }> { + if (variant !== undefined && variant !== 'original') { + if (['thumbnail', 'crop', 'optimized'].includes(variant)) + throw new NotFoundException(); + throw new BadRequestException('variant is invalid'); + } + const row = await this.repository.findVisible(id, user.id); + if (!row) throw new NotFoundException(); + const source = await this.storage.getStream(row.object_key); + if (source === null) { + this.metrics.increment('attachments.object_missing'); + this.logger.error( + `Object for ready attachment ${row.id} is missing in storage`, + ); + throw new InternalServerErrorException(); + } + const metrics = this.metrics; + const counter = new Transform({ + transform(chunk: Buffer, _encoding, callback) { + metrics.add('attachments.download.bytes_out', chunk.length); + callback(null, chunk); + }, + }); + pipeline(source, counter, () => undefined); + return { row, stream: counter }; + } +} diff --git a/app/src/attachments/filename.ts b/app/src/attachments/filename.ts new file mode 100644 index 00000000..6026c2e5 --- /dev/null +++ b/app/src/attachments/filename.ts @@ -0,0 +1,34 @@ +import { BadRequestException } from '@nestjs/common'; + +// oxlint-disable-next-line no-control-regex +const FORBIDDEN = + /[/\\\u0000-\u001f\u007f-\u009f\u200e\u200f\u202a-\u202e\u2066-\u2069]/u; + +/** The name is stored as-is and used for display only, never in paths or keys. */ +export function validateFilename(value: unknown): string { + if (typeof value !== 'string') throw invalid(); + const length = [...value].length; + if ( + length < 1 || + length > 255 || + /^\s*$/u.test(value) || + value === '.' || + value === '..' || + FORBIDDEN.test(value) + ) + throw invalid(); + return value; +} + +function invalid(): BadRequestException { + return new BadRequestException('filename is invalid'); +} + +export function contentDisposition(filename: string): string { + const fallback = filename.replace(/[^\x20-\x7e]|["\\]/gu, '_'); + const encoded = encodeURIComponent(filename).replace( + /['()*]/gu, + (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`, + ); + return `inline; filename="${fallback}"; filename*=UTF-8''${encoded}`; +} diff --git a/app/src/config/app-config.schema.ts b/app/src/config/app-config.schema.ts index 031055d1..9ab02a11 100644 --- a/app/src/config/app-config.schema.ts +++ b/app/src/config/app-config.schema.ts @@ -82,24 +82,9 @@ export const appConfigSchema = z undefined, 15000, ), - MAX_UPLOAD_BYTES: numeric( - 'MAX_UPLOAD_BYTES', - 1, - 10485760, - 10485760, - ), - MAX_IMAGE_PIXELS: numeric( - 'MAX_IMAGE_PIXELS', - 1, - 40000000, - 40000000, - ), - UPLOAD_TIMEOUT_MS: numeric( - 'UPLOAD_TIMEOUT_MS', - 1000, - undefined, - 25000, - ), + MAX_UPLOAD_BYTES: numeric('MAX_UPLOAD_BYTES', 1, 10485760, 10485760), + MAX_IMAGE_PIXELS: numeric('MAX_IMAGE_PIXELS', 1, 40000000, 40000000), + UPLOAD_TIMEOUT_MS: numeric('UPLOAD_TIMEOUT_MS', 1000, undefined, 25000), UPLOAD_MAX_IN_FLIGHT: numeric('UPLOAD_MAX_IN_FLIGHT', 1, 1024, 32), // 0 отключает фоновый проход уборщика (остаётся ручной CLI). ATTACHMENT_SWEEP_INTERVAL_MS: numeric( diff --git a/app/src/database/database.client.ts b/app/src/database/database.client.ts index 34413d95..408f8dcd 100644 --- a/app/src/database/database.client.ts +++ b/app/src/database/database.client.ts @@ -36,12 +36,15 @@ export class DatabaseClient implements OnModuleDestroy { connectionString: this.config.getOrThrow('DATABASE_URL'), max: 1, idleTimeoutMillis: 0, - connectionTimeoutMillis: this.config.getOrThrow('HEALTH_TIMEOUT_MS'), + connectionTimeoutMillis: + this.config.getOrThrow('HEALTH_TIMEOUT_MS'), query_timeout: this.config.getOrThrow('HEALTH_TIMEOUT_MS'), }); this.healthPool.on('error', (error: Error) => { this.metrics.increment('database.health_pool_error'); - this.logger.warn(`PostgreSQL health connection error: ${error.message}`); + this.logger.warn( + `PostgreSQL health connection error: ${error.message}`, + ); }); } diff --git a/app/src/main.ts b/app/src/main.ts index 1421e99f..357212c3 100644 --- a/app/src/main.ts +++ b/app/src/main.ts @@ -16,6 +16,18 @@ async function bootstrap(): Promise { AppModule, new FastifyAdapter({ logger: true }), ); + // Raw image bodies reach the controller as an unread stream: the upload is + // bounded by our own checks, not by Fastify's bodyLimit. + app.getHttpAdapter() + .getInstance() + .addContentTypeParser( + ['image/png', 'image/jpeg'], + ( + _request: unknown, + payload: unknown, + done: (error: Error | null, body?: unknown) => void, + ) => done(null, payload), + ); app.useGlobalInterceptors( new RequestIdInterceptor( app.get(HttpAdapterHost), @@ -50,7 +62,9 @@ async function bootstrap(): Promise { shuttingDown = true; health.setDraining(); if (drainDelayMs > 0) - await new Promise((resolve) => setTimeout(resolve, drainDelayMs)); + await new Promise((resolve) => + setTimeout(resolve, drainDelayMs), + ); await app.close(); process.exit(0); }; diff --git a/app/src/messages/dto/create-message.dto.ts b/app/src/messages/dto/create-message.dto.ts index 57e5be26..0a8b8d2a 100644 --- a/app/src/messages/dto/create-message.dto.ts +++ b/app/src/messages/dto/create-message.dto.ts @@ -1,8 +1,23 @@ -import { IsString } from 'class-validator'; +import { + ArrayMaxSize, + ArrayUnique, + IsArray, + IsString, + IsUUID, + ValidateIf, +} from 'class-validator'; import { CodePointLength } from '../../common/validation/code-point-length.js'; export class CreateMessageDto { @IsString() - @CodePointLength(1, 4000) + @CodePointLength(0, 4000) text!: string; + + // Absent means []; null is a client error. + @ValidateIf((_, value) => value !== undefined) + @IsArray() + @ArrayMaxSize(10) + @ArrayUnique() + @IsUUID('all', { each: true }) + attachment_ids: string[] = []; } diff --git a/app/src/messages/idempotency/idempotency.repository.spec.ts b/app/src/messages/idempotency/idempotency.repository.spec.ts index f6784dca..056876a4 100644 --- a/app/src/messages/idempotency/idempotency.repository.spec.ts +++ b/app/src/messages/idempotency/idempotency.repository.spec.ts @@ -6,12 +6,17 @@ describe('IdempotencyRepository expired-key cleanup', () => { const query = vi.fn().mockResolvedValue({ rowCount: 0, rows: [] }); const repository = new IdempotencyRepository({ query } as never); - await repository.forget('user', '/api/v1/chats/chat/messages', 'key', 86400); + await repository.forget( + 'user', + '/api/v1/chats/chat/messages', + 'key', + 86400, + ); expect(query).toHaveBeenCalledWith( 'idempotency.forget', expect.stringContaining( - 'created_at < now() - make_interval(secs => $4::double precision)', + 'created_at < now() - make_interval(secs => $4::double precision)', ), ['user', '/api/v1/chats/chat/messages', 'key', 86400], ); diff --git a/app/src/messages/idempotency/idempotency.repository.ts b/app/src/messages/idempotency/idempotency.repository.ts index 79ba9f8e..badd7364 100644 --- a/app/src/messages/idempotency/idempotency.repository.ts +++ b/app/src/messages/idempotency/idempotency.repository.ts @@ -22,30 +22,30 @@ const PURGE_BATCHES = 10; export class IdempotencyRepository { constructor(private readonly database: DatabaseClient) {} - /** - * Reads the stored result and re-checks access in the same round trip: a - * replay must still prove that the caller may read this chat. - */ - async read( - userId: string, - path: string, - key: string, - chatId: string, - ttlSeconds: number, - ): Promise { - const result = await this.database.query( - 'idempotency.read', - `SELECT k.request_fingerprint, k.status_code, k.response_body, k.created_at, + /** + * Reads the stored result and re-checks access in the same round trip: a + * replay must still prove that the caller may read this chat. + */ + async read( + userId: string, + path: string, + key: string, + chatId: string, + ttlSeconds: number, + ): Promise { + const result = await this.database.query( + 'idempotency.read', + `SELECT k.request_fingerprint, k.status_code, k.response_body, k.created_at, k.created_at < now() - make_interval(secs => $4::double precision) AS expired, EXISTS ( SELECT 1 FROM chat_members WHERE chat_id = $5 AND user_id = $1 ) AS is_member FROM idempotency_keys k WHERE k.user_id = $1 AND k.method = 'POST' AND k.path = $2 AND k.key = $3`, - [userId, path, key, ttlSeconds, chatId], - ); - return result.rows[0]; - } + [userId, path, key, ttlSeconds, chatId], + ); + return result.rows[0]; + } async forget( userId: string, diff --git a/app/src/messages/idempotency/idempotency.ts b/app/src/messages/idempotency/idempotency.ts index 9c3d0474..7c4f922f 100644 --- a/app/src/messages/idempotency/idempotency.ts +++ b/app/src/messages/idempotency/idempotency.ts @@ -1,5 +1,4 @@ import { createHash } from 'node:crypto'; -import type { CreateMessageDto } from '../dto/create-message.dto.js'; // Contract: ASCII [A-Za-z0-9._:-]{1,128}. Anything else (including a duplicated // header, which Fastify joins with ", ") is rejected as a client error. @@ -11,8 +10,17 @@ export function messagesPath(chatId: string): string { // The fingerprint is derived from the validated payload with a fixed field // order, so neither JSON key order nor an absent optional field can change it. -export function idempotencyFingerprint(input: CreateMessageDto): string { +// Text-only messages keep the lab3 fingerprint; the order of attachment ids +// is significant because it is the order of attachments in the message. +export function idempotencyFingerprint( + text: string, + attachmentIds: string[], +): string { return createHash('sha256') - .update(JSON.stringify({ text: input.text })) + .update( + attachmentIds.length === 0 + ? JSON.stringify({ text }) + : JSON.stringify({ text, attachment_ids: attachmentIds }), + ) .digest('hex'); } diff --git a/app/src/messages/message.ts b/app/src/messages/message.ts index 1fd5bfe8..cd6c1788 100644 --- a/app/src/messages/message.ts +++ b/app/src/messages/message.ts @@ -4,4 +4,5 @@ export type Message = { sender_id: string; text: string; created_at: string; + attachment_ids: string[]; }; diff --git a/app/src/messages/messages.module.ts b/app/src/messages/messages.module.ts index df803a01..895c16b1 100644 --- a/app/src/messages/messages.module.ts +++ b/app/src/messages/messages.module.ts @@ -8,6 +8,7 @@ import { MessagesCacheModule } from './cache/messages-cache.module.js'; import { IdempotencyModule } from './idempotency/idempotency.module.js'; import { UsersModule } from '../users/users.module.js'; import { RedisModule } from '../redis/redis.module.js'; +import { AttachmentsModule } from '../attachments/attachments.module.js'; import { MetricsModule } from '../metrics/metrics.module.js'; @Module({ @@ -19,6 +20,7 @@ import { MetricsModule } from '../metrics/metrics.module.js'; UsersModule, RedisModule, MetricsModule, + AttachmentsModule, ], controllers: [MessagesController], providers: [MessagesRepository, MessagesService], diff --git a/app/src/messages/messages.repository.spec.ts b/app/src/messages/messages.repository.spec.ts index ff217026..10fc6d3d 100644 --- a/app/src/messages/messages.repository.spec.ts +++ b/app/src/messages/messages.repository.spec.ts @@ -1,5 +1,4 @@ import { describe, expect, it, vi } from 'vitest'; -import type { Cursor } from '../common/http/cursor.js'; import type { Message } from './message.js'; import { MessagesRepository } from './messages.repository.js'; @@ -9,35 +8,15 @@ const message = (id: string, created_at: string): Message => ({ sender_id: 'sender', text: id, created_at, + attachment_ids: [], }); describe('MessagesRepository', () => { - it('uses named SQL history and a keyset cursor', async () => { - const query = vi.fn().mockResolvedValue({ rows: [], rowCount: 0 }); - const repository = new MessagesRepository({ - query, - withTransaction: vi.fn(), - } as never); - const cursor: Cursor = { - scope: 'messages:chat', - created_at: '2026-01-01T00:00:01.000Z', - id: '1', - }; - await repository.findPage('chat', 10, cursor); - expect(query).toHaveBeenCalledWith( - 'messages.history', - expect.stringContaining('(created_at, id) >'), - expect.arrayContaining(['chat', cursor.created_at, cursor.id, 11]), - ); - }); - it('returns rows in response shape', async () => { - const query = vi - .fn() - .mockResolvedValue({ - rows: [message('1', '2026-01-01T00:00:00.000Z')], - rowCount: 1, - }); + const query = vi.fn().mockResolvedValue({ + rows: [message('1', '2026-01-01T00:00:00.000Z')], + rowCount: 1, + }); const repository = new MessagesRepository({ query } as never); await expect(repository.findPage('chat', 1)).resolves.toEqual({ items: [message('1', '2026-01-01T00:00:00.000Z')], diff --git a/app/src/messages/messages.repository.ts b/app/src/messages/messages.repository.ts index d6673afe..5b49919f 100644 --- a/app/src/messages/messages.repository.ts +++ b/app/src/messages/messages.repository.ts @@ -10,6 +10,7 @@ type MessageRow = { sender_id: string; text: string; created_at: Date | string; + attachment_ids?: string[] | null; }; export type CreateOnceRequest = { @@ -19,6 +20,7 @@ export type CreateOnceRequest = { key: string; fingerprint: string; text: string; + attachmentIds: string[]; }; function toMessage(row: MessageRow): Message { @@ -28,6 +30,7 @@ function toMessage(row: MessageRow): Message { sender_id: row.sender_id, text: row.text, created_at: new Date(row.created_at).toISOString(), + attachment_ids: row.attachment_ids ?? [], }; } @@ -50,11 +53,15 @@ WITH claim AS ( 'sender_id', $1::uuid, 'text', $6::text, 'created_at', to_char(date_trunc('milliseconds', now()) AT TIME ZONE 'UTC', - 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"')), + 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'), + 'attachment_ids', to_jsonb($8::uuid[])), $5::uuid WHERE EXISTS ( SELECT 1 FROM chat_members WHERE chat_id = $7::uuid AND user_id = $1 ) + AND (SELECT count(*) FROM attachments a + WHERE a.chat_id = $7::uuid AND a.status = 'ready' + AND a.id = ANY($8::uuid[])) = cardinality($8::uuid[]) ON CONFLICT DO NOTHING RETURNING response_body ), inserted AS ( @@ -62,6 +69,10 @@ WITH claim AS ( SELECT $5::uuid, $7::uuid, $1::uuid, $6::text, date_trunc('milliseconds', now()) FROM claim RETURNING id +), linked AS ( + INSERT INTO message_attachments (message_id, chat_id, attachment_id, ordinal) + SELECT $5::uuid, $7::uuid, t.id, t.ord + FROM inserted, unnest($8::uuid[]) WITH ORDINALITY AS t(id, ord) ), bumped AS ( UPDATE chats SET message_version = message_version + 1 WHERE id = $7::uuid AND EXISTS (SELECT 1 FROM inserted) @@ -88,6 +99,7 @@ export class MessagesRepository { randomUUID(), request.text, request.chatId, + request.attachmentIds, ], ); return result.rows[0]?.response_body; @@ -112,12 +124,16 @@ export class MessagesRepository { let predicate = ''; if (cursor) { values.push(cursor.created_at, cursor.id); - predicate = 'AND (created_at, id) > ($2::timestamptz, $3::uuid)'; + predicate = + 'AND (m.created_at, m.id) > ($2::timestamptz, $3::uuid)'; } values.push(limit + 1); const result = await this.database.query( 'messages.history', - `SELECT id, chat_id, sender_id, text, created_at FROM messages WHERE chat_id = $1 ${predicate} ORDER BY created_at, id LIMIT $${values.length}`, + `SELECT m.id, m.chat_id, m.sender_id, m.text, m.created_at, + COALESCE((SELECT json_agg(ma.attachment_id ORDER BY ma.ordinal) + FROM message_attachments ma WHERE ma.message_id = m.id), '[]'::json) AS attachment_ids + FROM messages m WHERE m.chat_id = $1 ${predicate} ORDER BY m.created_at, m.id LIMIT $${values.length}`, values, ); return { diff --git a/app/src/messages/messages.service.spec.ts b/app/src/messages/messages.service.spec.ts index 6893a2a1..8618dea2 100644 --- a/app/src/messages/messages.service.spec.ts +++ b/app/src/messages/messages.service.spec.ts @@ -28,9 +28,10 @@ describe('MessagesService idempotency expiry race', () => { sender_id: 'user', text: 'hello', created_at: '2026-01-01T00:00:00.000Z', + attachment_ids: [], }; - let row: StoredRow | undefined = { - request_fingerprint: idempotencyFingerprint({ text: 'hello' }), + let row: StoredRow | undefined = { + request_fingerprint: idempotencyFingerprint('hello', []), response_body: { ...newMessage, id: 'message-old', @@ -58,9 +59,9 @@ describe('MessagesService idempotency expiry race', () => { } if (row) return undefined; messageWrites += 1; - row = { - request_fingerprint: idempotencyFingerprint({ text: 'hello' }), - response_body: newMessage, + row = { + request_fingerprint: idempotencyFingerprint('hello', []), + response_body: newMessage, created_at: new Date('2026-01-01T00:00:00.000Z'), expired: false, is_member: true, @@ -69,25 +70,29 @@ describe('MessagesService idempotency expiry race', () => { return newMessage; }), }; - const idempotency = { - read: vi.fn(async () => { - readCalls += 1; - if (readCalls === 2) bothInitialReads.resolve(); - if (readCalls <= 2) await bothInitialReads.promise; - return row; - }), - forget: vi.fn(async (...args: unknown[]) => { - forgetCalls += 1; - if (args.length !== 4) { - row = undefined; - return; - } - if (forgetCalls === 2) await replacementCreated.promise; - if (!row || row.created_at >= new Date('2026-01-01T00:00:00.000Z')) return; - row = undefined; - }), - isMember: vi.fn().mockResolvedValue(true), - }; + const idempotency = { + read: vi.fn(async () => { + readCalls += 1; + if (readCalls === 2) bothInitialReads.resolve(); + if (readCalls <= 2) await bothInitialReads.promise; + return row; + }), + forget: vi.fn(async (...args: unknown[]) => { + forgetCalls += 1; + if (args.length !== 4) { + row = undefined; + return; + } + if (forgetCalls === 2) await replacementCreated.promise; + if ( + !row || + row.created_at >= new Date('2026-01-01T00:00:00.000Z') + ) + return; + row = undefined; + }), + isMember: vi.fn().mockResolvedValue(true), + }; const makeService = () => new MessagesService( messagesRepository as never, @@ -96,8 +101,9 @@ describe('MessagesService idempotency expiry race', () => { idempotency as never, { getOrThrow: vi.fn().mockReturnValue(60) } as never, { increment: vi.fn() } as never, + {} as never, ); - const input = { text: 'hello' } as never; + const input = { text: 'hello', attachment_ids: [] } as never; const user = { id: 'user' } as never; const results = await Promise.all([ diff --git a/app/src/messages/messages.service.ts b/app/src/messages/messages.service.ts index 0777957e..34bee78b 100644 --- a/app/src/messages/messages.service.ts +++ b/app/src/messages/messages.service.ts @@ -12,6 +12,7 @@ import type { Page } from '../common/http/page.js'; import type { AppConfig } from '../config/app-config.schema.js'; import type { User } from '../users/user.js'; import { ChatsService } from '../chats/chats.service.js'; +import { AttachmentsRepository } from '../attachments/attachments.repository.js'; import { MetricsService } from '../metrics/metrics.service.js'; import type { CreateMessageDto } from './dto/create-message.dto.js'; import type { Message } from './message.js'; @@ -42,6 +43,7 @@ export class MessagesService { private readonly idempotency: IdempotencyRepository, private readonly config: ConfigService, private readonly metrics: MetricsService, + private readonly attachments: AttachmentsRepository, ) {} async create( @@ -53,14 +55,18 @@ export class MessagesService { // Ключ и тело проверяются до обращения к БД: клиентская ошибка не должна // создавать заявку и не должна зависеть от состояния хранилища. if (typeof rawKey !== 'string' || !IDEMPOTENCY_KEY_PATTERN.test(rawKey)) - throw new BadRequestException( - 'Idempotency-Key header is required', - ); - if ([...input.text].every((character) => /\s/u.test(character))) + throw new BadRequestException('Idempotency-Key header is required'); + const ids = input.attachment_ids.map((id) => id.toLowerCase()); + if (new Set(ids).size !== ids.length) + throw new BadRequestException('attachment_ids must be unique'); + if ( + ids.length === 0 && + [...input.text].every((character) => /\s/u.test(character)) + ) throw new BadRequestException('Message text cannot be blank'); const path = messagesPath(chatId); - const fingerprint = idempotencyFingerprint(input); + const fingerprint = idempotencyFingerprint(input.text, ids); const ttl = this.config.getOrThrow('IDEMPOTENCY_TTL_SECONDS'); for (let attempt = 1; attempt <= MAX_CLAIM_ATTEMPTS; attempt += 1) { const created = await this.messagesRepository.createOnce({ @@ -70,6 +76,7 @@ export class MessagesService { key: rawKey, fingerprint, text: input.text, + attachmentIds: ids, }); if (created) { this.metrics.increment('idempotency.claim'); @@ -90,6 +97,12 @@ export class MessagesService { // чужую заявку сняли между нашими двумя запросами (503). if (!(await this.idempotency.isMember(chatId, currentUser.id))) throw new NotFoundException(); + // Unknown, foreign-chat or unfinished attachment: not found. + if ( + ids.length > 0 && + !(await this.attachments.allLinkable(chatId, ids)) + ) + throw new NotFoundException(); this.metrics.increment('idempotency.claim_lost'); throw new ServiceUnavailableException( 'Idempotency key could not be claimed', @@ -113,7 +126,11 @@ export class MessagesService { } if (!stored.is_member) throw new NotFoundException(); this.metrics.increment('idempotency.replay'); - return stored.response_body; + // Bodies stored before attachments existed carry no attachment_ids. + return { + ...stored.response_body, + attachment_ids: stored.response_body.attachment_ids ?? [], + }; } throw new ServiceUnavailableException( 'Idempotency key could not be claimed', -- 2.54.0 From 7de3012b466f157f108da83555d330b6d93b18f0 Mon Sep 17 00:00:00 2001 From: Ilya Date: Thu, 22 Oct 2026 22:37:05 +0300 Subject: [PATCH 05/15] =?UTF-8?q?lab4:=20e2e=20=D0=B2=D0=BB=D0=BE=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B9,=20=D0=BE=D1=82=D0=BA=D0=B0=D0=B7?= =?UTF-8?q?=D1=8B=20S3/PG,=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=BE=D1=82=D0=BE=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/attachments/attachments.service.ts | 6 + app/src/attachments/filename.ts | 2 +- app/src/main.ts | 22 +- app/test/attachments.e2e-spec.ts | 363 +++++++++++++++++++++ app/test/dependency-failures.e2e-spec.ts | 233 ++++++++++++- app/test/support/e2e.ts | 158 +++++++++ evidence/lab4/presign-spike.txt | 6 + 7 files changed, 778 insertions(+), 12 deletions(-) create mode 100644 app/test/attachments.e2e-spec.ts create mode 100644 app/test/support/e2e.ts create mode 100644 evidence/lab4/presign-spike.txt diff --git a/app/src/attachments/attachments.service.ts b/app/src/attachments/attachments.service.ts index 7db590ee..a3a330cb 100644 --- a/app/src/attachments/attachments.service.ts +++ b/app/src/attachments/attachments.service.ts @@ -232,6 +232,11 @@ export class AttachmentsService { })(), ); + // A failing body must abort the PUT at once: the SDK does not end a + // request whose Content-Length can no longer be satisfied, it would + // hang until the request timeout. The error itself is reported via + // `rejection`; the listener also keeps a late error from crashing us. + readable.on('error', () => controller.abort()); let claimed = false; try { await this.storage.putStream( @@ -258,6 +263,7 @@ export class AttachmentsService { this.metrics.increment('attachments.upload.created'); return toAttachment(row); } catch (error) { + readable.destroy(); if (!claimed) await this.compensate(id, key); throw this.mapUploadError(rejection ?? error, timedOut); } diff --git a/app/src/attachments/filename.ts b/app/src/attachments/filename.ts index 6026c2e5..b4cb3b9b 100644 --- a/app/src/attachments/filename.ts +++ b/app/src/attachments/filename.ts @@ -1,7 +1,7 @@ import { BadRequestException } from '@nestjs/common'; -// oxlint-disable-next-line no-control-regex const FORBIDDEN = + // eslint-disable-next-line no-control-regex /[/\\\u0000-\u001f\u007f-\u009f\u200e\u200f\u202a-\u202e\u2066-\u2069]/u; /** The name is stored as-is and used for display only, never in paths or keys. */ diff --git a/app/src/main.ts b/app/src/main.ts index 357212c3..dee1f60a 100644 --- a/app/src/main.ts +++ b/app/src/main.ts @@ -18,16 +18,18 @@ async function bootstrap(): Promise { ); // Raw image bodies reach the controller as an unread stream: the upload is // bounded by our own checks, not by Fastify's bodyLimit. - app.getHttpAdapter() - .getInstance() - .addContentTypeParser( - ['image/png', 'image/jpeg'], - ( - _request: unknown, - payload: unknown, - done: (error: Error | null, body?: unknown) => void, - ) => done(null, payload), - ); + const fastify = app.getHttpAdapter().getInstance(); + // Fastify's built-in text/plain parser buffers the body and fails binary + // input with 400; the upload service answers 415 for it instead. + fastify.removeContentTypeParser('text/plain'); + fastify.addContentTypeParser( + ['image/png', 'image/jpeg', 'text/plain'], + ( + _request: unknown, + payload: unknown, + done: (error: Error | null, body?: unknown) => void, + ) => done(null, payload), + ); app.useGlobalInterceptors( new RequestIdInterceptor( app.get(HttpAdapterHost), diff --git a/app/test/attachments.e2e-spec.ts b/app/test/attachments.e2e-spec.ts new file mode 100644 index 00000000..ae6d08c0 --- /dev/null +++ b/app/test/attachments.e2e-spec.ts @@ -0,0 +1,363 @@ +import { createHash, randomBytes, randomUUID } from 'node:crypto'; +import { readFileSync } from 'node:fs'; +import net from 'node:net'; +import { setTimeout as sleep } from 'node:timers/promises'; +import { afterAll, beforeAll, describe, expect, it } from 'vitest'; +import type { Pool } from 'pg'; +import type { ApiErrorBody } from '../src/common/errors/api-error.js'; +import type { Page } from '../src/common/http/page.js'; +import type { Message } from '../src/messages/message.js'; +import { + Actor, + actor, + baseUrl, + bearer, + createChat, + database, + download, + expectError, + http, + postMessage, + upload, + uploadRaw, +} from './support/e2e.js'; +import { noisePng, padPngTo, pixelBombPng } from './support/png.js'; + +const png = readFileSync( + new URL('../../tests/fixtures/sample.png', import.meta.url), +); +const jpeg = readFileSync(new URL('./fixtures/sample.jpg', import.meta.url)); +const progressive = readFileSync( + new URL('./fixtures/sample-progressive.jpg', import.meta.url), +); +const MAX = 10_485_760; + +let db: Pool; +let alice: Actor; +let bob: Actor; +let eve: Actor; +let chatId: string; +let eveChatId: string; +let leftoverChatId: string; + +const sha256 = (data: Uint8Array) => + createHash('sha256').update(data).digest('hex'); + +async function ready(data: Buffer, type = 'image/png', chat = chatId) { + const result = await upload(alice.token, chat, data, { + contentType: type, + }); + expect(result.response.status).toBe(201); + return result.body; +} + +describe('attachments (proxy upload)', () => { + beforeAll(async () => { + db = database(); + alice = await actor(); + bob = await actor(); + eve = await actor(); + chatId = (await createChat(alice, [bob])).id; + eveChatId = (await createChat(eve, [])).id; + // Chat for rejected uploads: it must end up without any row. + leftoverChatId = (await createChat(alice, [])).id; + }); + + afterAll(async () => { + await db.end(); + }); + + it('stores a PNG and serves it only to chat members', async () => { + const created = await upload(alice.token, chatId, png, { + filename: 'Снимок.png', + }); + expect(created.response.status).toBe(201); + expect(created.body).toMatchObject({ + chat_id: chatId, + owner_id: alice.user.id, + filename: 'Снимок.png', + content_type: 'image/png', + size_bytes: png.length, + sha256: sha256(png), + status: 'ready', + variants: [], + error_code: null, + }); + const id = created.body.id; + + const metadata = await http( + `/api/v1/attachments/${id}`, + { headers: bearer(bob.token) }, + ); + expect(metadata.response.status).toBe(200); + expect(metadata.body.sha256).toBe(sha256(png)); + + const content = await download(bob.token, id); + expect(content.response.status).toBe(200); + expect(content.response.headers.get('content-type')).toBe('image/png'); + expect(content.response.headers.get('x-content-type-options')).toBe( + 'nosniff', + ); + expect(content.response.headers.get('content-length')).toBe( + String(png.length), + ); + expect(content.response.headers.get('content-disposition')).toContain( + "filename*=UTF-8''%D0%A1", + ); + expect(content.bytes.equals(png)).toBe(true); + + for (const path of [`/${id}`, `/${id}/content`]) { + expectError( + await http(`/api/v1/attachments${path}`, { + headers: bearer(eve.token), + }), + 404, + 'not_found', + ); + } + expectError( + await http(`/api/v1/attachments/${id}/content`), + 401, + 'unauthorized', + ); + expectError(await upload(eve.token, chatId, png), 404, 'not_found'); + expectError( + await http(`/api/v1/attachments/${randomUUID()}`, { + headers: bearer(bob.token), + }), + 404, + 'not_found', + ); + }); + + it.each([ + ['JPEG', jpeg], + ['progressive JPEG', progressive], + ])('accepts a %s', async (_name, data) => { + const created = await ready(data, 'image/jpeg'); + expect(created.content_type).toBe('image/jpeg'); + const content = await download(alice.token, created.id); + expect(content.bytes.equals(data)).toBe(true); + }); + + it('enforces the 10 MiB limit exactly', async () => { + const exact = padPngTo(png, MAX); + const created = await ready(exact); + expect(created.size_bytes).toBe(MAX); + expectError( + await upload(alice.token, leftoverChatId, padPngTo(png, MAX + 1)), + 413, + 'payload_too_large', + ); + }); + + it('rejects a pixel bomb before storing anything', async () => { + expectError( + await upload(alice.token, leftoverChatId, pixelBombPng()), + 413, + 'payload_too_large', + ); + }); + + it('rejects damaged images', async () => { + const flipped = Buffer.from(png); + flipped[Math.floor(png.length / 2)] ^= 0xff; + const cases: Buffer[] = [ + png.subarray(0, png.length - 100), + flipped, + Buffer.concat([png.subarray(0, 8), randomBytes(2048)]), + Buffer.alloc(0), + ]; + for (const data of cases) + expectError( + await upload(alice.token, leftoverChatId, data), + 415, + 'unsupported_media_type', + ); + }); + + it('rejects a content type that does not match the bytes', async () => { + const gif = Buffer.from('GIF89a' + 'x'.repeat(64)); + const cases: [Buffer, string][] = [ + [png, 'image/jpeg'], + [jpeg, 'image/png'], + [gif, 'image/png'], + [png, 'text/plain'], + [png, 'application/octet-stream'], + ]; + for (const [data, type] of cases) + expectError( + await upload(alice.token, leftoverChatId, data, { + contentType: type, + }), + 415, + 'unsupported_media_type', + ); + }); + + it('validates filenames by code points and forbidden characters', async () => { + const bad = [ + '?filename=a%2Fb.png', + '?filename=a%5Cb.png', + '?filename=a%00b.png', + '?filename=a%07b.png', + '?filename=%E2%80%AEgnp.exe', + '?filename=%20', + '?filename=', + `?filename=${'a'.repeat(256)}`, + '', + '?filename=a.png&filename=b.png', + ]; + for (const query of bad) + expectError( + await uploadRaw(alice.token, leftoverChatId, query, png), + 400, + 'invalid_request', + ); + const long = '😀'.repeat(255); + const created = await upload(alice.token, chatId, png, { + filename: long, + }); + expect(created.response.status).toBe(201); + expect(created.body.filename).toBe(long); + }); + + it('links attachments to messages in the given order', async () => { + const first = await ready(png); + const second = await ready(jpeg, 'image/jpeg'); + const order = [second.id, first.id]; + const key = randomUUID().replaceAll('-', ''); + const sent = await postMessage( + alice.token, + chatId, + { text: '', attachment_ids: order }, + key, + ); + expect(sent.response.status).toBe(201); + expect(sent.body.attachment_ids).toEqual(order); + + const history = await http>( + `/api/v1/chats/${chatId}/messages?limit=100`, + { headers: bearer(bob.token) }, + ); + const stored = history.body.items.find((m) => m.id === sent.body.id); + expect(stored?.attachment_ids).toEqual(order); + + const replay = await postMessage( + alice.token, + chatId, + { text: '', attachment_ids: order }, + key, + ); + expect(replay.response.status).toBe(201); + expect(replay.body).toEqual(sent.body); + expectError( + await postMessage( + alice.token, + chatId, + { text: '', attachment_ids: [first.id] }, + key, + ), + 409, + 'conflict', + ); + + const textOnly = await postMessage(alice.token, chatId, { + text: 'hello', + }); + expect(textOnly.response.status).toBe(201); + expect(textOnly.body.attachment_ids).toEqual([]); + }); + + it('rejects invalid attachment references', async () => { + const mine = await ready(png); + const foreign = await upload(eve.token, eveChatId, png); + expect(foreign.response.status).toBe(201); + expectError( + await postMessage(alice.token, chatId, { text: '' }), + 400, + 'invalid_request', + ); + expectError( + await postMessage(alice.token, chatId, { + text: '', + attachment_ids: [foreign.body.id], + }), + 404, + 'not_found', + ); + expectError( + await postMessage(alice.token, chatId, { + text: 'x', + attachment_ids: [randomUUID()], + }), + 404, + 'not_found', + ); + for (const ids of [ + [mine.id, mine.id], + [mine.id, mine.id.toUpperCase()], + Array.from({ length: 11 }, () => randomUUID()), + null, + ['not-a-uuid'], + ]) + expectError( + await postMessage(alice.token, chatId, { + text: 'x', + attachment_ids: ids, + }), + 400, + 'invalid_request', + ); + }); + + it('serves unknown content variants as errors, not bytes', async () => { + const created = await ready(png); + const variant = (name: string) => + http(`/api/v1/attachments/${created.id}/content?variant=${name}`, { + headers: bearer(alice.token), + }); + expect((await variant('original')).response.status).toBe(200); + expectError(await variant('thumbnail'), 404, 'not_found'); + expectError(await variant('bogus'), 400, 'invalid_request'); + }); + + it('removes the pending row when the client drops the connection', async () => { + const data = noisePng(2 * 1024 * 1024); + const url = new URL(baseUrl); + const socket = net.connect(Number(url.port || 80), url.hostname); + await new Promise((resolve, reject) => { + socket.once('connect', resolve); + socket.once('error', reject); + }); + socket.on('error', () => {}); + socket.write( + `POST /api/v1/chats/${leftoverChatId}/attachments?filename=cut.png HTTP/1.1\r\n` + + `Host: ${url.host}\r\nAuthorization: Bearer ${alice.token}\r\n` + + `Content-Type: image/png\r\nContent-Length: ${data.length}\r\n\r\n`, + ); + socket.write(data.subarray(0, 512 * 1024)); + await sleep(500); + socket.destroy(); + await settled(leftoverChatId); + }); + + it('leaves no rows behind after rejected uploads', async () => { + await settled(leftoverChatId); + }); +}); + +async function settled(chat: string): Promise { + const deadline = Date.now() + 10_000; + let count = -1; + while (Date.now() < deadline) { + const result = await db.query<{ count: string }>( + 'SELECT count(*) FROM attachments WHERE chat_id = $1', + [chat], + ); + count = Number(result.rows[0].count); + if (count === 0) return; + await sleep(250); + } + expect(count).toBe(0); +} diff --git a/app/test/dependency-failures.e2e-spec.ts b/app/test/dependency-failures.e2e-spec.ts index fd2a4d88..95cfae67 100644 --- a/app/test/dependency-failures.e2e-spec.ts +++ b/app/test/dependency-failures.e2e-spec.ts @@ -1,6 +1,8 @@ import { execFile } from 'node:child_process'; import { randomUUID } from 'node:crypto'; import { setTimeout as sleep } from 'node:timers/promises'; +import { readFileSync } from 'node:fs'; +import net from 'node:net'; import { fileURLToPath } from 'node:url'; import { promisify } from 'node:util'; import { afterAll, beforeAll, describe, expect, it } from 'vitest'; @@ -10,6 +12,7 @@ import type { ApiErrorBody } from '../src/common/errors/api-error.js'; import type { Page } from '../src/common/http/page.js'; import type { Message } from '../src/messages/message.js'; import type { User } from '../src/users/user.js'; +import { noisePng } from './support/png.js'; // Automated counterpart of the manual Redis/PostgreSQL outage checks. Four // topologies, because the load balancer probes /health/ready (the same route as @@ -41,6 +44,8 @@ const composeEnvFile = process.env.E2E_COMPOSE_ENV_FILE ?? '.env'; const redisService = process.env.E2E_REDIS_SERVICE ?? 'redis'; const postgresService = process.env.E2E_POSTGRES_SERVICE ?? 'postgres'; const apiService = process.env.E2E_API_SERVICE ?? 'api'; +const s3Service = process.env.E2E_S3_SERVICE ?? 's3'; +const s3Bucket = process.env.E2E_S3_BUCKET ?? 'messenger-attachments'; const lbStatsUrl = process.env.E2E_LB_STATS_URL ?? 'http://127.0.0.1:8404/stats;csv'; // PostgreSQL superuser of the stand (compose.yaml, .env); psql runs over the @@ -440,6 +445,106 @@ async function restoreDatabaseAccess(): Promise { await psql('select pg_reload_conf()'); } +const samplePng = readFileSync( + new URL('../../tests/fixtures/sample.png', import.meta.url), +); + +function secretFile(name: string): string { + return readFileSync(`${composeDir}/secrets/${name}`, 'utf8').trim(); +} + +// Root credentials stay inside the local process and the container's exec +// environment; they are never printed. +async function objectExists(key: string): Promise { + const host = `http://${secretFile('minio_root_user')}:${secretFile('minio_root_password')}@127.0.0.1:9000`; + try { + await dockerExecService( + s3Service, + 'env', + `MC_HOST_stand=${host}`, + 'mc', + 'stat', + `stand/${s3Bucket}/${key}`, + ); + return true; + } catch { + return false; + } +} + +async function waitForS3Healthy(): Promise { + const container = (await compose('ps', '-q', s3Service)).split('\n')[0]; + await waitFor( + async () => + (await docker( + 'inspect', + '-f', + '{{.State.Health.Status}}', + container, + ).catch(() => '')) === 'healthy', + async () => 's3 is not healthy', + 60_000, + ); +} + +function uploadPath(chatId: string, filename: string): string { + return `/api/v1/chats/${chatId}/attachments?filename=${encodeURIComponent(filename)}`; +} + +async function sweepNow(): Promise { + await compose( + 'exec', + '-T', + '-e', + 'ATTACHMENT_SWEEP_GRACE_SECONDS=0', + apiService, + 'node', + 'dist/attachments/attachments-sweep.cli.js', + ); +} + +async function waitUntilExpired(filter: string): Promise { + await waitFor( + async () => + Number( + await psql( + `select count(*) from attachments where ${filter} and expires_at < now()`, + ), + ) > 0, + async () => 'pending row did not expire', + 60_000, + ); +} + +async function rawUpload( + data: Buffer, + chatId: string, + filename: string, + token: string, + splitAt: number, + between: () => Promise, +): Promise { + const url = new URL(baseUrl); + const socket = net.connect(Number(url.port || 80), url.hostname); + await new Promise((resolve, reject) => { + socket.once('connect', resolve); + socket.once('error', reject); + }); + const chunks: Buffer[] = []; + socket.on('data', (chunk: Buffer) => chunks.push(chunk)); + const closed = new Promise((resolve) => socket.on('close', resolve)); + socket.write( + `POST ${uploadPath(chatId, filename)} HTTP/1.1\r\nHost: ${url.host}\r\n` + + `Authorization: Bearer ${token}\r\nContent-Type: image/png\r\n` + + `Content-Length: ${data.length}\r\nConnection: close\r\n\r\n`, + ); + socket.write(data.subarray(0, splitAt)); + await between(); + socket.write(data.subarray(splitAt)); + await closed; + return Buffer.concat(chunks).toString('latin1'); +} + describe.skipIf(!enabled)('dependency outages', () => { let user: User; let token: string; @@ -496,6 +601,7 @@ describe.skipIf(!enabled)('dependency outages', () => { // then the temporary per-replica rule, then rotation. await compose('start', redisService); await compose('start', postgresService); + await compose('start', s3Service); await waitForReadiness(200); await restoreDatabaseAccess(); const expected = (await apiContainers()).length; @@ -519,7 +625,8 @@ describe.skipIf(!enabled)('dependency outages', () => { let sampling = true; const sampler = (async () => { while (sampling) { - for (const slot of await lbSlots()) statuses.add(slot.status); + for (const slot of await lbSlots()) + statuses.add(slot.status); await sleep(200); } })(); @@ -796,4 +903,128 @@ describe.skipIf(!enabled)('dependency outages', () => { }, outagedRequestBudgetMs, ); + + it( + 'degrades attachments while S3 is down and sweeps the failed upload afterwards', + async () => { + const upload = (data: Buffer, name: string) => + request( + uploadPath(chat.id, name), + { + method: 'POST', + headers: { + ...bearer(token), + 'content-type': 'image/png', + }, + body: data as unknown as BodyInit, + }, + ); + const before = await upload(samplePng, `s3before-${runId}.png`); + expect(before.response.status).toBe(201); + + await compose('stop', s3Service); + try { + const failed = await upload(samplePng, `s3down-${runId}.png`); + expectBoundedOutage(failed); + const metadata = await request( + `/api/v1/attachments/${before.body.id}`, + { headers: bearer(token) }, + ); + expect(metadata.response.status).toBe(200); + const content = await request( + `/api/v1/attachments/${before.body.id}/content`, + { headers: bearer(token) }, + ); + expectBoundedOutage(content); + const text = await request( + `/api/v1/chats/${chat.id}/messages`, + json({ text: 'S3 down' }, messageHeaders(token)), + ); + expect(text.response.status).toBe(201); + expect((await request('/health/ready')).response.status).toBe( + 200, + ); + // Compensation could not reach S3, so the row stays for the sweeper. + expect( + await psql( + `select count(*) from attachments where chat_id = '${chat.id}' and status = 'pending' and filename = 's3down-${runId}.png'`, + ), + ).toBe('1'); + } finally { + await compose('start', s3Service); + } + await waitForS3Healthy(); + + const bytes = await fetch( + `${baseUrl}/api/v1/attachments/${before.body.id}/content`, + { headers: bearer(token) }, + ); + expect(bytes.status).toBe(200); + expect( + Buffer.from(await bytes.arrayBuffer()).equals(samplePng), + ).toBe(true); + const after = await upload(samplePng, `s3after-${runId}.png`); + expect(after.response.status).toBe(201); + + const filter = `chat_id = '${chat.id}' and status = 'pending' and filename = 's3down-${runId}.png'`; + await waitUntilExpired(filter); + await sweepNow(); + expect( + await psql(`select count(*) from attachments where ${filter}`), + ).toBe('0'); + }, + outagedRequestBudgetMs, + ); + + it( + 'compensates the S3 write when PostgreSQL fails before ready', + async () => { + const data = noisePng(1024 * 1024); + const filename = `pgfault-${runId}.png`; + const filter = `chat_id = '${chat.id}' and status = 'pending' and filename = '${filename}'`; + let restarted = false; + let reply = ''; + try { + reply = await rawUpload( + data, + chat.id, + filename, + token, + 64 * 1024, + async () => { + await waitFor( + async () => + Number( + await psql( + `select count(*) from attachments where ${filter}`, + ), + ) === 1, + async () => 'pending row did not appear', + 10_000, + ); + await compose('stop', postgresService); + }, + ); + } finally { + await compose('start', postgresService); + restarted = true; + } + expect(restarted).toBe(true); + expect(reply.startsWith('HTTP/1.1 503')).toBe(true); + await waitForReadiness(200); + + const key = await psql( + `select object_key from attachments where ${filter}`, + ); + expect(key).toMatch(/^attachments\/[0-9a-f-]{36}\/original$/u); + expect(await objectExists(key)).toBe(false); + + await waitUntilExpired(filter); + await sweepNow(); + expect( + await psql(`select count(*) from attachments where ${filter}`), + ).toBe('0'); + }, + outagedRequestBudgetMs, + ); }); diff --git a/app/test/support/e2e.ts b/app/test/support/e2e.ts new file mode 100644 index 00000000..5210baad --- /dev/null +++ b/app/test/support/e2e.ts @@ -0,0 +1,158 @@ +import { randomUUID } from 'node:crypto'; +import { Pool } from 'pg'; +import { expect } from 'vitest'; +import type { Chat } from '../../src/chats/chat.js'; +import type { ApiErrorBody } from '../../src/common/errors/api-error.js'; +import type { Message } from '../../src/messages/message.js'; +import type { Attachment } from '../../src/attachments/attachment.js'; +import type { User } from '../../src/users/user.js'; + +export const baseUrl = ( + process.env.API_BASE_URL ?? 'http://localhost:8080' +).replace(/\/+$/u, ''); +export const password = 'integration:пароль🔐'; +const runId = randomUUID().replaceAll('-', '').slice(0, 10); +let sequence = 0; + +export type Actor = { user: User; token: string }; +export type HttpResult = { body: T; response: Response }; + +export function database(): Pool { + return new Pool({ + connectionString: process.env.DATABASE_URL, + connectionTimeoutMillis: 5000, + }); +} + +export async function http( + path: string, + init: RequestInit = {}, +): Promise> { + const response = await fetch(`${baseUrl}${path}`, init); + const text = await response.text(); + let body: unknown = undefined; + if (text) { + try { + body = JSON.parse(text); + } catch { + body = text; + } + } + return { body: body as T, response }; +} + +export function json( + body: unknown, + headers: Record = {}, +): RequestInit { + return { + method: 'POST', + headers: { 'content-type': 'application/json', ...headers }, + body: JSON.stringify(body), + }; +} + +export function bearer(token: string): Record { + return { authorization: `Bearer ${token}` }; +} + +export function expectError( + result: HttpResult, + status: number, + code: string, +): void { + expect(result.response.status).toBe(status); + expect(result.body.error.code).toBe(code); + expect(result.body.error.request_id).toBe( + result.response.headers.get('x-request-id'), + ); +} + +export async function actor(): Promise { + const username = `e2e_${runId}_${sequence++}`.slice(0, 32); + const created = await http( + '/api/v1/users', + json({ username, display_name: 'Attachments e2e', password }), + ); + expect(created.response.status).toBe(201); + const basic = Buffer.from(`${username}:${password}`, 'utf8').toString( + 'base64', + ); + const session = await http<{ token: string }>('/api/v1/auth/sessions', { + method: 'POST', + headers: { authorization: `Basic ${basic}` }, + }); + expect(session.response.status).toBe(201); + return { user: created.body, token: session.body.token }; +} + +export async function createChat( + owner: Actor, + members: Actor[], +): Promise { + const result = await http( + '/api/v1/chats', + json( + { + title: 'attachments', + member_ids: [owner.user.id, ...members.map((m) => m.user.id)], + }, + bearer(owner.token), + ), + ); + expect(result.response.status).toBe(201); + return result.body; +} + +/** `query` is sent verbatim so tests can craft malformed filename parameters. */ +export function uploadRaw( + token: string, + chatId: string, + query: string, + body: Buffer | undefined, + contentType = 'image/png', +): Promise> { + return http(`/api/v1/chats/${chatId}/attachments${query}`, { + method: 'POST', + headers: { ...bearer(token), 'content-type': contentType }, + body: body as BodyInit | undefined, + }); +} + +export function upload( + token: string, + chatId: string, + body: Buffer | undefined, + options: { filename?: string; contentType?: string } = {}, +) { + return uploadRaw( + token, + chatId, + `?filename=${encodeURIComponent(options.filename ?? 'picture.png')}`, + body, + options.contentType ?? 'image/png', + ); +} + +export async function download( + token: string, + attachmentId: string, +): Promise<{ response: Response; bytes: Buffer }> { + const response = await fetch( + `${baseUrl}/api/v1/attachments/${attachmentId}/content`, + { headers: bearer(token) }, + ); + return { response, bytes: Buffer.from(await response.arrayBuffer()) }; +} + +export function postMessage( + token: string, + chatId: string, + body: unknown, + key = randomUUID().replaceAll('-', ''), +) { + return http( + `/api/v1/chats/${chatId}/messages`, + json(body, { ...bearer(token), 'idempotency-key': key }), + ); +} diff --git a/evidence/lab4/presign-spike.txt b/evidence/lab4/presign-spike.txt new file mode 100644 index 00000000..1ddb55cb --- /dev/null +++ b/evidence/lab4/presign-spike.txt @@ -0,0 +1,6 @@ +a) X-Amz-SignedHeaders=content-length;content-type;host;x-amz-checksum-sha256 +b) valid PUT -> {"status":200,"text":""} +e) HEAD size=5000 checksumSha256Matches=true +c) same size, one byte changed -> {"status":400,"text":"\nXAmzContentChecksumMismatchThe provided 'x-amz-checksum' header does not match what was computed.attachments/spike-1792697803765-c/originalmessenger-attachments"}; object created=false +d) longer body -> {"status":403,"text":"\nSignatureDoesNotMatchThe request signature we calculated does not match the signature you provided. Check your key and signing method.attachments/spike-1792697803775-d1/originalmessenger-attachments<"}; object created=false +d) shorter body -> {"status":403,"text":"\nSignatureDoesNotMatchThe request signature we calculated does not match the signature you provided. Check your key and signing method.attachments/spike-1792697803780-d2/originalmessenger-attachments<"}; object created=false -- 2.54.0 From 39a6df8c09fa69205b271ae9d628ef0bdd7d6781 Mon Sep 17 00:00:00 2001 From: Ilya Date: Thu, 22 Oct 2026 22:39:25 +0300 Subject: [PATCH 06/15] =?UTF-8?q?lab4:=20=D0=BF=D1=80=D1=8F=D0=BC=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B0,=20?= =?UTF-8?q?=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82=D1=8B=20=D1=8D=D0=BA=D1=81?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B8=D0=BC=D0=B5=D0=BD=D1=82=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=B8=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/attachments/attachments.controller.ts | 23 + app/src/attachments/attachments.module.ts | 8 +- app/src/attachments/attachments.service.ts | 2 +- app/src/attachments/direct-uploads.service.ts | 199 ++++++ .../dto/create-direct-upload.dto.ts | 16 + app/test/direct-upload.e2e-spec.ts | 288 +++++++++ contracts/extensions.openapi.json | 585 ++++++++++++++++++ scripts/lab4/attachments_bench.py | 293 +++++++++ scripts/lab4/check_s3_security.sh | 54 ++ scripts/lab4/consistency_check.sh | 35 ++ scripts/lab4/pngkit.py | 50 ++ scripts/lab4/run_matrix.sh | 23 + 12 files changed, 1574 insertions(+), 2 deletions(-) create mode 100644 app/src/attachments/direct-uploads.service.ts create mode 100644 app/src/attachments/dto/create-direct-upload.dto.ts create mode 100644 app/test/direct-upload.e2e-spec.ts create mode 100644 contracts/extensions.openapi.json create mode 100755 scripts/lab4/attachments_bench.py create mode 100755 scripts/lab4/check_s3_security.sh create mode 100755 scripts/lab4/consistency_check.sh create mode 100644 scripts/lab4/pngkit.py create mode 100755 scripts/lab4/run_matrix.sh diff --git a/app/src/attachments/attachments.controller.ts b/app/src/attachments/attachments.controller.ts index 51db0352..45d02ddb 100644 --- a/app/src/attachments/attachments.controller.ts +++ b/app/src/attachments/attachments.controller.ts @@ -1,4 +1,5 @@ import { + Body, Controller, Get, Headers, @@ -20,6 +21,8 @@ import { CurrentUserGuard } from '../common/auth/current-user.guard.js'; import type { AppConfig } from '../config/app-config.schema.js'; import type { User } from '../users/user.js'; import { AttachmentsService } from './attachments.service.js'; +import { CreateDirectUploadDto } from './dto/create-direct-upload.dto.js'; +import { DirectUploadsService } from './direct-uploads.service.js'; import { contentDisposition } from './filename.js'; @Controller('api/v1') @@ -29,6 +32,7 @@ export class AttachmentsController { constructor( private readonly attachments: AttachmentsService, + private readonly directUploads: DirectUploadsService, config: ConfigService, ) { this.maxUploadBytes = config.getOrThrow('MAX_UPLOAD_BYTES'); @@ -58,6 +62,25 @@ export class AttachmentsController { ); } + @Post('chats/:chatId/attachments/direct-uploads') + @HttpCode(201) + initDirectUpload( + @Param('chatId', new ParseUUIDPipe()) chatId: string, + @CurrentUser() user: User, + @Body() body: CreateDirectUploadDto, + ) { + return this.directUploads.init(chatId, user, body); + } + + @Post('attachments/:attachmentId/complete') + @HttpCode(200) + completeDirectUpload( + @Param('attachmentId', new ParseUUIDPipe()) attachmentId: string, + @CurrentUser() user: User, + ) { + return this.directUploads.complete(attachmentId, user); + } + @Get('attachments/:attachmentId') metadata( @Param('attachmentId', new ParseUUIDPipe()) attachmentId: string, diff --git a/app/src/attachments/attachments.module.ts b/app/src/attachments/attachments.module.ts index e1d1c1fc..32305df1 100644 --- a/app/src/attachments/attachments.module.ts +++ b/app/src/attachments/attachments.module.ts @@ -8,6 +8,7 @@ import { StorageModule } from '../storage/storage.module.js'; import { AttachmentSweeper } from './attachment-sweeper.service.js'; import { AttachmentsController } from './attachments.controller.js'; import { AttachmentsRepository } from './attachments.repository.js'; +import { DirectUploadsService } from './direct-uploads.service.js'; import { AttachmentsService } from './attachments.service.js'; @Module({ @@ -20,7 +21,12 @@ import { AttachmentsService } from './attachments.service.js'; StorageModule, ], controllers: [AttachmentsController], - providers: [AttachmentsRepository, AttachmentsService, AttachmentSweeper], + providers: [ + AttachmentsRepository, + AttachmentsService, + DirectUploadsService, + AttachmentSweeper, + ], exports: [AttachmentsRepository], }) export class AttachmentsModule {} diff --git a/app/src/attachments/attachments.service.ts b/app/src/attachments/attachments.service.ts index a3a330cb..e46b77d6 100644 --- a/app/src/attachments/attachments.service.ts +++ b/app/src/attachments/attachments.service.ts @@ -279,7 +279,7 @@ export class AttachmentsService { return error; } - private async compensate(id: string, key: string): Promise { + async compensate(id: string, key: string): Promise { try { await this.storage.delete(key); await this.repository.deletePending(id); diff --git a/app/src/attachments/direct-uploads.service.ts b/app/src/attachments/direct-uploads.service.ts new file mode 100644 index 00000000..b902ac33 --- /dev/null +++ b/app/src/attachments/direct-uploads.service.ts @@ -0,0 +1,199 @@ +import { + ConflictException, + HttpException, + Injectable, + NotFoundException, + PayloadTooLargeException, + UnsupportedMediaTypeException, +} from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; +import { randomUUID } from 'node:crypto'; +import type { AppConfig } from '../config/app-config.schema.js'; +import { ChatsService } from '../chats/chats.service.js'; +import { MetricsService } from '../metrics/metrics.service.js'; +import { ObjectStorage } from '../storage/object-storage.js'; +import type { User } from '../users/user.js'; +import { toAttachment, type Attachment } from './attachment.js'; +import { AttachmentsRepository } from './attachments.repository.js'; +import { AttachmentsService, imageRejection } from './attachments.service.js'; +import type { CreateDirectUploadDto } from './dto/create-direct-upload.dto.js'; +import { validateFilename } from './filename.js'; +import { + IMAGE_HEADER_MAX_BYTES, + ImageInspector, + ImageRejectedError, +} from './image/image-inspector.js'; + +export type DirectUpload = { + attachment_id: string; + method: 'PUT'; + url: string; + headers: Record; + expires_at: string; +}; + +const MEDIA_TYPES = new Set(['image/png', 'image/jpeg']); + +@Injectable() +export class DirectUploadsService { + private readonly maxUploadBytes: number; + private readonly maxPixels: number; + private readonly ttlSeconds: number; + private readonly maxPending: number; + + constructor( + config: ConfigService, + private readonly repository: AttachmentsRepository, + private readonly storage: ObjectStorage, + private readonly chats: ChatsService, + private readonly metrics: MetricsService, + private readonly attachments: AttachmentsService, + ) { + this.maxUploadBytes = config.getOrThrow('MAX_UPLOAD_BYTES'); + this.maxPixels = config.getOrThrow('MAX_IMAGE_PIXELS'); + this.ttlSeconds = config.getOrThrow('DIRECT_UPLOAD_URL_TTL_SECONDS'); + this.maxPending = config.getOrThrow( + 'DIRECT_UPLOAD_MAX_PENDING_PER_USER', + ); + } + + async init( + chatId: string, + user: User, + dto: CreateDirectUploadDto, + ): Promise { + const filename = validateFilename(dto.filename); + if (!MEDIA_TYPES.has(dto.content_type)) + throw new UnsupportedMediaTypeException( + 'content_type must be image/png or image/jpeg', + ); + if (dto.size_bytes > this.maxUploadBytes) + throw new PayloadTooLargeException('Image is too large'); + await this.chats.getForUser(chatId, user); + if ( + (await this.repository.countPendingDirect(user.id)) >= + this.maxPending + ) + throw new HttpException( + { + message: 'Too many unfinished direct uploads', + retryAfter: this.ttlSeconds, + }, + 429, + ); + + const id = randomUUID(); + const key = this.storage.objectKey(id); + await this.repository.insertPending({ + id, + chatId, + ownerId: user.id, + filename, + contentType: dto.content_type, + uploadMode: 'direct', + objectKey: key, + sizeBytes: dto.size_bytes, + sha256: dto.sha256, + ttlMs: this.ttlSeconds * 1000, + }); + const checksum = Buffer.from(dto.sha256, 'hex').toString('base64'); + let url: string; + try { + url = await this.storage.presignPut(key, { + contentType: dto.content_type, + contentLength: dto.size_bytes, + checksumSha256Base64: checksum, + expiresInSeconds: this.ttlSeconds, + }); + } catch (error) { + await this.repository.deletePending(id); + throw error; + } + this.metrics.increment('attachments.direct.initiated'); + return { + attachment_id: id, + method: 'PUT', + url, + headers: { + 'Content-Type': dto.content_type, + 'x-amz-checksum-sha256': checksum, + }, + expires_at: new Date( + Date.now() + this.ttlSeconds * 1000, + ).toISOString(), + }; + } + + async complete(attachmentId: string, user: User): Promise { + const row = await this.repository.findForComplete( + attachmentId, + user.id, + ); + if (!row) throw new NotFoundException(); + if (row.status === 'ready') return toAttachment(row); + + const size = Number(row.size_bytes); + const expectedChecksum = Buffer.from( + row.sha256 as string, + 'hex', + ).toString('base64'); + const head = await this.storage.head(row.object_key); + if (head === null) + throw new ConflictException('Upload has not been received'); + if (head.size !== size || head.checksumSha256 !== expectedChecksum) { + await this.attachments.compensate(row.id, row.object_key); + throw new ConflictException( + 'Uploaded object does not match the declaration', + ); + } + + // Only the header is read: the signed checksum already pins every byte. + const inspector = new ImageInspector(this.maxPixels); + const covered = size <= IMAGE_HEADER_MAX_BYTES; + const stream = await this.storage.getStream( + row.object_key, + `bytes=0-${Math.min(size, IMAGE_HEADER_MAX_BYTES) - 1}`, + ); + if (stream === null) + throw new ConflictException('Upload has not been received'); + let verified = 0; + try { + for await (const chunk of stream as AsyncIterable) { + verified += chunk.length; + inspector.push(chunk); + if (!covered && inspector.header !== undefined) break; + } + if (covered) inspector.finish(); + else if (inspector.header === undefined) + throw new ImageRejectedError( + 'unsupported_media_type', + 'Image header is missing', + ); + } catch (error) { + if (error instanceof ImageRejectedError) { + await this.attachments.compensate(row.id, row.object_key); + throw imageRejection(error); + } + throw error; + } finally { + stream.destroy(); + this.metrics.add('attachments.direct.verify_bytes', verified); + } + const header = inspector.header; + if (header === undefined || header.contentType !== row.content_type) { + await this.attachments.compensate(row.id, row.object_key); + throw new UnsupportedMediaTypeException( + 'Image content does not match content_type', + ); + } + const ready = await this.repository.markReady(row.id, { + sizeBytes: size, + sha256: row.sha256 as string, + width: header.width, + height: header.height, + }); + if (!ready) throw new ConflictException('Upload is no longer pending'); + this.metrics.increment('attachments.direct.completed'); + return toAttachment(ready); + } +} diff --git a/app/src/attachments/dto/create-direct-upload.dto.ts b/app/src/attachments/dto/create-direct-upload.dto.ts new file mode 100644 index 00000000..f883a126 --- /dev/null +++ b/app/src/attachments/dto/create-direct-upload.dto.ts @@ -0,0 +1,16 @@ +import { IsInt, IsString, Matches, Min } from 'class-validator'; + +export class CreateDirectUploadDto { + @IsString() + filename!: string; + + @IsString() + content_type!: string; + + @IsInt() + @Min(1) + size_bytes!: number; + + @Matches(/^[a-f0-9]{64}$/u) + sha256!: string; +} diff --git a/app/test/direct-upload.e2e-spec.ts b/app/test/direct-upload.e2e-spec.ts new file mode 100644 index 00000000..40e3d175 --- /dev/null +++ b/app/test/direct-upload.e2e-spec.ts @@ -0,0 +1,288 @@ +import { createHash } from 'node:crypto'; +import { readFileSync } from 'node:fs'; +import { setTimeout as sleep } from 'node:timers/promises'; +import { afterAll, beforeAll, describe, expect, it } from 'vitest'; +import type { Pool } from 'pg'; +import type { Attachment } from '../src/attachments/attachment.js'; +import type { DirectUpload } from '../src/attachments/direct-uploads.service.js'; +import type { ApiErrorBody } from '../src/common/errors/api-error.js'; +import { + Actor, + actor, + bearer, + createChat, + database, + download, + expectError, + http, + json, + postMessage, +} from './support/e2e.js'; +import { pixelBombPng } from './support/png.js'; + +const png = readFileSync( + new URL('../../tests/fixtures/sample.png', import.meta.url), +); +const jpeg = readFileSync(new URL('./fixtures/sample.jpg', import.meta.url)); +const MAX = 10_485_760; +const shortTtl = process.env.E2E_DIRECT_TTL_SHORT === '1'; + +let db: Pool; +let alice: Actor; +let bob: Actor; +let eve: Actor; +let chatId: string; + +const sha256 = (data: Uint8Array) => + createHash('sha256').update(data).digest('hex'); + +function init(token: string, chat: string, body: Record) { + return http( + `/api/v1/chats/${chat}/attachments/direct-uploads`, + json(body, bearer(token)), + ); +} + +function declaration(data: Buffer, contentType = 'image/png') { + return { + filename: 'direct.png', + content_type: contentType, + size_bytes: data.length, + sha256: sha256(data), + }; +} + +async function initOk(data: Buffer, contentType = 'image/png') { + const result = await init( + alice.token, + chatId, + declaration(data, contentType), + ); + expect(result.response.status).toBe(201); + return result.body; +} + +// The PUT goes straight to the public S3 endpoint, not through the API. +async function put(ticket: DirectUpload, data: Buffer): Promise { + return fetch(ticket.url, { + method: ticket.method, + headers: ticket.headers, + body: data as unknown as BodyInit, + }); +} + +function complete(token: string, id: string) { + return http( + `/api/v1/attachments/${id}/complete`, + { + method: 'POST', + headers: bearer(token), + }, + ); +} + +describe('direct upload (presigned PUT)', () => { + beforeAll(async () => { + db = database(); + alice = await actor(); + bob = await actor(); + eve = await actor(); + chatId = (await createChat(alice, [bob])).id; + }); + + afterAll(async () => { + await db.end(); + }); + + it('uploads around the API and exposes the attachment after complete', async () => { + const ticket = await initOk(png); + expect(ticket.method).toBe('PUT'); + expect(ticket.headers['x-amz-checksum-sha256']).toBe( + Buffer.from(sha256(png), 'hex').toString('base64'), + ); + expect(Date.parse(ticket.expires_at)).toBeGreaterThan(Date.now()); + expect(new URL(ticket.url).pathname).toBe( + `/messenger-attachments/attachments/${ticket.attachment_id}/original`, + ); + + const hidden = await http( + `/api/v1/attachments/${ticket.attachment_id}`, + { headers: bearer(bob.token) }, + ); + expectError(hidden, 404, 'not_found'); + expectError( + await postMessage(alice.token, chatId, { + text: '', + attachment_ids: [ticket.attachment_id], + }), + 404, + 'not_found', + ); + expectError( + await complete(alice.token, ticket.attachment_id), + 409, + 'conflict', + ); + + expect((await put(ticket, png)).status).toBe(200); + expectError( + await complete(bob.token, ticket.attachment_id), + 404, + 'not_found', + ); + expectError( + await complete(eve.token, ticket.attachment_id), + 404, + 'not_found', + ); + const done = await complete(alice.token, ticket.attachment_id); + expect(done.response.status).toBe(200); + expect(done.body).toMatchObject({ + id: ticket.attachment_id, + owner_id: alice.user.id, + content_type: 'image/png', + size_bytes: png.length, + sha256: sha256(png), + status: 'ready', + }); + const again = await complete(alice.token, ticket.attachment_id); + expect(again.response.status).toBe(200); + expect(again.body).toEqual(done.body); + + const content = await download(bob.token, ticket.attachment_id); + expect(content.response.status).toBe(200); + expect(content.bytes.equals(png)).toBe(true); + const sent = await postMessage(alice.token, chatId, { + text: '', + attachment_ids: [ticket.attachment_id], + }); + expect(sent.response.status).toBe(201); + expect(sent.body.attachment_ids).toEqual([ticket.attachment_id]); + }); + + it('rejects invalid declarations', async () => { + const base = declaration(png); + expectError(await init(eve.token, chatId, base), 404, 'not_found'); + expectError( + await init(alice.token, chatId, { ...base, size_bytes: MAX + 1 }), + 413, + 'payload_too_large', + ); + expectError( + await init(alice.token, chatId, { + ...base, + content_type: 'image/gif', + }), + 415, + 'unsupported_media_type', + ); + for (const bad of [ + { ...base, extra: true }, + { ...base, sha256: 'ABC' }, + { ...base, size_bytes: 0 }, + { ...base, filename: 'a/b.png' }, + ]) + expectError( + await init(alice.token, chatId, bad), + 400, + 'invalid_request', + ); + }); + + it('lets the storage refuse bytes that differ from the declaration', async () => { + const ticket = await initOk(png); + const tampered = Buffer.from(png); + tampered[1000] ^= 1; + const refused = await put(ticket, tampered); + expect(refused.status).toBe(400); + expect(await refused.text()).toContain('XAmzContentChecksumMismatch'); + // No object was created, so the upload can still be finished. + expectError( + await complete(alice.token, ticket.attachment_id), + 409, + 'conflict', + ); + expect((await put(ticket, png)).status).toBe(200); + expect( + (await complete(alice.token, ticket.attachment_id)).response.status, + ).toBe(200); + + const longer = await initOk(png); + const wrongLength = await put( + longer, + Buffer.concat([png, Buffer.from('x')]), + ); + expect(wrongLength.status).toBe(403); + }); + + it('rejects a declared PNG that is really a JPEG, then forgets the claim', async () => { + const ticket = await initOk(jpeg, 'image/png'); + expect((await put(ticket, jpeg)).status).toBe(200); + expectError( + await complete(alice.token, ticket.attachment_id), + 415, + 'unsupported_media_type', + ); + expectError( + await complete(alice.token, ticket.attachment_id), + 404, + 'not_found', + ); + }); + + it('rejects a pixel bomb on complete', async () => { + const bomb = pixelBombPng(); + const ticket = await initOk(bomb); + expect((await put(ticket, bomb)).status).toBe(200); + expectError( + await complete(alice.token, ticket.attachment_id), + 413, + 'payload_too_large', + ); + expectError( + await complete(alice.token, ticket.attachment_id), + 404, + 'not_found', + ); + }); + + it('limits unfinished direct uploads per user', async () => { + const spammer = await actor(); + const chat = (await createChat(spammer, [])).id; + for (let index = 0; index < 10; index += 1) { + const ok = await init(spammer.token, chat, declaration(png)); + expect(ok.response.status).toBe(201); + } + const limited = await init(spammer.token, chat, declaration(png)); + expectError(limited, 429, 'rate_limited'); + expect( + Number(limited.response.headers.get('retry-after')), + ).toBeGreaterThan(0); + }); + + it.runIf(shortTtl)( + 'refuses an expired URL and removes the claim', + async () => { + const ticket = await initOk(png); + const expiresAt = Date.parse(ticket.expires_at); + await sleep(Math.max(0, expiresAt - Date.now()) + 2000); + expect((await put(ticket, png)).status).toBe(403); + const deadline = Date.now() + 15_000; + for (;;) { + const rows = await db.query( + 'SELECT 1 FROM attachments WHERE id = $1', + [ticket.attachment_id], + ); + if (rows.rowCount === 0) break; + expect(Date.now()).toBeLessThan(deadline); + await sleep(250); + } + expectError( + await complete(alice.token, ticket.attachment_id), + 404, + 'not_found', + ); + }, + 60_000, + ); +}); diff --git a/contracts/extensions.openapi.json b/contracts/extensions.openapi.json new file mode 100644 index 00000000..d676f354 --- /dev/null +++ b/contracts/extensions.openapi.json @@ -0,0 +1,585 @@ +{ + "openapi": "3.1.0", + "info": { + "title": "MTUSI Messenger — расширение lab4: прямая загрузка", + "version": "1.4.0-ext.1", + "description": "Трек 1. Не меняет обязательный контракт openapi.json: POST /api/v1/chats/{chat_id}/attachments остаётся основным путём. Клиент получает presigned PUT URL и отправляет байты прямо в приватный bucket MinIO, минуя API. Подписаны заголовки content-type, content-length и x-amz-checksum-sha256: хранилище само отвергает тело с другим размером (403 SignatureDoesNotMatch) или другим SHA-256 (400 XAmzContentChecksumMismatch), объект при этом не создаётся. TTL URL — DIRECT_UPLOAD_URL_TTL_SECONDS (300 с по умолчанию). Ключ объекта attachments//original раскрывает только UUID вложения; bucket приватный, анонимный доступ запрещён. Незавершённые заявки и объекты убирает уборщик через ATTACHMENT_SWEEP_GRACE_SECONDS после истечения. Вложение видно участникам чата только после успешного complete (status=ready)." + }, + "servers": [ + { + "url": "http://localhost:8080", + "description": "Локальный учебный стенд" + } + ], + "security": [ + { + "bearerAuth": [] + } + ], + "paths": { + "/api/v1/chats/{chat_id}/attachments/direct-uploads": { + "post": { + "operationId": "initDirectUpload", + "summary": "Заявка на прямую загрузку: вернуть presigned PUT URL", + "parameters": [ + { + "name": "chat_id", + "in": "path", + "required": true, + "schema": { + "type": "string", + "format": "uuid" + } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CreateDirectUpload" + } + } + } + }, + "responses": { + "201": { + "description": "Заявка создана; вложение pending и не видно никому, кроме загрузки", + "headers": { + "X-Request-Id": { + "description": "Идентификатор запроса.", + "schema": { + "type": "string", + "minLength": 1 + } + }, + "X-Instance-Id": { + "description": "Идентификатор реплики.", + "schema": { + "type": "string", + "minLength": 1 + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/DirectUpload" + } + } + } + }, + "400": { + "description": "Некорректное тело, filename или sha256", + "headers": { + "X-Request-Id": { + "description": "Идентификатор запроса.", + "schema": { + "type": "string", + "minLength": 1 + } + }, + "X-Instance-Id": { + "description": "Идентификатор реплики.", + "schema": { + "type": "string", + "minLength": 1 + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "openapi.json#/components/schemas/Error" + } + } + } + }, + "401": { + "description": "Нет или неверен токен", + "headers": { + "X-Request-Id": { + "description": "Идентификатор запроса.", + "schema": { + "type": "string", + "minLength": 1 + } + }, + "X-Instance-Id": { + "description": "Идентификатор реплики.", + "schema": { + "type": "string", + "minLength": 1 + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "openapi.json#/components/schemas/Error" + } + } + } + }, + "404": { + "description": "Чат недоступен", + "headers": { + "X-Request-Id": { + "description": "Идентификатор запроса.", + "schema": { + "type": "string", + "minLength": 1 + } + }, + "X-Instance-Id": { + "description": "Идентификатор реплики.", + "schema": { + "type": "string", + "minLength": 1 + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "openapi.json#/components/schemas/Error" + } + } + } + }, + "413": { + "description": "size_bytes больше 10 MiB", + "headers": { + "X-Request-Id": { + "description": "Идентификатор запроса.", + "schema": { + "type": "string", + "minLength": 1 + } + }, + "X-Instance-Id": { + "description": "Идентификатор реплики.", + "schema": { + "type": "string", + "minLength": 1 + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "openapi.json#/components/schemas/Error" + } + } + } + }, + "415": { + "description": "content_type не image/png и не image/jpeg", + "headers": { + "X-Request-Id": { + "description": "Идентификатор запроса.", + "schema": { + "type": "string", + "minLength": 1 + } + }, + "X-Instance-Id": { + "description": "Идентификатор реплики.", + "schema": { + "type": "string", + "minLength": 1 + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "openapi.json#/components/schemas/Error" + } + } + } + }, + "429": { + "description": "Слишком много незавершённых прямых загрузок пользователя; Retry-After — секунды до освобождения слота (TTL URL).", + "headers": { + "X-Request-Id": { + "description": "Идентификатор запроса.", + "schema": { + "type": "string", + "minLength": 1 + } + }, + "X-Instance-Id": { + "description": "Идентификатор реплики.", + "schema": { + "type": "string", + "minLength": 1 + } + }, + "Retry-After": { + "description": "Секунды до повтора.", + "schema": { + "type": "integer", + "minimum": 1 + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "openapi.json#/components/schemas/Error" + } + } + } + }, + "503": { + "description": "Зависимость недоступна", + "headers": { + "X-Request-Id": { + "description": "Идентификатор запроса.", + "schema": { + "type": "string", + "minLength": 1 + } + }, + "X-Instance-Id": { + "description": "Идентификатор реплики.", + "schema": { + "type": "string", + "minLength": 1 + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "openapi.json#/components/schemas/Error" + } + } + } + } + } + } + }, + "/api/v1/attachments/{attachment_id}/complete": { + "post": { + "operationId": "completeDirectUpload", + "summary": "Подтвердить прямую загрузку: HEAD объекта и проверка заголовка изображения", + "description": "Только владелец заявки. Проверяет размер и подписанный SHA-256 объекта (HEAD), читает заголовок изображения (до 1 MiB) и сверяет тип и число пикселей. При несоответствии заявка и объект удаляются, повторный complete даёт 404. Повторный complete готового вложения идемпотентен и возвращает 200.", + "parameters": [ + { + "name": "attachment_id", + "in": "path", + "required": true, + "schema": { + "type": "string", + "format": "uuid" + } + } + ], + "responses": { + "200": { + "description": "Вложение готово; тело идентично Attachment из openapi.json", + "headers": { + "X-Request-Id": { + "description": "Идентификатор запроса.", + "schema": { + "type": "string", + "minLength": 1 + } + }, + "X-Instance-Id": { + "description": "Идентификатор реплики.", + "schema": { + "type": "string", + "minLength": 1 + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "openapi.json#/components/schemas/Attachment" + } + } + } + }, + "400": { + "description": "Некорректный attachment_id", + "headers": { + "X-Request-Id": { + "description": "Идентификатор запроса.", + "schema": { + "type": "string", + "minLength": 1 + } + }, + "X-Instance-Id": { + "description": "Идентификатор реплики.", + "schema": { + "type": "string", + "minLength": 1 + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "openapi.json#/components/schemas/Error" + } + } + } + }, + "401": { + "description": "Нет или неверен токен", + "headers": { + "X-Request-Id": { + "description": "Идентификатор запроса.", + "schema": { + "type": "string", + "minLength": 1 + } + }, + "X-Instance-Id": { + "description": "Идентификатор реплики.", + "schema": { + "type": "string", + "minLength": 1 + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "openapi.json#/components/schemas/Error" + } + } + } + }, + "404": { + "description": "Заявка не найдена, не принадлежит пользователю или уже удалена", + "headers": { + "X-Request-Id": { + "description": "Идентификатор запроса.", + "schema": { + "type": "string", + "minLength": 1 + } + }, + "X-Instance-Id": { + "description": "Идентификатор реплики.", + "schema": { + "type": "string", + "minLength": 1 + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "openapi.json#/components/schemas/Error" + } + } + } + }, + "409": { + "description": "Объект не получен или не совпадает с заявленным размером/SHA-256", + "headers": { + "X-Request-Id": { + "description": "Идентификатор запроса.", + "schema": { + "type": "string", + "minLength": 1 + } + }, + "X-Instance-Id": { + "description": "Идентификатор реплики.", + "schema": { + "type": "string", + "minLength": 1 + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "openapi.json#/components/schemas/Error" + } + } + } + }, + "413": { + "description": "Слишком много пикселей", + "headers": { + "X-Request-Id": { + "description": "Идентификатор запроса.", + "schema": { + "type": "string", + "minLength": 1 + } + }, + "X-Instance-Id": { + "description": "Идентификатор реплики.", + "schema": { + "type": "string", + "minLength": 1 + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "openapi.json#/components/schemas/Error" + } + } + } + }, + "415": { + "description": "Содержимое не PNG/JPEG или не совпадает с content_type", + "headers": { + "X-Request-Id": { + "description": "Идентификатор запроса.", + "schema": { + "type": "string", + "minLength": 1 + } + }, + "X-Instance-Id": { + "description": "Идентификатор реплики.", + "schema": { + "type": "string", + "minLength": 1 + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "openapi.json#/components/schemas/Error" + } + } + } + }, + "503": { + "description": "Хранилище недоступно", + "headers": { + "X-Request-Id": { + "description": "Идентификатор запроса.", + "schema": { + "type": "string", + "minLength": 1 + } + }, + "X-Instance-Id": { + "description": "Идентификатор реплики.", + "schema": { + "type": "string", + "minLength": 1 + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "openapi.json#/components/schemas/Error" + } + } + } + } + } + } + } + }, + "components": { + "securitySchemes": { + "bearerAuth": { + "type": "http", + "scheme": "bearer", + "bearerFormat": "opaque session token" + } + }, + "schemas": { + "CreateDirectUpload": { + "type": "object", + "additionalProperties": false, + "required": [ + "filename", + "content_type", + "size_bytes", + "sha256" + ], + "properties": { + "filename": { + "type": "string", + "minLength": 1, + "maxLength": 255 + }, + "content_type": { + "type": "string", + "enum": [ + "image/png", + "image/jpeg" + ] + }, + "size_bytes": { + "type": "integer", + "minimum": 1, + "maximum": 10485760 + }, + "sha256": { + "type": "string", + "pattern": "^[a-f0-9]{64}$" + } + } + }, + "DirectUpload": { + "type": "object", + "additionalProperties": false, + "required": [ + "attachment_id", + "method", + "url", + "headers", + "expires_at" + ], + "properties": { + "attachment_id": { + "type": "string", + "format": "uuid" + }, + "method": { + "type": "string", + "enum": [ + "PUT" + ] + }, + "url": { + "type": "string", + "format": "uri", + "description": "Presigned URL; содержит подпись, не логировать." + }, + "headers": { + "type": "object", + "description": "Заголовки, которые клиент обязан отправить как есть. Content-Length клиент ставит сам; тело должно быть ровно size_bytes.", + "properties": { + "Content-Type": { + "type": "string" + }, + "x-amz-checksum-sha256": { + "type": "string" + } + }, + "required": [ + "Content-Type", + "x-amz-checksum-sha256" + ] + }, + "expires_at": { + "type": "string", + "format": "date-time" + } + } + } + } + } +} diff --git a/scripts/lab4/attachments_bench.py b/scripts/lab4/attachments_bench.py new file mode 100755 index 00000000..e5b41742 --- /dev/null +++ b/scripts/lab4/attachments_bench.py @@ -0,0 +1,293 @@ +#!/usr/bin/env python3 +"""Upload benchmark: API traffic and peak RSS per upload for proxy vs direct mode. + + attachments_bench.py run --mode proxy --size-bytes 1048576 --concurrency 10 \ + --uploads-per-worker 5 --repeat 3 --output evidence/lab4/bench/proxy-1048576-c10.json + attachments_bench.py summarize evidence/lab4/bench/*.json > evidence/lab4/summary.md + +Run from the repository root with the stand up. Tokens, signed URLs and secrets +are never written to the output. +""" +import argparse +import base64 +import hashlib +import http.client +import json +import os +import statistics +import subprocess +import sys +import threading +import time +import urllib.parse +import uuid +from datetime import datetime, timezone + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from pngkit import noise_png # noqa: E402 + + +def sh(*args, check=True): + return subprocess.run(args, check=check, capture_output=True, text=True).stdout.strip() + + +def read_env(path=".env"): + values = {} + with open(path) as handle: + for line in handle: + line = line.strip() + if line and not line.startswith("#") and "=" in line: + key, _, value = line.partition("=") + values[key] = value + return values + + +def request(host, port, method, path, headers=None, body=None): + connection = http.client.HTTPConnection(host, port, timeout=120) + try: + connection.request(method, path, body=body, headers=headers or {}) + response = connection.getresponse() + payload = response.read() + return response.status, payload + finally: + connection.close() + + +def api_json(env, method, path, token=None, body=None, basic=None): + headers = {} + data = None + if body is not None: + headers["content-type"] = "application/json" + data = json.dumps(body).encode() + if token: + headers["authorization"] = f"Bearer {token}" + if basic: + headers["authorization"] = "Basic " + base64.b64encode(basic.encode()).decode() + port = int(env.get("APP_PUBLIC_PORT", "8080")) + status, payload = request("127.0.0.1", port, method, path, headers, data) + return status, json.loads(payload) if payload else None + + +def containers(): + ids = sh("docker", "compose", "--env-file", ".env", "ps", "-q", "api").split() + return sorted(ids) + + +NODE_METRICS = ( + "fetch('http://127.0.0.1:'+(process.env.APP_PORT||8080)+'/internal/metrics'+process.argv[1]," + "{method:process.argv[1]?'POST':'GET',headers:{authorization:'Bearer '+process.env.METRICS_TOKEN}})" + ".then(r=>r.text()).then(console.log)" +) + + +def metrics(container): + return json.loads(sh("docker", "exec", container, "node", "-e", NODE_METRICS, "")) + + +def reset_metrics(container): + sh("docker", "exec", container, "node", "-e", NODE_METRICS, "/reset") + + +def net_bytes(container): + for line in sh("docker", "exec", container, "cat", "/proc/net/dev").splitlines(): + if line.strip().startswith("eth0:"): + fields = line.split(":", 1)[1].split() + return int(fields[0]), int(fields[8]) + raise RuntimeError("eth0 not found") + + +def percentile(values, fraction): + ordered = sorted(values) + if not ordered: + return 0.0 + return ordered[min(len(ordered) - 1, max(0, int(round(fraction * len(ordered) + 0.5)) - 1))] + + +def one_upload(env, mode, token, chat_id, data, seed): + digest = hashlib.sha256(data).hexdigest() + filename = f"bench-{seed}.png" + port = int(env.get("APP_PUBLIC_PORT", "8080")) + started = time.perf_counter() + if mode == "proxy": + status, payload = request( + "127.0.0.1", port, "POST", + f"/api/v1/chats/{chat_id}/attachments?filename={urllib.parse.quote(filename)}", + {"authorization": f"Bearer {token}", "content-type": "image/png"}, data, + ) + ok = status == 201 + attachment = json.loads(payload) if ok else None + else: + status, ticket = api_json( + env, "POST", f"/api/v1/chats/{chat_id}/attachments/direct-uploads", token, + {"filename": filename, "content_type": "image/png", "size_bytes": len(data), "sha256": digest}, + ) + ok = status == 201 + attachment = None + if ok: + target = urllib.parse.urlsplit(ticket["url"]) + put_status, _ = request( + target.hostname, target.port, "PUT", target.path + "?" + target.query, + {**ticket["headers"]}, data, + ) + ok = put_status == 200 + if ok: + status, attachment = api_json( + env, "POST", f"/api/v1/attachments/{ticket['attachment_id']}/complete", token + ) + ok = status == 200 + elapsed_ms = (time.perf_counter() - started) * 1000 + if ok and (attachment is None or attachment["sha256"] != digest): + ok = False + return ok, elapsed_ms + + +def run_once(env, args, token, chat_id, ids): + for container in ids: + reset_metrics(container) + time.sleep(0.2) + baseline = {c: metrics(c) for c in ids} + net_before = {c: net_bytes(c) for c in ids} + latencies, failures = [], [] + lock = threading.Lock() + + def worker(index): + for step in range(args.uploads_per_worker): + seed = index * 1000 + step + data = noise_png(args.size_bytes, seed) + ok, elapsed = one_upload(env, args.mode, token, chat_id, data, seed) + with lock: + (latencies if ok else failures).append(elapsed) + + started = time.perf_counter() + threads = [threading.Thread(target=worker, args=(i,)) for i in range(args.concurrency)] + for thread in threads: + thread.start() + for thread in threads: + thread.join() + duration = time.perf_counter() - started + time.sleep(0.2) + after = {c: metrics(c) for c in ids} + net_after = {c: net_bytes(c) for c in ids} + + replicas = [] + for c in ids: + base_rss = baseline[c]["memory_bytes"]["rss"] + peak = after[c]["memory_peak_bytes"] + replicas.append({ + "instance_id": after[c]["instance_id"], + "delta_rx_bytes": net_after[c][0] - net_before[c][0], + "delta_tx_bytes": net_after[c][1] - net_before[c][1], + "baseline_rss_bytes": base_rss, + "peak_memory_bytes": peak, + "delta_rss_bytes": peak["rss"] - base_rss, + "counters": {k: v for k, v in after[c]["counters"].items() if k.startswith("attachments.")}, + }) + total = args.concurrency * args.uploads_per_worker + return { + "uploads": total, + "succeeded": len(latencies), + "failed": len(failures), + "duration_s": round(duration, 3), + "latency_ms": { + "p50": round(percentile(latencies, 0.50), 1), + "p95": round(percentile(latencies, 0.95), 1), + "p99": round(percentile(latencies, 0.99), 1), + }, + "replicas": replicas, + "total_delta_rx_bytes": sum(r["delta_rx_bytes"] for r in replicas), + "total_delta_tx_bytes": sum(r["delta_tx_bytes"] for r in replicas), + "rx_bytes_per_upload": round(sum(r["delta_rx_bytes"] for r in replicas) / total), + "tx_bytes_per_upload": round(sum(r["delta_tx_bytes"] for r in replicas) / total), + "max_delta_rss_bytes": max(r["delta_rss_bytes"] for r in replicas), + } + + +def command_run(args): + env = read_env() + ids = containers() + if not ids: + sys.exit("no api containers found") + name = f"bench_{uuid.uuid4().hex[:10]}" + password = "bench:" + uuid.uuid4().hex + status, user = api_json(env, "POST", "/api/v1/users", + body={"username": name, "display_name": "bench", "password": password}) + assert status == 201, status + status, session = api_json(env, "POST", "/api/v1/auth/sessions", basic=f"{name}:{password}") + assert status == 201, status + token = session["token"] + status, chat = api_json(env, "POST", "/api/v1/chats", token, {"title": "bench", "member_ids": [user["id"]]}) + assert status == 201, status + + # Warm-up: one upload per replica path, not measured. + for seed in range(len(ids) * 2): + one_upload(env, args.mode, token, chat["id"], noise_png(args.size_bytes, 900000 + seed), seed) + + limits = [] + for c in ids: + limits.append(sh("docker", "inspect", "-f", "{{.HostConfig.NanoCpus}} {{.HostConfig.Memory}}", c)) + repeats = [run_once(env, args, token, chat["id"], ids) for _ in range(args.repeat)] + mem_total = next(int(l.split()[1]) * 1024 for l in open("/proc/meminfo") if l.startswith("MemTotal")) + result = { + "date": datetime.now(timezone.utc).isoformat(timespec="seconds"), + "git": sh("git", "rev-parse", "--short", "HEAD", check=False), + "params": { + "mode": args.mode, "size_bytes": args.size_bytes, "concurrency": args.concurrency, + "uploads_per_worker": args.uploads_per_worker, "repeat": args.repeat, + }, + "host": {"nproc": os.cpu_count(), "mem_total_bytes": mem_total}, + "api_container_limits_nanocpus_memory": limits, + "repeats": repeats, + } + os.makedirs(os.path.dirname(os.path.abspath(args.output)), exist_ok=True) + with open(args.output, "w") as handle: + json.dump(result, handle, indent=2) + handle.write("\n") + for index, item in enumerate(repeats): + print(f"repeat {index + 1}: ok={item['succeeded']}/{item['uploads']} " + f"rx/upload={item['rx_bytes_per_upload']} tx/upload={item['tx_bytes_per_upload']} " + f"maxΔrss={item['max_delta_rss_bytes']} p50={item['latency_ms']['p50']}ms") + + +def mib(value): + return f"{value / 1048576:.2f}" + + +def command_summarize(args): + rows = [] + for path in args.paths: + with open(path) as handle: + data = json.load(handle) + p = data["params"] + reps = data["repeats"] + med = lambda key: statistics.median(r[key] for r in reps) # noqa: E731 + rows.append((p["mode"], p["size_bytes"], p["concurrency"], reps, med, data)) + rows.sort(key=lambda r: (r[1], r[0], r[2])) + print("| mode | size, MiB | C | ok | API rx/upload, MiB | API tx/upload, MiB | max Δrss, MiB | p50, ms | p95, ms |") + print("|---|---|---|---|---|---|---|---|---|") + for mode, size, conc, reps, med, _data in rows: + ok = sum(r["succeeded"] for r in reps) + total = sum(r["uploads"] for r in reps) + p50 = statistics.median(r["latency_ms"]["p50"] for r in reps) + p95 = statistics.median(r["latency_ms"]["p95"] for r in reps) + print(f"| {mode} | {mib(size)} | {conc} | {ok}/{total} | {mib(med('rx_bytes_per_upload'))} | " + f"{mib(med('tx_bytes_per_upload'))} | {mib(med('max_delta_rss_bytes'))} | {p50:.0f} | {p95:.0f} |") + + +def main(): + parser = argparse.ArgumentParser() + sub = parser.add_subparsers(dest="command", required=True) + run = sub.add_parser("run") + run.add_argument("--mode", choices=["proxy", "direct"], required=True) + run.add_argument("--size-bytes", type=int, required=True) + run.add_argument("--concurrency", type=int, default=10) + run.add_argument("--uploads-per-worker", type=int, default=5) + run.add_argument("--repeat", type=int, default=3) + run.add_argument("--output", required=True) + summarize = sub.add_parser("summarize") + summarize.add_argument("paths", nargs="+") + args = parser.parse_args() + {"run": command_run, "summarize": command_summarize}[args.command](args) + + +if __name__ == "__main__": + main() diff --git a/scripts/lab4/check_s3_security.sh b/scripts/lab4/check_s3_security.sh new file mode 100755 index 00000000..497c5ba1 --- /dev/null +++ b/scripts/lab4/check_s3_security.sh @@ -0,0 +1,54 @@ +#!/bin/sh +# Проверка приватности S3 вне API: анонимный доступ, права отдельных credentials +# API, закрытая консоль. Секреты не печатаются. +set -u +cd "$(dirname "$0")/../.." +env_file="${COMPOSE_ENV_FILE:-.env}" +# shellcheck disable=SC1090 +set -a; . "./$env_file"; set +a +endpoint="${S3_PUBLIC_ENDPOINT:-http://localhost:9000}" +bucket="${S3_BUCKET:-messenger-attachments}" +compose="docker compose --env-file $env_file" +fail=0 + +report() { # status name + if [ "$1" = ok ]; then echo "PASS $2"; else echo "FAIL $2"; fail=1; fi +} + +key=$($compose exec -T postgres psql -U "${POSTGRES_USER:-messenger}" -d "${POSTGRES_DB:-messenger}" -At \ + -c "SELECT object_key FROM attachments WHERE status = 'ready' ORDER BY created_at DESC LIMIT 1") +if [ -z "$key" ]; then + echo "FAIL no ready attachment to check; upload one first (make test)" + exit 1 +fi + +code=$(curl -s -o /dev/null -w '%{http_code}' "$endpoint/$bucket/$key") +[ "$code" = 403 ] && report ok "anonymous GET of a ready object -> 403" || report fail "anonymous GET of a ready object -> $code (want 403)" + +code=$(curl -s -o /dev/null -w '%{http_code}' "$endpoint/$bucket/") +[ "$code" = 403 ] && report ok "anonymous list of the bucket -> 403" || report fail "anonymous list of the bucket -> $code (want 403)" + +code=$(curl -s -o /dev/null -w '%{http_code}' -X PUT --data-binary x "$endpoint/$bucket/attachments/anonymous-write") +[ "$code" = 403 ] && report ok "anonymous PUT -> 403" || report fail "anonymous PUT -> $code (want 403)" + +# The API credentials only, inside a one-off container (secrets come from files). +api_mc() { + $compose run --rm --no-deps -T --entrypoint /bin/sh s3-init -c ' + IFS= read -r k < /run/secrets/s3_api_access_key_id + IFS= read -r s < /run/secrets/s3_api_secret_access_key + export MC_CONFIG_DIR=/tmp/.mc MC_HOST_api="http://$k:$s@s3:9000" + exec mc "$@"' sh "$@" >/dev/null 2>&1 +} + +api_mc mb api/forbidden-bucket && report fail "API credentials can create buckets" || report ok "API credentials cannot create buckets" +api_mc admin info api && report fail "API credentials can use admin API" || report ok "API credentials cannot use admin API" +api_mc stat "api/$bucket/$key" && report ok "API credentials can read attachments/*" || report fail "API credentials cannot read attachments/*" +api_mc stat "api/$bucket/outside-prefix" ; rc=$? +api_mc cp /etc/hostname "api/$bucket/outside-prefix" && report fail "API credentials can write outside attachments/" || report ok "API credentials cannot write outside attachments/" +: "$rc" + +port=$($compose port s3 9001 2>/dev/null || true) +[ -z "$port" ] && report ok "console port 9001 is not published" || report fail "console port 9001 is published ($port)" +if curl -s -o /dev/null --max-time 3 http://localhost:9001; then report fail "console reachable on localhost:9001"; else report ok "console not reachable on localhost:9001"; fi + +exit "$fail" diff --git a/scripts/lab4/consistency_check.sh b/scripts/lab4/consistency_check.sh new file mode 100755 index 00000000..fd97eb7e --- /dev/null +++ b/scripts/lab4/consistency_check.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# Сверка bucket и БД (только чтение): orphans — объект без строки, missing — +# ready-строка без объекта. Код выхода 1, если что-то найдено. +set -eu +cd "$(dirname "$0")/../.." +env_file="${COMPOSE_ENV_FILE:-.env}" +# shellcheck disable=SC1090 +set -a; . "./$env_file"; set +a +bucket="${S3_BUCKET:-messenger-attachments}" +compose="docker compose --env-file $env_file" + +objects=$(mktemp) +rows=$(mktemp) +trap 'rm -f "$objects" "$rows"' EXIT + +$compose run --rm --no-deps -T --entrypoint /bin/sh s3-init -c ' + IFS= read -r u < /run/secrets/minio_root_user + IFS= read -r p < /run/secrets/minio_root_password + export MC_CONFIG_DIR=/tmp/.mc MC_HOST_stand="http://$u:$p@s3:9000" + exec mc ls --recursive "stand/$S3_BUCKET"' 2>/dev/null \ + | sed -n 's/.* \(attachments\/.*\)$/\1/p' | sort > "$objects" +$compose exec -T postgres psql -U "${POSTGRES_USER:-messenger}" -d "${POSTGRES_DB:-messenger}" -At \ + -c "SELECT object_key, status FROM attachments" | sort > "$rows" + +echo "bucket: $bucket" +echo "objects: $(wc -l < "$objects" | tr -d ' ')" +echo "rows by status:" +cut -d'|' -f2 "$rows" | sort | uniq -c | sed 's/^ */ /' +orphans=$(cut -d'|' -f1 "$rows" | sort | comm -13 - "$objects") +missing=$(grep '|ready$' "$rows" | cut -d'|' -f1 | sort | comm -23 - "$objects") +echo "orphans: $(printf '%s' "$orphans" | grep -c . || true)" +[ -z "$orphans" ] || printf '%s\n' "$orphans" | sed 's/^/ orphan /' +echo "missing: $(printf '%s' "$missing" | grep -c . || true)" +[ -z "$missing" ] || printf '%s\n' "$missing" | sed 's/^/ missing /' +[ -z "$orphans$missing" ] diff --git a/scripts/lab4/pngkit.py b/scripts/lab4/pngkit.py new file mode 100644 index 00000000..a29c8864 --- /dev/null +++ b/scripts/lab4/pngkit.py @@ -0,0 +1,50 @@ +"""Synthetic PNG helpers (stdlib only); same semantics as app/test/support/png.ts.""" +import random +import struct +import zlib + +SIGNATURE = b"\x89PNG\r\n\x1a\n" +NOISE_WIDTH = 1024 +NOISE_ROW = 1 + NOISE_WIDTH * 3 + + +def chunk(kind: bytes, data: bytes) -> bytes: + crc = zlib.crc32(kind + data) & 0xFFFFFFFF + return struct.pack(">I", len(data)) + kind + data + struct.pack(">I", crc) + + +def build_png(width: int, height: int, idat: bytes) -> bytes: + ihdr = struct.pack(">IIBBBBB", width, height, 8, 2, 0, 0, 0) + return SIGNATURE + chunk(b"IHDR", ihdr) + chunk(b"IDAT", idat) + chunk(b"IEND", b"") + + +def pad_png(data: bytes, size: int) -> bytes: + """Insert a private ancillary chunk before IEND to reach exactly `size` bytes.""" + extra = size - len(data) + if extra == 0: + return data + if extra < 12: + raise ValueError("padding needs at least 12 bytes") + return data[:-12] + chunk(b"prVt", bytes(extra - 12)) + data[-12:] + + +def _noise_of_height(height: int, rng: random.Random) -> bytes: + raw = bytearray(rng.randbytes(NOISE_ROW * height)) + for row in range(height): + raw[row * NOISE_ROW] = 0 # filter type "none" + compressor = zlib.compressobj(0) + return build_png(NOISE_WIDTH, height, compressor.compress(bytes(raw)) + compressor.flush()) + + +def noise_png(size: int, seed: int = 0) -> bytes: + """Incompressible, structurally valid PNG of exactly `size` bytes.""" + rng = random.Random(seed) + height = max(1, size // NOISE_ROW) + while True: + png = _noise_of_height(height, rng) + if len(png) > size or 0 < size - len(png) < 12: + height -= 1 + if height < 1: + raise ValueError("size is too small") + continue + return pad_png(png, size) diff --git a/scripts/lab4/run_matrix.sh b/scripts/lab4/run_matrix.sh new file mode 100755 index 00000000..c45df4ee --- /dev/null +++ b/scripts/lab4/run_matrix.sh @@ -0,0 +1,23 @@ +#!/bin/sh +# Experiment matrix: sizes x {proxy,direct} at C=10, plus proxy 9.5 MiB at C=20. +# Needs a running stand (make stand-up) and `make init-env` credentials. +set -eu +cd "$(dirname "$0")/../.." +out=evidence/lab4/bench +mkdir -p "$out" +bench() { + mode=$1 size=$2 conc=$3 + python3 scripts/lab4/attachments_bench.py run --mode "$mode" --size-bytes "$size" \ + --concurrency "$conc" --uploads-per-worker 5 --repeat 3 \ + --output "$out/$mode-$size-c$conc.json" +} +for size in 131072 1048576 9961472; do + for mode in proxy direct; do + echo "== $mode size=$size c=10" + bench "$mode" "$size" 10 + done +done +echo "== proxy size=9961472 c=20" +bench proxy 9961472 20 +python3 scripts/lab4/attachments_bench.py summarize "$out"/*.json > evidence/lab4/summary.md +cat evidence/lab4/summary.md -- 2.54.0 From f048a37df9b60d47d86ef59594d59e437fb421e3 Mon Sep 17 00:00:00 2001 From: Ilya Date: Thu, 22 Oct 2026 22:47:48 +0300 Subject: [PATCH 07/15] =?UTF-8?q?lab4:=20evidence,=20REPORT.md,=20=D1=84?= =?UTF-8?q?=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- REPORT.md | 261 ++++++++++++++++++-- app/test/attachments.e2e-spec.ts | 9 +- evidence/lab4/bench/direct-1048576-c10.json | 207 ++++++++++++++++ evidence/lab4/bench/direct-131072-c10.json | 207 ++++++++++++++++ evidence/lab4/bench/direct-9961472-c10.json | 208 ++++++++++++++++ evidence/lab4/bench/proxy-1048576-c10.json | 195 +++++++++++++++ evidence/lab4/bench/proxy-131072-c10.json | 195 +++++++++++++++ evidence/lab4/bench/proxy-9961472-c10.json | 195 +++++++++++++++ evidence/lab4/bench/proxy-9961472-c20.json | 196 +++++++++++++++ evidence/lab4/consistency.txt | 8 + evidence/lab4/direct-ttl-short.txt | 8 + evidence/lab4/failover-attachment.txt | 11 + evidence/lab4/failover.txt | 21 ++ evidence/lab4/make-check.txt | 2 + evidence/lab4/make-test-dependencies.txt | 9 + evidence/lab4/make-test-e2e.txt | 8 + evidence/lab4/make-test.txt | 2 + evidence/lab4/persistence.txt | 29 +++ evidence/lab4/readonly-api.txt | 1 + evidence/lab4/s3-security.txt | 10 + evidence/lab4/summary.md | 9 + evidence/lab4/unit-tests.txt | 8 + 22 files changed, 1782 insertions(+), 17 deletions(-) create mode 100644 evidence/lab4/bench/direct-1048576-c10.json create mode 100644 evidence/lab4/bench/direct-131072-c10.json create mode 100644 evidence/lab4/bench/direct-9961472-c10.json create mode 100644 evidence/lab4/bench/proxy-1048576-c10.json create mode 100644 evidence/lab4/bench/proxy-131072-c10.json create mode 100644 evidence/lab4/bench/proxy-9961472-c10.json create mode 100644 evidence/lab4/bench/proxy-9961472-c20.json create mode 100644 evidence/lab4/consistency.txt create mode 100644 evidence/lab4/direct-ttl-short.txt create mode 100644 evidence/lab4/failover-attachment.txt create mode 100644 evidence/lab4/failover.txt create mode 100644 evidence/lab4/make-check.txt create mode 100644 evidence/lab4/make-test-dependencies.txt create mode 100644 evidence/lab4/make-test-e2e.txt create mode 100644 evidence/lab4/make-test.txt create mode 100644 evidence/lab4/persistence.txt create mode 100644 evidence/lab4/readonly-api.txt create mode 100644 evidence/lab4/s3-security.txt create mode 100644 evidence/lab4/summary.md create mode 100644 evidence/lab4/unit-tests.txt diff --git a/REPORT.md b/REPORT.md index 9ad2b84f..e79fd454 100644 --- a/REPORT.md +++ b/REPORT.md @@ -1,37 +1,270 @@ # Отчёт — лабораторная 4 -- Автор, группа: TODO -- Целевая оценка; выбранный трек 5, если нужен: TODO -- Commit/PR: TODO после публикации -- Использованные источники, библиотеки и помощь ИИ: TODO +- **Автор, группа:** Илья Тюнин; группа — БВТ2303 +- **Целевая оценка:** 5, трек 1 «Прямой upload» (presigned PUT) +- **Commit/PR:** ветка `lab4`, коммиты с префиксом `lab4: ` (стенд MinIO; конфигурация и `ObjectStorage`; + схема и потоковый валидатор; вложения и `attachment_ids`; e2e и отказы; прямая загрузка, скрипты + экспериментов). PR — после пуша ветки в origin. +- **Источники, библиотеки и помощь ИИ:** контракт `contracts/openapi.json`, `contracts/README.md`; + AWS S3 User Guide (object uploads, presigned URLs, checksums); документация MinIO (`mc`, политики, + `MINIO_*_FILE`); AWS SDK for JavaScript v3 (`@aws-sdk/client-s3` 3.1156.0, `s3-request-presigner`, + `@smithy/node-http-handler`); спецификации PNG (RFC 2083 / W3C) и JPEG (ITU-T T.81) для + потокового валидатора. Код и эксперименты подготовлены с помощью ИИ-ассистента; все числа ниже + получены прогонами на описанном стенде и лежат в `evidence/lab4/`. ## Запуск из чистого clone -TODO: версии runtime/образов, prerequisites, команды создания локальных secrets/.env, build, миграций, запуска, ожидания готовности, тестов и остановки. Указать необходимые действия оператора. Не вставлять секреты. Отдельно указать безопасную остановку и команду намеренного удаления учебных данных. +Версии: Docker 29.9.1, Docker Compose v5.6.0, Node.js 25.7.0 (сборка API — образ `node:25.7.0-slim`), +Python 3.14 (проверки и харнесс; нужен ≥3.9). Образы закреплены по digest: +`minio/minio:RELEASE.2025-09-07T16-13-09Z@sha256:14cea493…8936e`, +`minio/mc:RELEASE.2025-08-13T08-35-41Z@sha256:a7fe349e…1727`, `postgres:16.4-alpine`, +`redis:7.4.2-alpine`, `haproxy:3.2-alpine`. Хост — Fedora, 8 логических CPU, 16 GiB RAM. + +```sh +git clone lab4 && cd lab4 +make init-env # создаёт .env (пароль PG, METRICS_TOKEN) и secrets/* (root и API-credentials MinIO); идемпотентно, значения не печатает +make stand-up # docker compose up -d --build --wait: postgres, redis, s3, s3-init, migrate, api x2, haproxy +make wait-ready # GET /health/ready через LB +make test # публичный smoke (через LB) +make check # оффлайн-проверка структуры контракта +make test-e2e # black-box набор: app / attachments / direct-upload (нужны loopback-порты PG, Redis, MinIO) +make test-dependencies # отказы Redis/PG/S3 (останавливают контейнеры стенда и возвращают их) +make s3-security # приватность bucket и права API-credentials вне API +make consistency # сверка bucket и БД (orphans / missing) +make bench # матрица экспериментов, пишет evidence/lab4/bench/*.json и summary.md +make test-persistence ACTION_SCRIPT=scripts/restart.sh +make test-failover ACTION_SCRIPT=scripts/stop-one.sh && scripts/start-replica.sh +``` + +Действия оператора: только `make init-env` (секреты создаются локально в `secrets/`, каталог в +`.gitignore`; `secrets/` и `.env` нельзя коммитить). Остановка с сохранением данных — `make stand-down` +(тома `postgres-data`, `redis-data`, `s3-data` сохраняются). **Намеренное удаление учебных данных:** +`docker compose --env-file .env down -v` (удаляет все три тома, включая загруженные файлы; следующий +`make stand-up` создаёт пустую схему и заново идемпотентно настраивает bucket). + +Короткий TTL для проверки истёкшего URL: `DIRECT_UPLOAD_URL_TTL_SECONDS=5 ATTACHMENT_SWEEP_GRACE_SECONDS=0 +ATTACHMENT_SWEEP_INTERVAL_MS=1000 docker compose --env-file .env up -d --no-deps api`, затем +`E2E_DIRECT_TTL_SHORT=1 scripts/app-e2e.sh direct-upload`, затем вернуть стенд тем же `up -d --no-deps api` +без переменных. ## Архитектура и решения -TODO: схема процессов/хранилищ, источник истины, транзакционные границы, ограничения. Что перенесено из lab3, что изменено в этой работе. Соответствие переменных из .env.example реальной конфигурации. +``` +клиент ──► HAProxy ──► API × 2 ──► PostgreSQL (метаданные, связи, идемпотентность) + │ ├──► Redis (сессии, кэш истории) + │ └──► MinIO (s3) (байты оригиналов, приватный bucket) +клиент ───────────── presigned PUT (трек 1) ───► MinIO (минуя API) +``` + +- **Источник истины:** метаданные и связи «сообщение ↔ вложение» — PostgreSQL (`attachments`, + `message_attachments`); байты — только в bucket по ключу `attachments//original`. Имя файла + хранится для отображения и никогда не попадает в ключ или путь. На API нет локального файла + оригинала: корневая ФС контейнера `read_only: true`, `/tmp` — tmpfs 16 MiB + (`evidence/lab4/readonly-api.txt`). +- **Жизненный цикл строки:** `pending` (байты не подтверждены) → `ready` (видна участникам чата) или + `deleting` (захвачена уборщиком) → строка удалена. Публично существуют только `ready`. + Инварианты в БД: составные FK `(chat_id, owner_id) → chat_members` и + `(attachment_id, chat_id) → attachments(id, chat_id)` делают «вложение другого чата» невозможным; + `CHECK` требует size/sha256/width/height у `ready` и `expires_at` у незавершённых; FK + `message_attachments → attachments` без каскада запрещает удалить вложение, на которое ссылается + сообщение, а каскад удаления чата проходит. +- **Когда честно 201 (proxy):** только после того, как S3 принял весь объект (`PutObject` завершён) и + `UPDATE … SET status='ready' WHERE status='pending'` изменил строку. Этот `UPDATE` проигрывает + захвату уборщиком атомарно (строка уже `deleting` → 503, а не фальшивый 201). +- **S3 PUT прошёл, а COMMIT нет:** строка остаётся `pending`, объект есть. Запрос сначала пытается + компенсировать (`DeleteObject`, затем `DELETE … WHERE status='pending'`); если не удалось + (PG/S3 недоступны) — счётчик `attachments.compensation_deferred`, строка остаётся и через + `expires_at + ATTACHMENT_SWEEP_GRACE_SECONDS` её убирает уборщик (удаляет объект, затем строку). + Сверка: `make consistency`. Наблюдение — `dependency-failures` «compensates the S3 write when + PostgreSQL fails before ready». +- **Потоковая обработка (proxy):** тело читается как поток и сразу идёт в S3 с заранее известным + `Content-Length` (≤ 10 MiB, иначе 413 до чтения). Параллельно `ImageInspector` (байтовый автомат + PNG/JPEG, без декодирования и без буферизации тела) проверяет сигнатуру, структуру, CRC чанков PNG + и число пикселей (≤ 40 млн, 413). До появления заголовка (≤ 1 MiB) нет ни строки, ни объекта. + Последний кусок отдаётся в S3 только после `inspector.finish()` — S3 не получит полное тело + невалидного файла и не зафиксирует объект. Ограничители: `UPLOAD_MAX_IN_FLIGHT` (429 + + `Retry-After`), `UPLOAD_TIMEOUT_MS` (жёсткий дедлайн запроса), тайм-ауты S3-клиента. + Fastify `bodyLimit` к `image/*` не применяется: контент-парсеры отдают сырой поток (для + `text/plain` встроенный буферизующий парсер заменён — иначе бинарное тело давало 400). +- **Прямая загрузка (трек 1):** `POST /api/v1/chats/{id}/attachments/direct-uploads` создаёт строку + `pending` (`expires_at = now + TTL`) и возвращает presigned PUT. Подписаны `content-type`, + `content-length` и `x-amz-checksum-sha256`: S3 сам отвергает тело другого размера (403 + `SignatureDoesNotMatch`) или с другим SHA-256 (400 `XAmzContentChecksumMismatch`), объект при этом + не создаётся (`evidence/lab4/presign-spike.txt`). `POST /api/v1/attachments/{id}/complete` + (только владелец): `HEAD` (размер + подписанный checksum), чтение заголовка изображения (диапазон + до 1 MiB, поток обрывается после получения заголовка), сверка типа и пикселей, `markReady`. + Любое несоответствие → компенсация и 409/413/415; повторный `complete` готового — 200. Лимит + незавершённых заявок на пользователя: `DIRECT_UPLOAD_MAX_PENDING_PER_USER` (429 с `Retry-After`). + Перезапись по тому же URL до истечения TTL возможна только теми же байтами (checksum подписан). + Расширение контракта: `contracts/extensions.openapi.json`; обязательный proxy endpoint не менялся. +- **Почему volume реплики ≠ объектное хранилище:** файл в volume одной реплики недоступен другой, + теряется при пересоздании контейнера и не масштабируется; здесь байты лежат в общем MinIO со своим + томом, поэтому download через любую реплику возвращает тот же объект + (`evidence/lab4/failover-attachment.txt`). +- **Почему случайный ключ и приватный bucket не заменяют ACL приложения:** ключ — не секрет (он + может утечь через логи, presigned URL, дамп БД), а bucket приватен для всех, кроме API. Решение + «кто из пользователей видит вложение» принимает только приложение: каждый запрос метаданных и + content проверяет членство в чате (`findVisible`), посторонний получает 404; у bucket нет + понятия «участник чата». +- **Недоступность S3 — деградация, не отказ готовности:** S3 не входит в `/health/ready`; + вложения отвечают bounded `503 unavailable`, а текст, чаты, история, метаданные продолжают работать. + Так реплики не уходят из ротации LB из-за зависимости, нужной лишь части функций. +- **Секреты:** `secrets/*` монтируются как Docker secrets; MinIO читает root через + `MINIO_ROOT_USER_FILE`/`MINIO_ROOT_PASSWORD_FILE`, API — через `S3_*_FILE`. У API отдельный + пользователь с политикой `messenger-api`: `Get/Put/DeleteObject` только на `attachments/*` и + `ListBucket` (чтобы отсутствующий ключ давал 404, а не 403). `migrate` S3-секретов не получает + (`parseDatabaseConfig`). Консоль MinIO отключена (`MINIO_BROWSER=off`), порт 9001 не публикуется, + порт API S3 `9000` опубликован только на loopback (`S3_PUBLIC_BIND=127.0.0.1`) — нужен клиенту + presigned URL и тестам. + +Что перенесено из lab3: приложение NestJS/Fastify, HAProxy, Redis-сессии, идемпотентность, хуки. +Изменено: `messages.attachment_ids` (в `CREATE_ONCE_SQL` проверка и вставка ссылок в том же операторе, +что и сообщение и ключ идемпотентности; отпечаток текстовых сообщений совпадает с lab3), пустой +`text` допустим при наличии вложений, метрики (`add`, пики памяти с шагом 50 мс), заголовок +`Retry-After` у 429. + +### Соответствие `.env.example` → конфигурация + +| Переменная | Где читается | Назначение | +| --- | --- | --- | +| `S3_ENDPOINT`, `S3_PUBLIC_ENDPOINT` | `ObjectStorage` (клиент `internal` / клиент подписи) | сетевой адрес для API / хост в presigned URL | +| `S3_REGION`, `S3_BUCKET` | `ObjectStorage`, `infra/minio/bootstrap.sh` | регион подписи; имя bucket | +| `S3_ACCESS_KEY_ID_FILE`, `S3_SECRET_ACCESS_KEY_FILE` | `resolveSecret` → `S3_ACCESS_KEY_ID`/`S3_SECRET_ACCESS_KEY` | API-credentials из Docker secrets | +| `S3_CONNECT_TIMEOUT_MS`, `S3_REQUEST_TIMEOUT_MS` | `NodeHttpHandler` | тайм-ауты S3-клиента | +| `MAX_UPLOAD_BYTES`, `MAX_IMAGE_PIXELS` | `AttachmentsService`, `DirectUploadsService` | 10 MiB, 40 млн пикселей | +| `UPLOAD_TIMEOUT_MS`, `UPLOAD_MAX_IN_FLIGHT` | `AttachmentsService` | дедлайн запроса и число одновременных proxy-загрузок на реплику | +| `ATTACHMENT_SWEEP_INTERVAL_MS`, `ATTACHMENT_SWEEP_GRACE_SECONDS` | `AttachmentSweeper`, CLI | период фонового прохода (0 = выкл.) и grace после `expires_at` | +| `DIRECT_UPLOAD_URL_TTL_SECONDS`, `DIRECT_UPLOAD_MAX_PENDING_PER_USER` | `DirectUploadsService` | TTL подписи; лимит незавершённых заявок | +| `S3_PUBLIC_BIND`, `S3_PUBLIC_PORT`, `S3_CPUS`, `S3_MEMORY` | `compose.yaml` (сервис `s3`) | публикация порта на loopback; лимиты контейнера | +| `minio_root_*`, `s3_api_*` | `secrets/*` → `compose.yaml` secrets | credentials; создаются `scripts/init-env.sh` | + +Остальные переменные (`DATABASE_URL`, `REDIS_URL`, `METRICS_TOKEN`, лимиты, порты) — как в lab3. + +### Компенсация, сверка, очистка (grace period) + +`expires_at` у proxy = старт + `UPLOAD_TIMEOUT_MS` (жёсткий дедлайн запроса), у direct = выдача URL + TTL. +Уборщик берёт строку только через `ATTACHMENT_SWEEP_GRACE_SECONDS` (900 с по умолчанию) после этого: +живую загрузку он не застанет, а `markReady … WHERE status='pending'` проигрывает захвату +(`pending → deleting`, `FOR UPDATE SKIP LOCKED`, реплики не мешают друг другу). Застрявшая в +`deleting` строка (упавший уборщик) перезахватывается через минуту. Ручной запуск: +`docker compose exec api node dist/attachments/attachments-sweep.cli.js`. Сверка в обе стороны (только +чтение): `make consistency` — `orphans` (объект без строки) и `missing` (`ready` без объекта). +Отсутствующий объект у `ready`-строки при download — это потеря данных: 500 и счётчик +`attachments.object_missing`, а не клиентская ошибка. ## Доказательства критериев +Все файлы — в `evidence/lab4/`; в них нет `.env`, токенов, секретов и подписанных URL. + | Критерий README | Команда/сценарий | Наблюдаемый результат | Файл доказательства | | --- | --- | --- | --- | -| Публичный smoke | make test | TODO | TODO | -| Остальные пункты уровня 3 | TODO | TODO | TODO | -| Все пункты уровня 4, если заявлен | TODO | TODO | TODO | -| Выбранный трек 5, если заявлен | TODO | TODO | TODO | +| Публичный smoke | `make test` | `PASS: lab4 public API scenario` (upload 201 ready, сообщение с `''` и `attachment_ids`, download bob = байты, eve 404) | `make-test.txt` | +| Контракт offline | `make check` | PASS, `contracts/extensions.openapi.json` — валидный JSON | `make-check.txt` | +| 3: S3 в общем стенде, приватный bucket, метаданные в PG, байты в bucket | `make stand-up`; `docker compose ps`; `make consistency` | `s3` healthy, `s3-init` завершён с 0; bucket приватный (`mc anonymous set none`); число объектов в bucket = числу `ready`-строк (1308 после серии `make bench` и e2e), orphans/missing = 0 | `bootstrap-rerun.txt`, `consistency.txt` | +| 3: 201 ready, побайтный download, `attachment_ids` | `make test-e2e` (`attachments.e2e-spec.ts`) | sha256 в ответе = sha256 файла; content = байты, `nosniff`, `Content-Length` | `make-test-e2e.txt` | +| 3: PNG/JPEG ≤10 MiB и ≤40 млн px; MIME по содержимому; опасные filename; лимиты до чтения | e2e: 10485760 → 201, 10485761 → 413, pixel bomb 8000×5001 → 413 сразу после IHDR, PNG как `image/jpeg` → 415, `a/b.png`, `\u202E`, NUL, 256 символов → 400, 255×😀 → 201 | все кейсы зелёные, пользовательских 500 нет | `make-test-e2e.txt`, `unit-tests.txt` (`image-inspector.spec.ts`) | +| 3: другая реплика отдаёт файл после остановки загрузившей; restart сохраняет данные | `scripts/stop-one.sh` (обе реплики по очереди), `make test-failover`; `make test-persistence ACTION_SCRIPT=scripts/restart.sh` | failover: 0 неуспешных попыток, восстановление ≈3.3 с; download с тем же sha256 после остановки api-1 и api-2; persistence: `StartedAt` у postgres, redis, s3, api×2, haproxy изменился, данные и сессия сохранены | `failover.txt`, `failover-attachment.txt`, `persistence.txt` | +| 3: на API нет локального файла оригинала | `touch` в корне контейнера | `Read-only file system` | `readonly-api.txt` | +| 4: тесты: большой файл, повреждённое изображение, подмена MIME, чужое `attachment_id`, вложение другого чата, нет 500 | `make test-e2e` | 413; усечённый PNG, флип байта (CRC), сигнатура+мусор, пустое тело → 415; подмена MIME → 415; чужое/неизвестное/незавершённое → 404; вложение чата eve в чате alice → 404 | `make-test-e2e.txt` | +| 4: прерывание загрузки и отказ между S3/БД не оставляют вечных объектов | e2e «client drops the connection»; `make test-dependencies` | обрыв клиента → строк 0 за ≤10 с; S3 down → одна `pending`, после старта и sweep — 0; PG down между PUT и ready → 503, объекта в S3 нет, `pending` убрана sweep; затем `orphans: 0, missing: 0` | `make-test-e2e.txt`, `make-test-dependencies.txt`, `consistency.txt` | +| 4: лимиты, таймауты, потоковая обработка; эксперимент ≥10 загрузок с пиком памяти | `make bench` (proxy, C=10 и C=20, 9.5 MiB) | max Δrss реплики 10.7 MiB при C=10 и 17.9 MiB при C=20 против 95/190 MiB тел в полёте — см. «Эксперименты» | `summary.md`, `bench/*.json` | +| 4: идемпотентный bootstrap; отдельные ограниченные credentials; консоль закрыта; private bucket вне API | `docker compose run s3-init` дважды; `make s3-security` | повтор → `bootstrap ok`; анонимные GET/list/PUT → 403; API-credentials не создают bucket, не вызывают admin, не пишут вне `attachments/`, читают `attachments/*`; порт 9001 не опубликован и не отвечает | `bootstrap-rerun.txt`, `s3-security.txt` | +| 5 / трек 1: presigned flow (короткая подпись, уникальный ключ, принадлежность, размер/checksum на complete, незавершённые) | `direct-upload.e2e-spec.ts`; спайк подписи | init → PUT мимо API → complete → metadata/content → сообщение; чужой/посторонний complete → 404; подмена байта → S3 400, затем complete 409; JPEG под видом PNG → 415, затем 404; pixel bomb → 413; 11-я заявка → 429 + `Retry-After` | `make-test-e2e.txt`, `presign-spike.txt` | +| 5 / трек 1: истёкший URL и уборка | `E2E_DIRECT_TTL_SHORT=1` на стенде с TTL 5 с | PUT после `expires_at` → 403, строка убрана уборщиком, complete → 404 | `direct-ttl-short.txt` | +| 5 / трек 1: сравнение трафика и RAM API на ≥2 размерах | `make bench` (0.125, 1, 9.5 MiB) | см. таблицу ниже | `summary.md`, `bench/*.json` | -TODO: добавить отдельную строку для каждого заявленного критерия. PASS без команды и наблюдения не является доказательством. Проверка инфраструктурного hook требует подтверждения, какие реальные процессы/хранилища перезапущены. +Оговорка по hook'ам: `make test-persistence` и `make test-failover` подтверждают сохранность данных и +сессии; какие процессы перезапущены, видно по `StartedAt` до/после (`persistence.txt`). +`scripts/stop-one.sh` останавливает только реплику, обслужившую сессию теста (в трёх прогонах +`make test-failover` это была одна и та же реплика), поэтому остановка обеих реплик показана отдельно +`failover-attachment.txt`. ## Эксперименты и отказы -TODO: гипотеза, hardware/лимиты, версии, объём данных, профиль нагрузки, concurrency/arrival rate, длительность/прогрев, повторы, успешные RPS, ошибки, p50/p95/p99, CPU/RAM. Сохранить raw summary без tokens и объяснить ограничения измерения. +**Методика.** Хост: 8 логических CPU, 16 GiB RAM, один Docker-хост. Лимиты: API 1.5 CPU / 768 MiB на +реплику (2 реплики), MinIO 1 CPU / 512 MiB, PG 1.5 CPU / 512 MiB. Версии — см. «Запуск». Нагрузка: +`scripts/lab4/attachments_bench.py`, closed-loop: C потоков × 5 загрузок несжимаемых PNG +(`noise_png`, разные seed), R = 3 повтора, перед каждым повтором — прогрев (не измеряется) и +`POST /internal/metrics/reset` на каждой реплике. Трафик API — дельта `eth0` rx/tx из `/proc/net/dev` +контейнера; RAM — пик `process.memoryUsage().rss` с шагом 50 мс минус RSS в момент reset (Δrss); +в таблицу идёт медиана по повторам, для Δrss — максимум по репликам. Команда: `make bench` +(`scripts/lab4/run_matrix.sh`); raw — `evidence/lab4/bench/*.json` (без токенов и URL). + +**H1 (уровень 4).** Потоковый proxy держит рост пикового RSS реплики ограниченным и почти независимым +от размера файла: Δrss при 10 × 9.5 MiB много меньше суммарного объёма тел в полёте. + +**H2 (трек 1).** Прямая загрузка снижает трафик API на загрузку с ≈2 × size (вход от клиента + выход в +S3) до малой величины, не зависящей от размера, и не растит RSS; латентность малых файлов у direct +выше из-за трёх round trip. + +Результаты (`evidence/lab4/summary.md`; 150 загрузок на строку при C=10, 300 при C=20; ошибок 0): + +| mode | size, MiB | C | API rx/upload, MiB | API tx/upload, MiB | max Δrss, MiB | p50, ms | p95, ms | +| --- | --- | --- | --- | --- | --- | --- | --- | +| direct | 0.12 | 10 | 0.13 | 0.01 | 0.62 | 42 | 62 | +| proxy | 0.12 | 10 | 0.13 | 0.13 | 3.75 | 26 | 53 | +| direct | 1.00 | 10 | 1.01 | 0.01 | 3.88 | 69 | 100 | +| proxy | 1.00 | 10 | 1.01 | 1.01 | 5.12 | 44 | 79 | +| direct | 9.50 | 10 | 0.14 | 0.01 | 0.25 | 377 | 493 | +| proxy | 9.50 | 10 | 9.53 | 9.53 | 10.65 | 212 | 374 | +| proxy | 9.50 | 20 | 9.53 | 9.53 | 17.92 | 414 | 802 | + +Выводы: + +- **H1 подтверждена с оговоркой.** При C=10 и 9.5 MiB пик Δrss — 10.7 MiB при ≈95 MiB тел в полёте; при + C=20 — 17.9 MiB при ≈190 MiB. Память не пропорциональна размеру файла (размер ×76: 0.12 → 9.5 MiB + дал Δrss 3.75 → 10.65 MiB, ×2.8), но и не строго постоянна: растёт слабо с размером и с + concurrency (буферы сокетов, чанки в полёте, аллокатор). Δrss — шумная величина (между повторами одной + конфигурации 9.0–13.4 MiB для proxy 9.5 MiB C=10 и 2.0–5.5 MiB для proxy 1 MiB). +- **H2 подтверждена частично.** Для proxy tx ≈ rx ≈ size (≈2 × size суммарно: вход от клиента и выход + в S3). Для direct при size > 1 MiB API видит ≈0.14 MiB rx (заголовок изображения) и ≈0.01 MiB tx + независимо от размера, Δrss ≈ 0. **Для size ≤ 1 MiB direct не снижает входящий трафик API:** + `complete` читает диапазон до `IMAGE_HEADER_MAX_BYTES` = 1 MiB, и если он покрывает весь объект, + файл дочитывается до конца для `finish()` (структурная проверка) — rx = size (0.13 и 1.01 MiB); + выигрыш только по tx (≈0.01 против size). Латентность direct выше при малых/средних файлах + (p50 42 против 26 мс, 69 против 44 мс — три запроса вместо одного) и выше на 9.5 MiB + (377 против 212 мс): клиент заливает через loopback в MinIO с лимитом 1 CPU, а не через API; прирост + не объясняется в эксперименте и остаётся гипотезой (вероятно, проверка подписи и checksum в MinIO). + +**Ограничения измерений.** Один Docker-хост: клиент, LB, API и MinIO делят 8 CPU, без реальной сети; +`/proc/net/dev` реплики включает трафик PG/Redis и служебные запросы метрик (≈7–8 KiB на загрузку, +видно в tx у direct); closed-loop клиент не моделирует arrival rate; выборка RSS 50 мс может +пропустить короткий пик; нет TLS (до lab7); Python-клиент сам ограничен по CPU, поэтому абсолютные +латентности не переносимы. + +### Отказы | Воздействие | Что ожидаем | Что наблюдали | Время восстановления / потеря данных | | --- | --- | --- | --- | -| TODO | TODO | TODO | TODO | +| S3 остановлен (`compose stop s3`) | вложения → bounded 503; текст, история, метаданные, `/health/ready` работают | upload → 503 `unavailable` без утечки деталей; метаданные 200; content 503; текстовое сообщение 201; readiness 200; одна `pending`-строка неудачной загрузки | после `start s3` и healthy download старого файла 200 с теми же байтами, новый upload 201; `pending` убрана sweep; потерь нет | +| PostgreSQL остановлен между S3 PUT и `ready` | 503; объект не должен остаться | ответ 503; объект в S3 компенсирован (`mc stat` — нет), `pending`-строка осталась (БД недоступна) | после старта PG и `waitForReadiness`; строка убрана sweep после `expires_at`; `orphans: 0` | +| Обрыв клиента посреди загрузки (512 KiB из 2 MiB) | не остаётся ни строки, ни объекта | `AbortError` у PUT (без ожидания тайм-аута), компенсация, строк в чате 0 | ≤10 с (предел ожидания теста; точное время не измерялось) | +| Остановка обслужившей реплики | другая реплика отдаёт тот же файл | download 200, тот же sha256, другой `X-Instance-Id` для api-1 и api-2 | ≈3.3 с до первого успешного запроса, 0 неуспешных записей из 134–140 | +| Restart стенда (`scripts/restart.sh`) | метаданные и оригиналы сохраняются, сессия жива | persistence PASS; `StartedAt` всех сервисов изменился | весь прогон `make test-persistence` — 11 с; потерь нет | +| Истёкший presigned URL | PUT отвергается, заявка убирается | PUT → 403; строка убрана уборщиком; complete → 404 | TTL (5 с в прогоне) + grace 0 + период уборщика 1 с | +| Подмена байтов / размера при прямой загрузке | S3 отвергает, объект не создаётся | 400 `XAmzContentChecksumMismatch` / 403 `SignatureDoesNotMatch`; complete → 409 | заявка остаётся до TTL, клиент может доотправить | ## Ограничения и следующие шаги -TODO: какие отказы выдерживаются и какие нет; что не реализовано; где учебное упрощение; какое улучшение подтверждено, а какое пока гипотеза. +- **MinIO:** закреплён образ `RELEASE.2025-09-07T16-13-09Z`; по данным, использованным при планировании, + репозиторий `minio/minio` архивирован — новых образов и исправлений не будет *(в этой сессии не + перепроверялось)*. Для продакшена потребуется замена (SeaweedFS/RustFS) или форк. +- **Прямой путь не проверяет структуру хвоста файла** при size > 1 MiB: только заголовок (до 1 MiB) и + подписанный SHA-256/размер. Байты гарантированно те, что заявил клиент, но заявил он их сам; + усечённый или «склеенный» файл с корректным заголовком пройдёт `complete`. В proxy-режиме проверяется + весь поток (CRC чанков PNG, EOI JPEG). Для size ≤ 1 MiB direct проверяет всё, ценой входящего + трафика API. +- **Гонка лимита заявок:** `countPendingDirect` и `insertPending` не атомарны — параллельные `init` + одного пользователя могут превысить лимит на число параллельных запросов; для лабораторной принято. +- **Загрузка, не доставленная до `ready`, видна уборщику только через grace (по умолчанию 15 мин):** + до этого объект занимает место; для быстрой очистки в тестах grace уменьшается переменной окружения. +- **Недоступность S3 при `compensate`** оставляет объект, если сам `DeleteObject` не прошёл; его + убирает уборщик, но объект без строки (если строка уже удалена вручную) обнаружит только + `make consistency` — автоматического reconciler'а для orphan-объектов без строки нет (это трек 2). +- **TLS нет** до lab7: presigned URL и токены ходят по HTTP; консоль MinIO отключена полностью, поэтому + администрирование — только через `mc` из контейнера. +- **Не реализовано:** варианты вложений (`variants` всегда `[]`; `variant=thumbnail|crop|optimized` → 404), + delete-API вложений, WebP. +- **Подтверждено измерением:** потоковый proxy ограничивает память, direct уменьшает tx API и rx API для + файлов > 1 MiB. **Остаётся гипотезой:** причина роста латентности direct на 9.5 MiB; зависимость Δrss от + concurrency за пределами C=20. diff --git a/app/test/attachments.e2e-spec.ts b/app/test/attachments.e2e-spec.ts index ae6d08c0..4ab1009d 100644 --- a/app/test/attachments.e2e-spec.ts +++ b/app/test/attachments.e2e-spec.ts @@ -314,9 +314,12 @@ describe('attachments (proxy upload)', () => { it('serves unknown content variants as errors, not bytes', async () => { const created = await ready(png); const variant = (name: string) => - http(`/api/v1/attachments/${created.id}/content?variant=${name}`, { - headers: bearer(alice.token), - }); + http( + `/api/v1/attachments/${created.id}/content?variant=${name}`, + { + headers: bearer(alice.token), + }, + ); expect((await variant('original')).response.status).toBe(200); expectError(await variant('thumbnail'), 404, 'not_found'); expectError(await variant('bogus'), 400, 'invalid_request'); diff --git a/evidence/lab4/bench/direct-1048576-c10.json b/evidence/lab4/bench/direct-1048576-c10.json new file mode 100644 index 00000000..ff6950e6 --- /dev/null +++ b/evidence/lab4/bench/direct-1048576-c10.json @@ -0,0 +1,207 @@ +{ + "date": "2026-10-22T19:43:37+00:00", + "git": "39a6df8", + "params": { + "mode": "direct", + "size_bytes": 1048576, + "concurrency": 10, + "uploads_per_worker": 5, + "repeat": 3 + }, + "host": { + "nproc": 8, + "mem_total_bytes": 16538955776 + }, + "api_container_limits_nanocpus_memory": [ + "1500000000 805306368", + "1500000000 805306368" + ], + "repeats": [ + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 0.472, + "latency_ms": { + "p50": 68.8, + "p95": 100.5, + "p99": 116.7 + }, + "replicas": [ + { + "instance_id": "b50bb8514a7b", + "delta_rx_bytes": 24305156, + "delta_tx_bytes": 190336, + "baseline_rss_bytes": 196403200, + "peak_memory_bytes": { + "rss": 196403200, + "heap_used": 54520056, + "external": 19317560, + "array_buffers": 15527216 + }, + "delta_rss_bytes": 0, + "counters": { + "attachments.count_pending_direct": 27, + "attachments.insert_pending": 27, + "attachments.direct.initiated": 27, + "attachments.find_for_complete": 23, + "attachments.direct.verify_bytes": 24117248, + "attachments.mark_ready": 23, + "attachments.direct.completed": 23 + } + }, + { + "instance_id": "fc61f806b880", + "delta_rx_bytes": 28515385, + "delta_tx_bytes": 191536, + "baseline_rss_bytes": 192991232, + "peak_memory_bytes": { + "rss": 192991232, + "heap_used": 50609288, + "external": 23827415, + "array_buffers": 13323225 + }, + "delta_rss_bytes": 0, + "counters": { + "attachments.count_pending_direct": 23, + "attachments.insert_pending": 23, + "attachments.direct.initiated": 23, + "attachments.find_for_complete": 27, + "attachments.direct.verify_bytes": 28311552, + "attachments.mark_ready": 27, + "attachments.direct.completed": 27 + } + } + ], + "total_delta_rx_bytes": 52820541, + "total_delta_tx_bytes": 381872, + "rx_bytes_per_upload": 1056411, + "tx_bytes_per_upload": 7637, + "max_delta_rss_bytes": 0 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 0.526, + "latency_ms": { + "p50": 73.9, + "p95": 109.6, + "p99": 127.7 + }, + "replicas": [ + { + "instance_id": "b50bb8514a7b", + "delta_rx_bytes": 28515174, + "delta_tx_bytes": 193117, + "baseline_rss_bytes": 193875968, + "peak_memory_bytes": { + "rss": 203390976, + "heap_used": 57046056, + "external": 29834167, + "array_buffers": 26043823 + }, + "delta_rss_bytes": 9515008, + "counters": { + "attachments.count_pending_direct": 23, + "attachments.insert_pending": 23, + "attachments.direct.initiated": 23, + "attachments.find_for_complete": 27, + "attachments.direct.verify_bytes": 28311552, + "attachments.mark_ready": 27, + "attachments.direct.completed": 27 + } + }, + { + "instance_id": "fc61f806b880", + "delta_rx_bytes": 24304620, + "delta_tx_bytes": 183249, + "baseline_rss_bytes": 187240448, + "peak_memory_bytes": { + "rss": 193400832, + "heap_used": 55168312, + "external": 23469861, + "array_buffers": 19679517 + }, + "delta_rss_bytes": 6160384, + "counters": { + "attachments.count_pending_direct": 27, + "attachments.insert_pending": 27, + "attachments.direct.initiated": 27, + "attachments.find_for_complete": 23, + "attachments.direct.verify_bytes": 24117248, + "attachments.mark_ready": 23, + "attachments.direct.completed": 23 + } + } + ], + "total_delta_rx_bytes": 52819794, + "total_delta_tx_bytes": 376366, + "rx_bytes_per_upload": 1056396, + "tx_bytes_per_upload": 7527, + "max_delta_rss_bytes": 9515008 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 0.466, + "latency_ms": { + "p50": 64.7, + "p95": 93.7, + "p99": 107.8 + }, + "replicas": [ + { + "instance_id": "b50bb8514a7b", + "delta_rx_bytes": 26412041, + "delta_tx_bytes": 186281, + "baseline_rss_bytes": 195010560, + "peak_memory_bytes": { + "rss": 195010560, + "heap_used": 51614528, + "external": 19277639, + "array_buffers": 15487295 + }, + "delta_rss_bytes": 0, + "counters": { + "attachments.count_pending_direct": 25, + "attachments.insert_pending": 25, + "attachments.direct.initiated": 25, + "attachments.find_for_complete": 25, + "attachments.direct.verify_bytes": 26214400, + "attachments.mark_ready": 25, + "attachments.direct.completed": 25 + } + }, + { + "instance_id": "fc61f806b880", + "delta_rx_bytes": 26410201, + "delta_tx_bytes": 187551, + "baseline_rss_bytes": 190717952, + "peak_memory_bytes": { + "rss": 194781184, + "heap_used": 53366896, + "external": 19243061, + "array_buffers": 15452717 + }, + "delta_rss_bytes": 4063232, + "counters": { + "attachments.count_pending_direct": 25, + "attachments.insert_pending": 25, + "attachments.direct.initiated": 25, + "attachments.find_for_complete": 25, + "attachments.direct.verify_bytes": 26214400, + "attachments.mark_ready": 25, + "attachments.direct.completed": 25 + } + } + ], + "total_delta_rx_bytes": 52822242, + "total_delta_tx_bytes": 373832, + "rx_bytes_per_upload": 1056445, + "tx_bytes_per_upload": 7477, + "max_delta_rss_bytes": 4063232 + } + ] +} diff --git a/evidence/lab4/bench/direct-131072-c10.json b/evidence/lab4/bench/direct-131072-c10.json new file mode 100644 index 00000000..5ec49ab8 --- /dev/null +++ b/evidence/lab4/bench/direct-131072-c10.json @@ -0,0 +1,207 @@ +{ + "date": "2026-10-22T19:43:26+00:00", + "git": "39a6df8", + "params": { + "mode": "direct", + "size_bytes": 131072, + "concurrency": 10, + "uploads_per_worker": 5, + "repeat": 3 + }, + "host": { + "nproc": 8, + "mem_total_bytes": 16538955776 + }, + "api_container_limits_nanocpus_memory": [ + "1500000000 805306368", + "1500000000 805306368" + ], + "repeats": [ + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 0.265, + "latency_ms": { + "p50": 48.2, + "p95": 62.4, + "p99": 72.8 + }, + "replicas": [ + { + "instance_id": "b50bb8514a7b", + "delta_rx_bytes": 3306431, + "delta_tx_bytes": 182851, + "baseline_rss_bytes": 182366208, + "peak_memory_bytes": { + "rss": 184594432, + "heap_used": 61323144, + "external": 8848467, + "array_buffers": 5055973 + }, + "delta_rss_bytes": 2228224, + "counters": { + "attachments.count_pending_direct": 26, + "attachments.insert_pending": 26, + "attachments.direct.initiated": 26, + "attachments.find_for_complete": 24, + "attachments.direct.verify_bytes": 3145728, + "attachments.mark_ready": 24, + "attachments.direct.completed": 24 + } + }, + { + "instance_id": "fc61f806b880", + "delta_rx_bytes": 3573839, + "delta_tx_bytes": 184939, + "baseline_rss_bytes": 182042624, + "peak_memory_bytes": { + "rss": 182796288, + "heap_used": 60727960, + "external": 8999631, + "array_buffers": 5207169 + }, + "delta_rss_bytes": 753664, + "counters": { + "attachments.count_pending_direct": 24, + "attachments.insert_pending": 24, + "attachments.direct.initiated": 24, + "attachments.find_for_complete": 26, + "attachments.direct.verify_bytes": 3407872, + "attachments.mark_ready": 26, + "attachments.direct.completed": 26 + } + } + ], + "total_delta_rx_bytes": 6880270, + "total_delta_tx_bytes": 367790, + "rx_bytes_per_upload": 137605, + "tx_bytes_per_upload": 7356, + "max_delta_rss_bytes": 2228224 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 0.211, + "latency_ms": { + "p50": 36.7, + "p95": 50.0, + "p99": 54.8 + }, + "replicas": [ + { + "instance_id": "b50bb8514a7b", + "delta_rx_bytes": 3574513, + "delta_tx_bytes": 184486, + "baseline_rss_bytes": 184594432, + "peak_memory_bytes": { + "rss": 184987648, + "heap_used": 60934432, + "external": 9389278, + "array_buffers": 5596784 + }, + "delta_rss_bytes": 393216, + "counters": { + "attachments.count_pending_direct": 24, + "attachments.insert_pending": 24, + "attachments.direct.initiated": 24, + "attachments.find_for_complete": 26, + "attachments.direct.verify_bytes": 3407872, + "attachments.mark_ready": 26, + "attachments.direct.completed": 26 + } + }, + { + "instance_id": "fc61f806b880", + "delta_rx_bytes": 3306277, + "delta_tx_bytes": 181456, + "baseline_rss_bytes": 182796288, + "peak_memory_bytes": { + "rss": 183058432, + "heap_used": 59419712, + "external": 8997869, + "array_buffers": 5205407 + }, + "delta_rss_bytes": 262144, + "counters": { + "attachments.count_pending_direct": 26, + "attachments.insert_pending": 26, + "attachments.direct.initiated": 26, + "attachments.find_for_complete": 24, + "attachments.direct.verify_bytes": 3145728, + "attachments.mark_ready": 24, + "attachments.direct.completed": 24 + } + } + ], + "total_delta_rx_bytes": 6880790, + "total_delta_tx_bytes": 365942, + "rx_bytes_per_upload": 137616, + "tx_bytes_per_upload": 7319, + "max_delta_rss_bytes": 393216 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 0.241, + "latency_ms": { + "p50": 41.6, + "p95": 64.6, + "p99": 72.2 + }, + "replicas": [ + { + "instance_id": "b50bb8514a7b", + "delta_rx_bytes": 3574028, + "delta_tx_bytes": 183565, + "baseline_rss_bytes": 184987648, + "peak_memory_bytes": { + "rss": 185643008, + "heap_used": 62756424, + "external": 9669133, + "array_buffers": 5876639 + }, + "delta_rss_bytes": 655360, + "counters": { + "attachments.count_pending_direct": 24, + "attachments.insert_pending": 24, + "attachments.direct.initiated": 24, + "attachments.find_for_complete": 26, + "attachments.direct.verify_bytes": 3407872, + "attachments.mark_ready": 26, + "attachments.direct.completed": 26 + } + }, + { + "instance_id": "fc61f806b880", + "delta_rx_bytes": 3306617, + "delta_tx_bytes": 181349, + "baseline_rss_bytes": 183058432, + "peak_memory_bytes": { + "rss": 183713792, + "heap_used": 62301928, + "external": 9312649, + "array_buffers": 5520187 + }, + "delta_rss_bytes": 655360, + "counters": { + "attachments.count_pending_direct": 26, + "attachments.insert_pending": 26, + "attachments.direct.initiated": 26, + "attachments.find_for_complete": 24, + "attachments.direct.verify_bytes": 3145728, + "attachments.mark_ready": 24, + "attachments.direct.completed": 24 + } + } + ], + "total_delta_rx_bytes": 6880645, + "total_delta_tx_bytes": 364914, + "rx_bytes_per_upload": 137613, + "tx_bytes_per_upload": 7298, + "max_delta_rss_bytes": 655360 + } + ] +} diff --git a/evidence/lab4/bench/direct-9961472-c10.json b/evidence/lab4/bench/direct-9961472-c10.json new file mode 100644 index 00000000..f0b946b7 --- /dev/null +++ b/evidence/lab4/bench/direct-9961472-c10.json @@ -0,0 +1,208 @@ +{ + "date": "2026-10-22T19:44:02+00:00", + "git": "39a6df8", + "params": { + "mode": "direct", + "size_bytes": 9961472, + "concurrency": 10, + "uploads_per_worker": 5, + "repeat": 3 + }, + "host": { + "nproc": 8, + "mem_total_bytes": 16538955776 + }, + "api_container_limits_nanocpus_memory": [ + "1500000000 805306368", + "1500000000 805306368" + ], + "repeats": [ + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 2.977, + "latency_ms": { + "p50": 373.6, + "p95": 580.2, + "p99": 606.3 + }, + "replicas": [ + { + "instance_id": "b50bb8514a7b", + "delta_rx_bytes": 5859769, + "delta_tx_bytes": 204758, + "baseline_rss_bytes": 206934016, + "peak_memory_bytes": { + "rss": 207065088, + "heap_used": 59528520, + "external": 23734700, + "array_buffers": 19944356 + }, + "delta_rss_bytes": 131072, + "counters": { + "attachments.count_pending_direct": 24, + "attachments.insert_pending": 24, + "attachments.direct.initiated": 24, + "attachments.find_for_complete": 26, + "attachments.direct.verify_bytes": 573886, + "attachments.mark_ready": 26, + "attachments.direct.completed": 26 + } + }, + { + "instance_id": "fc61f806b880", + "delta_rx_bytes": 2941745, + "delta_tx_bytes": 201620, + "baseline_rss_bytes": 204890112, + "peak_memory_bytes": { + "rss": 205152256, + "heap_used": 58915888, + "external": 11971121, + "array_buffers": 8180777 + }, + "delta_rss_bytes": 262144, + "counters": { + "attachments.count_pending_direct": 26, + "attachments.insert_pending": 26, + "attachments.direct.initiated": 26, + "attachments.find_for_complete": 24, + "attachments.direct.verify_bytes": 454808, + "attachments.mark_ready": 24, + "attachments.direct.completed": 24 + } + } + ], + "total_delta_rx_bytes": 8801514, + "total_delta_tx_bytes": 406378, + "rx_bytes_per_upload": 176030, + "tx_bytes_per_upload": 8128, + "max_delta_rss_bytes": 262144 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 3.016, + "latency_ms": { + "p50": 377.9, + "p95": 493.4, + "p99": 534.7 + }, + "replicas": [ + { + "instance_id": "b50bb8514a7b", + "delta_rx_bytes": 3426165, + "delta_tx_bytes": 205333, + "baseline_rss_bytes": 207065088, + "peak_memory_bytes": { + "rss": 210079744, + "heap_used": 59538608, + "external": 12156543, + "array_buffers": 8366167 + }, + "delta_rss_bytes": 3014656, + "counters": { + "attachments.count_pending_direct": 24, + "attachments.insert_pending": 24, + "attachments.direct.initiated": 24, + "attachments.find_for_complete": 26, + "attachments.direct.verify_bytes": 553814, + "attachments.mark_ready": 26, + "attachments.direct.completed": 26 + } + }, + { + "instance_id": "fc61f806b880", + "delta_rx_bytes": 2100305, + "delta_tx_bytes": 201255, + "baseline_rss_bytes": 205152256, + "peak_memory_bytes": { + "rss": 208429056, + "heap_used": 59913256, + "external": 9769093, + "array_buffers": 5978717 + }, + "delta_rss_bytes": 3276800, + "counters": { + "attachments.count_pending_direct": 26, + "attachments.insert_pending": 26, + "attachments.direct.initiated": 26, + "attachments.find_for_complete": 24, + "attachments.direct.verify_bytes": 258704, + "attachments.mark_ready": 24, + "attachments.direct.completed": 24 + } + } + ], + "total_delta_rx_bytes": 5526470, + "total_delta_tx_bytes": 406588, + "rx_bytes_per_upload": 110529, + "tx_bytes_per_upload": 8132, + "max_delta_rss_bytes": 3276800 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 3.128, + "latency_ms": { + "p50": 376.7, + "p95": 483.1, + "p99": 546.2 + }, + "replicas": [ + { + "instance_id": "b50bb8514a7b", + "delta_rx_bytes": 3752711, + "delta_tx_bytes": 204356, + "baseline_rss_bytes": 207192064, + "peak_memory_bytes": { + "rss": 207192064, + "heap_used": 59773496, + "external": 12099081, + "array_buffers": 8308705 + }, + "delta_rss_bytes": 0, + "counters": { + "attachments.claim_expired": 1, + "attachments.count_pending_direct": 24, + "attachments.insert_pending": 24, + "attachments.direct.initiated": 24, + "attachments.find_for_complete": 26, + "attachments.direct.verify_bytes": 458246, + "attachments.mark_ready": 26, + "attachments.direct.completed": 26 + } + }, + { + "instance_id": "fc61f806b880", + "delta_rx_bytes": 3511316, + "delta_tx_bytes": 203010, + "baseline_rss_bytes": 205549568, + "peak_memory_bytes": { + "rss": 205549568, + "heap_used": 59832920, + "external": 10075786, + "array_buffers": 6285218 + }, + "delta_rss_bytes": 0, + "counters": { + "attachments.count_pending_direct": 26, + "attachments.insert_pending": 26, + "attachments.direct.initiated": 26, + "attachments.find_for_complete": 24, + "attachments.direct.verify_bytes": 477352, + "attachments.mark_ready": 24, + "attachments.direct.completed": 24 + } + } + ], + "total_delta_rx_bytes": 7264027, + "total_delta_tx_bytes": 407366, + "rx_bytes_per_upload": 145281, + "tx_bytes_per_upload": 8147, + "max_delta_rss_bytes": 0 + } + ] +} diff --git a/evidence/lab4/bench/proxy-1048576-c10.json b/evidence/lab4/bench/proxy-1048576-c10.json new file mode 100644 index 00000000..5df735eb --- /dev/null +++ b/evidence/lab4/bench/proxy-1048576-c10.json @@ -0,0 +1,195 @@ +{ + "date": "2026-10-22T19:43:32+00:00", + "git": "39a6df8", + "params": { + "mode": "proxy", + "size_bytes": 1048576, + "concurrency": 10, + "uploads_per_worker": 5, + "repeat": 3 + }, + "host": { + "nproc": 8, + "mem_total_bytes": 16538955776 + }, + "api_container_limits_nanocpus_memory": [ + "1500000000 805306368", + "1500000000 805306368" + ], + "repeats": [ + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 0.391, + "latency_ms": { + "p50": 44.5, + "p95": 80.1, + "p99": 85.9 + }, + "replicas": [ + { + "instance_id": "b50bb8514a7b", + "delta_rx_bytes": 26377008, + "delta_tx_bytes": 26400949, + "baseline_rss_bytes": 185679872, + "peak_memory_bytes": { + "rss": 191053824, + "heap_used": 54312648, + "external": 18076371, + "array_buffers": 14283909 + }, + "delta_rss_bytes": 5373952, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 26214400, + "attachments.proxy.bytes_to_s3": 26214400, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 + } + }, + { + "instance_id": "fc61f806b880", + "delta_rx_bytes": 26381521, + "delta_tx_bytes": 26398219, + "baseline_rss_bytes": 183795712, + "peak_memory_bytes": { + "rss": 187359232, + "heap_used": 62541304, + "external": 18146585, + "array_buffers": 9966050 + }, + "delta_rss_bytes": 3563520, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 26214400, + "attachments.proxy.bytes_to_s3": 26214400, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 + } + } + ], + "total_delta_rx_bytes": 52758529, + "total_delta_tx_bytes": 52799168, + "rx_bytes_per_upload": 1055171, + "tx_bytes_per_upload": 1055983, + "max_delta_rss_bytes": 5373952 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 0.387, + "latency_ms": { + "p50": 47.1, + "p95": 78.9, + "p99": 92.5 + }, + "replicas": [ + { + "instance_id": "b50bb8514a7b", + "delta_rx_bytes": 26389036, + "delta_tx_bytes": 26402274, + "baseline_rss_bytes": 191053824, + "peak_memory_bytes": { + "rss": 196558848, + "heap_used": 56457808, + "external": 23809883, + "array_buffers": 20017421 + }, + "delta_rss_bytes": 5505024, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 26214400, + "attachments.proxy.bytes_to_s3": 26214400, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 + } + }, + { + "instance_id": "fc61f806b880", + "delta_rx_bytes": 26383409, + "delta_tx_bytes": 26401615, + "baseline_rss_bytes": 187490304, + "peak_memory_bytes": { + "rss": 187490304, + "heap_used": 49941720, + "external": 17342677, + "array_buffers": 13550957 + }, + "delta_rss_bytes": 0, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 26214400, + "attachments.proxy.bytes_to_s3": 26214400, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 + } + } + ], + "total_delta_rx_bytes": 52772445, + "total_delta_tx_bytes": 52803889, + "rx_bytes_per_upload": 1055449, + "tx_bytes_per_upload": 1056078, + "max_delta_rss_bytes": 5505024 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 0.361, + "latency_ms": { + "p50": 42.5, + "p95": 64.3, + "p99": 77.5 + }, + "replicas": [ + { + "instance_id": "b50bb8514a7b", + "delta_rx_bytes": 26387499, + "delta_tx_bytes": 26400516, + "baseline_rss_bytes": 195969024, + "peak_memory_bytes": { + "rss": 197935104, + "heap_used": 51834416, + "external": 25755964, + "array_buffers": 16217341 + }, + "delta_rss_bytes": 1966080, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 26214400, + "attachments.proxy.bytes_to_s3": 26214400, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 + } + }, + { + "instance_id": "fc61f806b880", + "delta_rx_bytes": 26383525, + "delta_tx_bytes": 26400510, + "baseline_rss_bytes": 185294848, + "peak_memory_bytes": { + "rss": 187260928, + "heap_used": 49345096, + "external": 15398018, + "array_buffers": 11607674 + }, + "delta_rss_bytes": 1966080, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 26214400, + "attachments.proxy.bytes_to_s3": 26214400, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 + } + } + ], + "total_delta_rx_bytes": 52771024, + "total_delta_tx_bytes": 52801026, + "rx_bytes_per_upload": 1055420, + "tx_bytes_per_upload": 1056021, + "max_delta_rss_bytes": 1966080 + } + ] +} diff --git a/evidence/lab4/bench/proxy-131072-c10.json b/evidence/lab4/bench/proxy-131072-c10.json new file mode 100644 index 00000000..3c4f9adf --- /dev/null +++ b/evidence/lab4/bench/proxy-131072-c10.json @@ -0,0 +1,195 @@ +{ + "date": "2026-10-22T19:43:22+00:00", + "git": "39a6df8", + "params": { + "mode": "proxy", + "size_bytes": 131072, + "concurrency": 10, + "uploads_per_worker": 5, + "repeat": 3 + }, + "host": { + "nproc": 8, + "mem_total_bytes": 16538955776 + }, + "api_container_limits_nanocpus_memory": [ + "1500000000 805306368", + "1500000000 805306368" + ], + "repeats": [ + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 0.203, + "latency_ms": { + "p50": 32.4, + "p95": 56.7, + "p99": 62.2 + }, + "replicas": [ + { + "instance_id": "b50bb8514a7b", + "delta_rx_bytes": 3381217, + "delta_tx_bytes": 3397557, + "baseline_rss_bytes": 171487232, + "peak_memory_bytes": { + "rss": 177647616, + "heap_used": 58529080, + "external": 7415675, + "array_buffers": 3621869 + }, + "delta_rss_bytes": 6160384, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 3276800, + "attachments.proxy.bytes_to_s3": 3276800, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 + } + }, + { + "instance_id": "fc61f806b880", + "delta_rx_bytes": 3382121, + "delta_tx_bytes": 3397761, + "baseline_rss_bytes": 169697280, + "peak_memory_bytes": { + "rss": 176513024, + "heap_used": 56215752, + "external": 6720398, + "array_buffers": 2926784 + }, + "delta_rss_bytes": 6815744, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 3276800, + "attachments.proxy.bytes_to_s3": 3276800, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 + } + } + ], + "total_delta_rx_bytes": 6763338, + "total_delta_tx_bytes": 6795318, + "rx_bytes_per_upload": 135267, + "tx_bytes_per_upload": 135906, + "max_delta_rss_bytes": 6815744 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 0.147, + "latency_ms": { + "p50": 24.3, + "p95": 37.7, + "p99": 48.6 + }, + "replicas": [ + { + "instance_id": "b50bb8514a7b", + "delta_rx_bytes": 3376685, + "delta_tx_bytes": 3395659, + "baseline_rss_bytes": 177647616, + "peak_memory_bytes": { + "rss": 181579776, + "heap_used": 58637216, + "external": 10920677, + "array_buffers": 7128215 + }, + "delta_rss_bytes": 3932160, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 3276800, + "attachments.proxy.bytes_to_s3": 3276800, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 + } + }, + { + "instance_id": "fc61f806b880", + "delta_rx_bytes": 3378833, + "delta_tx_bytes": 3397177, + "baseline_rss_bytes": 176250880, + "peak_memory_bytes": { + "rss": 179134464, + "heap_used": 60877184, + "external": 11462611, + "array_buffers": 7669957 + }, + "delta_rss_bytes": 2883584, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 3276800, + "attachments.proxy.bytes_to_s3": 3276800, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 + } + } + ], + "total_delta_rx_bytes": 6755518, + "total_delta_tx_bytes": 6792836, + "rx_bytes_per_upload": 135110, + "tx_bytes_per_upload": 135857, + "max_delta_rss_bytes": 3932160 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 0.161, + "latency_ms": { + "p50": 26.4, + "p95": 52.8, + "p99": 56.1 + }, + "replicas": [ + { + "instance_id": "b50bb8514a7b", + "delta_rx_bytes": 3377664, + "delta_tx_bytes": 3397060, + "baseline_rss_bytes": 181579776, + "peak_memory_bytes": { + "rss": 182104064, + "heap_used": 56837496, + "external": 12815773, + "array_buffers": 9023311 + }, + "delta_rss_bytes": 524288, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 3276800, + "attachments.proxy.bytes_to_s3": 3276800, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 + } + }, + { + "instance_id": "fc61f806b880", + "delta_rx_bytes": 3375364, + "delta_tx_bytes": 3395107, + "baseline_rss_bytes": 179134464, + "peak_memory_bytes": { + "rss": 182018048, + "heap_used": 61048680, + "external": 12510518, + "array_buffers": 8718024 + }, + "delta_rss_bytes": 2883584, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 3276800, + "attachments.proxy.bytes_to_s3": 3276800, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 + } + } + ], + "total_delta_rx_bytes": 6753028, + "total_delta_tx_bytes": 6792167, + "rx_bytes_per_upload": 135061, + "tx_bytes_per_upload": 135843, + "max_delta_rss_bytes": 2883584 + } + ] +} diff --git a/evidence/lab4/bench/proxy-9961472-c10.json b/evidence/lab4/bench/proxy-9961472-c10.json new file mode 100644 index 00000000..be1fe8fc --- /dev/null +++ b/evidence/lab4/bench/proxy-9961472-c10.json @@ -0,0 +1,195 @@ +{ + "date": "2026-10-22T19:43:49+00:00", + "git": "39a6df8", + "params": { + "mode": "proxy", + "size_bytes": 9961472, + "concurrency": 10, + "uploads_per_worker": 5, + "repeat": 3 + }, + "host": { + "nproc": 8, + "mem_total_bytes": 16538955776 + }, + "api_container_limits_nanocpus_memory": [ + "1500000000 805306368", + "1500000000 805306368" + ], + "repeats": [ + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 2.888, + "latency_ms": { + "p50": 212.3, + "p95": 379.1, + "p99": 447.0 + }, + "replicas": [ + { + "instance_id": "b50bb8514a7b", + "delta_rx_bytes": 249726853, + "delta_tx_bytes": 249832292, + "baseline_rss_bytes": 201834496, + "peak_memory_bytes": { + "rss": 207208448, + "heap_used": 48318768, + "external": 33637892, + "array_buffers": 24213167 + }, + "delta_rss_bytes": 5373952, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 249036800, + "attachments.proxy.bytes_to_s3": 249036800, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 + } + }, + { + "instance_id": "fc61f806b880", + "delta_rx_bytes": 249652918, + "delta_tx_bytes": 249806626, + "baseline_rss_bytes": 194772992, + "peak_memory_bytes": { + "rss": 208158720, + "heap_used": 48256584, + "external": 27701797, + "array_buffers": 23911453 + }, + "delta_rss_bytes": 13385728, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 249036800, + "attachments.proxy.bytes_to_s3": 249036800, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 + } + } + ], + "total_delta_rx_bytes": 499379771, + "total_delta_tx_bytes": 499638918, + "rx_bytes_per_upload": 9987595, + "tx_bytes_per_upload": 9992778, + "max_delta_rss_bytes": 13385728 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 2.74, + "latency_ms": { + "p50": 188.3, + "p95": 357.0, + "p99": 439.5 + }, + "replicas": [ + { + "instance_id": "b50bb8514a7b", + "delta_rx_bytes": 249720677, + "delta_tx_bytes": 249833753, + "baseline_rss_bytes": 198889472, + "peak_memory_bytes": { + "rss": 207929344, + "heap_used": 48141072, + "external": 34434837, + "array_buffers": 24758541 + }, + "delta_rss_bytes": 9039872, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 249036800, + "attachments.proxy.bytes_to_s3": 249036800, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 + } + }, + { + "instance_id": "fc61f806b880", + "delta_rx_bytes": 249698838, + "delta_tx_bytes": 249844044, + "baseline_rss_bytes": 195190784, + "peak_memory_bytes": { + "rss": 202661888, + "heap_used": 48064416, + "external": 26063110, + "array_buffers": 21189095 + }, + "delta_rss_bytes": 7471104, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 249036800, + "attachments.proxy.bytes_to_s3": 249036800, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 + } + } + ], + "total_delta_rx_bytes": 499419515, + "total_delta_tx_bytes": 499677797, + "rx_bytes_per_upload": 9988390, + "tx_bytes_per_upload": 9993556, + "max_delta_rss_bytes": 9039872 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 2.786, + "latency_ms": { + "p50": 226.6, + "p95": 373.9, + "p99": 483.8 + }, + "replicas": [ + { + "instance_id": "b50bb8514a7b", + "delta_rx_bytes": 249712459, + "delta_tx_bytes": 249847251, + "baseline_rss_bytes": 199180288, + "peak_memory_bytes": { + "rss": 207888384, + "heap_used": 48883976, + "external": 33646702, + "array_buffers": 29856358 + }, + "delta_rss_bytes": 8708096, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 249036800, + "attachments.proxy.bytes_to_s3": 249036800, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 + } + }, + { + "instance_id": "fc61f806b880", + "delta_rx_bytes": 249713568, + "delta_tx_bytes": 249832760, + "baseline_rss_bytes": 193859584, + "peak_memory_bytes": { + "rss": 205029376, + "heap_used": 49053528, + "external": 28839619, + "array_buffers": 25049275 + }, + "delta_rss_bytes": 11169792, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 249036800, + "attachments.proxy.bytes_to_s3": 249036800, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 + } + } + ], + "total_delta_rx_bytes": 499426027, + "total_delta_tx_bytes": 499680011, + "rx_bytes_per_upload": 9988521, + "tx_bytes_per_upload": 9993600, + "max_delta_rss_bytes": 11169792 + } + ] +} diff --git a/evidence/lab4/bench/proxy-9961472-c20.json b/evidence/lab4/bench/proxy-9961472-c20.json new file mode 100644 index 00000000..3d2ba65c --- /dev/null +++ b/evidence/lab4/bench/proxy-9961472-c20.json @@ -0,0 +1,196 @@ +{ + "date": "2026-10-22T19:44:24+00:00", + "git": "39a6df8", + "params": { + "mode": "proxy", + "size_bytes": 9961472, + "concurrency": 20, + "uploads_per_worker": 5, + "repeat": 3 + }, + "host": { + "nproc": 8, + "mem_total_bytes": 16538955776 + }, + "api_container_limits_nanocpus_memory": [ + "1500000000 805306368", + "1500000000 805306368" + ], + "repeats": [ + { + "uploads": 100, + "succeeded": 100, + "failed": 0, + "duration_s": 6.29, + "latency_ms": { + "p50": 424.1, + "p95": 796.0, + "p99": 937.9 + }, + "replicas": [ + { + "instance_id": "b50bb8514a7b", + "delta_rx_bytes": 499638310, + "delta_tx_bytes": 499870304, + "baseline_rss_bytes": 192036864, + "peak_memory_bytes": { + "rss": 210829312, + "heap_used": 49626176, + "external": 34069726, + "array_buffers": 30279382 + }, + "delta_rss_bytes": 18792448, + "counters": { + "attachments.insert_pending": 50, + "attachments.proxy.bytes_in": 498073600, + "attachments.proxy.bytes_to_s3": 498073600, + "attachments.mark_ready": 50, + "attachments.upload.created": 50 + } + }, + { + "instance_id": "fc61f806b880", + "delta_rx_bytes": 499750187, + "delta_tx_bytes": 500007552, + "baseline_rss_bytes": 194543616, + "peak_memory_bytes": { + "rss": 210604032, + "heap_used": 48759736, + "external": 32187556, + "array_buffers": 28397212 + }, + "delta_rss_bytes": 16060416, + "counters": { + "attachments.insert_pending": 50, + "attachments.proxy.bytes_in": 498073600, + "attachments.proxy.bytes_to_s3": 498073600, + "attachments.mark_ready": 50, + "attachments.upload.created": 50, + "attachments.claim_expired": 1 + } + } + ], + "total_delta_rx_bytes": 999388497, + "total_delta_tx_bytes": 999877856, + "rx_bytes_per_upload": 9993885, + "tx_bytes_per_upload": 9998779, + "max_delta_rss_bytes": 18792448 + }, + { + "uploads": 100, + "succeeded": 100, + "failed": 0, + "duration_s": 5.824, + "latency_ms": { + "p50": 403.2, + "p95": 802.4, + "p99": 987.2 + }, + "replicas": [ + { + "instance_id": "b50bb8514a7b", + "delta_rx_bytes": 499452630, + "delta_tx_bytes": 499737912, + "baseline_rss_bytes": 197160960, + "peak_memory_bytes": { + "rss": 223768576, + "heap_used": 50330816, + "external": 46988209, + "array_buffers": 43197865 + }, + "delta_rss_bytes": 26607616, + "counters": { + "attachments.insert_pending": 50, + "attachments.proxy.bytes_in": 498073600, + "attachments.proxy.bytes_to_s3": 498073600, + "attachments.mark_ready": 50, + "attachments.upload.created": 50 + } + }, + { + "instance_id": "fc61f806b880", + "delta_rx_bytes": 499486574, + "delta_tx_bytes": 499756038, + "baseline_rss_bytes": 197701632, + "peak_memory_bytes": { + "rss": 215396352, + "heap_used": 49478224, + "external": 43102012, + "array_buffers": 30263688 + }, + "delta_rss_bytes": 17694720, + "counters": { + "attachments.insert_pending": 50, + "attachments.proxy.bytes_in": 498073600, + "attachments.proxy.bytes_to_s3": 498073600, + "attachments.mark_ready": 50, + "attachments.upload.created": 50 + } + } + ], + "total_delta_rx_bytes": 998939204, + "total_delta_tx_bytes": 999493950, + "rx_bytes_per_upload": 9989392, + "tx_bytes_per_upload": 9994940, + "max_delta_rss_bytes": 26607616 + }, + { + "uploads": 100, + "succeeded": 100, + "failed": 0, + "duration_s": 5.757, + "latency_ms": { + "p50": 413.8, + "p95": 866.6, + "p99": 1090.4 + }, + "replicas": [ + { + "instance_id": "b50bb8514a7b", + "delta_rx_bytes": 499421823, + "delta_tx_bytes": 499732729, + "baseline_rss_bytes": 195944448, + "peak_memory_bytes": { + "rss": 214212608, + "heap_used": 50078520, + "external": 38151413, + "array_buffers": 34361069 + }, + "delta_rss_bytes": 18268160, + "counters": { + "attachments.insert_pending": 50, + "attachments.proxy.bytes_in": 498073600, + "attachments.proxy.bytes_to_s3": 498073600, + "attachments.mark_ready": 50, + "attachments.upload.created": 50 + } + }, + { + "instance_id": "fc61f806b880", + "delta_rx_bytes": 499373397, + "delta_tx_bytes": 499664859, + "baseline_rss_bytes": 196259840, + "peak_memory_bytes": { + "rss": 207290368, + "heap_used": 49133976, + "external": 31644969, + "array_buffers": 27854625 + }, + "delta_rss_bytes": 11030528, + "counters": { + "attachments.insert_pending": 50, + "attachments.proxy.bytes_in": 498073600, + "attachments.proxy.bytes_to_s3": 498073600, + "attachments.mark_ready": 50, + "attachments.upload.created": 50 + } + } + ], + "total_delta_rx_bytes": 998795220, + "total_delta_tx_bytes": 999397588, + "rx_bytes_per_upload": 9987952, + "tx_bytes_per_upload": 9993976, + "max_delta_rss_bytes": 18268160 + } + ] +} diff --git a/evidence/lab4/consistency.txt b/evidence/lab4/consistency.txt new file mode 100644 index 00000000..0b8c1b25 --- /dev/null +++ b/evidence/lab4/consistency.txt @@ -0,0 +1,8 @@ +scripts/lab4/consistency_check.sh +bucket: messenger-attachments +objects: 1308 +rows by status: + 11 pending + 1308 ready +orphans: 0 +missing: 0 diff --git a/evidence/lab4/direct-ttl-short.txt b/evidence/lab4/direct-ttl-short.txt new file mode 100644 index 00000000..09d52f88 --- /dev/null +++ b/evidence/lab4/direct-ttl-short.txt @@ -0,0 +1,8 @@ +> app@0.0.1 test:e2e +> vitest run --config ./vitest.config.e2e.ts direct-upload +The plugin "vite-tsconfig-paths" is detected. Vite now supports tsconfig paths resolution natively via the resolve.tsconfigPaths option. You can remove the plugin and set resolve.tsconfigPaths: true in your Vite config instead. + RUN v4.1.11 /home/tomato/Projects/VP/mtusi2026lab4/app + Test Files 1 passed (1) + Tests 7 passed (7) + Start at 22:45:08 + Duration 8.14s (transform 44ms, setup 0ms, import 75ms, tests 7.94s, environment 0ms) diff --git a/evidence/lab4/failover-attachment.txt b/evidence/lab4/failover-attachment.txt new file mode 100644 index 00000000..8a642656 --- /dev/null +++ b/evidence/lab4/failover-attachment.txt @@ -0,0 +1,11 @@ +# attachment download survives the stop of either replica (sha256 of sample.png: 99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75) +stopped mtusi-lab4-api-1 + GET content -> HTTP/1.1 200 OK x-instance-id: fc61f806b880 sha256=99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75 + GET content -> HTTP/1.1 200 OK x-instance-id: fc61f806b880 sha256=99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75 + GET content -> HTTP/1.1 200 OK x-instance-id: fc61f806b880 sha256=99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75 +stopped mtusi-lab4-api-2 + GET content -> HTTP/1.1 200 OK x-instance-id: b50bb8514a7b sha256=99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75 + GET content -> HTTP/1.1 200 OK x-instance-id: b50bb8514a7b sha256=99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75 + GET content -> HTTP/1.1 200 OK x-instance-id: b50bb8514a7b sha256=99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75 +mtusi-lab4-api-1 Up 14 seconds (healthy) +mtusi-lab4-api-2 Up 5 seconds (healthy) diff --git a/evidence/lab4/failover.txt b/evidence/lab4/failover.txt new file mode 100644 index 00000000..c2f9f401 --- /dev/null +++ b/evidence/lab4/failover.txt @@ -0,0 +1,21 @@ +# failover round 1 +python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "http://localhost:8080" +Executing explicit failover hook; hook output suppressed to avoid leaking secrets. +{"observed_instances_before": 2, "successful_writes": 140, "failed_attempts": 0, "first_recovery_seconds": 3.331} +PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence. +api mtusi-lab4-api-1 Up 26 seconds (healthy) + Container mtusi-lab4-api-1 Running +# failover round 2 +Executing explicit failover hook; hook output suppressed to avoid leaking secrets. +{"observed_instances_before": 2, "successful_writes": 134, "failed_attempts": 0, "first_recovery_seconds": 3.359} +PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence. +mtusi-lab4-api-1 Up 50 seconds (healthy) +mtusi-lab4-api-2 Exited (0) 12 seconds ago +# failover round 3 +Executing explicit failover hook; hook output suppressed to avoid leaking secrets. +{"observed_instances_before": 2, "successful_writes": 134, "failed_attempts": 0, "first_recovery_seconds": 3.328} +PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence. +mtusi-lab4-api-1 Up About a minute (healthy) +mtusi-lab4-api-2 Exited (0) 12 seconds ago +mtusi-lab4-api-1 Up About a minute (healthy) +mtusi-lab4-api-2 Up 5 seconds (healthy) diff --git a/evidence/lab4/make-check.txt b/evidence/lab4/make-check.txt new file mode 100644 index 00000000..9a553306 --- /dev/null +++ b/evidence/lab4/make-check.txt @@ -0,0 +1,2 @@ +python3 scripts/check_contract.py +PASS: offline skeleton structure, local refs and Python syntax; application NOT tested. diff --git a/evidence/lab4/make-test-dependencies.txt b/evidence/lab4/make-test-dependencies.txt new file mode 100644 index 00000000..2e2dd11e --- /dev/null +++ b/evidence/lab4/make-test-dependencies.txt @@ -0,0 +1,9 @@ +cd app && E2E_COMPOSE_DIR="/home/tomato/Projects/VP/mtusi2026lab4" E2E_COMPOSE_ENV_FILE=".env" npm run test:dependencies +> app@0.0.1 test:dependencies +> E2E_DEPENDENCY_FAULTS=1 vitest run --config ./vitest.config.e2e.ts dependency-failures +The plugin "vite-tsconfig-paths" is detected. Vite now supports tsconfig paths resolution natively via the resolve.tsconfigPaths option. You can remove the plugin and set resolve.tsconfigPaths: true in your Vite config instead. + RUN v4.1.11 /home/tomato/Projects/VP/mtusi2026lab4/app + Test Files 1 passed (1) + Tests 6 passed (6) + Start at 22:45:26 + Duration 89.83s (transform 52ms, setup 0ms, import 69ms, tests 89.66s, environment 0ms) diff --git a/evidence/lab4/make-test-e2e.txt b/evidence/lab4/make-test-e2e.txt new file mode 100644 index 00000000..ecaf8051 --- /dev/null +++ b/evidence/lab4/make-test-e2e.txt @@ -0,0 +1,8 @@ +> app@0.0.1 test:e2e +> vitest run --config ./vitest.config.e2e.ts +The plugin "vite-tsconfig-paths" is detected. Vite now supports tsconfig paths resolution natively via the resolve.tsconfigPaths option. You can remove the plugin and set resolve.tsconfigPaths: true in your Vite config instead. + RUN v4.1.11 /home/tomato/Projects/VP/mtusi2026lab4/app + Test Files 3 passed | 1 skipped (4) + Tests 33 passed | 8 skipped (41) + Start at 22:44:49 + Duration 3.73s (transform 239ms, setup 0ms, import 536ms, tests 7.77s, environment 0ms) diff --git a/evidence/lab4/make-test.txt b/evidence/lab4/make-test.txt new file mode 100644 index 00000000..1e7b9ff4 --- /dev/null +++ b/evidence/lab4/make-test.txt @@ -0,0 +1,2 @@ +python3 tests/smoke.py --base-url "http://localhost:8080" +PASS: lab4 public API scenario; infrastructure and grading evidence remain separate. diff --git a/evidence/lab4/persistence.txt b/evidence/lab4/persistence.txt new file mode 100644 index 00000000..1d5f8889 --- /dev/null +++ b/evidence/lab4/persistence.txt @@ -0,0 +1,29 @@ +# before +api Up 19 seconds (healthy) +api Up 19 seconds (healthy) +haproxy Up 11 minutes +postgres Up 2 minutes (healthy) +redis Up 3 minutes (healthy) +s3 Up 3 minutes (healthy) +/mtusi-lab4-postgres-1 2026-10-22T19:38:19.352217508Z +/mtusi-lab4-redis-1 2026-10-22T19:37:15.343086395Z +/mtusi-lab4-s3-1 2026-10-22T19:37:46.289807129Z +/mtusi-lab4-api-1 2026-10-22T19:40:39.879853813Z +/mtusi-lab4-api-2 2026-10-22T19:40:39.774525559Z +/mtusi-lab4-haproxy-1 2026-10-22T19:29:53.978761189Z +python3 tests/resilience.py --mode persistence --action-script "scripts/restart.sh" --base-url "http://localhost:8080" +Executing explicit persistence hook; hook output suppressed to avoid leaking secrets. +PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence. +# after +api Up 6 seconds (healthy) +api Up 6 seconds (healthy) +haproxy Up 9 seconds +postgres Up 9 seconds (healthy) +redis Up 9 seconds (healthy) +s3 Up 9 seconds (healthy) +/mtusi-lab4-postgres-1 2026-10-22T19:41:00.616425802Z +/mtusi-lab4-redis-1 2026-10-22T19:41:00.545701172Z +/mtusi-lab4-s3-1 2026-10-22T19:41:00.507714044Z +/mtusi-lab4-api-1 2026-10-22T19:41:03.631509569Z +/mtusi-lab4-api-2 2026-10-22T19:41:03.665389961Z +/mtusi-lab4-haproxy-1 2026-10-22T19:41:00.434084255Z diff --git a/evidence/lab4/readonly-api.txt b/evidence/lab4/readonly-api.txt new file mode 100644 index 00000000..982ea3b8 --- /dev/null +++ b/evidence/lab4/readonly-api.txt @@ -0,0 +1 @@ +touch: cannot touch '/usr/src/app/x': Read-only file system diff --git a/evidence/lab4/s3-security.txt b/evidence/lab4/s3-security.txt new file mode 100644 index 00000000..be087818 --- /dev/null +++ b/evidence/lab4/s3-security.txt @@ -0,0 +1,10 @@ +scripts/lab4/check_s3_security.sh +PASS anonymous GET of a ready object -> 403 +PASS anonymous list of the bucket -> 403 +PASS anonymous PUT -> 403 +PASS API credentials cannot create buckets +PASS API credentials cannot use admin API +PASS API credentials can read attachments/* +PASS API credentials cannot write outside attachments/ +PASS console port 9001 is not published +PASS console not reachable on localhost:9001 diff --git a/evidence/lab4/summary.md b/evidence/lab4/summary.md new file mode 100644 index 00000000..eb63419d --- /dev/null +++ b/evidence/lab4/summary.md @@ -0,0 +1,9 @@ +| mode | size, MiB | C | ok | API rx/upload, MiB | API tx/upload, MiB | max Δrss, MiB | p50, ms | p95, ms | +|---|---|---|---|---|---|---|---|---| +| direct | 0.12 | 10 | 150/150 | 0.13 | 0.01 | 0.62 | 42 | 62 | +| proxy | 0.12 | 10 | 150/150 | 0.13 | 0.13 | 3.75 | 26 | 53 | +| direct | 1.00 | 10 | 150/150 | 1.01 | 0.01 | 3.88 | 69 | 100 | +| proxy | 1.00 | 10 | 150/150 | 1.01 | 1.01 | 5.12 | 44 | 79 | +| direct | 9.50 | 10 | 150/150 | 0.14 | 0.01 | 0.25 | 377 | 493 | +| proxy | 9.50 | 10 | 150/150 | 9.53 | 9.53 | 10.65 | 212 | 374 | +| proxy | 9.50 | 20 | 300/300 | 9.53 | 9.53 | 17.92 | 414 | 802 | diff --git a/evidence/lab4/unit-tests.txt b/evidence/lab4/unit-tests.txt new file mode 100644 index 00000000..5a32feef --- /dev/null +++ b/evidence/lab4/unit-tests.txt @@ -0,0 +1,8 @@ +The plugin "vite-tsconfig-paths" is detected. Vite now supports tsconfig paths resolution natively via the resolve.tsconfigPaths option. You can remove the plugin and set resolve.tsconfigPaths: true in your Vite config instead. + RUN v4.1.11 /home/tomato/Projects/VP/mtusi2026lab4/app +[Nest] 3057161 - 10/22/2026, 10:44:47 PM WARN [MessagesCacheService] Cache read failed, serving PostgreSQL: redis down +[Nest] 3057161 - 10/22/2026, 10:44:47 PM WARN [MessagesCacheService] Cache fill failed: redis down + Test Files 10 passed (10) + Tests 36 passed (36) + Start at 22:44:46 + Duration 1.93s (transform 718ms, setup 0ms, import 5.44s, tests 373ms, environment 1ms) -- 2.54.0 From 830e5811fc9da8f867ff698562c1e74cfdc8a8b5 Mon Sep 17 00:00:00 2001 From: Ilya Date: Thu, 22 Oct 2026 23:04:05 +0300 Subject: [PATCH 08/15] =?UTF-8?q?lab4:=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=BE=20=D1=80?= =?UTF-8?q?=D0=B5=D0=B2=D1=8C=D1=8E=20(=D0=BF=D0=B0=D1=80=D1=81=D0=B5?= =?UTF-8?q?=D1=80=D1=8B=20image/text=20=D1=82=D0=BE=D0=BB=D1=8C=D0=BA?= =?UTF-8?q?=D0=BE=20=D0=BD=D0=B0=20upload,=20rejected-=D1=81=D1=82=D0=B0?= =?UTF-8?q?=D1=82=D1=83=D1=81=20=D0=BF=D1=80=D1=8F=D0=BC=D0=BE=D0=B9=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B8,=20=D0=B4?= =?UTF-8?q?=D0=B8=D0=B0=D0=BF=D0=B0=D0=B7=D0=BE=D0=BD=2064=20KiB,=20=D0=BE?= =?UTF-8?q?=D1=82=D1=87=D1=91=D1=82)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- REPORT.md | 89 ++++--- app/src/attachments/attachment.ts | 2 +- app/src/attachments/attachments.repository.ts | 14 +- app/src/attachments/direct-uploads.service.ts | 97 ++++--- .../migrations/006_attachment_rejected.sql | 8 + app/src/main.ts | 51 +++- app/test/attachments.e2e-spec.ts | 15 ++ app/test/direct-upload.e2e-spec.ts | 13 + evidence/lab4/bench/direct-1048576-c10.json | 248 ++++++++--------- evidence/lab4/bench/direct-131072-c10.json | 248 ++++++++--------- evidence/lab4/bench/direct-9961472-c10.json | 249 +++++++++--------- evidence/lab4/bench/proxy-1048576-c10.json | 166 ++++++------ evidence/lab4/bench/proxy-131072-c10.json | 166 ++++++------ evidence/lab4/bench/proxy-9961472-c10.json | 168 ++++++------ evidence/lab4/bench/proxy-9961472-c20.json | 169 ++++++------ evidence/lab4/consistency.txt | 7 +- evidence/lab4/direct-ttl-short.txt | 4 +- evidence/lab4/make-test-dependencies.txt | 4 +- evidence/lab4/make-test-e2e.txt | 6 +- evidence/lab4/summary.md | 14 +- 20 files changed, 933 insertions(+), 805 deletions(-) create mode 100644 app/src/database/migrations/006_attachment_rejected.sql diff --git a/REPORT.md b/REPORT.md index e79fd454..5edd9807 100644 --- a/REPORT.md +++ b/REPORT.md @@ -91,9 +91,14 @@ ATTACHMENT_SWEEP_INTERVAL_MS=1000 docker compose --env-file .env up -d --no-deps `content-length` и `x-amz-checksum-sha256`: S3 сам отвергает тело другого размера (403 `SignatureDoesNotMatch`) или с другим SHA-256 (400 `XAmzContentChecksumMismatch`), объект при этом не создаётся (`evidence/lab4/presign-spike.txt`). `POST /api/v1/attachments/{id}/complete` - (только владелец): `HEAD` (размер + подписанный checksum), чтение заголовка изображения (диапазон - до 1 MiB, поток обрывается после получения заголовка), сверка типа и пикселей, `markReady`. - Любое несоответствие → компенсация и 409/413/415; повторный `complete` готового — 200. Лимит + (только владелец): `HEAD` (размер + подписанный checksum), чтение заголовка изображения (первый + диапазон 64 KiB, при необходимости расширяется до 1 MiB; объект, целиком попавший в диапазон, + проверяется до конца, включая CRC/EOI), сверка типа и пикселей, `markReady`. Несоответствие + (размер/checksum/тип/пиксели) → 409/413/415, объект удаляется, а строка получает статус + `rejected` и сохраняет `expires_at`: подписанный URL ещё может быть использован, и повторный PUT + оставил бы объект без строки; уборщик удаляет `rejected` после `expires_at` + grace, пока же строка + занимает слот лимита, а повторный `complete` даёт 404. «Upload has not been received» (409) + строку не трогает — клиент может доотправить. Повторный `complete` готового — 200. Лимит незавершённых заявок на пользователя: `DIRECT_UPLOAD_MAX_PENDING_PER_USER` (429 с `Retry-After`). Перезапись по тому же URL до истечения TTL возможна только теми же байтами (checksum подписан). Расширение контракта: `contracts/extensions.openapi.json`; обязательный proxy endpoint не менялся. @@ -160,14 +165,14 @@ ATTACHMENT_SWEEP_INTERVAL_MS=1000 docker compose --env-file .env up -d --no-deps | --- | --- | --- | --- | | Публичный smoke | `make test` | `PASS: lab4 public API scenario` (upload 201 ready, сообщение с `''` и `attachment_ids`, download bob = байты, eve 404) | `make-test.txt` | | Контракт offline | `make check` | PASS, `contracts/extensions.openapi.json` — валидный JSON | `make-check.txt` | -| 3: S3 в общем стенде, приватный bucket, метаданные в PG, байты в bucket | `make stand-up`; `docker compose ps`; `make consistency` | `s3` healthy, `s3-init` завершён с 0; bucket приватный (`mc anonymous set none`); число объектов в bucket = числу `ready`-строк (1308 после серии `make bench` и e2e), orphans/missing = 0 | `bootstrap-rerun.txt`, `consistency.txt` | +| 3: S3 в общем стенде, приватный bucket, метаданные в PG, байты в bucket | `make stand-up`; `docker compose ps`; `make consistency` | `s3` healthy, `s3-init` завершён с 0; bucket приватный (`mc anonymous set none`); число объектов в bucket = числу `ready`-строк (2577 после серий `make bench` и e2e; ещё 33 `pending` без объектов и 6 `rejected` ждут истечения + grace), orphans/missing = 0 | `bootstrap-rerun.txt`, `consistency.txt` | | 3: 201 ready, побайтный download, `attachment_ids` | `make test-e2e` (`attachments.e2e-spec.ts`) | sha256 в ответе = sha256 файла; content = байты, `nosniff`, `Content-Length` | `make-test-e2e.txt` | -| 3: PNG/JPEG ≤10 MiB и ≤40 млн px; MIME по содержимому; опасные filename; лимиты до чтения | e2e: 10485760 → 201, 10485761 → 413, pixel bomb 8000×5001 → 413 сразу после IHDR, PNG как `image/jpeg` → 415, `a/b.png`, `\u202E`, NUL, 256 символов → 400, 255×😀 → 201 | все кейсы зелёные, пользовательских 500 нет | `make-test-e2e.txt`, `unit-tests.txt` (`image-inspector.spec.ts`) | +| 3: PNG/JPEG ≤10 MiB и ≤40 млн px; MIME по содержимому; опасные filename; лимиты до чтения | e2e: 10485760 → 201, 10485761 → 413, pixel bomb 8000×5001 → 413 сразу после IHDR, PNG как `image/jpeg` → 415, `a/b.png`, `\u202E`, NUL, 256 символов → 400, 255×😀 → 201 | кейсы перечислены в `app/test/attachments.e2e-spec.ts` (в evidence — итог: 34 passed, 8 skipped opt-in); raw image/text тело на JSON-маршрутах → 415/400, не 500 | `make-test-e2e.txt`, `unit-tests.txt` (`image-inspector.spec.ts`) | | 3: другая реплика отдаёт файл после остановки загрузившей; restart сохраняет данные | `scripts/stop-one.sh` (обе реплики по очереди), `make test-failover`; `make test-persistence ACTION_SCRIPT=scripts/restart.sh` | failover: 0 неуспешных попыток, восстановление ≈3.3 с; download с тем же sha256 после остановки api-1 и api-2; persistence: `StartedAt` у postgres, redis, s3, api×2, haproxy изменился, данные и сессия сохранены | `failover.txt`, `failover-attachment.txt`, `persistence.txt` | | 3: на API нет локального файла оригинала | `touch` в корне контейнера | `Read-only file system` | `readonly-api.txt` | | 4: тесты: большой файл, повреждённое изображение, подмена MIME, чужое `attachment_id`, вложение другого чата, нет 500 | `make test-e2e` | 413; усечённый PNG, флип байта (CRC), сигнатура+мусор, пустое тело → 415; подмена MIME → 415; чужое/неизвестное/незавершённое → 404; вложение чата eve в чате alice → 404 | `make-test-e2e.txt` | | 4: прерывание загрузки и отказ между S3/БД не оставляют вечных объектов | e2e «client drops the connection»; `make test-dependencies` | обрыв клиента → строк 0 за ≤10 с; S3 down → одна `pending`, после старта и sweep — 0; PG down между PUT и ready → 503, объекта в S3 нет, `pending` убрана sweep; затем `orphans: 0, missing: 0` | `make-test-e2e.txt`, `make-test-dependencies.txt`, `consistency.txt` | -| 4: лимиты, таймауты, потоковая обработка; эксперимент ≥10 загрузок с пиком памяти | `make bench` (proxy, C=10 и C=20, 9.5 MiB) | max Δrss реплики 10.7 MiB при C=10 и 17.9 MiB при C=20 против 95/190 MiB тел в полёте — см. «Эксперименты» | `summary.md`, `bench/*.json` | +| 4: лимиты, таймауты, потоковая обработка; эксперимент ≥10 загрузок с пиком памяти | `make bench` (proxy, C=10 и C=20, 9.5 MiB) | max Δrss реплики 15.7 MiB при C=10 и 16.5 MiB при C=20 против 95/190 MiB тел в полёте — см. «Эксперименты» | `summary.md`, `bench/*.json` | | 4: идемпотентный bootstrap; отдельные ограниченные credentials; консоль закрыта; private bucket вне API | `docker compose run s3-init` дважды; `make s3-security` | повтор → `bootstrap ok`; анонимные GET/list/PUT → 403; API-credentials не создают bucket, не вызывают admin, не пишут вне `attachments/`, читают `attachments/*`; порт 9001 не опубликован и не отвечает | `bootstrap-rerun.txt`, `s3-security.txt` | | 5 / трек 1: presigned flow (короткая подпись, уникальный ключ, принадлежность, размер/checksum на complete, незавершённые) | `direct-upload.e2e-spec.ts`; спайк подписи | init → PUT мимо API → complete → metadata/content → сообщение; чужой/посторонний complete → 404; подмена байта → S3 400, затем complete 409; JPEG под видом PNG → 415, затем 404; pixel bomb → 413; 11-я заявка → 429 + `Retry-After` | `make-test-e2e.txt`, `presign-spike.txt` | | 5 / трек 1: истёкший URL и уборка | `E2E_DIRECT_TTL_SHORT=1` на стенде с TTL 5 с | PUT после `expires_at` → 403, строка убрана уборщиком, complete → 404 | `direct-ttl-short.txt` | @@ -184,8 +189,8 @@ ATTACHMENT_SWEEP_INTERVAL_MS=1000 docker compose --env-file .env up -d --no-deps **Методика.** Хост: 8 логических CPU, 16 GiB RAM, один Docker-хост. Лимиты: API 1.5 CPU / 768 MiB на реплику (2 реплики), MinIO 1 CPU / 512 MiB, PG 1.5 CPU / 512 MiB. Версии — см. «Запуск». Нагрузка: `scripts/lab4/attachments_bench.py`, closed-loop: C потоков × 5 загрузок несжимаемых PNG -(`noise_png`, разные seed), R = 3 повтора, перед каждым повтором — прогрев (не измеряется) и -`POST /internal/metrics/reset` на каждой реплике. Трафик API — дельта `eth0` rx/tx из `/proc/net/dev` +(`noise_png`, разные seed), R = 3 повтора; один прогрев на конфигурацию (2 × число реплик загрузок, +не измеряется), перед каждым повтором — `POST /internal/metrics/reset` на каждой реплике. Трафик API — дельта `eth0` rx/tx из `/proc/net/dev` контейнера; RAM — пик `process.memoryUsage().rss` с шагом 50 мс минус RSS в момент reset (Δrss); в таблицу идёт медиана по повторам, для Δrss — максимум по репликам. Команда: `make bench` (`scripts/lab4/run_matrix.sh`); raw — `evidence/lab4/bench/*.json` (без токенов и URL). @@ -201,34 +206,36 @@ S3) до малой величины, не зависящей от размер | mode | size, MiB | C | API rx/upload, MiB | API tx/upload, MiB | max Δrss, MiB | p50, ms | p95, ms | | --- | --- | --- | --- | --- | --- | --- | --- | -| direct | 0.12 | 10 | 0.13 | 0.01 | 0.62 | 42 | 62 | -| proxy | 0.12 | 10 | 0.13 | 0.13 | 3.75 | 26 | 53 | -| direct | 1.00 | 10 | 1.01 | 0.01 | 3.88 | 69 | 100 | -| proxy | 1.00 | 10 | 1.01 | 1.01 | 5.12 | 44 | 79 | -| direct | 9.50 | 10 | 0.14 | 0.01 | 0.25 | 377 | 493 | -| proxy | 9.50 | 10 | 9.53 | 9.53 | 10.65 | 212 | 374 | -| proxy | 9.50 | 20 | 9.53 | 9.53 | 17.92 | 414 | 802 | +| direct | 0.12 | 10 | 0.07 | 0.01 | 0.40 | 45 | 65 | +| proxy | 0.12 | 10 | 0.13 | 0.13 | 3.78 | 32 | 62 | +| direct | 1.00 | 10 | 0.07 | 0.01 | 0.75 | 75 | 137 | +| proxy | 1.00 | 10 | 1.01 | 1.01 | 4.38 | 59 | 110 | +| direct | 9.50 | 10 | 0.07 | 0.01 | 0.88 | 346 | 571 | +| proxy | 9.50 | 10 | 9.52 | 9.53 | 15.70 | 239 | 394 | +| proxy | 9.50 | 20 | 9.53 | 9.53 | 16.46 | 409 | 812 | Выводы: -- **H1 подтверждена с оговоркой.** При C=10 и 9.5 MiB пик Δrss — 10.7 MiB при ≈95 MiB тел в полёте; при - C=20 — 17.9 MiB при ≈190 MiB. Память не пропорциональна размеру файла (размер ×76: 0.12 → 9.5 MiB - дал Δrss 3.75 → 10.65 MiB, ×2.8), но и не строго постоянна: растёт слабо с размером и с - concurrency (буферы сокетов, чанки в полёте, аллокатор). Δrss — шумная величина (между повторами одной - конфигурации 9.0–13.4 MiB для proxy 9.5 MiB C=10 и 2.0–5.5 MiB для proxy 1 MiB). -- **H2 подтверждена частично.** Для proxy tx ≈ rx ≈ size (≈2 × size суммарно: вход от клиента и выход - в S3). Для direct при size > 1 MiB API видит ≈0.14 MiB rx (заголовок изображения) и ≈0.01 MiB tx - независимо от размера, Δrss ≈ 0. **Для size ≤ 1 MiB direct не снижает входящий трафик API:** - `complete` читает диапазон до `IMAGE_HEADER_MAX_BYTES` = 1 MiB, и если он покрывает весь объект, - файл дочитывается до конца для `finish()` (структурная проверка) — rx = size (0.13 и 1.01 MiB); - выигрыш только по tx (≈0.01 против size). Латентность direct выше при малых/средних файлах - (p50 42 против 26 мс, 69 против 44 мс — три запроса вместо одного) и выше на 9.5 MiB - (377 против 212 мс): клиент заливает через loopback в MinIO с лимитом 1 CPU, а не через API; прирост - не объясняется в эксперименте и остаётся гипотезой (вероятно, проверка подписи и checksum в MinIO). +- **H1 подтверждена с оговоркой.** При C=10 и 9.5 MiB пик Δrss — 15.7 MiB (по повторам 14.5–18.1) при + ≈95 MiB тел в полёте; при C=20 — 16.5 MiB (12.1–21.0) при ≈190 MiB: удвоение concurrency в пределах + шума не изменило пик. Память не пропорциональна размеру файла (размер ×76: 0.12 → 9.5 MiB дал Δrss + 3.78 → 15.7 MiB, ×4.2), но и не постоянна: растёт с размером (буферы сокетов, чанки в полёте, + аллокатор), оставаясь на порядок меньше тел в полёте. Δrss — шумная величина (между повторами одной + конфигурации 1.9–6.3 MiB для proxy 0.12/1 MiB), поэтому разница между C=10 и C=20 не интерпретируется. +- **H2 подтверждена.** Для proxy tx ≈ rx ≈ size (≈2 × size суммарно: вход от клиента и выход в S3). + Для direct при любом из трёх размеров API видит ≈0.07 MiB rx (первый диапазон 64 KiB + служебные + запросы) и ≈0.01 MiB tx, Δrss ≤ 0.9 MiB. Для размера 0.12 MiB выигрыш по rx вдвое (0.13 → 0.07), + по tx — на порядок. Латентность direct выше (p50 45 против 32 мс, 75 против 59 мс — три запроса + вместо одного) и на 9.5 MiB (346 против 239 мс): клиент заливает через loopback в MinIO с лимитом + 1 CPU, а не через API; причина прироста в эксперименте не выяснялась и остаётся гипотезой (вероятно, + проверка подписи и checksum в MinIO). Первая версия `complete` читала диапазон до 1 MiB и + останавливалась по заголовку: сокет к этому моменту уже вычитывал 110–176 KB (read-ahead), а для файлов + ≤ 1 MiB объект читался целиком (rx = size). Это нашло ревью; диапазон 64 KiB убрал оба эффекта. **Ограничения измерений.** Один Docker-хост: клиент, LB, API и MinIO делят 8 CPU, без реальной сети; `/proc/net/dev` реплики включает трафик PG/Redis и служебные запросы метрик (≈7–8 KiB на загрузку, -видно в tx у direct); closed-loop клиент не моделирует arrival rate; выборка RSS 50 мс может +видно в tx у direct; метрики и конфигурация берутся прогонами `docker exec`, но их трафик в +измеряемое окно не входит, кроме двух чтений метрик); closed-loop клиент не моделирует arrival rate; выборка RSS 50 мс может пропустить короткий пик; нет TLS (до lab7); Python-клиент сам ограничен по CPU, поэтому абсолютные латентности не переносимы. @@ -238,9 +245,9 @@ S3) до малой величины, не зависящей от размер | --- | --- | --- | --- | | S3 остановлен (`compose stop s3`) | вложения → bounded 503; текст, история, метаданные, `/health/ready` работают | upload → 503 `unavailable` без утечки деталей; метаданные 200; content 503; текстовое сообщение 201; readiness 200; одна `pending`-строка неудачной загрузки | после `start s3` и healthy download старого файла 200 с теми же байтами, новый upload 201; `pending` убрана sweep; потерь нет | | PostgreSQL остановлен между S3 PUT и `ready` | 503; объект не должен остаться | ответ 503; объект в S3 компенсирован (`mc stat` — нет), `pending`-строка осталась (БД недоступна) | после старта PG и `waitForReadiness`; строка убрана sweep после `expires_at`; `orphans: 0` | -| Обрыв клиента посреди загрузки (512 KiB из 2 MiB) | не остаётся ни строки, ни объекта | `AbortError` у PUT (без ожидания тайм-аута), компенсация, строк в чате 0 | ≤10 с (предел ожидания теста; точное время не измерялось) | +| Обрыв клиента посреди загрузки (512 KiB из 2 MiB) | не остаётся ни строки, ни объекта | PUT прерывается (`S3 put failed: AbortError` в логе API, в evidence не сохранён) без ожидания тайм-аута, компенсация, строк в чате 0 | ≤10 с (предел ожидания теста; точное время не измерялось) | | Остановка обслужившей реплики | другая реплика отдаёт тот же файл | download 200, тот же sha256, другой `X-Instance-Id` для api-1 и api-2 | ≈3.3 с до первого успешного запроса, 0 неуспешных записей из 134–140 | -| Restart стенда (`scripts/restart.sh`) | метаданные и оригиналы сохраняются, сессия жива | persistence PASS; `StartedAt` всех сервисов изменился | весь прогон `make test-persistence` — 11 с; потерь нет | +| Restart стенда (`scripts/restart.sh`) | метаданные и оригиналы сохраняются, сессия жива | persistence PASS; `StartedAt` всех сервисов изменился | потерь нет (время до готовности отдельно не измерялось) | | Истёкший presigned URL | PUT отвергается, заявка убирается | PUT → 403; строка убрана уборщиком; complete → 404 | TTL (5 с в прогоне) + grace 0 + период уборщика 1 с | | Подмена байтов / размера при прямой загрузке | S3 отвергает, объект не создаётся | 400 `XAmzContentChecksumMismatch` / 403 `SignatureDoesNotMatch`; complete → 409 | заявка остаётся до TTL, клиент может доотправить | @@ -249,22 +256,28 @@ S3) до малой величины, не зависящей от размер - **MinIO:** закреплён образ `RELEASE.2025-09-07T16-13-09Z`; по данным, использованным при планировании, репозиторий `minio/minio` архивирован — новых образов и исправлений не будет *(в этой сессии не перепроверялось)*. Для продакшена потребуется замена (SeaweedFS/RustFS) или форк. -- **Прямой путь не проверяет структуру хвоста файла** при size > 1 MiB: только заголовок (до 1 MiB) и +- **Прямой путь не проверяет структуру хвоста файла** при size > 64 KiB: только заголовок (первые 64 KiB, при необходимости до 1 MiB) и подписанный SHA-256/размер. Байты гарантированно те, что заявил клиент, но заявил он их сам; усечённый или «склеенный» файл с корректным заголовком пройдёт `complete`. В proxy-режиме проверяется - весь поток (CRC чанков PNG, EOI JPEG). Для size ≤ 1 MiB direct проверяет всё, ценой входящего + весь поток (CRC чанков PNG, EOI JPEG). Для size ≤ 64 KiB direct проверяет всё, ценой входящего трафика API. - **Гонка лимита заявок:** `countPendingDirect` и `insertPending` не атомарны — параллельные `init` одного пользователя могут превысить лимит на число параллельных запросов; для лабораторной принято. - **Загрузка, не доставленная до `ready`, видна уборщику только через grace (по умолчанию 15 мин):** до этого объект занимает место; для быстрой очистки в тестах grace уменьшается переменной окружения. - **Недоступность S3 при `compensate`** оставляет объект, если сам `DeleteObject` не прошёл; его - убирает уборщик, но объект без строки (если строка уже удалена вручную) обнаружит только - `make consistency` — автоматического reconciler'а для orphan-объектов без строки нет (это трек 2). + убирает уборщик по строке. Объект без строки (например, строку удалили вручную) обнаружит только + `make consistency` — автоматического reconciler'а для orphan-объектов нет (это трек 2). +- **Порядок компенсации proxy:** сначала удаляется объект, затем строка. Если `markReady` на самом деле + зафиксирован, а клиент БД увидел обрыв соединения, объект будет удалён у строки `ready` (потеря данных; + `object_missing` → 500 на download). Обратный порядок противоречил бы требованию «объекта не должно + остаться при отказе PG»; окно — доли секунды между commit и обрывом, принято как ограничение. +- **Таймаут загрузки** уничтожает тело (и сокет) — клиент может получить обрыв соединения вместо + ожидаемого 400 «Upload was interrupted»; строка и объект при этом компенсируются. - **TLS нет** до lab7: presigned URL и токены ходят по HTTP; консоль MinIO отключена полностью, поэтому администрирование — только через `mc` из контейнера. - **Не реализовано:** варианты вложений (`variants` всегда `[]`; `variant=thumbnail|crop|optimized` → 404), delete-API вложений, WebP. -- **Подтверждено измерением:** потоковый proxy ограничивает память, direct уменьшает tx API и rx API для - файлов > 1 MiB. **Остаётся гипотезой:** причина роста латентности direct на 9.5 MiB; зависимость Δrss от +- **Подтверждено измерением:** потоковый proxy ограничивает память, direct уменьшает tx и rx API для + любого из проверенных размеров. **Остаётся гипотезой:** причина роста латентности direct на 9.5 MiB; зависимость Δrss от concurrency за пределами C=20. diff --git a/app/src/attachments/attachment.ts b/app/src/attachments/attachment.ts index 86a0733d..c3df9ec9 100644 --- a/app/src/attachments/attachment.ts +++ b/app/src/attachments/attachment.ts @@ -20,7 +20,7 @@ export type AttachmentRow = { filename: string; content_type: 'image/png' | 'image/jpeg'; upload_mode: 'proxy' | 'direct'; - status: 'pending' | 'ready' | 'deleting'; + status: 'pending' | 'ready' | 'deleting' | 'rejected'; object_key: string; size_bytes: string | number | null; sha256: string | null; diff --git a/app/src/attachments/attachments.repository.ts b/app/src/attachments/attachments.repository.ts index f846ed0e..a3cea2c8 100644 --- a/app/src/attachments/attachments.repository.ts +++ b/app/src/attachments/attachments.repository.ts @@ -75,6 +75,15 @@ export class AttachmentsRepository { ); } + async rejectPending(id: string): Promise { + await this.database.query( + 'attachments.reject_pending', + `UPDATE attachments SET status = 'rejected', updated_at = now() + WHERE id = $1 AND status = 'pending'`, + [id], + ); + } + async findVisible( id: string, userId: string, @@ -106,7 +115,8 @@ export class AttachmentsRepository { const result = await this.database.query<{ count: string }>( 'attachments.count_pending_direct', `SELECT count(*) AS count FROM attachments - WHERE owner_id = $1 AND status = 'pending' AND upload_mode = 'direct'`, + WHERE owner_id = $1 AND status IN ('pending', 'rejected') + AND upload_mode = 'direct' AND expires_at > now()`, [ownerId], ); return Number(result.rows[0].count); @@ -134,7 +144,7 @@ export class AttachmentsRepository { `UPDATE attachments SET status = 'deleting', updated_at = now() WHERE id IN ( SELECT id FROM attachments - WHERE (status = 'pending' + WHERE (status IN ('pending', 'rejected') AND expires_at < now() - make_interval(secs => $1::double precision)) OR (status = 'deleting' AND updated_at < now() - interval '1 minute') ORDER BY expires_at NULLS FIRST diff --git a/app/src/attachments/direct-uploads.service.ts b/app/src/attachments/direct-uploads.service.ts index b902ac33..4229436b 100644 --- a/app/src/attachments/direct-uploads.service.ts +++ b/app/src/attachments/direct-uploads.service.ts @@ -13,15 +13,20 @@ import { ChatsService } from '../chats/chats.service.js'; import { MetricsService } from '../metrics/metrics.service.js'; import { ObjectStorage } from '../storage/object-storage.js'; import type { User } from '../users/user.js'; -import { toAttachment, type Attachment } from './attachment.js'; +import { + toAttachment, + type Attachment, + type AttachmentRow, +} from './attachment.js'; import { AttachmentsRepository } from './attachments.repository.js'; -import { AttachmentsService, imageRejection } from './attachments.service.js'; +import { imageRejection } from './attachments.service.js'; import type { CreateDirectUploadDto } from './dto/create-direct-upload.dto.js'; import { validateFilename } from './filename.js'; import { IMAGE_HEADER_MAX_BYTES, ImageInspector, ImageRejectedError, + type ImageHeader, } from './image/image-inspector.js'; export type DirectUpload = { @@ -32,6 +37,7 @@ export type DirectUpload = { expires_at: string; }; +const FIRST_RANGE_BYTES = 65_536; const MEDIA_TYPES = new Set(['image/png', 'image/jpeg']); @Injectable() @@ -47,7 +53,6 @@ export class DirectUploadsService { private readonly storage: ObjectStorage, private readonly chats: ChatsService, private readonly metrics: MetricsService, - private readonly attachments: AttachmentsService, ) { this.maxUploadBytes = config.getOrThrow('MAX_UPLOAD_BYTES'); this.maxPixels = config.getOrThrow('MAX_IMAGE_PIXELS'); @@ -141,47 +146,25 @@ export class DirectUploadsService { if (head === null) throw new ConflictException('Upload has not been received'); if (head.size !== size || head.checksumSha256 !== expectedChecksum) { - await this.attachments.compensate(row.id, row.object_key); + await this.reject(row); throw new ConflictException( 'Uploaded object does not match the declaration', ); } // Only the header is read: the signed checksum already pins every byte. - const inspector = new ImageInspector(this.maxPixels); - const covered = size <= IMAGE_HEADER_MAX_BYTES; - const stream = await this.storage.getStream( - row.object_key, - `bytes=0-${Math.min(size, IMAGE_HEADER_MAX_BYTES) - 1}`, - ); - if (stream === null) - throw new ConflictException('Upload has not been received'); - let verified = 0; + let header: ImageHeader; try { - for await (const chunk of stream as AsyncIterable) { - verified += chunk.length; - inspector.push(chunk); - if (!covered && inspector.header !== undefined) break; - } - if (covered) inspector.finish(); - else if (inspector.header === undefined) - throw new ImageRejectedError( - 'unsupported_media_type', - 'Image header is missing', - ); + header = await this.readHeader(row.object_key, size); } catch (error) { if (error instanceof ImageRejectedError) { - await this.attachments.compensate(row.id, row.object_key); + await this.reject(row); throw imageRejection(error); } throw error; - } finally { - stream.destroy(); - this.metrics.add('attachments.direct.verify_bytes', verified); } - const header = inspector.header; - if (header === undefined || header.contentType !== row.content_type) { - await this.attachments.compensate(row.id, row.object_key); + if (header.contentType !== row.content_type) { + await this.reject(row); throw new UnsupportedMediaTypeException( 'Image content does not match content_type', ); @@ -196,4 +179,56 @@ export class DirectUploadsService { this.metrics.increment('attachments.direct.completed'); return toAttachment(ready); } + + /** + * Reads a small first range and widens it only when the header is not in it, + * so the usual `complete` costs one short ranged GET. A range that covers the + * whole object is also checked for structural completeness. + */ + private async readHeader(key: string, size: number): Promise { + const ceiling = Math.min(size, IMAGE_HEADER_MAX_BYTES); + let range = Math.min(size, FIRST_RANGE_BYTES); + for (;;) { + const inspector = new ImageInspector(this.maxPixels); + const stream = await this.storage.getStream( + key, + `bytes=0-${range - 1}`, + ); + if (stream === null) + throw new ConflictException('Upload has not been received'); + let verified = 0; + try { + for await (const chunk of stream as AsyncIterable) { + verified += chunk.length; + inspector.push(chunk); + } + } finally { + stream.destroy(); + this.metrics.add('attachments.direct.verify_bytes', verified); + } + if (range === size) return inspector.finish(); + if (inspector.header !== undefined) return inspector.header; + if (range >= ceiling) + throw new ImageRejectedError( + 'unsupported_media_type', + 'Image header is missing', + ); + range = ceiling; + } + } + + /** + * A rejected claim keeps its row (status `rejected`, original expiry) while + * the signed URL may still be used: a later re-PUT would otherwise leave an + * object that no row refers to. The sweeper removes both after expiry + grace. + */ + private async reject(row: AttachmentRow): Promise { + await this.repository.rejectPending(row.id); + try { + await this.storage.delete(row.object_key); + } catch { + // The sweeper deletes the object again after expiry. + } + this.metrics.increment('attachments.direct.rejected'); + } } diff --git a/app/src/database/migrations/006_attachment_rejected.sql b/app/src/database/migrations/006_attachment_rejected.sql new file mode 100644 index 00000000..6040217f --- /dev/null +++ b/app/src/database/migrations/006_attachment_rejected.sql @@ -0,0 +1,8 @@ +-- Rejected direct uploads keep their row until the signed URL can no longer be +-- used, so an object re-PUT after rejection is still found by the sweeper. +ALTER TABLE attachments DROP CONSTRAINT attachments_status_check; +ALTER TABLE attachments ADD CONSTRAINT attachments_status_check + CHECK (status IN ('pending', 'ready', 'deleting', 'rejected')); +DROP INDEX attachments_owner_direct_pending_idx; +CREATE INDEX attachments_owner_direct_pending_idx ON attachments (owner_id) + WHERE status IN ('pending', 'rejected') AND upload_mode = 'direct'; diff --git a/app/src/main.ts b/app/src/main.ts index dee1f60a..b799f2e0 100644 --- a/app/src/main.ts +++ b/app/src/main.ts @@ -1,7 +1,12 @@ import { NestFactory } from '@nestjs/core'; import { HttpAdapterHost } from '@nestjs/core'; import { ConfigService } from '@nestjs/config'; -import { ValidationPipe } from '@nestjs/common'; +import { + PayloadTooLargeException, + UnsupportedMediaTypeException, + ValidationPipe, +} from '@nestjs/common'; +import type { Readable } from 'node:stream'; import { FastifyAdapter, NestFastifyApplication, @@ -11,24 +16,52 @@ import { HealthService } from './health/health.service.js'; import { MetricsService } from './metrics/metrics.service.js'; import { RequestIdInterceptor } from './common/http/request-id.interceptor.js'; +const TEXT_BODY_LIMIT = 1_048_576; +const UPLOAD_ROUTE = '/api/v1/chats/:chatId/attachments'; + async function bootstrap(): Promise { const app = await NestFactory.create( AppModule, new FastifyAdapter({ logger: true }), ); // Raw image bodies reach the controller as an unread stream: the upload is - // bounded by our own checks, not by Fastify's bodyLimit. + // bounded by our own checks, not by Fastify's bodyLimit. A stream may reach + // only the upload route: on JSON routes it would hit the ValidationPipe and + // overflow the stack there, so other routes keep the pre-upload behavior. const fastify = app.getHttpAdapter().getInstance(); + type ParserRequest = { method: string; routeOptions?: { url?: string } }; + type Done = (error: Error | null, body?: unknown) => void; + const isUpload = (request: ParserRequest) => + request.method === 'POST' && request.routeOptions?.url === UPLOAD_ROUTE; + fastify.addContentTypeParser( + ['image/png', 'image/jpeg'], + (request: ParserRequest, payload: unknown, done: Done) => + isUpload(request) + ? done(null, payload) + : done(new UnsupportedMediaTypeException()), + ); // Fastify's built-in text/plain parser buffers the body and fails binary - // input with 400; the upload service answers 415 for it instead. + // input with 400; on the upload route the service answers 415 instead. + // Elsewhere text/plain keeps being buffered as a string (1 MiB cap). fastify.removeContentTypeParser('text/plain'); fastify.addContentTypeParser( - ['image/png', 'image/jpeg', 'text/plain'], - ( - _request: unknown, - payload: unknown, - done: (error: Error | null, body?: unknown) => void, - ) => done(null, payload), + 'text/plain', + (request: ParserRequest, payload: Readable, done: Done) => { + if (isUpload(request)) return done(null, payload); + const chunks: Buffer[] = []; + let size = 0; + payload.on('data', (chunk: Buffer) => { + size += chunk.length; + if (size > TEXT_BODY_LIMIT) { + payload.destroy(); + done(new PayloadTooLargeException()); + } else chunks.push(chunk); + }); + payload.on('end', () => + done(null, Buffer.concat(chunks).toString('utf8')), + ); + payload.on('error', (error: Error) => done(error)); + }, ); app.useGlobalInterceptors( new RequestIdInterceptor( diff --git a/app/test/attachments.e2e-spec.ts b/app/test/attachments.e2e-spec.ts index 4ab1009d..12412585 100644 --- a/app/test/attachments.e2e-spec.ts +++ b/app/test/attachments.e2e-spec.ts @@ -325,6 +325,21 @@ describe('attachments (proxy upload)', () => { expectError(await variant('bogus'), 400, 'invalid_request'); }); + it('answers 4xx, not 500, for raw image or text bodies on JSON routes', async () => { + for (const [type, status, code] of [ + ['image/png', 415, 'unsupported_media_type'], + ['image/jpeg', 415, 'unsupported_media_type'], + ['text/plain', 400, 'invalid_request'], + ] as const) { + const result = await http('/api/v1/users', { + method: 'POST', + headers: { 'content-type': type }, + body: 'x', + }); + expectError(result, status, code); + } + }); + it('removes the pending row when the client drops the connection', async () => { const data = noisePng(2 * 1024 * 1024); const url = new URL(baseUrl); diff --git a/app/test/direct-upload.e2e-spec.ts b/app/test/direct-upload.e2e-spec.ts index 40e3d175..f448dae3 100644 --- a/app/test/direct-upload.e2e-spec.ts +++ b/app/test/direct-upload.e2e-spec.ts @@ -228,6 +228,19 @@ describe('direct upload (presigned PUT)', () => { 404, 'not_found', ); + // The URL is still valid: a re-PUT must stay tracked so the sweeper + // removes the new object too. + expect((await put(ticket, jpeg)).status).toBe(200); + const row = await db.query<{ status: string }>( + 'SELECT status FROM attachments WHERE id = $1', + [ticket.attachment_id], + ); + expect(row.rows[0]?.status).toBe('rejected'); + expectError( + await complete(alice.token, ticket.attachment_id), + 404, + 'not_found', + ); }); it('rejects a pixel bomb on complete', async () => { diff --git a/evidence/lab4/bench/direct-1048576-c10.json b/evidence/lab4/bench/direct-1048576-c10.json index ff6950e6..e6f9e3fd 100644 --- a/evidence/lab4/bench/direct-1048576-c10.json +++ b/evidence/lab4/bench/direct-1048576-c10.json @@ -1,6 +1,6 @@ { - "date": "2026-10-22T19:43:37+00:00", - "git": "39a6df8", + "date": "2026-10-22T20:02:21+00:00", + "git": "f048a37", "params": { "mode": "direct", "size_bytes": 1048576, @@ -21,147 +21,169 @@ "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.472, + "duration_s": 0.542, "latency_ms": { - "p50": 68.8, - "p95": 100.5, - "p99": 116.7 + "p50": 69.2, + "p95": 101.4, + "p99": 125.5 }, "replicas": [ { - "instance_id": "b50bb8514a7b", - "delta_rx_bytes": 24305156, - "delta_tx_bytes": 190336, - "baseline_rss_bytes": 196403200, + "instance_id": "01e84e9e9e38", + "delta_rx_bytes": 1732876, + "delta_tx_bytes": 185102, + "baseline_rss_bytes": 192851968, "peak_memory_bytes": { - "rss": 196403200, - "heap_used": 54520056, - "external": 19317560, - "array_buffers": 15527216 + "rss": 192983040, + "heap_used": 51764168, + "external": 7874039, + "array_buffers": 4083695 }, - "delta_rss_bytes": 0, + "delta_rss_bytes": 131072, "counters": { - "attachments.count_pending_direct": 27, - "attachments.insert_pending": 27, - "attachments.direct.initiated": 27, - "attachments.find_for_complete": 23, - "attachments.direct.verify_bytes": 24117248, - "attachments.mark_ready": 23, - "attachments.direct.completed": 23 + "attachments.count_pending_direct": 26, + "attachments.insert_pending": 26, + "attachments.direct.initiated": 26, + "attachments.find_for_complete": 24, + "attachments.direct.verify_bytes": 1572864, + "attachments.mark_ready": 24, + "attachments.direct.completed": 24 } }, { - "instance_id": "fc61f806b880", - "delta_rx_bytes": 28515385, - "delta_tx_bytes": 191536, - "baseline_rss_bytes": 192991232, + "instance_id": "d49b799653d6", + "delta_rx_bytes": 1868893, + "delta_tx_bytes": 186494, + "baseline_rss_bytes": 181489664, "peak_memory_bytes": { - "rss": 192991232, - "heap_used": 50609288, - "external": 23827415, - "array_buffers": 13323225 + "rss": 182013952, + "heap_used": 53099792, + "external": 7642630, + "array_buffers": 3852254 }, - "delta_rss_bytes": 0, + "delta_rss_bytes": 524288, "counters": { - "attachments.count_pending_direct": 23, - "attachments.insert_pending": 23, - "attachments.direct.initiated": 23, - "attachments.find_for_complete": 27, - "attachments.direct.verify_bytes": 28311552, - "attachments.mark_ready": 27, - "attachments.direct.completed": 27 + "attachments.count_pending_direct": 24, + "attachments.insert_pending": 24, + "attachments.direct.initiated": 24, + "attachments.find_for_complete": 26, + "attachments.direct.verify_bytes": 1703936, + "attachments.mark_ready": 26, + "attachments.direct.completed": 26 } } ], - "total_delta_rx_bytes": 52820541, - "total_delta_tx_bytes": 381872, - "rx_bytes_per_upload": 1056411, - "tx_bytes_per_upload": 7637, - "max_delta_rss_bytes": 0 + "total_delta_rx_bytes": 3601769, + "total_delta_tx_bytes": 371596, + "rx_bytes_per_upload": 72035, + "tx_bytes_per_upload": 7432, + "max_delta_rss_bytes": 524288 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.526, + "duration_s": 0.685, "latency_ms": { - "p50": 73.9, - "p95": 109.6, - "p99": 127.7 + "p50": 111.1, + "p95": 137.0, + "p99": 142.2 }, "replicas": [ { - "instance_id": "b50bb8514a7b", - "delta_rx_bytes": 28515174, - "delta_tx_bytes": 193117, - "baseline_rss_bytes": 193875968, + "instance_id": "01e84e9e9e38", + "delta_rx_bytes": 1800815, + "delta_tx_bytes": 186876, + "baseline_rss_bytes": 192983040, "peak_memory_bytes": { - "rss": 203390976, - "heap_used": 57046056, - "external": 29834167, - "array_buffers": 26043823 + "rss": 193507328, + "heap_used": 51579728, + "external": 6754919, + "array_buffers": 2800370 }, - "delta_rss_bytes": 9515008, + "delta_rss_bytes": 524288, "counters": { - "attachments.count_pending_direct": 23, - "attachments.insert_pending": 23, - "attachments.direct.initiated": 23, - "attachments.find_for_complete": 27, - "attachments.direct.verify_bytes": 28311552, - "attachments.mark_ready": 27, - "attachments.direct.completed": 27 + "attachments.count_pending_direct": 25, + "attachments.insert_pending": 25, + "attachments.direct.initiated": 25, + "attachments.find_for_complete": 25, + "attachments.direct.verify_bytes": 1638400, + "attachments.mark_ready": 25, + "attachments.direct.completed": 25 } }, { - "instance_id": "fc61f806b880", - "delta_rx_bytes": 24304620, - "delta_tx_bytes": 183249, - "baseline_rss_bytes": 187240448, + "instance_id": "d49b799653d6", + "delta_rx_bytes": 1800709, + "delta_tx_bytes": 185964, + "baseline_rss_bytes": 182013952, "peak_memory_bytes": { - "rss": 193400832, - "heap_used": 55168312, - "external": 23469861, - "array_buffers": 19679517 + "rss": 182800384, + "heap_used": 53017320, + "external": 7914245, + "array_buffers": 4123869 }, - "delta_rss_bytes": 6160384, + "delta_rss_bytes": 786432, "counters": { - "attachments.count_pending_direct": 27, - "attachments.insert_pending": 27, - "attachments.direct.initiated": 27, - "attachments.find_for_complete": 23, - "attachments.direct.verify_bytes": 24117248, - "attachments.mark_ready": 23, - "attachments.direct.completed": 23 + "attachments.count_pending_direct": 25, + "attachments.insert_pending": 25, + "attachments.direct.initiated": 25, + "attachments.find_for_complete": 25, + "attachments.direct.verify_bytes": 1638400, + "attachments.mark_ready": 25, + "attachments.direct.completed": 25 } } ], - "total_delta_rx_bytes": 52819794, - "total_delta_tx_bytes": 376366, - "rx_bytes_per_upload": 1056396, - "tx_bytes_per_upload": 7527, - "max_delta_rss_bytes": 9515008 + "total_delta_rx_bytes": 3601524, + "total_delta_tx_bytes": 372840, + "rx_bytes_per_upload": 72030, + "tx_bytes_per_upload": 7457, + "max_delta_rss_bytes": 786432 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.466, + "duration_s": 0.552, "latency_ms": { - "p50": 64.7, - "p95": 93.7, - "p99": 107.8 + "p50": 75.4, + "p95": 147.0, + "p99": 157.9 }, "replicas": [ { - "instance_id": "b50bb8514a7b", - "delta_rx_bytes": 26412041, - "delta_tx_bytes": 186281, - "baseline_rss_bytes": 195010560, + "instance_id": "01e84e9e9e38", + "delta_rx_bytes": 1801291, + "delta_tx_bytes": 185886, + "baseline_rss_bytes": 193396736, "peak_memory_bytes": { - "rss": 195010560, - "heap_used": 51614528, - "external": 19277639, - "array_buffers": 15487295 + "rss": 194314240, + "heap_used": 52852056, + "external": 6737214, + "array_buffers": 2946870 + }, + "delta_rss_bytes": 917504, + "counters": { + "attachments.count_pending_direct": 25, + "attachments.insert_pending": 25, + "attachments.direct.initiated": 25, + "attachments.find_for_complete": 25, + "attachments.direct.verify_bytes": 1638400, + "attachments.mark_ready": 25, + "attachments.direct.completed": 25 + } + }, + { + "instance_id": "d49b799653d6", + "delta_rx_bytes": 1800711, + "delta_tx_bytes": 185106, + "baseline_rss_bytes": 182374400, + "peak_memory_bytes": { + "rss": 182374400, + "heap_used": 53283160, + "external": 7898022, + "array_buffers": 3970019 }, "delta_rss_bytes": 0, "counters": { @@ -169,39 +191,17 @@ "attachments.insert_pending": 25, "attachments.direct.initiated": 25, "attachments.find_for_complete": 25, - "attachments.direct.verify_bytes": 26214400, - "attachments.mark_ready": 25, - "attachments.direct.completed": 25 - } - }, - { - "instance_id": "fc61f806b880", - "delta_rx_bytes": 26410201, - "delta_tx_bytes": 187551, - "baseline_rss_bytes": 190717952, - "peak_memory_bytes": { - "rss": 194781184, - "heap_used": 53366896, - "external": 19243061, - "array_buffers": 15452717 - }, - "delta_rss_bytes": 4063232, - "counters": { - "attachments.count_pending_direct": 25, - "attachments.insert_pending": 25, - "attachments.direct.initiated": 25, - "attachments.find_for_complete": 25, - "attachments.direct.verify_bytes": 26214400, + "attachments.direct.verify_bytes": 1638400, "attachments.mark_ready": 25, "attachments.direct.completed": 25 } } ], - "total_delta_rx_bytes": 52822242, - "total_delta_tx_bytes": 373832, - "rx_bytes_per_upload": 1056445, - "tx_bytes_per_upload": 7477, - "max_delta_rss_bytes": 4063232 + "total_delta_rx_bytes": 3602002, + "total_delta_tx_bytes": 370992, + "rx_bytes_per_upload": 72040, + "tx_bytes_per_upload": 7420, + "max_delta_rss_bytes": 917504 } ] } diff --git a/evidence/lab4/bench/direct-131072-c10.json b/evidence/lab4/bench/direct-131072-c10.json index 5ec49ab8..7c42ee97 100644 --- a/evidence/lab4/bench/direct-131072-c10.json +++ b/evidence/lab4/bench/direct-131072-c10.json @@ -1,6 +1,6 @@ { - "date": "2026-10-22T19:43:26+00:00", - "git": "39a6df8", + "date": "2026-10-22T20:02:09+00:00", + "git": "f048a37", "params": { "mode": "direct", "size_bytes": 131072, @@ -21,187 +21,187 @@ "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.265, + "duration_s": 0.242, "latency_ms": { - "p50": 48.2, - "p95": 62.4, - "p99": 72.8 + "p50": 43.2, + "p95": 56.1, + "p99": 59.7 }, "replicas": [ { - "instance_id": "b50bb8514a7b", - "delta_rx_bytes": 3306431, - "delta_tx_bytes": 182851, - "baseline_rss_bytes": 182366208, + "instance_id": "01e84e9e9e38", + "delta_rx_bytes": 1869074, + "delta_tx_bytes": 185920, + "baseline_rss_bytes": 182263808, "peak_memory_bytes": { - "rss": 184594432, - "heap_used": 61323144, - "external": 8848467, - "array_buffers": 5055973 + "rss": 182898688, + "heap_used": 53275328, + "external": 9220810, + "array_buffers": 5428348 }, - "delta_rss_bytes": 2228224, + "delta_rss_bytes": 634880, + "counters": { + "attachments.count_pending_direct": 24, + "attachments.insert_pending": 24, + "attachments.direct.initiated": 24, + "attachments.find_for_complete": 26, + "attachments.direct.verify_bytes": 1703936, + "attachments.mark_ready": 26, + "attachments.direct.completed": 26 + } + }, + { + "instance_id": "d49b799653d6", + "delta_rx_bytes": 1732185, + "delta_tx_bytes": 183862, + "baseline_rss_bytes": 173453312, + "peak_memory_bytes": { + "rss": 173862912, + "heap_used": 51776512, + "external": 7372259, + "array_buffers": 3579797 + }, + "delta_rss_bytes": 409600, "counters": { "attachments.count_pending_direct": 26, "attachments.insert_pending": 26, "attachments.direct.initiated": 26, "attachments.find_for_complete": 24, - "attachments.direct.verify_bytes": 3145728, + "attachments.direct.verify_bytes": 1572864, "attachments.mark_ready": 24, "attachments.direct.completed": 24 } - }, - { - "instance_id": "fc61f806b880", - "delta_rx_bytes": 3573839, - "delta_tx_bytes": 184939, - "baseline_rss_bytes": 182042624, - "peak_memory_bytes": { - "rss": 182796288, - "heap_used": 60727960, - "external": 8999631, - "array_buffers": 5207169 - }, - "delta_rss_bytes": 753664, - "counters": { - "attachments.count_pending_direct": 24, - "attachments.insert_pending": 24, - "attachments.direct.initiated": 24, - "attachments.find_for_complete": 26, - "attachments.direct.verify_bytes": 3407872, - "attachments.mark_ready": 26, - "attachments.direct.completed": 26 - } } ], - "total_delta_rx_bytes": 6880270, - "total_delta_tx_bytes": 367790, - "rx_bytes_per_upload": 137605, - "tx_bytes_per_upload": 7356, - "max_delta_rss_bytes": 2228224 + "total_delta_rx_bytes": 3601259, + "total_delta_tx_bytes": 369782, + "rx_bytes_per_upload": 72025, + "tx_bytes_per_upload": 7396, + "max_delta_rss_bytes": 634880 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.211, + "duration_s": 0.254, "latency_ms": { - "p50": 36.7, - "p95": 50.0, - "p99": 54.8 + "p50": 44.9, + "p95": 64.9, + "p99": 74.0 }, "replicas": [ { - "instance_id": "b50bb8514a7b", - "delta_rx_bytes": 3574513, - "delta_tx_bytes": 184486, - "baseline_rss_bytes": 184594432, + "instance_id": "01e84e9e9e38", + "delta_rx_bytes": 1663798, + "delta_tx_bytes": 181411, + "baseline_rss_bytes": 182898688, "peak_memory_bytes": { - "rss": 184987648, - "heap_used": 60934432, - "external": 9389278, - "array_buffers": 5596784 + "rss": 183029760, + "heap_used": 52623040, + "external": 9199397, + "array_buffers": 5406935 }, - "delta_rss_bytes": 393216, + "delta_rss_bytes": 131072, "counters": { - "attachments.count_pending_direct": 24, - "attachments.insert_pending": 24, - "attachments.direct.initiated": 24, - "attachments.find_for_complete": 26, - "attachments.direct.verify_bytes": 3407872, - "attachments.mark_ready": 26, - "attachments.direct.completed": 26 + "attachments.count_pending_direct": 27, + "attachments.insert_pending": 27, + "attachments.direct.initiated": 27, + "attachments.find_for_complete": 23, + "attachments.direct.verify_bytes": 1507328, + "attachments.mark_ready": 23, + "attachments.direct.completed": 23 } }, { - "instance_id": "fc61f806b880", - "delta_rx_bytes": 3306277, - "delta_tx_bytes": 181456, - "baseline_rss_bytes": 182796288, + "instance_id": "d49b799653d6", + "delta_rx_bytes": 1936597, + "delta_tx_bytes": 185873, + "baseline_rss_bytes": 173862912, "peak_memory_bytes": { - "rss": 183058432, - "heap_used": 59419712, - "external": 8997869, - "array_buffers": 5205407 + "rss": 174125056, + "heap_used": 53719328, + "external": 7649562, + "array_buffers": 3857100 }, "delta_rss_bytes": 262144, "counters": { - "attachments.count_pending_direct": 26, - "attachments.insert_pending": 26, - "attachments.direct.initiated": 26, - "attachments.find_for_complete": 24, - "attachments.direct.verify_bytes": 3145728, - "attachments.mark_ready": 24, - "attachments.direct.completed": 24 + "attachments.count_pending_direct": 23, + "attachments.insert_pending": 23, + "attachments.direct.initiated": 23, + "attachments.find_for_complete": 27, + "attachments.direct.verify_bytes": 1769472, + "attachments.mark_ready": 27, + "attachments.direct.completed": 27 } } ], - "total_delta_rx_bytes": 6880790, - "total_delta_tx_bytes": 365942, - "rx_bytes_per_upload": 137616, - "tx_bytes_per_upload": 7319, - "max_delta_rss_bytes": 393216 + "total_delta_rx_bytes": 3600395, + "total_delta_tx_bytes": 367284, + "rx_bytes_per_upload": 72008, + "tx_bytes_per_upload": 7346, + "max_delta_rss_bytes": 262144 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.241, + "duration_s": 0.441, "latency_ms": { - "p50": 41.6, - "p95": 64.6, - "p99": 72.2 + "p50": 80.3, + "p95": 124.0, + "p99": 127.6 }, "replicas": [ { - "instance_id": "b50bb8514a7b", - "delta_rx_bytes": 3574028, - "delta_tx_bytes": 183565, - "baseline_rss_bytes": 184987648, + "instance_id": "01e84e9e9e38", + "delta_rx_bytes": 2007125, + "delta_tx_bytes": 186925, + "baseline_rss_bytes": 183029760, "peak_memory_bytes": { - "rss": 185643008, - "heap_used": 62756424, - "external": 9669133, - "array_buffers": 5876639 + "rss": 183447552, + "heap_used": 56507192, + "external": 9369635, + "array_buffers": 5577173 }, - "delta_rss_bytes": 655360, + "delta_rss_bytes": 417792, "counters": { - "attachments.count_pending_direct": 24, - "attachments.insert_pending": 24, - "attachments.direct.initiated": 24, - "attachments.find_for_complete": 26, - "attachments.direct.verify_bytes": 3407872, - "attachments.mark_ready": 26, - "attachments.direct.completed": 26 + "attachments.count_pending_direct": 22, + "attachments.insert_pending": 22, + "attachments.direct.initiated": 22, + "attachments.find_for_complete": 28, + "attachments.direct.verify_bytes": 1835008, + "attachments.mark_ready": 28, + "attachments.direct.completed": 28 } }, { - "instance_id": "fc61f806b880", - "delta_rx_bytes": 3306617, - "delta_tx_bytes": 181349, - "baseline_rss_bytes": 183058432, + "instance_id": "d49b799653d6", + "delta_rx_bytes": 1596449, + "delta_tx_bytes": 182757, + "baseline_rss_bytes": 174125056, "peak_memory_bytes": { - "rss": 183713792, - "heap_used": 62301928, - "external": 9312649, - "array_buffers": 5520187 + "rss": 174387200, + "heap_used": 54337704, + "external": 7649635, + "array_buffers": 3857173 }, - "delta_rss_bytes": 655360, + "delta_rss_bytes": 262144, "counters": { - "attachments.count_pending_direct": 26, - "attachments.insert_pending": 26, - "attachments.direct.initiated": 26, - "attachments.find_for_complete": 24, - "attachments.direct.verify_bytes": 3145728, - "attachments.mark_ready": 24, - "attachments.direct.completed": 24 + "attachments.count_pending_direct": 28, + "attachments.insert_pending": 28, + "attachments.direct.initiated": 28, + "attachments.find_for_complete": 22, + "attachments.direct.verify_bytes": 1441792, + "attachments.mark_ready": 22, + "attachments.direct.completed": 22 } } ], - "total_delta_rx_bytes": 6880645, - "total_delta_tx_bytes": 364914, - "rx_bytes_per_upload": 137613, - "tx_bytes_per_upload": 7298, - "max_delta_rss_bytes": 655360 + "total_delta_rx_bytes": 3603574, + "total_delta_tx_bytes": 369682, + "rx_bytes_per_upload": 72071, + "tx_bytes_per_upload": 7394, + "max_delta_rss_bytes": 417792 } ] } diff --git a/evidence/lab4/bench/direct-9961472-c10.json b/evidence/lab4/bench/direct-9961472-c10.json index f0b946b7..a06e0b5e 100644 --- a/evidence/lab4/bench/direct-9961472-c10.json +++ b/evidence/lab4/bench/direct-9961472-c10.json @@ -1,6 +1,6 @@ { - "date": "2026-10-22T19:44:02+00:00", - "git": "39a6df8", + "date": "2026-10-22T20:02:47+00:00", + "git": "f048a37", "params": { "mode": "direct", "size_bytes": 9961472, @@ -21,188 +21,187 @@ "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 2.977, + "duration_s": 3.048, "latency_ms": { - "p50": 373.6, - "p95": 580.2, - "p99": 606.3 + "p50": 346.0, + "p95": 575.3, + "p99": 581.2 }, "replicas": [ { - "instance_id": "b50bb8514a7b", - "delta_rx_bytes": 5859769, - "delta_tx_bytes": 204758, - "baseline_rss_bytes": 206934016, + "instance_id": "01e84e9e9e38", + "delta_rx_bytes": 1669140, + "delta_tx_bytes": 194261, + "baseline_rss_bytes": 189468672, "peak_memory_bytes": { - "rss": 207065088, - "heap_used": 59528520, - "external": 23734700, - "array_buffers": 19944356 + "rss": 189468672, + "heap_used": 59441184, + "external": 6250789, + "array_buffers": 2449996 }, - "delta_rss_bytes": 131072, + "delta_rss_bytes": 0, "counters": { - "attachments.count_pending_direct": 24, - "attachments.insert_pending": 24, - "attachments.direct.initiated": 24, - "attachments.find_for_complete": 26, - "attachments.direct.verify_bytes": 573886, - "attachments.mark_ready": 26, - "attachments.direct.completed": 26 + "attachments.count_pending_direct": 27, + "attachments.insert_pending": 27, + "attachments.direct.initiated": 27, + "attachments.find_for_complete": 23, + "attachments.direct.verify_bytes": 1507328, + "attachments.mark_ready": 23, + "attachments.direct.completed": 23 } }, { - "instance_id": "fc61f806b880", - "delta_rx_bytes": 2941745, - "delta_tx_bytes": 201620, - "baseline_rss_bytes": 204890112, + "instance_id": "d49b799653d6", + "delta_rx_bytes": 1940713, + "delta_tx_bytes": 195885, + "baseline_rss_bytes": 179376128, "peak_memory_bytes": { - "rss": 205152256, - "heap_used": 58915888, - "external": 11971121, - "array_buffers": 8180777 + "rss": 180293632, + "heap_used": 59568768, + "external": 6672150, + "array_buffers": 2881806 }, - "delta_rss_bytes": 262144, + "delta_rss_bytes": 917504, "counters": { - "attachments.count_pending_direct": 26, - "attachments.insert_pending": 26, - "attachments.direct.initiated": 26, - "attachments.find_for_complete": 24, - "attachments.direct.verify_bytes": 454808, - "attachments.mark_ready": 24, - "attachments.direct.completed": 24 + "attachments.count_pending_direct": 23, + "attachments.insert_pending": 23, + "attachments.direct.initiated": 23, + "attachments.find_for_complete": 27, + "attachments.direct.verify_bytes": 1769472, + "attachments.mark_ready": 27, + "attachments.direct.completed": 27 } } ], - "total_delta_rx_bytes": 8801514, - "total_delta_tx_bytes": 406378, - "rx_bytes_per_upload": 176030, - "tx_bytes_per_upload": 8128, - "max_delta_rss_bytes": 262144 + "total_delta_rx_bytes": 3609853, + "total_delta_tx_bytes": 390146, + "rx_bytes_per_upload": 72197, + "tx_bytes_per_upload": 7803, + "max_delta_rss_bytes": 917504 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 3.016, + "duration_s": 2.948, "latency_ms": { - "p50": 377.9, - "p95": 493.4, - "p99": 534.7 + "p50": 350.2, + "p95": 570.8, + "p99": 608.6 }, "replicas": [ { - "instance_id": "b50bb8514a7b", - "delta_rx_bytes": 3426165, - "delta_tx_bytes": 205333, - "baseline_rss_bytes": 207065088, + "instance_id": "01e84e9e9e38", + "delta_rx_bytes": 1803498, + "delta_tx_bytes": 194370, + "baseline_rss_bytes": 189468672, "peak_memory_bytes": { - "rss": 210079744, - "heap_used": 59538608, - "external": 12156543, - "array_buffers": 8366167 + "rss": 189861888, + "heap_used": 59295328, + "external": 6363945, + "array_buffers": 2573569 }, - "delta_rss_bytes": 3014656, + "delta_rss_bytes": 393216, "counters": { - "attachments.count_pending_direct": 24, - "attachments.insert_pending": 24, - "attachments.direct.initiated": 24, - "attachments.find_for_complete": 26, - "attachments.direct.verify_bytes": 553814, - "attachments.mark_ready": 26, - "attachments.direct.completed": 26 + "attachments.count_pending_direct": 25, + "attachments.insert_pending": 25, + "attachments.direct.initiated": 25, + "attachments.find_for_complete": 25, + "attachments.direct.verify_bytes": 1638400, + "attachments.mark_ready": 25, + "attachments.direct.completed": 25 } }, { - "instance_id": "fc61f806b880", - "delta_rx_bytes": 2100305, - "delta_tx_bytes": 201255, - "baseline_rss_bytes": 205152256, + "instance_id": "d49b799653d6", + "delta_rx_bytes": 1804525, + "delta_tx_bytes": 194742, + "baseline_rss_bytes": 179740672, "peak_memory_bytes": { - "rss": 208429056, - "heap_used": 59913256, - "external": 9769093, - "array_buffers": 5978717 + "rss": 179740672, + "heap_used": 59420128, + "external": 6260844, + "array_buffers": 2470500 }, - "delta_rss_bytes": 3276800, + "delta_rss_bytes": 0, "counters": { - "attachments.count_pending_direct": 26, - "attachments.insert_pending": 26, - "attachments.direct.initiated": 26, - "attachments.find_for_complete": 24, - "attachments.direct.verify_bytes": 258704, - "attachments.mark_ready": 24, - "attachments.direct.completed": 24 + "attachments.count_pending_direct": 25, + "attachments.insert_pending": 25, + "attachments.direct.initiated": 25, + "attachments.find_for_complete": 25, + "attachments.direct.verify_bytes": 1638400, + "attachments.mark_ready": 25, + "attachments.direct.completed": 25 } } ], - "total_delta_rx_bytes": 5526470, - "total_delta_tx_bytes": 406588, - "rx_bytes_per_upload": 110529, - "tx_bytes_per_upload": 8132, - "max_delta_rss_bytes": 3276800 + "total_delta_rx_bytes": 3608023, + "total_delta_tx_bytes": 389112, + "rx_bytes_per_upload": 72160, + "tx_bytes_per_upload": 7782, + "max_delta_rss_bytes": 393216 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 3.128, + "duration_s": 2.556, "latency_ms": { - "p50": 376.7, - "p95": 483.1, - "p99": 546.2 + "p50": 314.1, + "p95": 425.2, + "p99": 453.1 }, "replicas": [ { - "instance_id": "b50bb8514a7b", - "delta_rx_bytes": 3752711, - "delta_tx_bytes": 204356, - "baseline_rss_bytes": 207192064, + "instance_id": "01e84e9e9e38", + "delta_rx_bytes": 1531515, + "delta_tx_bytes": 190497, + "baseline_rss_bytes": 189861888, "peak_memory_bytes": { - "rss": 207192064, - "heap_used": 59773496, - "external": 12099081, - "array_buffers": 8308705 + "rss": 190910464, + "heap_used": 60034376, + "external": 6373249, + "array_buffers": 2582873 }, - "delta_rss_bytes": 0, + "delta_rss_bytes": 1048576, "counters": { - "attachments.claim_expired": 1, - "attachments.count_pending_direct": 24, - "attachments.insert_pending": 24, - "attachments.direct.initiated": 24, - "attachments.find_for_complete": 26, - "attachments.direct.verify_bytes": 458246, - "attachments.mark_ready": 26, - "attachments.direct.completed": 26 + "attachments.count_pending_direct": 29, + "attachments.insert_pending": 29, + "attachments.direct.initiated": 29, + "attachments.find_for_complete": 21, + "attachments.direct.verify_bytes": 1376256, + "attachments.mark_ready": 21, + "attachments.direct.completed": 21 } }, { - "instance_id": "fc61f806b880", - "delta_rx_bytes": 3511316, - "delta_tx_bytes": 203010, - "baseline_rss_bytes": 205549568, + "instance_id": "d49b799653d6", + "delta_rx_bytes": 2076238, + "delta_tx_bytes": 196531, + "baseline_rss_bytes": 179740672, "peak_memory_bytes": { - "rss": 205549568, - "heap_used": 59832920, - "external": 10075786, - "array_buffers": 6285218 + "rss": 179740672, + "heap_used": 59642168, + "external": 6672708, + "array_buffers": 2755498 }, "delta_rss_bytes": 0, "counters": { - "attachments.count_pending_direct": 26, - "attachments.insert_pending": 26, - "attachments.direct.initiated": 26, - "attachments.find_for_complete": 24, - "attachments.direct.verify_bytes": 477352, - "attachments.mark_ready": 24, - "attachments.direct.completed": 24 + "attachments.count_pending_direct": 21, + "attachments.insert_pending": 21, + "attachments.direct.initiated": 21, + "attachments.find_for_complete": 29, + "attachments.direct.verify_bytes": 1900544, + "attachments.mark_ready": 29, + "attachments.direct.completed": 29 } } ], - "total_delta_rx_bytes": 7264027, - "total_delta_tx_bytes": 407366, - "rx_bytes_per_upload": 145281, - "tx_bytes_per_upload": 8147, - "max_delta_rss_bytes": 0 + "total_delta_rx_bytes": 3607753, + "total_delta_tx_bytes": 387028, + "rx_bytes_per_upload": 72155, + "tx_bytes_per_upload": 7741, + "max_delta_rss_bytes": 1048576 } ] } diff --git a/evidence/lab4/bench/proxy-1048576-c10.json b/evidence/lab4/bench/proxy-1048576-c10.json index 5df735eb..603094f6 100644 --- a/evidence/lab4/bench/proxy-1048576-c10.json +++ b/evidence/lab4/bench/proxy-1048576-c10.json @@ -1,6 +1,6 @@ { - "date": "2026-10-22T19:43:32+00:00", - "git": "39a6df8", + "date": "2026-10-22T20:02:15+00:00", + "git": "f048a37", "params": { "mode": "proxy", "size_bytes": 1048576, @@ -21,25 +21,25 @@ "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.391, + "duration_s": 0.369, "latency_ms": { - "p50": 44.5, - "p95": 80.1, - "p99": 85.9 + "p50": 46.4, + "p95": 68.3, + "p99": 72.8 }, "replicas": [ { - "instance_id": "b50bb8514a7b", - "delta_rx_bytes": 26377008, - "delta_tx_bytes": 26400949, - "baseline_rss_bytes": 185679872, + "instance_id": "01e84e9e9e38", + "delta_rx_bytes": 26390991, + "delta_tx_bytes": 26399463, + "baseline_rss_bytes": 183496704, "peak_memory_bytes": { - "rss": 191053824, - "heap_used": 54312648, - "external": 18076371, - "array_buffers": 14283909 + "rss": 188407808, + "heap_used": 58350032, + "external": 15612927, + "array_buffers": 11820465 }, - "delta_rss_bytes": 5373952, + "delta_rss_bytes": 4911104, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, @@ -49,17 +49,17 @@ } }, { - "instance_id": "fc61f806b880", - "delta_rx_bytes": 26381521, - "delta_tx_bytes": 26398219, - "baseline_rss_bytes": 183795712, + "instance_id": "d49b799653d6", + "delta_rx_bytes": 26389902, + "delta_tx_bytes": 26401063, + "baseline_rss_bytes": 172593152, "peak_memory_bytes": { - "rss": 187359232, - "heap_used": 62541304, - "external": 18146585, - "array_buffers": 9966050 + "rss": 179159040, + "heap_used": 51726640, + "external": 10983870, + "array_buffers": 7191408 }, - "delta_rss_bytes": 3563520, + "delta_rss_bytes": 6565888, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, @@ -69,35 +69,35 @@ } } ], - "total_delta_rx_bytes": 52758529, - "total_delta_tx_bytes": 52799168, - "rx_bytes_per_upload": 1055171, - "tx_bytes_per_upload": 1055983, - "max_delta_rss_bytes": 5373952 + "total_delta_rx_bytes": 52780893, + "total_delta_tx_bytes": 52800526, + "rx_bytes_per_upload": 1055618, + "tx_bytes_per_upload": 1056011, + "max_delta_rss_bytes": 6565888 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.387, + "duration_s": 0.55, "latency_ms": { - "p50": 47.1, - "p95": 78.9, - "p99": 92.5 + "p50": 59.3, + "p95": 210.6, + "p99": 226.6 }, "replicas": [ { - "instance_id": "b50bb8514a7b", - "delta_rx_bytes": 26389036, - "delta_tx_bytes": 26402274, - "baseline_rss_bytes": 191053824, + "instance_id": "01e84e9e9e38", + "delta_rx_bytes": 26377432, + "delta_tx_bytes": 26403430, + "baseline_rss_bytes": 188645376, "peak_memory_bytes": { - "rss": 196558848, - "heap_used": 56457808, - "external": 23809883, - "array_buffers": 20017421 + "rss": 193232896, + "heap_used": 52490432, + "external": 19098493, + "array_buffers": 15306617 }, - "delta_rss_bytes": 5505024, + "delta_rss_bytes": 4587520, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, @@ -107,17 +107,17 @@ } }, { - "instance_id": "fc61f806b880", - "delta_rx_bytes": 26383409, - "delta_tx_bytes": 26401615, - "baseline_rss_bytes": 187490304, + "instance_id": "d49b799653d6", + "delta_rx_bytes": 26383216, + "delta_tx_bytes": 26401660, + "baseline_rss_bytes": 179159040, "peak_memory_bytes": { - "rss": 187490304, - "heap_used": 49941720, - "external": 17342677, - "array_buffers": 13550957 + "rss": 179486720, + "heap_used": 49462912, + "external": 15506324, + "array_buffers": 11714604 }, - "delta_rss_bytes": 0, + "delta_rss_bytes": 327680, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, @@ -127,35 +127,35 @@ } } ], - "total_delta_rx_bytes": 52772445, - "total_delta_tx_bytes": 52803889, - "rx_bytes_per_upload": 1055449, - "tx_bytes_per_upload": 1056078, - "max_delta_rss_bytes": 5505024 + "total_delta_rx_bytes": 52760648, + "total_delta_tx_bytes": 52805090, + "rx_bytes_per_upload": 1055213, + "tx_bytes_per_upload": 1056102, + "max_delta_rss_bytes": 4587520 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.361, + "duration_s": 0.461, "latency_ms": { - "p50": 42.5, - "p95": 64.3, - "p99": 77.5 + "p50": 67.3, + "p95": 109.8, + "p99": 118.7 }, "replicas": [ { - "instance_id": "b50bb8514a7b", - "delta_rx_bytes": 26387499, - "delta_tx_bytes": 26400516, - "baseline_rss_bytes": 195969024, + "instance_id": "01e84e9e9e38", + "delta_rx_bytes": 26385813, + "delta_tx_bytes": 26399597, + "baseline_rss_bytes": 193232896, "peak_memory_bytes": { - "rss": 197935104, - "heap_used": 51834416, - "external": 25755964, - "array_buffers": 16217341 + "rss": 194363392, + "heap_used": 51280880, + "external": 19455489, + "array_buffers": 15663613 }, - "delta_rss_bytes": 1966080, + "delta_rss_bytes": 1130496, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, @@ -165,17 +165,17 @@ } }, { - "instance_id": "fc61f806b880", - "delta_rx_bytes": 26383525, - "delta_tx_bytes": 26400510, - "baseline_rss_bytes": 185294848, + "instance_id": "d49b799653d6", + "delta_rx_bytes": 26391095, + "delta_tx_bytes": 26404143, + "baseline_rss_bytes": 178298880, "peak_memory_bytes": { - "rss": 187260928, - "heap_used": 49345096, - "external": 15398018, - "array_buffers": 11607674 + "rss": 181444608, + "heap_used": 50462384, + "external": 17515725, + "array_buffers": 13659712 }, - "delta_rss_bytes": 1966080, + "delta_rss_bytes": 3145728, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, @@ -185,11 +185,11 @@ } } ], - "total_delta_rx_bytes": 52771024, - "total_delta_tx_bytes": 52801026, - "rx_bytes_per_upload": 1055420, - "tx_bytes_per_upload": 1056021, - "max_delta_rss_bytes": 1966080 + "total_delta_rx_bytes": 52776908, + "total_delta_tx_bytes": 52803740, + "rx_bytes_per_upload": 1055538, + "tx_bytes_per_upload": 1056075, + "max_delta_rss_bytes": 3145728 } ] } diff --git a/evidence/lab4/bench/proxy-131072-c10.json b/evidence/lab4/bench/proxy-131072-c10.json index 3c4f9adf..9b85fd70 100644 --- a/evidence/lab4/bench/proxy-131072-c10.json +++ b/evidence/lab4/bench/proxy-131072-c10.json @@ -1,6 +1,6 @@ { - "date": "2026-10-22T19:43:22+00:00", - "git": "39a6df8", + "date": "2026-10-22T20:02:04+00:00", + "git": "f048a37", "params": { "mode": "proxy", "size_bytes": 131072, @@ -21,25 +21,25 @@ "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.203, + "duration_s": 0.221, "latency_ms": { - "p50": 32.4, - "p95": 56.7, - "p99": 62.2 + "p50": 32.5, + "p95": 61.7, + "p99": 75.6 }, "replicas": [ { - "instance_id": "b50bb8514a7b", - "delta_rx_bytes": 3381217, - "delta_tx_bytes": 3397557, - "baseline_rss_bytes": 171487232, + "instance_id": "01e84e9e9e38", + "delta_rx_bytes": 3382582, + "delta_tx_bytes": 3398177, + "baseline_rss_bytes": 172421120, "peak_memory_bytes": { - "rss": 177647616, - "heap_used": 58529080, - "external": 7415675, - "array_buffers": 3621869 + "rss": 177926144, + "heap_used": 50033192, + "external": 7706616, + "array_buffers": 3914122 }, - "delta_rss_bytes": 6160384, + "delta_rss_bytes": 5505024, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, @@ -49,17 +49,17 @@ } }, { - "instance_id": "fc61f806b880", - "delta_rx_bytes": 3382121, - "delta_tx_bytes": 3397761, - "baseline_rss_bytes": 169697280, + "instance_id": "d49b799653d6", + "delta_rx_bytes": 3380734, + "delta_tx_bytes": 3397755, + "baseline_rss_bytes": 164986880, "peak_memory_bytes": { - "rss": 176513024, - "heap_used": 56215752, - "external": 6720398, - "array_buffers": 2926784 + "rss": 170360832, + "heap_used": 49897896, + "external": 7704663, + "array_buffers": 3911977 }, - "delta_rss_bytes": 6815744, + "delta_rss_bytes": 5373952, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, @@ -69,35 +69,35 @@ } } ], - "total_delta_rx_bytes": 6763338, - "total_delta_tx_bytes": 6795318, - "rx_bytes_per_upload": 135267, - "tx_bytes_per_upload": 135906, - "max_delta_rss_bytes": 6815744 + "total_delta_rx_bytes": 6763316, + "total_delta_tx_bytes": 6795932, + "rx_bytes_per_upload": 135266, + "tx_bytes_per_upload": 135919, + "max_delta_rss_bytes": 5505024 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.147, + "duration_s": 0.178, "latency_ms": { - "p50": 24.3, - "p95": 37.7, - "p99": 48.6 + "p50": 30.3, + "p95": 39.9, + "p99": 40.8 }, "replicas": [ { - "instance_id": "b50bb8514a7b", - "delta_rx_bytes": 3376685, - "delta_tx_bytes": 3395659, - "baseline_rss_bytes": 177647616, + "instance_id": "01e84e9e9e38", + "delta_rx_bytes": 3378937, + "delta_tx_bytes": 3395467, + "baseline_rss_bytes": 177926144, "peak_memory_bytes": { - "rss": 181579776, - "heap_used": 58637216, - "external": 10920677, - "array_buffers": 7128215 + "rss": 181886976, + "heap_used": 51028472, + "external": 10337544, + "array_buffers": 6545050 }, - "delta_rss_bytes": 3932160, + "delta_rss_bytes": 3960832, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, @@ -107,17 +107,17 @@ } }, { - "instance_id": "fc61f806b880", - "delta_rx_bytes": 3378833, - "delta_tx_bytes": 3397177, - "baseline_rss_bytes": 176250880, + "instance_id": "d49b799653d6", + "delta_rx_bytes": 3380009, + "delta_tx_bytes": 3397063, + "baseline_rss_bytes": 170360832, "peak_memory_bytes": { - "rss": 179134464, - "heap_used": 60877184, - "external": 11462611, - "array_buffers": 7669957 + "rss": 171278336, + "heap_used": 50939136, + "external": 8430160, + "array_buffers": 4637666 }, - "delta_rss_bytes": 2883584, + "delta_rss_bytes": 917504, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, @@ -127,35 +127,35 @@ } } ], - "total_delta_rx_bytes": 6755518, - "total_delta_tx_bytes": 6792836, - "rx_bytes_per_upload": 135110, - "tx_bytes_per_upload": 135857, - "max_delta_rss_bytes": 3932160 + "total_delta_rx_bytes": 6758946, + "total_delta_tx_bytes": 6792530, + "rx_bytes_per_upload": 135179, + "tx_bytes_per_upload": 135851, + "max_delta_rss_bytes": 3960832 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.161, + "duration_s": 0.291, "latency_ms": { - "p50": 26.4, - "p95": 52.8, - "p99": 56.1 + "p50": 41.2, + "p95": 87.2, + "p99": 93.6 }, "replicas": [ { - "instance_id": "b50bb8514a7b", - "delta_rx_bytes": 3377664, - "delta_tx_bytes": 3397060, - "baseline_rss_bytes": 181579776, + "instance_id": "01e84e9e9e38", + "delta_rx_bytes": 3377137, + "delta_tx_bytes": 3395161, + "baseline_rss_bytes": 181886976, "peak_memory_bytes": { - "rss": 182104064, - "heap_used": 56837496, - "external": 12815773, - "array_buffers": 9023311 + "rss": 182149120, + "heap_used": 51984832, + "external": 9554628, + "array_buffers": 5762166 }, - "delta_rss_bytes": 524288, + "delta_rss_bytes": 262144, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, @@ -165,17 +165,17 @@ } }, { - "instance_id": "fc61f806b880", - "delta_rx_bytes": 3375364, - "delta_tx_bytes": 3395107, - "baseline_rss_bytes": 179134464, + "instance_id": "d49b799653d6", + "delta_rx_bytes": 3377713, + "delta_tx_bytes": 3396473, + "baseline_rss_bytes": 171278336, "peak_memory_bytes": { - "rss": 182018048, - "heap_used": 61048680, - "external": 12510518, - "array_buffers": 8718024 + "rss": 173244416, + "heap_used": 52256384, + "external": 10276505, + "array_buffers": 6484011 }, - "delta_rss_bytes": 2883584, + "delta_rss_bytes": 1966080, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, @@ -185,11 +185,11 @@ } } ], - "total_delta_rx_bytes": 6753028, - "total_delta_tx_bytes": 6792167, - "rx_bytes_per_upload": 135061, - "tx_bytes_per_upload": 135843, - "max_delta_rss_bytes": 2883584 + "total_delta_rx_bytes": 6754850, + "total_delta_tx_bytes": 6791634, + "rx_bytes_per_upload": 135097, + "tx_bytes_per_upload": 135833, + "max_delta_rss_bytes": 1966080 } ] } diff --git a/evidence/lab4/bench/proxy-9961472-c10.json b/evidence/lab4/bench/proxy-9961472-c10.json index be1fe8fc..39652201 100644 --- a/evidence/lab4/bench/proxy-9961472-c10.json +++ b/evidence/lab4/bench/proxy-9961472-c10.json @@ -1,6 +1,6 @@ { - "date": "2026-10-22T19:43:49+00:00", - "git": "39a6df8", + "date": "2026-10-22T20:02:34+00:00", + "git": "f048a37", "params": { "mode": "proxy", "size_bytes": 9961472, @@ -21,25 +21,25 @@ "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 2.888, + "duration_s": 2.923, "latency_ms": { - "p50": 212.3, - "p95": 379.1, - "p99": 447.0 + "p50": 217.7, + "p95": 393.7, + "p99": 469.2 }, "replicas": [ { - "instance_id": "b50bb8514a7b", - "delta_rx_bytes": 249726853, - "delta_tx_bytes": 249832292, - "baseline_rss_bytes": 201834496, + "instance_id": "01e84e9e9e38", + "delta_rx_bytes": 249719999, + "delta_tx_bytes": 249864966, + "baseline_rss_bytes": 193277952, "peak_memory_bytes": { - "rss": 207208448, - "heap_used": 48318768, - "external": 33637892, - "array_buffers": 24213167 + "rss": 208244736, + "heap_used": 49103680, + "external": 38092148, + "array_buffers": 31938886 }, - "delta_rss_bytes": 5373952, + "delta_rss_bytes": 14966784, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, @@ -49,17 +49,17 @@ } }, { - "instance_id": "fc61f806b880", - "delta_rx_bytes": 249652918, - "delta_tx_bytes": 249806626, - "baseline_rss_bytes": 194772992, + "instance_id": "d49b799653d6", + "delta_rx_bytes": 249670108, + "delta_tx_bytes": 249826185, + "baseline_rss_bytes": 178913280, "peak_memory_bytes": { - "rss": 208158720, - "heap_used": 48256584, - "external": 27701797, - "array_buffers": 23911453 + "rss": 195375104, + "heap_used": 48823672, + "external": 30056217, + "array_buffers": 26265873 }, - "delta_rss_bytes": 13385728, + "delta_rss_bytes": 16461824, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, @@ -69,57 +69,59 @@ } } ], - "total_delta_rx_bytes": 499379771, - "total_delta_tx_bytes": 499638918, - "rx_bytes_per_upload": 9987595, - "tx_bytes_per_upload": 9992778, - "max_delta_rss_bytes": 13385728 + "total_delta_rx_bytes": 499390107, + "total_delta_tx_bytes": 499691151, + "rx_bytes_per_upload": 9987802, + "tx_bytes_per_upload": 9993823, + "max_delta_rss_bytes": 16461824 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 2.74, + "duration_s": 3.32, "latency_ms": { - "p50": 188.3, - "p95": 357.0, - "p99": 439.5 + "p50": 277.4, + "p95": 513.9, + "p99": 548.1 }, "replicas": [ { - "instance_id": "b50bb8514a7b", - "delta_rx_bytes": 249720677, - "delta_tx_bytes": 249833753, - "baseline_rss_bytes": 198889472, + "instance_id": "01e84e9e9e38", + "delta_rx_bytes": 249653538, + "delta_tx_bytes": 249812864, + "baseline_rss_bytes": 193380352, "peak_memory_bytes": { - "rss": 207929344, - "heap_used": 48141072, - "external": 34434837, - "array_buffers": 24758541 + "rss": 208535552, + "heap_used": 49665920, + "external": 36105007, + "array_buffers": 32313340 }, - "delta_rss_bytes": 9039872, + "delta_rss_bytes": 15155200, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, + "attachments.claim_expired": 1, "attachments.proxy.bytes_to_s3": 249036800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } }, { - "instance_id": "fc61f806b880", - "delta_rx_bytes": 249698838, - "delta_tx_bytes": 249844044, - "baseline_rss_bytes": 195190784, + "instance_id": "d49b799653d6", + "delta_rx_bytes": 249644423, + "delta_tx_bytes": 249817785, + "baseline_rss_bytes": 194199552, "peak_memory_bytes": { - "rss": 202661888, - "heap_used": 48064416, - "external": 26063110, - "array_buffers": 21189095 + "rss": 208871424, + "heap_used": 50742312, + "external": 43475182, + "array_buffers": 39684838 }, - "delta_rss_bytes": 7471104, + "delta_rss_bytes": 14671872, "counters": { "attachments.insert_pending": 25, + "attachments.claim_expired": 1, "attachments.proxy.bytes_in": 249036800, "attachments.proxy.bytes_to_s3": 249036800, "attachments.mark_ready": 25, @@ -127,35 +129,35 @@ } } ], - "total_delta_rx_bytes": 499419515, - "total_delta_tx_bytes": 499677797, - "rx_bytes_per_upload": 9988390, - "tx_bytes_per_upload": 9993556, - "max_delta_rss_bytes": 9039872 + "total_delta_rx_bytes": 499297961, + "total_delta_tx_bytes": 499630649, + "rx_bytes_per_upload": 9985959, + "tx_bytes_per_upload": 9992613, + "max_delta_rss_bytes": 15155200 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 2.786, + "duration_s": 3.07, "latency_ms": { - "p50": 226.6, - "p95": 373.9, - "p99": 483.8 + "p50": 238.9, + "p95": 391.0, + "p99": 423.1 }, "replicas": [ { - "instance_id": "b50bb8514a7b", - "delta_rx_bytes": 249712459, - "delta_tx_bytes": 249847251, - "baseline_rss_bytes": 199180288, + "instance_id": "01e84e9e9e38", + "delta_rx_bytes": 249690323, + "delta_tx_bytes": 249843279, + "baseline_rss_bytes": 193445888, "peak_memory_bytes": { - "rss": 207888384, - "heap_used": 48883976, - "external": 33646702, - "array_buffers": 29856358 + "rss": 212447232, + "heap_used": 48981896, + "external": 28322088, + "array_buffers": 24531744 }, - "delta_rss_bytes": 8708096, + "delta_rss_bytes": 19001344, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, @@ -165,17 +167,17 @@ } }, { - "instance_id": "fc61f806b880", - "delta_rx_bytes": 249713568, - "delta_tx_bytes": 249832760, - "baseline_rss_bytes": 193859584, + "instance_id": "d49b799653d6", + "delta_rx_bytes": 249684428, + "delta_tx_bytes": 249830235, + "baseline_rss_bytes": 200146944, "peak_memory_bytes": { - "rss": 205029376, - "heap_used": 49053528, - "external": 28839619, - "array_buffers": 25049275 + "rss": 200146944, + "heap_used": 48496592, + "external": 26712221, + "array_buffers": 22921877 }, - "delta_rss_bytes": 11169792, + "delta_rss_bytes": 0, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, @@ -185,11 +187,11 @@ } } ], - "total_delta_rx_bytes": 499426027, - "total_delta_tx_bytes": 499680011, - "rx_bytes_per_upload": 9988521, - "tx_bytes_per_upload": 9993600, - "max_delta_rss_bytes": 11169792 + "total_delta_rx_bytes": 499374751, + "total_delta_tx_bytes": 499673514, + "rx_bytes_per_upload": 9987495, + "tx_bytes_per_upload": 9993470, + "max_delta_rss_bytes": 19001344 } ] } diff --git a/evidence/lab4/bench/proxy-9961472-c20.json b/evidence/lab4/bench/proxy-9961472-c20.json index 3d2ba65c..c5299ab1 100644 --- a/evidence/lab4/bench/proxy-9961472-c20.json +++ b/evidence/lab4/bench/proxy-9961472-c20.json @@ -1,6 +1,6 @@ { - "date": "2026-10-22T19:44:24+00:00", - "git": "39a6df8", + "date": "2026-10-22T20:03:09+00:00", + "git": "f048a37", "params": { "mode": "proxy", "size_bytes": 9961472, @@ -21,25 +21,25 @@ "uploads": 100, "succeeded": 100, "failed": 0, - "duration_s": 6.29, + "duration_s": 5.789, "latency_ms": { - "p50": 424.1, - "p95": 796.0, - "p99": 937.9 + "p50": 409.2, + "p95": 812.5, + "p99": 959.0 }, "replicas": [ { - "instance_id": "b50bb8514a7b", - "delta_rx_bytes": 499638310, - "delta_tx_bytes": 499870304, - "baseline_rss_bytes": 192036864, + "instance_id": "01e84e9e9e38", + "delta_rx_bytes": 499859990, + "delta_tx_bytes": 500110302, + "baseline_rss_bytes": 189095936, "peak_memory_bytes": { - "rss": 210829312, - "heap_used": 49626176, - "external": 34069726, - "array_buffers": 30279382 + "rss": 209506304, + "heap_used": 49551104, + "external": 37459480, + "array_buffers": 28998398 }, - "delta_rss_bytes": 18792448, + "delta_rss_bytes": 20410368, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, @@ -49,56 +49,55 @@ } }, { - "instance_id": "fc61f806b880", - "delta_rx_bytes": 499750187, - "delta_tx_bytes": 500007552, - "baseline_rss_bytes": 194543616, + "instance_id": "d49b799653d6", + "delta_rx_bytes": 499688844, + "delta_tx_bytes": 499961376, + "baseline_rss_bytes": 179896320, "peak_memory_bytes": { - "rss": 210604032, - "heap_used": 48759736, - "external": 32187556, - "array_buffers": 28397212 + "rss": 201883648, + "heap_used": 48903104, + "external": 30171785, + "array_buffers": 23259151 }, - "delta_rss_bytes": 16060416, + "delta_rss_bytes": 21987328, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, "attachments.proxy.bytes_to_s3": 498073600, "attachments.mark_ready": 50, - "attachments.upload.created": 50, - "attachments.claim_expired": 1 + "attachments.upload.created": 50 } } ], - "total_delta_rx_bytes": 999388497, - "total_delta_tx_bytes": 999877856, - "rx_bytes_per_upload": 9993885, - "tx_bytes_per_upload": 9998779, - "max_delta_rss_bytes": 18792448 + "total_delta_rx_bytes": 999548834, + "total_delta_tx_bytes": 1000071678, + "rx_bytes_per_upload": 9995488, + "tx_bytes_per_upload": 10000717, + "max_delta_rss_bytes": 21987328 }, { "uploads": 100, "succeeded": 100, "failed": 0, - "duration_s": 5.824, + "duration_s": 5.789, "latency_ms": { - "p50": 403.2, - "p95": 802.4, - "p99": 987.2 + "p50": 406.7, + "p95": 756.8, + "p99": 1110.8 }, "replicas": [ { - "instance_id": "b50bb8514a7b", - "delta_rx_bytes": 499452630, - "delta_tx_bytes": 499737912, - "baseline_rss_bytes": 197160960, + "instance_id": "01e84e9e9e38", + "delta_rx_bytes": 499409660, + "delta_tx_bytes": 499704231, + "baseline_rss_bytes": 204034048, "peak_memory_bytes": { - "rss": 223768576, - "heap_used": 50330816, - "external": 46988209, - "array_buffers": 43197865 + "rss": 216682496, + "heap_used": 50958080, + "external": 42044393, + "array_buffers": 38254049 }, - "delta_rss_bytes": 26607616, + "delta_rss_bytes": 12648448, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, @@ -108,17 +107,17 @@ } }, { - "instance_id": "fc61f806b880", - "delta_rx_bytes": 499486574, - "delta_tx_bytes": 499756038, - "baseline_rss_bytes": 197701632, + "instance_id": "d49b799653d6", + "delta_rx_bytes": 499385236, + "delta_tx_bytes": 499657364, + "baseline_rss_bytes": 196177920, "peak_memory_bytes": { - "rss": 215396352, - "heap_used": 49478224, - "external": 43102012, - "array_buffers": 30263688 + "rss": 208781312, + "heap_used": 49416712, + "external": 29886702, + "array_buffers": 26096358 }, - "delta_rss_bytes": 17694720, + "delta_rss_bytes": 12603392, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, @@ -128,35 +127,35 @@ } } ], - "total_delta_rx_bytes": 998939204, - "total_delta_tx_bytes": 999493950, - "rx_bytes_per_upload": 9989392, - "tx_bytes_per_upload": 9994940, - "max_delta_rss_bytes": 26607616 + "total_delta_rx_bytes": 998794896, + "total_delta_tx_bytes": 999361595, + "rx_bytes_per_upload": 9987949, + "tx_bytes_per_upload": 9993616, + "max_delta_rss_bytes": 12648448 }, { "uploads": 100, "succeeded": 100, "failed": 0, - "duration_s": 5.757, + "duration_s": 6.222, "latency_ms": { - "p50": 413.8, - "p95": 866.6, - "p99": 1090.4 + "p50": 452.3, + "p95": 913.7, + "p99": 1284.1 }, "replicas": [ { - "instance_id": "b50bb8514a7b", - "delta_rx_bytes": 499421823, - "delta_tx_bytes": 499732729, - "baseline_rss_bytes": 195944448, + "instance_id": "01e84e9e9e38", + "delta_rx_bytes": 499462554, + "delta_tx_bytes": 499707805, + "baseline_rss_bytes": 208515072, "peak_memory_bytes": { - "rss": 214212608, - "heap_used": 50078520, - "external": 38151413, - "array_buffers": 34361069 + "rss": 213237760, + "heap_used": 50201400, + "external": 39684000, + "array_buffers": 35893464 }, - "delta_rss_bytes": 18268160, + "delta_rss_bytes": 4722688, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, @@ -166,17 +165,17 @@ } }, { - "instance_id": "fc61f806b880", - "delta_rx_bytes": 499373397, - "delta_tx_bytes": 499664859, - "baseline_rss_bytes": 196259840, + "instance_id": "d49b799653d6", + "delta_rx_bytes": 499435292, + "delta_tx_bytes": 499704897, + "baseline_rss_bytes": 192315392, "peak_memory_bytes": { - "rss": 207290368, - "heap_used": 49133976, - "external": 31644969, - "array_buffers": 27854625 + "rss": 209580032, + "heap_used": 50343440, + "external": 38677040, + "array_buffers": 34886696 }, - "delta_rss_bytes": 11030528, + "delta_rss_bytes": 17264640, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, @@ -186,11 +185,11 @@ } } ], - "total_delta_rx_bytes": 998795220, - "total_delta_tx_bytes": 999397588, - "rx_bytes_per_upload": 9987952, - "tx_bytes_per_upload": 9993976, - "max_delta_rss_bytes": 18268160 + "total_delta_rx_bytes": 998897846, + "total_delta_tx_bytes": 999412702, + "rx_bytes_per_upload": 9988978, + "tx_bytes_per_upload": 9994127, + "max_delta_rss_bytes": 17264640 } ] } diff --git a/evidence/lab4/consistency.txt b/evidence/lab4/consistency.txt index 0b8c1b25..b2f9c3e2 100644 --- a/evidence/lab4/consistency.txt +++ b/evidence/lab4/consistency.txt @@ -1,8 +1,9 @@ scripts/lab4/consistency_check.sh bucket: messenger-attachments -objects: 1308 +objects: 2580 rows by status: - 11 pending - 1308 ready + 33 pending + 2577 ready + 6 rejected orphans: 0 missing: 0 diff --git a/evidence/lab4/direct-ttl-short.txt b/evidence/lab4/direct-ttl-short.txt index 09d52f88..f9afeee9 100644 --- a/evidence/lab4/direct-ttl-short.txt +++ b/evidence/lab4/direct-ttl-short.txt @@ -4,5 +4,5 @@ The plugin "vite-tsconfig-paths" is detected. Vite now supports tsconfig paths r RUN v4.1.11 /home/tomato/Projects/VP/mtusi2026lab4/app Test Files 1 passed (1) Tests 7 passed (7) - Start at 22:45:08 - Duration 8.14s (transform 44ms, setup 0ms, import 75ms, tests 7.94s, environment 0ms) + Start at 23:00:12 + Duration 8.41s (transform 64ms, setup 0ms, import 94ms, tests 8.16s, environment 0ms) diff --git a/evidence/lab4/make-test-dependencies.txt b/evidence/lab4/make-test-dependencies.txt index 2e2dd11e..36cd7ceb 100644 --- a/evidence/lab4/make-test-dependencies.txt +++ b/evidence/lab4/make-test-dependencies.txt @@ -5,5 +5,5 @@ The plugin "vite-tsconfig-paths" is detected. Vite now supports tsconfig paths r RUN v4.1.11 /home/tomato/Projects/VP/mtusi2026lab4/app Test Files 1 passed (1) Tests 6 passed (6) - Start at 22:45:26 - Duration 89.83s (transform 52ms, setup 0ms, import 69ms, tests 89.66s, environment 0ms) + Start at 23:00:31 + Duration 88.83s (transform 48ms, setup 0ms, import 73ms, tests 88.65s, environment 0ms) diff --git a/evidence/lab4/make-test-e2e.txt b/evidence/lab4/make-test-e2e.txt index ecaf8051..433cb5a7 100644 --- a/evidence/lab4/make-test-e2e.txt +++ b/evidence/lab4/make-test-e2e.txt @@ -3,6 +3,6 @@ The plugin "vite-tsconfig-paths" is detected. Vite now supports tsconfig paths resolution natively via the resolve.tsconfigPaths option. You can remove the plugin and set resolve.tsconfigPaths: true in your Vite config instead. RUN v4.1.11 /home/tomato/Projects/VP/mtusi2026lab4/app Test Files 3 passed | 1 skipped (4) - Tests 33 passed | 8 skipped (41) - Start at 22:44:49 - Duration 3.73s (transform 239ms, setup 0ms, import 536ms, tests 7.77s, environment 0ms) + Tests 34 passed | 8 skipped (42) + Start at 22:59:53 + Duration 4.87s (transform 409ms, setup 0ms, import 764ms, tests 9.39s, environment 0ms) diff --git a/evidence/lab4/summary.md b/evidence/lab4/summary.md index eb63419d..f7408851 100644 --- a/evidence/lab4/summary.md +++ b/evidence/lab4/summary.md @@ -1,9 +1,9 @@ | mode | size, MiB | C | ok | API rx/upload, MiB | API tx/upload, MiB | max Δrss, MiB | p50, ms | p95, ms | |---|---|---|---|---|---|---|---|---| -| direct | 0.12 | 10 | 150/150 | 0.13 | 0.01 | 0.62 | 42 | 62 | -| proxy | 0.12 | 10 | 150/150 | 0.13 | 0.13 | 3.75 | 26 | 53 | -| direct | 1.00 | 10 | 150/150 | 1.01 | 0.01 | 3.88 | 69 | 100 | -| proxy | 1.00 | 10 | 150/150 | 1.01 | 1.01 | 5.12 | 44 | 79 | -| direct | 9.50 | 10 | 150/150 | 0.14 | 0.01 | 0.25 | 377 | 493 | -| proxy | 9.50 | 10 | 150/150 | 9.53 | 9.53 | 10.65 | 212 | 374 | -| proxy | 9.50 | 20 | 300/300 | 9.53 | 9.53 | 17.92 | 414 | 802 | +| direct | 0.12 | 10 | 150/150 | 0.07 | 0.01 | 0.40 | 45 | 65 | +| proxy | 0.12 | 10 | 150/150 | 0.13 | 0.13 | 3.78 | 32 | 62 | +| direct | 1.00 | 10 | 150/150 | 0.07 | 0.01 | 0.75 | 75 | 137 | +| proxy | 1.00 | 10 | 150/150 | 1.01 | 1.01 | 4.38 | 59 | 110 | +| direct | 9.50 | 10 | 150/150 | 0.07 | 0.01 | 0.88 | 346 | 571 | +| proxy | 9.50 | 10 | 150/150 | 9.52 | 9.53 | 15.70 | 239 | 394 | +| proxy | 9.50 | 20 | 300/300 | 9.53 | 9.53 | 16.46 | 409 | 812 | -- 2.54.0 From b32ce9a75deb8f4e68e8472b9d9be0d2af3ca9f8 Mon Sep 17 00:00:00 2001 From: Ilya Date: Fri, 23 Oct 2026 00:50:40 +0300 Subject: [PATCH 09/15] =?UTF-8?q?lab4:=20=D0=B7=D0=B0=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=20=D1=88=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=20PR,?= =?UTF-8?q?=20=D1=81=D0=B2=D0=B5=D0=B6=D0=B8=D0=B9=20=D0=B2=D1=8B=D0=B2?= =?UTF-8?q?=D0=BE=D0=B4=20make=20check/test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/pull_request_template.md | 59 ++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 1bec5472..8508ab04 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,18 +1,49 @@ ## Лабораторная 4 -Автор / группа: TODO -Целевая оценка (3/4/5): TODO -Трек 5, если заявлен: TODO +Автор / группа: Илья Тюнин / БВТ2303 +Целевая оценка (3/4/5): 5 +Трек 5, если заявлен: трек 1 «Прямой upload» (presigned PUT) -Что реализовано и что перенесено: TODO -Команды запуска из чистого clone: TODO -Результаты проверок и ссылка на REPORT.md: TODO -Ограничения / известные ошибки: TODO -Источники и использование ИИ: TODO +Что реализовано и что перенесено: +- Перенесено из lab3: NestJS 12 + Fastify 5, PostgreSQL, Redis-сессии и кэш, идемпотентность POST сообщений, HAProxy + 2 API-реплики, хуки `restart.sh` / `stop-one.sh` / `start-replica.sh`. +- Стенд: MinIO (образ закреплён по digest), идемпотентный bootstrap `s3-init` (приватный bucket, политика `messenger-api` только на `attachments/*`, отдельный пользователь API), секреты через Docker secrets (`make init-env`), консоль MinIO отключена, порт 9001 не публикуется, корневая ФС API `read_only`. +- Proxy upload PNG/JPEG: потоковая передача в S3 без буферизации тела; `ImageInspector` проверяет сигнатуру, структуру и CRC, лимиты 10 MiB / 40 млн пикселей применяются до чтения; при отказе — компенсация; 201 ready только после PUT в S3 и `markReady`. +- Download через API с проверкой членства в чате; `attachment_ids` в сообщениях (атомарно в `CREATE_ONCE_SQL`, составные FK запрещают вложение другого чата); уборщик незавершённых загрузок с grace period; CLI sweep. +- Недоступность S3 — деградация: вложения отвечают 503, текст, история и readiness работают. +- Трек 1: `POST /chats/{id}/attachments/direct-uploads` → presigned PUT (подписаны content-type, content-length, x-amz-checksum-sha256) → `POST /attachments/{id}/complete` (HEAD + чтение заголовка изображения, статус `rejected` для отклонённых); расширение — `contracts/extensions.openapi.json`, обязательный proxy endpoint не изменён. -- [ ] Весь обязательный минимум текущей и предыдущих работ сохранён с объявленными переходами. -- [ ] Контракт и публичные тесты не ослаблены. -- [ ] make check и make test выполнены; приложен реальный вывод. -- [ ] Сценарии отказов/безопасности своего уровня воспроизведены. -- [ ] Все секреты и приватные ключи находятся вне Git; отчёт не содержит tokens. -- [ ] README задания сохранён, REPORT.md содержит инструкцию именно моего решения. +Команды запуска из чистого clone: +```sh +make init-env && make stand-up && make wait-ready +make check && make test && make test-e2e +make test-dependencies && make s3-security && make consistency +make test-persistence ACTION_SCRIPT=scripts/restart.sh +make test-failover ACTION_SCRIPT=scripts/stop-one.sh && scripts/start-replica.sh +make bench +``` +Остановка: `make stand-down` (тома сохраняются); удаление данных: `docker compose --env-file .env down -v`. + +Результаты проверок и ссылка на REPORT.md: [REPORT.md](../REPORT.md); вывод — `evidence/lab4/`. +- `make check` — PASS; `make test` — PASS (`make-check.txt`, `make-test.txt`). +- `make test-e2e`: 34 passed, 8 skipped (opt-in); unit-тесты: 36 passed. +- `make test-dependencies`: 6 passed (Redis, PG, S3 down, PG down между PUT и ready). +- Persistence и failover — PASS; download после остановки каждой из реплик возвращает тот же sha256. +- `make s3-security`: 9 PASS; `make consistency`: orphans 0, missing 0; спайк подписи: чужие байты → S3 400/403. +- Эксперимент: proxy 10×9.5 MiB — пик Δrss 15.7 MiB, 20×9.5 MiB — 16.5 MiB; direct — трафик API ≈0.07 MiB на загрузку при любом размере, proxy ≈2×size. + +Ограничения / известные ошибки: +- Прямой путь проверяет только заголовок изображения (структура хвоста файла >64 KiB не проверяется; байты зафиксированы подписанным SHA-256). +- Не атомарна проверка лимита незавершённых заявок прямой загрузки (гонка параллельных init). +- Порядок компенсации proxy (сначала объект, потом строка): при ложном обрыве после commit возможна потеря объекта. +- Тайм-аут загрузки обрывает сокет вместо ответа 400. +- Нет автоматического reconciler'а orphan-объектов (только `make consistency`), нет TLS (до lab7), нет вариантов/WebP/delete-API. +- Репозиторий MinIO, вероятно, архивирован (в этой работе не перепроверялось). + +Источники и использование ИИ: контракт и `contracts/README.md`; AWS S3 User Guide (uploads, presigned URLs, checksums); документация MinIO (`mc`, политики, `MINIO_*_FILE`); AWS SDK for JavaScript v3; спецификации PNG и JPEG. Код, тесты и эксперименты подготовлены с помощью ИИ-ассистента и проверены прогонами на стенде; ревью кода — отдельным ИИ-агентом, найденные проблемы исправлены (см. REPORT.md). + +- [x] Весь обязательный минимум текущей и предыдущих работ сохранён с объявленными переходами. +- [x] Контракт и публичные тесты не ослаблены. +- [x] make check и make test выполнены; приложен реальный вывод. +- [x] Сценарии отказов/безопасности своего уровня воспроизведены. +- [x] Все секреты и приватные ключи находятся вне Git; отчёт не содержит tokens. +- [x] README задания сохранён, REPORT.md содержит инструкцию именно моего решения. -- 2.54.0 From 4badd5a7b941f8b63c4fa0b60a576c01470570bb Mon Sep 17 00:00:00 2001 From: Ilya Date: Fri, 23 Oct 2026 16:37:13 +0300 Subject: [PATCH 10/15] =?UTF-8?q?lab4:=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=B5?= =?UTF-8?q?=D0=BD=D1=81=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B1=D0=B5=D0=B7=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=82=D0=B5=D1=80=D0=B8=20=D0=BE=D0=B1=D1=8A=D0=B5?= =?UTF-8?q?=D0=BA=D1=82=D0=B0=20=D0=BF=D1=80=D0=B8=20=D0=BF=D0=BE=D1=82?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=20=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D0=B0=20COM?= =?UTF-8?q?MIT,=20=D0=BF=D0=BE=D0=BB=D0=BD=D1=8B=D0=B9=20=D0=B4=D0=B5?= =?UTF-8?q?=D0=BA=D0=BE=D0=B4=20=D0=B8=D0=B7=D0=BE=D0=B1=D1=80=D0=B0=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B9=20(sharp)=20=D0=B2=20proxy=20=D0=B8=20?= =?UTF-8?q?direct=20complete?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 5 +- app/package-lock.json | 561 +++++++++++++++++- app/package.json | 1 + app/src/attachments/attachments.module.ts | 4 + app/src/attachments/attachments.repository.ts | 29 +- .../attachments/attachments.service.spec.ts | 113 ++++ app/src/attachments/attachments.service.ts | 85 ++- app/src/attachments/direct-uploads.service.ts | 79 +-- .../attachments/image/image-decoder.spec.ts | 51 ++ app/src/attachments/image/image-decoder.ts | 72 +++ app/src/attachments/image/image-inspector.ts | 4 +- app/src/attachments/upload-slots.ts | 31 + app/src/config/app-config.schema.ts | 8 +- app/test/attachments.e2e-spec.ts | 28 +- app/test/dependency-failures.e2e-spec.ts | 35 +- app/test/direct-upload.e2e-spec.ts | 30 +- app/test/support/jpeg.ts | 10 + app/test/support/png.ts | 11 + evidence/lab4/bench/direct-1048576-c10.json | 286 ++++----- evidence/lab4/bench/direct-131072-c10.json | 230 +++---- evidence/lab4/bench/direct-9961472-c10.json | 338 +++++------ evidence/lab4/bench/proxy-1048576-c10.json | 172 +++--- evidence/lab4/bench/proxy-131072-c10.json | 178 +++--- evidence/lab4/bench/proxy-9961472-c10.json | 174 +++--- evidence/lab4/bench/proxy-9961472-c20.json | 180 +++--- evidence/lab4/consistency.txt | 8 +- evidence/lab4/decode-memory.txt | 4 + evidence/lab4/direct-ttl-short.txt | 6 +- evidence/lab4/make-test-dependencies.txt | 4 +- evidence/lab4/make-test-e2e.txt | 6 +- evidence/lab4/summary.md | 14 +- evidence/lab4/unit-tests.txt | 14 +- scripts/lab4/decode_memory.mjs | 22 + 33 files changed, 1932 insertions(+), 861 deletions(-) create mode 100644 app/src/attachments/attachments.service.spec.ts create mode 100644 app/src/attachments/image/image-decoder.spec.ts create mode 100644 app/src/attachments/image/image-decoder.ts create mode 100644 app/src/attachments/upload-slots.ts create mode 100644 app/test/support/jpeg.ts create mode 100644 evidence/lab4/decode-memory.txt create mode 100644 scripts/lab4/decode_memory.mjs diff --git a/.env.example b/.env.example index 87462e24..fd340910 100644 --- a/.env.example +++ b/.env.example @@ -68,7 +68,10 @@ S3_CONNECT_TIMEOUT_MS=1000 S3_REQUEST_TIMEOUT_MS=15000 MAX_UPLOAD_BYTES=10485760 MAX_IMAGE_PIXELS=40000000 -UPLOAD_MAX_IN_FLIGHT=32 +# Каждая загрузка держит копию файла (≤ MAX_UPLOAD_BYTES) до полного декода: +# память реплики ≈ UPLOAD_MAX_IN_FLIGHT × 10 MiB + IMAGE_DECODE_MAX_CONCURRENT декодов. +UPLOAD_MAX_IN_FLIGHT=16 +IMAGE_DECODE_MAX_CONCURRENT=2 DIRECT_UPLOAD_MAX_PENDING_PER_USER=10 # UPLOAD_TIMEOUT_MS, DIRECT_UPLOAD_URL_TTL_SECONDS, ATTACHMENT_SWEEP_GRACE_SECONDS, # ATTACHMENT_SWEEP_INTERVAL_MS задаются в compose.yaml (environment) с умолчаниями diff --git a/app/package-lock.json b/app/package-lock.json index 4338b4b9..32fbef7d 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -26,6 +26,7 @@ "redis": "^6.3.0", "reflect-metadata": "^0.2.2", "rxjs": "^7.8.1", + "sharp": "^0.35.5", "zod": "^4.6.5" }, "devDependencies": { @@ -553,6 +554,16 @@ "node": ">=0.1.90" } }, + "node_modules/@emnapi/runtime": { + "version": "1.11.3", + "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.11.3.tgz", + "integrity": "sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA==", + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, "node_modules/@epic-web/invariant": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@epic-web/invariant/-/invariant-1.0.0.tgz", @@ -1200,6 +1211,506 @@ "node": ">= 10" } }, + "node_modules/@img/colour": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@img/colour/-/colour-1.1.0.tgz", + "integrity": "sha512-Td76q7j57o/tLVdgS746cYARfSyxk8iEfRxewL9h4OMzYhbW4TAcppl0mT4eyqXddh6L/jwoM75mo7ixa/pCeQ==", + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/@img/sharp-darwin-arm64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.35.5.tgz", + "integrity": "sha512-QRUlFQ0WxvdWyqqG/WtI3iupfD5rBzmCHXSdPsY91sAtVtTo7Q4cb6zOccZ3gqEqkr0f1As1ehLqmEpDsRf+lg==", + "cpu": [ + "arm64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-darwin-arm64": "1.3.4" + } + }, + "node_modules/@img/sharp-darwin-x64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-darwin-x64/-/sharp-darwin-x64-0.35.5.tgz", + "integrity": "sha512-+BR255RhDlpygUpOc/Jdt1nT6DQ3XG/ERo5wbcdOf5Q320dKtPCKPLR1LJs9VGXRaMa8l1uUa0tkCNOXiAxZUw==", + "cpu": [ + "x64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-darwin-x64": "1.3.4" + } + }, + "node_modules/@img/sharp-freebsd-wasm32": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-freebsd-wasm32/-/sharp-freebsd-wasm32-0.35.5.tgz", + "integrity": "sha512-Y/z91nEZ4uIBX5X3nfTovjU9lHNKFYbL2lpHCLVNmXQK03VIZvXBBt0KxbPGp2SdGSF+2mQU4e+hQaWOt86iAw==", + "license": "Apache-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "dependencies": { + "@img/sharp-wasm32": "0.35.5" + }, + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-darwin-arm64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-arm64/-/sharp-libvips-darwin-arm64-1.3.4.tgz", + "integrity": "sha512-5R89nBYiRdUlSWJxPhO+GVtaXzXSxKnRu/xqMn3KTA3L9EB9Oy/P+Nn2f2vlhPuUdy/Zusb2DarbyTpGCfEDuw==", + "cpu": [ + "arm64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "darwin" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-darwin-x64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-x64/-/sharp-libvips-darwin-x64-1.3.4.tgz", + "integrity": "sha512-iR2OKH80yi0U+dUplyh3/xdpFvps6YkCwsXenIJxqxR1v9o+xtKTGbS9H7cps+2Vxjc8B1j96p75NmTGjIhtpQ==", + "cpu": [ + "x64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "darwin" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-arm": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm/-/sharp-libvips-linux-arm-1.3.4.tgz", + "integrity": "sha512-LmRtTsOHuvM2+wlO2Db37dx5MiZhB0FvSunciw48YjdOkZz9KAiRbm8ujeMOA1INqmei5NapFxYEK1D1ZSidmw==", + "cpu": [ + "arm" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-arm64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm64/-/sharp-libvips-linux-arm64-1.3.4.tgz", + "integrity": "sha512-Y3dgX/6lE2QhQb+Gxy0WZxfg9MEm/JBjamZpS2IklP7xIQoKN4hzAm7KcMVGtaVDt3neE9OKBC7vAfonA/Lr1A==", + "cpu": [ + "arm64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-ppc64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-ppc64/-/sharp-libvips-linux-ppc64-1.3.4.tgz", + "integrity": "sha512-Le6boB8Tai0Nis+gIxIpKx68UDVVIqdR8Tin5Yf1z2LJJQLDJvCDRqRu+jC2qCoD+eIomonmOwB4smBRxfVpYQ==", + "cpu": [ + "ppc64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-riscv64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-riscv64/-/sharp-libvips-linux-riscv64-1.3.4.tgz", + "integrity": "sha512-aHkkIEHPRdQEegJN20MLmGtxYD9R2wQr3Cwpddnu5+YKMt6Uzax7S9h5gpZTo8wyrGuZSlfQ63OevL5mTyOC7Q==", + "cpu": [ + "riscv64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-s390x": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-s390x/-/sharp-libvips-linux-s390x-1.3.4.tgz", + "integrity": "sha512-ra/mB6MikESDUO7Yg+Mi95bFBb9GsObURuhnOv3OqknjGe9sZrG8tCe9q0xSIGrtLgvgw0gKnFWcK4blSgQOuQ==", + "cpu": [ + "s390x" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-x64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-x64/-/sharp-libvips-linux-x64-1.3.4.tgz", + "integrity": "sha512-GJ//SSXbnwSDes02umB3nDJLFcQzw8a18V8fyhqr6tV515tOEMdImjjxj1AoafMRz56F3PHgftnj1QEKSU1zkw==", + "cpu": [ + "x64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linuxmusl-arm64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-arm64/-/sharp-libvips-linuxmusl-arm64-1.3.4.tgz", + "integrity": "sha512-hvulFwtjUcagsis6BBxHwGFwWoNZjgYmULGVrZcyfNbjA8hKILbRxGg15/7w5HDyXHXUos/j6baAWqnCyQ2DWA==", + "cpu": [ + "arm64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linuxmusl-x64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-x64/-/sharp-libvips-linuxmusl-x64-1.3.4.tgz", + "integrity": "sha512-6zXKeE/p39I1AmA3cJG35eyBGNqNddLnUXjhwBnsGjFPWqf5VKkDBEqaEkPDoTEtkxwi2vv8Tcr2mDyP4So7Fg==", + "cpu": [ + "x64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-linux-arm": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm/-/sharp-linux-arm-0.35.5.tgz", + "integrity": "sha512-LEaXK2WdXVK5ykcw0buWyPMsmLLL2vpHLD6yrNSW+JGEL3BZPA4tpKN6iaMc4AxTTAoaX/sU1rOL51lcIz48ZQ==", + "cpu": [ + "arm" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-arm": "1.3.4" + } + }, + "node_modules/@img/sharp-linux-arm64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm64/-/sharp-linux-arm64-0.35.5.tgz", + "integrity": "sha512-LYVx5JTsOM2CBzmxreh+nl64/3H6Xb09iSLknqH47z2T2DFFxDeFLP5y4dJwe6H7uGQlHPyEEtIqyo3DYsRwdQ==", + "cpu": [ + "arm64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-arm64": "1.3.4" + } + }, + "node_modules/@img/sharp-linux-ppc64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-ppc64/-/sharp-linux-ppc64-0.35.5.tgz", + "integrity": "sha512-QVxAAq8evVRI9ia2vqgwrmWucn5Dfv+JdWzj75pD8omHLPSP7f8p20O8jxzjCcuCEQEOtYOZUmX1hkiZ0kdevA==", + "cpu": [ + "ppc64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-ppc64": "1.3.4" + } + }, + "node_modules/@img/sharp-linux-riscv64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-riscv64/-/sharp-linux-riscv64-0.35.5.tgz", + "integrity": "sha512-LtdreXguaavKODPIfzJ4kffx7UNt1omwtK0rch4EBbbSTXPnxWmYSayXdLJw0fJzQ97kHt1gL/yh4tvU+nCyRQ==", + "cpu": [ + "riscv64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-riscv64": "1.3.4" + } + }, + "node_modules/@img/sharp-linux-s390x": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-s390x/-/sharp-linux-s390x-0.35.5.tgz", + "integrity": "sha512-UZasTOFiYzotTsGOCu42BfUzP6Tu6Do/947iRm1RsLKvlllxwGcn4RN27LibGWceix4Y+Pmw3jsnTcCQIgWjqA==", + "cpu": [ + "s390x" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-s390x": "1.3.4" + } + }, + "node_modules/@img/sharp-linux-x64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-x64/-/sharp-linux-x64-0.35.5.tgz", + "integrity": "sha512-SxFtLTeJInhAA9Q836kux2vZNeOBQEx658qvbboZScr0wIARym3IcGmW7KpVD5sbVg0Ojy+udFQdayYIZyoNog==", + "cpu": [ + "x64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-x64": "1.3.4" + } + }, + "node_modules/@img/sharp-linuxmusl-arm64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-arm64/-/sharp-linuxmusl-arm64-0.35.5.tgz", + "integrity": "sha512-9HbMclmI1zlNkFRs3z9/eBtDjfD0sGlrX1z6b1qwmiFY5ElDLh4BC0LPBdVp7z1DXFiKlIcznf+ZlsuZzLxQqg==", + "cpu": [ + "arm64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linuxmusl-arm64": "1.3.4" + } + }, + "node_modules/@img/sharp-linuxmusl-x64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.35.5.tgz", + "integrity": "sha512-4KOphqB035HrVdqLZfCgMzzERrQkkzOwRhl4OAkRO1YCldbaFjySXMaK534Mo0V+LndnlJk+sbUyLeU0ULyD1A==", + "cpu": [ + "x64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linuxmusl-x64": "1.3.4" + } + }, + "node_modules/@img/sharp-wasm32": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-wasm32/-/sharp-wasm32-0.35.5.tgz", + "integrity": "sha512-Ptsga1su4tQx+LLF1ECS9U6nz5kmrXKo6XVbtR48Ke3ZRxxgaWBu7IDtEe1quo8hiupwm6WFqxVlXaSf7IINGQ==", + "license": "Apache-2.0 AND LGPL-3.0-or-later AND MIT", + "optional": true, + "dependencies": { + "@emnapi/runtime": "^1.11.3" + }, + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-webcontainers-wasm32": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-webcontainers-wasm32/-/sharp-webcontainers-wasm32-0.35.5.tgz", + "integrity": "sha512-hfhF/FmoQyTUkA0bIKFOtw536BQSeBMe6BF6QyWlrPxT754+TFLaZ7sKKTfvvM0yJgKgaYTwnFCIZ/GuDw5SUA==", + "cpu": [ + "wasm32" + ], + "license": "Apache-2.0", + "optional": true, + "dependencies": { + "@img/sharp-wasm32": "0.35.5" + }, + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-win32-arm64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-arm64/-/sharp-win32-arm64-0.35.5.tgz", + "integrity": "sha512-X4t7g+7ZA5DKblCBEXGjUqqemj4vczING/5viFwAL8h4N3qYeyjwdCvRLHi4EdOUI+2Z7UFlp1VM+p/AuEtm6Q==", + "cpu": [ + "arm64" + ], + "license": "Apache-2.0 AND LGPL-3.0-or-later", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-win32-ia32": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-ia32/-/sharp-win32-ia32-0.35.5.tgz", + "integrity": "sha512-5Zm82LoBc43nhwNybZlG7Y1KO//Zhsn306fQl29ZOuStHLGTo3BWL83q3cznX0poxSAMuYL1On/BHBxkBeKr6A==", + "cpu": [ + "ia32" + ], + "license": "Apache-2.0 AND LGPL-3.0-or-later", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-win32-x64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-x64/-/sharp-win32-x64-0.35.5.tgz", + "integrity": "sha512-x76eH0vEiHlcMQu8Y8IenntaACtddpT6W0wmXtWrnKcnKI7ME5DdgqhAD6SEWOEl1v2zDvkZDhFA9KnURwpfqg==", + "cpu": [ + "x64" + ], + "license": "Apache-2.0 AND LGPL-3.0-or-later", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, "node_modules/@inquirer/ansi": { "version": "2.0.8", "resolved": "https://registry.npmjs.org/@inquirer/ansi/-/ansi-2.0.8.tgz", @@ -4014,7 +4525,6 @@ "version": "2.1.2", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==", - "dev": true, "license": "Apache-2.0", "engines": { "node": ">=8" @@ -6842,6 +7352,55 @@ "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", "license": "ISC" }, + "node_modules/sharp": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/sharp/-/sharp-0.35.5.tgz", + "integrity": "sha512-Ywn4OnzGukp7CDMrp08RQ50YKmuwG47brZgIVPTvBaaAfQlRlygrRqSrxdCiL9M+LlzLBiJ68IR1QqvzHyjC7g==", + "license": "Apache-2.0", + "dependencies": { + "@img/colour": "^1.1.0", + "detect-libc": "^2.1.2", + "semver": "^7.8.5" + }, + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-darwin-arm64": "0.35.5", + "@img/sharp-darwin-x64": "0.35.5", + "@img/sharp-freebsd-wasm32": "0.35.5", + "@img/sharp-libvips-darwin-arm64": "1.3.4", + "@img/sharp-libvips-darwin-x64": "1.3.4", + "@img/sharp-libvips-linux-arm": "1.3.4", + "@img/sharp-libvips-linux-arm64": "1.3.4", + "@img/sharp-libvips-linux-ppc64": "1.3.4", + "@img/sharp-libvips-linux-riscv64": "1.3.4", + "@img/sharp-libvips-linux-s390x": "1.3.4", + "@img/sharp-libvips-linux-x64": "1.3.4", + "@img/sharp-libvips-linuxmusl-arm64": "1.3.4", + "@img/sharp-libvips-linuxmusl-x64": "1.3.4", + "@img/sharp-linux-arm": "0.35.5", + "@img/sharp-linux-arm64": "0.35.5", + "@img/sharp-linux-ppc64": "0.35.5", + "@img/sharp-linux-riscv64": "0.35.5", + "@img/sharp-linux-s390x": "0.35.5", + "@img/sharp-linux-x64": "0.35.5", + "@img/sharp-linuxmusl-arm64": "0.35.5", + "@img/sharp-linuxmusl-x64": "0.35.5", + "@img/sharp-webcontainers-wasm32": "0.35.5", + "@img/sharp-win32-arm64": "0.35.5", + "@img/sharp-win32-ia32": "0.35.5", + "@img/sharp-win32-x64": "0.35.5" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + } + } + }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", diff --git a/app/package.json b/app/package.json index 3b58c6c2..30a2c2b1 100644 --- a/app/package.json +++ b/app/package.json @@ -44,6 +44,7 @@ "redis": "^6.3.0", "reflect-metadata": "^0.2.2", "rxjs": "^7.8.1", + "sharp": "^0.35.5", "zod": "^4.6.5" }, "devDependencies": { diff --git a/app/src/attachments/attachments.module.ts b/app/src/attachments/attachments.module.ts index 32305df1..951c8d62 100644 --- a/app/src/attachments/attachments.module.ts +++ b/app/src/attachments/attachments.module.ts @@ -8,6 +8,8 @@ import { StorageModule } from '../storage/storage.module.js'; import { AttachmentSweeper } from './attachment-sweeper.service.js'; import { AttachmentsController } from './attachments.controller.js'; import { AttachmentsRepository } from './attachments.repository.js'; +import { ImageDecoder } from './image/image-decoder.js'; +import { UploadSlots } from './upload-slots.js'; import { DirectUploadsService } from './direct-uploads.service.js'; import { AttachmentsService } from './attachments.service.js'; @@ -25,6 +27,8 @@ import { AttachmentsService } from './attachments.service.js'; AttachmentsRepository, AttachmentsService, DirectUploadsService, + ImageDecoder, + UploadSlots, AttachmentSweeper, ], exports: [AttachmentsRepository], diff --git a/app/src/attachments/attachments.repository.ts b/app/src/attachments/attachments.repository.ts index a3cea2c8..d5f36c0f 100644 --- a/app/src/attachments/attachments.repository.ts +++ b/app/src/attachments/attachments.repository.ts @@ -75,13 +75,38 @@ export class AttachmentsRepository { ); } - async rejectPending(id: string): Promise { - await this.database.query( + async rejectPending(id: string): Promise { + const result = await this.database.query( 'attachments.reject_pending', `UPDATE attachments SET status = 'rejected', updated_at = now() WHERE id = $1 AND status = 'pending'`, [id], ); + return result.rowCount === 1; + } + + /** + * Takes a pending row out of play before its object is deleted. The object + * is deleted only when this returns true: a row that is already `ready` + * (its commit succeeded even if the reply was lost) keeps its object. + */ + async claimForCompensation(id: string): Promise { + const result = await this.database.query( + 'attachments.claim_for_compensation', + `UPDATE attachments SET status = 'deleting', updated_at = now() + WHERE id = $1 AND status = 'pending'`, + [id], + ); + return result.rowCount === 1; + } + + async findById(id: string): Promise { + const result = await this.database.query( + 'attachments.find_by_id', + 'SELECT * FROM attachments WHERE id = $1', + [id], + ); + return result.rows[0]; } async findVisible( diff --git a/app/src/attachments/attachments.service.spec.ts b/app/src/attachments/attachments.service.spec.ts new file mode 100644 index 00000000..77b0478c --- /dev/null +++ b/app/src/attachments/attachments.service.spec.ts @@ -0,0 +1,113 @@ +import { readFileSync } from 'node:fs'; +import { dirname, join } from 'node:path'; +import { Readable } from 'node:stream'; +import { fileURLToPath } from 'node:url'; +import { describe, expect, it, vi } from 'vitest'; +import type { AttachmentRow } from './attachment.js'; +import { AttachmentsService } from './attachments.service.js'; + +const here = dirname(fileURLToPath(import.meta.url)); +const png = readFileSync(join(here, '../../../tests/fixtures/sample.png')); +const lostReply = () => + Object.assign(new Error('Connection terminated unexpectedly'), {}); + +const settings: Record = { + MAX_UPLOAD_BYTES: 10_485_760, + MAX_IMAGE_PIXELS: 40_000_000, + UPLOAD_TIMEOUT_MS: 10_000, +}; + +function setup(repository: Record) { + const storage = { + objectKey: (id: string) => `attachments/${id}/original`, + putStream: vi.fn(async (_key: string, body: Readable) => { + for await (const _chunk of body) { + // drain like S3 does + } + }), + delete: vi.fn().mockResolvedValue(undefined), + }; + const service = new AttachmentsService( + { getOrThrow: (key: string) => settings[key] } as never, + { + insertPending: vi.fn(), + deleteClaimed: vi.fn(), + ...repository, + } as never, + storage as never, + { getForUser: vi.fn() } as never, + { increment: vi.fn(), add: vi.fn() } as never, + { verify: vi.fn() } as never, + { run: (work: () => Promise) => work() } as never, + ); + const upload = () => + service.uploadProxy( + 'chat', + { id: 'user' } as never, + 'a.png', + 'image/png', + String(png.length), + Readable.from([png]), + ); + return { storage, upload }; +} + +const readyRow = (id: string): AttachmentRow => ({ + id, + chat_id: 'chat', + owner_id: 'user', + filename: 'a.png', + content_type: 'image/png', + upload_mode: 'proxy', + status: 'ready', + object_key: `attachments/${id}/original`, + size_bytes: png.length, + sha256: 'a'.repeat(64), + width: 320, + height: 200, + expires_at: null, + created_at: new Date(), + updated_at: new Date(), +}); + +describe('AttachmentsService compensation', () => { + it('keeps the object and answers 201 when ready was committed but its reply was lost', async () => { + const { storage, upload } = setup({ + markReady: vi.fn().mockRejectedValue(lostReply()), + claimForCompensation: vi.fn().mockResolvedValue(false), + findById: vi.fn((id: string) => Promise.resolve(readyRow(id))), + }); + const attachment = await upload(); + expect(attachment.status).toBe('ready'); + expect(storage.delete).not.toHaveBeenCalled(); + }); + + it('deletes nothing while PostgreSQL is unreachable', async () => { + const { storage, upload } = setup({ + markReady: vi.fn().mockRejectedValue(lostReply()), + claimForCompensation: vi.fn().mockRejectedValue(lostReply()), + findById: vi.fn().mockRejectedValue(lostReply()), + }); + await expect(upload()).rejects.toThrow(); + expect(storage.delete).not.toHaveBeenCalled(); + }); + + it('deletes the object only after claiming the pending row', async () => { + const order: string[] = []; + const { storage, upload } = setup({ + markReady: vi.fn().mockRejectedValue(lostReply()), + claimForCompensation: vi.fn(async () => { + order.push('claim'); + return true; + }), + deleteClaimed: vi.fn(async () => { + order.push('delete-row'); + }), + }); + storage.delete.mockImplementation(async () => { + order.push('delete-object'); + }); + await expect(upload()).rejects.toThrow(); + expect(order).toEqual(['claim', 'delete-object', 'delete-row']); + }); +}); diff --git a/app/src/attachments/attachments.service.ts b/app/src/attachments/attachments.service.ts index e46b77d6..7a7fa4e3 100644 --- a/app/src/attachments/attachments.service.ts +++ b/app/src/attachments/attachments.service.ts @@ -30,6 +30,8 @@ import { ImageRejectedError, } from './image/image-inspector.js'; import { AttachmentsRepository } from './attachments.repository.js'; +import { ImageDecoder } from './image/image-decoder.js'; +import { UploadSlots } from './upload-slots.js'; const MEDIA_TYPES = new Set(['image/png', 'image/jpeg']); @@ -49,11 +51,9 @@ class UploadInterruptedError extends Error {} @Injectable() export class AttachmentsService { private readonly logger = new Logger(AttachmentsService.name); - private inFlight = 0; private readonly maxUploadBytes: number; private readonly maxPixels: number; private readonly uploadTimeoutMs: number; - private readonly maxInFlight: number; constructor( config: ConfigService, @@ -61,11 +61,12 @@ export class AttachmentsService { private readonly storage: ObjectStorage, private readonly chats: ChatsService, private readonly metrics: MetricsService, + private readonly decoder: ImageDecoder, + private readonly slots: UploadSlots, ) { this.maxUploadBytes = config.getOrThrow('MAX_UPLOAD_BYTES'); this.maxPixels = config.getOrThrow('MAX_IMAGE_PIXELS'); this.uploadTimeoutMs = config.getOrThrow('UPLOAD_TIMEOUT_MS'); - this.maxInFlight = config.getOrThrow('UPLOAD_MAX_IN_FLIGHT'); } async uploadProxy( @@ -93,15 +94,9 @@ export class AttachmentsService { if (contentLength > this.maxUploadBytes) throw new PayloadTooLargeException('Image is too large'); - if (this.inFlight >= this.maxInFlight) - throw new HttpException( - { message: 'Too many concurrent uploads', retryAfter: 1 }, - 429, - ); - this.inFlight += 1; - try { + return this.slots.run(async () => { await this.chats.getForUser(chatId, user); - return await this.receive( + return this.receive( chatId, user, filename, @@ -109,9 +104,7 @@ export class AttachmentsService { contentLength, body, ); - } finally { - this.inFlight -= 1; - } + }); } private async receive( @@ -193,8 +186,12 @@ export class AttachmentsService { }); const sha256 = createHash('sha256'); + const decoder = this.decoder; + // Copy for the full decode check; bounded by MAX_UPLOAD_BYTES and + // UPLOAD_MAX_IN_FLIGHT, released as soon as the decode starts. + const copy: Buffer[] = []; let total = 0; - const account = (chunk: Buffer, inspect: boolean): void => { + const account = (chunk: Buffer, inspect: boolean): boolean => { total += chunk.length; if (total > contentLength) throw new UploadInterruptedError( @@ -203,19 +200,26 @@ export class AttachmentsService { if (inspect) inspector.push(chunk); sha256.update(chunk); this.metrics.add('attachments.proxy.bytes_in', chunk.length); - // Validate before the last bytes reach S3: it cannot commit an - // object whose body is incomplete. - if (total === contentLength) inspector.finish(); + copy.push(chunk); + return total === contentLength; + }; + // Validate before the last bytes reach S3: it cannot commit an object + // whose body is incomplete, so an invalid image never becomes an object. + const finalize = async (): Promise => { + inspector.finish(); + const data = Buffer.concat(copy, total); + copy.length = 0; + await decoder.verify(data); }; async function* generate(): AsyncGenerator { for (const chunk of head) { - account(chunk, false); + if (account(chunk, false)) await finalize(); yield chunk; } for (;;) { const step = await next(); if (step.done) break; - account(step.value, true); + if (account(step.value, true)) await finalize(); yield step.value; } if (total < contentLength) @@ -238,6 +242,7 @@ export class AttachmentsService { // `rejection`; the listener also keeps a late error from crashing us. readable.on('error', () => controller.abort()); let claimed = false; + let stored = false; try { await this.storage.putStream( key, @@ -250,6 +255,7 @@ export class AttachmentsService { 'attachments.proxy.bytes_to_s3', contentLength, ); + stored = true; const row = await this.repository.markReady(id, { sizeBytes: total, sha256: sha256.digest('hex'), @@ -264,7 +270,23 @@ export class AttachmentsService { return toAttachment(row); } catch (error) { readable.destroy(); - if (!claimed) await this.compensate(id, key); + if (!claimed) { + const outcome = await this.compensate(id, key); + // markReady failed on our side, but the row is no longer + // pending: the commit may have succeeded with its reply lost. + // If so, the upload is complete and 201 is the truth. + if (outcome === 'not_pending' && stored) { + const row = await this.repository + .findById(id) + .catch(() => undefined); + if (row?.status === 'ready') { + this.metrics.increment( + 'attachments.upload.recovered', + ); + return toAttachment(row); + } + } + } throw this.mapUploadError(rejection ?? error, timedOut); } } finally { @@ -279,16 +301,33 @@ export class AttachmentsService { return error; } - async compensate(id: string, key: string): Promise { + /** + * Undoes an upload that did not reach `ready`. The row is claimed first + * (pending -> deleting) and the object is deleted only after a successful + * claim: if PostgreSQL committed `ready` but the reply was lost, the claim + * matches nothing and the object stays. If PostgreSQL is unreachable, + * nothing is deleted; the sweeper finishes the job after expiry + grace + * (a row stuck in `deleting` is re-claimed after a minute). + */ + async compensate( + id: string, + key: string, + ): Promise<'compensated' | 'not_pending' | 'deferred'> { try { + if (!(await this.repository.claimForCompensation(id))) { + this.metrics.increment('attachments.compensation_skipped'); + return 'not_pending'; + } await this.storage.delete(key); - await this.repository.deletePending(id); + await this.repository.deleteClaimed(id); this.metrics.increment('attachments.compensated'); + return 'compensated'; } catch (error) { this.metrics.increment('attachments.compensation_deferred'); this.logger.warn( `Compensation of attachment ${id} deferred: ${error instanceof Error ? error.message : 'unknown error'}`, ); + return 'deferred'; } } diff --git a/app/src/attachments/direct-uploads.service.ts b/app/src/attachments/direct-uploads.service.ts index 4229436b..c35cdc4c 100644 --- a/app/src/attachments/direct-uploads.service.ts +++ b/app/src/attachments/direct-uploads.service.ts @@ -22,8 +22,9 @@ import { AttachmentsRepository } from './attachments.repository.js'; import { imageRejection } from './attachments.service.js'; import type { CreateDirectUploadDto } from './dto/create-direct-upload.dto.js'; import { validateFilename } from './filename.js'; +import { ImageDecoder } from './image/image-decoder.js'; +import { UploadSlots } from './upload-slots.js'; import { - IMAGE_HEADER_MAX_BYTES, ImageInspector, ImageRejectedError, type ImageHeader, @@ -37,7 +38,6 @@ export type DirectUpload = { expires_at: string; }; -const FIRST_RANGE_BYTES = 65_536; const MEDIA_TYPES = new Set(['image/png', 'image/jpeg']); @Injectable() @@ -53,6 +53,8 @@ export class DirectUploadsService { private readonly storage: ObjectStorage, private readonly chats: ChatsService, private readonly metrics: MetricsService, + private readonly decoder: ImageDecoder, + private readonly slots: UploadSlots, ) { this.maxUploadBytes = config.getOrThrow('MAX_UPLOAD_BYTES'); this.maxPixels = config.getOrThrow('MAX_IMAGE_PIXELS'); @@ -136,7 +138,10 @@ export class DirectUploadsService { ); if (!row) throw new NotFoundException(); if (row.status === 'ready') return toAttachment(row); + return this.slots.run(() => this.verifyAndMarkReady(row)); + } + private async verifyAndMarkReady(row: AttachmentRow): Promise { const size = Number(row.size_bytes); const expectedChecksum = Buffer.from( row.sha256 as string, @@ -152,10 +157,9 @@ export class DirectUploadsService { ); } - // Only the header is read: the signed checksum already pins every byte. let header: ImageHeader; try { - header = await this.readHeader(row.object_key, size); + header = await this.verifyObject(row.object_key, size); } catch (error) { if (error instanceof ImageRejectedError) { await this.reject(row); @@ -181,40 +185,41 @@ export class DirectUploadsService { } /** - * Reads a small first range and widens it only when the header is not in it, - * so the usual `complete` costs one short ranged GET. A range that covers the - * whole object is also checked for structural completeness. + * Reads the whole object: a correct signed checksum only proves that the + * bytes are the ones the client declared, not that they form an image. The + * stream goes through ImageInspector (structure, CRCs, completeness), then + * the copy is fully decoded. Memory is bounded like a proxy upload. */ - private async readHeader(key: string, size: number): Promise { - const ceiling = Math.min(size, IMAGE_HEADER_MAX_BYTES); - let range = Math.min(size, FIRST_RANGE_BYTES); - for (;;) { - const inspector = new ImageInspector(this.maxPixels); - const stream = await this.storage.getStream( - key, - `bytes=0-${range - 1}`, - ); - if (stream === null) - throw new ConflictException('Upload has not been received'); - let verified = 0; - try { - for await (const chunk of stream as AsyncIterable) { - verified += chunk.length; - inspector.push(chunk); - } - } finally { - stream.destroy(); - this.metrics.add('attachments.direct.verify_bytes', verified); + private async verifyObject( + key: string, + size: number, + ): Promise { + const stream = await this.storage.getStream(key); + if (stream === null) + throw new ConflictException('Upload has not been received'); + const inspector = new ImageInspector(this.maxPixels); + const chunks: Buffer[] = []; + let read = 0; + try { + for await (const chunk of stream as AsyncIterable) { + read += chunk.length; + if (read > size) + throw new ImageRejectedError( + 'unsupported_media_type', + 'Object is larger than declared', + ); + inspector.push(chunk); + chunks.push(chunk); } - if (range === size) return inspector.finish(); - if (inspector.header !== undefined) return inspector.header; - if (range >= ceiling) - throw new ImageRejectedError( - 'unsupported_media_type', - 'Image header is missing', - ); - range = ceiling; + } finally { + stream.destroy(); + this.metrics.add('attachments.direct.verify_bytes', read); } + const header = inspector.finish(); + const data = Buffer.concat(chunks, read); + chunks.length = 0; + await this.decoder.verify(data); + return header; } /** @@ -223,7 +228,9 @@ export class DirectUploadsService { * object that no row refers to. The sweeper removes both after expiry + grace. */ private async reject(row: AttachmentRow): Promise { - await this.repository.rejectPending(row.id); + // Row first: a row that is not pending any more (ready after a parallel + // complete, or claimed by the sweeper) keeps its object. + if (!(await this.repository.rejectPending(row.id))) return; try { await this.storage.delete(row.object_key); } catch { diff --git a/app/src/attachments/image/image-decoder.spec.ts b/app/src/attachments/image/image-decoder.spec.ts new file mode 100644 index 00000000..9b36dbe1 --- /dev/null +++ b/app/src/attachments/image/image-decoder.spec.ts @@ -0,0 +1,51 @@ +import { readFileSync } from 'node:fs'; +import { dirname, join } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { describe, expect, it } from 'vitest'; +import { jpegWithoutScanData } from '../../../test/support/jpeg.js'; +import { noisePng, pngWithGarbageIdat } from '../../../test/support/png.js'; +import { ImageDecoder } from './image-decoder.js'; +import { ImageInspector, ImageRejectedError } from './image-inspector.js'; + +const here = dirname(fileURLToPath(import.meta.url)); +const png = readFileSync(join(here, '../../../../tests/fixtures/sample.png')); +const jpeg = readFileSync(join(here, '../../../test/fixtures/sample.jpg')); +const progressive = readFileSync( + join(here, '../../../test/fixtures/sample-progressive.jpg'), +); + +const settings: Record = { + MAX_IMAGE_PIXELS: 40_000_000, + IMAGE_DECODE_MAX_CONCURRENT: 1, +}; +const decoder = new ImageDecoder( + { getOrThrow: (key: string) => settings[key] } as never, + { increment: () => undefined, add: () => undefined } as never, +); + +describe('ImageDecoder', () => { + it('accepts valid PNG and JPEG files, also concurrently', async () => { + await Promise.all( + [png, jpeg, progressive, noisePng(1_048_576)].map((data) => + decoder.verify(data), + ), + ); + }); + + // These files pass the structural inspector; only a decode catches them. + it.each([ + ['PNG with a garbage zlib stream', pngWithGarbageIdat()], + ['JPEG without scan data', jpegWithoutScanData(jpeg)], + [ + 'progressive JPEG without scan data', + jpegWithoutScanData(progressive), + ], + ])('rejects a %s', async (_name, data) => { + const inspector = new ImageInspector(40_000_000); + inspector.push(data); + expect(inspector.finish().width).toBe(320); + await expect(decoder.verify(data)).rejects.toBeInstanceOf( + ImageRejectedError, + ); + }); +}); diff --git a/app/src/attachments/image/image-decoder.ts b/app/src/attachments/image/image-decoder.ts new file mode 100644 index 00000000..8dfe35f4 --- /dev/null +++ b/app/src/attachments/image/image-decoder.ts @@ -0,0 +1,72 @@ +import { Injectable } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; +import sharp from 'sharp'; +import type { AppConfig } from '../../config/app-config.schema.js'; +import { MetricsService } from '../../metrics/metrics.service.js'; +import { ImageRejectedError } from './image-inspector.js'; + +// One libvips worker per decode and no operation cache: decodes are one-off, +// and memory must stay predictable under the per-replica limit. +sharp.cache(false); +sharp.concurrency(1); + +/** + * Full decode check. ImageInspector only proves the container structure + * (signature, chunk CRCs, markers, dimensions); a PNG with a garbage zlib stream + * or a JPEG without scan data passes it. Decoding every pixel with + * failOn=warning rejects those, including truncated or corrupted entropy data. + * Decodes are bounded by IMAGE_DECODE_MAX_CONCURRENT; callers wait for a slot. + */ +@Injectable() +export class ImageDecoder { + private readonly maxPixels: number; + private readonly maxConcurrent: number; + private active = 0; + private readonly waiting: (() => void)[] = []; + + constructor( + config: ConfigService, + private readonly metrics: MetricsService, + ) { + this.maxPixels = config.getOrThrow('MAX_IMAGE_PIXELS'); + this.maxConcurrent = config.getOrThrow('IMAGE_DECODE_MAX_CONCURRENT'); + } + + async verify(data: Buffer): Promise { + await this.acquire(); + const started = performance.now(); + try { + await sharp(data, { + failOn: 'warning', + sequentialRead: true, + limitInputPixels: this.maxPixels, + }).stats(); + } catch { + this.metrics.increment('attachments.decode.rejected'); + throw new ImageRejectedError( + 'unsupported_media_type', + 'Image data cannot be decoded', + ); + } finally { + this.metrics.add( + 'attachments.decode.ms', + performance.now() - started, + ); + this.release(); + } + } + + private async acquire(): Promise { + if (this.active < this.maxConcurrent) { + this.active += 1; + return; + } + await new Promise((resolve) => this.waiting.push(resolve)); + } + + private release(): void { + const next = this.waiting.shift(); + if (next) next(); + else this.active -= 1; + } +} diff --git a/app/src/attachments/image/image-inspector.ts b/app/src/attachments/image/image-inspector.ts index eb041265..64a2f0eb 100644 --- a/app/src/attachments/image/image-inspector.ts +++ b/app/src/attachments/image/image-inspector.ts @@ -59,7 +59,9 @@ function unsupported(message: string): ImageRejectedError { /** * Streaming structural validator for PNG and JPEG. It never buffers the body: * only fixed-size fields (chunk headers, IHDR, SOF) are accumulated, and - * nothing is decompressed. + * nothing is decompressed. It is the early gate (type, dimensions, pixel limit + * before anything is stored), not proof of a valid image: compressed pixel + * data is checked by ImageDecoder. */ export class ImageInspector { private state: State = 'start'; diff --git a/app/src/attachments/upload-slots.ts b/app/src/attachments/upload-slots.ts new file mode 100644 index 00000000..528c4838 --- /dev/null +++ b/app/src/attachments/upload-slots.ts @@ -0,0 +1,31 @@ +import { HttpException, Injectable } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; +import type { AppConfig } from '../config/app-config.schema.js'; + +/** + * Per-replica cap on requests that hold an image in memory (proxy upload, + * direct complete): each may keep up to MAX_UPLOAD_BYTES for the decode check. + */ +@Injectable() +export class UploadSlots { + private inFlight = 0; + private readonly max: number; + + constructor(config: ConfigService) { + this.max = config.getOrThrow('UPLOAD_MAX_IN_FLIGHT'); + } + + async run(work: () => Promise): Promise { + if (this.inFlight >= this.max) + throw new HttpException( + { message: 'Too many concurrent uploads', retryAfter: 1 }, + 429, + ); + this.inFlight += 1; + try { + return await work(); + } finally { + this.inFlight -= 1; + } + } +} diff --git a/app/src/config/app-config.schema.ts b/app/src/config/app-config.schema.ts index 9ab02a11..e1155015 100644 --- a/app/src/config/app-config.schema.ts +++ b/app/src/config/app-config.schema.ts @@ -85,7 +85,13 @@ export const appConfigSchema = z MAX_UPLOAD_BYTES: numeric('MAX_UPLOAD_BYTES', 1, 10485760, 10485760), MAX_IMAGE_PIXELS: numeric('MAX_IMAGE_PIXELS', 1, 40000000, 40000000), UPLOAD_TIMEOUT_MS: numeric('UPLOAD_TIMEOUT_MS', 1000, undefined, 25000), - UPLOAD_MAX_IN_FLIGHT: numeric('UPLOAD_MAX_IN_FLIGHT', 1, 1024, 32), + UPLOAD_MAX_IN_FLIGHT: numeric('UPLOAD_MAX_IN_FLIGHT', 1, 1024, 16), + IMAGE_DECODE_MAX_CONCURRENT: numeric( + 'IMAGE_DECODE_MAX_CONCURRENT', + 1, + 64, + 2, + ), // 0 отключает фоновый проход уборщика (остаётся ручной CLI). ATTACHMENT_SWEEP_INTERVAL_MS: numeric( 'ATTACHMENT_SWEEP_INTERVAL_MS', diff --git a/app/test/attachments.e2e-spec.ts b/app/test/attachments.e2e-spec.ts index 12412585..0758ba6c 100644 --- a/app/test/attachments.e2e-spec.ts +++ b/app/test/attachments.e2e-spec.ts @@ -21,7 +21,13 @@ import { upload, uploadRaw, } from './support/e2e.js'; -import { noisePng, padPngTo, pixelBombPng } from './support/png.js'; +import { jpegWithoutScanData } from './support/jpeg.js'; +import { + noisePng, + padPngTo, + pixelBombPng, + pngWithGarbageIdat, +} from './support/png.js'; const png = readFileSync( new URL('../../tests/fixtures/sample.png', import.meta.url), @@ -167,6 +173,8 @@ describe('attachments (proxy upload)', () => { flipped, Buffer.concat([png.subarray(0, 8), randomBytes(2048)]), Buffer.alloc(0), + // Structure and CRCs are fine; the pixel data does not decode. + pngWithGarbageIdat(), ]; for (const data of cases) expectError( @@ -176,6 +184,24 @@ describe('attachments (proxy upload)', () => { ); }); + it.each([ + ['baseline', jpeg], + ['progressive', progressive], + ])('rejects a %s JPEG without scan data', async (_name, data) => { + expectError( + await upload( + alice.token, + leftoverChatId, + jpegWithoutScanData(data), + { + contentType: 'image/jpeg', + }, + ), + 415, + 'unsupported_media_type', + ); + }); + it('rejects a content type that does not match the bytes', async () => { const gif = Buffer.from('GIF89a' + 'x'.repeat(64)); const cases: [Buffer, string][] = [ diff --git a/app/test/dependency-failures.e2e-spec.ts b/app/test/dependency-failures.e2e-spec.ts index 95cfae67..c44822c8 100644 --- a/app/test/dependency-failures.e2e-spec.ts +++ b/app/test/dependency-failures.e2e-spec.ts @@ -944,12 +944,13 @@ describe.skipIf(!enabled)('dependency outages', () => { expect((await request('/health/ready')).response.status).toBe( 200, ); - // Compensation could not reach S3, so the row stays for the sweeper. + // Compensation claimed the row but could not delete the object: + // the row stays in `deleting`, tracked for the sweeper. expect( await psql( - `select count(*) from attachments where chat_id = '${chat.id}' and status = 'pending' and filename = 's3down-${runId}.png'`, + `select status from attachments where chat_id = '${chat.id}' and filename = 's3down-${runId}.png'`, ), - ).toBe('1'); + ).toBe('deleting'); } finally { await compose('start', s3Service); } @@ -966,18 +967,27 @@ describe.skipIf(!enabled)('dependency outages', () => { const after = await upload(samplePng, `s3after-${runId}.png`); expect(after.response.status).toBe(201); - const filter = `chat_id = '${chat.id}' and status = 'pending' and filename = 's3down-${runId}.png'`; - await waitUntilExpired(filter); - await sweepNow(); - expect( - await psql(`select count(*) from attachments where ${filter}`), - ).toBe('0'); + // A `deleting` row is re-claimed one minute after its last change + // (an in-flight compensation is never raced), then swept. + const filter = `chat_id = '${chat.id}' and filename = 's3down-${runId}.png'`; + await waitFor( + async () => { + await sweepNow(); + return ( + (await psql( + `select count(*) from attachments where ${filter}`, + )) === '0' + ); + }, + async () => 'deleting row was not swept', + 90_000, + ); }, outagedRequestBudgetMs, ); it( - 'compensates the S3 write when PostgreSQL fails before ready', + 'keeps the object while PostgreSQL is down before ready and sweeps it afterwards', async () => { const data = noisePng(1024 * 1024); const filename = `pgfault-${runId}.png`; @@ -1017,13 +1027,16 @@ describe.skipIf(!enabled)('dependency outages', () => { `select object_key from attachments where ${filter}`, ); expect(key).toMatch(/^attachments\/[0-9a-f-]{36}\/original$/u); - expect(await objectExists(key)).toBe(false); + // Without PostgreSQL the API cannot tell a lost commit from a failed + // one, so it deletes nothing; the pending row keeps the object tracked. + expect(await objectExists(key)).toBe(true); await waitUntilExpired(filter); await sweepNow(); expect( await psql(`select count(*) from attachments where ${filter}`), ).toBe('0'); + expect(await objectExists(key)).toBe(false); }, outagedRequestBudgetMs, ); diff --git a/app/test/direct-upload.e2e-spec.ts b/app/test/direct-upload.e2e-spec.ts index f448dae3..0411595b 100644 --- a/app/test/direct-upload.e2e-spec.ts +++ b/app/test/direct-upload.e2e-spec.ts @@ -18,7 +18,7 @@ import { json, postMessage, } from './support/e2e.js'; -import { pixelBombPng } from './support/png.js'; +import { noisePng, pixelBombPng } from './support/png.js'; const png = readFileSync( new URL('../../tests/fixtures/sample.png', import.meta.url), @@ -243,6 +243,34 @@ describe('direct upload (presigned PUT)', () => { ); }); + it.each([ + ['truncated PNG', () => png.subarray(0, png.length - 100)], + [ + 'PNG damaged after the first 64 KiB', + () => { + const data = noisePng(1_048_576); + data[700_000] ^= 0xff; + return data; + }, + ], + ])('rejects a %s even with a matching checksum', async (_name, make) => { + // The declaration and the signed checksum match the bytes exactly: + // only a check of the whole image can tell they are not an image. + const data = make(); + const ticket = await initOk(data); + expect((await put(ticket, data)).status).toBe(200); + expectError( + await complete(alice.token, ticket.attachment_id), + 415, + 'unsupported_media_type', + ); + expectError( + await complete(alice.token, ticket.attachment_id), + 404, + 'not_found', + ); + }); + it('rejects a pixel bomb on complete', async () => { const bomb = pixelBombPng(); const ticket = await initOk(bomb); diff --git a/app/test/support/jpeg.ts b/app/test/support/jpeg.ts new file mode 100644 index 00000000..ea60571e --- /dev/null +++ b/app/test/support/jpeg.ts @@ -0,0 +1,10 @@ +/** Keeps every segment through the SOS header and drops the scan data. */ +export function jpegWithoutScanData(jpeg: Buffer): Buffer { + let offset = 2; + for (;;) { + const marker = jpeg[offset + 1]; + offset += 2 + jpeg.readUInt16BE(offset + 2); + if (marker === 0xda) break; + } + return Buffer.concat([jpeg.subarray(0, offset), Buffer.from([0xff, 0xd9])]); +} diff --git a/app/test/support/png.ts b/app/test/support/png.ts index 9dd29a41..714ce8af 100644 --- a/app/test/support/png.ts +++ b/app/test/support/png.ts @@ -93,3 +93,14 @@ export function noisePng(size: number): Buffer { return padPngTo(png, size); } } + +/** Valid signature, IHDR, CRCs and IEND around a zlib stream of random bytes. */ +export function pngWithGarbageIdat(): Buffer { + return buildPng({ + width: 320, + height: 200, + colorType: 2, + bitDepth: 8, + idat: randomBytes(5000), + }); +} diff --git a/evidence/lab4/bench/direct-1048576-c10.json b/evidence/lab4/bench/direct-1048576-c10.json index e6f9e3fd..3ea65699 100644 --- a/evidence/lab4/bench/direct-1048576-c10.json +++ b/evidence/lab4/bench/direct-1048576-c10.json @@ -1,6 +1,6 @@ { - "date": "2026-10-22T20:02:21+00:00", - "git": "f048a37", + "date": "2026-10-23T13:32:53+00:00", + "git": "b32ce9a", "params": { "mode": "direct", "size_bytes": 1048576, @@ -21,187 +21,193 @@ "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.542, + "duration_s": 0.939, "latency_ms": { - "p50": 69.2, - "p95": 101.4, - "p99": 125.5 + "p50": 168.0, + "p95": 249.0, + "p99": 276.8 }, "replicas": [ { - "instance_id": "01e84e9e9e38", - "delta_rx_bytes": 1732876, - "delta_tx_bytes": 185102, - "baseline_rss_bytes": 192851968, + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 32727785, + "delta_tx_bytes": 202005, + "baseline_rss_bytes": 227401728, "peak_memory_bytes": { - "rss": 192983040, - "heap_used": 51764168, - "external": 7874039, - "array_buffers": 4083695 + "rss": 237686784, + "heap_used": 55834912, + "external": 36616919, + "array_buffers": 32826575 }, - "delta_rss_bytes": 131072, + "delta_rss_bytes": 10285056, "counters": { - "attachments.count_pending_direct": 26, - "attachments.insert_pending": 26, - "attachments.direct.initiated": 26, - "attachments.find_for_complete": 24, - "attachments.direct.verify_bytes": 1572864, - "attachments.mark_ready": 24, - "attachments.direct.completed": 24 + "attachments.count_pending_direct": 19, + "attachments.insert_pending": 19, + "attachments.direct.initiated": 19, + "attachments.find_for_complete": 31, + "attachments.direct.verify_bytes": 32505856, + "attachments.decode.ms": 1715.4081129999686, + "attachments.mark_ready": 31, + "attachments.direct.completed": 31 } }, { - "instance_id": "d49b799653d6", - "delta_rx_bytes": 1868893, - "delta_tx_bytes": 186494, - "baseline_rss_bytes": 181489664, + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 20096072, + "delta_tx_bytes": 188541, + "baseline_rss_bytes": 215158784, "peak_memory_bytes": { - "rss": 182013952, - "heap_used": 53099792, - "external": 7642630, - "array_buffers": 3852254 + "rss": 219668480, + "heap_used": 53068512, + "external": 26447857, + "array_buffers": 22657513 }, - "delta_rss_bytes": 524288, + "delta_rss_bytes": 4509696, + "counters": { + "attachments.count_pending_direct": 31, + "attachments.insert_pending": 31, + "attachments.direct.initiated": 31, + "attachments.find_for_complete": 19, + "attachments.direct.verify_bytes": 19922944, + "attachments.decode.ms": 711.329723999952, + "attachments.mark_ready": 19, + "attachments.direct.completed": 19 + } + } + ], + "total_delta_rx_bytes": 52823857, + "total_delta_tx_bytes": 390546, + "rx_bytes_per_upload": 1056477, + "tx_bytes_per_upload": 7811, + "max_delta_rss_bytes": 10285056 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 0.91, + "latency_ms": { + "p50": 151.5, + "p95": 258.3, + "p99": 269.0 + }, + "replicas": [ + { + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 27461632, + "delta_tx_bytes": 190483, + "baseline_rss_bytes": 235499520, + "peak_memory_bytes": { + "rss": 235499520, + "heap_used": 55890664, + "external": 36465919, + "array_buffers": 32675575 + }, + "delta_rss_bytes": 0, "counters": { "attachments.count_pending_direct": 24, "attachments.insert_pending": 24, "attachments.direct.initiated": 24, "attachments.find_for_complete": 26, - "attachments.direct.verify_bytes": 1703936, + "attachments.direct.verify_bytes": 27262976, + "attachments.decode.ms": 1528.2079319999611, "attachments.mark_ready": 26, "attachments.direct.completed": 26 } + }, + { + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 25359054, + "delta_tx_bytes": 191385, + "baseline_rss_bytes": 209186816, + "peak_memory_bytes": { + "rss": 224399360, + "heap_used": 55409152, + "external": 31990072, + "array_buffers": 25029140 + }, + "delta_rss_bytes": 15212544, + "counters": { + "attachments.count_pending_direct": 26, + "attachments.insert_pending": 26, + "attachments.direct.initiated": 26, + "attachments.find_for_complete": 24, + "attachments.direct.verify_bytes": 25165824, + "attachments.decode.ms": 1024.5066690000385, + "attachments.mark_ready": 24, + "attachments.direct.completed": 24 + } } ], - "total_delta_rx_bytes": 3601769, - "total_delta_tx_bytes": 371596, - "rx_bytes_per_upload": 72035, - "tx_bytes_per_upload": 7432, - "max_delta_rss_bytes": 524288 + "total_delta_rx_bytes": 52820686, + "total_delta_tx_bytes": 381868, + "rx_bytes_per_upload": 1056414, + "tx_bytes_per_upload": 7637, + "max_delta_rss_bytes": 15212544 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.685, + "duration_s": 0.936, "latency_ms": { - "p50": 111.1, - "p95": 137.0, - "p99": 142.2 + "p50": 164.5, + "p95": 215.8, + "p99": 221.0 }, "replicas": [ { - "instance_id": "01e84e9e9e38", - "delta_rx_bytes": 1800815, - "delta_tx_bytes": 186876, - "baseline_rss_bytes": 192983040, + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 27463159, + "delta_tx_bytes": 187686, + "baseline_rss_bytes": 226234368, "peak_memory_bytes": { - "rss": 193507328, - "heap_used": 51579728, - "external": 6754919, - "array_buffers": 2800370 + "rss": 231608320, + "heap_used": 55751432, + "external": 34449311, + "array_buffers": 30658967 }, - "delta_rss_bytes": 524288, + "delta_rss_bytes": 5373952, "counters": { - "attachments.count_pending_direct": 25, - "attachments.insert_pending": 25, - "attachments.direct.initiated": 25, - "attachments.find_for_complete": 25, - "attachments.direct.verify_bytes": 1638400, - "attachments.mark_ready": 25, - "attachments.direct.completed": 25 + "attachments.count_pending_direct": 24, + "attachments.insert_pending": 24, + "attachments.direct.initiated": 24, + "attachments.find_for_complete": 26, + "attachments.direct.verify_bytes": 27262976, + "attachments.decode.ms": 975.2134359999909, + "attachments.mark_ready": 26, + "attachments.direct.completed": 26 } }, { - "instance_id": "d49b799653d6", - "delta_rx_bytes": 1800709, - "delta_tx_bytes": 185964, - "baseline_rss_bytes": 182013952, + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 25357194, + "delta_tx_bytes": 186994, + "baseline_rss_bytes": 223174656, "peak_memory_bytes": { - "rss": 182800384, - "heap_used": 53017320, - "external": 7914245, - "array_buffers": 4123869 + "rss": 225120256, + "heap_used": 53461888, + "external": 29769942, + "array_buffers": 25979406 }, - "delta_rss_bytes": 786432, + "delta_rss_bytes": 1945600, "counters": { - "attachments.count_pending_direct": 25, - "attachments.insert_pending": 25, - "attachments.direct.initiated": 25, - "attachments.find_for_complete": 25, - "attachments.direct.verify_bytes": 1638400, - "attachments.mark_ready": 25, - "attachments.direct.completed": 25 + "attachments.count_pending_direct": 26, + "attachments.insert_pending": 26, + "attachments.direct.initiated": 26, + "attachments.find_for_complete": 24, + "attachments.direct.verify_bytes": 25165824, + "attachments.decode.ms": 805.6966420000099, + "attachments.mark_ready": 24, + "attachments.direct.completed": 24 } } ], - "total_delta_rx_bytes": 3601524, - "total_delta_tx_bytes": 372840, - "rx_bytes_per_upload": 72030, - "tx_bytes_per_upload": 7457, - "max_delta_rss_bytes": 786432 - }, - { - "uploads": 50, - "succeeded": 50, - "failed": 0, - "duration_s": 0.552, - "latency_ms": { - "p50": 75.4, - "p95": 147.0, - "p99": 157.9 - }, - "replicas": [ - { - "instance_id": "01e84e9e9e38", - "delta_rx_bytes": 1801291, - "delta_tx_bytes": 185886, - "baseline_rss_bytes": 193396736, - "peak_memory_bytes": { - "rss": 194314240, - "heap_used": 52852056, - "external": 6737214, - "array_buffers": 2946870 - }, - "delta_rss_bytes": 917504, - "counters": { - "attachments.count_pending_direct": 25, - "attachments.insert_pending": 25, - "attachments.direct.initiated": 25, - "attachments.find_for_complete": 25, - "attachments.direct.verify_bytes": 1638400, - "attachments.mark_ready": 25, - "attachments.direct.completed": 25 - } - }, - { - "instance_id": "d49b799653d6", - "delta_rx_bytes": 1800711, - "delta_tx_bytes": 185106, - "baseline_rss_bytes": 182374400, - "peak_memory_bytes": { - "rss": 182374400, - "heap_used": 53283160, - "external": 7898022, - "array_buffers": 3970019 - }, - "delta_rss_bytes": 0, - "counters": { - "attachments.count_pending_direct": 25, - "attachments.insert_pending": 25, - "attachments.direct.initiated": 25, - "attachments.find_for_complete": 25, - "attachments.direct.verify_bytes": 1638400, - "attachments.mark_ready": 25, - "attachments.direct.completed": 25 - } - } - ], - "total_delta_rx_bytes": 3602002, - "total_delta_tx_bytes": 370992, - "rx_bytes_per_upload": 72040, - "tx_bytes_per_upload": 7420, - "max_delta_rss_bytes": 917504 + "total_delta_rx_bytes": 52820353, + "total_delta_tx_bytes": 374680, + "rx_bytes_per_upload": 1056407, + "tx_bytes_per_upload": 7494, + "max_delta_rss_bytes": 5373952 } ] } diff --git a/evidence/lab4/bench/direct-131072-c10.json b/evidence/lab4/bench/direct-131072-c10.json index 7c42ee97..5563c6b0 100644 --- a/evidence/lab4/bench/direct-131072-c10.json +++ b/evidence/lab4/bench/direct-131072-c10.json @@ -1,6 +1,6 @@ { - "date": "2026-10-22T20:02:09+00:00", - "git": "f048a37", + "date": "2026-10-23T13:32:40+00:00", + "git": "b32ce9a", "params": { "mode": "direct", "size_bytes": 131072, @@ -21,85 +21,87 @@ "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.242, + "duration_s": 0.421, "latency_ms": { - "p50": 43.2, - "p95": 56.1, - "p99": 59.7 + "p50": 68.3, + "p95": 104.0, + "p99": 117.0 }, "replicas": [ { - "instance_id": "01e84e9e9e38", - "delta_rx_bytes": 1869074, - "delta_tx_bytes": 185920, - "baseline_rss_bytes": 182263808, + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 3707052, + "delta_tx_bytes": 186917, + "baseline_rss_bytes": 193892352, "peak_memory_bytes": { - "rss": 182898688, - "heap_used": 53275328, - "external": 9220810, - "array_buffers": 5428348 + "rss": 195555328, + "heap_used": 52983040, + "external": 6914994, + "array_buffers": 3122532 }, - "delta_rss_bytes": 634880, + "delta_rss_bytes": 1662976, "counters": { - "attachments.count_pending_direct": 24, - "attachments.insert_pending": 24, - "attachments.direct.initiated": 24, - "attachments.find_for_complete": 26, - "attachments.direct.verify_bytes": 1703936, - "attachments.mark_ready": 26, - "attachments.direct.completed": 26 + "attachments.count_pending_direct": 23, + "attachments.insert_pending": 23, + "attachments.direct.initiated": 23, + "attachments.find_for_complete": 27, + "attachments.direct.verify_bytes": 3538944, + "attachments.decode.ms": 666.184485999991, + "attachments.mark_ready": 27, + "attachments.direct.completed": 27 } }, { - "instance_id": "d49b799653d6", - "delta_rx_bytes": 1732185, - "delta_tx_bytes": 183862, - "baseline_rss_bytes": 173453312, + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 3172669, + "delta_tx_bytes": 183467, + "baseline_rss_bytes": 194297856, "peak_memory_bytes": { - "rss": 173862912, - "heap_used": 51776512, - "external": 7372259, - "array_buffers": 3579797 + "rss": 196395008, + "heap_used": 53364080, + "external": 9480998, + "array_buffers": 5688536 }, - "delta_rss_bytes": 409600, + "delta_rss_bytes": 2097152, "counters": { - "attachments.count_pending_direct": 26, - "attachments.insert_pending": 26, - "attachments.direct.initiated": 26, - "attachments.find_for_complete": 24, - "attachments.direct.verify_bytes": 1572864, - "attachments.mark_ready": 24, - "attachments.direct.completed": 24 + "attachments.count_pending_direct": 27, + "attachments.insert_pending": 27, + "attachments.direct.initiated": 27, + "attachments.find_for_complete": 23, + "attachments.direct.verify_bytes": 3014656, + "attachments.decode.ms": 578.859613999979, + "attachments.mark_ready": 23, + "attachments.direct.completed": 23 } } ], - "total_delta_rx_bytes": 3601259, - "total_delta_tx_bytes": 369782, - "rx_bytes_per_upload": 72025, - "tx_bytes_per_upload": 7396, - "max_delta_rss_bytes": 634880 + "total_delta_rx_bytes": 6879721, + "total_delta_tx_bytes": 370384, + "rx_bytes_per_upload": 137594, + "tx_bytes_per_upload": 7408, + "max_delta_rss_bytes": 2097152 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.254, + "duration_s": 0.419, "latency_ms": { - "p50": 44.9, - "p95": 64.9, - "p99": 74.0 + "p50": 78.9, + "p95": 123.4, + "p99": 144.3 }, "replicas": [ { - "instance_id": "01e84e9e9e38", - "delta_rx_bytes": 1663798, - "delta_tx_bytes": 181411, - "baseline_rss_bytes": 182898688, + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 3172151, + "delta_tx_bytes": 182160, + "baseline_rss_bytes": 195555328, "peak_memory_bytes": { - "rss": 183029760, - "heap_used": 52623040, - "external": 9199397, - "array_buffers": 5406935 + "rss": 195686400, + "heap_used": 55040192, + "external": 7674854, + "array_buffers": 3882392 }, "delta_rss_bytes": 131072, "counters": { @@ -107,101 +109,105 @@ "attachments.insert_pending": 27, "attachments.direct.initiated": 27, "attachments.find_for_complete": 23, - "attachments.direct.verify_bytes": 1507328, + "attachments.direct.verify_bytes": 3014656, + "attachments.decode.ms": 521.6287550000125, "attachments.mark_ready": 23, "attachments.direct.completed": 23 } }, { - "instance_id": "d49b799653d6", - "delta_rx_bytes": 1936597, - "delta_tx_bytes": 185873, - "baseline_rss_bytes": 173862912, + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 3706567, + "delta_tx_bytes": 185794, + "baseline_rss_bytes": 196395008, "peak_memory_bytes": { - "rss": 174125056, - "heap_used": 53719328, - "external": 7649562, - "array_buffers": 3857100 + "rss": 196788224, + "heap_used": 53658784, + "external": 10141571, + "array_buffers": 6134972 }, - "delta_rss_bytes": 262144, + "delta_rss_bytes": 393216, "counters": { "attachments.count_pending_direct": 23, "attachments.insert_pending": 23, "attachments.direct.initiated": 23, "attachments.find_for_complete": 27, - "attachments.direct.verify_bytes": 1769472, + "attachments.direct.verify_bytes": 3538944, + "attachments.decode.ms": 674.9609369999744, "attachments.mark_ready": 27, "attachments.direct.completed": 27 } } ], - "total_delta_rx_bytes": 3600395, - "total_delta_tx_bytes": 367284, - "rx_bytes_per_upload": 72008, - "tx_bytes_per_upload": 7346, - "max_delta_rss_bytes": 262144 + "total_delta_rx_bytes": 6878718, + "total_delta_tx_bytes": 367954, + "rx_bytes_per_upload": 137574, + "tx_bytes_per_upload": 7359, + "max_delta_rss_bytes": 393216 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.441, + "duration_s": 0.395, "latency_ms": { - "p50": 80.3, - "p95": 124.0, - "p99": 127.6 + "p50": 67.0, + "p95": 95.3, + "p99": 116.5 }, "replicas": [ { - "instance_id": "01e84e9e9e38", - "delta_rx_bytes": 2007125, - "delta_tx_bytes": 186925, - "baseline_rss_bytes": 183029760, + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 3305839, + "delta_tx_bytes": 183731, + "baseline_rss_bytes": 191291392, "peak_memory_bytes": { - "rss": 183447552, - "heap_used": 56507192, - "external": 9369635, - "array_buffers": 5577173 + "rss": 192471040, + "heap_used": 56329664, + "external": 7513663, + "array_buffers": 3721201 }, - "delta_rss_bytes": 417792, + "delta_rss_bytes": 1179648, "counters": { - "attachments.count_pending_direct": 22, - "attachments.insert_pending": 22, - "attachments.direct.initiated": 22, - "attachments.find_for_complete": 28, - "attachments.direct.verify_bytes": 1835008, - "attachments.mark_ready": 28, - "attachments.direct.completed": 28 + "attachments.count_pending_direct": 26, + "attachments.insert_pending": 26, + "attachments.direct.initiated": 26, + "attachments.find_for_complete": 24, + "attachments.direct.verify_bytes": 3145728, + "attachments.decode.ms": 499.52755800001614, + "attachments.mark_ready": 24, + "attachments.direct.completed": 24 } }, { - "instance_id": "d49b799653d6", - "delta_rx_bytes": 1596449, - "delta_tx_bytes": 182757, - "baseline_rss_bytes": 174125056, + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 3572208, + "delta_tx_bytes": 183605, + "baseline_rss_bytes": 196788224, "peak_memory_bytes": { - "rss": 174387200, - "heap_used": 54337704, - "external": 7649635, - "array_buffers": 3857173 + "rss": 197181440, + "heap_used": 55084856, + "external": 7691196, + "array_buffers": 3898734 }, - "delta_rss_bytes": 262144, + "delta_rss_bytes": 393216, "counters": { - "attachments.count_pending_direct": 28, - "attachments.insert_pending": 28, - "attachments.direct.initiated": 28, - "attachments.find_for_complete": 22, - "attachments.direct.verify_bytes": 1441792, - "attachments.mark_ready": 22, - "attachments.direct.completed": 22 + "attachments.count_pending_direct": 24, + "attachments.insert_pending": 24, + "attachments.direct.initiated": 24, + "attachments.find_for_complete": 26, + "attachments.direct.verify_bytes": 3407872, + "attachments.decode.ms": 667.7248300000065, + "attachments.mark_ready": 26, + "attachments.direct.completed": 26 } } ], - "total_delta_rx_bytes": 3603574, - "total_delta_tx_bytes": 369682, - "rx_bytes_per_upload": 72071, - "tx_bytes_per_upload": 7394, - "max_delta_rss_bytes": 417792 + "total_delta_rx_bytes": 6878047, + "total_delta_tx_bytes": 367336, + "rx_bytes_per_upload": 137561, + "tx_bytes_per_upload": 7347, + "max_delta_rss_bytes": 1179648 } ] } diff --git a/evidence/lab4/bench/direct-9961472-c10.json b/evidence/lab4/bench/direct-9961472-c10.json index a06e0b5e..fc84204b 100644 --- a/evidence/lab4/bench/direct-9961472-c10.json +++ b/evidence/lab4/bench/direct-9961472-c10.json @@ -1,6 +1,6 @@ { - "date": "2026-10-22T20:02:47+00:00", - "git": "f048a37", + "date": "2026-10-23T13:33:31+00:00", + "git": "b32ce9a", "params": { "mode": "direct", "size_bytes": 9961472, @@ -21,23 +21,174 @@ "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 3.048, + "duration_s": 5.212, "latency_ms": { - "p50": 346.0, - "p95": 575.3, - "p99": 581.2 + "p50": 693.0, + "p95": 1084.0, + "p99": 1175.0 }, "replicas": [ { - "instance_id": "01e84e9e9e38", - "delta_rx_bytes": 1669140, - "delta_tx_bytes": 194261, - "baseline_rss_bytes": 189468672, + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 269480509, + "delta_tx_bytes": 305993, + "baseline_rss_bytes": 283983872, "peak_memory_bytes": { - "rss": 189468672, - "heap_used": 59441184, - "external": 6250789, - "array_buffers": 2449996 + "rss": 404570112, + "heap_used": 50680344, + "external": 123548186, + "array_buffers": 119757842 + }, + "delta_rss_bytes": 120586240, + "counters": { + "attachments.count_pending_direct": 23, + "attachments.insert_pending": 23, + "attachments.direct.initiated": 23, + "attachments.find_for_complete": 27, + "attachments.direct.verify_bytes": 268959744, + "attachments.decode.ms": 6438.860078999976, + "attachments.mark_ready": 27, + "attachments.direct.completed": 27 + } + }, + { + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 229561819, + "delta_tx_bytes": 313227, + "baseline_rss_bytes": 328466432, + "peak_memory_bytes": { + "rss": 385613824, + "heap_used": 52894936, + "external": 114148298, + "array_buffers": 110357821 + }, + "delta_rss_bytes": 57147392, + "counters": { + "attachments.count_pending_direct": 27, + "attachments.insert_pending": 27, + "attachments.direct.initiated": 27, + "attachments.find_for_complete": 23, + "attachments.direct.verify_bytes": 229113856, + "attachments.decode.ms": 5666.515076999989, + "attachments.mark_ready": 23, + "attachments.direct.completed": 23 + } + } + ], + "total_delta_rx_bytes": 499042328, + "total_delta_tx_bytes": 619220, + "rx_bytes_per_upload": 9980847, + "tx_bytes_per_upload": 12384, + "max_delta_rss_bytes": 120586240 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 4.689, + "latency_ms": { + "p50": 668.9, + "p95": 1081.6, + "p99": 1164.9 + }, + "replicas": [ + { + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 249519521, + "delta_tx_bytes": 283986, + "baseline_rss_bytes": 324087808, + "peak_memory_bytes": { + "rss": 408424448, + "heap_used": 51009296, + "external": 126698352, + "array_buffers": 122908008 + }, + "delta_rss_bytes": 84336640, + "counters": { + "attachments.count_pending_direct": 25, + "attachments.insert_pending": 25, + "attachments.direct.initiated": 25, + "attachments.find_for_complete": 25, + "attachments.direct.verify_bytes": 249036800, + "attachments.decode.ms": 6319.900557000001, + "attachments.mark_ready": 25, + "attachments.direct.completed": 25 + } + }, + { + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 249503096, + "delta_tx_bytes": 276564, + "baseline_rss_bytes": 320462848, + "peak_memory_bytes": { + "rss": 388620288, + "heap_used": 50687792, + "external": 135613815, + "array_buffers": 131823471 + }, + "delta_rss_bytes": 68157440, + "counters": { + "attachments.count_pending_direct": 25, + "attachments.insert_pending": 25, + "attachments.direct.initiated": 25, + "attachments.find_for_complete": 25, + "attachments.direct.verify_bytes": 249036800, + "attachments.decode.ms": 6777.923052999977, + "attachments.mark_ready": 25, + "attachments.direct.completed": 25 + } + } + ], + "total_delta_rx_bytes": 499022617, + "total_delta_tx_bytes": 560550, + "rx_bytes_per_upload": 9980452, + "tx_bytes_per_upload": 11211, + "max_delta_rss_bytes": 84336640 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 4.773, + "latency_ms": { + "p50": 695.7, + "p95": 1021.4, + "p99": 1371.6 + }, + "replicas": [ + { + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 269526599, + "delta_tx_bytes": 273432, + "baseline_rss_bytes": 303702016, + "peak_memory_bytes": { + "rss": 389439488, + "heap_used": 50333808, + "external": 124077219, + "array_buffers": 120286875 + }, + "delta_rss_bytes": 85737472, + "counters": { + "attachments.count_pending_direct": 23, + "attachments.insert_pending": 23, + "attachments.direct.initiated": 23, + "attachments.find_for_complete": 27, + "attachments.direct.verify_bytes": 268959744, + "attachments.decode.ms": 7513.258526999998, + "attachments.mark_ready": 27, + "attachments.direct.completed": 27 + } + }, + { + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 229549332, + "delta_tx_bytes": 263832, + "baseline_rss_bytes": 367620096, + "peak_memory_bytes": { + "rss": 367620096, + "heap_used": 50715496, + "external": 84222677, + "array_buffers": 80432333 }, "delta_rss_bytes": 0, "counters": { @@ -45,163 +196,18 @@ "attachments.insert_pending": 27, "attachments.direct.initiated": 27, "attachments.find_for_complete": 23, - "attachments.direct.verify_bytes": 1507328, + "attachments.direct.verify_bytes": 229113856, + "attachments.decode.ms": 6132.513337000011, "attachments.mark_ready": 23, "attachments.direct.completed": 23 } - }, - { - "instance_id": "d49b799653d6", - "delta_rx_bytes": 1940713, - "delta_tx_bytes": 195885, - "baseline_rss_bytes": 179376128, - "peak_memory_bytes": { - "rss": 180293632, - "heap_used": 59568768, - "external": 6672150, - "array_buffers": 2881806 - }, - "delta_rss_bytes": 917504, - "counters": { - "attachments.count_pending_direct": 23, - "attachments.insert_pending": 23, - "attachments.direct.initiated": 23, - "attachments.find_for_complete": 27, - "attachments.direct.verify_bytes": 1769472, - "attachments.mark_ready": 27, - "attachments.direct.completed": 27 - } } ], - "total_delta_rx_bytes": 3609853, - "total_delta_tx_bytes": 390146, - "rx_bytes_per_upload": 72197, - "tx_bytes_per_upload": 7803, - "max_delta_rss_bytes": 917504 - }, - { - "uploads": 50, - "succeeded": 50, - "failed": 0, - "duration_s": 2.948, - "latency_ms": { - "p50": 350.2, - "p95": 570.8, - "p99": 608.6 - }, - "replicas": [ - { - "instance_id": "01e84e9e9e38", - "delta_rx_bytes": 1803498, - "delta_tx_bytes": 194370, - "baseline_rss_bytes": 189468672, - "peak_memory_bytes": { - "rss": 189861888, - "heap_used": 59295328, - "external": 6363945, - "array_buffers": 2573569 - }, - "delta_rss_bytes": 393216, - "counters": { - "attachments.count_pending_direct": 25, - "attachments.insert_pending": 25, - "attachments.direct.initiated": 25, - "attachments.find_for_complete": 25, - "attachments.direct.verify_bytes": 1638400, - "attachments.mark_ready": 25, - "attachments.direct.completed": 25 - } - }, - { - "instance_id": "d49b799653d6", - "delta_rx_bytes": 1804525, - "delta_tx_bytes": 194742, - "baseline_rss_bytes": 179740672, - "peak_memory_bytes": { - "rss": 179740672, - "heap_used": 59420128, - "external": 6260844, - "array_buffers": 2470500 - }, - "delta_rss_bytes": 0, - "counters": { - "attachments.count_pending_direct": 25, - "attachments.insert_pending": 25, - "attachments.direct.initiated": 25, - "attachments.find_for_complete": 25, - "attachments.direct.verify_bytes": 1638400, - "attachments.mark_ready": 25, - "attachments.direct.completed": 25 - } - } - ], - "total_delta_rx_bytes": 3608023, - "total_delta_tx_bytes": 389112, - "rx_bytes_per_upload": 72160, - "tx_bytes_per_upload": 7782, - "max_delta_rss_bytes": 393216 - }, - { - "uploads": 50, - "succeeded": 50, - "failed": 0, - "duration_s": 2.556, - "latency_ms": { - "p50": 314.1, - "p95": 425.2, - "p99": 453.1 - }, - "replicas": [ - { - "instance_id": "01e84e9e9e38", - "delta_rx_bytes": 1531515, - "delta_tx_bytes": 190497, - "baseline_rss_bytes": 189861888, - "peak_memory_bytes": { - "rss": 190910464, - "heap_used": 60034376, - "external": 6373249, - "array_buffers": 2582873 - }, - "delta_rss_bytes": 1048576, - "counters": { - "attachments.count_pending_direct": 29, - "attachments.insert_pending": 29, - "attachments.direct.initiated": 29, - "attachments.find_for_complete": 21, - "attachments.direct.verify_bytes": 1376256, - "attachments.mark_ready": 21, - "attachments.direct.completed": 21 - } - }, - { - "instance_id": "d49b799653d6", - "delta_rx_bytes": 2076238, - "delta_tx_bytes": 196531, - "baseline_rss_bytes": 179740672, - "peak_memory_bytes": { - "rss": 179740672, - "heap_used": 59642168, - "external": 6672708, - "array_buffers": 2755498 - }, - "delta_rss_bytes": 0, - "counters": { - "attachments.count_pending_direct": 21, - "attachments.insert_pending": 21, - "attachments.direct.initiated": 21, - "attachments.find_for_complete": 29, - "attachments.direct.verify_bytes": 1900544, - "attachments.mark_ready": 29, - "attachments.direct.completed": 29 - } - } - ], - "total_delta_rx_bytes": 3607753, - "total_delta_tx_bytes": 387028, - "rx_bytes_per_upload": 72155, - "tx_bytes_per_upload": 7741, - "max_delta_rss_bytes": 1048576 + "total_delta_rx_bytes": 499075931, + "total_delta_tx_bytes": 537264, + "rx_bytes_per_upload": 9981519, + "tx_bytes_per_upload": 10745, + "max_delta_rss_bytes": 85737472 } ] } diff --git a/evidence/lab4/bench/proxy-1048576-c10.json b/evidence/lab4/bench/proxy-1048576-c10.json index 603094f6..ea636ea8 100644 --- a/evidence/lab4/bench/proxy-1048576-c10.json +++ b/evidence/lab4/bench/proxy-1048576-c10.json @@ -1,6 +1,6 @@ { - "date": "2026-10-22T20:02:15+00:00", - "git": "f048a37", + "date": "2026-10-23T13:32:46+00:00", + "git": "b32ce9a", "params": { "mode": "proxy", "size_bytes": 1048576, @@ -21,175 +21,181 @@ "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.369, + "duration_s": 0.854, "latency_ms": { - "p50": 46.4, - "p95": 68.3, - "p99": 72.8 + "p50": 142.8, + "p95": 192.1, + "p99": 208.3 }, "replicas": [ { - "instance_id": "01e84e9e9e38", - "delta_rx_bytes": 26390991, - "delta_tx_bytes": 26399463, - "baseline_rss_bytes": 183496704, + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 26385133, + "delta_tx_bytes": 26401283, + "baseline_rss_bytes": 197070848, "peak_memory_bytes": { - "rss": 188407808, - "heap_used": 58350032, - "external": 15612927, - "array_buffers": 11820465 + "rss": 217759744, + "heap_used": 55062960, + "external": 22455454, + "array_buffers": 18665110 }, - "delta_rss_bytes": 4911104, + "delta_rss_bytes": 20688896, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, + "attachments.decode.ms": 1479.7760639999906, "attachments.proxy.bytes_to_s3": 26214400, "attachments.mark_ready": 25, "attachments.upload.created": 25 } }, { - "instance_id": "d49b799653d6", - "delta_rx_bytes": 26389902, - "delta_tx_bytes": 26401063, - "baseline_rss_bytes": 172593152, + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 26379459, + "delta_tx_bytes": 26398957, + "baseline_rss_bytes": 199708672, "peak_memory_bytes": { - "rss": 179159040, - "heap_used": 51726640, - "external": 10983870, - "array_buffers": 7191408 + "rss": 214302720, + "heap_used": 55570040, + "external": 24543846, + "array_buffers": 20174104 }, - "delta_rss_bytes": 6565888, + "delta_rss_bytes": 14594048, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, + "attachments.decode.ms": 1331.2164019999764, "attachments.proxy.bytes_to_s3": 26214400, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 52780893, - "total_delta_tx_bytes": 52800526, - "rx_bytes_per_upload": 1055618, - "tx_bytes_per_upload": 1056011, - "max_delta_rss_bytes": 6565888 + "total_delta_rx_bytes": 52764592, + "total_delta_tx_bytes": 52800240, + "rx_bytes_per_upload": 1055292, + "tx_bytes_per_upload": 1056005, + "max_delta_rss_bytes": 20688896 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.55, + "duration_s": 0.82, "latency_ms": { - "p50": 59.3, - "p95": 210.6, - "p99": 226.6 + "p50": 137.2, + "p95": 181.4, + "p99": 245.1 }, "replicas": [ { - "instance_id": "01e84e9e9e38", - "delta_rx_bytes": 26377432, - "delta_tx_bytes": 26403430, - "baseline_rss_bytes": 188645376, + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 26381801, + "delta_tx_bytes": 26401373, + "baseline_rss_bytes": 217759744, "peak_memory_bytes": { - "rss": 193232896, - "heap_used": 52490432, - "external": 19098493, - "array_buffers": 15306617 + "rss": 220250112, + "heap_used": 50014112, + "external": 24298087, + "array_buffers": 20507743 }, - "delta_rss_bytes": 4587520, + "delta_rss_bytes": 2490368, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, + "attachments.decode.ms": 1444.9002450000553, "attachments.proxy.bytes_to_s3": 26214400, "attachments.mark_ready": 25, "attachments.upload.created": 25 } }, { - "instance_id": "d49b799653d6", - "delta_rx_bytes": 26383216, - "delta_tx_bytes": 26401660, - "baseline_rss_bytes": 179159040, + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 26383381, + "delta_tx_bytes": 26401803, + "baseline_rss_bytes": 209428480, "peak_memory_bytes": { - "rss": 179486720, - "heap_used": 49462912, - "external": 15506324, - "array_buffers": 11714604 + "rss": 212426752, + "heap_used": 49637440, + "external": 21932135, + "array_buffers": 18141791 }, - "delta_rss_bytes": 327680, + "delta_rss_bytes": 2998272, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, + "attachments.decode.ms": 1494.1810810000025, "attachments.proxy.bytes_to_s3": 26214400, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 52760648, - "total_delta_tx_bytes": 52805090, - "rx_bytes_per_upload": 1055213, - "tx_bytes_per_upload": 1056102, - "max_delta_rss_bytes": 4587520 + "total_delta_rx_bytes": 52765182, + "total_delta_tx_bytes": 52803176, + "rx_bytes_per_upload": 1055304, + "tx_bytes_per_upload": 1056064, + "max_delta_rss_bytes": 2998272 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.461, + "duration_s": 0.818, "latency_ms": { - "p50": 67.3, - "p95": 109.8, - "p99": 118.7 + "p50": 146.1, + "p95": 209.1, + "p99": 245.9 }, "replicas": [ { - "instance_id": "01e84e9e9e38", - "delta_rx_bytes": 26385813, - "delta_tx_bytes": 26399597, - "baseline_rss_bytes": 193232896, + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 26379700, + "delta_tx_bytes": 26402387, + "baseline_rss_bytes": 216440832, "peak_memory_bytes": { - "rss": 194363392, - "heap_used": 51280880, - "external": 19455489, - "array_buffers": 15663613 + "rss": 229879808, + "heap_used": 52186344, + "external": 34161027, + "array_buffers": 30370683 }, - "delta_rss_bytes": 1130496, + "delta_rss_bytes": 13438976, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, + "attachments.decode.ms": 1491.96600400006, "attachments.proxy.bytes_to_s3": 26214400, "attachments.mark_ready": 25, "attachments.upload.created": 25 } }, { - "instance_id": "d49b799653d6", - "delta_rx_bytes": 26391095, - "delta_tx_bytes": 26404143, - "baseline_rss_bytes": 178298880, + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 26384562, + "delta_tx_bytes": 26402573, + "baseline_rss_bytes": 212082688, "peak_memory_bytes": { - "rss": 181444608, - "heap_used": 50462384, - "external": 17515725, - "array_buffers": 13659712 + "rss": 217251840, + "heap_used": 51036376, + "external": 26410042, + "array_buffers": 22619698 }, - "delta_rss_bytes": 3145728, + "delta_rss_bytes": 5169152, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, + "attachments.decode.ms": 1386.4965829999855, "attachments.proxy.bytes_to_s3": 26214400, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 52776908, - "total_delta_tx_bytes": 52803740, - "rx_bytes_per_upload": 1055538, - "tx_bytes_per_upload": 1056075, - "max_delta_rss_bytes": 3145728 + "total_delta_rx_bytes": 52764262, + "total_delta_tx_bytes": 52804960, + "rx_bytes_per_upload": 1055285, + "tx_bytes_per_upload": 1056099, + "max_delta_rss_bytes": 13438976 } ] } diff --git a/evidence/lab4/bench/proxy-131072-c10.json b/evidence/lab4/bench/proxy-131072-c10.json index 9b85fd70..84939c02 100644 --- a/evidence/lab4/bench/proxy-131072-c10.json +++ b/evidence/lab4/bench/proxy-131072-c10.json @@ -1,6 +1,6 @@ { - "date": "2026-10-22T20:02:04+00:00", - "git": "f048a37", + "date": "2026-10-23T13:32:35+00:00", + "git": "b32ce9a", "params": { "mode": "proxy", "size_bytes": 131072, @@ -21,175 +21,183 @@ "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.221, + "duration_s": 0.363, "latency_ms": { - "p50": 32.5, - "p95": 61.7, - "p99": 75.6 + "p50": 60.4, + "p95": 113.2, + "p99": 139.1 }, "replicas": [ { - "instance_id": "01e84e9e9e38", - "delta_rx_bytes": 3382582, - "delta_tx_bytes": 3398177, - "baseline_rss_bytes": 172421120, + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 3381618, + "delta_tx_bytes": 3399633, + "baseline_rss_bytes": 180125696, "peak_memory_bytes": { - "rss": 177926144, - "heap_used": 50033192, - "external": 7706616, - "array_buffers": 3914122 + "rss": 187985920, + "heap_used": 50414440, + "external": 8673461, + "array_buffers": 4505870 }, - "delta_rss_bytes": 5505024, + "delta_rss_bytes": 7860224, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, + "attachments.decode.ms": 528.2537349999984, "attachments.proxy.bytes_to_s3": 3276800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } }, { - "instance_id": "d49b799653d6", - "delta_rx_bytes": 3380734, - "delta_tx_bytes": 3397755, - "baseline_rss_bytes": 164986880, + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 3384159, + "delta_tx_bytes": 3399409, + "baseline_rss_bytes": 181567488, "peak_memory_bytes": { - "rss": 170360832, - "heap_used": 49897896, - "external": 7704663, - "array_buffers": 3911977 + "rss": 189956096, + "heap_used": 51892912, + "external": 9517393, + "array_buffers": 5724803 }, - "delta_rss_bytes": 5373952, + "delta_rss_bytes": 8388608, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, + "attachments.decode.ms": 670.2341740000047, "attachments.proxy.bytes_to_s3": 3276800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 6763316, - "total_delta_tx_bytes": 6795932, - "rx_bytes_per_upload": 135266, - "tx_bytes_per_upload": 135919, - "max_delta_rss_bytes": 5505024 + "total_delta_rx_bytes": 6765777, + "total_delta_tx_bytes": 6799042, + "rx_bytes_per_upload": 135316, + "tx_bytes_per_upload": 135981, + "max_delta_rss_bytes": 8388608 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.178, + "duration_s": 0.351, "latency_ms": { - "p50": 30.3, - "p95": 39.9, - "p99": 40.8 + "p50": 51.1, + "p95": 105.8, + "p99": 118.4 }, "replicas": [ { - "instance_id": "01e84e9e9e38", - "delta_rx_bytes": 3378937, - "delta_tx_bytes": 3395467, - "baseline_rss_bytes": 177926144, + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 3380483, + "delta_tx_bytes": 3398895, + "baseline_rss_bytes": 187985920, "peak_memory_bytes": { - "rss": 181886976, - "heap_used": 51028472, - "external": 10337544, - "array_buffers": 6545050 + "rss": 190345216, + "heap_used": 52699440, + "external": 10502334, + "array_buffers": 6709680 }, - "delta_rss_bytes": 3960832, + "delta_rss_bytes": 2359296, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, + "attachments.decode.ms": 633.1175999999905, "attachments.proxy.bytes_to_s3": 3276800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } }, { - "instance_id": "d49b799653d6", - "delta_rx_bytes": 3380009, - "delta_tx_bytes": 3397063, - "baseline_rss_bytes": 170360832, + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 3376222, + "delta_tx_bytes": 3395913, + "baseline_rss_bytes": 189956096, "peak_memory_bytes": { - "rss": 171278336, - "heap_used": 50939136, - "external": 8430160, - "array_buffers": 4637666 + "rss": 193220608, + "heap_used": 52790776, + "external": 10858460, + "array_buffers": 7065998 }, - "delta_rss_bytes": 917504, + "delta_rss_bytes": 3264512, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, + "attachments.decode.ms": 359.4751439999891, "attachments.proxy.bytes_to_s3": 3276800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 6758946, - "total_delta_tx_bytes": 6792530, - "rx_bytes_per_upload": 135179, - "tx_bytes_per_upload": 135851, - "max_delta_rss_bytes": 3960832 + "total_delta_rx_bytes": 6756705, + "total_delta_tx_bytes": 6794808, + "rx_bytes_per_upload": 135134, + "tx_bytes_per_upload": 135896, + "max_delta_rss_bytes": 3264512 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.291, + "duration_s": 0.354, "latency_ms": { - "p50": 41.2, - "p95": 87.2, - "p99": 93.6 + "p50": 60.3, + "p95": 96.3, + "p99": 120.9 }, "replicas": [ { - "instance_id": "01e84e9e9e38", - "delta_rx_bytes": 3377137, - "delta_tx_bytes": 3395161, - "baseline_rss_bytes": 181886976, + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 3377197, + "delta_tx_bytes": 3396754, + "baseline_rss_bytes": 190345216, "peak_memory_bytes": { - "rss": 182149120, - "heap_used": 51984832, - "external": 9554628, - "array_buffers": 5762166 + "rss": 193884160, + "heap_used": 53140928, + "external": 13245272, + "array_buffers": 9452618 }, - "delta_rss_bytes": 262144, + "delta_rss_bytes": 3538944, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, + "attachments.decode.ms": 518.702403999996, "attachments.proxy.bytes_to_s3": 3276800, "attachments.mark_ready": 25, - "attachments.upload.created": 25 + "attachments.upload.created": 25, + "attachments.claim_expired": 1 } }, { - "instance_id": "d49b799653d6", - "delta_rx_bytes": 3377713, - "delta_tx_bytes": 3396473, - "baseline_rss_bytes": 171278336, + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 3377745, + "delta_tx_bytes": 3397208, + "baseline_rss_bytes": 193220608, "peak_memory_bytes": { - "rss": 173244416, - "heap_used": 52256384, - "external": 10276505, - "array_buffers": 6484011 + "rss": 193744896, + "heap_used": 52880424, + "external": 11681352, + "array_buffers": 7888698 }, - "delta_rss_bytes": 1966080, + "delta_rss_bytes": 524288, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, + "attachments.decode.ms": 643.8722639999905, "attachments.proxy.bytes_to_s3": 3276800, "attachments.mark_ready": 25, - "attachments.upload.created": 25 + "attachments.upload.created": 25, + "attachments.claim_expired": 1 } } ], - "total_delta_rx_bytes": 6754850, - "total_delta_tx_bytes": 6791634, - "rx_bytes_per_upload": 135097, - "tx_bytes_per_upload": 135833, - "max_delta_rss_bytes": 1966080 + "total_delta_rx_bytes": 6754942, + "total_delta_tx_bytes": 6793962, + "rx_bytes_per_upload": 135099, + "tx_bytes_per_upload": 135879, + "max_delta_rss_bytes": 3538944 } ] } diff --git a/evidence/lab4/bench/proxy-9961472-c10.json b/evidence/lab4/bench/proxy-9961472-c10.json index 39652201..d41c413e 100644 --- a/evidence/lab4/bench/proxy-9961472-c10.json +++ b/evidence/lab4/bench/proxy-9961472-c10.json @@ -1,6 +1,6 @@ { - "date": "2026-10-22T20:02:34+00:00", - "git": "f048a37", + "date": "2026-10-23T13:33:12+00:00", + "git": "b32ce9a", "params": { "mode": "proxy", "size_bytes": 9961472, @@ -21,177 +21,181 @@ "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 2.923, + "duration_s": 4.768, "latency_ms": { - "p50": 217.7, - "p95": 393.7, - "p99": 469.2 + "p50": 712.4, + "p95": 946.8, + "p99": 1012.6 }, "replicas": [ { - "instance_id": "01e84e9e9e38", - "delta_rx_bytes": 249719999, - "delta_tx_bytes": 249864966, - "baseline_rss_bytes": 193277952, + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 249658454, + "delta_tx_bytes": 249823407, + "baseline_rss_bytes": 252616704, "peak_memory_bytes": { - "rss": 208244736, - "heap_used": 49103680, - "external": 38092148, - "array_buffers": 31938886 + "rss": 364154880, + "heap_used": 49794104, + "external": 95705802, + "array_buffers": 78688662 }, - "delta_rss_bytes": 14966784, + "delta_rss_bytes": 111538176, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, + "attachments.decode.ms": 7843.138166000004, "attachments.proxy.bytes_to_s3": 249036800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } }, { - "instance_id": "d49b799653d6", - "delta_rx_bytes": 249670108, - "delta_tx_bytes": 249826185, - "baseline_rss_bytes": 178913280, + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 249677855, + "delta_tx_bytes": 249819092, + "baseline_rss_bytes": 228974592, "peak_memory_bytes": { - "rss": 195375104, - "heap_used": 48823672, - "external": 30056217, - "array_buffers": 26265873 + "rss": 359043072, + "heap_used": 50979480, + "external": 105502404, + "array_buffers": 101712060 }, - "delta_rss_bytes": 16461824, + "delta_rss_bytes": 130068480, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, + "attachments.decode.ms": 7969.015626000037, "attachments.proxy.bytes_to_s3": 249036800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 499390107, - "total_delta_tx_bytes": 499691151, - "rx_bytes_per_upload": 9987802, - "tx_bytes_per_upload": 9993823, - "max_delta_rss_bytes": 16461824 + "total_delta_rx_bytes": 499336309, + "total_delta_tx_bytes": 499642499, + "rx_bytes_per_upload": 9986726, + "tx_bytes_per_upload": 9992850, + "max_delta_rss_bytes": 130068480 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 3.32, + "duration_s": 4.843, "latency_ms": { - "p50": 277.4, - "p95": 513.9, - "p99": 548.1 + "p50": 687.8, + "p95": 997.1, + "p99": 1046.8 }, "replicas": [ { - "instance_id": "01e84e9e9e38", - "delta_rx_bytes": 249653538, - "delta_tx_bytes": 249812864, - "baseline_rss_bytes": 193380352, + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 249636288, + "delta_tx_bytes": 249801589, + "baseline_rss_bytes": 349237248, "peak_memory_bytes": { - "rss": 208535552, - "heap_used": 49665920, - "external": 36105007, - "array_buffers": 32313340 + "rss": 367636480, + "heap_used": 50033840, + "external": 85069927, + "array_buffers": 81278745 }, - "delta_rss_bytes": 15155200, + "delta_rss_bytes": 18399232, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, - "attachments.claim_expired": 1, + "attachments.decode.ms": 7391.692848000006, "attachments.proxy.bytes_to_s3": 249036800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } }, { - "instance_id": "d49b799653d6", - "delta_rx_bytes": 249644423, - "delta_tx_bytes": 249817785, - "baseline_rss_bytes": 194199552, + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 249653773, + "delta_tx_bytes": 249814308, + "baseline_rss_bytes": 270807040, "peak_memory_bytes": { - "rss": 208871424, - "heap_used": 50742312, - "external": 43475182, - "array_buffers": 39684838 + "rss": 336084992, + "heap_used": 49357656, + "external": 85003828, + "array_buffers": 81213484 }, - "delta_rss_bytes": 14671872, + "delta_rss_bytes": 65277952, "counters": { "attachments.insert_pending": 25, - "attachments.claim_expired": 1, "attachments.proxy.bytes_in": 249036800, + "attachments.decode.ms": 7897.397337000031, "attachments.proxy.bytes_to_s3": 249036800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 499297961, - "total_delta_tx_bytes": 499630649, - "rx_bytes_per_upload": 9985959, - "tx_bytes_per_upload": 9992613, - "max_delta_rss_bytes": 15155200 + "total_delta_rx_bytes": 499290061, + "total_delta_tx_bytes": 499615897, + "rx_bytes_per_upload": 9985801, + "tx_bytes_per_upload": 9992318, + "max_delta_rss_bytes": 65277952 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 3.07, + "duration_s": 4.694, "latency_ms": { - "p50": 238.9, - "p95": 391.0, - "p99": 423.1 + "p50": 637.3, + "p95": 848.8, + "p99": 979.4 }, "replicas": [ { - "instance_id": "01e84e9e9e38", - "delta_rx_bytes": 249690323, - "delta_tx_bytes": 249843279, - "baseline_rss_bytes": 193445888, + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 249629894, + "delta_tx_bytes": 249780802, + "baseline_rss_bytes": 322142208, "peak_memory_bytes": { - "rss": 212447232, - "heap_used": 48981896, - "external": 28322088, - "array_buffers": 24531744 + "rss": 366731264, + "heap_used": 50163968, + "external": 85133242, + "array_buffers": 81342898 }, - "delta_rss_bytes": 19001344, + "delta_rss_bytes": 44589056, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, + "attachments.decode.ms": 7874.299524000016, "attachments.proxy.bytes_to_s3": 249036800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } }, { - "instance_id": "d49b799653d6", - "delta_rx_bytes": 249684428, - "delta_tx_bytes": 249830235, - "baseline_rss_bytes": 200146944, + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 249682445, + "delta_tx_bytes": 249837698, + "baseline_rss_bytes": 325865472, "peak_memory_bytes": { - "rss": 200146944, - "heap_used": 48496592, - "external": 26712221, - "array_buffers": 22921877 + "rss": 365383680, + "heap_used": 50007528, + "external": 84862098, + "array_buffers": 81070915 }, - "delta_rss_bytes": 0, + "delta_rss_bytes": 39518208, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, + "attachments.decode.ms": 7699.224510000015, "attachments.proxy.bytes_to_s3": 249036800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 499374751, - "total_delta_tx_bytes": 499673514, - "rx_bytes_per_upload": 9987495, - "tx_bytes_per_upload": 9993470, - "max_delta_rss_bytes": 19001344 + "total_delta_rx_bytes": 499312339, + "total_delta_tx_bytes": 499618500, + "rx_bytes_per_upload": 9986247, + "tx_bytes_per_upload": 9992370, + "max_delta_rss_bytes": 44589056 } ] } diff --git a/evidence/lab4/bench/proxy-9961472-c20.json b/evidence/lab4/bench/proxy-9961472-c20.json index c5299ab1..34dbd64c 100644 --- a/evidence/lab4/bench/proxy-9961472-c20.json +++ b/evidence/lab4/bench/proxy-9961472-c20.json @@ -1,6 +1,6 @@ { - "date": "2026-10-22T20:03:09+00:00", - "git": "f048a37", + "date": "2026-10-23T13:34:02+00:00", + "git": "b32ce9a", "params": { "mode": "proxy", "size_bytes": 9961472, @@ -21,175 +21,185 @@ "uploads": 100, "succeeded": 100, "failed": 0, - "duration_s": 5.789, + "duration_s": 8.965, "latency_ms": { - "p50": 409.2, - "p95": 812.5, - "p99": 959.0 + "p50": 1396.5, + "p95": 1795.3, + "p99": 1927.7 }, "replicas": [ { - "instance_id": "01e84e9e9e38", - "delta_rx_bytes": 499859990, - "delta_tx_bytes": 500110302, - "baseline_rss_bytes": 189095936, + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 500201125, + "delta_tx_bytes": 500377070, + "baseline_rss_bytes": 305356800, "peak_memory_bytes": { - "rss": 209506304, - "heap_used": 49551104, - "external": 37459480, - "array_buffers": 28998398 + "rss": 434417664, + "heap_used": 51274840, + "external": 145565797, + "array_buffers": 141709917 }, - "delta_rss_bytes": 20410368, + "delta_rss_bytes": 129060864, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, + "attachments.decode.ms": 15301.763066, "attachments.proxy.bytes_to_s3": 498073600, "attachments.mark_ready": 50, - "attachments.upload.created": 50 + "attachments.upload.created": 50, + "attachments.claim_expired": 1, + "attachments.delete_claimed": 2, + "attachments.sweep.deleted": 2 } }, { - "instance_id": "d49b799653d6", - "delta_rx_bytes": 499688844, - "delta_tx_bytes": 499961376, - "baseline_rss_bytes": 179896320, + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 499840721, + "delta_tx_bytes": 500065968, + "baseline_rss_bytes": 315572224, "peak_memory_bytes": { - "rss": 201883648, - "heap_used": 48903104, - "external": 30171785, - "array_buffers": 23259151 + "rss": 417861632, + "heap_used": 51333520, + "external": 141534029, + "array_buffers": 137743685 }, - "delta_rss_bytes": 21987328, + "delta_rss_bytes": 102289408, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, + "attachments.decode.ms": 15764.19308799997, "attachments.proxy.bytes_to_s3": 498073600, "attachments.mark_ready": 50, - "attachments.upload.created": 50 + "attachments.upload.created": 50, + "attachments.claim_expired": 1 } } ], - "total_delta_rx_bytes": 999548834, - "total_delta_tx_bytes": 1000071678, - "rx_bytes_per_upload": 9995488, - "tx_bytes_per_upload": 10000717, - "max_delta_rss_bytes": 21987328 + "total_delta_rx_bytes": 1000041846, + "total_delta_tx_bytes": 1000443038, + "rx_bytes_per_upload": 10000418, + "tx_bytes_per_upload": 10004430, + "max_delta_rss_bytes": 129060864 }, { "uploads": 100, "succeeded": 100, "failed": 0, - "duration_s": 5.789, + "duration_s": 8.87, "latency_ms": { - "p50": 406.7, - "p95": 756.8, - "p99": 1110.8 + "p50": 1327.7, + "p95": 1753.9, + "p99": 2016.9 }, "replicas": [ { - "instance_id": "01e84e9e9e38", - "delta_rx_bytes": 499409660, - "delta_tx_bytes": 499704231, - "baseline_rss_bytes": 204034048, + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 500384354, + "delta_tx_bytes": 500549484, + "baseline_rss_bytes": 405041152, "peak_memory_bytes": { - "rss": 216682496, - "heap_used": 50958080, - "external": 42044393, - "array_buffers": 38254049 + "rss": 442638336, + "heap_used": 51584448, + "external": 136101545, + "array_buffers": 132311201 }, - "delta_rss_bytes": 12648448, + "delta_rss_bytes": 37597184, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, + "attachments.decode.ms": 15850.254651000054, "attachments.proxy.bytes_to_s3": 498073600, "attachments.mark_ready": 50, "attachments.upload.created": 50 } }, { - "instance_id": "d49b799653d6", - "delta_rx_bytes": 499385236, - "delta_tx_bytes": 499657364, - "baseline_rss_bytes": 196177920, + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 500629918, + "delta_tx_bytes": 500817708, + "baseline_rss_bytes": 379080704, "peak_memory_bytes": { - "rss": 208781312, - "heap_used": 49416712, - "external": 29886702, - "array_buffers": 26096358 + "rss": 435548160, + "heap_used": 51076952, + "external": 146391435, + "array_buffers": 142601091 }, - "delta_rss_bytes": 12603392, + "delta_rss_bytes": 56467456, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, + "attachments.decode.ms": 15065.693191000057, "attachments.proxy.bytes_to_s3": 498073600, "attachments.mark_ready": 50, "attachments.upload.created": 50 } } ], - "total_delta_rx_bytes": 998794896, - "total_delta_tx_bytes": 999361595, - "rx_bytes_per_upload": 9987949, - "tx_bytes_per_upload": 9993616, - "max_delta_rss_bytes": 12648448 + "total_delta_rx_bytes": 1001014272, + "total_delta_tx_bytes": 1001367192, + "rx_bytes_per_upload": 10010143, + "tx_bytes_per_upload": 10013672, + "max_delta_rss_bytes": 56467456 }, { "uploads": 100, "succeeded": 100, "failed": 0, - "duration_s": 6.222, + "duration_s": 9.117, "latency_ms": { - "p50": 452.3, - "p95": 913.7, - "p99": 1284.1 + "p50": 1442.2, + "p95": 1862.3, + "p99": 1962.7 }, "replicas": [ { - "instance_id": "01e84e9e9e38", - "delta_rx_bytes": 499462554, - "delta_tx_bytes": 499707805, - "baseline_rss_bytes": 208515072, + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 499434564, + "delta_tx_bytes": 499705234, + "baseline_rss_bytes": 421199872, "peak_memory_bytes": { - "rss": 213237760, - "heap_used": 50201400, - "external": 39684000, - "array_buffers": 35893464 + "rss": 441876480, + "heap_used": 50736392, + "external": 135949482, + "array_buffers": 132036017 }, - "delta_rss_bytes": 4722688, + "delta_rss_bytes": 20676608, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, + "attachments.decode.ms": 16234.571914999979, "attachments.proxy.bytes_to_s3": 498073600, "attachments.mark_ready": 50, "attachments.upload.created": 50 } }, { - "instance_id": "d49b799653d6", - "delta_rx_bytes": 499435292, - "delta_tx_bytes": 499704897, - "baseline_rss_bytes": 192315392, + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 499505499, + "delta_tx_bytes": 499795523, + "baseline_rss_bytes": 348524544, "peak_memory_bytes": { - "rss": 209580032, - "heap_used": 50343440, - "external": 38677040, - "array_buffers": 34886696 + "rss": 441692160, + "heap_used": 50551064, + "external": 136342743, + "array_buffers": 132552399 }, - "delta_rss_bytes": 17264640, + "delta_rss_bytes": 93167616, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, + "attachments.decode.ms": 16105.769058999955, "attachments.proxy.bytes_to_s3": 498073600, "attachments.mark_ready": 50, "attachments.upload.created": 50 } } ], - "total_delta_rx_bytes": 998897846, - "total_delta_tx_bytes": 999412702, - "rx_bytes_per_upload": 9988978, - "tx_bytes_per_upload": 9994127, - "max_delta_rss_bytes": 17264640 + "total_delta_rx_bytes": 998940063, + "total_delta_tx_bytes": 999500757, + "rx_bytes_per_upload": 9989401, + "tx_bytes_per_upload": 9995008, + "max_delta_rss_bytes": 93167616 } ] } diff --git a/evidence/lab4/consistency.txt b/evidence/lab4/consistency.txt index b2f9c3e2..7e9b0474 100644 --- a/evidence/lab4/consistency.txt +++ b/evidence/lab4/consistency.txt @@ -1,9 +1,9 @@ scripts/lab4/consistency_check.sh bucket: messenger-attachments -objects: 2580 +objects: 3823 rows by status: - 33 pending - 2577 ready - 6 rejected + 11 pending + 3822 ready + 4 rejected orphans: 0 missing: 0 diff --git a/evidence/lab4/decode-memory.txt b/evidence/lab4/decode-memory.txt new file mode 100644 index 00000000..09ebb0df --- /dev/null +++ b/evidence/lab4/decode-memory.txt @@ -0,0 +1,4 @@ +# inputs: magick -size 6320x6320 gradient:red-blue (PNG); same as JPEG q85 baseline and -interlace JPEG +png 6320x6320 bytes=53350 decode_ms=1159 peak_delta_rss_mib=116.8 +jpeg 6320x6320 bytes=4899767 decode_ms=1234 peak_delta_rss_mib=126.5 +jpeg 6320x6320 progressive bytes=4791710 decode_ms=1379 peak_delta_rss_mib=130.5 diff --git a/evidence/lab4/direct-ttl-short.txt b/evidence/lab4/direct-ttl-short.txt index f9afeee9..2f063108 100644 --- a/evidence/lab4/direct-ttl-short.txt +++ b/evidence/lab4/direct-ttl-short.txt @@ -3,6 +3,6 @@ The plugin "vite-tsconfig-paths" is detected. Vite now supports tsconfig paths resolution natively via the resolve.tsconfigPaths option. You can remove the plugin and set resolve.tsconfigPaths: true in your Vite config instead. RUN v4.1.11 /home/tomato/Projects/VP/mtusi2026lab4/app Test Files 1 passed (1) - Tests 7 passed (7) - Start at 23:00:12 - Duration 8.41s (transform 64ms, setup 0ms, import 94ms, tests 8.16s, environment 0ms) + Tests 9 passed (9) + Start at 16:31:20 + Duration 8.28s (transform 48ms, setup 0ms, import 72ms, tests 8.12s, environment 0ms) diff --git a/evidence/lab4/make-test-dependencies.txt b/evidence/lab4/make-test-dependencies.txt index 36cd7ceb..39008861 100644 --- a/evidence/lab4/make-test-dependencies.txt +++ b/evidence/lab4/make-test-dependencies.txt @@ -5,5 +5,5 @@ The plugin "vite-tsconfig-paths" is detected. Vite now supports tsconfig paths r RUN v4.1.11 /home/tomato/Projects/VP/mtusi2026lab4/app Test Files 1 passed (1) Tests 6 passed (6) - Start at 23:00:31 - Duration 88.83s (transform 48ms, setup 0ms, import 73ms, tests 88.65s, environment 0ms) + Start at 16:34:39 + Duration 124.94s (transform 75ms, setup 0ms, import 94ms, tests 124.75s, environment 0ms) diff --git a/evidence/lab4/make-test-e2e.txt b/evidence/lab4/make-test-e2e.txt index 433cb5a7..9dd7805d 100644 --- a/evidence/lab4/make-test-e2e.txt +++ b/evidence/lab4/make-test-e2e.txt @@ -3,6 +3,6 @@ The plugin "vite-tsconfig-paths" is detected. Vite now supports tsconfig paths resolution natively via the resolve.tsconfigPaths option. You can remove the plugin and set resolve.tsconfigPaths: true in your Vite config instead. RUN v4.1.11 /home/tomato/Projects/VP/mtusi2026lab4/app Test Files 3 passed | 1 skipped (4) - Tests 34 passed | 8 skipped (42) - Start at 22:59:53 - Duration 4.87s (transform 409ms, setup 0ms, import 764ms, tests 9.39s, environment 0ms) + Tests 38 passed | 8 skipped (46) + Start at 16:30:56 + Duration 4.59s (transform 196ms, setup 0ms, import 593ms, tests 10.10s, environment 0ms) diff --git a/evidence/lab4/summary.md b/evidence/lab4/summary.md index f7408851..322a2256 100644 --- a/evidence/lab4/summary.md +++ b/evidence/lab4/summary.md @@ -1,9 +1,9 @@ | mode | size, MiB | C | ok | API rx/upload, MiB | API tx/upload, MiB | max Δrss, MiB | p50, ms | p95, ms | |---|---|---|---|---|---|---|---|---| -| direct | 0.12 | 10 | 150/150 | 0.07 | 0.01 | 0.40 | 45 | 65 | -| proxy | 0.12 | 10 | 150/150 | 0.13 | 0.13 | 3.78 | 32 | 62 | -| direct | 1.00 | 10 | 150/150 | 0.07 | 0.01 | 0.75 | 75 | 137 | -| proxy | 1.00 | 10 | 150/150 | 1.01 | 1.01 | 4.38 | 59 | 110 | -| direct | 9.50 | 10 | 150/150 | 0.07 | 0.01 | 0.88 | 346 | 571 | -| proxy | 9.50 | 10 | 150/150 | 9.52 | 9.53 | 15.70 | 239 | 394 | -| proxy | 9.50 | 20 | 300/300 | 9.53 | 9.53 | 16.46 | 409 | 812 | +| direct | 0.12 | 10 | 150/150 | 0.13 | 0.01 | 1.12 | 68 | 104 | +| proxy | 0.12 | 10 | 150/150 | 0.13 | 0.13 | 3.38 | 60 | 106 | +| direct | 1.00 | 10 | 150/150 | 1.01 | 0.01 | 9.81 | 164 | 249 | +| proxy | 1.00 | 10 | 150/150 | 1.01 | 1.01 | 12.82 | 143 | 192 | +| direct | 9.50 | 10 | 150/150 | 9.52 | 0.01 | 81.77 | 693 | 1082 | +| proxy | 9.50 | 10 | 150/150 | 9.52 | 9.53 | 62.25 | 688 | 947 | +| proxy | 9.50 | 20 | 300/300 | 9.54 | 9.54 | 88.85 | 1396 | 1795 | diff --git a/evidence/lab4/unit-tests.txt b/evidence/lab4/unit-tests.txt index 5a32feef..273e1641 100644 --- a/evidence/lab4/unit-tests.txt +++ b/evidence/lab4/unit-tests.txt @@ -1,8 +1,6 @@ -The plugin "vite-tsconfig-paths" is detected. Vite now supports tsconfig paths resolution natively via the resolve.tsconfigPaths option. You can remove the plugin and set resolve.tsconfigPaths: true in your Vite config instead. - RUN v4.1.11 /home/tomato/Projects/VP/mtusi2026lab4/app -[Nest] 3057161 - 10/22/2026, 10:44:47 PM WARN [MessagesCacheService] Cache read failed, serving PostgreSQL: redis down -[Nest] 3057161 - 10/22/2026, 10:44:47 PM WARN [MessagesCacheService] Cache fill failed: redis down - Test Files 10 passed (10) - Tests 36 passed (36) - Start at 22:44:46 - Duration 1.93s (transform 718ms, setup 0ms, import 5.44s, tests 373ms, environment 1ms) +[Nest] 3821708 - 10/23/2026, 4:31:09 PM WARN [MessagesCacheService] Cache fill failed: redis down +[Nest] 3821732 - 10/23/2026, 4:31:10 PM WARN [AttachmentsService] Compensation of attachment 26212360-edf3-428c-9246-43cb29900490 deferred: Connection terminated unexpectedly + Test Files 12 passed (12) + Tests 43 passed (43) + Start at 16:31:08 + Duration 2.59s (transform 791ms, setup 0ms, import 8.70s, tests 543ms, environment 2ms) diff --git a/scripts/lab4/decode_memory.mjs b/scripts/lab4/decode_memory.mjs new file mode 100644 index 00000000..475316d6 --- /dev/null +++ b/scripts/lab4/decode_memory.mjs @@ -0,0 +1,22 @@ +// Peak RSS of one full decode check (same sharp options as ImageDecoder) on +// worst-case inputs near MAX_IMAGE_PIXELS. Run from app/: node ../scripts/lab4/decode_memory.mjs +import { readFileSync } from 'node:fs'; +import { createRequire } from 'node:module'; +const sharp = createRequire(`${process.cwd()}/`)('sharp'); +sharp.cache(false); +sharp.concurrency(1); +for (const file of process.argv.slice(2)) { + const data = readFileSync(file); + const meta = await sharp(data).metadata(); + const base = process.memoryUsage().rss; + let peak = base; + const timer = setInterval(() => { + peak = Math.max(peak, process.memoryUsage().rss); + }, 10); + const started = Date.now(); + await sharp(data, { failOn: 'warning', sequentialRead: true, limitInputPixels: 40_000_000 }).stats(); + clearInterval(timer); + console.log( + `${meta.format} ${meta.width}x${meta.height}${meta.isProgressive ? ' progressive' : ''} bytes=${data.length} decode_ms=${Date.now() - started} peak_delta_rss_mib=${((peak - base) / 1048576).toFixed(1)}`, + ); +} -- 2.54.0 From a06471a6c60f449cd08b50242966fe5a6c92f17f Mon Sep 17 00:00:00 2001 From: Ilya Date: Fri, 23 Oct 2026 16:40:34 +0300 Subject: [PATCH 11/15] =?UTF-8?q?lab4:=20evidence=20=D0=B8=20=D0=BE=D1=82?= =?UTF-8?q?=D1=87=D1=91=D1=82=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=B4=D0=B5=D0=BA=D0=BE?= =?UTF-8?q?=D0=B4=D0=B0=20=D0=B8=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=B5?= =?UTF-8?q?=D0=BD=D1=81=D0=B0=D1=86=D0=B8=D0=B8;=20=D1=88=D0=B0=D0=B1?= =?UTF-8?q?=D0=BB=D0=BE=D0=BD=20PR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/pull_request_template.md | 15 +- REPORT.md | 188 +++++++----- evidence/lab4/bench/direct-1048576-c10.json | 295 +++++++++--------- evidence/lab4/bench/direct-131072-c10.json | 292 +++++++++--------- evidence/lab4/bench/direct-9961472-c10.json | 314 ++++++++++---------- evidence/lab4/bench/proxy-1048576-c10.json | 166 +++++------ evidence/lab4/bench/proxy-131072-c10.json | 234 ++++++++------- evidence/lab4/bench/proxy-9961472-c10.json | 166 +++++------ evidence/lab4/bench/proxy-9961472-c20.json | 238 ++++++++------- evidence/lab4/consistency.txt | 4 +- evidence/lab4/make-test-e2e.txt | 4 +- evidence/lab4/summary.md | 14 +- evidence/lab4/unit-tests.txt | 8 +- 13 files changed, 987 insertions(+), 951 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 8508ab04..627df3cf 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -7,10 +7,11 @@ Что реализовано и что перенесено: - Перенесено из lab3: NestJS 12 + Fastify 5, PostgreSQL, Redis-сессии и кэш, идемпотентность POST сообщений, HAProxy + 2 API-реплики, хуки `restart.sh` / `stop-one.sh` / `start-replica.sh`. - Стенд: MinIO (образ закреплён по digest), идемпотентный bootstrap `s3-init` (приватный bucket, политика `messenger-api` только на `attachments/*`, отдельный пользователь API), секреты через Docker secrets (`make init-env`), консоль MinIO отключена, порт 9001 не публикуется, корневая ФС API `read_only`. -- Proxy upload PNG/JPEG: потоковая передача в S3 без буферизации тела; `ImageInspector` проверяет сигнатуру, структуру и CRC, лимиты 10 MiB / 40 млн пикселей применяются до чтения; при отказе — компенсация; 201 ready только после PUT в S3 и `markReady`. +- Proxy upload PNG/JPEG: потоковая передача в S3; два слоя проверки — `ImageInspector` (сигнатура, структура, CRC, тип, лимит 40 млн пикселей до любого декода) и полный декод libvips/sharp (`failOn: 'warning'`), последний кусок уходит в S3 только после обоих; лимит 10 MiB до чтения; 201 ready только после PUT в S3 и `markReady`. +- Компенсация не теряет оригинал: сначала захват строки `pending → deleting`, объект удаляется только после успешного захвата; если COMMIT `ready` прошёл, а ответ потерян — объект сохраняется, клиент получает 201; при недоступной БД ничего не удаляется (уборщик). - Download через API с проверкой членства в чате; `attachment_ids` в сообщениях (атомарно в `CREATE_ONCE_SQL`, составные FK запрещают вложение другого чата); уборщик незавершённых загрузок с grace period; CLI sweep. - Недоступность S3 — деградация: вложения отвечают 503, текст, история и readiness работают. -- Трек 1: `POST /chats/{id}/attachments/direct-uploads` → presigned PUT (подписаны content-type, content-length, x-amz-checksum-sha256) → `POST /attachments/{id}/complete` (HEAD + чтение заголовка изображения, статус `rejected` для отклонённых); расширение — `contracts/extensions.openapi.json`, обязательный proxy endpoint не изменён. +- Трек 1: `POST /chats/{id}/attachments/direct-uploads` → presigned PUT (подписаны content-type, content-length, x-amz-checksum-sha256) → `POST /attachments/{id}/complete` (HEAD размера и checksum, полное чтение и декод объекта, статус `rejected` для отклонённых); расширение — `contracts/extensions.openapi.json`, обязательный proxy endpoint не изменён. Команды запуска из чистого clone: ```sh @@ -25,16 +26,16 @@ make bench Результаты проверок и ссылка на REPORT.md: [REPORT.md](../REPORT.md); вывод — `evidence/lab4/`. - `make check` — PASS; `make test` — PASS (`make-check.txt`, `make-test.txt`). -- `make test-e2e`: 34 passed, 8 skipped (opt-in); unit-тесты: 36 passed. -- `make test-dependencies`: 6 passed (Redis, PG, S3 down, PG down между PUT и ready). +- `make test-e2e`: 38 passed, 8 skipped (opt-in); unit-тесты: 43 passed (включая регрессию потерянного COMMIT и декодер). +- `make test-dependencies`: 6 passed (Redis, PG, S3 down, PG down между PUT и ready — объект сохранён до уборки); короткий TTL: 9 passed. - Persistence и failover — PASS; download после остановки каждой из реплик возвращает тот же sha256. - `make s3-security`: 9 PASS; `make consistency`: orphans 0, missing 0; спайк подписи: чужие байты → S3 400/403. -- Эксперимент: proxy 10×9.5 MiB — пик Δrss 15.7 MiB, 20×9.5 MiB — 16.5 MiB; direct — трафик API ≈0.07 MiB на загрузку при любом размере, proxy ≈2×size. +- Эксперимент: proxy 10×9.5 MiB — медиана пика Δrss 43 MiB, 20×9.5 MiB — 50 MiB (граница по конфигурации ≈422 MiB, пик RSS ≤ 391 из 768 MiB); худший декод 40 млн px — 131 MiB; direct снимает с API исходящий трафик (≈0.01 MiB против size), входящий одинаков (≈size), т.к. complete проверяет объект целиком. Ограничения / известные ошибки: -- Прямой путь проверяет только заголовок изображения (структура хвоста файла >64 KiB не проверяется; байты зафиксированы подписанным SHA-256). +- Полная проверка стоит памяти (копия тела ≤10 MiB + декод) и времени (p50 proxy 9.5 MiB вырос с 239 до 642 мс); direct не экономит входящий трафик API — нужна асинхронная проверка рядом с хранилищем. +- Потерянный ответ COMMIT проверен unit-тестом с моком (в стенде нет прокси, рвущего соединение после COMMIT). - Не атомарна проверка лимита незавершённых заявок прямой загрузки (гонка параллельных init). -- Порядок компенсации proxy (сначала объект, потом строка): при ложном обрыве после commit возможна потеря объекта. - Тайм-аут загрузки обрывает сокет вместо ответа 400. - Нет автоматического reconciler'а orphan-объектов (только `make consistency`), нет TLS (до lab7), нет вариантов/WebP/delete-API. - Репозиторий MinIO, вероятно, архивирован (в этой работе не перепроверялось). diff --git a/REPORT.md b/REPORT.md index 5edd9807..79ba2738 100644 --- a/REPORT.md +++ b/REPORT.md @@ -61,8 +61,9 @@ ATTACHMENT_SWEEP_INTERVAL_MS=1000 docker compose --env-file .env up -d --no-deps хранится для отображения и никогда не попадает в ключ или путь. На API нет локального файла оригинала: корневая ФС контейнера `read_only: true`, `/tmp` — tmpfs 16 MiB (`evidence/lab4/readonly-api.txt`). -- **Жизненный цикл строки:** `pending` (байты не подтверждены) → `ready` (видна участникам чата) или - `deleting` (захвачена уборщиком) → строка удалена. Публично существуют только `ready`. +- **Жизненный цикл строки:** `pending` (байты не подтверждены) → `ready` (видна участникам чата), + либо `deleting` (захвачена компенсацией или уборщиком) → строка удалена, либо (direct) `rejected` + (проверка не пройдена, URL ещё может действовать) → уборщик. Публично существуют только `ready`. Инварианты в БД: составные FK `(chat_id, owner_id) → chat_members` и `(attachment_id, chat_id) → attachments(id, chat_id)` делают «вложение другого чата» невозможным; `CHECK` требует size/sha256/width/height у `ready` и `expires_at` у незавершённых; FK @@ -71,29 +72,53 @@ ATTACHMENT_SWEEP_INTERVAL_MS=1000 docker compose --env-file .env up -d --no-deps - **Когда честно 201 (proxy):** только после того, как S3 принял весь объект (`PutObject` завершён) и `UPDATE … SET status='ready' WHERE status='pending'` изменил строку. Этот `UPDATE` проигрывает захвату уборщиком атомарно (строка уже `deleting` → 503, а не фальшивый 201). -- **S3 PUT прошёл, а COMMIT нет:** строка остаётся `pending`, объект есть. Запрос сначала пытается - компенсировать (`DeleteObject`, затем `DELETE … WHERE status='pending'`); если не удалось - (PG/S3 недоступны) — счётчик `attachments.compensation_deferred`, строка остаётся и через - `expires_at + ATTACHMENT_SWEEP_GRACE_SECONDS` её убирает уборщик (удаляет объект, затем строку). - Сверка: `make consistency`. Наблюдение — `dependency-failures` «compensates the S3 write when - PostgreSQL fails before ready». -- **Потоковая обработка (proxy):** тело читается как поток и сразу идёт в S3 с заранее известным - `Content-Length` (≤ 10 MiB, иначе 413 до чтения). Параллельно `ImageInspector` (байтовый автомат - PNG/JPEG, без декодирования и без буферизации тела) проверяет сигнатуру, структуру, CRC чанков PNG - и число пикселей (≤ 40 млн, 413). До появления заголовка (≤ 1 MiB) нет ни строки, ни объекта. - Последний кусок отдаётся в S3 только после `inspector.finish()` — S3 не получит полное тело - невалидного файла и не зафиксирует объект. Ограничители: `UPLOAD_MAX_IN_FLIGHT` (429 + - `Retry-After`), `UPLOAD_TIMEOUT_MS` (жёсткий дедлайн запроса), тайм-ауты S3-клиента. - Fastify `bodyLimit` к `image/*` не применяется: контент-парсеры отдают сырой поток (для - `text/plain` встроенный буферизующий парсер заменён — иначе бинарное тело давало 400). +- **S3 PUT прошёл, а COMMIT нет — и как не потерять оригинал.** Ошибка `markReady` на стороне API + не означает, что COMMIT не прошёл: соединение может оборваться *после* фиксации, и тогда строка + уже `ready`. Поэтому компенсация сначала **захватывает строку** + (`UPDATE … SET status='deleting' WHERE id=$1 AND status='pending'`) и удаляет объект **только после + успешного захвата**, затем удаляет строку: + - захват не сработал (строка уже не `pending`) — объект не трогается; если строка `ready`, API + отвечает 201 с этим вложением (`attachments.upload.recovered`): COMMIT был, это правда; + - PostgreSQL недоступен — ничего не удаляется (`attachments.compensation_deferred`): по строке + `pending` объект найдёт уборщик через `expires_at + ATTACHMENT_SWEEP_GRACE_SECONDS`, и он тоже + сначала захватывает строку; + - S3 недоступен после захвата — строка остаётся `deleting` и перезахватывается уборщиком через минуту. + + Так «объект без строки» не возникает ни при каком сбое, а `ready` без объекта — только при внешнем + удалении из bucket. Первая версия удаляла объект до строки и теряла оригинал при потерянном ответе + COMMIT; регрессия — `attachments.service.spec.ts` (unit, мок «COMMIT прошёл, ответ потерян»), а + fault-тест `dependency-failures` «keeps the object while PostgreSQL is down before ready» проверяет, + что при остановленном PG объект сохраняется до уборки. +- **Proxy: потоковая передача + полная проверка изображения.** Тело читается как поток и сразу идёт + в S3 с заранее известным `Content-Length` (≤ 10 MiB, иначе 413 до чтения). Проверка в два слоя: + 1. `ImageInspector` — байтовый автомат PNG/JPEG без буферизации: сигнатура, структура, CRC чанков + PNG, тип по содержимому и число пикселей (≤ 40 млн → 413) по IHDR/SOF. До появления заголовка + (≤ 1 MiB) нет ни строки, ни объекта; pixel bomb отвергается до любого декодирования. + 2. `ImageDecoder` — полный декод всех пикселей libvips (sharp 0.35, `failOn: 'warning'`, + `limitInputPixels`). Структуры и CRC недостаточно: PNG с мусорным zlib-потоком (верные CRC) и JPEG + без данных скана проходят первый слой — их ловит только декод (первая версия возвращала на них + 201). Декод ограничен `IMAGE_DECODE_MAX_CONCURRENT` (очередь), libvips — один поток, без кэша. + + Последний кусок отдаётся в S3 только после обоих слоёв — S3 не получает полное тело невалидного + файла и не фиксирует объект. Цена: на время загрузки API держит копию тела (≤ 10 MiB) для декода + (libvips не принимает поток), плюс память декода (≈117–131 MiB на изображение 40 млн пикселей, + `evidence/lab4/decode-memory.txt`). Верхняя граница на реплику: + `UPLOAD_MAX_IN_FLIGHT × 10 MiB + IMAGE_DECODE_MAX_CONCURRENT × 131 MiB` = 16 × 10 + 2 × 131 ≈ 422 MiB + при лимите контейнера 768 MiB. Остальные ограничители: `UPLOAD_MAX_IN_FLIGHT` (429 + + `Retry-After`, общий для proxy и direct complete), `UPLOAD_TIMEOUT_MS`, тайм-ауты S3-клиента. + Fastify `bodyLimit` к `image/*` не применяется: контент-парсеры отдают сырой поток только маршруту + загрузки (для `text/plain` на нём встроенный буферизующий парсер заменён — иначе бинарное тело + давало 400; на остальных маршрутах `image/*` → 415, `text/plain` буферизуется как прежде). - **Прямая загрузка (трек 1):** `POST /api/v1/chats/{id}/attachments/direct-uploads` создаёт строку `pending` (`expires_at = now + TTL`) и возвращает presigned PUT. Подписаны `content-type`, `content-length` и `x-amz-checksum-sha256`: S3 сам отвергает тело другого размера (403 `SignatureDoesNotMatch`) или с другим SHA-256 (400 `XAmzContentChecksumMismatch`), объект при этом не создаётся (`evidence/lab4/presign-spike.txt`). `POST /api/v1/attachments/{id}/complete` - (только владелец): `HEAD` (размер + подписанный checksum), чтение заголовка изображения (первый - диапазон 64 KiB, при необходимости расширяется до 1 MiB; объект, целиком попавший в диапазон, - проверяется до конца, включая CRC/EOI), сверка типа и пикселей, `markReady`. Несоответствие + (только владелец): `HEAD` (размер + подписанный checksum), затем объект **читается целиком** и + проходит те же два слоя, что и proxy (инспектор + полный декод), сверка типа и пикселей, `markReady`. + Подписанный checksum доказывает лишь, что байты те, что заявил клиент, а не что это изображение: + первая версия читала только начало и принимала усечённый PNG и файл, повреждённый после первых + 64 KiB (оба с верным checksum). Цена — входящий трафик API = size на `complete` (см. H2). Несоответствие (размер/checksum/тип/пиксели) → 409/413/415, объект удаляется, а строка получает статус `rejected` и сохраняет `expires_at`: подписанный URL ещё может быть использован, и повторный PUT оставил бы объект без строки; уборщик удаляет `rejected` после `expires_at` + grace, пока же строка @@ -137,7 +162,8 @@ ATTACHMENT_SWEEP_INTERVAL_MS=1000 docker compose --env-file .env up -d --no-deps | `S3_ACCESS_KEY_ID_FILE`, `S3_SECRET_ACCESS_KEY_FILE` | `resolveSecret` → `S3_ACCESS_KEY_ID`/`S3_SECRET_ACCESS_KEY` | API-credentials из Docker secrets | | `S3_CONNECT_TIMEOUT_MS`, `S3_REQUEST_TIMEOUT_MS` | `NodeHttpHandler` | тайм-ауты S3-клиента | | `MAX_UPLOAD_BYTES`, `MAX_IMAGE_PIXELS` | `AttachmentsService`, `DirectUploadsService` | 10 MiB, 40 млн пикселей | -| `UPLOAD_TIMEOUT_MS`, `UPLOAD_MAX_IN_FLIGHT` | `AttachmentsService` | дедлайн запроса и число одновременных proxy-загрузок на реплику | +| `UPLOAD_TIMEOUT_MS`, `UPLOAD_MAX_IN_FLIGHT` | `AttachmentsService`, `UploadSlots` | дедлайн запроса; число одновременных proxy-загрузок и direct complete на реплику (16) | +| `IMAGE_DECODE_MAX_CONCURRENT` | `ImageDecoder` | одновременные полные декоды на реплику (2) | | `ATTACHMENT_SWEEP_INTERVAL_MS`, `ATTACHMENT_SWEEP_GRACE_SECONDS` | `AttachmentSweeper`, CLI | период фонового прохода (0 = выкл.) и grace после `expires_at` | | `DIRECT_UPLOAD_URL_TTL_SECONDS`, `DIRECT_UPLOAD_MAX_PENDING_PER_USER` | `DirectUploadsService` | TTL подписи; лимит незавершённых заявок | | `S3_PUBLIC_BIND`, `S3_PUBLIC_PORT`, `S3_CPUS`, `S3_MEMORY` | `compose.yaml` (сервис `s3`) | публикация порта на loopback; лимиты контейнера | @@ -148,10 +174,11 @@ ATTACHMENT_SWEEP_INTERVAL_MS=1000 docker compose --env-file .env up -d --no-deps ### Компенсация, сверка, очистка (grace period) `expires_at` у proxy = старт + `UPLOAD_TIMEOUT_MS` (жёсткий дедлайн запроса), у direct = выдача URL + TTL. -Уборщик берёт строку только через `ATTACHMENT_SWEEP_GRACE_SECONDS` (900 с по умолчанию) после этого: +Уборщик берёт строки `pending`/`rejected` только через `ATTACHMENT_SWEEP_GRACE_SECONDS` (900 с по умолчанию) после этого: живую загрузку он не застанет, а `markReady … WHERE status='pending'` проигрывает захвату (`pending → deleting`, `FOR UPDATE SKIP LOCKED`, реплики не мешают друг другу). Застрявшая в -`deleting` строка (упавший уборщик) перезахватывается через минуту. Ручной запуск: +`deleting` строка (упавший уборщик или компенсация, которой не ответил S3) перезахватывается через +минуту — живая компенсация за это время либо завершается, либо уже не идёт. Ручной запуск: `docker compose exec api node dist/attachments/attachments-sweep.cli.js`. Сверка в обе стороны (только чтение): `make consistency` — `orphans` (объект без строки) и `missing` (`ready` без объекта). Отсутствующий объект у `ready`-строки при download — это потеря данных: 500 и счётчик @@ -165,16 +192,16 @@ ATTACHMENT_SWEEP_INTERVAL_MS=1000 docker compose --env-file .env up -d --no-deps | --- | --- | --- | --- | | Публичный smoke | `make test` | `PASS: lab4 public API scenario` (upload 201 ready, сообщение с `''` и `attachment_ids`, download bob = байты, eve 404) | `make-test.txt` | | Контракт offline | `make check` | PASS, `contracts/extensions.openapi.json` — валидный JSON | `make-check.txt` | -| 3: S3 в общем стенде, приватный bucket, метаданные в PG, байты в bucket | `make stand-up`; `docker compose ps`; `make consistency` | `s3` healthy, `s3-init` завершён с 0; bucket приватный (`mc anonymous set none`); число объектов в bucket = числу `ready`-строк (2577 после серий `make bench` и e2e; ещё 33 `pending` без объектов и 6 `rejected` ждут истечения + grace), orphans/missing = 0 | `bootstrap-rerun.txt`, `consistency.txt` | +| 3: S3 в общем стенде, приватный bucket, метаданные в PG, байты в bucket | `make stand-up`; `docker compose ps`; `make consistency` | `s3` healthy, `s3-init` завершён с 0; bucket приватный (`mc anonymous set none`); после серий `make bench`, e2e и fault-тестов: 5066 объектов на 5065 `ready` + 15 незавершённых строк (`pending`/`rejected`, ждут истечения + grace; одна из них — с объектом), orphans/missing = 0 | `bootstrap-rerun.txt`, `consistency.txt` | | 3: 201 ready, побайтный download, `attachment_ids` | `make test-e2e` (`attachments.e2e-spec.ts`) | sha256 в ответе = sha256 файла; content = байты, `nosniff`, `Content-Length` | `make-test-e2e.txt` | -| 3: PNG/JPEG ≤10 MiB и ≤40 млн px; MIME по содержимому; опасные filename; лимиты до чтения | e2e: 10485760 → 201, 10485761 → 413, pixel bomb 8000×5001 → 413 сразу после IHDR, PNG как `image/jpeg` → 415, `a/b.png`, `\u202E`, NUL, 256 символов → 400, 255×😀 → 201 | кейсы перечислены в `app/test/attachments.e2e-spec.ts` (в evidence — итог: 34 passed, 8 skipped opt-in); raw image/text тело на JSON-маршрутах → 415/400, не 500 | `make-test-e2e.txt`, `unit-tests.txt` (`image-inspector.spec.ts`) | +| 3: PNG/JPEG ≤10 MiB и ≤40 млн px; MIME по содержимому; опасные filename; лимиты до чтения | e2e: 10485760 → 201, 10485761 → 413, pixel bomb 8000×5001 → 413 сразу после IHDR, PNG как `image/jpeg` → 415, `a/b.png`, `\u202E`, NUL, 256 символов → 400, 255×😀 → 201 | кейсы перечислены в `app/test/attachments.e2e-spec.ts` (в evidence — итог: 38 passed, 8 skipped opt-in); raw image/text тело на JSON-маршрутах → 415/400, не 500 | `make-test-e2e.txt`, `unit-tests.txt` (43 passed: `image-inspector.spec.ts`, `image-decoder.spec.ts`, `attachments.service.spec.ts`) | | 3: другая реплика отдаёт файл после остановки загрузившей; restart сохраняет данные | `scripts/stop-one.sh` (обе реплики по очереди), `make test-failover`; `make test-persistence ACTION_SCRIPT=scripts/restart.sh` | failover: 0 неуспешных попыток, восстановление ≈3.3 с; download с тем же sha256 после остановки api-1 и api-2; persistence: `StartedAt` у postgres, redis, s3, api×2, haproxy изменился, данные и сессия сохранены | `failover.txt`, `failover-attachment.txt`, `persistence.txt` | | 3: на API нет локального файла оригинала | `touch` в корне контейнера | `Read-only file system` | `readonly-api.txt` | -| 4: тесты: большой файл, повреждённое изображение, подмена MIME, чужое `attachment_id`, вложение другого чата, нет 500 | `make test-e2e` | 413; усечённый PNG, флип байта (CRC), сигнатура+мусор, пустое тело → 415; подмена MIME → 415; чужое/неизвестное/незавершённое → 404; вложение чата eve в чате alice → 404 | `make-test-e2e.txt` | -| 4: прерывание загрузки и отказ между S3/БД не оставляют вечных объектов | e2e «client drops the connection»; `make test-dependencies` | обрыв клиента → строк 0 за ≤10 с; S3 down → одна `pending`, после старта и sweep — 0; PG down между PUT и ready → 503, объекта в S3 нет, `pending` убрана sweep; затем `orphans: 0, missing: 0` | `make-test-e2e.txt`, `make-test-dependencies.txt`, `consistency.txt` | -| 4: лимиты, таймауты, потоковая обработка; эксперимент ≥10 загрузок с пиком памяти | `make bench` (proxy, C=10 и C=20, 9.5 MiB) | max Δrss реплики 15.7 MiB при C=10 и 16.5 MiB при C=20 против 95/190 MiB тел в полёте — см. «Эксперименты» | `summary.md`, `bench/*.json` | +| 4: тесты: большой файл, повреждённое изображение, подмена MIME, чужое `attachment_id`, вложение другого чата, нет 500 | `make test-e2e` | 413; усечённый PNG, флип байта (CRC), сигнатура+мусор, пустое тело, PNG с мусорным zlib-потоком при верных CRC, JPEG (baseline и прогрессивный) без данных скана → 415; подмена MIME → 415; чужое/неизвестное/незавершённое → 404; вложение чата eve в чате alice → 404 | `make-test-e2e.txt` | +| 4: прерывание загрузки и отказ между S3/БД не оставляют вечных объектов | e2e «client drops the connection»; `make test-dependencies` | обрыв клиента → строк 0 за ≤10 с; S3 down → строка в `deleting`, после старта перезахвачена и убрана sweep; PG down между PUT и ready → 503, объект сохранён до уборки (строка `pending` его учитывает), после sweep нет ни объекта, ни строки; потерянный ответ COMMIT → объект не удаляется, 201 (unit `attachments.service.spec.ts`); затем `orphans: 0, missing: 0` | `make-test-e2e.txt`, `make-test-dependencies.txt`, `consistency.txt` | +| 4: лимиты, таймауты, потоковая обработка; эксперимент ≥10 загрузок с пиком памяти | `make bench` (proxy, C=10 и C=20, 9.5 MiB) | медиана max Δrss реплики 43 MiB при C=10 и 50 MiB при C=20 (≈95/190 MiB тел в полёте), абсолютный пик RSS ≤ 391 MiB при лимите 768 MiB; граница по конфигурации ≈422 MiB сверх базового RSS; худший декод 40 млн px — 131 MiB — см. «Эксперименты» | `summary.md`, `bench/*.json`, `decode-memory.txt` | | 4: идемпотентный bootstrap; отдельные ограниченные credentials; консоль закрыта; private bucket вне API | `docker compose run s3-init` дважды; `make s3-security` | повтор → `bootstrap ok`; анонимные GET/list/PUT → 403; API-credentials не создают bucket, не вызывают admin, не пишут вне `attachments/`, читают `attachments/*`; порт 9001 не опубликован и не отвечает | `bootstrap-rerun.txt`, `s3-security.txt` | -| 5 / трек 1: presigned flow (короткая подпись, уникальный ключ, принадлежность, размер/checksum на complete, незавершённые) | `direct-upload.e2e-spec.ts`; спайк подписи | init → PUT мимо API → complete → metadata/content → сообщение; чужой/посторонний complete → 404; подмена байта → S3 400, затем complete 409; JPEG под видом PNG → 415, затем 404; pixel bomb → 413; 11-я заявка → 429 + `Retry-After` | `make-test-e2e.txt`, `presign-spike.txt` | +| 5 / трек 1: presigned flow (короткая подпись, уникальный ключ, принадлежность, размер/checksum на complete, незавершённые) | `direct-upload.e2e-spec.ts`; спайк подписи | init → PUT мимо API → complete → metadata/content → сообщение; чужой/посторонний complete → 404; усечённый PNG и PNG, повреждённый после первых 64 KiB (оба с верным checksum) → 415, затем 404; подмена байта → S3 400, затем complete 409; JPEG под видом PNG → 415, затем 404; pixel bomb → 413; 11-я заявка → 429 + `Retry-After` | `make-test-e2e.txt`, `presign-spike.txt` | | 5 / трек 1: истёкший URL и уборка | `E2E_DIRECT_TTL_SHORT=1` на стенде с TTL 5 с | PUT после `expires_at` → 403, строка убрана уборщиком, complete → 404 | `direct-ttl-short.txt` | | 5 / трек 1: сравнение трафика и RAM API на ≥2 размерах | `make bench` (0.125, 1, 9.5 MiB) | см. таблицу ниже | `summary.md`, `bench/*.json` | @@ -189,48 +216,55 @@ ATTACHMENT_SWEEP_INTERVAL_MS=1000 docker compose --env-file .env up -d --no-deps **Методика.** Хост: 8 логических CPU, 16 GiB RAM, один Docker-хост. Лимиты: API 1.5 CPU / 768 MiB на реплику (2 реплики), MinIO 1 CPU / 512 MiB, PG 1.5 CPU / 512 MiB. Версии — см. «Запуск». Нагрузка: `scripts/lab4/attachments_bench.py`, closed-loop: C потоков × 5 загрузок несжимаемых PNG -(`noise_png`, разные seed), R = 3 повтора; один прогрев на конфигурацию (2 × число реплик загрузок, +(`noise_png`, разные seed — несжимаемые, поэтому декод не дешевле реальных фото), R = 3 повтора; один прогрев на конфигурацию (2 × число реплик загрузок, не измеряется), перед каждым повтором — `POST /internal/metrics/reset` на каждой реплике. Трафик API — дельта `eth0` rx/tx из `/proc/net/dev` контейнера; RAM — пик `process.memoryUsage().rss` с шагом 50 мс минус RSS в момент reset (Δrss); в таблицу идёт медиана по повторам, для Δrss — максимум по репликам. Команда: `make bench` (`scripts/lab4/run_matrix.sh`); raw — `evidence/lab4/bench/*.json` (без токенов и URL). -**H1 (уровень 4).** Потоковый proxy держит рост пикового RSS реплики ограниченным и почти независимым -от размера файла: Δrss при 10 × 9.5 MiB много меньше суммарного объёма тел в полёте. +**H1 (уровень 4).** Память реплики при ≥ 10 параллельных загрузках ограничена сверху конфигурацией +(`UPLOAD_MAX_IN_FLIGHT × 10 MiB + IMAGE_DECODE_MAX_CONCURRENT × ≈131 MiB` ≈ 422 MiB) и не зависит от +числа клиентов сверх этого лимита. Исходная формулировка («Δrss почти не зависит от размера файла») для +текущей версии неверна по построению: ради полного декода API держит копию тела. -**H2 (трек 1).** Прямая загрузка снижает трафик API на загрузку с ≈2 × size (вход от клиента + выход в -S3) до малой величины, не зависящей от размера, и не растит RSS; латентность малых файлов у direct -выше из-за трёх round trip. +**H2 (трек 1).** Прямая загрузка снимает с API передачу байтов в S3 (tx) и не требует держать соединение +клиента на время заливки; входящий трафик API она не снижает, потому что `complete` читает объект +целиком для проверки; латентность direct выше из-за трёх round trip и повторного чтения. -Результаты (`evidence/lab4/summary.md`; 150 загрузок на строку при C=10, 300 при C=20; ошибок 0): +Результаты (`evidence/lab4/summary.md`, коммит `4badd5a`; 150 загрузок на строку при C=10, 300 при +C=20; ошибок 0): | mode | size, MiB | C | API rx/upload, MiB | API tx/upload, MiB | max Δrss, MiB | p50, ms | p95, ms | | --- | --- | --- | --- | --- | --- | --- | --- | -| direct | 0.12 | 10 | 0.07 | 0.01 | 0.40 | 45 | 65 | -| proxy | 0.12 | 10 | 0.13 | 0.13 | 3.78 | 32 | 62 | -| direct | 1.00 | 10 | 0.07 | 0.01 | 0.75 | 75 | 137 | -| proxy | 1.00 | 10 | 1.01 | 1.01 | 4.38 | 59 | 110 | -| direct | 9.50 | 10 | 0.07 | 0.01 | 0.88 | 346 | 571 | -| proxy | 9.50 | 10 | 9.52 | 9.53 | 15.70 | 239 | 394 | -| proxy | 9.50 | 20 | 9.53 | 9.53 | 16.46 | 409 | 812 | +| direct | 0.12 | 10 | 0.13 | 0.01 | 5.25 | 72 | 120 | +| proxy | 0.12 | 10 | 0.13 | 0.13 | 3.00 | 57 | 87 | +| direct | 1.00 | 10 | 1.01 | 0.01 | 1.38 | 154 | 252 | +| proxy | 1.00 | 10 | 1.01 | 1.01 | 2.00 | 132 | 183 | +| direct | 9.50 | 10 | 9.52 | 0.01 | 83.62 | 755 | 1018 | +| proxy | 9.50 | 10 | 9.52 | 9.53 | 42.94 | 642 | 889 | +| proxy | 9.50 | 20 | 9.53 | 9.53 | 49.98 | 1336 | 1743 | Выводы: -- **H1 подтверждена с оговоркой.** При C=10 и 9.5 MiB пик Δrss — 15.7 MiB (по повторам 14.5–18.1) при - ≈95 MiB тел в полёте; при C=20 — 16.5 MiB (12.1–21.0) при ≈190 MiB: удвоение concurrency в пределах - шума не изменило пик. Память не пропорциональна размеру файла (размер ×76: 0.12 → 9.5 MiB дал Δrss - 3.78 → 15.7 MiB, ×4.2), но и не постоянна: растёт с размером (буферы сокетов, чанки в полёте, - аллокатор), оставаясь на порядок меньше тел в полёте. Δrss — шумная величина (между повторами одной - конфигурации 1.9–6.3 MiB для proxy 0.12/1 MiB), поэтому разница между C=10 и C=20 не интерпретируется. -- **H2 подтверждена.** Для proxy tx ≈ rx ≈ size (≈2 × size суммарно: вход от клиента и выход в S3). - Для direct при любом из трёх размеров API видит ≈0.07 MiB rx (первый диапазон 64 KiB + служебные - запросы) и ≈0.01 MiB tx, Δrss ≤ 0.9 MiB. Для размера 0.12 MiB выигрыш по rx вдвое (0.13 → 0.07), - по tx — на порядок. Латентность direct выше (p50 45 против 32 мс, 75 против 59 мс — три запроса - вместо одного) и на 9.5 MiB (346 против 239 мс): клиент заливает через loopback в MinIO с лимитом - 1 CPU, а не через API; причина прироста в эксперименте не выяснялась и остаётся гипотезой (вероятно, - проверка подписи и checksum в MinIO). Первая версия `complete` читала диапазон до 1 MiB и - останавливалась по заголовку: сокет к этому моменту уже вычитывал 110–176 KB (read-ahead), а для файлов - ≤ 1 MiB объект читался целиком (rx = size). Это нашло ревью; диапазон 64 KiB убрал оба эффекта. +- **H1 подтверждена.** Рост памяти сверх базового RSS процесса (≈240–255 MiB после прогрева, включая + загруженный libvips): Δrss 26–57 MiB по повторам при proxy 9.5 MiB C=10 (медиана 43) и 28–121 MiB при + C=20 (медиана 50) — ниже границы ≈422 MiB и намного меньше ≈95/190 MiB тел в полёте на весь стенд. + Абсолютный пик RSS реплики — 311–391 MiB при лимите контейнера 768 MiB. Рост от размера файла есть + (0.12 и 1 MiB — 0.5–6 MiB, 9.5 MiB — десятки MiB): это копия тела для декода и сам декод (≈155 мс на + файл 9.5 MiB, счётчик `attachments.decode.ms`). Худший допустимый декод (40 млн пикселей) — ≈131 MiB, + измерен отдельно (`decode-memory.txt`) и в бенчмарк не входил. Δrss шумная (у одной конфигурации + разброс до 4×), поэтому разница между C=10 и C=20 не интерпретируется. +- **H2 подтверждена в новой формулировке.** API tx у direct ≈0.01 MiB против size у proxy (≈1000× для + 9.5 MiB); API rx одинаков (≈size), потому что `complete` читает объект целиком. Ранняя версия, читавшая + только начало объекта, давала rx ≈0.07 MiB, но принимала повреждённые изображения — этот выигрыш был + ценой корректности и отозван. Δrss у direct 9.5 MiB выше, чем у proxy (84 против 43 MiB): объект + читается из S3 быстрее, чем приходит от клиента, и больше копий одновременно ждут декода. Латентность + direct выше на всех размерах (p50 72/154/755 против 57/132/642 мс): три запроса и повторное чтение + объекта. Выигрыш direct в этой реализации — только снятие с API исходящего трафика в S3 и времени + заливки клиентом; для полного выигрыша по rx проверку нужно вынести с API (асинхронный воркер рядом + с хранилищем) — это следующий шаг, не реализован. +- Сравнение с предыдущими прогонами (без полного декода, коммит `830e581`): p50 proxy 9.5 MiB C=10 вырос + с 239 до 642 мс, медиана Δrss — с 15.7 до 42.9 MiB. Это цена закрытия дыры в валидации. **Ограничения измерений.** Один Docker-хост: клиент, LB, API и MinIO делят 8 CPU, без реальной сети; `/proc/net/dev` реплики включает трафик PG/Redis и служебные запросы метрик (≈7–8 KiB на загрузку, @@ -243,8 +277,9 @@ S3) до малой величины, не зависящей от размер | Воздействие | Что ожидаем | Что наблюдали | Время восстановления / потеря данных | | --- | --- | --- | --- | -| S3 остановлен (`compose stop s3`) | вложения → bounded 503; текст, история, метаданные, `/health/ready` работают | upload → 503 `unavailable` без утечки деталей; метаданные 200; content 503; текстовое сообщение 201; readiness 200; одна `pending`-строка неудачной загрузки | после `start s3` и healthy download старого файла 200 с теми же байтами, новый upload 201; `pending` убрана sweep; потерь нет | -| PostgreSQL остановлен между S3 PUT и `ready` | 503; объект не должен остаться | ответ 503; объект в S3 компенсирован (`mc stat` — нет), `pending`-строка осталась (БД недоступна) | после старта PG и `waitForReadiness`; строка убрана sweep после `expires_at`; `orphans: 0` | +| S3 остановлен (`compose stop s3`) | вложения → bounded 503; текст, история, метаданные, `/health/ready` работают | upload → 503 `unavailable` без утечки деталей; метаданные 200; content 503; текстовое сообщение 201; readiness 200; строка неудачной загрузки в `deleting` (захвачена, удаление объекта не прошло) | после `start s3` и healthy download старого файла 200 с теми же байтами, новый upload 201; строка перезахвачена и убрана sweep через минуту; потерь нет | +| PostgreSQL остановлен между S3 PUT и `ready` | 503; API не знает, прошёл ли COMMIT, — ничего не удаляет; объект учтён строкой | ответ 503; после старта PG строка `pending`, объект на месте (`mc stat` — есть); после `expires_at` sweep удалил объект и строку | уборка через `expires_at` + grace; `orphans: 0`, `missing: 0` | +| COMMIT `ready` прошёл, ответ PostgreSQL потерян | объект не удаляется, клиент получает 201 | unit `attachments.service.spec.ts`: захват строки не срабатывает, `delete` не вызывается, ответ 201 `ready` | потерь нет (в стенде не воспроизводится без прокси, разрывающего соединение после COMMIT) | | Обрыв клиента посреди загрузки (512 KiB из 2 MiB) | не остаётся ни строки, ни объекта | PUT прерывается (`S3 put failed: AbortError` в логе API, в evidence не сохранён) без ожидания тайм-аута, компенсация, строк в чате 0 | ≤10 с (предел ожидания теста; точное время не измерялось) | | Остановка обслужившей реплики | другая реплика отдаёт тот же файл | download 200, тот же sha256, другой `X-Instance-Id` для api-1 и api-2 | ≈3.3 с до первого успешного запроса, 0 неуспешных записей из 134–140 | | Restart стенда (`scripts/restart.sh`) | метаданные и оригиналы сохраняются, сессия жива | persistence PASS; `StartedAt` всех сервисов изменился | потерь нет (время до готовности отдельно не измерялось) | @@ -256,28 +291,31 @@ S3) до малой величины, не зависящей от размер - **MinIO:** закреплён образ `RELEASE.2025-09-07T16-13-09Z`; по данным, использованным при планировании, репозиторий `minio/minio` архивирован — новых образов и исправлений не будет *(в этой сессии не перепроверялось)*. Для продакшена потребуется замена (SeaweedFS/RustFS) или форк. -- **Прямой путь не проверяет структуру хвоста файла** при size > 64 KiB: только заголовок (первые 64 KiB, при необходимости до 1 MiB) и - подписанный SHA-256/размер. Байты гарантированно те, что заявил клиент, но заявил он их сам; - усечённый или «склеенный» файл с корректным заголовком пройдёт `complete`. В proxy-режиме проверяется - весь поток (CRC чанков PNG, EOI JPEG). Для size ≤ 64 KiB direct проверяет всё, ценой входящего - трафика API. +- **Полная проверка изображения стоит памяти и времени:** копия тела (≤ 10 MiB) на загрузку и декод + через libvips (нативная зависимость sharp, ≈131 MiB на худший вход). `failOn: 'warning'` строже + браузеров: файл с предупреждением libjpeg/libpng будет отвергнут (на 300 изображениях с хоста ложных + отказов не было, но выборка не репрезентативна для фото с камер). Проверяются декодируемость и + целостность, а не «безопасность для всех декодеров» — перекодирование в чистый формат не делается. +- **Direct не экономит входящий трафик API** (см. H2); это следствие проверки на API. Следующий шаг — + асинхронная проверка воркером рядом с хранилищем (`status: processing`), что требует расширения + контракта. - **Гонка лимита заявок:** `countPendingDirect` и `insertPending` не атомарны — параллельные `init` одного пользователя могут превысить лимит на число параллельных запросов; для лабораторной принято. - **Загрузка, не доставленная до `ready`, видна уборщику только через grace (по умолчанию 15 мин):** до этого объект занимает место; для быстрой очистки в тестах grace уменьшается переменной окружения. -- **Недоступность S3 при `compensate`** оставляет объект, если сам `DeleteObject` не прошёл; его - убирает уборщик по строке. Объект без строки (например, строку удалили вручную) обнаружит только - `make consistency` — автоматического reconciler'а для orphan-объектов нет (это трек 2). -- **Порядок компенсации proxy:** сначала удаляется объект, затем строка. Если `markReady` на самом деле - зафиксирован, а клиент БД увидел обрыв соединения, объект будет удалён у строки `ready` (потеря данных; - `object_missing` → 500 на download). Обратный порядок противоречил бы требованию «объекта не должно - остаться при отказе PG»; окно — доли секунды между commit и обрывом, принято как ограничение. +- **Компенсация при недоступной БД ничего не удаляет:** объект остаётся до уборки + (`expires_at` + 900 с grace) — сознательный выбор: без БД нельзя отличить «COMMIT не прошёл» от «ответ + потерян», а удаление в втором случае теряет оригинал. Объект без строки (например, строку удалили + вручную) обнаружит только `make consistency` — автоматического reconciler'а нет (это трек 2). +- **Потерянный COMMIT проверен только unit-тестом** с моком репозитория: стенд не умеет разорвать + соединение PostgreSQL ровно после COMMIT (для этого нужен прокси вроде toxiproxy). - **Таймаут загрузки** уничтожает тело (и сокет) — клиент может получить обрыв соединения вместо ожидаемого 400 «Upload was interrupted»; строка и объект при этом компенсируются. - **TLS нет** до lab7: presigned URL и токены ходят по HTTP; консоль MinIO отключена полностью, поэтому администрирование — только через `mc` из контейнера. - **Не реализовано:** варианты вложений (`variants` всегда `[]`; `variant=thumbnail|crop|optimized` → 404), delete-API вложений, WebP. -- **Подтверждено измерением:** потоковый proxy ограничивает память, direct уменьшает tx и rx API для - любого из проверенных размеров. **Остаётся гипотезой:** причина роста латентности direct на 9.5 MiB; зависимость Δrss от - concurrency за пределами C=20. +- **Подтверждено измерением:** память реплики ограничена конфигурацией и в эксперименте далеко от + лимита; direct снимает с API исходящий трафик в S3. **Опровергнуто для текущей версии:** снижение + входящего трафика API прямой загрузкой. **Остаётся гипотезой:** поведение памяти при C ≫ 20 (упор в + `UPLOAD_MAX_IN_FLIGHT`, 429) и на реальных фото, а не на шуме. diff --git a/evidence/lab4/bench/direct-1048576-c10.json b/evidence/lab4/bench/direct-1048576-c10.json index 3ea65699..641fc4b7 100644 --- a/evidence/lab4/bench/direct-1048576-c10.json +++ b/evidence/lab4/bench/direct-1048576-c10.json @@ -1,6 +1,6 @@ { - "date": "2026-10-23T13:32:53+00:00", - "git": "b32ce9a", + "date": "2026-10-23T13:37:36+00:00", + "git": "4badd5a", "params": { "mode": "direct", "size_bytes": 1048576, @@ -21,193 +21,194 @@ "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.939, + "duration_s": 0.97, "latency_ms": { - "p50": 168.0, - "p95": 249.0, - "p99": 276.8 + "p50": 159.8, + "p95": 252.1, + "p99": 272.0 }, "replicas": [ { "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 32727785, - "delta_tx_bytes": 202005, - "baseline_rss_bytes": 227401728, + "delta_rx_bytes": 31673930, + "delta_tx_bytes": 203789, + "baseline_rss_bytes": 233545728, "peak_memory_bytes": { - "rss": 237686784, - "heap_used": 55834912, - "external": 36616919, - "array_buffers": 32826575 + "rss": 236560384, + "heap_used": 54194600, + "external": 35034666, + "array_buffers": 31244322 }, - "delta_rss_bytes": 10285056, + "delta_rss_bytes": 3014656, "counters": { - "attachments.count_pending_direct": 19, - "attachments.insert_pending": 19, - "attachments.direct.initiated": 19, - "attachments.find_for_complete": 31, - "attachments.direct.verify_bytes": 32505856, - "attachments.decode.ms": 1715.4081129999686, - "attachments.mark_ready": 31, - "attachments.direct.completed": 31 + "attachments.count_pending_direct": 20, + "attachments.insert_pending": 20, + "attachments.direct.initiated": 20, + "attachments.find_for_complete": 30, + "attachments.direct.verify_bytes": 31457280, + "attachments.decode.ms": 1724.6966849999153, + "attachments.mark_ready": 30, + "attachments.direct.completed": 30 } }, { "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 20096072, - "delta_tx_bytes": 188541, - "baseline_rss_bytes": 215158784, + "delta_rx_bytes": 21149099, + "delta_tx_bytes": 198366, + "baseline_rss_bytes": 268025856, "peak_memory_bytes": { - "rss": 219668480, - "heap_used": 53068512, - "external": 26447857, - "array_buffers": 22657513 + "rss": 269074432, + "heap_used": 54788360, + "external": 25616254, + "array_buffers": 21825910 }, - "delta_rss_bytes": 4509696, + "delta_rss_bytes": 1048576, "counters": { - "attachments.count_pending_direct": 31, - "attachments.insert_pending": 31, - "attachments.direct.initiated": 31, - "attachments.find_for_complete": 19, - "attachments.direct.verify_bytes": 19922944, - "attachments.decode.ms": 711.329723999952, - "attachments.mark_ready": 19, - "attachments.direct.completed": 19 + "attachments.count_pending_direct": 30, + "attachments.insert_pending": 30, + "attachments.direct.initiated": 30, + "attachments.find_for_complete": 20, + "attachments.direct.verify_bytes": 20971520, + "attachments.decode.ms": 688.2958910000743, + "attachments.mark_ready": 20, + "attachments.direct.completed": 20 } } ], - "total_delta_rx_bytes": 52823857, - "total_delta_tx_bytes": 390546, - "rx_bytes_per_upload": 1056477, - "tx_bytes_per_upload": 7811, - "max_delta_rss_bytes": 10285056 + "total_delta_rx_bytes": 52823029, + "total_delta_tx_bytes": 402155, + "rx_bytes_per_upload": 1056461, + "tx_bytes_per_upload": 8043, + "max_delta_rss_bytes": 3014656 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.91, + "duration_s": 0.9, "latency_ms": { - "p50": 151.5, - "p95": 258.3, - "p99": 269.0 + "p50": 141.1, + "p95": 244.2, + "p99": 270.7 }, "replicas": [ { "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 27461632, - "delta_tx_bytes": 190483, - "baseline_rss_bytes": 235499520, + "delta_rx_bytes": 27465799, + "delta_tx_bytes": 191310, + "baseline_rss_bytes": 236560384, "peak_memory_bytes": { - "rss": 235499520, - "heap_used": 55890664, - "external": 36465919, - "array_buffers": 32675575 + "rss": 236953600, + "heap_used": 54493200, + "external": 30789946, + "array_buffers": 26999410 + }, + "delta_rss_bytes": 393216, + "counters": { + "attachments.count_pending_direct": 24, + "attachments.insert_pending": 24, + "attachments.direct.initiated": 24, + "attachments.find_for_complete": 26, + "attachments.direct.verify_bytes": 27262976, + "attachments.decode.ms": 1384.4109410000383, + "attachments.mark_ready": 26, + "attachments.direct.completed": 26 + } + }, + { + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 25357866, + "delta_tx_bytes": 191558, + "baseline_rss_bytes": 269074432, + "peak_memory_bytes": { + "rss": 270516224, + "heap_used": 54339648, + "external": 30902899, + "array_buffers": 27112555 + }, + "delta_rss_bytes": 1441792, + "counters": { + "attachments.count_pending_direct": 26, + "attachments.insert_pending": 26, + "attachments.direct.initiated": 26, + "attachments.find_for_complete": 24, + "attachments.direct.verify_bytes": 25165824, + "attachments.decode.ms": 1058.1902670000563, + "attachments.mark_ready": 24, + "attachments.direct.completed": 24 + } + } + ], + "total_delta_rx_bytes": 52823665, + "total_delta_tx_bytes": 382868, + "rx_bytes_per_upload": 1056473, + "tx_bytes_per_upload": 7657, + "max_delta_rss_bytes": 1441792 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 0.969, + "latency_ms": { + "p50": 154.4, + "p95": 274.5, + "p99": 328.1 + }, + "replicas": [ + { + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 24307994, + "delta_tx_bytes": 188454, + "baseline_rss_bytes": 236953600, + "peak_memory_bytes": { + "rss": 236953600, + "heap_used": 53822176, + "external": 29735853, + "array_buffers": 25943144 }, "delta_rss_bytes": 0, "counters": { - "attachments.count_pending_direct": 24, - "attachments.insert_pending": 24, - "attachments.direct.initiated": 24, - "attachments.find_for_complete": 26, - "attachments.direct.verify_bytes": 27262976, - "attachments.decode.ms": 1528.2079319999611, - "attachments.mark_ready": 26, - "attachments.direct.completed": 26 + "attachments.count_pending_direct": 27, + "attachments.insert_pending": 27, + "attachments.direct.initiated": 27, + "attachments.find_for_complete": 23, + "attachments.direct.verify_bytes": 24117248, + "attachments.decode.ms": 1452.813747000182, + "attachments.mark_ready": 23, + "attachments.direct.completed": 23 } }, { "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 25359054, - "delta_tx_bytes": 191385, - "baseline_rss_bytes": 209186816, + "delta_rx_bytes": 28514629, + "delta_tx_bytes": 189117, + "baseline_rss_bytes": 270516224, "peak_memory_bytes": { - "rss": 224399360, - "heap_used": 55409152, - "external": 31990072, - "array_buffers": 25029140 + "rss": 271433728, + "heap_used": 54290488, + "external": 34042295, + "array_buffers": 30251951 }, - "delta_rss_bytes": 15212544, + "delta_rss_bytes": 917504, "counters": { - "attachments.count_pending_direct": 26, - "attachments.insert_pending": 26, - "attachments.direct.initiated": 26, - "attachments.find_for_complete": 24, - "attachments.direct.verify_bytes": 25165824, - "attachments.decode.ms": 1024.5066690000385, - "attachments.mark_ready": 24, - "attachments.direct.completed": 24 + "attachments.claim_expired": 1, + "attachments.count_pending_direct": 23, + "attachments.insert_pending": 23, + "attachments.direct.initiated": 23, + "attachments.find_for_complete": 27, + "attachments.direct.verify_bytes": 28311552, + "attachments.decode.ms": 1425.6747240000404, + "attachments.mark_ready": 27, + "attachments.direct.completed": 27 } } ], - "total_delta_rx_bytes": 52820686, - "total_delta_tx_bytes": 381868, - "rx_bytes_per_upload": 1056414, - "tx_bytes_per_upload": 7637, - "max_delta_rss_bytes": 15212544 - }, - { - "uploads": 50, - "succeeded": 50, - "failed": 0, - "duration_s": 0.936, - "latency_ms": { - "p50": 164.5, - "p95": 215.8, - "p99": 221.0 - }, - "replicas": [ - { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 27463159, - "delta_tx_bytes": 187686, - "baseline_rss_bytes": 226234368, - "peak_memory_bytes": { - "rss": 231608320, - "heap_used": 55751432, - "external": 34449311, - "array_buffers": 30658967 - }, - "delta_rss_bytes": 5373952, - "counters": { - "attachments.count_pending_direct": 24, - "attachments.insert_pending": 24, - "attachments.direct.initiated": 24, - "attachments.find_for_complete": 26, - "attachments.direct.verify_bytes": 27262976, - "attachments.decode.ms": 975.2134359999909, - "attachments.mark_ready": 26, - "attachments.direct.completed": 26 - } - }, - { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 25357194, - "delta_tx_bytes": 186994, - "baseline_rss_bytes": 223174656, - "peak_memory_bytes": { - "rss": 225120256, - "heap_used": 53461888, - "external": 29769942, - "array_buffers": 25979406 - }, - "delta_rss_bytes": 1945600, - "counters": { - "attachments.count_pending_direct": 26, - "attachments.insert_pending": 26, - "attachments.direct.initiated": 26, - "attachments.find_for_complete": 24, - "attachments.direct.verify_bytes": 25165824, - "attachments.decode.ms": 805.6966420000099, - "attachments.mark_ready": 24, - "attachments.direct.completed": 24 - } - } - ], - "total_delta_rx_bytes": 52820353, - "total_delta_tx_bytes": 374680, - "rx_bytes_per_upload": 1056407, - "tx_bytes_per_upload": 7494, - "max_delta_rss_bytes": 5373952 + "total_delta_rx_bytes": 52822623, + "total_delta_tx_bytes": 377571, + "rx_bytes_per_upload": 1056452, + "tx_bytes_per_upload": 7551, + "max_delta_rss_bytes": 917504 } ] } diff --git a/evidence/lab4/bench/direct-131072-c10.json b/evidence/lab4/bench/direct-131072-c10.json index 5563c6b0..896afa48 100644 --- a/evidence/lab4/bench/direct-131072-c10.json +++ b/evidence/lab4/bench/direct-131072-c10.json @@ -1,6 +1,6 @@ { - "date": "2026-10-23T13:32:40+00:00", - "git": "b32ce9a", + "date": "2026-10-23T13:37:23+00:00", + "git": "4badd5a", "params": { "mode": "direct", "size_bytes": 131072, @@ -21,193 +21,193 @@ "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.421, + "duration_s": 0.413, "latency_ms": { - "p50": 68.3, - "p95": 104.0, - "p99": 117.0 + "p50": 72.1, + "p95": 114.3, + "p99": 142.9 }, "replicas": [ { "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 3707052, - "delta_tx_bytes": 186917, - "baseline_rss_bytes": 193892352, + "delta_rx_bytes": 3172654, + "delta_tx_bytes": 183439, + "baseline_rss_bytes": 224358400, "peak_memory_bytes": { - "rss": 195555328, - "heap_used": 52983040, - "external": 6914994, - "array_buffers": 3122532 + "rss": 224620544, + "heap_used": 49708416, + "external": 6066500, + "array_buffers": 2276156 }, - "delta_rss_bytes": 1662976, - "counters": { - "attachments.count_pending_direct": 23, - "attachments.insert_pending": 23, - "attachments.direct.initiated": 23, - "attachments.find_for_complete": 27, - "attachments.direct.verify_bytes": 3538944, - "attachments.decode.ms": 666.184485999991, - "attachments.mark_ready": 27, - "attachments.direct.completed": 27 - } - }, - { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 3172669, - "delta_tx_bytes": 183467, - "baseline_rss_bytes": 194297856, - "peak_memory_bytes": { - "rss": 196395008, - "heap_used": 53364080, - "external": 9480998, - "array_buffers": 5688536 - }, - "delta_rss_bytes": 2097152, + "delta_rss_bytes": 262144, "counters": { "attachments.count_pending_direct": 27, "attachments.insert_pending": 27, "attachments.direct.initiated": 27, "attachments.find_for_complete": 23, "attachments.direct.verify_bytes": 3014656, - "attachments.decode.ms": 578.859613999979, + "attachments.decode.ms": 395.56102700001793, "attachments.mark_ready": 23, "attachments.direct.completed": 23 } + }, + { + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 3707235, + "delta_tx_bytes": 187659, + "baseline_rss_bytes": 255918080, + "peak_memory_bytes": { + "rss": 257359872, + "heap_used": 50212920, + "external": 8800241, + "array_buffers": 5009897 + }, + "delta_rss_bytes": 1441792, + "counters": { + "attachments.count_pending_direct": 23, + "attachments.insert_pending": 23, + "attachments.direct.initiated": 23, + "attachments.find_for_complete": 27, + "attachments.direct.verify_bytes": 3538944, + "attachments.decode.ms": 743.5491730003268, + "attachments.mark_ready": 27, + "attachments.direct.completed": 27 + } } ], - "total_delta_rx_bytes": 6879721, - "total_delta_tx_bytes": 370384, - "rx_bytes_per_upload": 137594, - "tx_bytes_per_upload": 7408, - "max_delta_rss_bytes": 2097152 + "total_delta_rx_bytes": 6879889, + "total_delta_tx_bytes": 371098, + "rx_bytes_per_upload": 137598, + "tx_bytes_per_upload": 7422, + "max_delta_rss_bytes": 1441792 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.419, + "duration_s": 0.434, "latency_ms": { - "p50": 78.9, - "p95": 123.4, - "p99": 144.3 + "p50": 82.0, + "p95": 119.6, + "p99": 136.5 }, "replicas": [ { "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 3172151, - "delta_tx_bytes": 182160, - "baseline_rss_bytes": 195555328, + "delta_rx_bytes": 3572309, + "delta_tx_bytes": 186069, + "baseline_rss_bytes": 224620544, "peak_memory_bytes": { - "rss": 195686400, - "heap_used": 55040192, - "external": 7674854, - "array_buffers": 3882392 + "rss": 224751616, + "heap_used": 49977872, + "external": 6204496, + "array_buffers": 2414152 }, "delta_rss_bytes": 131072, - "counters": { - "attachments.count_pending_direct": 27, - "attachments.insert_pending": 27, - "attachments.direct.initiated": 27, - "attachments.find_for_complete": 23, - "attachments.direct.verify_bytes": 3014656, - "attachments.decode.ms": 521.6287550000125, - "attachments.mark_ready": 23, - "attachments.direct.completed": 23 - } - }, - { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 3706567, - "delta_tx_bytes": 185794, - "baseline_rss_bytes": 196395008, - "peak_memory_bytes": { - "rss": 196788224, - "heap_used": 53658784, - "external": 10141571, - "array_buffers": 6134972 - }, - "delta_rss_bytes": 393216, - "counters": { - "attachments.count_pending_direct": 23, - "attachments.insert_pending": 23, - "attachments.direct.initiated": 23, - "attachments.find_for_complete": 27, - "attachments.direct.verify_bytes": 3538944, - "attachments.decode.ms": 674.9609369999744, - "attachments.mark_ready": 27, - "attachments.direct.completed": 27 - } - } - ], - "total_delta_rx_bytes": 6878718, - "total_delta_tx_bytes": 367954, - "rx_bytes_per_upload": 137574, - "tx_bytes_per_upload": 7359, - "max_delta_rss_bytes": 393216 - }, - { - "uploads": 50, - "succeeded": 50, - "failed": 0, - "duration_s": 0.395, - "latency_ms": { - "p50": 67.0, - "p95": 95.3, - "p99": 116.5 - }, - "replicas": [ - { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 3305839, - "delta_tx_bytes": 183731, - "baseline_rss_bytes": 191291392, - "peak_memory_bytes": { - "rss": 192471040, - "heap_used": 56329664, - "external": 7513663, - "array_buffers": 3721201 - }, - "delta_rss_bytes": 1179648, - "counters": { - "attachments.count_pending_direct": 26, - "attachments.insert_pending": 26, - "attachments.direct.initiated": 26, - "attachments.find_for_complete": 24, - "attachments.direct.verify_bytes": 3145728, - "attachments.decode.ms": 499.52755800001614, - "attachments.mark_ready": 24, - "attachments.direct.completed": 24 - } - }, - { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 3572208, - "delta_tx_bytes": 183605, - "baseline_rss_bytes": 196788224, - "peak_memory_bytes": { - "rss": 197181440, - "heap_used": 55084856, - "external": 7691196, - "array_buffers": 3898734 - }, - "delta_rss_bytes": 393216, "counters": { "attachments.count_pending_direct": 24, "attachments.insert_pending": 24, "attachments.direct.initiated": 24, "attachments.find_for_complete": 26, "attachments.direct.verify_bytes": 3407872, - "attachments.decode.ms": 667.7248300000065, + "attachments.decode.ms": 610.345750999928, "attachments.mark_ready": 26, "attachments.direct.completed": 26 } + }, + { + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 3306233, + "delta_tx_bytes": 183451, + "baseline_rss_bytes": 257359872, + "peak_memory_bytes": { + "rss": 262864896, + "heap_used": 53884096, + "external": 9284140, + "array_buffers": 5493796 + }, + "delta_rss_bytes": 5505024, + "counters": { + "attachments.count_pending_direct": 26, + "attachments.insert_pending": 26, + "attachments.direct.initiated": 26, + "attachments.find_for_complete": 24, + "attachments.direct.verify_bytes": 3145728, + "attachments.decode.ms": 675.0934380001272, + "attachments.mark_ready": 24, + "attachments.direct.completed": 24 + } } ], - "total_delta_rx_bytes": 6878047, - "total_delta_tx_bytes": 367336, - "rx_bytes_per_upload": 137561, + "total_delta_rx_bytes": 6878542, + "total_delta_tx_bytes": 369520, + "rx_bytes_per_upload": 137571, + "tx_bytes_per_upload": 7390, + "max_delta_rss_bytes": 5505024 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 0.457, + "latency_ms": { + "p50": 69.4, + "p95": 160.1, + "p99": 168.0 + }, + "replicas": [ + { + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 3973401, + "delta_tx_bytes": 186806, + "baseline_rss_bytes": 224751616, + "peak_memory_bytes": { + "rss": 231305216, + "heap_used": 52952680, + "external": 7971474, + "array_buffers": 4181130 + }, + "delta_rss_bytes": 6553600, + "counters": { + "attachments.count_pending_direct": 21, + "attachments.insert_pending": 21, + "attachments.direct.initiated": 21, + "attachments.find_for_complete": 29, + "attachments.direct.verify_bytes": 3801088, + "attachments.decode.ms": 828.3032130000065, + "attachments.mark_ready": 29, + "attachments.direct.completed": 29 + } + }, + { + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 2904621, + "delta_tx_bytes": 180542, + "baseline_rss_bytes": 262864896, + "peak_memory_bytes": { + "rss": 262995968, + "heap_used": 53715664, + "external": 7518119, + "array_buffers": 3727743 + }, + "delta_rss_bytes": 131072, + "counters": { + "attachments.count_pending_direct": 29, + "attachments.insert_pending": 29, + "attachments.direct.initiated": 29, + "attachments.find_for_complete": 21, + "attachments.direct.verify_bytes": 2752512, + "attachments.decode.ms": 312.0048850000021, + "attachments.mark_ready": 21, + "attachments.direct.completed": 21 + } + } + ], + "total_delta_rx_bytes": 6878022, + "total_delta_tx_bytes": 367348, + "rx_bytes_per_upload": 137560, "tx_bytes_per_upload": 7347, - "max_delta_rss_bytes": 1179648 + "max_delta_rss_bytes": 6553600 } ] } diff --git a/evidence/lab4/bench/direct-9961472-c10.json b/evidence/lab4/bench/direct-9961472-c10.json index fc84204b..1aa8c095 100644 --- a/evidence/lab4/bench/direct-9961472-c10.json +++ b/evidence/lab4/bench/direct-9961472-c10.json @@ -1,6 +1,6 @@ { - "date": "2026-10-23T13:33:31+00:00", - "git": "b32ce9a", + "date": "2026-10-23T13:38:14+00:00", + "git": "4badd5a", "params": { "mode": "direct", "size_bytes": 9961472, @@ -21,193 +21,193 @@ "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 5.212, + "duration_s": 4.981, "latency_ms": { - "p50": 693.0, - "p95": 1084.0, - "p99": 1175.0 + "p50": 754.7, + "p95": 975.5, + "p99": 1146.0 }, "replicas": [ { "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 269480509, - "delta_tx_bytes": 305993, - "baseline_rss_bytes": 283983872, + "delta_rx_bytes": 289415606, + "delta_tx_bytes": 315409, + "baseline_rss_bytes": 233209856, "peak_memory_bytes": { - "rss": 404570112, - "heap_used": 50680344, - "external": 123548186, - "array_buffers": 119757842 + "rss": 348733440, + "heap_used": 50095696, + "external": 115684307, + "array_buffers": 111893963 }, - "delta_rss_bytes": 120586240, + "delta_rss_bytes": 115523584, + "counters": { + "attachments.count_pending_direct": 21, + "attachments.insert_pending": 21, + "attachments.direct.initiated": 21, + "attachments.find_for_complete": 29, + "attachments.direct.verify_bytes": 288882688, + "attachments.decode.ms": 7608.848039000004, + "attachments.mark_ready": 29, + "attachments.direct.completed": 29 + } + }, + { + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 209597436, + "delta_tx_bytes": 298627, + "baseline_rss_bytes": 299487232, + "peak_memory_bytes": { + "rss": 330563584, + "heap_used": 51925192, + "external": 97861662, + "array_buffers": 94071318 + }, + "delta_rss_bytes": 31076352, + "counters": { + "attachments.count_pending_direct": 29, + "attachments.insert_pending": 29, + "attachments.direct.initiated": 29, + "attachments.find_for_complete": 21, + "attachments.direct.verify_bytes": 209190912, + "attachments.decode.ms": 5015.750637000019, + "attachments.mark_ready": 21, + "attachments.direct.completed": 21 + } + } + ], + "total_delta_rx_bytes": 499013042, + "total_delta_tx_bytes": 614036, + "rx_bytes_per_upload": 9980261, + "tx_bytes_per_upload": 12281, + "max_delta_rss_bytes": 115523584 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 5.254, + "latency_ms": { + "p50": 900.1, + "p95": 1222.8, + "p99": 1235.6 + }, + "replicas": [ + { + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 309427096, + "delta_tx_bytes": 332725, + "baseline_rss_bytes": 282836992, + "peak_memory_bytes": { + "rss": 370515968, + "heap_used": 52368944, + "external": 134179853, + "array_buffers": 130389509 + }, + "delta_rss_bytes": 87678976, + "counters": { + "attachments.count_pending_direct": 19, + "attachments.insert_pending": 19, + "attachments.direct.initiated": 19, + "attachments.find_for_complete": 31, + "attachments.direct.verify_bytes": 308805632, + "attachments.decode.ms": 8379.456620000012, + "attachments.mark_ready": 31, + "attachments.direct.completed": 31 + } + }, + { + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 189647218, + "delta_tx_bytes": 291721, + "baseline_rss_bytes": 286593024, + "peak_memory_bytes": { + "rss": 338497536, + "heap_used": 53161904, + "external": 107895361, + "array_buffers": 104105017 + }, + "delta_rss_bytes": 51904512, + "counters": { + "attachments.count_pending_direct": 31, + "attachments.insert_pending": 31, + "attachments.direct.initiated": 31, + "attachments.find_for_complete": 19, + "attachments.direct.verify_bytes": 189267968, + "attachments.decode.ms": 3974.233845000039, + "attachments.mark_ready": 19, + "attachments.direct.completed": 19 + } + } + ], + "total_delta_rx_bytes": 499074314, + "total_delta_tx_bytes": 624446, + "rx_bytes_per_upload": 9981486, + "tx_bytes_per_upload": 12489, + "max_delta_rss_bytes": 87678976 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 4.652, + "latency_ms": { + "p50": 692.0, + "p95": 1018.5, + "p99": 1133.8 + }, + "replicas": [ + { + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 269445871, + "delta_tx_bytes": 269717, + "baseline_rss_bytes": 340176896, + "peak_memory_bytes": { + "rss": 342388736, + "heap_used": 50625080, + "external": 119380564, + "array_buffers": 100369674 + }, + "delta_rss_bytes": 2211840, "counters": { "attachments.count_pending_direct": 23, "attachments.insert_pending": 23, "attachments.direct.initiated": 23, "attachments.find_for_complete": 27, "attachments.direct.verify_bytes": 268959744, - "attachments.decode.ms": 6438.860078999976, + "attachments.decode.ms": 7779.908828999905, "attachments.mark_ready": 27, "attachments.direct.completed": 27 } }, { "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 229561819, - "delta_tx_bytes": 313227, - "baseline_rss_bytes": 328466432, + "delta_rx_bytes": 229550093, + "delta_tx_bytes": 268720, + "baseline_rss_bytes": 308649984, "peak_memory_bytes": { - "rss": 385613824, - "heap_used": 52894936, - "external": 114148298, - "array_buffers": 110357821 + "rss": 354787328, + "heap_used": 52204288, + "external": 121315649, + "array_buffers": 100267973 }, - "delta_rss_bytes": 57147392, + "delta_rss_bytes": 46137344, "counters": { "attachments.count_pending_direct": 27, "attachments.insert_pending": 27, "attachments.direct.initiated": 27, "attachments.find_for_complete": 23, "attachments.direct.verify_bytes": 229113856, - "attachments.decode.ms": 5666.515076999989, + "attachments.decode.ms": 6111.090034999943, "attachments.mark_ready": 23, "attachments.direct.completed": 23 } } ], - "total_delta_rx_bytes": 499042328, - "total_delta_tx_bytes": 619220, - "rx_bytes_per_upload": 9980847, - "tx_bytes_per_upload": 12384, - "max_delta_rss_bytes": 120586240 - }, - { - "uploads": 50, - "succeeded": 50, - "failed": 0, - "duration_s": 4.689, - "latency_ms": { - "p50": 668.9, - "p95": 1081.6, - "p99": 1164.9 - }, - "replicas": [ - { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 249519521, - "delta_tx_bytes": 283986, - "baseline_rss_bytes": 324087808, - "peak_memory_bytes": { - "rss": 408424448, - "heap_used": 51009296, - "external": 126698352, - "array_buffers": 122908008 - }, - "delta_rss_bytes": 84336640, - "counters": { - "attachments.count_pending_direct": 25, - "attachments.insert_pending": 25, - "attachments.direct.initiated": 25, - "attachments.find_for_complete": 25, - "attachments.direct.verify_bytes": 249036800, - "attachments.decode.ms": 6319.900557000001, - "attachments.mark_ready": 25, - "attachments.direct.completed": 25 - } - }, - { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 249503096, - "delta_tx_bytes": 276564, - "baseline_rss_bytes": 320462848, - "peak_memory_bytes": { - "rss": 388620288, - "heap_used": 50687792, - "external": 135613815, - "array_buffers": 131823471 - }, - "delta_rss_bytes": 68157440, - "counters": { - "attachments.count_pending_direct": 25, - "attachments.insert_pending": 25, - "attachments.direct.initiated": 25, - "attachments.find_for_complete": 25, - "attachments.direct.verify_bytes": 249036800, - "attachments.decode.ms": 6777.923052999977, - "attachments.mark_ready": 25, - "attachments.direct.completed": 25 - } - } - ], - "total_delta_rx_bytes": 499022617, - "total_delta_tx_bytes": 560550, - "rx_bytes_per_upload": 9980452, - "tx_bytes_per_upload": 11211, - "max_delta_rss_bytes": 84336640 - }, - { - "uploads": 50, - "succeeded": 50, - "failed": 0, - "duration_s": 4.773, - "latency_ms": { - "p50": 695.7, - "p95": 1021.4, - "p99": 1371.6 - }, - "replicas": [ - { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 269526599, - "delta_tx_bytes": 273432, - "baseline_rss_bytes": 303702016, - "peak_memory_bytes": { - "rss": 389439488, - "heap_used": 50333808, - "external": 124077219, - "array_buffers": 120286875 - }, - "delta_rss_bytes": 85737472, - "counters": { - "attachments.count_pending_direct": 23, - "attachments.insert_pending": 23, - "attachments.direct.initiated": 23, - "attachments.find_for_complete": 27, - "attachments.direct.verify_bytes": 268959744, - "attachments.decode.ms": 7513.258526999998, - "attachments.mark_ready": 27, - "attachments.direct.completed": 27 - } - }, - { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 229549332, - "delta_tx_bytes": 263832, - "baseline_rss_bytes": 367620096, - "peak_memory_bytes": { - "rss": 367620096, - "heap_used": 50715496, - "external": 84222677, - "array_buffers": 80432333 - }, - "delta_rss_bytes": 0, - "counters": { - "attachments.count_pending_direct": 27, - "attachments.insert_pending": 27, - "attachments.direct.initiated": 27, - "attachments.find_for_complete": 23, - "attachments.direct.verify_bytes": 229113856, - "attachments.decode.ms": 6132.513337000011, - "attachments.mark_ready": 23, - "attachments.direct.completed": 23 - } - } - ], - "total_delta_rx_bytes": 499075931, - "total_delta_tx_bytes": 537264, - "rx_bytes_per_upload": 9981519, - "tx_bytes_per_upload": 10745, - "max_delta_rss_bytes": 85737472 + "total_delta_rx_bytes": 498995964, + "total_delta_tx_bytes": 538437, + "rx_bytes_per_upload": 9979919, + "tx_bytes_per_upload": 10769, + "max_delta_rss_bytes": 46137344 } ] } diff --git a/evidence/lab4/bench/proxy-1048576-c10.json b/evidence/lab4/bench/proxy-1048576-c10.json index ea636ea8..837c66c0 100644 --- a/evidence/lab4/bench/proxy-1048576-c10.json +++ b/evidence/lab4/bench/proxy-1048576-c10.json @@ -1,6 +1,6 @@ { - "date": "2026-10-23T13:32:46+00:00", - "git": "b32ce9a", + "date": "2026-10-23T13:37:29+00:00", + "git": "4badd5a", "params": { "mode": "proxy", "size_bytes": 1048576, @@ -21,29 +21,29 @@ "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.854, + "duration_s": 0.885, "latency_ms": { - "p50": 142.8, - "p95": 192.1, - "p99": 208.3 + "p50": 156.2, + "p95": 207.1, + "p99": 235.1 }, "replicas": [ { "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 26385133, - "delta_tx_bytes": 26401283, - "baseline_rss_bytes": 197070848, + "delta_rx_bytes": 26389500, + "delta_tx_bytes": 26402061, + "baseline_rss_bytes": 231522304, "peak_memory_bytes": { - "rss": 217759744, - "heap_used": 55062960, - "external": 22455454, - "array_buffers": 18665110 + "rss": 231522304, + "heap_used": 52773312, + "external": 23343330, + "array_buffers": 19552986 }, - "delta_rss_bytes": 20688896, + "delta_rss_bytes": 0, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, - "attachments.decode.ms": 1479.7760639999906, + "attachments.decode.ms": 1601.4592339998344, "attachments.proxy.bytes_to_s3": 26214400, "attachments.mark_ready": 25, "attachments.upload.created": 25 @@ -51,59 +51,59 @@ }, { "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 26379459, - "delta_tx_bytes": 26398957, - "baseline_rss_bytes": 199708672, + "delta_rx_bytes": 26384219, + "delta_tx_bytes": 26403431, + "baseline_rss_bytes": 264105984, "peak_memory_bytes": { - "rss": 214302720, - "heap_used": 55570040, - "external": 24543846, - "array_buffers": 20174104 + "rss": 266989568, + "heap_used": 49942048, + "external": 24835619, + "array_buffers": 18813186 }, - "delta_rss_bytes": 14594048, + "delta_rss_bytes": 2883584, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, - "attachments.decode.ms": 1331.2164019999764, + "attachments.decode.ms": 1562.9852019998943, "attachments.proxy.bytes_to_s3": 26214400, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 52764592, - "total_delta_tx_bytes": 52800240, - "rx_bytes_per_upload": 1055292, - "tx_bytes_per_upload": 1056005, - "max_delta_rss_bytes": 20688896 + "total_delta_rx_bytes": 52773719, + "total_delta_tx_bytes": 52805492, + "rx_bytes_per_upload": 1055474, + "tx_bytes_per_upload": 1056110, + "max_delta_rss_bytes": 2883584 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.82, + "duration_s": 0.771, "latency_ms": { - "p50": 137.2, - "p95": 181.4, - "p99": 245.1 + "p50": 131.9, + "p95": 174.7, + "p99": 175.6 }, "replicas": [ { "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 26381801, - "delta_tx_bytes": 26401373, - "baseline_rss_bytes": 217759744, + "delta_rx_bytes": 26384709, + "delta_tx_bytes": 26401945, + "baseline_rss_bytes": 231522304, "peak_memory_bytes": { - "rss": 220250112, - "heap_used": 50014112, - "external": 24298087, - "array_buffers": 20507743 + "rss": 233619456, + "heap_used": 51880616, + "external": 32630526, + "array_buffers": 26533593 }, - "delta_rss_bytes": 2490368, + "delta_rss_bytes": 2097152, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, - "attachments.decode.ms": 1444.9002450000553, + "attachments.decode.ms": 1264.4056559997844, "attachments.proxy.bytes_to_s3": 26214400, "attachments.mark_ready": 25, "attachments.upload.created": 25 @@ -111,59 +111,59 @@ }, { "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 26383381, - "delta_tx_bytes": 26401803, - "baseline_rss_bytes": 209428480, + "delta_rx_bytes": 26376275, + "delta_tx_bytes": 26401865, + "baseline_rss_bytes": 266989568, "peak_memory_bytes": { - "rss": 212426752, - "heap_used": 49637440, - "external": 21932135, - "array_buffers": 18141791 + "rss": 266989568, + "heap_used": 50529400, + "external": 26599488, + "array_buffers": 22809144 }, - "delta_rss_bytes": 2998272, + "delta_rss_bytes": 0, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, - "attachments.decode.ms": 1494.1810810000025, + "attachments.decode.ms": 1410.3865230001393, "attachments.proxy.bytes_to_s3": 26214400, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 52765182, - "total_delta_tx_bytes": 52803176, - "rx_bytes_per_upload": 1055304, - "tx_bytes_per_upload": 1056064, - "max_delta_rss_bytes": 2998272 + "total_delta_rx_bytes": 52760984, + "total_delta_tx_bytes": 52803810, + "rx_bytes_per_upload": 1055220, + "tx_bytes_per_upload": 1056076, + "max_delta_rss_bytes": 2097152 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.818, + "duration_s": 0.792, "latency_ms": { - "p50": 146.1, - "p95": 209.1, - "p99": 245.9 + "p50": 126.4, + "p95": 182.7, + "p99": 191.3 }, "replicas": [ { "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 26379700, - "delta_tx_bytes": 26402387, - "baseline_rss_bytes": 216440832, + "delta_rx_bytes": 26385221, + "delta_tx_bytes": 26404709, + "baseline_rss_bytes": 233619456, "peak_memory_bytes": { - "rss": 229879808, - "heap_used": 52186344, - "external": 34161027, - "array_buffers": 30370683 + "rss": 233619456, + "heap_used": 51420296, + "external": 29512306, + "array_buffers": 25721962 }, - "delta_rss_bytes": 13438976, + "delta_rss_bytes": 0, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, - "attachments.decode.ms": 1491.96600400006, + "attachments.decode.ms": 1199.6556880001444, "attachments.proxy.bytes_to_s3": 26214400, "attachments.mark_ready": 25, "attachments.upload.created": 25 @@ -171,31 +171,31 @@ }, { "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 26384562, - "delta_tx_bytes": 26402573, - "baseline_rss_bytes": 212082688, + "delta_rx_bytes": 26378117, + "delta_tx_bytes": 26400049, + "baseline_rss_bytes": 266989568, "peak_memory_bytes": { - "rss": 217251840, - "heap_used": 51036376, - "external": 26410042, - "array_buffers": 22619698 + "rss": 267907072, + "heap_used": 51921864, + "external": 30362031, + "array_buffers": 26571687 }, - "delta_rss_bytes": 5169152, + "delta_rss_bytes": 917504, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, - "attachments.decode.ms": 1386.4965829999855, + "attachments.decode.ms": 1393.8144420000026, "attachments.proxy.bytes_to_s3": 26214400, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 52764262, - "total_delta_tx_bytes": 52804960, - "rx_bytes_per_upload": 1055285, - "tx_bytes_per_upload": 1056099, - "max_delta_rss_bytes": 13438976 + "total_delta_rx_bytes": 52763338, + "total_delta_tx_bytes": 52804758, + "rx_bytes_per_upload": 1055267, + "tx_bytes_per_upload": 1056095, + "max_delta_rss_bytes": 917504 } ] } diff --git a/evidence/lab4/bench/proxy-131072-c10.json b/evidence/lab4/bench/proxy-131072-c10.json index 84939c02..7cabee16 100644 --- a/evidence/lab4/bench/proxy-131072-c10.json +++ b/evidence/lab4/bench/proxy-131072-c10.json @@ -1,6 +1,6 @@ { - "date": "2026-10-23T13:32:35+00:00", - "git": "b32ce9a", + "date": "2026-10-23T13:37:18+00:00", + "git": "4badd5a", "params": { "mode": "proxy", "size_bytes": 131072, @@ -21,89 +21,29 @@ "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.363, + "duration_s": 0.331, "latency_ms": { - "p50": 60.4, - "p95": 113.2, - "p99": 139.1 + "p50": 57.2, + "p95": 80.6, + "p99": 88.9 }, "replicas": [ { "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 3381618, - "delta_tx_bytes": 3399633, - "baseline_rss_bytes": 180125696, + "delta_rx_bytes": 3385418, + "delta_tx_bytes": 3400077, + "baseline_rss_bytes": 218017792, "peak_memory_bytes": { - "rss": 187985920, - "heap_used": 50414440, - "external": 8673461, - "array_buffers": 4505870 - }, - "delta_rss_bytes": 7860224, - "counters": { - "attachments.insert_pending": 25, - "attachments.proxy.bytes_in": 3276800, - "attachments.decode.ms": 528.2537349999984, - "attachments.proxy.bytes_to_s3": 3276800, - "attachments.mark_ready": 25, - "attachments.upload.created": 25 - } - }, - { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 3384159, - "delta_tx_bytes": 3399409, - "baseline_rss_bytes": 181567488, - "peak_memory_bytes": { - "rss": 189956096, - "heap_used": 51892912, - "external": 9517393, - "array_buffers": 5724803 - }, - "delta_rss_bytes": 8388608, - "counters": { - "attachments.insert_pending": 25, - "attachments.proxy.bytes_in": 3276800, - "attachments.decode.ms": 670.2341740000047, - "attachments.proxy.bytes_to_s3": 3276800, - "attachments.mark_ready": 25, - "attachments.upload.created": 25 - } - } - ], - "total_delta_rx_bytes": 6765777, - "total_delta_tx_bytes": 6799042, - "rx_bytes_per_upload": 135316, - "tx_bytes_per_upload": 135981, - "max_delta_rss_bytes": 8388608 - }, - { - "uploads": 50, - "succeeded": 50, - "failed": 0, - "duration_s": 0.351, - "latency_ms": { - "p50": 51.1, - "p95": 105.8, - "p99": 118.4 - }, - "replicas": [ - { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 3380483, - "delta_tx_bytes": 3398895, - "baseline_rss_bytes": 187985920, - "peak_memory_bytes": { - "rss": 190345216, - "heap_used": 52699440, - "external": 10502334, - "array_buffers": 6709680 + "rss": 220377088, + "heap_used": 50283096, + "external": 8478293, + "array_buffers": 4687725 }, "delta_rss_bytes": 2359296, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, - "attachments.decode.ms": 633.1175999999905, + "attachments.decode.ms": 575.8783200000762, "attachments.proxy.bytes_to_s3": 3276800, "attachments.mark_ready": 25, "attachments.upload.created": 25 @@ -111,93 +51,151 @@ }, { "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 3376222, - "delta_tx_bytes": 3395913, - "baseline_rss_bytes": 189956096, + "delta_rx_bytes": 3385072, + "delta_tx_bytes": 3399873, + "baseline_rss_bytes": 249233408, "peak_memory_bytes": { - "rss": 193220608, - "heap_used": 52790776, - "external": 10858460, - "array_buffers": 7065998 + "rss": 252379136, + "heap_used": 50306832, + "external": 9099311, + "array_buffers": 5308711 }, - "delta_rss_bytes": 3264512, + "delta_rss_bytes": 3145728, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, - "attachments.decode.ms": 359.4751439999891, + "attachments.decode.ms": 590.1611679997877, "attachments.proxy.bytes_to_s3": 3276800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 6756705, - "total_delta_tx_bytes": 6794808, - "rx_bytes_per_upload": 135134, - "tx_bytes_per_upload": 135896, - "max_delta_rss_bytes": 3264512 + "total_delta_rx_bytes": 6770490, + "total_delta_tx_bytes": 6799950, + "rx_bytes_per_upload": 135410, + "tx_bytes_per_upload": 135999, + "max_delta_rss_bytes": 3145728 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.354, + "duration_s": 0.316, "latency_ms": { - "p50": 60.3, - "p95": 96.3, - "p99": 120.9 + "p50": 55.2, + "p95": 87.2, + "p99": 99.2 }, "replicas": [ { "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 3377197, - "delta_tx_bytes": 3396754, - "baseline_rss_bytes": 190345216, + "delta_rx_bytes": 3376247, + "delta_tx_bytes": 3395251, + "baseline_rss_bytes": 220508160, "peak_memory_bytes": { - "rss": 193884160, - "heap_used": 53140928, - "external": 13245272, - "array_buffers": 9452618 + "rss": 223653888, + "heap_used": 50422968, + "external": 8537602, + "array_buffers": 4747258 }, - "delta_rss_bytes": 3538944, + "delta_rss_bytes": 3145728, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, - "attachments.decode.ms": 518.702403999996, + "attachments.decode.ms": 568.8078680001199, "attachments.proxy.bytes_to_s3": 3276800, "attachments.mark_ready": 25, - "attachments.upload.created": 25, - "attachments.claim_expired": 1 + "attachments.upload.created": 25 } }, { "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 3377745, - "delta_tx_bytes": 3397208, - "baseline_rss_bytes": 193220608, + "delta_rx_bytes": 3378432, + "delta_tx_bytes": 3395587, + "baseline_rss_bytes": 252379136, "peak_memory_bytes": { - "rss": 193744896, - "heap_used": 52880424, - "external": 11681352, - "array_buffers": 7888698 + "rss": 255524864, + "heap_used": 49969448, + "external": 10496847, + "array_buffers": 6706503 + }, + "delta_rss_bytes": 3145728, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 3276800, + "attachments.decode.ms": 575.633941000211, + "attachments.proxy.bytes_to_s3": 3276800, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 + } + } + ], + "total_delta_rx_bytes": 6754679, + "total_delta_tx_bytes": 6790838, + "rx_bytes_per_upload": 135094, + "tx_bytes_per_upload": 135817, + "max_delta_rss_bytes": 3145728 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 0.364, + "latency_ms": { + "p50": 61.0, + "p95": 100.6, + "p99": 109.1 + }, + "replicas": [ + { + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 3377231, + "delta_tx_bytes": 3396261, + "baseline_rss_bytes": 223653888, + "peak_memory_bytes": { + "rss": 224178176, + "heap_used": 50203952, + "external": 12043208, + "array_buffers": 8243836 }, "delta_rss_bytes": 524288, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, - "attachments.decode.ms": 643.8722639999905, + "attachments.decode.ms": 554.1256450000219, "attachments.proxy.bytes_to_s3": 3276800, "attachments.mark_ready": 25, - "attachments.upload.created": 25, - "attachments.claim_expired": 1 + "attachments.upload.created": 25 + } + }, + { + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 3376327, + "delta_tx_bytes": 3397971, + "baseline_rss_bytes": 255524864, + "peak_memory_bytes": { + "rss": 255655936, + "heap_used": 50414024, + "external": 11828788, + "array_buffers": 8038444 + }, + "delta_rss_bytes": 131072, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 3276800, + "attachments.decode.ms": 655.3769140000804, + "attachments.proxy.bytes_to_s3": 3276800, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 6754942, - "total_delta_tx_bytes": 6793962, - "rx_bytes_per_upload": 135099, - "tx_bytes_per_upload": 135879, - "max_delta_rss_bytes": 3538944 + "total_delta_rx_bytes": 6753558, + "total_delta_tx_bytes": 6794232, + "rx_bytes_per_upload": 135071, + "tx_bytes_per_upload": 135885, + "max_delta_rss_bytes": 524288 } ] } diff --git a/evidence/lab4/bench/proxy-9961472-c10.json b/evidence/lab4/bench/proxy-9961472-c10.json index d41c413e..da8a1462 100644 --- a/evidence/lab4/bench/proxy-9961472-c10.json +++ b/evidence/lab4/bench/proxy-9961472-c10.json @@ -1,6 +1,6 @@ { - "date": "2026-10-23T13:33:12+00:00", - "git": "b32ce9a", + "date": "2026-10-23T13:37:55+00:00", + "git": "4badd5a", "params": { "mode": "proxy", "size_bytes": 9961472, @@ -21,29 +21,29 @@ "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 4.768, + "duration_s": 4.75, "latency_ms": { - "p50": 712.4, - "p95": 946.8, - "p99": 1012.6 + "p50": 586.5, + "p95": 851.2, + "p99": 924.0 }, "replicas": [ { "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 249658454, - "delta_tx_bytes": 249823407, - "baseline_rss_bytes": 252616704, + "delta_rx_bytes": 249636366, + "delta_tx_bytes": 249800729, + "baseline_rss_bytes": 242110464, "peak_memory_bytes": { - "rss": 364154880, - "heap_used": 49794104, - "external": 95705802, - "array_buffers": 78688662 + "rss": 302125056, + "heap_used": 50330056, + "external": 79829666, + "array_buffers": 76039322 }, - "delta_rss_bytes": 111538176, + "delta_rss_bytes": 60014592, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, - "attachments.decode.ms": 7843.138166000004, + "attachments.decode.ms": 7776.616332000063, "attachments.proxy.bytes_to_s3": 249036800, "attachments.mark_ready": 25, "attachments.upload.created": 25 @@ -51,59 +51,59 @@ }, { "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 249677855, - "delta_tx_bytes": 249819092, - "baseline_rss_bytes": 228974592, + "delta_rx_bytes": 249671660, + "delta_tx_bytes": 249815904, + "baseline_rss_bytes": 279318528, "peak_memory_bytes": { - "rss": 359043072, - "heap_used": 50979480, - "external": 105502404, - "array_buffers": 101712060 + "rss": 335978496, + "heap_used": 50779240, + "external": 99370165, + "array_buffers": 91157282 }, - "delta_rss_bytes": 130068480, + "delta_rss_bytes": 56659968, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, - "attachments.decode.ms": 7969.015626000037, + "attachments.decode.ms": 7460.193873999873, "attachments.proxy.bytes_to_s3": 249036800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 499336309, - "total_delta_tx_bytes": 499642499, - "rx_bytes_per_upload": 9986726, - "tx_bytes_per_upload": 9992850, - "max_delta_rss_bytes": 130068480 + "total_delta_rx_bytes": 499308026, + "total_delta_tx_bytes": 499616633, + "rx_bytes_per_upload": 9986161, + "tx_bytes_per_upload": 9992333, + "max_delta_rss_bytes": 60014592 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 4.843, + "duration_s": 4.661, "latency_ms": { - "p50": 687.8, - "p95": 997.1, - "p99": 1046.8 + "p50": 656.5, + "p95": 888.8, + "p99": 959.9 }, "replicas": [ { "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 249636288, - "delta_tx_bytes": 249801589, - "baseline_rss_bytes": 349237248, + "delta_rx_bytes": 249639519, + "delta_tx_bytes": 249795892, + "baseline_rss_bytes": 281255936, "peak_memory_bytes": { - "rss": 367636480, - "heap_used": 50033840, - "external": 85069927, - "array_buffers": 81278745 + "rss": 326279168, + "heap_used": 49159264, + "external": 96056449, + "array_buffers": 80803439 }, - "delta_rss_bytes": 18399232, + "delta_rss_bytes": 45023232, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, - "attachments.decode.ms": 7391.692848000006, + "attachments.decode.ms": 7871.141386000323, "attachments.proxy.bytes_to_s3": 249036800, "attachments.mark_ready": 25, "attachments.upload.created": 25 @@ -111,59 +111,59 @@ }, { "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 249653773, - "delta_tx_bytes": 249814308, - "baseline_rss_bytes": 270807040, + "delta_rx_bytes": 249675448, + "delta_tx_bytes": 249820400, + "baseline_rss_bytes": 305864704, "peak_memory_bytes": { - "rss": 336084992, - "heap_used": 49357656, - "external": 85003828, - "array_buffers": 81213484 + "rss": 325267456, + "heap_used": 49459520, + "external": 94883105, + "array_buffers": 91092761 }, - "delta_rss_bytes": 65277952, + "delta_rss_bytes": 19402752, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, - "attachments.decode.ms": 7897.397337000031, + "attachments.decode.ms": 7501.386025000014, "attachments.proxy.bytes_to_s3": 249036800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 499290061, - "total_delta_tx_bytes": 499615897, - "rx_bytes_per_upload": 9985801, - "tx_bytes_per_upload": 9992318, - "max_delta_rss_bytes": 65277952 + "total_delta_rx_bytes": 499314967, + "total_delta_tx_bytes": 499616292, + "rx_bytes_per_upload": 9986299, + "tx_bytes_per_upload": 9992326, + "max_delta_rss_bytes": 45023232 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 4.694, + "duration_s": 4.725, "latency_ms": { - "p50": 637.3, - "p95": 848.8, - "p99": 979.4 + "p50": 642.3, + "p95": 1021.8, + "p99": 1063.9 }, "replicas": [ { "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 249629894, - "delta_tx_bytes": 249780802, - "baseline_rss_bytes": 322142208, + "delta_rx_bytes": 249673539, + "delta_tx_bytes": 249815151, + "baseline_rss_bytes": 301092864, "peak_memory_bytes": { - "rss": 366731264, - "heap_used": 50163968, - "external": 85133242, - "array_buffers": 81342898 + "rss": 327974912, + "heap_used": 49201912, + "external": 94750424, + "array_buffers": 90960080 }, - "delta_rss_bytes": 44589056, + "delta_rss_bytes": 26882048, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, - "attachments.decode.ms": 7874.299524000016, + "attachments.decode.ms": 7622.966706999927, "attachments.proxy.bytes_to_s3": 249036800, "attachments.mark_ready": 25, "attachments.upload.created": 25 @@ -171,31 +171,31 @@ }, { "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 249682445, - "delta_tx_bytes": 249837698, - "baseline_rss_bytes": 325865472, + "delta_rx_bytes": 249648565, + "delta_tx_bytes": 249815222, + "baseline_rss_bytes": 296456192, "peak_memory_bytes": { - "rss": 365383680, - "heap_used": 50007528, - "external": 84862098, - "array_buffers": 81070915 + "rss": 307523584, + "heap_used": 50677504, + "external": 85057449, + "array_buffers": 81100125 }, - "delta_rss_bytes": 39518208, + "delta_rss_bytes": 11067392, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, - "attachments.decode.ms": 7699.224510000015, + "attachments.decode.ms": 7061.106053000025, "attachments.proxy.bytes_to_s3": 249036800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 499312339, - "total_delta_tx_bytes": 499618500, - "rx_bytes_per_upload": 9986247, - "tx_bytes_per_upload": 9992370, - "max_delta_rss_bytes": 44589056 + "total_delta_rx_bytes": 499322104, + "total_delta_tx_bytes": 499630373, + "rx_bytes_per_upload": 9986442, + "tx_bytes_per_upload": 9992607, + "max_delta_rss_bytes": 26882048 } ] } diff --git a/evidence/lab4/bench/proxy-9961472-c20.json b/evidence/lab4/bench/proxy-9961472-c20.json index 34dbd64c..aa8e9774 100644 --- a/evidence/lab4/bench/proxy-9961472-c20.json +++ b/evidence/lab4/bench/proxy-9961472-c20.json @@ -1,6 +1,6 @@ { - "date": "2026-10-23T13:34:02+00:00", - "git": "b32ce9a", + "date": "2026-10-23T13:38:46+00:00", + "git": "4badd5a", "params": { "mode": "proxy", "size_bytes": 9961472, @@ -21,53 +21,111 @@ "uploads": 100, "succeeded": 100, "failed": 0, - "duration_s": 8.965, + "duration_s": 8.833, "latency_ms": { - "p50": 1396.5, - "p95": 1795.3, - "p99": 1927.7 + "p50": 1330.2, + "p95": 1656.1, + "p99": 1727.7 }, "replicas": [ { "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 500201125, - "delta_tx_bytes": 500377070, - "baseline_rss_bytes": 305356800, + "delta_rx_bytes": 499759117, + "delta_tx_bytes": 499989656, + "baseline_rss_bytes": 261660672, "peak_memory_bytes": { - "rss": 434417664, - "heap_used": 51274840, - "external": 145565797, - "array_buffers": 141709917 + "rss": 388141056, + "heap_used": 50630264, + "external": 155166578, + "array_buffers": 139745634 }, - "delta_rss_bytes": 129060864, + "delta_rss_bytes": 126480384, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, - "attachments.decode.ms": 15301.763066, + "attachments.decode.ms": 15729.830076000188, "attachments.proxy.bytes_to_s3": 498073600, "attachments.mark_ready": 50, - "attachments.upload.created": 50, - "attachments.claim_expired": 1, - "attachments.delete_claimed": 2, - "attachments.sweep.deleted": 2 + "attachments.upload.created": 50 } }, { "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 499840721, - "delta_tx_bytes": 500065968, - "baseline_rss_bytes": 315572224, + "delta_rx_bytes": 499883600, + "delta_tx_bytes": 500123779, + "baseline_rss_bytes": 292487168, "peak_memory_bytes": { - "rss": 417861632, - "heap_used": 51333520, - "external": 141534029, - "array_buffers": 137743685 + "rss": 393953280, + "heap_used": 51133536, + "external": 142116265, + "array_buffers": 138325921 }, - "delta_rss_bytes": 102289408, + "delta_rss_bytes": 101466112, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, - "attachments.decode.ms": 15764.19308799997, + "attachments.decode.ms": 15020.501326000027, + "attachments.proxy.bytes_to_s3": 498073600, + "attachments.mark_ready": 50, + "attachments.upload.created": 50 + } + } + ], + "total_delta_rx_bytes": 999642717, + "total_delta_tx_bytes": 1000113435, + "rx_bytes_per_upload": 9996427, + "tx_bytes_per_upload": 10001134, + "max_delta_rss_bytes": 126480384 + }, + { + "uploads": 100, + "succeeded": 100, + "failed": 0, + "duration_s": 8.864, + "latency_ms": { + "p50": 1336.0, + "p95": 1742.8, + "p99": 1799.2 + }, + "replicas": [ + { + "instance_id": "7c7cf67931e5", + "delta_rx_bytes": 499464722, + "delta_tx_bytes": 499742563, + "baseline_rss_bytes": 380321792, + "peak_memory_bytes": { + "rss": 402067456, + "heap_used": 50852712, + "external": 145616176, + "array_buffers": 130815545 + }, + "delta_rss_bytes": 21745664, + "counters": { + "attachments.insert_pending": 50, + "attachments.proxy.bytes_in": 498073600, + "attachments.decode.ms": 15730.587417000032, + "attachments.proxy.bytes_to_s3": 498073600, + "attachments.mark_ready": 50, + "attachments.upload.created": 50, + "attachments.claim_expired": 1 + } + }, + { + "instance_id": "ff9a363e52b1", + "delta_rx_bytes": 499665326, + "delta_tx_bytes": 499906835, + "baseline_rss_bytes": 365027328, + "peak_memory_bytes": { + "rss": 393994240, + "heap_used": 50916312, + "external": 127865497, + "array_buffers": 124075153 + }, + "delta_rss_bytes": 28966912, + "counters": { + "attachments.insert_pending": 50, + "attachments.proxy.bytes_in": 498073600, + "attachments.decode.ms": 16026.04880199983, "attachments.proxy.bytes_to_s3": 498073600, "attachments.mark_ready": 50, "attachments.upload.created": 50, @@ -75,39 +133,39 @@ } } ], - "total_delta_rx_bytes": 1000041846, - "total_delta_tx_bytes": 1000443038, - "rx_bytes_per_upload": 10000418, - "tx_bytes_per_upload": 10004430, - "max_delta_rss_bytes": 129060864 + "total_delta_rx_bytes": 999130048, + "total_delta_tx_bytes": 999649398, + "rx_bytes_per_upload": 9991300, + "tx_bytes_per_upload": 9996494, + "max_delta_rss_bytes": 28966912 }, { "uploads": 100, "succeeded": 100, "failed": 0, - "duration_s": 8.87, + "duration_s": 9.064, "latency_ms": { - "p50": 1327.7, - "p95": 1753.9, - "p99": 2016.9 + "p50": 1457.1, + "p95": 1774.1, + "p99": 1926.1 }, "replicas": [ { "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 500384354, - "delta_tx_bytes": 500549484, - "baseline_rss_bytes": 405041152, + "delta_rx_bytes": 499401262, + "delta_tx_bytes": 499684797, + "baseline_rss_bytes": 357986304, "peak_memory_bytes": { - "rss": 442638336, - "heap_used": 51584448, - "external": 136101545, - "array_buffers": 132311201 + "rss": 410398720, + "heap_used": 50734960, + "external": 146163060, + "array_buffers": 132312269 }, - "delta_rss_bytes": 37597184, + "delta_rss_bytes": 52412416, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, - "attachments.decode.ms": 15850.254651000054, + "attachments.decode.ms": 16195.981729999883, "attachments.proxy.bytes_to_s3": 498073600, "attachments.mark_ready": 50, "attachments.upload.created": 50 @@ -115,91 +173,31 @@ }, { "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 500629918, - "delta_tx_bytes": 500817708, - "baseline_rss_bytes": 379080704, + "delta_rx_bytes": 499729379, + "delta_tx_bytes": 499980797, + "baseline_rss_bytes": 355852288, "peak_memory_bytes": { - "rss": 435548160, - "heap_used": 51076952, - "external": 146391435, - "array_buffers": 142601091 + "rss": 408215552, + "heap_used": 50802144, + "external": 136256487, + "array_buffers": 132466143 }, - "delta_rss_bytes": 56467456, + "delta_rss_bytes": 52363264, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, - "attachments.decode.ms": 15065.693191000057, + "attachments.decode.ms": 16008.327908000094, "attachments.proxy.bytes_to_s3": 498073600, "attachments.mark_ready": 50, "attachments.upload.created": 50 } } ], - "total_delta_rx_bytes": 1001014272, - "total_delta_tx_bytes": 1001367192, - "rx_bytes_per_upload": 10010143, - "tx_bytes_per_upload": 10013672, - "max_delta_rss_bytes": 56467456 - }, - { - "uploads": 100, - "succeeded": 100, - "failed": 0, - "duration_s": 9.117, - "latency_ms": { - "p50": 1442.2, - "p95": 1862.3, - "p99": 1962.7 - }, - "replicas": [ - { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 499434564, - "delta_tx_bytes": 499705234, - "baseline_rss_bytes": 421199872, - "peak_memory_bytes": { - "rss": 441876480, - "heap_used": 50736392, - "external": 135949482, - "array_buffers": 132036017 - }, - "delta_rss_bytes": 20676608, - "counters": { - "attachments.insert_pending": 50, - "attachments.proxy.bytes_in": 498073600, - "attachments.decode.ms": 16234.571914999979, - "attachments.proxy.bytes_to_s3": 498073600, - "attachments.mark_ready": 50, - "attachments.upload.created": 50 - } - }, - { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 499505499, - "delta_tx_bytes": 499795523, - "baseline_rss_bytes": 348524544, - "peak_memory_bytes": { - "rss": 441692160, - "heap_used": 50551064, - "external": 136342743, - "array_buffers": 132552399 - }, - "delta_rss_bytes": 93167616, - "counters": { - "attachments.insert_pending": 50, - "attachments.proxy.bytes_in": 498073600, - "attachments.decode.ms": 16105.769058999955, - "attachments.proxy.bytes_to_s3": 498073600, - "attachments.mark_ready": 50, - "attachments.upload.created": 50 - } - } - ], - "total_delta_rx_bytes": 998940063, - "total_delta_tx_bytes": 999500757, - "rx_bytes_per_upload": 9989401, - "tx_bytes_per_upload": 9995008, - "max_delta_rss_bytes": 93167616 + "total_delta_rx_bytes": 999130641, + "total_delta_tx_bytes": 999665594, + "rx_bytes_per_upload": 9991306, + "tx_bytes_per_upload": 9996656, + "max_delta_rss_bytes": 52412416 } ] } diff --git a/evidence/lab4/consistency.txt b/evidence/lab4/consistency.txt index 7e9b0474..fe77da37 100644 --- a/evidence/lab4/consistency.txt +++ b/evidence/lab4/consistency.txt @@ -1,9 +1,9 @@ scripts/lab4/consistency_check.sh bucket: messenger-attachments -objects: 3823 +objects: 5066 rows by status: 11 pending - 3822 ready + 5065 ready 4 rejected orphans: 0 missing: 0 diff --git a/evidence/lab4/make-test-e2e.txt b/evidence/lab4/make-test-e2e.txt index 9dd7805d..bf6dd224 100644 --- a/evidence/lab4/make-test-e2e.txt +++ b/evidence/lab4/make-test-e2e.txt @@ -4,5 +4,5 @@ The plugin "vite-tsconfig-paths" is detected. Vite now supports tsconfig paths r RUN v4.1.11 /home/tomato/Projects/VP/mtusi2026lab4/app Test Files 3 passed | 1 skipped (4) Tests 38 passed | 8 skipped (46) - Start at 16:30:56 - Duration 4.59s (transform 196ms, setup 0ms, import 593ms, tests 10.10s, environment 0ms) + Start at 16:39:49 + Duration 4.15s (transform 319ms, setup 0ms, import 598ms, tests 8.73s, environment 0ms) diff --git a/evidence/lab4/summary.md b/evidence/lab4/summary.md index 322a2256..c5e16e88 100644 --- a/evidence/lab4/summary.md +++ b/evidence/lab4/summary.md @@ -1,9 +1,9 @@ | mode | size, MiB | C | ok | API rx/upload, MiB | API tx/upload, MiB | max Δrss, MiB | p50, ms | p95, ms | |---|---|---|---|---|---|---|---|---| -| direct | 0.12 | 10 | 150/150 | 0.13 | 0.01 | 1.12 | 68 | 104 | -| proxy | 0.12 | 10 | 150/150 | 0.13 | 0.13 | 3.38 | 60 | 106 | -| direct | 1.00 | 10 | 150/150 | 1.01 | 0.01 | 9.81 | 164 | 249 | -| proxy | 1.00 | 10 | 150/150 | 1.01 | 1.01 | 12.82 | 143 | 192 | -| direct | 9.50 | 10 | 150/150 | 9.52 | 0.01 | 81.77 | 693 | 1082 | -| proxy | 9.50 | 10 | 150/150 | 9.52 | 9.53 | 62.25 | 688 | 947 | -| proxy | 9.50 | 20 | 300/300 | 9.54 | 9.54 | 88.85 | 1396 | 1795 | +| direct | 0.12 | 10 | 150/150 | 0.13 | 0.01 | 5.25 | 72 | 120 | +| proxy | 0.12 | 10 | 150/150 | 0.13 | 0.13 | 3.00 | 57 | 87 | +| direct | 1.00 | 10 | 150/150 | 1.01 | 0.01 | 1.38 | 154 | 252 | +| proxy | 1.00 | 10 | 150/150 | 1.01 | 1.01 | 2.00 | 132 | 183 | +| direct | 9.50 | 10 | 150/150 | 9.52 | 0.01 | 83.62 | 755 | 1018 | +| proxy | 9.50 | 10 | 150/150 | 9.52 | 9.53 | 42.94 | 642 | 889 | +| proxy | 9.50 | 20 | 300/300 | 9.53 | 9.53 | 49.98 | 1336 | 1743 | diff --git a/evidence/lab4/unit-tests.txt b/evidence/lab4/unit-tests.txt index 273e1641..5c51ded1 100644 --- a/evidence/lab4/unit-tests.txt +++ b/evidence/lab4/unit-tests.txt @@ -1,6 +1,6 @@ -[Nest] 3821708 - 10/23/2026, 4:31:09 PM WARN [MessagesCacheService] Cache fill failed: redis down -[Nest] 3821732 - 10/23/2026, 4:31:10 PM WARN [AttachmentsService] Compensation of attachment 26212360-edf3-428c-9246-43cb29900490 deferred: Connection terminated unexpectedly +[Nest] 3895186 - 10/23/2026, 4:39:54 PM WARN [MessagesCacheService] Cache fill failed: redis down +[Nest] 3895204 - 10/23/2026, 4:39:56 PM WARN [AttachmentsService] Compensation of attachment 5f9c0c33-dfa1-42a3-80a8-37f3ea9ef571 deferred: Connection terminated unexpectedly Test Files 12 passed (12) Tests 43 passed (43) - Start at 16:31:08 - Duration 2.59s (transform 791ms, setup 0ms, import 8.70s, tests 543ms, environment 2ms) + Start at 16:39:54 + Duration 2.47s (transform 762ms, setup 0ms, import 7.87s, tests 495ms, environment 2ms) -- 2.54.0 From 4b53e03fd66d77bfd995068725ebd9e12792b786 Mon Sep 17 00:00:00 2001 From: Ilya Date: Fri, 23 Oct 2026 17:09:49 +0300 Subject: [PATCH 12/15] =?UTF-8?q?lab4:=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B2=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20=D1=80=D0=B5=D0=B2=D1=8C=D1=8E=20(40=20?= =?UTF-8?q?=D0=9C=D0=BF=20=D0=B2=20tmpfs,=20=D1=82=D0=B0=D0=B9=D0=BC=D0=B0?= =?UTF-8?q?=D1=83=D1=82=D1=8B=20S3,=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BB=D0=BB?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20complete,=20auth=20?= =?UTF-8?q?=D0=B4=D0=BE=20Content-Type,=20=D0=BB=D0=B8=D0=BC=D0=B8=D1=82?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D1=82=D0=B5=D0=BB=D1=8F,=20=D0=B1=D1=8E=D0=B4=D0=B6?= =?UTF-8?q?=D0=B5=D1=82=20=D0=BF=D0=B0=D0=BC=D1=8F=D1=82=D0=B8=20=D0=B4?= =?UTF-8?q?=D0=B5=D0=BA=D0=BE=D0=B4=D0=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 12 +- app/src/attachments/attachments.controller.ts | 6 +- .../attachments/attachments.service.spec.ts | 4 +- app/src/attachments/attachments.service.ts | 35 +++--- app/src/attachments/direct-uploads.service.ts | 30 ++++- .../attachments/image/image-decoder.spec.ts | 21 +++- app/src/attachments/image/image-decoder.ts | 77 ++++++++++--- app/src/attachments/image/image-inspector.ts | 2 - app/src/attachments/upload-request.ts | 9 ++ app/src/attachments/upload-slots.spec.ts | 54 +++++++++ app/src/attachments/upload-slots.ts | 16 ++- app/src/config/app-config.schema.ts | 8 +- app/src/main.ts | 70 +++++------- app/src/storage/object-storage.ts | 22 ++-- app/test/attachments.e2e-spec.ts | 104 +++++++++++++++++- app/test/dependency-failures.e2e-spec.ts | 60 ++++++++++ app/test/direct-upload.e2e-spec.ts | 15 +++ app/test/support/jpeg.ts | 14 +++ app/test/support/png.ts | 36 +++++- app/tsconfig.json | 2 +- compose.yaml | 5 +- contracts/extensions.openapi.json | 43 +++++++- evidence/lab4/decode-memory.txt | 11 +- scripts/lab4/attachments_bench.py | 64 +++++++---- scripts/lab4/decode_memory.mjs | 23 +++- scripts/lab4/pngkit.py | 28 +++++ scripts/lab4/run_matrix.sh | 12 ++ 27 files changed, 642 insertions(+), 141 deletions(-) create mode 100644 app/src/attachments/upload-request.ts create mode 100644 app/src/attachments/upload-slots.spec.ts diff --git a/.env.example b/.env.example index fd340910..c8470c66 100644 --- a/.env.example +++ b/.env.example @@ -33,7 +33,7 @@ IDEMPOTENCY_TTL_SECONDS=86400 # Стенд (compose.yaml и scripts/): API_REPLICAS=2 API_CPUS_PER_REPLICA=1.5 -API_MEMORY_PER_REPLICA=768m +API_MEMORY_PER_REPLICA=1024m PG_CPUS=1.5 PG_MEMORY=512m REDIS_CPUS=0.25 @@ -68,10 +68,14 @@ S3_CONNECT_TIMEOUT_MS=1000 S3_REQUEST_TIMEOUT_MS=15000 MAX_UPLOAD_BYTES=10485760 MAX_IMAGE_PIXELS=40000000 -# Каждая загрузка держит копию файла (≤ MAX_UPLOAD_BYTES) до полного декода: -# память реплики ≈ UPLOAD_MAX_IN_FLIGHT × 10 MiB + IMAGE_DECODE_MAX_CONCURRENT декодов. +# Каждая загрузка держит копию файла (≤ MAX_UPLOAD_BYTES) до полного декода; +# худший декод (40 Мп RGBA16 interlaced PNG) ≈ 340 MiB. Граница памяти реплики: +# базовый RSS (~250 MiB) + UPLOAD_MAX_IN_FLIGHT × 10 MiB + IMAGE_DECODE_MAX_CONCURRENT × 340 MiB +# = 250 + 160 + 340 ≈ 750 MiB при API_MEMORY_PER_REPLICA=1024m. UPLOAD_MAX_IN_FLIGHT=16 -IMAGE_DECODE_MAX_CONCURRENT=2 +# Не больше стольких одновременных загрузок одного пользователя на реплику. +UPLOAD_MAX_IN_FLIGHT_PER_USER=4 +IMAGE_DECODE_MAX_CONCURRENT=1 DIRECT_UPLOAD_MAX_PENDING_PER_USER=10 # UPLOAD_TIMEOUT_MS, DIRECT_UPLOAD_URL_TTL_SECONDS, ATTACHMENT_SWEEP_GRACE_SECONDS, # ATTACHMENT_SWEEP_INTERVAL_MS задаются в compose.yaml (environment) с умолчаниями diff --git a/app/src/attachments/attachments.controller.ts b/app/src/attachments/attachments.controller.ts index 45d02ddb..64358497 100644 --- a/app/src/attachments/attachments.controller.ts +++ b/app/src/attachments/attachments.controller.ts @@ -23,6 +23,7 @@ import type { User } from '../users/user.js'; import { AttachmentsService } from './attachments.service.js'; import { CreateDirectUploadDto } from './dto/create-direct-upload.dto.js'; import { DirectUploadsService } from './direct-uploads.service.js'; +import type { UploadRequest } from './upload-request.js'; import { contentDisposition } from './filename.js'; @Controller('api/v1') @@ -44,9 +45,8 @@ export class AttachmentsController { @Param('chatId', new ParseUUIDPipe()) chatId: string, @CurrentUser() user: User, @Query('filename') filename: unknown, - @Headers('content-type') contentType: string | undefined, @Headers('content-length') contentLength: string | undefined, - @Req() request: FastifyRequest, + @Req() request: FastifyRequest & UploadRequest, @Res({ passthrough: true }) reply: FastifyReply, ) { // A gigantic body is not worth draining: close the connection after the answer. @@ -56,7 +56,7 @@ export class AttachmentsController { chatId, user, filename, - contentType, + request.uploadContentType, contentLength, request.body as Readable | undefined, ); diff --git a/app/src/attachments/attachments.service.spec.ts b/app/src/attachments/attachments.service.spec.ts index 77b0478c..b79287a0 100644 --- a/app/src/attachments/attachments.service.spec.ts +++ b/app/src/attachments/attachments.service.spec.ts @@ -38,7 +38,9 @@ function setup(repository: Record) { { getForUser: vi.fn() } as never, { increment: vi.fn(), add: vi.fn() } as never, { verify: vi.fn() } as never, - { run: (work: () => Promise) => work() } as never, + { + run: (_user: string, work: () => Promise) => work(), + } as never, ); const upload = () => service.uploadProxy( diff --git a/app/src/attachments/attachments.service.ts b/app/src/attachments/attachments.service.ts index 7a7fa4e3..b346b6e2 100644 --- a/app/src/attachments/attachments.service.ts +++ b/app/src/attachments/attachments.service.ts @@ -24,7 +24,6 @@ import { } from './attachment.js'; import { validateFilename } from './filename.js'; import { - IMAGE_HEADER_MAX_BYTES, ImageHeader, ImageInspector, ImageRejectedError, @@ -94,7 +93,7 @@ export class AttachmentsService { if (contentLength > this.maxUploadBytes) throw new PayloadTooLargeException('Image is too large'); - return this.slots.run(async () => { + return this.slots.run(user.id, async () => { await this.chats.getForUser(chatId, user); return this.receive( chatId, @@ -137,8 +136,9 @@ export class AttachmentsService { let key = ''; let rejection: unknown; try { - // Header phase: nothing exists in the database or S3 yet. - let headBytes = 0; + // Header phase: nothing exists in the database or S3 yet. It is + // bounded by Content-Length (<= MAX_UPLOAD_BYTES): a JPEG may carry + // megabytes of APPn metadata before its frame header. try { while (inspector.header === undefined) { const step = await next(); @@ -150,16 +150,7 @@ export class AttachmentsService { ); } head.push(step.value); - headBytes += step.value.length; inspector.push(step.value); - if ( - inspector.header === undefined && - headBytes > IMAGE_HEADER_MAX_BYTES - ) - throw new ImageRejectedError( - 'unsupported_media_type', - 'Image header is missing', - ); } } catch (error) { throw this.mapUploadError(error, timedOut); @@ -191,6 +182,7 @@ export class AttachmentsService { // UPLOAD_MAX_IN_FLIGHT, released as soon as the decode starts. const copy: Buffer[] = []; let total = 0; + let allSent = false; const account = (chunk: Buffer, inspect: boolean): boolean => { total += chunk.length; if (total > contentLength) @@ -209,7 +201,10 @@ export class AttachmentsService { inspector.finish(); const data = Buffer.concat(copy, total); copy.length = 0; - await decoder.verify(data); + await decoder.verify(data, controller.signal); + // From here S3 may receive the whole body and commit the object + // even if this request fails or times out afterwards. + allSent = true; }; async function* generate(): AsyncGenerator { for (const chunk of head) { @@ -271,7 +266,12 @@ export class AttachmentsService { } catch (error) { readable.destroy(); if (!claimed) { - const outcome = await this.compensate(id, key); + // After the last byte was handed to S3, a PUT aborted on our + // side may still be committed by S3 after our DELETE: keep the + // row so the sweeper deletes the key again later. + const outcome = await this.compensate(id, key, { + keepRow: allSent && !stored, + }); // markReady failed on our side, but the row is no longer // pending: the commit may have succeeded with its reply lost. // If so, the upload is complete and 201 is the truth. @@ -312,6 +312,7 @@ export class AttachmentsService { async compensate( id: string, key: string, + options: { keepRow?: boolean } = {}, ): Promise<'compensated' | 'not_pending' | 'deferred'> { try { if (!(await this.repository.claimForCompensation(id))) { @@ -319,7 +320,9 @@ export class AttachmentsService { return 'not_pending'; } await this.storage.delete(key); - await this.repository.deleteClaimed(id); + // A kept `deleting` row is re-claimed by the sweeper after a minute, + // which deletes the key once more and only then the row. + if (!options.keepRow) await this.repository.deleteClaimed(id); this.metrics.increment('attachments.compensated'); return 'compensated'; } catch (error) { diff --git a/app/src/attachments/direct-uploads.service.ts b/app/src/attachments/direct-uploads.service.ts index c35cdc4c..1b738ddf 100644 --- a/app/src/attachments/direct-uploads.service.ts +++ b/app/src/attachments/direct-uploads.service.ts @@ -11,7 +11,10 @@ import { randomUUID } from 'node:crypto'; import type { AppConfig } from '../config/app-config.schema.js'; import { ChatsService } from '../chats/chats.service.js'; import { MetricsService } from '../metrics/metrics.service.js'; -import { ObjectStorage } from '../storage/object-storage.js'; +import { + ObjectStorage, + ObjectStorageUnavailableError, +} from '../storage/object-storage.js'; import type { User } from '../users/user.js'; import { toAttachment, @@ -44,6 +47,7 @@ const MEDIA_TYPES = new Set(['image/png', 'image/jpeg']); export class DirectUploadsService { private readonly maxUploadBytes: number; private readonly maxPixels: number; + private readonly uploadTimeoutMs: number; private readonly ttlSeconds: number; private readonly maxPending: number; @@ -58,6 +62,7 @@ export class DirectUploadsService { ) { this.maxUploadBytes = config.getOrThrow('MAX_UPLOAD_BYTES'); this.maxPixels = config.getOrThrow('MAX_IMAGE_PIXELS'); + this.uploadTimeoutMs = config.getOrThrow('UPLOAD_TIMEOUT_MS'); this.ttlSeconds = config.getOrThrow('DIRECT_UPLOAD_URL_TTL_SECONDS'); this.maxPending = config.getOrThrow( 'DIRECT_UPLOAD_MAX_PENDING_PER_USER', @@ -138,7 +143,7 @@ export class DirectUploadsService { ); if (!row) throw new NotFoundException(); if (row.status === 'ready') return toAttachment(row); - return this.slots.run(() => this.verifyAndMarkReady(row)); + return this.slots.run(user.id, () => this.verifyAndMarkReady(row)); } private async verifyAndMarkReady(row: AttachmentRow): Promise { @@ -179,7 +184,15 @@ export class DirectUploadsService { width: header.width, height: header.height, }); - if (!ready) throw new ConflictException('Upload is no longer pending'); + if (!ready) { + // A parallel complete of the same upload won: answer like a repeat. + const current = await this.repository.findForComplete( + row.id, + row.owner_id, + ); + if (current?.status === 'ready') return toAttachment(current); + throw new ConflictException('Upload is no longer pending'); + } this.metrics.increment('attachments.direct.completed'); return toAttachment(ready); } @@ -194,7 +207,9 @@ export class DirectUploadsService { key: string, size: number, ): Promise { - const stream = await this.storage.getStream(key); + // Same deadline as a proxy upload: a slow or hung read releases its slot. + const signal = AbortSignal.timeout(this.uploadTimeoutMs); + const stream = await this.storage.getStream(key, signal); if (stream === null) throw new ConflictException('Upload has not been received'); const inspector = new ImageInspector(this.maxPixels); @@ -211,6 +226,11 @@ export class DirectUploadsService { inspector.push(chunk); chunks.push(chunk); } + } catch (error) { + if (error instanceof ImageRejectedError) throw error; + // The object stream broke mid-read (S3 outage, timeout): the image + // was not judged, so this is an outage, not a client error. + throw new ObjectStorageUnavailableError(); } finally { stream.destroy(); this.metrics.add('attachments.direct.verify_bytes', read); @@ -218,7 +238,7 @@ export class DirectUploadsService { const header = inspector.finish(); const data = Buffer.concat(chunks, read); chunks.length = 0; - await this.decoder.verify(data); + await this.decoder.verify(data, signal); return header; } diff --git a/app/src/attachments/image/image-decoder.spec.ts b/app/src/attachments/image/image-decoder.spec.ts index 9b36dbe1..e5d82cfe 100644 --- a/app/src/attachments/image/image-decoder.spec.ts +++ b/app/src/attachments/image/image-decoder.spec.ts @@ -3,7 +3,11 @@ import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; import { describe, expect, it } from 'vitest'; import { jpegWithoutScanData } from '../../../test/support/jpeg.js'; -import { noisePng, pngWithGarbageIdat } from '../../../test/support/png.js'; +import { + maxPixelsRgba16Png, + noisePng, + pngWithGarbageIdat, +} from '../../../test/support/png.js'; import { ImageDecoder } from './image-decoder.js'; import { ImageInspector, ImageRejectedError } from './image-inspector.js'; @@ -48,4 +52,19 @@ describe('ImageDecoder', () => { ImageRejectedError, ); }); + + it('accepts the heaviest valid input: 40 MP RGBA 16-bit', async () => { + await decoder.verify(await maxPixelsRgba16Png()); + }); + + it('drops an aborted waiter from the queue without running its decode', async () => { + const busy = decoder.verify(noisePng(4_000_000)); + const controller = new AbortController(); + const waiting = decoder.verify(png, controller.signal); + controller.abort(); + await expect(waiting).rejects.toMatchObject({ status: 503 }); + await busy; + // The slot was not leaked: the next decode runs. + await decoder.verify(png); + }); }); diff --git a/app/src/attachments/image/image-decoder.ts b/app/src/attachments/image/image-decoder.ts index 8dfe35f4..fc1ee067 100644 --- a/app/src/attachments/image/image-decoder.ts +++ b/app/src/attachments/image/image-decoder.ts @@ -1,4 +1,9 @@ -import { Injectable } from '@nestjs/common'; +import { + Injectable, + InternalServerErrorException, + Logger, + ServiceUnavailableException, +} from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import sharp from 'sharp'; import type { AppConfig } from '../../config/app-config.schema.js'; @@ -10,19 +15,31 @@ import { ImageRejectedError } from './image-inspector.js'; sharp.cache(false); sharp.concurrency(1); +// Failures of the replica itself, not of the image: they must not turn into a +// client 415. libvips spills large images to a temp file unless +// VIPS_DISC_THRESHOLD (compose.yaml) keeps them in memory; a full /tmp or an +// allocation failure ends up here. +const SERVER_FAULT = + /no space left|out of memory|unable to allocate|cannot allocate|write failed|unable to open|tmp/iu; + /** * Full decode check. ImageInspector only proves the container structure * (signature, chunk CRCs, markers, dimensions); a PNG with a garbage zlib stream - * or a JPEG without scan data passes it. Decoding every pixel with - * failOn=warning rejects those, including truncated or corrupted entropy data. - * Decodes are bounded by IMAGE_DECODE_MAX_CONCURRENT; callers wait for a slot. + * or a JPEG without scan data passes it. Decoding every scanline with + * failOn=warning rejects those, including truncated or corrupted compressed + * data. A downscale to a thumbnail is the sink: it decodes all input but keeps + * far less in memory than a full-size pipeline (measured in + * evidence/lab4/decode-memory.txt). Decodes are bounded by + * IMAGE_DECODE_MAX_CONCURRENT; a waiter whose request was aborted leaves the + * queue and releases its buffer. */ @Injectable() export class ImageDecoder { + private readonly logger = new Logger(ImageDecoder.name); private readonly maxPixels: number; private readonly maxConcurrent: number; private active = 0; - private readonly waiting: (() => void)[] = []; + private readonly waiting = new Set<() => void>(); constructor( config: ConfigService, @@ -32,16 +49,27 @@ export class ImageDecoder { this.maxConcurrent = config.getOrThrow('IMAGE_DECODE_MAX_CONCURRENT'); } - async verify(data: Buffer): Promise { - await this.acquire(); + async verify(data: Buffer, signal?: AbortSignal): Promise { + await this.acquire(signal); const started = performance.now(); try { await sharp(data, { failOn: 'warning', sequentialRead: true, limitInputPixels: this.maxPixels, - }).stats(); - } catch { + }) + .resize(64, 64, { fit: 'inside' }) + .toBuffer(); + } catch (error) { + const message = + error instanceof Error ? error.message : String(error); + if (SERVER_FAULT.test(message)) { + this.metrics.increment('attachments.decode.server_error'); + this.logger.error( + `Image decode failed on the server: ${message}`, + ); + throw new InternalServerErrorException(); + } this.metrics.increment('attachments.decode.rejected'); throw new ImageRejectedError( 'unsupported_media_type', @@ -56,17 +84,36 @@ export class ImageDecoder { } } - private async acquire(): Promise { + private acquire(signal?: AbortSignal): Promise { + const abandoned = new ServiceUnavailableException( + 'Image check was abandoned', + ); + if (signal?.aborted) return Promise.reject(abandoned); if (this.active < this.maxConcurrent) { this.active += 1; - return; + return Promise.resolve(); } - await new Promise((resolve) => this.waiting.push(resolve)); + const { promise, resolve, reject } = Promise.withResolvers(); + const cancel = () => { + this.waiting.delete(grant); + reject(abandoned); + }; + const grant = () => { + signal?.removeEventListener('abort', cancel); + resolve(); + }; + this.waiting.add(grant); + signal?.addEventListener('abort', cancel, { once: true }); + return promise; } private release(): void { - const next = this.waiting.shift(); - if (next) next(); - else this.active -= 1; + const next = this.waiting.values().next(); + if (next.done) { + this.active -= 1; + return; + } + this.waiting.delete(next.value); + next.value(); } } diff --git a/app/src/attachments/image/image-inspector.ts b/app/src/attachments/image/image-inspector.ts index 64a2f0eb..aeb88feb 100644 --- a/app/src/attachments/image/image-inspector.ts +++ b/app/src/attachments/image/image-inspector.ts @@ -1,7 +1,5 @@ import { crc32 } from 'node:zlib'; -export const IMAGE_HEADER_MAX_BYTES = 1_048_576; - export type ImageHeader = { contentType: 'image/png' | 'image/jpeg'; width: number; diff --git a/app/src/attachments/upload-request.ts b/app/src/attachments/upload-request.ts new file mode 100644 index 00000000..3479cc34 --- /dev/null +++ b/app/src/attachments/upload-request.ts @@ -0,0 +1,9 @@ +/** Request of the upload route; see the onRequest hook in main.ts. */ +export type UploadRequest = { + method: string; + routeOptions?: { url?: string }; + headers: Record; + /** Content-Type as sent by the client (the header itself is rewritten). */ + uploadContentType?: string | string[]; + body?: unknown; +}; diff --git a/app/src/attachments/upload-slots.spec.ts b/app/src/attachments/upload-slots.spec.ts new file mode 100644 index 00000000..9910b9a7 --- /dev/null +++ b/app/src/attachments/upload-slots.spec.ts @@ -0,0 +1,54 @@ +import { describe, expect, it } from 'vitest'; +import { UploadSlots } from './upload-slots.js'; + +const slots = (max: number, perUser: number) => + new UploadSlots({ + getOrThrow: (key: string) => + key === 'UPLOAD_MAX_IN_FLIGHT' ? max : perUser, + } as never); + +function hold() { + const { promise, resolve } = Promise.withResolvers(); + return { work: () => promise, release: resolve }; +} + +describe('UploadSlots', () => { + it('caps one user without starving others, and frees slots after work', async () => { + const limiter = slots(10, 2); + const held = [hold(), hold()]; + const running = held.map((h) => limiter.run('a', h.work)); + await expect(limiter.run('a', async () => 'x')).rejects.toMatchObject({ + status: 429, + }); + await expect(limiter.run('b', async () => 'ok')).resolves.toBe('ok'); + held.forEach((h) => h.release()); + await Promise.all(running); + await expect(limiter.run('a', async () => 'again')).resolves.toBe( + 'again', + ); + }); + + it('applies the replica-wide cap across users', async () => { + const limiter = slots(2, 2); + const held = [hold(), hold()]; + const running = [ + limiter.run('a', held[0].work), + limiter.run('b', held[1].work), + ]; + await expect(limiter.run('c', async () => 'x')).rejects.toMatchObject({ + status: 429, + }); + held.forEach((h) => h.release()); + await Promise.all(running); + }); + + it('releases a slot when the work fails', async () => { + const limiter = slots(1, 1); + await expect( + limiter.run('a', async () => { + throw new Error('boom'); + }), + ).rejects.toThrow('boom'); + await expect(limiter.run('a', async () => 'ok')).resolves.toBe('ok'); + }); +}); diff --git a/app/src/attachments/upload-slots.ts b/app/src/attachments/upload-slots.ts index 528c4838..bc4129f8 100644 --- a/app/src/attachments/upload-slots.ts +++ b/app/src/attachments/upload-slots.ts @@ -3,29 +3,39 @@ import { ConfigService } from '@nestjs/config'; import type { AppConfig } from '../config/app-config.schema.js'; /** - * Per-replica cap on requests that hold an image in memory (proxy upload, + * Per-replica caps on requests that hold an image in memory (proxy upload, * direct complete): each may keep up to MAX_UPLOAD_BYTES for the decode check. + * The per-user cap keeps one client (e.g. slow senders holding slots until + * UPLOAD_TIMEOUT_MS) from starving everyone else. */ @Injectable() export class UploadSlots { private inFlight = 0; + private readonly perUser = new Map(); private readonly max: number; + private readonly maxPerUser: number; constructor(config: ConfigService) { this.max = config.getOrThrow('UPLOAD_MAX_IN_FLIGHT'); + this.maxPerUser = config.getOrThrow('UPLOAD_MAX_IN_FLIGHT_PER_USER'); } - async run(work: () => Promise): Promise { - if (this.inFlight >= this.max) + async run(userId: string, work: () => Promise): Promise { + const mine = this.perUser.get(userId) ?? 0; + if (this.inFlight >= this.max || mine >= this.maxPerUser) throw new HttpException( { message: 'Too many concurrent uploads', retryAfter: 1 }, 429, ); this.inFlight += 1; + this.perUser.set(userId, mine + 1); try { return await work(); } finally { this.inFlight -= 1; + const left = (this.perUser.get(userId) ?? 1) - 1; + if (left === 0) this.perUser.delete(userId); + else this.perUser.set(userId, left); } } } diff --git a/app/src/config/app-config.schema.ts b/app/src/config/app-config.schema.ts index e1155015..86fd5a2e 100644 --- a/app/src/config/app-config.schema.ts +++ b/app/src/config/app-config.schema.ts @@ -86,11 +86,17 @@ export const appConfigSchema = z MAX_IMAGE_PIXELS: numeric('MAX_IMAGE_PIXELS', 1, 40000000, 40000000), UPLOAD_TIMEOUT_MS: numeric('UPLOAD_TIMEOUT_MS', 1000, undefined, 25000), UPLOAD_MAX_IN_FLIGHT: numeric('UPLOAD_MAX_IN_FLIGHT', 1, 1024, 16), + UPLOAD_MAX_IN_FLIGHT_PER_USER: numeric( + 'UPLOAD_MAX_IN_FLIGHT_PER_USER', + 1, + 1024, + 4, + ), IMAGE_DECODE_MAX_CONCURRENT: numeric( 'IMAGE_DECODE_MAX_CONCURRENT', 1, 64, - 2, + 1, ), // 0 отключает фоновый проход уборщика (остаётся ручной CLI). ATTACHMENT_SWEEP_INTERVAL_MS: numeric( diff --git a/app/src/main.ts b/app/src/main.ts index b799f2e0..8c4a615c 100644 --- a/app/src/main.ts +++ b/app/src/main.ts @@ -1,12 +1,8 @@ import { NestFactory } from '@nestjs/core'; import { HttpAdapterHost } from '@nestjs/core'; import { ConfigService } from '@nestjs/config'; -import { - PayloadTooLargeException, - UnsupportedMediaTypeException, - ValidationPipe, -} from '@nestjs/common'; -import type { Readable } from 'node:stream'; +import { ValidationPipe } from '@nestjs/common'; +import type { UploadRequest } from './attachments/upload-request.js'; import { FastifyAdapter, NestFastifyApplication, @@ -16,53 +12,41 @@ import { HealthService } from './health/health.service.js'; import { MetricsService } from './metrics/metrics.service.js'; import { RequestIdInterceptor } from './common/http/request-id.interceptor.js'; -const TEXT_BODY_LIMIT = 1_048_576; const UPLOAD_ROUTE = '/api/v1/chats/:chatId/attachments'; +const UPLOAD_STREAM_TYPE = 'application/x-messenger-upload-stream'; async function bootstrap(): Promise { const app = await NestFactory.create( AppModule, new FastifyAdapter({ logger: true }), ); - // Raw image bodies reach the controller as an unread stream: the upload is - // bounded by our own checks, not by Fastify's bodyLimit. A stream may reach - // only the upload route: on JSON routes it would hit the ValidationPipe and - // overflow the stack there, so other routes keep the pre-upload behavior. + // The upload route receives its body as an unread stream whatever the + // declared Content-Type: the service checks the type itself, after the + // auth guard (401 before 415, contracts/README.md), and bounds the body by + // its own limits, not Fastify's bodyLimit. The declared type is kept on the + // request; all other routes keep Fastify's parsers untouched. const fastify = app.getHttpAdapter().getInstance(); - type ParserRequest = { method: string; routeOptions?: { url?: string } }; - type Done = (error: Error | null, body?: unknown) => void; - const isUpload = (request: ParserRequest) => - request.method === 'POST' && request.routeOptions?.url === UPLOAD_ROUTE; - fastify.addContentTypeParser( - ['image/png', 'image/jpeg'], - (request: ParserRequest, payload: unknown, done: Done) => - isUpload(request) - ? done(null, payload) - : done(new UnsupportedMediaTypeException()), - ); - // Fastify's built-in text/plain parser buffers the body and fails binary - // input with 400; on the upload route the service answers 415 instead. - // Elsewhere text/plain keeps being buffered as a string (1 MiB cap). - fastify.removeContentTypeParser('text/plain'); - fastify.addContentTypeParser( - 'text/plain', - (request: ParserRequest, payload: Readable, done: Done) => { - if (isUpload(request)) return done(null, payload); - const chunks: Buffer[] = []; - let size = 0; - payload.on('data', (chunk: Buffer) => { - size += chunk.length; - if (size > TEXT_BODY_LIMIT) { - payload.destroy(); - done(new PayloadTooLargeException()); - } else chunks.push(chunk); - }); - payload.on('end', () => - done(null, Buffer.concat(chunks).toString('utf8')), - ); - payload.on('error', (error: Error) => done(error)); + fastify.addHook( + 'onRequest', + (request: UploadRequest, _reply: unknown, done: () => void) => { + if ( + request.method === 'POST' && + request.routeOptions?.url === UPLOAD_ROUTE + ) { + request.uploadContentType = request.headers['content-type']; + request.headers['content-type'] = UPLOAD_STREAM_TYPE; + } + done(); }, ); + fastify.addContentTypeParser( + UPLOAD_STREAM_TYPE, + ( + _request: unknown, + payload: unknown, + done: (error: Error | null, body?: unknown) => void, + ) => done(null, payload), + ); app.useGlobalInterceptors( new RequestIdInterceptor( app.get(HttpAdapterHost), diff --git a/app/src/storage/object-storage.ts b/app/src/storage/object-storage.ts index f6448742..cddbb5fd 100644 --- a/app/src/storage/object-storage.ts +++ b/app/src/storage/object-storage.ts @@ -62,9 +62,15 @@ export class ObjectStorage { maxAttempts: 1, requestChecksumCalculation: 'WHEN_REQUIRED' as const, responseChecksumValidation: 'WHEN_REQUIRED' as const, + // requestTimeout bounds a request until its response arrives and, + // with throwOnRequestTimeout, actually fails it (otherwise smithy + // only logs a warning); socketTimeout bounds a stalled body read. + // A hung S3 therefore costs at most S3_REQUEST_TIMEOUT_MS per call. requestHandler: new NodeHttpHandler({ connectionTimeout: config.getOrThrow('S3_CONNECT_TIMEOUT_MS'), requestTimeout: config.getOrThrow('S3_REQUEST_TIMEOUT_MS'), + throwOnRequestTimeout: true, + socketTimeout: config.getOrThrow('S3_REQUEST_TIMEOUT_MS'), httpAgent: new http.Agent({ keepAlive: true, maxSockets: 64 }), }), }; @@ -99,21 +105,23 @@ export class ObjectStorage { ContentLength: contentLength, ContentType: contentType, }), - { abortSignal: signal }, + // The upload deadline (UPLOAD_TIMEOUT_MS, via `signal`) bounds the + // PUT: it lasts as long as the client sends, not S3_REQUEST_TIMEOUT_MS. + { abortSignal: signal, requestTimeout: 0 }, ); } catch (error) { throw this.fail('put', error); } } - async getStream(key: string, range?: string): Promise { + async getStream( + key: string, + signal?: AbortSignal, + ): Promise { try { const result = await this.internal.send( - new GetObjectCommand({ - Bucket: this.bucket, - Key: key, - Range: range, - }), + new GetObjectCommand({ Bucket: this.bucket, Key: key }), + { abortSignal: signal }, ); return result.Body as Readable; } catch (error) { diff --git a/app/test/attachments.e2e-spec.ts b/app/test/attachments.e2e-spec.ts index 0758ba6c..d35bd73d 100644 --- a/app/test/attachments.e2e-spec.ts +++ b/app/test/attachments.e2e-spec.ts @@ -21,8 +21,10 @@ import { upload, uploadRaw, } from './support/e2e.js'; -import { jpegWithoutScanData } from './support/jpeg.js'; +import sharp from 'sharp'; +import { jpegWithMetadata, jpegWithoutScanData } from './support/jpeg.js'; import { + maxPixelsRgba16Png, noisePng, padPngTo, pixelBombPng, @@ -146,6 +148,106 @@ describe('attachments (proxy upload)', () => { expect(content.bytes.equals(data)).toBe(true); }); + it('accepts camera-size images up to the pixel limit', async () => { + // 7728x5152 = 39.8 MP, like a 40 MP camera; decoded size far above the + // replica's 16 MiB /tmp, so libvips must not spill to a temp file. + const camera = sharp({ + create: { + width: 7728, + height: 5152, + channels: 3, + background: { r: 120, g: 80, b: 40 }, + }, + }); + const baseline = await camera.clone().jpeg({ quality: 85 }).toBuffer(); + const progressiveCamera = await camera + .clone() + .jpeg({ quality: 85, progressive: true }) + .toBuffer(); + for (const data of [baseline, progressiveCamera]) + expect((await ready(data, 'image/jpeg')).size_bytes).toBe( + data.length, + ); + const rgba16 = await maxPixelsRgba16Png(); + expect((await ready(rgba16)).size_bytes).toBe(rgba16.length); + }, 120_000); + + it('accepts a JPEG with megabytes of metadata before the frame header', async () => { + const data = jpegWithMetadata(jpeg, 20); + expect(data.length).toBeGreaterThan(1_048_576); + expect((await ready(data, 'image/jpeg')).sha256).toBe(sha256(data)); + }); + + it('authenticates before judging the content type', async () => { + const zip = await http( + `/api/v1/chats/${chatId}/attachments?filename=a.zip`, + { + method: 'POST', + headers: { 'content-type': 'application/zip' }, + body: png as unknown as BodyInit, + }, + ); + expectError(zip, 401, 'unauthorized'); + expectError( + await upload(alice.token, leftoverChatId, png, { + contentType: 'application/json', + }), + 415, + 'unsupported_media_type', + ); + }); + + it('answers 413 with the error envelope to an oversized text body on JSON routes', async () => { + const result = await http( + `/api/v1/chats/${chatId}/messages`, + { + method: 'POST', + headers: { + ...bearer(alice.token), + 'content-type': 'text/plain', + 'idempotency-key': randomUUID().replaceAll('-', ''), + }, + body: 'x'.repeat(2_100_000), + }, + ); + expectError(result, 413, 'payload_too_large'); + }); + + it('keeps one slow client from taking every upload slot', async () => { + const slow = await actor(); + const slowChat = (await createChat(slow, [])).id; + const url = new URL(baseUrl); + const sockets: net.Socket[] = []; + try { + for (let index = 0; index < 12; index += 1) { + const socket = net.connect( + Number(url.port || 80), + url.hostname, + ); + socket.on('error', () => {}); + socket.write( + `POST /api/v1/chats/${slowChat}/attachments?filename=slow.png HTTP/1.1\r\n` + + `Host: ${url.host}\r\nAuthorization: Bearer ${slow.token}\r\n` + + `Content-Type: image/png\r\nContent-Length: ${png.length}\r\n\r\n`, + ); + socket.write(png.subarray(0, 4)); + sockets.push(socket); + } + await sleep(1000); + const extra = await upload(slow.token, slowChat, png); + expectError(extra, 429, 'rate_limited'); + expect(extra.response.headers.get('retry-after')).toBe('1'); + // Another user is not affected by the slow client. + for (let index = 0; index < 4; index += 1) + expect( + (await upload(bob.token, chatId, png)).response.status, + ).toBe(201); + } finally { + for (const socket of sockets) socket.destroy(); + } + await settled(slowChat); + }); + it('enforces the 10 MiB limit exactly', async () => { const exact = padPngTo(png, MAX); const created = await ready(exact); diff --git a/app/test/dependency-failures.e2e-spec.ts b/app/test/dependency-failures.e2e-spec.ts index c44822c8..7f489cc4 100644 --- a/app/test/dependency-failures.e2e-spec.ts +++ b/app/test/dependency-failures.e2e-spec.ts @@ -602,6 +602,10 @@ describe.skipIf(!enabled)('dependency outages', () => { await compose('start', redisService); await compose('start', postgresService); await compose('start', s3Service); + const s3Container = (await compose('ps', '-q', s3Service)).split( + '\n', + )[0]; + await docker('unpause', s3Container).catch(() => undefined); await waitForReadiness(200); await restoreDatabaseAccess(); const expected = (await apiContainers()).length; @@ -986,6 +990,62 @@ describe.skipIf(!enabled)('dependency outages', () => { outagedRequestBudgetMs, ); + it( + 'bounds requests by S3_REQUEST_TIMEOUT_MS when S3 hangs instead of refusing', + async () => { + const created = await request<{ id: string }>( + uploadPath(chat.id, `hang-${runId}.png`), + { + method: 'POST', + headers: { ...bearer(token), 'content-type': 'image/png' }, + body: samplePng as unknown as BodyInit, + }, + ); + expect(created.response.status).toBe(201); + // A paused container keeps its TCP port open but never answers: the + // failure mode a stopped container (connection refused) does not show. + const container = (await compose('ps', '-q', s3Service)).split( + '\n', + )[0]; + await docker('pause', container); + try { + const started = Date.now(); + const content = await request( + `/api/v1/attachments/${created.body.id}/content`, + { headers: bearer(token) }, + ); + const elapsed = Date.now() - started; + expectBoundedOutage(content); + // S3_REQUEST_TIMEOUT_MS is 15 s in the stand; HAProxy gives up at 30 s. + expect(elapsed).toBeLessThan(20_000); + expect( + ( + await request( + `/api/v1/attachments/${created.body.id}`, + { + headers: bearer(token), + }, + ) + ).response.status, + ).toBe(200); + expect((await request('/health/ready')).response.status).toBe( + 200, + ); + } finally { + await docker('unpause', container); + } + const bytes = await fetch( + `${baseUrl}/api/v1/attachments/${created.body.id}/content`, + { headers: bearer(token) }, + ); + expect(bytes.status).toBe(200); + expect( + Buffer.from(await bytes.arrayBuffer()).equals(samplePng), + ).toBe(true); + }, + outagedRequestBudgetMs, + ); + it( 'keeps the object while PostgreSQL is down before ready and sweeps it afterwards', async () => { diff --git a/app/test/direct-upload.e2e-spec.ts b/app/test/direct-upload.e2e-spec.ts index 0411595b..7713bdb5 100644 --- a/app/test/direct-upload.e2e-spec.ts +++ b/app/test/direct-upload.e2e-spec.ts @@ -160,6 +160,21 @@ describe('direct upload (presigned PUT)', () => { expect(sent.body.attachment_ids).toEqual([ticket.attachment_id]); }); + it('answers 200 to every parallel complete of one upload', async () => { + const ticket = await initOk(png); + expect((await put(ticket, png)).status).toBe(200); + const results = await Promise.all( + Array.from({ length: 4 }, () => + complete(alice.token, ticket.attachment_id), + ), + ); + expect(results.map((result) => result.response.status)).toEqual([ + 200, 200, 200, 200, + ]); + for (const result of results) + expect(result.body.id).toBe(ticket.attachment_id); + }); + it('rejects invalid declarations', async () => { const base = declaration(png); expectError(await init(eve.token, chatId, base), 404, 'not_found'); diff --git a/app/test/support/jpeg.ts b/app/test/support/jpeg.ts index ea60571e..b2d1ef97 100644 --- a/app/test/support/jpeg.ts +++ b/app/test/support/jpeg.ts @@ -8,3 +8,17 @@ export function jpegWithoutScanData(jpeg: Buffer): Buffer { } return Buffer.concat([jpeg.subarray(0, offset), Buffer.from([0xff, 0xd9])]); } + +/** Inserts `count` APP13 segments of ~64 KiB right after SOI (Photoshop-style metadata). */ +export function jpegWithMetadata(jpeg: Buffer, count: number): Buffer { + const payload = Buffer.alloc(65_533, 0x20); + const segment = Buffer.concat([ + Buffer.from([0xff, 0xed, 0xff, 0xff]), + payload, + ]); + return Buffer.concat([ + jpeg.subarray(0, 2), + ...Array.from({ length: count }, () => segment), + jpeg.subarray(2), + ]); +} diff --git a/app/test/support/png.ts b/app/test/support/png.ts index 714ce8af..0605b82f 100644 --- a/app/test/support/png.ts +++ b/app/test/support/png.ts @@ -1,5 +1,6 @@ import { randomBytes } from 'node:crypto'; -import { crc32, deflateSync } from 'node:zlib'; +import { once } from 'node:events'; +import { crc32, createDeflate, deflateSync } from 'node:zlib'; const SIGNATURE = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]); @@ -104,3 +105,36 @@ export function pngWithGarbageIdat(): Buffer { idat: randomBytes(5000), }); } + +/** + * 8000x5000 RGBA 16-bit (8 bytes/pixel, 40 000 000 px — the pixel limit): + * the heaviest decode a valid upload can ask for. Rows are streamed into the + * compressor, so the 320 MB raw image is never allocated here. + */ +export async function maxPixelsRgba16Png(): Promise { + const width = 8000; + const height = 5000; + // First row: a gradient; every next row uses filter "Up" with zero + // deltas, i.e. repeats it — a valid image that compresses well. + const first = Buffer.alloc(1 + width * 8); + for (let x = 0; x < width; x += 1) + first.writeUInt16BE((x * 8) & 0xffff, 1 + x * 8); + const repeat = Buffer.alloc(1 + width * 8); + repeat[0] = 2; + const deflate = createDeflate({ level: 1 }); + const chunks: Buffer[] = []; + deflate.on('data', (chunk: Buffer) => chunks.push(chunk)); + const ended = once(deflate, 'end'); + for (let y = 0; y < height; y += 1) + if (!deflate.write(y === 0 ? first : repeat)) + await once(deflate, 'drain'); + deflate.end(); + await ended; + return buildPng({ + width, + height, + colorType: 6, + bitDepth: 16, + idat: Buffer.concat(chunks), + }); +} diff --git a/app/tsconfig.json b/app/tsconfig.json index 8109c41f..6aa3ca79 100644 --- a/app/tsconfig.json +++ b/app/tsconfig.json @@ -10,7 +10,7 @@ "emitDecoratorMetadata": true, "experimentalDecorators": true, "allowSyntheticDefaultImports": true, - "target": "ES2023", + "target": "ES2024", "sourceMap": true, "outDir": "./dist", "incremental": true, diff --git a/compose.yaml b/compose.yaml index 139d436b..ddef2e2c 100644 --- a/compose.yaml +++ b/compose.yaml @@ -169,6 +169,9 @@ services: DIRECT_UPLOAD_URL_TTL_SECONDS: ${DIRECT_UPLOAD_URL_TTL_SECONDS:-300} ATTACHMENT_SWEEP_GRACE_SECONDS: ${ATTACHMENT_SWEEP_GRACE_SECONDS:-900} ATTACHMENT_SWEEP_INTERVAL_MS: ${ATTACHMENT_SWEEP_INTERVAL_MS:-60000} + # libvips держит декодируемое изображение в памяти, а не во временном + # файле: /tmp — tmpfs 16 MiB, и изображение ~40 Мп туда не помещается. + VIPS_DISC_THRESHOLD: ${VIPS_DISC_THRESHOLD:-1g} secrets: [s3_api_access_key_id, s3_api_secret_access_key] # Корневая ФС только для чтения: локального файла оригинала на API нет. read_only: true @@ -178,7 +181,7 @@ services: resources: limits: cpus: '${API_CPUS_PER_REPLICA:-1.5}' - memory: ${API_MEMORY_PER_REPLICA:-768m} + memory: ${API_MEMORY_PER_REPLICA:-1024m} stop_grace_period: 20s restart: unless-stopped depends_on: diff --git a/contracts/extensions.openapi.json b/contracts/extensions.openapi.json index d676f354..8dded17a 100644 --- a/contracts/extensions.openapi.json +++ b/contracts/extensions.openapi.json @@ -2,8 +2,8 @@ "openapi": "3.1.0", "info": { "title": "MTUSI Messenger — расширение lab4: прямая загрузка", - "version": "1.4.0-ext.1", - "description": "Трек 1. Не меняет обязательный контракт openapi.json: POST /api/v1/chats/{chat_id}/attachments остаётся основным путём. Клиент получает presigned PUT URL и отправляет байты прямо в приватный bucket MinIO, минуя API. Подписаны заголовки content-type, content-length и x-amz-checksum-sha256: хранилище само отвергает тело с другим размером (403 SignatureDoesNotMatch) или другим SHA-256 (400 XAmzContentChecksumMismatch), объект при этом не создаётся. TTL URL — DIRECT_UPLOAD_URL_TTL_SECONDS (300 с по умолчанию). Ключ объекта attachments//original раскрывает только UUID вложения; bucket приватный, анонимный доступ запрещён. Незавершённые заявки и объекты убирает уборщик через ATTACHMENT_SWEEP_GRACE_SECONDS после истечения. Вложение видно участникам чата только после успешного complete (status=ready)." + "version": "1.4.0-ext.2", + "description": "Трек 1. Не меняет обязательный контракт openapi.json: POST /api/v1/chats/{chat_id}/attachments остаётся основным путём. Клиент получает presigned PUT URL и отправляет байты прямо в приватный bucket MinIO, минуя API. Подписаны заголовки content-type, content-length и x-amz-checksum-sha256: хранилище само отвергает тело с другим размером (403 SignatureDoesNotMatch) или другим SHA-256 (400 XAmzContentChecksumMismatch), объект при этом не создаётся. TTL URL — DIRECT_UPLOAD_URL_TTL_SECONDS (300 с по умолчанию). Ключ объекта attachments//original раскрывает только UUID вложения; bucket приватный, анонимный доступ запрещён. Незавершённые и отклонённые заявки и их объекты убирает уборщик через ATTACHMENT_SWEEP_GRACE_SECONDS после истечения. Вложение видно участникам чата только после успешного complete (status=ready)." }, "servers": [ { @@ -264,8 +264,8 @@ "/api/v1/attachments/{attachment_id}/complete": { "post": { "operationId": "completeDirectUpload", - "summary": "Подтвердить прямую загрузку: HEAD объекта и проверка заголовка изображения", - "description": "Только владелец заявки. Проверяет размер и подписанный SHA-256 объекта (HEAD), читает заголовок изображения (до 1 MiB) и сверяет тип и число пикселей. При несоответствии заявка и объект удаляются, повторный complete даёт 404. Повторный complete готового вложения идемпотентен и возвращает 200.", + "summary": "Подтвердить прямую загрузку: HEAD объекта, полное чтение и декод изображения", + "description": "Только владелец заявки. Сверяет размер и подписанный SHA-256 объекта (HEAD), затем читает объект целиком: структурная проверка PNG/JPEG и полный декод (повреждённые и усечённые изображения отвергаются, даже если checksum совпадает). При несоответствии объект удаляется, а заявка получает внутренний статус rejected до истечения URL и grace-периода уборщика (повторный PUT по ещё действующему URL не оставит неучтённый объект); повторный complete отклонённой заявки — 404. Если объект ещё не загружен — 409, заявка не меняется. Повторный и параллельный complete готового вложения идемпотентен (200).", "parameters": [ { "name": "attachment_id", @@ -461,7 +461,7 @@ } }, "503": { - "description": "Хранилище недоступно", + "description": "Хранилище недоступно или не ответило за S3_REQUEST_TIMEOUT_MS / UPLOAD_TIMEOUT_MS", "headers": { "X-Request-Id": { "description": "Идентификатор запроса.", @@ -485,6 +485,39 @@ } } } + }, + "429": { + "description": "Реплика проверяет слишком много изображений одновременно (UPLOAD_MAX_IN_FLIGHT) или у пользователя слишком много одновременных проверок (UPLOAD_MAX_IN_FLIGHT_PER_USER); Retry-After — секунды до повтора.", + "headers": { + "X-Request-Id": { + "description": "Идентификатор запроса.", + "schema": { + "type": "string", + "minLength": 1 + } + }, + "X-Instance-Id": { + "description": "Идентификатор реплики.", + "schema": { + "type": "string", + "minLength": 1 + } + }, + "Retry-After": { + "description": "Секунды до повтора.", + "schema": { + "type": "integer", + "minimum": 1 + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "openapi.json#/components/schemas/Error" + } + } + } } } } diff --git a/evidence/lab4/decode-memory.txt b/evidence/lab4/decode-memory.txt index 09ebb0df..6a6bbf24 100644 --- a/evidence/lab4/decode-memory.txt +++ b/evidence/lab4/decode-memory.txt @@ -1,4 +1,7 @@ -# inputs: magick -size 6320x6320 gradient:red-blue (PNG); same as JPEG q85 baseline and -interlace JPEG -png 6320x6320 bytes=53350 decode_ms=1159 peak_delta_rss_mib=116.8 -jpeg 6320x6320 bytes=4899767 decode_ms=1234 peak_delta_rss_mib=126.5 -jpeg 6320x6320 progressive bytes=4791710 decode_ms=1379 peak_delta_rss_mib=130.5 +# container /mtusi-lab4-api-1, limits: 805306368 bytes, VIPS_DISC_THRESHOLD=1g; commit a06471a+worktree +jpeg 7728x5152 3ch uchar bytes=4921012 decode_ms=58 peak_delta_rss_mib=3.9 ok +jpeg 7728x5152 3ch uchar progressive bytes=4826968 decode_ms=278 peak_delta_rss_mib=117.7 ok +jpeg 7728x5152 4ch uchar bytes=10601868 decode_ms=161 peak_delta_rss_mib=7.7 ok +png 8000x5000 4ch ushort bytes=1420114 decode_ms=496 peak_delta_rss_mib=66.6 ok +png 8000x5000 4ch ushort progressive bytes=364096 decode_ms=1270 peak_delta_rss_mib=338.6 ok +png 8000x5000 3ch uchar progressive palette bytes=61042 decode_ms=341 peak_delta_rss_mib=126.0 ok diff --git a/scripts/lab4/attachments_bench.py b/scripts/lab4/attachments_bench.py index e5b41742..3ed8e626 100755 --- a/scripts/lab4/attachments_bench.py +++ b/scripts/lab4/attachments_bench.py @@ -141,7 +141,14 @@ def one_upload(env, mode, token, chat_id, data, seed): return ok, elapsed_ms -def run_once(env, args, token, chat_id, ids): +def payload(args, seed): + if args.image: + with open(args.image, "rb") as handle: + return handle.read() + return noise_png(args.size_bytes, seed) + + +def run_once(env, args, actors, ids): for container in ids: reset_metrics(container) time.sleep(0.2) @@ -153,7 +160,8 @@ def run_once(env, args, token, chat_id, ids): def worker(index): for step in range(args.uploads_per_worker): seed = index * 1000 + step - data = noise_png(args.size_bytes, seed) + data = payload(args, seed) + token, chat_id = actors[index % len(actors)] ok, elapsed = one_upload(env, args.mode, token, chat_id, data, seed) with lock: (latencies if ok else failures).append(elapsed) @@ -203,29 +211,39 @@ def run_once(env, args, token, chat_id, ids): def command_run(args): + if args.image: + args.size_bytes = os.path.getsize(args.image) + if args.size_bytes <= 0: + sys.exit("--size-bytes or --image is required") env = read_env() ids = containers() if not ids: sys.exit("no api containers found") - name = f"bench_{uuid.uuid4().hex[:10]}" - password = "bench:" + uuid.uuid4().hex - status, user = api_json(env, "POST", "/api/v1/users", - body={"username": name, "display_name": "bench", "password": password}) - assert status == 201, status - status, session = api_json(env, "POST", "/api/v1/auth/sessions", basic=f"{name}:{password}") - assert status == 201, status - token = session["token"] - status, chat = api_json(env, "POST", "/api/v1/chats", token, {"title": "bench", "member_ids": [user["id"]]}) - assert status == 201, status + # One user per worker: the API caps concurrent uploads per user + # (UPLOAD_MAX_IN_FLIGHT_PER_USER), and real traffic comes from many users. + actors = [] + for _ in range(args.concurrency): + name = f"bench_{uuid.uuid4().hex[:10]}" + password = "bench:" + uuid.uuid4().hex + status, user = api_json(env, "POST", "/api/v1/users", + body={"username": name, "display_name": "bench", "password": password}) + assert status == 201, status + status, session = api_json(env, "POST", "/api/v1/auth/sessions", basic=f"{name}:{password}") + assert status == 201, status + token = session["token"] + status, chat = api_json(env, "POST", "/api/v1/chats", token, {"title": "bench", "member_ids": [user["id"]]}) + assert status == 201, status + actors.append((token, chat["id"])) - # Warm-up: one upload per replica path, not measured. + # Warm-up: two uploads per replica, not measured. for seed in range(len(ids) * 2): - one_upload(env, args.mode, token, chat["id"], noise_png(args.size_bytes, 900000 + seed), seed) + token, chat_id = actors[seed % len(actors)] + one_upload(env, args.mode, token, chat_id, payload(args, 900000 + seed), seed) limits = [] for c in ids: limits.append(sh("docker", "inspect", "-f", "{{.HostConfig.NanoCpus}} {{.HostConfig.Memory}}", c)) - repeats = [run_once(env, args, token, chat["id"], ids) for _ in range(args.repeat)] + repeats = [run_once(env, args, actors, ids) for _ in range(args.repeat)] mem_total = next(int(l.split()[1]) * 1024 for l in open("/proc/meminfo") if l.startswith("MemTotal")) result = { "date": datetime.now(timezone.utc).isoformat(timespec="seconds"), @@ -233,6 +251,7 @@ def command_run(args): "params": { "mode": args.mode, "size_bytes": args.size_bytes, "concurrency": args.concurrency, "uploads_per_worker": args.uploads_per_worker, "repeat": args.repeat, + "users": args.concurrency, "image": os.path.basename(args.image) if args.image else None, }, "host": {"nproc": os.cpu_count(), "mem_total_bytes": mem_total}, "api_container_limits_nanocpus_memory": limits, @@ -260,17 +279,19 @@ def command_summarize(args): p = data["params"] reps = data["repeats"] med = lambda key: statistics.median(r[key] for r in reps) # noqa: E731 - rows.append((p["mode"], p["size_bytes"], p["concurrency"], reps, med, data)) - rows.sort(key=lambda r: (r[1], r[0], r[2])) - print("| mode | size, MiB | C | ok | API rx/upload, MiB | API tx/upload, MiB | max Δrss, MiB | p50, ms | p95, ms |") - print("|---|---|---|---|---|---|---|---|---|") + label = p["mode"] + (f" ({p['image']})" if p.get("image") else "") + rows.append((label, p["size_bytes"], p["concurrency"], reps, med, data)) + rows.sort(key=lambda r: (r[0].count("("), r[1], r[0], r[2])) + print("| mode | size, MiB | C | ok | API rx/upload, MiB | API tx/upload, MiB | max Δrss, MiB | peak RSS, MiB | p50, ms | p95, ms |") + print("|---|---|---|---|---|---|---|---|---|---|") for mode, size, conc, reps, med, _data in rows: + peak = max(x["peak_memory_bytes"]["rss"] for r in reps for x in r["replicas"]) ok = sum(r["succeeded"] for r in reps) total = sum(r["uploads"] for r in reps) p50 = statistics.median(r["latency_ms"]["p50"] for r in reps) p95 = statistics.median(r["latency_ms"]["p95"] for r in reps) print(f"| {mode} | {mib(size)} | {conc} | {ok}/{total} | {mib(med('rx_bytes_per_upload'))} | " - f"{mib(med('tx_bytes_per_upload'))} | {mib(med('max_delta_rss_bytes'))} | {p50:.0f} | {p95:.0f} |") + f"{mib(med('tx_bytes_per_upload'))} | {mib(med('max_delta_rss_bytes'))} | {mib(peak)} | {p50:.0f} | {p95:.0f} |") def main(): @@ -278,7 +299,8 @@ def main(): sub = parser.add_subparsers(dest="command", required=True) run = sub.add_parser("run") run.add_argument("--mode", choices=["proxy", "direct"], required=True) - run.add_argument("--size-bytes", type=int, required=True) + run.add_argument("--size-bytes", type=int, default=0) + run.add_argument("--image", help="upload this file instead of generated noise PNGs") run.add_argument("--concurrency", type=int, default=10) run.add_argument("--uploads-per-worker", type=int, default=5) run.add_argument("--repeat", type=int, default=3) diff --git a/scripts/lab4/decode_memory.mjs b/scripts/lab4/decode_memory.mjs index 475316d6..65bd84b4 100644 --- a/scripts/lab4/decode_memory.mjs +++ b/scripts/lab4/decode_memory.mjs @@ -1,22 +1,33 @@ -// Peak RSS of one full decode check (same sharp options as ImageDecoder) on -// worst-case inputs near MAX_IMAGE_PIXELS. Run from app/: node ../scripts/lab4/decode_memory.mjs +// Peak RSS of one full decode check with the same sharp pipeline as +// app/src/attachments/image/image-decoder.ts, on worst-case inputs near +// MAX_IMAGE_PIXELS. Runs where the API runs (same libvips, VIPS_DISC_THRESHOLD): +// docker compose exec -T api node - < scripts/lab4/decode_memory.mjs # reads files from IMAGES (paths in the container) +// or on the host from app/: IMAGES="a.png b.jpg" node ../scripts/lab4/decode_memory.mjs import { readFileSync } from 'node:fs'; import { createRequire } from 'node:module'; + const sharp = createRequire(`${process.cwd()}/`)('sharp'); sharp.cache(false); sharp.concurrency(1); -for (const file of process.argv.slice(2)) { +for (const file of (process.env.IMAGES ?? '').split(/\s+/u).filter(Boolean)) { const data = readFileSync(file); const meta = await sharp(data).metadata(); const base = process.memoryUsage().rss; let peak = base; const timer = setInterval(() => { peak = Math.max(peak, process.memoryUsage().rss); - }, 10); + }, 5); const started = Date.now(); - await sharp(data, { failOn: 'warning', sequentialRead: true, limitInputPixels: 40_000_000 }).stats(); + let verdict = 'ok'; + try { + await sharp(data, { failOn: 'warning', sequentialRead: true, limitInputPixels: 40_000_000 }) + .resize(64, 64, { fit: 'inside' }) + .toBuffer(); + } catch (error) { + verdict = `rejected: ${String(error.message).split('\n')[0]}`; + } clearInterval(timer); console.log( - `${meta.format} ${meta.width}x${meta.height}${meta.isProgressive ? ' progressive' : ''} bytes=${data.length} decode_ms=${Date.now() - started} peak_delta_rss_mib=${((peak - base) / 1048576).toFixed(1)}`, + `${meta.format} ${meta.width}x${meta.height} ${meta.channels}ch ${meta.depth}${meta.isProgressive ? ' progressive' : ''}${meta.isPalette ? ' palette' : ''} bytes=${data.length} decode_ms=${Date.now() - started} peak_delta_rss_mib=${((peak - base) / 1048576).toFixed(1)} ${verdict}`, ); } diff --git a/scripts/lab4/pngkit.py b/scripts/lab4/pngkit.py index a29c8864..1ec0b8d5 100644 --- a/scripts/lab4/pngkit.py +++ b/scripts/lab4/pngkit.py @@ -48,3 +48,31 @@ def noise_png(size: int, seed: int = 0) -> bytes: raise ValueError("size is too small") continue return pad_png(png, size) + + +ADAM7 = [(0, 0, 8, 8), (4, 0, 8, 8), (0, 4, 4, 8), (2, 0, 4, 4), (0, 2, 2, 4), (1, 0, 2, 2), (0, 1, 1, 2)] + + +def worst_decode_png(size: int = 10_485_760, width: int = 8000, height: int = 5000) -> bytes: + """The heaviest valid upload to decode: 40 MP RGBA 16-bit, Adam7-interlaced + (the decoder must hold the whole image), padded to exactly `size` bytes.""" + compressor = zlib.compressobj(1) + parts = [] + for x0, y0, dx, dy in ADAM7: + pass_width = (width - x0 + dx - 1) // dx if width > x0 else 0 + pass_height = (height - y0 + dy - 1) // dy if height > y0 else 0 + if pass_width == 0 or pass_height == 0: + continue + row = bytes(1 + pass_width * 8) + for _ in range(pass_height): + parts.append(compressor.compress(row)) + parts.append(compressor.flush()) + ihdr = struct.pack(">IIBBBBB", width, height, 16, 6, 0, 0, 1) + png = SIGNATURE + chunk(b"IHDR", ihdr) + chunk(b"IDAT", b"".join(parts)) + chunk(b"IEND", b"") + return pad_png(png, size) + + +if __name__ == "__main__": + import sys + + sys.stdout.buffer.write(worst_decode_png()) diff --git a/scripts/lab4/run_matrix.sh b/scripts/lab4/run_matrix.sh index c45df4ee..7edd2752 100755 --- a/scripts/lab4/run_matrix.sh +++ b/scripts/lab4/run_matrix.sh @@ -19,5 +19,17 @@ for size in 131072 1048576 9961472; do done echo "== proxy size=9961472 c=20" bench proxy 9961472 20 +# Worst case for memory: every request carries the heaviest valid image +# (40 MP RGBA16 Adam7 PNG padded to 10 MiB, ~340 MiB per decode) and C=32 +# saturates UPLOAD_MAX_IN_FLIGHT (16) on both replicas. +worst=$(mktemp --suffix=.png) +trap 'rm -f "$worst"' EXIT +python3 scripts/lab4/pngkit.py > "$worst" +for mode in proxy direct; do + echo "== $mode worst-case image c=32" + python3 scripts/lab4/attachments_bench.py run --mode "$mode" --image "$worst" \ + --concurrency 32 --uploads-per-worker 2 --repeat 3 \ + --output "$out/$mode-worst-c32.json" +done python3 scripts/lab4/attachments_bench.py summarize "$out"/*.json > evidence/lab4/summary.md cat evidence/lab4/summary.md -- 2.54.0 From 9caa0313be1b816e49e651dbdc2cd1104e163483 Mon Sep 17 00:00:00 2001 From: Ilya Date: Fri, 23 Oct 2026 17:18:54 +0300 Subject: [PATCH 13/15] =?UTF-8?q?lab4:=20=D0=B1=D0=B5=D0=BD=D1=87=D0=BC?= =?UTF-8?q?=D0=B0=D1=80=D0=BA=20=E2=80=94=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=82=D0=BE=D0=BA,=20=D1=85=D1=83=D0=B4=D1=88?= =?UTF-8?q?=D0=B8=D0=B9=20=D0=B2=D1=85=D0=BE=D0=B4,=20=D0=BA=D0=BB=D0=B0?= =?UTF-8?q?=D1=81=D1=81=D0=B8=D1=84=D0=B8=D0=BA=D0=B0=D1=86=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BE=D1=82=D0=BA=D0=B0=D0=B7=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- evidence/lab4/bench/direct-1048576-c10.json | 285 ++++++++++---------- evidence/lab4/bench/direct-131072-c10.json | 242 ++++++++--------- evidence/lab4/bench/direct-9961472-c10.json | 270 ++++++++++--------- evidence/lab4/bench/direct-worst-c32.json | 217 +++++++++++++++ evidence/lab4/bench/proxy-1048576-c10.json | 186 ++++++------- evidence/lab4/bench/proxy-131072-c10.json | 268 +++++++++--------- evidence/lab4/bench/proxy-9961472-c10.json | 192 ++++++------- evidence/lab4/bench/proxy-9961472-c20.json | 192 ++++++------- evidence/lab4/bench/proxy-worst-c32.json | 207 ++++++++++++++ evidence/lab4/decode-memory.txt | 15 +- evidence/lab4/direct-ttl-short.txt | 6 +- evidence/lab4/make-test-dependencies.txt | 6 +- evidence/lab4/make-test-e2e.txt | 6 +- evidence/lab4/summary.md | 20 +- evidence/lab4/unit-tests.txt | 12 +- scripts/lab4/attachments_bench.py | 91 ++++--- scripts/lab4/run_matrix.sh | 5 +- 17 files changed, 1343 insertions(+), 877 deletions(-) create mode 100644 evidence/lab4/bench/direct-worst-c32.json create mode 100644 evidence/lab4/bench/proxy-worst-c32.json diff --git a/evidence/lab4/bench/direct-1048576-c10.json b/evidence/lab4/bench/direct-1048576-c10.json index 641fc4b7..070e304e 100644 --- a/evidence/lab4/bench/direct-1048576-c10.json +++ b/evidence/lab4/bench/direct-1048576-c10.json @@ -1,214 +1,215 @@ { - "date": "2026-10-23T13:37:36+00:00", - "git": "4badd5a", + "date": "2026-10-23T14:14:08+00:00", + "git": "4b53e03", "params": { "mode": "direct", "size_bytes": 1048576, "concurrency": 10, "uploads_per_worker": 5, - "repeat": 3 + "repeat": 3, + "users": 10, + "image": null }, "host": { "nproc": 8, "mem_total_bytes": 16538955776 }, "api_container_limits_nanocpus_memory": [ - "1500000000 805306368", - "1500000000 805306368" + "1500000000 1073741824", + "1500000000 1073741824" ], "repeats": [ { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.97, + "duration_s": 0.499, "latency_ms": { - "p50": 159.8, - "p95": 252.1, - "p99": 272.0 + "p50": 75.9, + "p95": 103.8, + "p99": 130.9 }, "replicas": [ { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 31673930, - "delta_tx_bytes": 203789, - "baseline_rss_bytes": 233545728, + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 27463858, + "delta_tx_bytes": 202183, + "baseline_rss_bytes": 178360320, "peak_memory_bytes": { - "rss": 236560384, - "heap_used": 54194600, - "external": 35034666, - "array_buffers": 31244322 + "rss": 201052160, + "heap_used": 56368848, + "external": 36994298, + "array_buffers": 33183530 }, - "delta_rss_bytes": 3014656, - "counters": { - "attachments.count_pending_direct": 20, - "attachments.insert_pending": 20, - "attachments.direct.initiated": 20, - "attachments.find_for_complete": 30, - "attachments.direct.verify_bytes": 31457280, - "attachments.decode.ms": 1724.6966849999153, - "attachments.mark_ready": 30, - "attachments.direct.completed": 30 - } - }, - { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 21149099, - "delta_tx_bytes": 198366, - "baseline_rss_bytes": 268025856, - "peak_memory_bytes": { - "rss": 269074432, - "heap_used": 54788360, - "external": 25616254, - "array_buffers": 21825910 - }, - "delta_rss_bytes": 1048576, - "counters": { - "attachments.count_pending_direct": 30, - "attachments.insert_pending": 30, - "attachments.direct.initiated": 30, - "attachments.find_for_complete": 20, - "attachments.direct.verify_bytes": 20971520, - "attachments.decode.ms": 688.2958910000743, - "attachments.mark_ready": 20, - "attachments.direct.completed": 20 - } - } - ], - "total_delta_rx_bytes": 52823029, - "total_delta_tx_bytes": 402155, - "rx_bytes_per_upload": 1056461, - "tx_bytes_per_upload": 8043, - "max_delta_rss_bytes": 3014656 - }, - { - "uploads": 50, - "succeeded": 50, - "failed": 0, - "duration_s": 0.9, - "latency_ms": { - "p50": 141.1, - "p95": 244.2, - "p99": 270.7 - }, - "replicas": [ - { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 27465799, - "delta_tx_bytes": 191310, - "baseline_rss_bytes": 236560384, - "peak_memory_bytes": { - "rss": 236953600, - "heap_used": 54493200, - "external": 30789946, - "array_buffers": 26999410 - }, - "delta_rss_bytes": 393216, + "delta_rss_bytes": 22691840, "counters": { "attachments.count_pending_direct": 24, "attachments.insert_pending": 24, "attachments.direct.initiated": 24, "attachments.find_for_complete": 26, "attachments.direct.verify_bytes": 27262976, - "attachments.decode.ms": 1384.4109410000383, + "attachments.decode.ms": 193.75719499992556, "attachments.mark_ready": 26, "attachments.direct.completed": 26 } }, { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 25357866, - "delta_tx_bytes": 191558, - "baseline_rss_bytes": 269074432, + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 25359117, + "delta_tx_bytes": 199445, + "baseline_rss_bytes": 184389632, "peak_memory_bytes": { - "rss": 270516224, - "heap_used": 54339648, - "external": 30902899, - "array_buffers": 27112555 + "rss": 192516096, + "heap_used": 53666840, + "external": 28723916, + "array_buffers": 24917693 }, - "delta_rss_bytes": 1441792, + "delta_rss_bytes": 8126464, "counters": { "attachments.count_pending_direct": 26, "attachments.insert_pending": 26, "attachments.direct.initiated": 26, "attachments.find_for_complete": 24, "attachments.direct.verify_bytes": 25165824, - "attachments.decode.ms": 1058.1902670000563, + "attachments.decode.ms": 152.91470899997512, "attachments.mark_ready": 24, "attachments.direct.completed": 24 } } ], - "total_delta_rx_bytes": 52823665, - "total_delta_tx_bytes": 382868, - "rx_bytes_per_upload": 1056473, - "tx_bytes_per_upload": 7657, - "max_delta_rss_bytes": 1441792 + "total_delta_rx_bytes": 52822975, + "total_delta_tx_bytes": 401628, + "rx_bytes_per_upload": 1056460, + "tx_bytes_per_upload": 8033, + "max_delta_rss_bytes": 22691840 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.969, + "duration_s": 0.528, "latency_ms": { - "p50": 154.4, - "p95": 274.5, - "p99": 328.1 + "p50": 75.6, + "p95": 106.0, + "p99": 124.3 }, "replicas": [ { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 24307994, - "delta_tx_bytes": 188454, - "baseline_rss_bytes": 236953600, + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 26408075, + "delta_tx_bytes": 188162, + "baseline_rss_bytes": 201052160, "peak_memory_bytes": { - "rss": 236953600, - "heap_used": 53822176, - "external": 29735853, - "array_buffers": 25943144 + "rss": 209047552, + "heap_used": 59470168, + "external": 43348610, + "array_buffers": 39528755 }, - "delta_rss_bytes": 0, + "delta_rss_bytes": 7995392, "counters": { - "attachments.count_pending_direct": 27, - "attachments.insert_pending": 27, - "attachments.direct.initiated": 27, - "attachments.find_for_complete": 23, - "attachments.direct.verify_bytes": 24117248, - "attachments.decode.ms": 1452.813747000182, - "attachments.mark_ready": 23, - "attachments.direct.completed": 23 + "attachments.count_pending_direct": 25, + "attachments.insert_pending": 25, + "attachments.direct.initiated": 25, + "attachments.find_for_complete": 25, + "attachments.direct.verify_bytes": 26214400, + "attachments.decode.ms": 129.85774100001436, + "attachments.mark_ready": 25, + "attachments.direct.completed": 25 } }, { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 28514629, - "delta_tx_bytes": 189117, - "baseline_rss_bytes": 270516224, + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 26411366, + "delta_tx_bytes": 196214, + "baseline_rss_bytes": 189214720, "peak_memory_bytes": { - "rss": 271433728, - "heap_used": 54290488, - "external": 34042295, - "array_buffers": 30251951 + "rss": 206053376, + "heap_used": 55771464, + "external": 29767218, + "array_buffers": 25958693 }, - "delta_rss_bytes": 917504, + "delta_rss_bytes": 16838656, "counters": { - "attachments.claim_expired": 1, - "attachments.count_pending_direct": 23, - "attachments.insert_pending": 23, - "attachments.direct.initiated": 23, - "attachments.find_for_complete": 27, - "attachments.direct.verify_bytes": 28311552, - "attachments.decode.ms": 1425.6747240000404, - "attachments.mark_ready": 27, - "attachments.direct.completed": 27 + "attachments.count_pending_direct": 25, + "attachments.insert_pending": 25, + "attachments.direct.initiated": 25, + "attachments.find_for_complete": 25, + "attachments.direct.verify_bytes": 26214400, + "attachments.decode.ms": 134.29743300002883, + "attachments.mark_ready": 25, + "attachments.direct.completed": 25 } } ], - "total_delta_rx_bytes": 52822623, - "total_delta_tx_bytes": 377571, - "rx_bytes_per_upload": 1056452, - "tx_bytes_per_upload": 7551, - "max_delta_rss_bytes": 917504 + "total_delta_rx_bytes": 52819441, + "total_delta_tx_bytes": 384376, + "rx_bytes_per_upload": 1056389, + "tx_bytes_per_upload": 7688, + "max_delta_rss_bytes": 16838656 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 0.499, + "latency_ms": { + "p50": 71.8, + "p95": 96.8, + "p99": 111.2 + }, + "replicas": [ + { + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 25354317, + "delta_tx_bytes": 184357, + "baseline_rss_bytes": 190746624, + "peak_memory_bytes": { + "rss": 192581632, + "heap_used": 53105536, + "external": 22274012, + "array_buffers": 18470057 + }, + "delta_rss_bytes": 1835008, + "counters": { + "attachments.count_pending_direct": 26, + "attachments.insert_pending": 26, + "attachments.direct.initiated": 26, + "attachments.find_for_complete": 24, + "attachments.direct.verify_bytes": 25165824, + "attachments.decode.ms": 120.24603700000443, + "attachments.mark_ready": 24, + "attachments.direct.completed": 24 + } + }, + { + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 27462079, + "delta_tx_bytes": 189327, + "baseline_rss_bytes": 206053376, + "peak_memory_bytes": { + "rss": 206053376, + "heap_used": 53308280, + "external": 30828871, + "array_buffers": 23867652 + }, + "delta_rss_bytes": 0, + "counters": { + "attachments.count_pending_direct": 24, + "attachments.insert_pending": 24, + "attachments.direct.initiated": 24, + "attachments.find_for_complete": 26, + "attachments.direct.verify_bytes": 27262976, + "attachments.decode.ms": 152.01662400003988, + "attachments.mark_ready": 26, + "attachments.direct.completed": 26 + } + } + ], + "total_delta_rx_bytes": 52816396, + "total_delta_tx_bytes": 373684, + "rx_bytes_per_upload": 1056328, + "tx_bytes_per_upload": 7474, + "max_delta_rss_bytes": 1835008 } ] } diff --git a/evidence/lab4/bench/direct-131072-c10.json b/evidence/lab4/bench/direct-131072-c10.json index 896afa48..da94832a 100644 --- a/evidence/lab4/bench/direct-131072-c10.json +++ b/evidence/lab4/bench/direct-131072-c10.json @@ -1,213 +1,215 @@ { - "date": "2026-10-23T13:37:23+00:00", - "git": "4badd5a", + "date": "2026-10-23T14:13:55+00:00", + "git": "4b53e03", "params": { "mode": "direct", "size_bytes": 131072, "concurrency": 10, "uploads_per_worker": 5, - "repeat": 3 + "repeat": 3, + "users": 10, + "image": null }, "host": { "nproc": 8, "mem_total_bytes": 16538955776 }, "api_container_limits_nanocpus_memory": [ - "1500000000 805306368", - "1500000000 805306368" + "1500000000 1073741824", + "1500000000 1073741824" ], "repeats": [ { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.413, + "duration_s": 0.243, "latency_ms": { - "p50": 72.1, - "p95": 114.3, - "p99": 142.9 + "p50": 43.7, + "p95": 53.9, + "p99": 61.8 }, "replicas": [ { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 3172654, - "delta_tx_bytes": 183439, - "baseline_rss_bytes": 224358400, + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 3172400, + "delta_tx_bytes": 183678, + "baseline_rss_bytes": 156618752, "peak_memory_bytes": { - "rss": 224620544, - "heap_used": 49708416, - "external": 6066500, - "array_buffers": 2276156 + "rss": 158715904, + "heap_used": 54191144, + "external": 9449376, + "array_buffers": 5653126 }, - "delta_rss_bytes": 262144, + "delta_rss_bytes": 2097152, "counters": { "attachments.count_pending_direct": 27, "attachments.insert_pending": 27, "attachments.direct.initiated": 27, "attachments.find_for_complete": 23, "attachments.direct.verify_bytes": 3014656, - "attachments.decode.ms": 395.56102700001793, + "attachments.decode.ms": 76.10400699995807, "attachments.mark_ready": 23, "attachments.direct.completed": 23 } }, { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 3707235, - "delta_tx_bytes": 187659, - "baseline_rss_bytes": 255918080, + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 3707187, + "delta_tx_bytes": 186902, + "baseline_rss_bytes": 156594176, "peak_memory_bytes": { - "rss": 257359872, - "heap_used": 50212920, - "external": 8800241, - "array_buffers": 5009897 + "rss": 157773824, + "heap_used": 53887688, + "external": 8848676, + "array_buffers": 5052846 }, - "delta_rss_bytes": 1441792, + "delta_rss_bytes": 1179648, "counters": { "attachments.count_pending_direct": 23, "attachments.insert_pending": 23, "attachments.direct.initiated": 23, "attachments.find_for_complete": 27, "attachments.direct.verify_bytes": 3538944, - "attachments.decode.ms": 743.5491730003268, + "attachments.decode.ms": 104.25295099997311, "attachments.mark_ready": 27, "attachments.direct.completed": 27 } } ], - "total_delta_rx_bytes": 6879889, - "total_delta_tx_bytes": 371098, - "rx_bytes_per_upload": 137598, - "tx_bytes_per_upload": 7422, - "max_delta_rss_bytes": 1441792 + "total_delta_rx_bytes": 6879587, + "total_delta_tx_bytes": 370580, + "rx_bytes_per_upload": 137592, + "tx_bytes_per_upload": 7412, + "max_delta_rss_bytes": 2097152 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.434, + "duration_s": 0.277, "latency_ms": { - "p50": 82.0, - "p95": 119.6, - "p99": 136.5 + "p50": 44.7, + "p95": 89.7, + "p99": 95.4 }, "replicas": [ { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 3572309, - "delta_tx_bytes": 186069, - "baseline_rss_bytes": 224620544, + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 3172155, + "delta_tx_bytes": 182647, + "baseline_rss_bytes": 158715904, "peak_memory_bytes": { - "rss": 224751616, - "heap_used": 49977872, - "external": 6204496, - "array_buffers": 2414152 + "rss": 159240192, + "heap_used": 54550992, + "external": 9440830, + "array_buffers": 5644565 }, - "delta_rss_bytes": 131072, + "delta_rss_bytes": 524288, "counters": { - "attachments.count_pending_direct": 24, - "attachments.insert_pending": 24, - "attachments.direct.initiated": 24, - "attachments.find_for_complete": 26, - "attachments.direct.verify_bytes": 3407872, - "attachments.decode.ms": 610.345750999928, - "attachments.mark_ready": 26, - "attachments.direct.completed": 26 + "attachments.count_pending_direct": 27, + "attachments.insert_pending": 27, + "attachments.direct.initiated": 27, + "attachments.find_for_complete": 23, + "attachments.direct.verify_bytes": 3014656, + "attachments.decode.ms": 78.99052299992763, + "attachments.mark_ready": 23, + "attachments.direct.completed": 23 } }, { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 3306233, - "delta_tx_bytes": 183451, - "baseline_rss_bytes": 257359872, + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 3706467, + "delta_tx_bytes": 186009, + "baseline_rss_bytes": 157396992, "peak_memory_bytes": { - "rss": 262864896, - "heap_used": 53884096, - "external": 9284140, - "array_buffers": 5493796 + "rss": 157790208, + "heap_used": 54303864, + "external": 8848749, + "array_buffers": 5052919 }, - "delta_rss_bytes": 5505024, + "delta_rss_bytes": 393216, "counters": { - "attachments.count_pending_direct": 26, - "attachments.insert_pending": 26, - "attachments.direct.initiated": 26, - "attachments.find_for_complete": 24, - "attachments.direct.verify_bytes": 3145728, - "attachments.decode.ms": 675.0934380001272, - "attachments.mark_ready": 24, - "attachments.direct.completed": 24 + "attachments.count_pending_direct": 23, + "attachments.insert_pending": 23, + "attachments.direct.initiated": 23, + "attachments.find_for_complete": 27, + "attachments.direct.verify_bytes": 3538944, + "attachments.decode.ms": 96.7698720000626, + "attachments.mark_ready": 27, + "attachments.direct.completed": 27 } } ], - "total_delta_rx_bytes": 6878542, - "total_delta_tx_bytes": 369520, - "rx_bytes_per_upload": 137571, - "tx_bytes_per_upload": 7390, - "max_delta_rss_bytes": 5505024 + "total_delta_rx_bytes": 6878622, + "total_delta_tx_bytes": 368656, + "rx_bytes_per_upload": 137572, + "tx_bytes_per_upload": 7373, + "max_delta_rss_bytes": 524288 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.457, + "duration_s": 0.266, "latency_ms": { - "p50": 69.4, - "p95": 160.1, - "p99": 168.0 + "p50": 46.8, + "p95": 70.1, + "p99": 72.4 }, "replicas": [ { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 3973401, - "delta_tx_bytes": 186806, - "baseline_rss_bytes": 224751616, + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 3839887, + "delta_tx_bytes": 184887, + "baseline_rss_bytes": 159240192, "peak_memory_bytes": { - "rss": 231305216, - "heap_used": 52952680, - "external": 7971474, - "array_buffers": 4181130 + "rss": 165924864, + "heap_used": 56746264, + "external": 9177437, + "array_buffers": 5381598 }, - "delta_rss_bytes": 6553600, + "delta_rss_bytes": 6684672, "counters": { - "attachments.count_pending_direct": 21, - "attachments.insert_pending": 21, - "attachments.direct.initiated": 21, - "attachments.find_for_complete": 29, - "attachments.direct.verify_bytes": 3801088, - "attachments.decode.ms": 828.3032130000065, - "attachments.mark_ready": 29, - "attachments.direct.completed": 29 + "attachments.count_pending_direct": 22, + "attachments.insert_pending": 22, + "attachments.direct.initiated": 22, + "attachments.find_for_complete": 28, + "attachments.direct.verify_bytes": 3670016, + "attachments.decode.ms": 115.71663299991633, + "attachments.mark_ready": 28, + "attachments.direct.completed": 28 } }, { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 2904621, - "delta_tx_bytes": 180542, - "baseline_rss_bytes": 262864896, + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 3037580, + "delta_tx_bytes": 179535, + "baseline_rss_bytes": 157790208, "peak_memory_bytes": { - "rss": 262995968, - "heap_used": 53715664, - "external": 7518119, - "array_buffers": 3727743 + "rss": 159514624, + "heap_used": 55134936, + "external": 8340329, + "array_buffers": 4545339 }, - "delta_rss_bytes": 131072, + "delta_rss_bytes": 1724416, "counters": { - "attachments.count_pending_direct": 29, - "attachments.insert_pending": 29, - "attachments.direct.initiated": 29, - "attachments.find_for_complete": 21, - "attachments.direct.verify_bytes": 2752512, - "attachments.decode.ms": 312.0048850000021, - "attachments.mark_ready": 21, - "attachments.direct.completed": 21 + "attachments.count_pending_direct": 28, + "attachments.insert_pending": 28, + "attachments.direct.initiated": 28, + "attachments.find_for_complete": 22, + "attachments.direct.verify_bytes": 2883584, + "attachments.decode.ms": 78.47993500009761, + "attachments.mark_ready": 22, + "attachments.direct.completed": 22 } } ], - "total_delta_rx_bytes": 6878022, - "total_delta_tx_bytes": 367348, - "rx_bytes_per_upload": 137560, - "tx_bytes_per_upload": 7347, - "max_delta_rss_bytes": 6553600 + "total_delta_rx_bytes": 6877467, + "total_delta_tx_bytes": 364422, + "rx_bytes_per_upload": 137549, + "tx_bytes_per_upload": 7288, + "max_delta_rss_bytes": 6684672 } ] } diff --git a/evidence/lab4/bench/direct-9961472-c10.json b/evidence/lab4/bench/direct-9961472-c10.json index 1aa8c095..19ab4861 100644 --- a/evidence/lab4/bench/direct-9961472-c10.json +++ b/evidence/lab4/bench/direct-9961472-c10.json @@ -1,213 +1,215 @@ { - "date": "2026-10-23T13:38:14+00:00", - "git": "4badd5a", + "date": "2026-10-23T14:14:37+00:00", + "git": "4b53e03", "params": { "mode": "direct", "size_bytes": 9961472, "concurrency": 10, "uploads_per_worker": 5, - "repeat": 3 + "repeat": 3, + "users": 10, + "image": null }, "host": { "nproc": 8, "mem_total_bytes": 16538955776 }, "api_container_limits_nanocpus_memory": [ - "1500000000 805306368", - "1500000000 805306368" + "1500000000 1073741824", + "1500000000 1073741824" ], "repeats": [ { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 4.981, + "duration_s": 3.609, "latency_ms": { - "p50": 754.7, - "p95": 975.5, - "p99": 1146.0 + "p50": 437.2, + "p95": 593.2, + "p99": 654.5 }, "replicas": [ { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 289415606, - "delta_tx_bytes": 315409, - "baseline_rss_bytes": 233209856, + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 249509901, + "delta_tx_bytes": 287547, + "baseline_rss_bytes": 195174400, "peak_memory_bytes": { - "rss": 348733440, - "heap_used": 50095696, - "external": 115684307, - "array_buffers": 111893963 + "rss": 288415744, + "heap_used": 54409488, + "external": 117617657, + "array_buffers": 113825666 }, - "delta_rss_bytes": 115523584, + "delta_rss_bytes": 93241344, "counters": { - "attachments.count_pending_direct": 21, - "attachments.insert_pending": 21, - "attachments.direct.initiated": 21, - "attachments.find_for_complete": 29, - "attachments.direct.verify_bytes": 288882688, - "attachments.decode.ms": 7608.848039000004, - "attachments.mark_ready": 29, - "attachments.direct.completed": 29 + "attachments.count_pending_direct": 25, + "attachments.insert_pending": 25, + "attachments.direct.initiated": 25, + "attachments.find_for_complete": 25, + "attachments.direct.verify_bytes": 249036800, + "attachments.decode.ms": 315.7971269999689, + "attachments.mark_ready": 25, + "attachments.direct.completed": 25 } }, { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 209597436, - "delta_tx_bytes": 298627, - "baseline_rss_bytes": 299487232, + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 249507617, + "delta_tx_bytes": 274665, + "baseline_rss_bytes": 214401024, "peak_memory_bytes": { - "rss": 330563584, - "heap_used": 51925192, - "external": 97861662, - "array_buffers": 94071318 + "rss": 289472512, + "heap_used": 51210776, + "external": 78987756, + "array_buffers": 75194088 }, - "delta_rss_bytes": 31076352, + "delta_rss_bytes": 75071488, "counters": { - "attachments.count_pending_direct": 29, - "attachments.insert_pending": 29, - "attachments.direct.initiated": 29, - "attachments.find_for_complete": 21, - "attachments.direct.verify_bytes": 209190912, - "attachments.decode.ms": 5015.750637000019, - "attachments.mark_ready": 21, - "attachments.direct.completed": 21 + "attachments.count_pending_direct": 25, + "attachments.insert_pending": 25, + "attachments.direct.initiated": 25, + "attachments.find_for_complete": 25, + "attachments.direct.verify_bytes": 249036800, + "attachments.decode.ms": 276.87352200000896, + "attachments.mark_ready": 25, + "attachments.direct.completed": 25 } } ], - "total_delta_rx_bytes": 499013042, - "total_delta_tx_bytes": 614036, - "rx_bytes_per_upload": 9980261, - "tx_bytes_per_upload": 12281, - "max_delta_rss_bytes": 115523584 + "total_delta_rx_bytes": 499017518, + "total_delta_tx_bytes": 562212, + "rx_bytes_per_upload": 9980350, + "tx_bytes_per_upload": 11244, + "max_delta_rss_bytes": 93241344 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 5.254, + "duration_s": 3.4, "latency_ms": { - "p50": 900.1, - "p95": 1222.8, - "p99": 1235.6 + "p50": 424.6, + "p95": 661.8, + "p99": 810.6 }, "replicas": [ { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 309427096, - "delta_tx_bytes": 332725, - "baseline_rss_bytes": 282836992, + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 239528101, + "delta_tx_bytes": 272852, + "baseline_rss_bytes": 205328384, "peak_memory_bytes": { - "rss": 370515968, - "heap_used": 52368944, - "external": 134179853, - "array_buffers": 130389509 + "rss": 300617728, + "heap_used": 50698680, + "external": 103322639, + "array_buffers": 99528980 }, - "delta_rss_bytes": 87678976, + "delta_rss_bytes": 95289344, "counters": { - "attachments.count_pending_direct": 19, - "attachments.insert_pending": 19, - "attachments.direct.initiated": 19, - "attachments.find_for_complete": 31, - "attachments.direct.verify_bytes": 308805632, - "attachments.decode.ms": 8379.456620000012, - "attachments.mark_ready": 31, - "attachments.direct.completed": 31 + "attachments.count_pending_direct": 26, + "attachments.insert_pending": 26, + "attachments.direct.initiated": 26, + "attachments.find_for_complete": 24, + "attachments.direct.verify_bytes": 239075328, + "attachments.decode.ms": 398.21300999989035, + "attachments.mark_ready": 24, + "attachments.direct.completed": 24 } }, { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 189647218, - "delta_tx_bytes": 291721, - "baseline_rss_bytes": 286593024, + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 259470789, + "delta_tx_bytes": 262770, + "baseline_rss_bytes": 246329344, "peak_memory_bytes": { - "rss": 338497536, - "heap_used": 53161904, - "external": 107895361, - "array_buffers": 104105017 + "rss": 286126080, + "heap_used": 50197744, + "external": 84091903, + "array_buffers": 80294845 }, - "delta_rss_bytes": 51904512, + "delta_rss_bytes": 39796736, "counters": { - "attachments.count_pending_direct": 31, - "attachments.insert_pending": 31, - "attachments.direct.initiated": 31, - "attachments.find_for_complete": 19, - "attachments.direct.verify_bytes": 189267968, - "attachments.decode.ms": 3974.233845000039, - "attachments.mark_ready": 19, - "attachments.direct.completed": 19 + "attachments.count_pending_direct": 24, + "attachments.insert_pending": 24, + "attachments.direct.initiated": 24, + "attachments.find_for_complete": 26, + "attachments.direct.verify_bytes": 258998272, + "attachments.decode.ms": 379.7956310000154, + "attachments.mark_ready": 26, + "attachments.direct.completed": 26 } } ], - "total_delta_rx_bytes": 499074314, - "total_delta_tx_bytes": 624446, - "rx_bytes_per_upload": 9981486, - "tx_bytes_per_upload": 12489, - "max_delta_rss_bytes": 87678976 + "total_delta_rx_bytes": 498998890, + "total_delta_tx_bytes": 535622, + "rx_bytes_per_upload": 9979978, + "tx_bytes_per_upload": 10712, + "max_delta_rss_bytes": 95289344 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 4.652, + "duration_s": 3.356, "latency_ms": { - "p50": 692.0, - "p95": 1018.5, - "p99": 1133.8 + "p50": 420.6, + "p95": 614.8, + "p99": 658.8 }, "replicas": [ { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 269445871, - "delta_tx_bytes": 269717, - "baseline_rss_bytes": 340176896, + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 279414785, + "delta_tx_bytes": 268777, + "baseline_rss_bytes": 247771136, "peak_memory_bytes": { - "rss": 342388736, - "heap_used": 50625080, - "external": 119380564, - "array_buffers": 100369674 + "rss": 275718144, + "heap_used": 51721152, + "external": 97550522, + "array_buffers": 92510562 }, - "delta_rss_bytes": 2211840, + "delta_rss_bytes": 27947008, "counters": { - "attachments.count_pending_direct": 23, - "attachments.insert_pending": 23, - "attachments.direct.initiated": 23, - "attachments.find_for_complete": 27, - "attachments.direct.verify_bytes": 268959744, - "attachments.decode.ms": 7779.908828999905, - "attachments.mark_ready": 27, - "attachments.direct.completed": 27 + "attachments.count_pending_direct": 22, + "attachments.insert_pending": 22, + "attachments.direct.initiated": 22, + "attachments.find_for_complete": 28, + "attachments.direct.verify_bytes": 278921216, + "attachments.decode.ms": 460.6956299999729, + "attachments.mark_ready": 28, + "attachments.direct.completed": 28 } }, { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 229550093, - "delta_tx_bytes": 268720, - "baseline_rss_bytes": 308649984, + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 219572364, + "delta_tx_bytes": 248203, + "baseline_rss_bytes": 246599680, "peak_memory_bytes": { - "rss": 354787328, - "heap_used": 52204288, - "external": 121315649, - "array_buffers": 100267973 + "rss": 280461312, + "heap_used": 51774984, + "external": 90380520, + "array_buffers": 86585199 }, - "delta_rss_bytes": 46137344, + "delta_rss_bytes": 33861632, "counters": { - "attachments.count_pending_direct": 27, - "attachments.insert_pending": 27, - "attachments.direct.initiated": 27, - "attachments.find_for_complete": 23, - "attachments.direct.verify_bytes": 229113856, - "attachments.decode.ms": 6111.090034999943, - "attachments.mark_ready": 23, - "attachments.direct.completed": 23 + "attachments.count_pending_direct": 28, + "attachments.insert_pending": 28, + "attachments.direct.initiated": 28, + "attachments.find_for_complete": 22, + "attachments.direct.verify_bytes": 219152384, + "attachments.decode.ms": 303.119670999964, + "attachments.mark_ready": 22, + "attachments.direct.completed": 22 } } ], - "total_delta_rx_bytes": 498995964, - "total_delta_tx_bytes": 538437, - "rx_bytes_per_upload": 9979919, - "tx_bytes_per_upload": 10769, - "max_delta_rss_bytes": 46137344 + "total_delta_rx_bytes": 498987149, + "total_delta_tx_bytes": 516980, + "rx_bytes_per_upload": 9979743, + "tx_bytes_per_upload": 10340, + "max_delta_rss_bytes": 33861632 } ] } diff --git a/evidence/lab4/bench/direct-worst-c32.json b/evidence/lab4/bench/direct-worst-c32.json new file mode 100644 index 00000000..59f53a19 --- /dev/null +++ b/evidence/lab4/bench/direct-worst-c32.json @@ -0,0 +1,217 @@ +{ + "date": "2026-10-23T14:17:56+00:00", + "git": "4b53e03", + "params": { + "mode": "direct", + "size_bytes": 10485760, + "concurrency": 32, + "uploads_per_worker": 2, + "repeat": 3, + "users": 32, + "image": "tmp.n0I8NPEIWj.png" + }, + "host": { + "nproc": 8, + "mem_total_bytes": 16538955776 + }, + "api_container_limits_nanocpus_memory": [ + "1500000000 1073741824", + "1500000000 1073741824" + ], + "repeats": [ + { + "uploads": 64, + "succeeded": 48, + "failed": 16, + "duration_s": 25.799, + "latency_ms": { + "p50": 10903.2, + "p95": 13413.2, + "p99": 14173.1 + }, + "replicas": [ + { + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 168207096, + "delta_tx_bytes": 377593, + "baseline_rss_bytes": 413126656, + "peak_memory_bytes": { + "rss": 811970560, + "heap_used": 51684264, + "external": 224794743, + "array_buffers": 221004399 + }, + "delta_rss_bytes": 398843904, + "counters": { + "attachments.count_pending_direct": 48, + "attachments.insert_pending": 48, + "attachments.direct.initiated": 48, + "attachments.find_for_complete": 16, + "attachments.direct.verify_bytes": 167772160, + "attachments.decode.ms": 12822.89115199988, + "attachments.mark_ready": 16, + "attachments.direct.completed": 16 + } + }, + { + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 336356397, + "delta_tx_bytes": 437597, + "baseline_rss_bytes": 273133568, + "peak_memory_bytes": { + "rss": 811171840, + "heap_used": 50554752, + "external": 236627771, + "array_buffers": 232837243 + }, + "delta_rss_bytes": 538038272, + "counters": { + "attachments.count_pending_direct": 16, + "attachments.insert_pending": 16, + "attachments.direct.initiated": 16, + "attachments.find_for_complete": 48, + "attachments.direct.verify_bytes": 335544320, + "attachments.decode.ms": 24913.963424000074, + "attachments.mark_ready": 32, + "attachments.direct.completed": 32 + } + } + ], + "total_delta_rx_bytes": 504563493, + "total_delta_tx_bytes": 815190, + "rx_bytes_per_upload": 7883805, + "tx_bytes_per_upload": 12737, + "max_delta_rss_bytes": 538038272 + }, + { + "uploads": 64, + "succeeded": 48, + "failed": 16, + "duration_s": 25.734, + "latency_ms": { + "p50": 11194.6, + "p95": 13476.1, + "p99": 14262.3 + }, + "replicas": [ + { + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 168183438, + "delta_tx_bytes": 346932, + "baseline_rss_bytes": 458866688, + "peak_memory_bytes": { + "rss": 790888448, + "heap_used": 51757664, + "external": 233673177, + "array_buffers": 229882833 + }, + "delta_rss_bytes": 332021760, + "counters": { + "attachments.count_pending_direct": 48, + "attachments.insert_pending": 48, + "attachments.direct.initiated": 48, + "attachments.find_for_complete": 16, + "attachments.direct.verify_bytes": 167772160, + "attachments.decode.ms": 12989.242685000005, + "attachments.mark_ready": 16, + "attachments.direct.completed": 16, + "attachments.claim_expired": 1 + } + }, + { + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 336214769, + "delta_tx_bytes": 436112, + "baseline_rss_bytes": 457699328, + "peak_memory_bytes": { + "rss": 825307136, + "heap_used": 54086928, + "external": 219073224, + "array_buffers": 208987973 + }, + "delta_rss_bytes": 367607808, + "counters": { + "attachments.count_pending_direct": 16, + "attachments.insert_pending": 16, + "attachments.direct.initiated": 16, + "attachments.find_for_complete": 48, + "attachments.direct.verify_bytes": 335544320, + "attachments.decode.ms": 24466.148074000026, + "attachments.mark_ready": 32, + "attachments.direct.completed": 32, + "attachments.claim_expired": 1 + } + } + ], + "total_delta_rx_bytes": 504398207, + "total_delta_tx_bytes": 783044, + "rx_bytes_per_upload": 7881222, + "tx_bytes_per_upload": 12235, + "max_delta_rss_bytes": 367607808 + }, + { + "uploads": 64, + "succeeded": 48, + "failed": 16, + "duration_s": 25.623, + "latency_ms": { + "p50": 10789.6, + "p95": 13221.5, + "p99": 14052.1 + }, + "replicas": [ + { + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 168209005, + "delta_tx_bytes": 348167, + "baseline_rss_bytes": 437620736, + "peak_memory_bytes": { + "rss": 822276096, + "heap_used": 51899912, + "external": 234753853, + "array_buffers": 230961509 + }, + "delta_rss_bytes": 384655360, + "counters": { + "attachments.count_pending_direct": 48, + "attachments.insert_pending": 48, + "attachments.direct.initiated": 48, + "attachments.find_for_complete": 16, + "attachments.direct.verify_bytes": 167772160, + "attachments.decode.ms": 12794.351691999997, + "attachments.mark_ready": 16, + "attachments.direct.completed": 16 + } + }, + { + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 336206395, + "delta_tx_bytes": 391291, + "baseline_rss_bytes": 472084480, + "peak_memory_bytes": { + "rss": 803594240, + "heap_used": 54432464, + "external": 237968850, + "array_buffers": 234178395 + }, + "delta_rss_bytes": 331509760, + "counters": { + "attachments.count_pending_direct": 16, + "attachments.insert_pending": 16, + "attachments.direct.initiated": 16, + "attachments.find_for_complete": 48, + "attachments.direct.verify_bytes": 335544320, + "attachments.decode.ms": 24526.03154399991, + "attachments.mark_ready": 32, + "attachments.direct.completed": 32 + } + } + ], + "total_delta_rx_bytes": 504415400, + "total_delta_tx_bytes": 739458, + "rx_bytes_per_upload": 7881491, + "tx_bytes_per_upload": 11554, + "max_delta_rss_bytes": 384655360 + } + ] +} diff --git a/evidence/lab4/bench/proxy-1048576-c10.json b/evidence/lab4/bench/proxy-1048576-c10.json index 837c66c0..7f312bf6 100644 --- a/evidence/lab4/bench/proxy-1048576-c10.json +++ b/evidence/lab4/bench/proxy-1048576-c10.json @@ -1,201 +1,203 @@ { - "date": "2026-10-23T13:37:29+00:00", - "git": "4badd5a", + "date": "2026-10-23T14:14:01+00:00", + "git": "4b53e03", "params": { "mode": "proxy", "size_bytes": 1048576, "concurrency": 10, "uploads_per_worker": 5, - "repeat": 3 + "repeat": 3, + "users": 10, + "image": null }, "host": { "nproc": 8, "mem_total_bytes": 16538955776 }, "api_container_limits_nanocpus_memory": [ - "1500000000 805306368", - "1500000000 805306368" + "1500000000 1073741824", + "1500000000 1073741824" ], "repeats": [ { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.885, + "duration_s": 0.392, "latency_ms": { - "p50": 156.2, - "p95": 207.1, - "p99": 235.1 + "p50": 56.0, + "p95": 100.2, + "p99": 108.3 }, "replicas": [ { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 26389500, - "delta_tx_bytes": 26402061, - "baseline_rss_bytes": 231522304, + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 26387282, + "delta_tx_bytes": 26396329, + "baseline_rss_bytes": 167575552, "peak_memory_bytes": { - "rss": 231522304, - "heap_used": 52773312, - "external": 23343330, - "array_buffers": 19552986 + "rss": 180232192, + "heap_used": 54305016, + "external": 22415054, + "array_buffers": 18606583 }, - "delta_rss_bytes": 0, + "delta_rss_bytes": 12656640, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, - "attachments.decode.ms": 1601.4592339998344, + "attachments.decode.ms": 161.38972300002933, "attachments.proxy.bytes_to_s3": 26214400, "attachments.mark_ready": 25, "attachments.upload.created": 25 } }, { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 26384219, - "delta_tx_bytes": 26403431, - "baseline_rss_bytes": 264105984, + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 26380621, + "delta_tx_bytes": 26397967, + "baseline_rss_bytes": 164233216, "peak_memory_bytes": { - "rss": 266989568, - "heap_used": 49942048, - "external": 24835619, - "array_buffers": 18813186 + "rss": 182816768, + "heap_used": 55081640, + "external": 25150489, + "array_buffers": 21337451 }, - "delta_rss_bytes": 2883584, + "delta_rss_bytes": 18583552, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, - "attachments.decode.ms": 1562.9852019998943, + "attachments.decode.ms": 153.55793299997458, "attachments.proxy.bytes_to_s3": 26214400, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 52773719, - "total_delta_tx_bytes": 52805492, - "rx_bytes_per_upload": 1055474, - "tx_bytes_per_upload": 1056110, - "max_delta_rss_bytes": 2883584 + "total_delta_rx_bytes": 52767903, + "total_delta_tx_bytes": 52794296, + "rx_bytes_per_upload": 1055358, + "tx_bytes_per_upload": 1055886, + "max_delta_rss_bytes": 18583552 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.771, + "duration_s": 0.44, "latency_ms": { - "p50": 131.9, - "p95": 174.7, - "p99": 175.6 + "p50": 57.0, + "p95": 123.6, + "p99": 164.4 }, "replicas": [ { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 26384709, - "delta_tx_bytes": 26401945, - "baseline_rss_bytes": 231522304, + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 26400102, + "delta_tx_bytes": 26408679, + "baseline_rss_bytes": 180232192, "peak_memory_bytes": { - "rss": 233619456, - "heap_used": 51880616, - "external": 32630526, - "array_buffers": 26533593 + "rss": 186654720, + "heap_used": 52146632, + "external": 28489237, + "array_buffers": 24678454 }, - "delta_rss_bytes": 2097152, + "delta_rss_bytes": 6422528, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, - "attachments.decode.ms": 1264.4056559997844, + "attachments.decode.ms": 200.20289300006698, "attachments.proxy.bytes_to_s3": 26214400, "attachments.mark_ready": 25, "attachments.upload.created": 25 } }, { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 26376275, - "delta_tx_bytes": 26401865, - "baseline_rss_bytes": 266989568, + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 26378813, + "delta_tx_bytes": 26400238, + "baseline_rss_bytes": 182816768, "peak_memory_bytes": { - "rss": 266989568, - "heap_used": 50529400, - "external": 26599488, - "array_buffers": 22809144 + "rss": 191991808, + "heap_used": 53527584, + "external": 35009900, + "array_buffers": 31190059 }, - "delta_rss_bytes": 0, + "delta_rss_bytes": 9175040, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, - "attachments.decode.ms": 1410.3865230001393, + "attachments.decode.ms": 137.82972499995958, "attachments.proxy.bytes_to_s3": 26214400, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 52760984, - "total_delta_tx_bytes": 52803810, - "rx_bytes_per_upload": 1055220, - "tx_bytes_per_upload": 1056076, - "max_delta_rss_bytes": 2097152 + "total_delta_rx_bytes": 52778915, + "total_delta_tx_bytes": 52808917, + "rx_bytes_per_upload": 1055578, + "tx_bytes_per_upload": 1056178, + "max_delta_rss_bytes": 9175040 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.792, + "duration_s": 0.37, "latency_ms": { - "p50": 126.4, - "p95": 182.7, - "p99": 191.3 + "p50": 46.4, + "p95": 81.6, + "p99": 99.1 }, "replicas": [ { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 26385221, - "delta_tx_bytes": 26404709, - "baseline_rss_bytes": 233619456, + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 26383217, + "delta_tx_bytes": 26399979, + "baseline_rss_bytes": 181960704, "peak_memory_bytes": { - "rss": 233619456, - "heap_used": 51420296, - "external": 29512306, - "array_buffers": 25721962 + "rss": 188776448, + "heap_used": 52208392, + "external": 28664130, + "array_buffers": 24846506 }, - "delta_rss_bytes": 0, + "delta_rss_bytes": 6815744, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, - "attachments.decode.ms": 1199.6556880001444, + "attachments.decode.ms": 139.54196999999112, "attachments.proxy.bytes_to_s3": 26214400, "attachments.mark_ready": 25, "attachments.upload.created": 25 } }, { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 26378117, - "delta_tx_bytes": 26400049, - "baseline_rss_bytes": 266989568, + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 26394762, + "delta_tx_bytes": 26403375, + "baseline_rss_bytes": 179302400, "peak_memory_bytes": { - "rss": 267907072, - "heap_used": 51921864, - "external": 30362031, - "array_buffers": 26571687 + "rss": 184086528, + "heap_used": 50413992, + "external": 24938566, + "array_buffers": 21130086 }, - "delta_rss_bytes": 917504, + "delta_rss_bytes": 4784128, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, - "attachments.decode.ms": 1393.8144420000026, + "attachments.decode.ms": 202.13070199999493, "attachments.proxy.bytes_to_s3": 26214400, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 52763338, - "total_delta_tx_bytes": 52804758, - "rx_bytes_per_upload": 1055267, - "tx_bytes_per_upload": 1056095, - "max_delta_rss_bytes": 917504 + "total_delta_rx_bytes": 52777979, + "total_delta_tx_bytes": 52803354, + "rx_bytes_per_upload": 1055560, + "tx_bytes_per_upload": 1056067, + "max_delta_rss_bytes": 6815744 } ] } diff --git a/evidence/lab4/bench/proxy-131072-c10.json b/evidence/lab4/bench/proxy-131072-c10.json index 7cabee16..e8d40dff 100644 --- a/evidence/lab4/bench/proxy-131072-c10.json +++ b/evidence/lab4/bench/proxy-131072-c10.json @@ -1,201 +1,203 @@ { - "date": "2026-10-23T13:37:18+00:00", - "git": "4badd5a", + "date": "2026-10-23T14:13:50+00:00", + "git": "4b53e03", "params": { "mode": "proxy", "size_bytes": 131072, "concurrency": 10, "uploads_per_worker": 5, - "repeat": 3 + "repeat": 3, + "users": 10, + "image": null }, "host": { "nproc": 8, "mem_total_bytes": 16538955776 }, "api_container_limits_nanocpus_memory": [ - "1500000000 805306368", - "1500000000 805306368" + "1500000000 1073741824", + "1500000000 1073741824" ], "repeats": [ { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.331, + "duration_s": 0.166, "latency_ms": { - "p50": 57.2, - "p95": 80.6, - "p99": 88.9 + "p50": 26.0, + "p95": 43.4, + "p99": 53.2 }, "replicas": [ { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 3385418, - "delta_tx_bytes": 3400077, - "baseline_rss_bytes": 218017792, + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 3383029, + "delta_tx_bytes": 3398057, + "baseline_rss_bytes": 140619776, "peak_memory_bytes": { - "rss": 220377088, - "heap_used": 50283096, - "external": 8478293, - "array_buffers": 4687725 + "rss": 149794816, + "heap_used": 51367680, + "external": 8055768, + "array_buffers": 4261819 }, - "delta_rss_bytes": 2359296, + "delta_rss_bytes": 9175040, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, - "attachments.decode.ms": 575.8783200000762, + "attachments.decode.ms": 83.07460599998012, "attachments.proxy.bytes_to_s3": 3276800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } }, { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 3385072, - "delta_tx_bytes": 3399873, - "baseline_rss_bytes": 249233408, + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 3381990, + "delta_tx_bytes": 3399067, + "baseline_rss_bytes": 139079680, "peak_memory_bytes": { - "rss": 252379136, - "heap_used": 50306832, - "external": 9099311, - "array_buffers": 5308711 + "rss": 148328448, + "heap_used": 51262864, + "external": 7893259, + "array_buffers": 4099697 }, - "delta_rss_bytes": 3145728, + "delta_rss_bytes": 9248768, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, - "attachments.decode.ms": 590.1611679997877, + "attachments.decode.ms": 89.15959899991867, "attachments.proxy.bytes_to_s3": 3276800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 6770490, - "total_delta_tx_bytes": 6799950, - "rx_bytes_per_upload": 135410, - "tx_bytes_per_upload": 135999, - "max_delta_rss_bytes": 3145728 + "total_delta_rx_bytes": 6765019, + "total_delta_tx_bytes": 6797124, + "rx_bytes_per_upload": 135300, + "tx_bytes_per_upload": 135942, + "max_delta_rss_bytes": 9248768 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.316, + "duration_s": 0.173, "latency_ms": { - "p50": 55.2, - "p95": 87.2, - "p99": 99.2 + "p50": 27.7, + "p95": 49.1, + "p99": 49.5 }, "replicas": [ { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 3376247, - "delta_tx_bytes": 3395251, - "baseline_rss_bytes": 220508160, + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 3377379, + "delta_tx_bytes": 3394793, + "baseline_rss_bytes": 149794816, "peak_memory_bytes": { - "rss": 223653888, - "heap_used": 50422968, - "external": 8537602, - "array_buffers": 4747258 - }, - "delta_rss_bytes": 3145728, - "counters": { - "attachments.insert_pending": 25, - "attachments.proxy.bytes_in": 3276800, - "attachments.decode.ms": 568.8078680001199, - "attachments.proxy.bytes_to_s3": 3276800, - "attachments.mark_ready": 25, - "attachments.upload.created": 25 - } - }, - { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 3378432, - "delta_tx_bytes": 3395587, - "baseline_rss_bytes": 252379136, - "peak_memory_bytes": { - "rss": 255524864, - "heap_used": 49969448, - "external": 10496847, - "array_buffers": 6706503 - }, - "delta_rss_bytes": 3145728, - "counters": { - "attachments.insert_pending": 25, - "attachments.proxy.bytes_in": 3276800, - "attachments.decode.ms": 575.633941000211, - "attachments.proxy.bytes_to_s3": 3276800, - "attachments.mark_ready": 25, - "attachments.upload.created": 25 - } - } - ], - "total_delta_rx_bytes": 6754679, - "total_delta_tx_bytes": 6790838, - "rx_bytes_per_upload": 135094, - "tx_bytes_per_upload": 135817, - "max_delta_rss_bytes": 3145728 - }, - { - "uploads": 50, - "succeeded": 50, - "failed": 0, - "duration_s": 0.364, - "latency_ms": { - "p50": 61.0, - "p95": 100.6, - "p99": 109.1 - }, - "replicas": [ - { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 3377231, - "delta_tx_bytes": 3396261, - "baseline_rss_bytes": 223653888, - "peak_memory_bytes": { - "rss": 224178176, - "heap_used": 50203952, - "external": 12043208, - "array_buffers": 8243836 - }, - "delta_rss_bytes": 524288, - "counters": { - "attachments.insert_pending": 25, - "attachments.proxy.bytes_in": 3276800, - "attachments.decode.ms": 554.1256450000219, - "attachments.proxy.bytes_to_s3": 3276800, - "attachments.mark_ready": 25, - "attachments.upload.created": 25 - } - }, - { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 3376327, - "delta_tx_bytes": 3397971, - "baseline_rss_bytes": 255524864, - "peak_memory_bytes": { - "rss": 255655936, - "heap_used": 50414024, - "external": 11828788, - "array_buffers": 8038444 + "rss": 149925888, + "heap_used": 50693344, + "external": 7902800, + "array_buffers": 4109077 }, "delta_rss_bytes": 131072, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, - "attachments.decode.ms": 655.3769140000804, + "attachments.decode.ms": 85.17745499999728, + "attachments.proxy.bytes_to_s3": 3276800, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 + } + }, + { + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 3377406, + "delta_tx_bytes": 3395327, + "baseline_rss_bytes": 148328448, + "peak_memory_bytes": { + "rss": 149770240, + "heap_used": 51549096, + "external": 8924915, + "array_buffers": 4317559 + }, + "delta_rss_bytes": 1441792, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 3276800, + "attachments.decode.ms": 96.18780900008278, "attachments.proxy.bytes_to_s3": 3276800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 6753558, - "total_delta_tx_bytes": 6794232, - "rx_bytes_per_upload": 135071, - "tx_bytes_per_upload": 135885, - "max_delta_rss_bytes": 524288 + "total_delta_rx_bytes": 6754785, + "total_delta_tx_bytes": 6790120, + "rx_bytes_per_upload": 135096, + "tx_bytes_per_upload": 135802, + "max_delta_rss_bytes": 1441792 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "duration_s": 0.206, + "latency_ms": { + "p50": 33.9, + "p95": 57.9, + "p99": 66.3 + }, + "replicas": [ + { + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 3376104, + "delta_tx_bytes": 3395515, + "baseline_rss_bytes": 149925888, + "peak_memory_bytes": { + "rss": 156610560, + "heap_used": 52936520, + "external": 10702533, + "array_buffers": 6907528 + }, + "delta_rss_bytes": 6684672, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 3276800, + "attachments.decode.ms": 92.25257400004193, + "attachments.proxy.bytes_to_s3": 3276800, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 + } + }, + { + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 3375521, + "delta_tx_bytes": 3395653, + "baseline_rss_bytes": 149770240, + "peak_memory_bytes": { + "rss": 155930624, + "heap_used": 52559728, + "external": 11541159, + "array_buffers": 7744900 + }, + "delta_rss_bytes": 6160384, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 3276800, + "attachments.decode.ms": 134.16439100005664, + "attachments.proxy.bytes_to_s3": 3276800, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 + } + } + ], + "total_delta_rx_bytes": 6751625, + "total_delta_tx_bytes": 6791168, + "rx_bytes_per_upload": 135032, + "tx_bytes_per_upload": 135823, + "max_delta_rss_bytes": 6684672 } ] } diff --git a/evidence/lab4/bench/proxy-9961472-c10.json b/evidence/lab4/bench/proxy-9961472-c10.json index da8a1462..71871734 100644 --- a/evidence/lab4/bench/proxy-9961472-c10.json +++ b/evidence/lab4/bench/proxy-9961472-c10.json @@ -1,201 +1,205 @@ { - "date": "2026-10-23T13:37:55+00:00", - "git": "4badd5a", + "date": "2026-10-23T14:14:21+00:00", + "git": "4b53e03", "params": { "mode": "proxy", "size_bytes": 9961472, "concurrency": 10, "uploads_per_worker": 5, - "repeat": 3 + "repeat": 3, + "users": 10, + "image": null }, "host": { "nproc": 8, "mem_total_bytes": 16538955776 }, "api_container_limits_nanocpus_memory": [ - "1500000000 805306368", - "1500000000 805306368" + "1500000000 1073741824", + "1500000000 1073741824" ], "repeats": [ { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 4.75, + "duration_s": 2.855, "latency_ms": { - "p50": 586.5, - "p95": 851.2, - "p99": 924.0 + "p50": 254.6, + "p95": 441.6, + "p99": 469.3 }, "replicas": [ { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 249636366, - "delta_tx_bytes": 249800729, - "baseline_rss_bytes": 242110464, + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 249684122, + "delta_tx_bytes": 249819648, + "baseline_rss_bytes": 194351104, "peak_memory_bytes": { - "rss": 302125056, - "heap_used": 50330056, - "external": 79829666, - "array_buffers": 76039322 + "rss": 243703808, + "heap_used": 49360872, + "external": 68770063, + "array_buffers": 64974750 }, - "delta_rss_bytes": 60014592, + "delta_rss_bytes": 49352704, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, - "attachments.decode.ms": 7776.616332000063, + "attachments.decode.ms": 317.76610400003847, "attachments.proxy.bytes_to_s3": 249036800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } }, { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 249671660, - "delta_tx_bytes": 249815904, - "baseline_rss_bytes": 279318528, + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 249687515, + "delta_tx_bytes": 249813144, + "baseline_rss_bytes": 212090880, "peak_memory_bytes": { - "rss": 335978496, - "heap_used": 50779240, - "external": 99370165, - "array_buffers": 91157282 + "rss": 245616640, + "heap_used": 49395480, + "external": 62511358, + "array_buffers": 58716046 }, - "delta_rss_bytes": 56659968, + "delta_rss_bytes": 33525760, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, - "attachments.decode.ms": 7460.193873999873, + "attachments.decode.ms": 328.639833000052, "attachments.proxy.bytes_to_s3": 249036800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 499308026, - "total_delta_tx_bytes": 499616633, - "rx_bytes_per_upload": 9986161, - "tx_bytes_per_upload": 9992333, - "max_delta_rss_bytes": 60014592 + "total_delta_rx_bytes": 499371637, + "total_delta_tx_bytes": 499632792, + "rx_bytes_per_upload": 9987433, + "tx_bytes_per_upload": 9992656, + "max_delta_rss_bytes": 49352704 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 4.661, + "duration_s": 2.859, "latency_ms": { - "p50": 656.5, - "p95": 888.8, - "p99": 959.9 + "p50": 218.9, + "p95": 429.5, + "p99": 473.5 }, "replicas": [ { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 249639519, - "delta_tx_bytes": 249795892, - "baseline_rss_bytes": 281255936, + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 249691287, + "delta_tx_bytes": 249848369, + "baseline_rss_bytes": 243703808, "peak_memory_bytes": { - "rss": 326279168, - "heap_used": 49159264, - "external": 96056449, - "array_buffers": 80803439 + "rss": 247758848, + "heap_used": 49779768, + "external": 74267235, + "array_buffers": 70471924 }, - "delta_rss_bytes": 45023232, + "delta_rss_bytes": 4055040, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, - "attachments.decode.ms": 7871.141386000323, + "attachments.decode.ms": 323.61892599996645, "attachments.proxy.bytes_to_s3": 249036800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } }, { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 249675448, - "delta_tx_bytes": 249820400, - "baseline_rss_bytes": 305864704, + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 249684697, + "delta_tx_bytes": 249842962, + "baseline_rss_bytes": 204165120, "peak_memory_bytes": { - "rss": 325267456, - "heap_used": 49459520, - "external": 94883105, - "array_buffers": 91092761 + "rss": 244056064, + "heap_used": 50327648, + "external": 69652092, + "array_buffers": 65858420 }, - "delta_rss_bytes": 19402752, + "delta_rss_bytes": 39890944, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, - "attachments.decode.ms": 7501.386025000014, + "attachments.decode.ms": 374.5309960000159, "attachments.proxy.bytes_to_s3": 249036800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 499314967, - "total_delta_tx_bytes": 499616292, - "rx_bytes_per_upload": 9986299, - "tx_bytes_per_upload": 9992326, - "max_delta_rss_bytes": 45023232 + "total_delta_rx_bytes": 499375984, + "total_delta_tx_bytes": 499691331, + "rx_bytes_per_upload": 9987520, + "tx_bytes_per_upload": 9993827, + "max_delta_rss_bytes": 39890944 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 4.725, + "duration_s": 2.833, "latency_ms": { - "p50": 642.3, - "p95": 1021.8, - "p99": 1063.9 + "p50": 232.3, + "p95": 371.9, + "p99": 484.0 }, "replicas": [ { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 249673539, - "delta_tx_bytes": 249815151, - "baseline_rss_bytes": 301092864, + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 249693755, + "delta_tx_bytes": 249824387, + "baseline_rss_bytes": 213168128, "peak_memory_bytes": { - "rss": 327974912, - "heap_used": 49201912, - "external": 94750424, - "array_buffers": 90960080 + "rss": 233091072, + "heap_used": 49724808, + "external": 74286513, + "array_buffers": 58931141 }, - "delta_rss_bytes": 26882048, + "delta_rss_bytes": 19922944, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, - "attachments.decode.ms": 7622.966706999927, + "attachments.decode.ms": 245.89502999989782, "attachments.proxy.bytes_to_s3": 249036800, "attachments.mark_ready": 25, - "attachments.upload.created": 25 + "attachments.upload.created": 25, + "attachments.claim_expired": 1 } }, { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 249648565, - "delta_tx_bytes": 249815222, - "baseline_rss_bytes": 296456192, + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 249643327, + "delta_tx_bytes": 249823027, + "baseline_rss_bytes": 214241280, "peak_memory_bytes": { - "rss": 307523584, - "heap_used": 50677504, - "external": 85057449, - "array_buffers": 81100125 + "rss": 245899264, + "heap_used": 50003816, + "external": 74661871, + "array_buffers": 52933830 }, - "delta_rss_bytes": 11067392, + "delta_rss_bytes": 31657984, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, - "attachments.decode.ms": 7061.106053000025, + "attachments.decode.ms": 375.14921199998935, "attachments.proxy.bytes_to_s3": 249036800, "attachments.mark_ready": 25, - "attachments.upload.created": 25 + "attachments.upload.created": 25, + "attachments.claim_expired": 1 } } ], - "total_delta_rx_bytes": 499322104, - "total_delta_tx_bytes": 499630373, - "rx_bytes_per_upload": 9986442, - "tx_bytes_per_upload": 9992607, - "max_delta_rss_bytes": 26882048 + "total_delta_rx_bytes": 499337082, + "total_delta_tx_bytes": 499647414, + "rx_bytes_per_upload": 9986742, + "tx_bytes_per_upload": 9992948, + "max_delta_rss_bytes": 31657984 } ] } diff --git a/evidence/lab4/bench/proxy-9961472-c20.json b/evidence/lab4/bench/proxy-9961472-c20.json index aa8e9774..d21da563 100644 --- a/evidence/lab4/bench/proxy-9961472-c20.json +++ b/evidence/lab4/bench/proxy-9961472-c20.json @@ -1,203 +1,203 @@ { - "date": "2026-10-23T13:38:46+00:00", - "git": "4badd5a", + "date": "2026-10-23T14:15:00+00:00", + "git": "4b53e03", "params": { "mode": "proxy", "size_bytes": 9961472, "concurrency": 20, "uploads_per_worker": 5, - "repeat": 3 + "repeat": 3, + "users": 20, + "image": null }, "host": { "nproc": 8, "mem_total_bytes": 16538955776 }, "api_container_limits_nanocpus_memory": [ - "1500000000 805306368", - "1500000000 805306368" + "1500000000 1073741824", + "1500000000 1073741824" ], "repeats": [ { "uploads": 100, "succeeded": 100, "failed": 0, - "duration_s": 8.833, + "duration_s": 5.725, "latency_ms": { - "p50": 1330.2, - "p95": 1656.1, - "p99": 1727.7 + "p50": 386.4, + "p95": 694.0, + "p99": 1065.1 }, "replicas": [ { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 499759117, - "delta_tx_bytes": 499989656, - "baseline_rss_bytes": 261660672, + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 499431062, + "delta_tx_bytes": 499720016, + "baseline_rss_bytes": 219865088, "peak_memory_bytes": { - "rss": 388141056, - "heap_used": 50630264, - "external": 155166578, - "array_buffers": 139745634 + "rss": 256589824, + "heap_used": 50949776, + "external": 78382688, + "array_buffers": 74585512 }, - "delta_rss_bytes": 126480384, + "delta_rss_bytes": 36724736, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, - "attachments.decode.ms": 15729.830076000188, + "attachments.decode.ms": 752.4353919999558, "attachments.proxy.bytes_to_s3": 498073600, "attachments.mark_ready": 50, "attachments.upload.created": 50 } }, { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 499883600, - "delta_tx_bytes": 500123779, - "baseline_rss_bytes": 292487168, + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 499402749, + "delta_tx_bytes": 499684515, + "baseline_rss_bytes": 205688832, "peak_memory_bytes": { - "rss": 393953280, - "heap_used": 51133536, - "external": 142116265, - "array_buffers": 138325921 + "rss": 253865984, + "heap_used": 50007064, + "external": 77441306, + "array_buffers": 73644321 }, - "delta_rss_bytes": 101466112, + "delta_rss_bytes": 48177152, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, - "attachments.decode.ms": 15020.501326000027, + "attachments.decode.ms": 689.5382070000051, "attachments.proxy.bytes_to_s3": 498073600, "attachments.mark_ready": 50, "attachments.upload.created": 50 } } ], - "total_delta_rx_bytes": 999642717, - "total_delta_tx_bytes": 1000113435, - "rx_bytes_per_upload": 9996427, - "tx_bytes_per_upload": 10001134, - "max_delta_rss_bytes": 126480384 + "total_delta_rx_bytes": 998833811, + "total_delta_tx_bytes": 999404531, + "rx_bytes_per_upload": 9988338, + "tx_bytes_per_upload": 9994045, + "max_delta_rss_bytes": 48177152 }, { "uploads": 100, "succeeded": 100, "failed": 0, - "duration_s": 8.864, + "duration_s": 5.595, "latency_ms": { - "p50": 1336.0, - "p95": 1742.8, - "p99": 1799.2 + "p50": 416.1, + "p95": 850.5, + "p99": 1043.3 }, "replicas": [ { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 499464722, - "delta_tx_bytes": 499742563, - "baseline_rss_bytes": 380321792, + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 499433153, + "delta_tx_bytes": 499703916, + "baseline_rss_bytes": 232402944, "peak_memory_bytes": { - "rss": 402067456, - "heap_used": 50852712, - "external": 145616176, - "array_buffers": 130815545 + "rss": 259272704, + "heap_used": 51280096, + "external": 72760119, + "array_buffers": 68966438 }, - "delta_rss_bytes": 21745664, + "delta_rss_bytes": 26869760, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, - "attachments.decode.ms": 15730.587417000032, + "attachments.decode.ms": 696.6430249999976, "attachments.proxy.bytes_to_s3": 498073600, "attachments.mark_ready": 50, - "attachments.upload.created": 50, - "attachments.claim_expired": 1 + "attachments.upload.created": 50 } }, { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 499665326, - "delta_tx_bytes": 499906835, - "baseline_rss_bytes": 365027328, + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 499356462, + "delta_tx_bytes": 499635353, + "baseline_rss_bytes": 218791936, "peak_memory_bytes": { - "rss": 393994240, - "heap_used": 50916312, - "external": 127865497, - "array_buffers": 124075153 + "rss": 269750272, + "heap_used": 50527976, + "external": 84610578, + "array_buffers": 80809839 }, - "delta_rss_bytes": 28966912, + "delta_rss_bytes": 50958336, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, - "attachments.decode.ms": 16026.04880199983, + "attachments.decode.ms": 679.306210000097, "attachments.proxy.bytes_to_s3": 498073600, "attachments.mark_ready": 50, - "attachments.upload.created": 50, - "attachments.claim_expired": 1 + "attachments.upload.created": 50 } } ], - "total_delta_rx_bytes": 999130048, - "total_delta_tx_bytes": 999649398, - "rx_bytes_per_upload": 9991300, - "tx_bytes_per_upload": 9996494, - "max_delta_rss_bytes": 28966912 + "total_delta_rx_bytes": 998789615, + "total_delta_tx_bytes": 999339269, + "rx_bytes_per_upload": 9987896, + "tx_bytes_per_upload": 9993393, + "max_delta_rss_bytes": 50958336 }, { "uploads": 100, "succeeded": 100, "failed": 0, - "duration_s": 9.064, + "duration_s": 5.614, "latency_ms": { - "p50": 1457.1, - "p95": 1774.1, - "p99": 1926.1 + "p50": 428.0, + "p95": 804.7, + "p99": 1004.9 }, "replicas": [ { - "instance_id": "7c7cf67931e5", - "delta_rx_bytes": 499401262, - "delta_tx_bytes": 499684797, - "baseline_rss_bytes": 357986304, + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 499425024, + "delta_tx_bytes": 499698391, + "baseline_rss_bytes": 229511168, "peak_memory_bytes": { - "rss": 410398720, - "heap_used": 50734960, - "external": 146163060, - "array_buffers": 132312269 + "rss": 276029440, + "heap_used": 50966520, + "external": 81342826, + "array_buffers": 77549156 }, - "delta_rss_bytes": 52412416, + "delta_rss_bytes": 46518272, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, - "attachments.decode.ms": 16195.981729999883, + "attachments.decode.ms": 690.9916989999474, "attachments.proxy.bytes_to_s3": 498073600, "attachments.mark_ready": 50, "attachments.upload.created": 50 } }, { - "instance_id": "ff9a363e52b1", - "delta_rx_bytes": 499729379, - "delta_tx_bytes": 499980797, - "baseline_rss_bytes": 355852288, + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 499340690, + "delta_tx_bytes": 499623342, + "baseline_rss_bytes": 209854464, "peak_memory_bytes": { - "rss": 408215552, - "heap_used": 50802144, - "external": 136256487, - "array_buffers": 132466143 + "rss": 269647872, + "heap_used": 50830664, + "external": 84194138, + "array_buffers": 71282017 }, - "delta_rss_bytes": 52363264, + "delta_rss_bytes": 59793408, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, - "attachments.decode.ms": 16008.327908000094, + "attachments.decode.ms": 772.5123690000619, "attachments.proxy.bytes_to_s3": 498073600, "attachments.mark_ready": 50, "attachments.upload.created": 50 } } ], - "total_delta_rx_bytes": 999130641, - "total_delta_tx_bytes": 999665594, - "rx_bytes_per_upload": 9991306, - "tx_bytes_per_upload": 9996656, - "max_delta_rss_bytes": 52412416 + "total_delta_rx_bytes": 998765714, + "total_delta_tx_bytes": 999321733, + "rx_bytes_per_upload": 9987657, + "tx_bytes_per_upload": 9993217, + "max_delta_rss_bytes": 59793408 } ] } diff --git a/evidence/lab4/bench/proxy-worst-c32.json b/evidence/lab4/bench/proxy-worst-c32.json new file mode 100644 index 00000000..baf34847 --- /dev/null +++ b/evidence/lab4/bench/proxy-worst-c32.json @@ -0,0 +1,207 @@ +{ + "date": "2026-10-23T14:16:28+00:00", + "git": "4b53e03", + "params": { + "mode": "proxy", + "size_bytes": 10485760, + "concurrency": 32, + "uploads_per_worker": 2, + "repeat": 3, + "users": 32, + "image": "tmp.n0I8NPEIWj.png" + }, + "host": { + "nproc": 8, + "mem_total_bytes": 16538955776 + }, + "api_container_limits_nanocpus_memory": [ + "1500000000 1073741824", + "1500000000 1073741824" + ], + "repeats": [ + { + "uploads": 64, + "succeeded": 63, + "failed": 1, + "duration_s": 25.819, + "latency_ms": { + "p50": 11818.4, + "p95": 12931.4, + "p99": 13553.9 + }, + "replicas": [ + { + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 337133327, + "delta_tx_bytes": 326730589, + "baseline_rss_bytes": 242167808, + "peak_memory_bytes": { + "rss": 764227584, + "heap_used": 53277928, + "external": 205747809, + "array_buffers": 201957465 + }, + "delta_rss_bytes": 522059776, + "counters": { + "attachments.insert_pending": 31, + "attachments.proxy.bytes_in": 325058560, + "attachments.decode.ms": 25036.73668600002, + "attachments.proxy.bytes_to_s3": 325058560, + "attachments.mark_ready": 31, + "attachments.upload.created": 31, + "attachments.claim_expired": 1 + } + }, + { + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 337211779, + "delta_tx_bytes": 337283965, + "baseline_rss_bytes": 228610048, + "peak_memory_bytes": { + "rss": 778199040, + "heap_used": 51989272, + "external": 236791924, + "array_buffers": 233001507 + }, + "delta_rss_bytes": 549588992, + "counters": { + "attachments.insert_pending": 32, + "attachments.proxy.bytes_in": 335544320, + "attachments.decode.ms": 25586.631086000038, + "attachments.proxy.bytes_to_s3": 335544320, + "attachments.mark_ready": 32, + "attachments.upload.created": 32, + "attachments.claim_expired": 1 + } + } + ], + "total_delta_rx_bytes": 674345106, + "total_delta_tx_bytes": 664014554, + "rx_bytes_per_upload": 10536642, + "tx_bytes_per_upload": 10375227, + "max_delta_rss_bytes": 549588992 + }, + { + "uploads": 64, + "succeeded": 63, + "failed": 1, + "duration_s": 25.757, + "latency_ms": { + "p50": 11572.1, + "p95": 12715.5, + "p99": 13392.7 + }, + "replicas": [ + { + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 334592209, + "delta_tx_bytes": 326276198, + "baseline_rss_bytes": 398258176, + "peak_memory_bytes": { + "rss": 783015936, + "heap_used": 55518080, + "external": 207730225, + "array_buffers": 203939881 + }, + "delta_rss_bytes": 384757760, + "counters": { + "attachments.insert_pending": 31, + "attachments.proxy.bytes_in": 325058560, + "attachments.decode.ms": 24831.425972000143, + "attachments.proxy.bytes_to_s3": 325058560, + "attachments.mark_ready": 31, + "attachments.upload.created": 31 + } + }, + { + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 336487647, + "delta_tx_bytes": 336637754, + "baseline_rss_bytes": 402874368, + "peak_memory_bytes": { + "rss": 798023680, + "heap_used": 53729504, + "external": 238180613, + "array_buffers": 234390237 + }, + "delta_rss_bytes": 395149312, + "counters": { + "attachments.insert_pending": 32, + "attachments.proxy.bytes_in": 335544320, + "attachments.decode.ms": 25634.232347999874, + "attachments.proxy.bytes_to_s3": 335544320, + "attachments.mark_ready": 32, + "attachments.upload.created": 32 + } + } + ], + "total_delta_rx_bytes": 671079856, + "total_delta_tx_bytes": 662913952, + "rx_bytes_per_upload": 10485623, + "tx_bytes_per_upload": 10358030, + "max_delta_rss_bytes": 395149312 + }, + { + "uploads": 64, + "succeeded": 63, + "failed": 1, + "duration_s": 25.464, + "latency_ms": { + "p50": 11705.5, + "p95": 12780.4, + "p99": 13430.4 + }, + "replicas": [ + { + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 336576208, + "delta_tx_bytes": 326212836, + "baseline_rss_bytes": 429645824, + "peak_memory_bytes": { + "rss": 788910080, + "heap_used": 51970176, + "external": 237910954, + "array_buffers": 234120537 + }, + "delta_rss_bytes": 359264256, + "counters": { + "attachments.insert_pending": 31, + "attachments.proxy.bytes_in": 325058560, + "attachments.decode.ms": 24706.14007100009, + "attachments.proxy.bytes_to_s3": 325058560, + "attachments.mark_ready": 31, + "attachments.upload.created": 31, + "attachments.claim_expired": 1 + } + }, + { + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 336605411, + "delta_tx_bytes": 336677870, + "baseline_rss_bytes": 444702720, + "peak_memory_bytes": { + "rss": 810758144, + "heap_used": 54356496, + "external": 217451321, + "array_buffers": 213660977 + }, + "delta_rss_bytes": 366055424, + "counters": { + "attachments.insert_pending": 32, + "attachments.proxy.bytes_in": 335544320, + "attachments.decode.ms": 25312.452498999774, + "attachments.proxy.bytes_to_s3": 335544320, + "attachments.mark_ready": 32, + "attachments.upload.created": 32, + "attachments.claim_expired": 1 + } + } + ], + "total_delta_rx_bytes": 673181619, + "total_delta_tx_bytes": 662890706, + "rx_bytes_per_upload": 10518463, + "tx_bytes_per_upload": 10357667, + "max_delta_rss_bytes": 366055424 + } + ] +} diff --git a/evidence/lab4/decode-memory.txt b/evidence/lab4/decode-memory.txt index 6a6bbf24..9bf773dc 100644 --- a/evidence/lab4/decode-memory.txt +++ b/evidence/lab4/decode-memory.txt @@ -1,7 +1,8 @@ -# container /mtusi-lab4-api-1, limits: 805306368 bytes, VIPS_DISC_THRESHOLD=1g; commit a06471a+worktree -jpeg 7728x5152 3ch uchar bytes=4921012 decode_ms=58 peak_delta_rss_mib=3.9 ok -jpeg 7728x5152 3ch uchar progressive bytes=4826968 decode_ms=278 peak_delta_rss_mib=117.7 ok -jpeg 7728x5152 4ch uchar bytes=10601868 decode_ms=161 peak_delta_rss_mib=7.7 ok -png 8000x5000 4ch ushort bytes=1420114 decode_ms=496 peak_delta_rss_mib=66.6 ok -png 8000x5000 4ch ushort progressive bytes=364096 decode_ms=1270 peak_delta_rss_mib=338.6 ok -png 8000x5000 3ch uchar progressive palette bytes=61042 decode_ms=341 peak_delta_rss_mib=126.0 ok +# container /mtusi-lab4-api-1, memory limit 1073741824 bytes, VIPS_DISC_THRESHOLD=1g, commit 4b53e03; same pipeline as ImageDecoder +jpeg 7728x5152 3ch uchar bytes=4921012 decode_ms=61 peak_delta_rss_mib=4.5 ok +jpeg 7728x5152 3ch uchar progressive bytes=4826968 decode_ms=273 peak_delta_rss_mib=118.1 ok +jpeg 7728x5152 4ch uchar bytes=10601868 decode_ms=159 peak_delta_rss_mib=7.5 ok +png 8000x5000 4ch ushort bytes=1420114 decode_ms=524 peak_delta_rss_mib=67.1 ok +png 8000x5000 4ch ushort progressive bytes=364096 decode_ms=1231 peak_delta_rss_mib=338.5 ok +png 8000x5000 3ch uchar progressive palette bytes=61042 decode_ms=356 peak_delta_rss_mib=126.0 ok +png 8000x5000 4ch ushort progressive bytes=10485760 decode_ms=707 peak_delta_rss_mib=338.4 ok diff --git a/evidence/lab4/direct-ttl-short.txt b/evidence/lab4/direct-ttl-short.txt index 2f063108..f9028aea 100644 --- a/evidence/lab4/direct-ttl-short.txt +++ b/evidence/lab4/direct-ttl-short.txt @@ -3,6 +3,6 @@ The plugin "vite-tsconfig-paths" is detected. Vite now supports tsconfig paths resolution natively via the resolve.tsconfigPaths option. You can remove the plugin and set resolve.tsconfigPaths: true in your Vite config instead. RUN v4.1.11 /home/tomato/Projects/VP/mtusi2026lab4/app Test Files 1 passed (1) - Tests 9 passed (9) - Start at 16:31:20 - Duration 8.28s (transform 48ms, setup 0ms, import 72ms, tests 8.12s, environment 0ms) + Tests 10 passed (10) + Start at 17:11:07 + Duration 8.19s (transform 48ms, setup 0ms, import 72ms, tests 8.02s, environment 0ms) diff --git a/evidence/lab4/make-test-dependencies.txt b/evidence/lab4/make-test-dependencies.txt index 39008861..54050306 100644 --- a/evidence/lab4/make-test-dependencies.txt +++ b/evidence/lab4/make-test-dependencies.txt @@ -4,6 +4,6 @@ cd app && E2E_COMPOSE_DIR="/home/tomato/Projects/VP/mtusi2026lab4" E2E_COMPOSE_E The plugin "vite-tsconfig-paths" is detected. Vite now supports tsconfig paths resolution natively via the resolve.tsconfigPaths option. You can remove the plugin and set resolve.tsconfigPaths: true in your Vite config instead. RUN v4.1.11 /home/tomato/Projects/VP/mtusi2026lab4/app Test Files 1 passed (1) - Tests 6 passed (6) - Start at 16:34:39 - Duration 124.94s (transform 75ms, setup 0ms, import 94ms, tests 124.75s, environment 0ms) + Tests 7 passed (7) + Start at 17:11:25 + Duration 140.04s (transform 65ms, setup 0ms, import 80ms, tests 139.87s, environment 0ms) diff --git a/evidence/lab4/make-test-e2e.txt b/evidence/lab4/make-test-e2e.txt index bf6dd224..d7c3b7f4 100644 --- a/evidence/lab4/make-test-e2e.txt +++ b/evidence/lab4/make-test-e2e.txt @@ -3,6 +3,6 @@ The plugin "vite-tsconfig-paths" is detected. Vite now supports tsconfig paths resolution natively via the resolve.tsconfigPaths option. You can remove the plugin and set resolve.tsconfigPaths: true in your Vite config instead. RUN v4.1.11 /home/tomato/Projects/VP/mtusi2026lab4/app Test Files 3 passed | 1 skipped (4) - Tests 38 passed | 8 skipped (46) - Start at 16:39:49 - Duration 4.15s (transform 319ms, setup 0ms, import 598ms, tests 8.73s, environment 0ms) + Tests 44 passed | 9 skipped (53) + Start at 17:10:37 + Duration 6.55s (transform 310ms, setup 0ms, import 591ms, tests 12.84s, environment 0ms) diff --git a/evidence/lab4/summary.md b/evidence/lab4/summary.md index c5e16e88..679f503e 100644 --- a/evidence/lab4/summary.md +++ b/evidence/lab4/summary.md @@ -1,9 +1,11 @@ -| mode | size, MiB | C | ok | API rx/upload, MiB | API tx/upload, MiB | max Δrss, MiB | p50, ms | p95, ms | -|---|---|---|---|---|---|---|---|---| -| direct | 0.12 | 10 | 150/150 | 0.13 | 0.01 | 5.25 | 72 | 120 | -| proxy | 0.12 | 10 | 150/150 | 0.13 | 0.13 | 3.00 | 57 | 87 | -| direct | 1.00 | 10 | 150/150 | 1.01 | 0.01 | 1.38 | 154 | 252 | -| proxy | 1.00 | 10 | 150/150 | 1.01 | 1.01 | 2.00 | 132 | 183 | -| direct | 9.50 | 10 | 150/150 | 9.52 | 0.01 | 83.62 | 755 | 1018 | -| proxy | 9.50 | 10 | 150/150 | 9.52 | 9.53 | 42.94 | 642 | 889 | -| proxy | 9.50 | 20 | 300/300 | 9.53 | 9.53 | 49.98 | 1336 | 1743 | +| mode | size, MiB | C | ok | API rx/upload, MiB | API tx/upload, MiB | max Δrss, MiB | peak RSS, MiB | p50, ms | p95, ms | +|---|---|---|---|---|---|---|---|---|---| +| direct | 0.12 | 10 | 150/150 | 0.13 | 0.01 | 2.00 | 158.24 | 45 | 70 | +| proxy | 0.12 | 10 | 150/150 | 0.13 | 0.13 | 6.38 | 149.36 | 28 | 49 | +| direct | 1.00 | 10 | 150/150 | 1.01 | 0.01 | 16.06 | 199.36 | 76 | 104 | +| proxy | 1.00 | 10 | 150/150 | 1.01 | 1.01 | 8.75 | 183.10 | 56 | 100 | +| direct | 9.50 | 10 | 150/150 | 9.52 | 0.01 | 88.92 | 286.69 | 425 | 615 | +| proxy | 9.50 | 10 | 150/150 | 9.52 | 9.53 | 38.04 | 236.28 | 232 | 430 | +| proxy | 9.50 | 20 | 300/300 | 9.53 | 9.53 | 48.60 | 263.24 | 416 | 805 | +| direct (tmp.n0I8NPEIWj.png) | 10.00 | 32 | 144/192 | 7.52 | 0.01 | 366.84 | 787.07 | 10903 | 13413 | +| proxy (tmp.n0I8NPEIWj.png) | 10.00 | 32 | 189/192 | 10.03 | 9.88 | 376.84 | 773.20 | 11706 | 12780 | diff --git a/evidence/lab4/unit-tests.txt b/evidence/lab4/unit-tests.txt index 5c51ded1..348e65c9 100644 --- a/evidence/lab4/unit-tests.txt +++ b/evidence/lab4/unit-tests.txt @@ -1,6 +1,6 @@ -[Nest] 3895186 - 10/23/2026, 4:39:54 PM WARN [MessagesCacheService] Cache fill failed: redis down -[Nest] 3895204 - 10/23/2026, 4:39:56 PM WARN [AttachmentsService] Compensation of attachment 5f9c0c33-dfa1-42a3-80a8-37f3ea9ef571 deferred: Connection terminated unexpectedly - Test Files 12 passed (12) - Tests 43 passed (43) - Start at 16:39:54 - Duration 2.47s (transform 762ms, setup 0ms, import 7.87s, tests 495ms, environment 2ms) +[Nest] 4013602 - 10/23/2026, 5:10:35 PM WARN [MessagesCacheService] Cache fill failed: redis down +[Nest] 4013620 - 10/23/2026, 5:10:37 PM WARN [AttachmentsService] Compensation of attachment 2dc5fe05-aac7-484f-935e-186a935e9224 deferred: Connection terminated unexpectedly + Test Files 13 passed (13) + Tests 48 passed (48) + Start at 17:10:34 + Duration 2.68s (transform 652ms, setup 0ms, import 8.56s, tests 1.95s, environment 2ms) diff --git a/scripts/lab4/attachments_bench.py b/scripts/lab4/attachments_bench.py index 3ed8e626..9e5151d8 100755 --- a/scripts/lab4/attachments_bench.py +++ b/scripts/lab4/attachments_bench.py @@ -104,41 +104,56 @@ def percentile(values, fraction): def one_upload(env, mode, token, chat_id, data, seed): + """Returns (ok, elapsed_ms, outcome); outcome names the failing step and status, e.g. "complete:429".""" digest = hashlib.sha256(data).hexdigest() filename = f"bench-{seed}.png" port = int(env.get("APP_PUBLIC_PORT", "8080")) started = time.perf_counter() - if mode == "proxy": - status, payload = request( - "127.0.0.1", port, "POST", - f"/api/v1/chats/{chat_id}/attachments?filename={urllib.parse.quote(filename)}", - {"authorization": f"Bearer {token}", "content-type": "image/png"}, data, - ) - ok = status == 201 - attachment = json.loads(payload) if ok else None - else: - status, ticket = api_json( - env, "POST", f"/api/v1/chats/{chat_id}/attachments/direct-uploads", token, - {"filename": filename, "content_type": "image/png", "size_bytes": len(data), "sha256": digest}, - ) - ok = status == 201 - attachment = None - if ok: - target = urllib.parse.urlsplit(ticket["url"]) - put_status, _ = request( - target.hostname, target.port, "PUT", target.path + "?" + target.query, - {**ticket["headers"]}, data, + outcome, attachment = "ok", None + try: + if mode == "proxy": + status, body = request( + "127.0.0.1", port, "POST", + f"/api/v1/chats/{chat_id}/attachments?filename={urllib.parse.quote(filename)}", + {"authorization": f"Bearer {token}", "content-type": "image/png"}, data, ) - ok = put_status == 200 - if ok: - status, attachment = api_json( - env, "POST", f"/api/v1/attachments/{ticket['attachment_id']}/complete", token + if status == 201: + attachment = json.loads(body) + else: + outcome = f"upload:{status}" + else: + headers = {"authorization": f"Bearer {token}", "content-type": "application/json"} + status, body = request( + "127.0.0.1", port, "POST", f"/api/v1/chats/{chat_id}/attachments/direct-uploads", headers, + json.dumps({"filename": filename, "content_type": "image/png", + "size_bytes": len(data), "sha256": digest}).encode(), + ) + if status != 201: + outcome = f"init:{status}" + else: + ticket = json.loads(body) + target = urllib.parse.urlsplit(ticket["url"]) + put_status, _ = request( + target.hostname, target.port, "PUT", target.path + "?" + target.query, + {**ticket["headers"]}, data, ) - ok = status == 200 + if put_status != 200: + outcome = f"put:{put_status}" + else: + status, body = request( + "127.0.0.1", port, "POST", f"/api/v1/attachments/{ticket['attachment_id']}/complete", + {"authorization": f"Bearer {token}"}, + ) + if status == 200: + attachment = json.loads(body) + else: + outcome = f"complete:{status}" + except (OSError, http.client.HTTPException, ValueError) as error: + outcome = f"error:{type(error).__name__}" elapsed_ms = (time.perf_counter() - started) * 1000 - if ok and (attachment is None or attachment["sha256"] != digest): - ok = False - return ok, elapsed_ms + if outcome == "ok" and (attachment is None or attachment["sha256"] != digest): + outcome = "checksum_mismatch" + return outcome == "ok", elapsed_ms, outcome def payload(args, seed): @@ -155,6 +170,7 @@ def run_once(env, args, actors, ids): baseline = {c: metrics(c) for c in ids} net_before = {c: net_bytes(c) for c in ids} latencies, failures = [], [] + outcomes = {} lock = threading.Lock() def worker(index): @@ -162,9 +178,10 @@ def run_once(env, args, actors, ids): seed = index * 1000 + step data = payload(args, seed) token, chat_id = actors[index % len(actors)] - ok, elapsed = one_upload(env, args.mode, token, chat_id, data, seed) + ok, elapsed, outcome = one_upload(env, args.mode, token, chat_id, data, seed) with lock: (latencies if ok else failures).append(elapsed) + outcomes[outcome] = outcomes.get(outcome, 0) + 1 started = time.perf_counter() threads = [threading.Thread(target=worker, args=(i,)) for i in range(args.concurrency)] @@ -195,6 +212,7 @@ def run_once(env, args, actors, ids): "uploads": total, "succeeded": len(latencies), "failed": len(failures), + "outcomes": outcomes, "duration_s": round(duration, 3), "latency_ms": { "p50": round(percentile(latencies, 0.50), 1), @@ -264,7 +282,8 @@ def command_run(args): for index, item in enumerate(repeats): print(f"repeat {index + 1}: ok={item['succeeded']}/{item['uploads']} " f"rx/upload={item['rx_bytes_per_upload']} tx/upload={item['tx_bytes_per_upload']} " - f"maxΔrss={item['max_delta_rss_bytes']} p50={item['latency_ms']['p50']}ms") + f"maxΔrss={item['max_delta_rss_bytes']} p50={item['latency_ms']['p50']}ms " + f"outcomes={item['outcomes']}") def mib(value): @@ -282,15 +301,21 @@ def command_summarize(args): label = p["mode"] + (f" ({p['image']})" if p.get("image") else "") rows.append((label, p["size_bytes"], p["concurrency"], reps, med, data)) rows.sort(key=lambda r: (r[0].count("("), r[1], r[0], r[2])) - print("| mode | size, MiB | C | ok | API rx/upload, MiB | API tx/upload, MiB | max Δrss, MiB | peak RSS, MiB | p50, ms | p95, ms |") - print("|---|---|---|---|---|---|---|---|---|---|") + print("| mode | size, MiB | C | ok | failures | API rx/upload, MiB | API tx/upload, MiB | max Δrss, MiB | peak RSS, MiB | p50, ms | p95, ms |") + print("|---|---|---|---|---|---|---|---|---|---|---|") for mode, size, conc, reps, med, _data in rows: peak = max(x["peak_memory_bytes"]["rss"] for r in reps for x in r["replicas"]) + failed = {} + for rep in reps: + for name, count in rep.get("outcomes", {}).items(): + if name != "ok": + failed[name] = failed.get(name, 0) + count + failures = ", ".join(f"{name}×{count}" for name, count in sorted(failed.items())) or "—" ok = sum(r["succeeded"] for r in reps) total = sum(r["uploads"] for r in reps) p50 = statistics.median(r["latency_ms"]["p50"] for r in reps) p95 = statistics.median(r["latency_ms"]["p95"] for r in reps) - print(f"| {mode} | {mib(size)} | {conc} | {ok}/{total} | {mib(med('rx_bytes_per_upload'))} | " + print(f"| {mode} | {mib(size)} | {conc} | {ok}/{total} | {failures} | {mib(med('rx_bytes_per_upload'))} | " f"{mib(med('tx_bytes_per_upload'))} | {mib(med('max_delta_rss_bytes'))} | {mib(peak)} | {p50:.0f} | {p95:.0f} |") diff --git a/scripts/lab4/run_matrix.sh b/scripts/lab4/run_matrix.sh index 7edd2752..2c6578cf 100755 --- a/scripts/lab4/run_matrix.sh +++ b/scripts/lab4/run_matrix.sh @@ -22,8 +22,9 @@ bench proxy 9961472 20 # Worst case for memory: every request carries the heaviest valid image # (40 MP RGBA16 Adam7 PNG padded to 10 MiB, ~340 MiB per decode) and C=32 # saturates UPLOAD_MAX_IN_FLIGHT (16) on both replicas. -worst=$(mktemp --suffix=.png) -trap 'rm -f "$worst"' EXIT +tmp=$(mktemp -d) +trap 'rm -rf "$tmp"' EXIT +worst="$tmp/worst-40mp-rgba16-adam7.png" python3 scripts/lab4/pngkit.py > "$worst" for mode in proxy direct; do echo "== $mode worst-case image c=32" -- 2.54.0 From 66c44aa0f3f544fbcf63a06c33d81e703b6a87d5 Mon Sep 17 00:00:00 2001 From: Ilya Date: Fri, 23 Oct 2026 17:27:37 +0300 Subject: [PATCH 14/15] =?UTF-8?q?lab4:=20evidence=20=D0=B8=20=D0=BE=D1=82?= =?UTF-8?q?=D1=87=D1=91=D1=82=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20=D0=B2?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BE=D0=B3=D0=BE=20=D1=80=D0=B5=D0=B2=D1=8C?= =?UTF-8?q?=D1=8E=20(=D0=B1=D1=8E=D0=B4=D0=B6=D0=B5=D1=82=20=D0=BF=D0=B0?= =?UTF-8?q?=D0=BC=D1=8F=D1=82=D0=B8,=20=D1=85=D1=83=D0=B4=D1=88=D0=B8?= =?UTF-8?q?=D0=B9=20=D1=81=D0=BB=D1=83=D1=87=D0=B0=D0=B9,=20=D1=82=D0=B0?= =?UTF-8?q?=D0=B9=D0=BC=D0=B0=D1=83=D1=82=D1=8B=20S3),=20=D1=88=D0=B0?= =?UTF-8?q?=D0=B1=D0=BB=D0=BE=D0=BD=20PR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/pull_request_template.md | 14 +- REPORT.md | 220 +++++++----- evidence/lab4/bench-oom-check.txt | 2 + evidence/lab4/bench/direct-1048576-c10.json | 363 ++++++++++---------- evidence/lab4/bench/direct-131072-c10.json | 255 +++++++------- evidence/lab4/bench/direct-9961472-c10.json | 291 ++++++++-------- evidence/lab4/bench/direct-worst-c32.json | 234 +++++++------ evidence/lab4/bench/proxy-1048576-c10.json | 175 +++++----- evidence/lab4/bench/proxy-131072-c10.json | 175 +++++----- evidence/lab4/bench/proxy-9961472-c10.json | 249 +++++++------- evidence/lab4/bench/proxy-9961472-c20.json | 175 +++++----- evidence/lab4/bench/proxy-worst-c32.json | 249 +++++++------- evidence/lab4/consistency.txt | 6 +- evidence/lab4/failover-attachment.txt | 14 +- evidence/lab4/failover.txt | 26 +- evidence/lab4/persistence.txt | 37 +- evidence/lab4/summary.md | 22 +- 17 files changed, 1315 insertions(+), 1192 deletions(-) create mode 100644 evidence/lab4/bench-oom-check.txt diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 627df3cf..a636f0aa 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -7,11 +7,11 @@ Что реализовано и что перенесено: - Перенесено из lab3: NestJS 12 + Fastify 5, PostgreSQL, Redis-сессии и кэш, идемпотентность POST сообщений, HAProxy + 2 API-реплики, хуки `restart.sh` / `stop-one.sh` / `start-replica.sh`. - Стенд: MinIO (образ закреплён по digest), идемпотентный bootstrap `s3-init` (приватный bucket, политика `messenger-api` только на `attachments/*`, отдельный пользователь API), секреты через Docker secrets (`make init-env`), консоль MinIO отключена, порт 9001 не публикуется, корневая ФС API `read_only`. -- Proxy upload PNG/JPEG: потоковая передача в S3; два слоя проверки — `ImageInspector` (сигнатура, структура, CRC, тип, лимит 40 млн пикселей до любого декода) и полный декод libvips/sharp (`failOn: 'warning'`), последний кусок уходит в S3 только после обоих; лимит 10 MiB до чтения; 201 ready только после PUT в S3 и `markReady`. +- Proxy upload PNG/JPEG: потоковая передача в S3; два слоя проверки — `ImageInspector` (сигнатура, структура, CRC, тип, лимит 40 млн пикселей до любого декода) и полный декод libvips/sharp (`failOn: 'warning'`, один декод на реплику, принимаются снимки до 40 Мп включая RGBA16), последний кусок уходит в S3 только после обоих; тип проверяется после аутентификации (401 раньше 415); лимит 10 MiB до чтения; 201 ready только после PUT в S3 и `markReady`. - Компенсация не теряет оригинал: сначала захват строки `pending → deleting`, объект удаляется только после успешного захвата; если COMMIT `ready` прошёл, а ответ потерян — объект сохраняется, клиент получает 201; при недоступной БД ничего не удаляется (уборщик). - Download через API с проверкой членства в чате; `attachment_ids` в сообщениях (атомарно в `CREATE_ONCE_SQL`, составные FK запрещают вложение другого чата); уборщик незавершённых загрузок с grace period; CLI sweep. - Недоступность S3 — деградация: вложения отвечают 503, текст, история и readiness работают. -- Трек 1: `POST /chats/{id}/attachments/direct-uploads` → presigned PUT (подписаны content-type, content-length, x-amz-checksum-sha256) → `POST /attachments/{id}/complete` (HEAD размера и checksum, полное чтение и декод объекта, статус `rejected` для отклонённых); расширение — `contracts/extensions.openapi.json`, обязательный proxy endpoint не изменён. +- Трек 1: `POST /chats/{id}/attachments/direct-uploads` → presigned PUT (подписаны content-type, content-length, x-amz-checksum-sha256) → `POST /attachments/{id}/complete` (HEAD размера и checksum, полное чтение и декод объекта с дедлайном, статус `rejected` для отклонённых, параллельные complete идемпотентны); расширение — `contracts/extensions.openapi.json`, обязательный proxy endpoint не изменён. Команды запуска из чистого clone: ```sh @@ -26,17 +26,17 @@ make bench Результаты проверок и ссылка на REPORT.md: [REPORT.md](../REPORT.md); вывод — `evidence/lab4/`. - `make check` — PASS; `make test` — PASS (`make-check.txt`, `make-test.txt`). -- `make test-e2e`: 38 passed, 8 skipped (opt-in); unit-тесты: 43 passed (включая регрессию потерянного COMMIT и декодер). -- `make test-dependencies`: 6 passed (Redis, PG, S3 down, PG down между PUT и ready — объект сохранён до уборки); короткий TTL: 9 passed. +- `make test-e2e`: 44 passed, 9 skipped (opt-in); unit-тесты: 48 passed (регрессия потерянного COMMIT, декодер, лимиты слотов). +- `make test-dependencies`: 7 passed (Redis, PG, S3 остановлен, S3 завис — 503 за ≤ 20 с, PG down между PUT и ready — объект сохранён до уборки); короткий TTL: 10 passed. - Persistence и failover — PASS; download после остановки каждой из реплик возвращает тот же sha256. - `make s3-security`: 9 PASS; `make consistency`: orphans 0, missing 0; спайк подписи: чужие байты → S3 400/403. -- Эксперимент: proxy 10×9.5 MiB — медиана пика Δrss 43 MiB, 20×9.5 MiB — 50 MiB (граница по конфигурации ≈422 MiB, пик RSS ≤ 391 из 768 MiB); худший декод 40 млн px — 131 MiB; direct снимает с API исходящий трафик (≈0.01 MiB против size), входящий одинаков (≈size), т.к. complete проверяет объект целиком. +- Эксперимент: proxy 10×9.5 MiB — медиана пика Δrss 20 MiB, 20×9.5 MiB — 43 MiB; худший случай (32 клиента, 40 Мп RGBA16 Adam7, 10 MiB) — пик RSS 791 из 1024 MiB без OOM, все отказы — 429; худший декод в контейнере — 338 MiB; direct снимает с API исходящий трафик (≈0.01 MiB против size), входящий одинаков (≈size), т.к. complete проверяет объект целиком. Ограничения / известные ошибки: -- Полная проверка стоит памяти (копия тела ≤10 MiB + декод) и времени (p50 proxy 9.5 MiB вырос с 239 до 642 мс); direct не экономит входящий трафик API — нужна асинхронная проверка рядом с хранилищем. +- Полная проверка стоит памяти (копия тела ≤10 MiB + декод до 338 MiB, поэтому декод по одному и 1 GiB на реплику) и времени под потоком тяжёлых изображений; изменённый байт в сжатых данных baseline JPEG может пройти (у JPEG нет контрольной суммы); direct не экономит входящий трафик API — нужна асинхронная проверка рядом с хранилищем. - Потерянный ответ COMMIT проверен unit-тестом с моком (в стенде нет прокси, рвущего соединение после COMMIT). - Не атомарна проверка лимита незавершённых заявок прямой загрузки (гонка параллельных init). -- Тайм-аут загрузки обрывает сокет вместо ответа 400. +- Тайм-аут загрузки обрывает сокет вместо ответа 400; лимит на пользователя не защищает от медленных клиентов с многих аккаунтов. - Нет автоматического reconciler'а orphan-объектов (только `make consistency`), нет TLS (до lab7), нет вариантов/WebP/delete-API. - Репозиторий MinIO, вероятно, архивирован (в этой работе не перепроверялось). diff --git a/REPORT.md b/REPORT.md index 79ba2738..91828976 100644 --- a/REPORT.md +++ b/REPORT.md @@ -36,7 +36,10 @@ make test-persistence ACTION_SCRIPT=scripts/restart.sh make test-failover ACTION_SCRIPT=scripts/stop-one.sh && scripts/start-replica.sh ``` -Действия оператора: только `make init-env` (секреты создаются локально в `secrets/`, каталог в +Действия оператора: только `make init-env`. Он не перезаписывает существующий `.env`: при обновлении с +предыдущей версии сверьте его с `.env.example` (`diff <(grep -o '^[A-Z_0-9]*=[^#]*' .env.example) .env`), +иначе останутся старые лимиты (так один из прогонов этой работы шёл с `UPLOAD_MAX_IN_FLIGHT=32`). +Далее — (секреты создаются локально в `secrets/`, каталог в `.gitignore`; `secrets/` и `.env` нельзя коммитить). Остановка с сохранением данных — `make stand-down` (тома `postgres-data`, `redis-data`, `s3-data` сохраняются). **Намеренное удаление учебных данных:** `docker compose --env-file .env down -v` (удаляет все три тома, включая загруженные файлы; следующий @@ -82,9 +85,13 @@ ATTACHMENT_SWEEP_INTERVAL_MS=1000 docker compose --env-file .env up -d --no-deps - PostgreSQL недоступен — ничего не удаляется (`attachments.compensation_deferred`): по строке `pending` объект найдёт уборщик через `expires_at + ATTACHMENT_SWEEP_GRACE_SECONDS`, и он тоже сначала захватывает строку; - - S3 недоступен после захвата — строка остаётся `deleting` и перезахватывается уборщиком через минуту. + - S3 недоступен после захвата — строка остаётся `deleting` и перезахватывается уборщиком через минуту; + - запрос оборван (таймаут) уже после того, как последний байт ушёл в S3, — S3 может зафиксировать PUT + *после* нашего DELETE; поэтому строка остаётся `deleting`, и уборщик через минуту удаляет ключ ещё + раз и только потом строку. Если же последний байт не ушёл (обрыв клиента, отказ проверки), S3 не + может зафиксировать объект с неполным телом, и строка удаляется сразу. - Так «объект без строки» не возникает ни при каком сбое, а `ready` без объекта — только при внешнем + Так «объект без строки» не возникает ни в одном из этих сценариев, а `ready` без объекта — только при внешнем удалении из bucket. Первая версия удаляла объект до строки и теряла оригинал при потерянном ответе COMMIT; регрессия — `attachments.service.spec.ts` (unit, мок «COMMIT прошёл, ответ потерян»), а fault-тест `dependency-failures` «keeps the object while PostgreSQL is down before ready» проверяет, @@ -93,22 +100,39 @@ ATTACHMENT_SWEEP_INTERVAL_MS=1000 docker compose --env-file .env up -d --no-deps в S3 с заранее известным `Content-Length` (≤ 10 MiB, иначе 413 до чтения). Проверка в два слоя: 1. `ImageInspector` — байтовый автомат PNG/JPEG без буферизации: сигнатура, структура, CRC чанков PNG, тип по содержимому и число пикселей (≤ 40 млн → 413) по IHDR/SOF. До появления заголовка - (≤ 1 MiB) нет ни строки, ни объекта; pixel bomb отвергается до любого декодирования. - 2. `ImageDecoder` — полный декод всех пикселей libvips (sharp 0.35, `failOn: 'warning'`, - `limitInputPixels`). Структуры и CRC недостаточно: PNG с мусорным zlib-потоком (верные CRC) и JPEG - без данных скана проходят первый слой — их ловит только декод (первая версия возвращала на них - 201). Декод ограничен `IMAGE_DECODE_MAX_CONCURRENT` (очередь), libvips — один поток, без кэша. + нет ни строки, ни объекта (фаза заголовка ограничена `Content-Length` ≤ 10 MiB: у JPEG до SOF + бывают мегабайты APPn-метаданных); pixel bomb отвергается до любого декодирования. + 2. `ImageDecoder` — полный декод libvips (sharp 0.35, `failOn: 'warning'`, `limitInputPixels`), + стоком служит уменьшение до 64 px: оно читает все сжатые данные, но держит в памяти меньше + полноразмерного конвейера (вердикты по 14 видам корректных и битых файлов совпадают с `stats()`, + худший пик памяти — 339 против 329–232 MiB у других стоков… см. `decode-memory.txt`). Структуры и + CRC недостаточно: PNG с мусорным zlib-потоком (верные CRC) и JPEG без данных скана проходят первый + слой — их ловит только декод. Ошибка самого сервера (нет места, нет памяти) не выдаётся за 415: + она логируется и даёт 500. `VIPS_DISC_THRESHOLD=1g` не даёт libvips уносить большие изображения во + временный файл: `/tmp` у API — tmpfs 16 MiB, и до этой настройки снимки ≈40 Мп получали 415. Последний кусок отдаётся в S3 только после обоих слоёв — S3 не получает полное тело невалидного - файла и не фиксирует объект. Цена: на время загрузки API держит копию тела (≤ 10 MiB) для декода - (libvips не принимает поток), плюс память декода (≈117–131 MiB на изображение 40 млн пикселей, - `evidence/lab4/decode-memory.txt`). Верхняя граница на реплику: - `UPLOAD_MAX_IN_FLIGHT × 10 MiB + IMAGE_DECODE_MAX_CONCURRENT × 131 MiB` = 16 × 10 + 2 × 131 ≈ 422 MiB - при лимите контейнера 768 MiB. Остальные ограничители: `UPLOAD_MAX_IN_FLIGHT` (429 + - `Retry-After`, общий для proxy и direct complete), `UPLOAD_TIMEOUT_MS`, тайм-ауты S3-клиента. - Fastify `bodyLimit` к `image/*` не применяется: контент-парсеры отдают сырой поток только маршруту - загрузки (для `text/plain` на нём встроенный буферизующий парсер заменён — иначе бинарное тело - давало 400; на остальных маршрутах `image/*` → 415, `text/plain` буферизуется как прежде). + файла и не фиксирует объект. Цена — память: копия тела (≤ 10 MiB, libvips не принимает поток) и + декод. Худший допустимый вход — 40 Мп RGBA 16 bit с Adam7-чередованием (декодер обязан держать всё + изображение): **338 MiB** на декод в контейнере (`decode-memory.txt`; baseline JPEG 4.5 MiB, + progressive JPEG 118 MiB, CMYK 7.5 MiB, RGBA16 без чередования 67 MiB). Отсюда настройки: + `IMAGE_DECODE_MAX_CONCURRENT=1` (остальные ждут в очереди; ожидающий запрос, у которого истёк + `UPLOAD_TIMEOUT_MS`, покидает очередь вместе со своим буфером) и `API_MEMORY_PER_REPLICA=1024m`. + Граница на реплику: базовый RSS ≈250 MiB + `UPLOAD_MAX_IN_FLIGHT` 16 × 10 MiB + 1 × 340 MiB + ≈ 750 MiB. Нагрузочный прогон худшего случая (32 клиента одновременно шлют именно такой файл + 10 MiB) дал пик RSS 791 MiB из 1024 без OOM и рестартов (`bench/*-worst-c32.json`, + `bench-oom-check.txt`). Слоты: `UPLOAD_MAX_IN_FLIGHT` на реплику и `UPLOAD_MAX_IN_FLIGHT_PER_USER` + (4) на пользователя — медленный клиент (держит слот до `UPLOAD_TIMEOUT_MS`) не занимает слоты + остальных; при исчерпании — 429 + `Retry-After`. Слоты общие для proxy и direct complete. + Маршрут загрузки получает тело сырым потоком при любом `Content-Type`: хук `onRequest` помечает + запрос, и тип проверяет сервис уже после guard (401 раньше 415, как требует contracts/README); + Fastify `bodyLimit` к нему не применяется (лимит считает сервис), остальные маршруты используют + штатные парсеры Fastify (`text/plain` > 1 MiB → 413 в конверте ошибки). +- **Таймауты S3.** `S3_REQUEST_TIMEOUT_MS` (15 с) действует как жёсткий предел: `throwOnRequestTimeout` + (без него smithy только пишет предупреждение) и `socketTimeout` на простой при чтении тела. Для PUT + предел — `UPLOAD_TIMEOUT_MS` (сигнал отмены), чтобы медленный клиент не обрывался на 15 с. + Проверено fault-тестом с `docker pause s3` (порт открыт, ответа нет): download → 503 быстрее 20 с, + метаданные и readiness — 200, после `unpause` файл отдаётся. - **Прямая загрузка (трек 1):** `POST /api/v1/chats/{id}/attachments/direct-uploads` создаёт строку `pending` (`expires_at = now + TTL`) и возвращает presigned PUT. Подписаны `content-type`, `content-length` и `x-amz-checksum-sha256`: S3 сам отвергает тело другого размера (403 @@ -118,7 +142,9 @@ ATTACHMENT_SWEEP_INTERVAL_MS=1000 docker compose --env-file .env up -d --no-deps проходит те же два слоя, что и proxy (инспектор + полный декод), сверка типа и пикселей, `markReady`. Подписанный checksum доказывает лишь, что байты те, что заявил клиент, а не что это изображение: первая версия читала только начало и принимала усечённый PNG и файл, повреждённый после первых - 64 KiB (оба с верным checksum). Цена — входящий трафик API = size на `complete` (см. H2). Несоответствие + 64 KiB (оба с верным checksum). Цена — входящий трафик API = size на `complete` (см. H2). Чтение и + декод ограничены `UPLOAD_TIMEOUT_MS`, обрыв чтения из S3 → 503. Параллельные `complete` одной заявки + все получают 200 (проигравший `markReady` перечитывает строку). Несоответствие (размер/checksum/тип/пиксели) → 409/413/415, объект удаляется, а строка получает статус `rejected` и сохраняет `expires_at`: подписанный URL ещё может быть использован, и повторный PUT оставил бы объект без строки; уборщик удаляет `rejected` после `expires_at` + grace, пока же строка @@ -162,8 +188,11 @@ ATTACHMENT_SWEEP_INTERVAL_MS=1000 docker compose --env-file .env up -d --no-deps | `S3_ACCESS_KEY_ID_FILE`, `S3_SECRET_ACCESS_KEY_FILE` | `resolveSecret` → `S3_ACCESS_KEY_ID`/`S3_SECRET_ACCESS_KEY` | API-credentials из Docker secrets | | `S3_CONNECT_TIMEOUT_MS`, `S3_REQUEST_TIMEOUT_MS` | `NodeHttpHandler` | тайм-ауты S3-клиента | | `MAX_UPLOAD_BYTES`, `MAX_IMAGE_PIXELS` | `AttachmentsService`, `DirectUploadsService` | 10 MiB, 40 млн пикселей | -| `UPLOAD_TIMEOUT_MS`, `UPLOAD_MAX_IN_FLIGHT` | `AttachmentsService`, `UploadSlots` | дедлайн запроса; число одновременных proxy-загрузок и direct complete на реплику (16) | -| `IMAGE_DECODE_MAX_CONCURRENT` | `ImageDecoder` | одновременные полные декоды на реплику (2) | +| `UPLOAD_TIMEOUT_MS` | `AttachmentsService`, `DirectUploadsService` | дедлайн загрузки и `complete` (25 с), включая ожидание декода | +| `UPLOAD_MAX_IN_FLIGHT`, `UPLOAD_MAX_IN_FLIGHT_PER_USER` | `UploadSlots` | одновременные proxy-загрузки и direct complete на реплику (16) и на пользователя (4) | +| `IMAGE_DECODE_MAX_CONCURRENT` | `ImageDecoder` | одновременные полные декоды на реплику (1; худший декод ≈340 MiB) | +| `VIPS_DISC_THRESHOLD` | `compose.yaml` → libvips | 1g: декод в памяти, не во временном файле в tmpfs `/tmp` | +| `API_MEMORY_PER_REPLICA` | `compose.yaml` | лимит памяти реплики, 1024m (бюджет ≈750 MiB, см. выше) | | `ATTACHMENT_SWEEP_INTERVAL_MS`, `ATTACHMENT_SWEEP_GRACE_SECONDS` | `AttachmentSweeper`, CLI | период фонового прохода (0 = выкл.) и grace после `expires_at` | | `DIRECT_UPLOAD_URL_TTL_SECONDS`, `DIRECT_UPLOAD_MAX_PENDING_PER_USER` | `DirectUploadsService` | TTL подписи; лимит незавершённых заявок | | `S3_PUBLIC_BIND`, `S3_PUBLIC_PORT`, `S3_CPUS`, `S3_MEMORY` | `compose.yaml` (сервис `s3`) | публикация порта на loopback; лимиты контейнера | @@ -194,84 +223,96 @@ ATTACHMENT_SWEEP_INTERVAL_MS=1000 docker compose --env-file .env up -d --no-deps | Контракт offline | `make check` | PASS, `contracts/extensions.openapi.json` — валидный JSON | `make-check.txt` | | 3: S3 в общем стенде, приватный bucket, метаданные в PG, байты в bucket | `make stand-up`; `docker compose ps`; `make consistency` | `s3` healthy, `s3-init` завершён с 0; bucket приватный (`mc anonymous set none`); после серий `make bench`, e2e и fault-тестов: 5066 объектов на 5065 `ready` + 15 незавершённых строк (`pending`/`rejected`, ждут истечения + grace; одна из них — с объектом), orphans/missing = 0 | `bootstrap-rerun.txt`, `consistency.txt` | | 3: 201 ready, побайтный download, `attachment_ids` | `make test-e2e` (`attachments.e2e-spec.ts`) | sha256 в ответе = sha256 файла; content = байты, `nosniff`, `Content-Length` | `make-test-e2e.txt` | -| 3: PNG/JPEG ≤10 MiB и ≤40 млн px; MIME по содержимому; опасные filename; лимиты до чтения | e2e: 10485760 → 201, 10485761 → 413, pixel bomb 8000×5001 → 413 сразу после IHDR, PNG как `image/jpeg` → 415, `a/b.png`, `\u202E`, NUL, 256 символов → 400, 255×😀 → 201 | кейсы перечислены в `app/test/attachments.e2e-spec.ts` (в evidence — итог: 38 passed, 8 skipped opt-in); raw image/text тело на JSON-маршрутах → 415/400, не 500 | `make-test-e2e.txt`, `unit-tests.txt` (43 passed: `image-inspector.spec.ts`, `image-decoder.spec.ts`, `attachments.service.spec.ts`) | +| 3: PNG/JPEG ≤10 MiB и ≤40 млн px; MIME по содержимому; опасные filename; лимиты до чтения | e2e: снимок 7728×5152 (39.8 Мп) baseline и progressive JPEG → 201, PNG 8000×5000 RGBA16 → 201, JPEG с 1.3 MB метаданных до SOF → 201; 10485760 → 201, 10485761 → 413, pixel bomb 8000×5001 → 413 сразу после IHDR, PNG как `image/jpeg` → 415, `a/b.png`, `\u202E`, NUL, 256 символов → 400, 255×😀 → 201 | кейсы перечислены в `app/test/attachments.e2e-spec.ts` (в evidence — итог: 44 passed, 9 skipped opt-in); raw image/text тело на JSON-маршрутах → 415/400, `text/plain` > 1 MiB → 413, без токена с `application/zip` → 401 (не 415) | `make-test-e2e.txt`, `unit-tests.txt` (48 passed: `image-inspector.spec.ts`, `image-decoder.spec.ts`, `attachments.service.spec.ts`, `upload-slots.spec.ts`) | | 3: другая реплика отдаёт файл после остановки загрузившей; restart сохраняет данные | `scripts/stop-one.sh` (обе реплики по очереди), `make test-failover`; `make test-persistence ACTION_SCRIPT=scripts/restart.sh` | failover: 0 неуспешных попыток, восстановление ≈3.3 с; download с тем же sha256 после остановки api-1 и api-2; persistence: `StartedAt` у postgres, redis, s3, api×2, haproxy изменился, данные и сессия сохранены | `failover.txt`, `failover-attachment.txt`, `persistence.txt` | | 3: на API нет локального файла оригинала | `touch` в корне контейнера | `Read-only file system` | `readonly-api.txt` | | 4: тесты: большой файл, повреждённое изображение, подмена MIME, чужое `attachment_id`, вложение другого чата, нет 500 | `make test-e2e` | 413; усечённый PNG, флип байта (CRC), сигнатура+мусор, пустое тело, PNG с мусорным zlib-потоком при верных CRC, JPEG (baseline и прогрессивный) без данных скана → 415; подмена MIME → 415; чужое/неизвестное/незавершённое → 404; вложение чата eve в чате alice → 404 | `make-test-e2e.txt` | | 4: прерывание загрузки и отказ между S3/БД не оставляют вечных объектов | e2e «client drops the connection»; `make test-dependencies` | обрыв клиента → строк 0 за ≤10 с; S3 down → строка в `deleting`, после старта перезахвачена и убрана sweep; PG down между PUT и ready → 503, объект сохранён до уборки (строка `pending` его учитывает), после sweep нет ни объекта, ни строки; потерянный ответ COMMIT → объект не удаляется, 201 (unit `attachments.service.spec.ts`); затем `orphans: 0, missing: 0` | `make-test-e2e.txt`, `make-test-dependencies.txt`, `consistency.txt` | -| 4: лимиты, таймауты, потоковая обработка; эксперимент ≥10 загрузок с пиком памяти | `make bench` (proxy, C=10 и C=20, 9.5 MiB) | медиана max Δrss реплики 43 MiB при C=10 и 50 MiB при C=20 (≈95/190 MiB тел в полёте), абсолютный пик RSS ≤ 391 MiB при лимите 768 MiB; граница по конфигурации ≈422 MiB сверх базового RSS; худший декод 40 млн px — 131 MiB — см. «Эксперименты» | `summary.md`, `bench/*.json`, `decode-memory.txt` | +| 4: лимиты, таймауты, потоковая обработка; эксперимент ≥10 загрузок с пиком памяти | `make bench`: proxy 9.5 MiB при C=10 и C=20; худший случай — 32 клиента с 40 Мп RGBA16 Adam7 10 MiB; `docker pause s3` в `make test-dependencies` | типичные: Δrss 20 / 43 MiB; худший: пик RSS 791 из 1024 MiB, без OOM, избыток — 429; граница по конфигурации ≈750 MiB; худший декод в контейнере 338 MiB; зависший S3 → 503 за ≤ 20 с | `summary.md`, `bench/*.json`, `bench-oom-check.txt`, `decode-memory.txt`, `make-test-dependencies.txt` | | 4: идемпотентный bootstrap; отдельные ограниченные credentials; консоль закрыта; private bucket вне API | `docker compose run s3-init` дважды; `make s3-security` | повтор → `bootstrap ok`; анонимные GET/list/PUT → 403; API-credentials не создают bucket, не вызывают admin, не пишут вне `attachments/`, читают `attachments/*`; порт 9001 не опубликован и не отвечает | `bootstrap-rerun.txt`, `s3-security.txt` | -| 5 / трек 1: presigned flow (короткая подпись, уникальный ключ, принадлежность, размер/checksum на complete, незавершённые) | `direct-upload.e2e-spec.ts`; спайк подписи | init → PUT мимо API → complete → metadata/content → сообщение; чужой/посторонний complete → 404; усечённый PNG и PNG, повреждённый после первых 64 KiB (оба с верным checksum) → 415, затем 404; подмена байта → S3 400, затем complete 409; JPEG под видом PNG → 415, затем 404; pixel bomb → 413; 11-я заявка → 429 + `Retry-After` | `make-test-e2e.txt`, `presign-spike.txt` | +| 5 / трек 1: presigned flow (короткая подпись, уникальный ключ, принадлежность, размер/checksum на complete, незавершённые) | `direct-upload.e2e-spec.ts`; спайк подписи | init → PUT мимо API → complete → metadata/content → сообщение; чужой/посторонний complete → 404; 4 параллельных complete → 200 × 4; усечённый PNG и PNG, повреждённый после первых 64 KiB (оба с верным checksum) → 415, затем 404; подмена байта → S3 400, затем complete 409; JPEG под видом PNG → 415, затем 404; pixel bomb → 413; 11-я заявка → 429 + `Retry-After` | `make-test-e2e.txt`, `presign-spike.txt` | | 5 / трек 1: истёкший URL и уборка | `E2E_DIRECT_TTL_SHORT=1` на стенде с TTL 5 с | PUT после `expires_at` → 403, строка убрана уборщиком, complete → 404 | `direct-ttl-short.txt` | | 5 / трек 1: сравнение трафика и RAM API на ≥2 размерах | `make bench` (0.125, 1, 9.5 MiB) | см. таблицу ниже | `summary.md`, `bench/*.json` | Оговорка по hook'ам: `make test-persistence` и `make test-failover` подтверждают сохранность данных и сессии; какие процессы перезапущены, видно по `StartedAt` до/после (`persistence.txt`). -`scripts/stop-one.sh` останавливает только реплику, обслужившую сессию теста (в трёх прогонах +`scripts/stop-one.sh` останавливает только реплику, обслужившую сессию теста (в обоих прогонах `make test-failover` это была одна и та же реплика), поэтому остановка обеих реплик показана отдельно -`failover-attachment.txt`. +`failover-attachment.txt`. Persistence, failover, бенчмарк, безопасность и сверка перезапущены на +коммите `9caa031` (код приложения тот же, что в `4b53e03`); unit, e2e, отказы и короткий TTL — на `4b53e03`. ## Эксперименты и отказы -**Методика.** Хост: 8 логических CPU, 16 GiB RAM, один Docker-хост. Лимиты: API 1.5 CPU / 768 MiB на -реплику (2 реплики), MinIO 1 CPU / 512 MiB, PG 1.5 CPU / 512 MiB. Версии — см. «Запуск». Нагрузка: -`scripts/lab4/attachments_bench.py`, closed-loop: C потоков × 5 загрузок несжимаемых PNG -(`noise_png`, разные seed — несжимаемые, поэтому декод не дешевле реальных фото), R = 3 повтора; один прогрев на конфигурацию (2 × число реплик загрузок, -не измеряется), перед каждым повтором — `POST /internal/metrics/reset` на каждой реплике. Трафик API — дельта `eth0` rx/tx из `/proc/net/dev` -контейнера; RAM — пик `process.memoryUsage().rss` с шагом 50 мс минус RSS в момент reset (Δrss); -в таблицу идёт медиана по повторам, для Δrss — максимум по репликам. Команда: `make bench` -(`scripts/lab4/run_matrix.sh`); raw — `evidence/lab4/bench/*.json` (без токенов и URL). +**Методика.** Хост: 8 логических CPU, 16 GiB RAM, один Docker-хост. Лимиты: API 1.5 CPU / 1024 MiB на +реплику (2 реплики), MinIO 1 CPU / 512 MiB, PG 1.5 CPU / 512 MiB; `UPLOAD_MAX_IN_FLIGHT=16`, +`UPLOAD_MAX_IN_FLIGHT_PER_USER=4`, `IMAGE_DECODE_MAX_CONCURRENT=1`. Версии — см. «Запуск». Нагрузка: +`scripts/lab4/attachments_bench.py`, closed-loop: C потоков (у каждого свой пользователь и чат) × K +загрузок, R = 3 повтора; один прогрев на конфигурацию (2 × число реплик загрузок, не измеряется), перед +каждым повтором — `POST /internal/metrics/reset` на каждой реплике. Два вида входа: +1. **типичный** — несжимаемые PNG ширины 1024 (`noise_png`, разные seed) 0.125 / 1 / 9.5 MiB, K = 5: + нагружают сеть и S3, декод у них дешёвый (≈15 мс на 9.5 MiB); +2. **худший для памяти** — 40 Мп RGBA 16 bit, Adam7, дополненный до 10 MiB (`pngkit.py`), C = 32, K = 2: + каждый запрос требует максимального декода (≈810 мс, 338 MiB), а C = 32 упирается в + `UPLOAD_MAX_IN_FLIGHT` обеих реплик. -**H1 (уровень 4).** Память реплики при ≥ 10 параллельных загрузках ограничена сверху конфигурацией -(`UPLOAD_MAX_IN_FLIGHT × 10 MiB + IMAGE_DECODE_MAX_CONCURRENT × ≈131 MiB` ≈ 422 MiB) и не зависит от -числа клиентов сверх этого лимита. Исходная формулировка («Δrss почти не зависит от размера файла») для -текущей версии неверна по построению: ради полного декода API держит копию тела. +Трафик API — дельта `eth0` rx/tx из `/proc/net/dev` контейнера; RAM — пик `process.memoryUsage().rss` +с шагом 50 мс (Δrss — минус RSS в момент reset; peak RSS — абсолютный максимум по репликам и повторам); +отказы классифицируются по шагу и статусу. В таблицу идут медианы по повторам. Команда: `make bench` +(`scripts/lab4/run_matrix.sh`); raw — `evidence/lab4/bench/*.json` (без токенов и URL), коммит `9caa031`. + +**H1 (уровень 4).** Память реплики ограничена сверху конфигурацией — базовый RSS ≈250 MiB + +`UPLOAD_MAX_IN_FLIGHT × 10 MiB` + `IMAGE_DECODE_MAX_CONCURRENT × 340 MiB` ≈ 750 MiB < 1024 MiB — при любом +числе клиентов и любом допустимом изображении; избыток нагрузки получает 429, а не OOM. (Исходная +формулировка «Δrss почти не зависит от размера файла» для текущей версии неверна по построению: ради +полного декода API держит копию тела.) **H2 (трек 1).** Прямая загрузка снимает с API передачу байтов в S3 (tx) и не требует держать соединение клиента на время заливки; входящий трафик API она не снижает, потому что `complete` читает объект целиком для проверки; латентность direct выше из-за трёх round trip и повторного чтения. -Результаты (`evidence/lab4/summary.md`, коммит `4badd5a`; 150 загрузок на строку при C=10, 300 при -C=20; ошибок 0): +Результаты (`evidence/lab4/summary.md`; 150 загрузок на строку при C=10, 300 при C=20, 192 в худшем случае): -| mode | size, MiB | C | API rx/upload, MiB | API tx/upload, MiB | max Δrss, MiB | p50, ms | p95, ms | -| --- | --- | --- | --- | --- | --- | --- | --- | -| direct | 0.12 | 10 | 0.13 | 0.01 | 5.25 | 72 | 120 | -| proxy | 0.12 | 10 | 0.13 | 0.13 | 3.00 | 57 | 87 | -| direct | 1.00 | 10 | 1.01 | 0.01 | 1.38 | 154 | 252 | -| proxy | 1.00 | 10 | 1.01 | 1.01 | 2.00 | 132 | 183 | -| direct | 9.50 | 10 | 9.52 | 0.01 | 83.62 | 755 | 1018 | -| proxy | 9.50 | 10 | 9.52 | 9.53 | 42.94 | 642 | 889 | -| proxy | 9.50 | 20 | 9.53 | 9.53 | 49.98 | 1336 | 1743 | +| mode | size, MiB | C | ok | отказы | API rx/upload, MiB | API tx/upload, MiB | max Δrss, MiB | peak RSS, MiB | p50, ms | p95, ms | +| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | +| direct | 0.12 | 10 | 150/150 | — | 0.13 | 0.01 | 0.38 | 394 | 40 | 71 | +| proxy | 0.12 | 10 | 150/150 | — | 0.13 | 0.13 | 0.00 | 447 | 26 | 46 | +| direct | 1.00 | 10 | 150/150 | — | 1.01 | 0.01 | 0.00 | 244 | 71 | 107 | +| proxy | 1.00 | 10 | 150/150 | — | 1.01 | 1.01 | 0.12 | 395 | 50 | 82 | +| direct | 9.50 | 10 | 150/150 | — | 9.52 | 0.01 | 67.06 | 344 | 448 | 672 | +| proxy | 9.50 | 10 | 150/150 | — | 9.52 | 9.53 | 20.31 | 273 | 245 | 399 | +| proxy | 9.50 | 20 | 300/300 | — | 9.53 | 9.53 | 42.53 | 274 | 433 | 781 | +| direct, худший | 10.00 | 32 | 167/192 | complete 429 × 25 | 9.24 | 0.01 | 366.88 | 791 | 11067 | 13423 | +| proxy, худший | 10.00 | 32 | 190/192 | upload 429 × 2 | 10.04 | 9.90 | 356.76 | 785 | 11982 | 13068 | Выводы: -- **H1 подтверждена.** Рост памяти сверх базового RSS процесса (≈240–255 MiB после прогрева, включая - загруженный libvips): Δrss 26–57 MiB по повторам при proxy 9.5 MiB C=10 (медиана 43) и 28–121 MiB при - C=20 (медиана 50) — ниже границы ≈422 MiB и намного меньше ≈95/190 MiB тел в полёте на весь стенд. - Абсолютный пик RSS реплики — 311–391 MiB при лимите контейнера 768 MiB. Рост от размера файла есть - (0.12 и 1 MiB — 0.5–6 MiB, 9.5 MiB — десятки MiB): это копия тела для декода и сам декод (≈155 мс на - файл 9.5 MiB, счётчик `attachments.decode.ms`). Худший допустимый декод (40 млн пикселей) — ≈131 MiB, - измерен отдельно (`decode-memory.txt`) и в бенчмарк не входил. Δrss шумная (у одной конфигурации - разброс до 4×), поэтому разница между C=10 и C=20 не интерпретируется. +- **H1 подтверждена.** В худшем случае пик RSS реплики — 785–791 MiB из 1024, OOM и рестартов нет + (`bench-oom-check.txt`); все неуспехи — 429 с `Retry-After` (сработал лимит слотов), ни одного 5xx. + Пик выше расчётных ≈750 MiB на ≈40 MiB: базовый RSS к этому прогону уже был выше 250 MiB (аллокатор + не возвращает память ОС после предыдущих прогонов — поэтому и абсолютный peak RSS у малых файлов + в таблице 394–447 MiB при Δrss ≈ 0). Для типичных файлов Δrss — 0–2 MiB на 0.12–1 MiB и 20–43 MiB на + 9.5 MiB (C = 10 / 20) при ≈95 / 190 MiB тел в полёте на весь стенд. Латентность худшего случая + (p50 ≈ 11–12 с) — очередь к единственному декоду: 16 запросов × ≈0.8 с; это плата за ограничение + памяти, ожидающие дольше `UPLOAD_TIMEOUT_MS` уходят из очереди с 503. - **H2 подтверждена в новой формулировке.** API tx у direct ≈0.01 MiB против size у proxy (≈1000× для 9.5 MiB); API rx одинаков (≈size), потому что `complete` читает объект целиком. Ранняя версия, читавшая только начало объекта, давала rx ≈0.07 MiB, но принимала повреждённые изображения — этот выигрыш был - ценой корректности и отозван. Δrss у direct 9.5 MiB выше, чем у proxy (84 против 43 MiB): объект + ценой корректности и отозван. Δrss у direct 9.5 MiB выше, чем у proxy (67 против 20 MiB): объект читается из S3 быстрее, чем приходит от клиента, и больше копий одновременно ждут декода. Латентность - direct выше на всех размерах (p50 72/154/755 против 57/132/642 мс): три запроса и повторное чтение - объекта. Выигрыш direct в этой реализации — только снятие с API исходящего трафика в S3 и времени - заливки клиентом; для полного выигрыша по rx проверку нужно вынести с API (асинхронный воркер рядом - с хранилищем) — это следующий шаг, не реализован. -- Сравнение с предыдущими прогонами (без полного декода, коммит `830e581`): p50 proxy 9.5 MiB C=10 вырос - с 239 до 642 мс, медиана Δrss — с 15.7 до 42.9 MiB. Это цена закрытия дыры в валидации. + direct выше на всех размерах (p50 40/71/448 против 26/50/245 мс): три запроса и повторное чтение + объекта. Выигрыш direct в этой реализации — снятие с API исходящего трафика в S3 и времени заливки + клиентом; для выигрыша по rx проверку нужно вынести с API (асинхронный воркер рядом с хранилищем, + `status: processing`) — следующий шаг, не реализован. +- История версий: до полного декода (`830e581`) p50 proxy 9.5 MiB C=10 — 239 мс; с декодом через + `stats()` (`4badd5a`, тот прогон по ошибке шёл с `UPLOAD_MAX_IN_FLIGHT=32` из устаревшего локального + `.env`) — 642 мс; с декодом через уменьшение (`9caa031`) — 245 мс. **Ограничения измерений.** Один Docker-хост: клиент, LB, API и MinIO делят 8 CPU, без реальной сети; -`/proc/net/dev` реплики включает трафик PG/Redis и служебные запросы метрик (≈7–8 KiB на загрузку, -видно в tx у direct; метрики и конфигурация берутся прогонами `docker exec`, но их трафик в -измеряемое окно не входит, кроме двух чтений метрик); closed-loop клиент не моделирует arrival rate; выборка RSS 50 мс может -пропустить короткий пик; нет TLS (до lab7); Python-клиент сам ограничен по CPU, поэтому абсолютные -латентности не переносимы. +`/proc/net/dev` реплики включает трафик PG/Redis и служебные запросы метрик (≈7–13 KiB на загрузку, +видно в tx у direct); closed-loop клиент не моделирует arrival rate; выборка RSS 50 мс может +пропустить короткий пик; абсолютный RSS зависит от истории процесса; типичные файлы — синтетический +шум, а не фото (худший случай по памяти проверен отдельно); нет TLS (до lab7); Python-клиент сам +ограничен по CPU, поэтому абсолютные латентности не переносимы. ### Отказы @@ -280,8 +321,12 @@ C=20; ошибок 0): | S3 остановлен (`compose stop s3`) | вложения → bounded 503; текст, история, метаданные, `/health/ready` работают | upload → 503 `unavailable` без утечки деталей; метаданные 200; content 503; текстовое сообщение 201; readiness 200; строка неудачной загрузки в `deleting` (захвачена, удаление объекта не прошло) | после `start s3` и healthy download старого файла 200 с теми же байтами, новый upload 201; строка перезахвачена и убрана sweep через минуту; потерь нет | | PostgreSQL остановлен между S3 PUT и `ready` | 503; API не знает, прошёл ли COMMIT, — ничего не удаляет; объект учтён строкой | ответ 503; после старта PG строка `pending`, объект на месте (`mc stat` — есть); после `expires_at` sweep удалил объект и строку | уборка через `expires_at` + grace; `orphans: 0`, `missing: 0` | | COMMIT `ready` прошёл, ответ PostgreSQL потерян | объект не удаляется, клиент получает 201 | unit `attachments.service.spec.ts`: захват строки не срабатывает, `delete` не вызывается, ответ 201 `ready` | потерь нет (в стенде не воспроизводится без прокси, разрывающего соединение после COMMIT) | +| S3 «завис» (`docker pause s3`: порт открыт, ответа нет) | ответ в пределах `S3_REQUEST_TIMEOUT_MS`, а не бесконечное ожидание | download → 503 быстрее 20 с (15 с таймаут); метаданные и readiness — 200 | после `unpause` download 200 с теми же байтами; потерь нет | +| Медленный клиент держит 12 соединений загрузки | его лишние запросы → 429, остальные пользователи не страдают | его 13-я загрузка → 429 `Retry-After: 1`; 4 загрузки другого пользователя подряд → 201 | соединения закрыты — строк не осталось | +| 4 параллельных `complete` одной прямой загрузки | все получают готовое вложение | 200 × 4 с одним и тем же `id` | — | +| 32 клиента одновременно шлют худший по памяти файл | без OOM; избыток → 429 | пик RSS 791 из 1024 MiB, OOM нет, 27 отказов — все 429 | — | | Обрыв клиента посреди загрузки (512 KiB из 2 MiB) | не остаётся ни строки, ни объекта | PUT прерывается (`S3 put failed: AbortError` в логе API, в evidence не сохранён) без ожидания тайм-аута, компенсация, строк в чате 0 | ≤10 с (предел ожидания теста; точное время не измерялось) | -| Остановка обслужившей реплики | другая реплика отдаёт тот же файл | download 200, тот же sha256, другой `X-Instance-Id` для api-1 и api-2 | ≈3.3 с до первого успешного запроса, 0 неуспешных записей из 134–140 | +| Остановка обслужившей реплики | другая реплика отдаёт тот же файл | download 200, тот же sha256, другой `X-Instance-Id` для api-1 и api-2 | ≈3.2 с до первого успешного запроса, 0 неуспешных записей из 133–141 | | Restart стенда (`scripts/restart.sh`) | метаданные и оригиналы сохраняются, сессия жива | persistence PASS; `StartedAt` всех сервисов изменился | потерь нет (время до готовности отдельно не измерялось) | | Истёкший presigned URL | PUT отвергается, заявка убирается | PUT → 403; строка убрана уборщиком; complete → 404 | TTL (5 с в прогоне) + grace 0 + период уборщика 1 с | | Подмена байтов / размера при прямой загрузке | S3 отвергает, объект не создаётся | 400 `XAmzContentChecksumMismatch` / 403 `SignatureDoesNotMatch`; complete → 409 | заявка остаётся до TTL, клиент может доотправить | @@ -292,30 +337,41 @@ C=20; ошибок 0): репозиторий `minio/minio` архивирован — новых образов и исправлений не будет *(в этой сессии не перепроверялось)*. Для продакшена потребуется замена (SeaweedFS/RustFS) или форк. - **Полная проверка изображения стоит памяти и времени:** копия тела (≤ 10 MiB) на загрузку и декод - через libvips (нативная зависимость sharp, ≈131 MiB на худший вход). `failOn: 'warning'` строже - браузеров: файл с предупреждением libjpeg/libpng будет отвергнут (на 300 изображениях с хоста ложных - отказов не было, но выборка не репрезентативна для фото с камер). Проверяются декодируемость и - целостность, а не «безопасность для всех декодеров» — перекодирование в чистый формат не делается. + через libvips (нативная зависимость sharp; худший вход — 338 MiB, ≈0.8 с). Поэтому декод на реплике + строго по одному, а реплике нужен 1 GiB; под потоком «тяжёлых» изображений латентность растёт до + секунд (очередь), а лишние запросы получают 429. `failOn: 'warning'` строже браузеров: файл с + предупреждением libjpeg/libpng будет отвергнут (на 300 изображениях с хоста ложных отказов не было, + но выборка не репрезентативна для фото с камер). Проверяются декодируемость и целостность, а не + «безопасность для всех декодеров» — перекодирование в чистый формат не делается. +- **Изменённый байт внутри сжатых данных baseline JPEG может пройти проверку:** у JPEG нет контрольной + суммы, и такой байт часто даёт другой, но корректный поток Хаффмана (замер: из 14 видов порчи не + пойман только этот). Для PNG то же поймает CRC/Adler-32. В direct байты дополнительно зафиксированы + подписанным SHA-256 — они ровно те, что заявил клиент. - **Direct не экономит входящий трафик API** (см. H2); это следствие проверки на API. Следующий шаг — асинхронная проверка воркером рядом с хранилищем (`status: processing`), что требует расширения контракта. +- **Лимит на пользователя не защищает от многих аккаунтов:** регистрация открыта, поэтому распределённый + «медленный клиент» из ≥ 4 аккаунтов на реплику всё ещё может занять все слоты на `UPLOAD_TIMEOUT_MS` + (25 с). Защита — минимальная скорость приёма тела или ограничения на LB; не реализовано. - **Гонка лимита заявок:** `countPendingDirect` и `insertPending` не атомарны — параллельные `init` одного пользователя могут превысить лимит на число параллельных запросов; для лабораторной принято. -- **Загрузка, не доставленная до `ready`, видна уборщику только через grace (по умолчанию 15 мин):** - до этого объект занимает место; для быстрой очистки в тестах grace уменьшается переменной окружения. +- **Незавершённые загрузки занимают место до уборки** (`expires_at` + grace 15 мин): в т. ч. прямые + заявки, чей `complete` получил 429 (после серии бенчмарка в `consistency.txt` видно 84 `pending`). + Если строка уже `deleting` из-за поздно зафиксированного PUT после таймаута, уборщик повторно удалит + ключ через минуту. - **Компенсация при недоступной БД ничего не удаляет:** объект остаётся до уборки (`expires_at` + 900 с grace) — сознательный выбор: без БД нельзя отличить «COMMIT не прошёл» от «ответ - потерян», а удаление в втором случае теряет оригинал. Объект без строки (например, строку удалили + потерян», а удаление во втором случае теряет оригинал. Объект без строки (например, строку удалили вручную) обнаружит только `make consistency` — автоматического reconciler'а нет (это трек 2). - **Потерянный COMMIT проверен только unit-тестом** с моком репозитория: стенд не умеет разорвать соединение PostgreSQL ровно после COMMIT (для этого нужен прокси вроде toxiproxy). -- **Таймаут загрузки** уничтожает тело (и сокет) — клиент может получить обрыв соединения вместо - ожидаемого 400 «Upload was interrupted»; строка и объект при этом компенсируются. +- **Таймаут загрузки** уничтожает тело (и сокет) — клиент получает обрыв соединения (через HAProxy — 502 + без `X-Request-Id`) вместо 400 «Upload was interrupted»; строка и объект при этом компенсируются. - **TLS нет** до lab7: presigned URL и токены ходят по HTTP; консоль MinIO отключена полностью, поэтому администрирование — только через `mc` из контейнера. - **Не реализовано:** варианты вложений (`variants` всегда `[]`; `variant=thumbnail|crop|optimized` → 404), - delete-API вложений, WebP. -- **Подтверждено измерением:** память реплики ограничена конфигурацией и в эксперименте далеко от + delete-API вложений, WebP, `Range` на download (игнорируется, отдаётся весь файл с 200). +- **Подтверждено измерением:** память реплики ограничена конфигурацией и в худшем случае не доходит до лимита; direct снимает с API исходящий трафик в S3. **Опровергнуто для текущей версии:** снижение - входящего трафика API прямой загрузкой. **Остаётся гипотезой:** поведение памяти при C ≫ 20 (упор в - `UPLOAD_MAX_IN_FLIGHT`, 429) и на реальных фото, а не на шуме. + входящего трафика API прямой загрузкой. **Остаётся гипотезой:** поведение на реальных фото (типичный + бенчмарк — синтетический шум) и при C, многократно превышающем лимит слотов. diff --git a/evidence/lab4/bench-oom-check.txt b/evidence/lab4/bench-oom-check.txt new file mode 100644 index 00000000..8fb74cc0 --- /dev/null +++ b/evidence/lab4/bench-oom-check.txt @@ -0,0 +1,2 @@ +/mtusi-lab4-api-1 OOMKilled=false restarts=0 +/mtusi-lab4-api-2 OOMKilled=false restarts=0 diff --git a/evidence/lab4/bench/direct-1048576-c10.json b/evidence/lab4/bench/direct-1048576-c10.json index 070e304e..ab327e57 100644 --- a/evidence/lab4/bench/direct-1048576-c10.json +++ b/evidence/lab4/bench/direct-1048576-c10.json @@ -1,6 +1,6 @@ { - "date": "2026-10-23T14:14:08+00:00", - "git": "4b53e03", + "date": "2026-10-23T14:19:18+00:00", + "git": "9caa031", "params": { "mode": "direct", "size_bytes": 1048576, @@ -23,193 +23,202 @@ "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.499, + "outcomes": { + "ok": 50 + }, + "duration_s": 0.474, "latency_ms": { - "p50": 75.9, - "p95": 103.8, - "p99": 130.9 + "p50": 71.2, + "p95": 97.4, + "p99": 114.6 }, "replicas": [ { "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 27463858, - "delta_tx_bytes": 202183, - "baseline_rss_bytes": 178360320, + "delta_rx_bytes": 26410731, + "delta_tx_bytes": 192869, + "baseline_rss_bytes": 255631360, "peak_memory_bytes": { - "rss": 201052160, - "heap_used": 56368848, - "external": 36994298, - "array_buffers": 33183530 - }, - "delta_rss_bytes": 22691840, - "counters": { - "attachments.count_pending_direct": 24, - "attachments.insert_pending": 24, - "attachments.direct.initiated": 24, - "attachments.find_for_complete": 26, - "attachments.direct.verify_bytes": 27262976, - "attachments.decode.ms": 193.75719499992556, - "attachments.mark_ready": 26, - "attachments.direct.completed": 26 - } - }, - { - "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 25359117, - "delta_tx_bytes": 199445, - "baseline_rss_bytes": 184389632, - "peak_memory_bytes": { - "rss": 192516096, - "heap_used": 53666840, - "external": 28723916, - "array_buffers": 24917693 - }, - "delta_rss_bytes": 8126464, - "counters": { - "attachments.count_pending_direct": 26, - "attachments.insert_pending": 26, - "attachments.direct.initiated": 26, - "attachments.find_for_complete": 24, - "attachments.direct.verify_bytes": 25165824, - "attachments.decode.ms": 152.91470899997512, - "attachments.mark_ready": 24, - "attachments.direct.completed": 24 - } - } - ], - "total_delta_rx_bytes": 52822975, - "total_delta_tx_bytes": 401628, - "rx_bytes_per_upload": 1056460, - "tx_bytes_per_upload": 8033, - "max_delta_rss_bytes": 22691840 - }, - { - "uploads": 50, - "succeeded": 50, - "failed": 0, - "duration_s": 0.528, - "latency_ms": { - "p50": 75.6, - "p95": 106.0, - "p99": 124.3 - }, - "replicas": [ - { - "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 26408075, - "delta_tx_bytes": 188162, - "baseline_rss_bytes": 201052160, - "peak_memory_bytes": { - "rss": 209047552, - "heap_used": 59470168, - "external": 43348610, - "array_buffers": 39528755 - }, - "delta_rss_bytes": 7995392, - "counters": { - "attachments.count_pending_direct": 25, - "attachments.insert_pending": 25, - "attachments.direct.initiated": 25, - "attachments.find_for_complete": 25, - "attachments.direct.verify_bytes": 26214400, - "attachments.decode.ms": 129.85774100001436, - "attachments.mark_ready": 25, - "attachments.direct.completed": 25 - } - }, - { - "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 26411366, - "delta_tx_bytes": 196214, - "baseline_rss_bytes": 189214720, - "peak_memory_bytes": { - "rss": 206053376, - "heap_used": 55771464, - "external": 29767218, - "array_buffers": 25958693 - }, - "delta_rss_bytes": 16838656, - "counters": { - "attachments.count_pending_direct": 25, - "attachments.insert_pending": 25, - "attachments.direct.initiated": 25, - "attachments.find_for_complete": 25, - "attachments.direct.verify_bytes": 26214400, - "attachments.decode.ms": 134.29743300002883, - "attachments.mark_ready": 25, - "attachments.direct.completed": 25 - } - } - ], - "total_delta_rx_bytes": 52819441, - "total_delta_tx_bytes": 384376, - "rx_bytes_per_upload": 1056389, - "tx_bytes_per_upload": 7688, - "max_delta_rss_bytes": 16838656 - }, - { - "uploads": 50, - "succeeded": 50, - "failed": 0, - "duration_s": 0.499, - "latency_ms": { - "p50": 71.8, - "p95": 96.8, - "p99": 111.2 - }, - "replicas": [ - { - "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 25354317, - "delta_tx_bytes": 184357, - "baseline_rss_bytes": 190746624, - "peak_memory_bytes": { - "rss": 192581632, - "heap_used": 53105536, - "external": 22274012, - "array_buffers": 18470057 - }, - "delta_rss_bytes": 1835008, - "counters": { - "attachments.count_pending_direct": 26, - "attachments.insert_pending": 26, - "attachments.direct.initiated": 26, - "attachments.find_for_complete": 24, - "attachments.direct.verify_bytes": 25165824, - "attachments.decode.ms": 120.24603700000443, - "attachments.mark_ready": 24, - "attachments.direct.completed": 24 - } - }, - { - "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 27462079, - "delta_tx_bytes": 189327, - "baseline_rss_bytes": 206053376, - "peak_memory_bytes": { - "rss": 206053376, - "heap_used": 53308280, - "external": 30828871, - "array_buffers": 23867652 + "rss": 255631360, + "heap_used": 55130048, + "external": 30839902, + "array_buffers": 27031366 }, "delta_rss_bytes": 0, "counters": { - "attachments.count_pending_direct": 24, - "attachments.insert_pending": 24, - "attachments.direct.initiated": 24, - "attachments.find_for_complete": 26, - "attachments.direct.verify_bytes": 27262976, - "attachments.decode.ms": 152.01662400003988, - "attachments.mark_ready": 26, - "attachments.direct.completed": 26 + "attachments.count_pending_direct": 25, + "attachments.insert_pending": 25, + "attachments.direct.initiated": 25, + "attachments.find_for_complete": 25, + "attachments.direct.verify_bytes": 26214400, + "attachments.decode.ms": 149.66068200027803, + "attachments.mark_ready": 25, + "attachments.direct.completed": 25 + } + }, + { + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 26409853, + "delta_tx_bytes": 199121, + "baseline_rss_bytes": 220901376, + "peak_memory_bytes": { + "rss": 220901376, + "heap_used": 49764944, + "external": 19106520, + "array_buffers": 15302577 + }, + "delta_rss_bytes": 0, + "counters": { + "attachments.count_pending_direct": 25, + "attachments.insert_pending": 25, + "attachments.direct.initiated": 25, + "attachments.find_for_complete": 25, + "attachments.direct.verify_bytes": 26214400, + "attachments.decode.ms": 134.77708099997835, + "attachments.mark_ready": 25, + "attachments.direct.completed": 25 } } ], - "total_delta_rx_bytes": 52816396, - "total_delta_tx_bytes": 373684, - "rx_bytes_per_upload": 1056328, - "tx_bytes_per_upload": 7474, - "max_delta_rss_bytes": 1835008 + "total_delta_rx_bytes": 52820584, + "total_delta_tx_bytes": 391990, + "rx_bytes_per_upload": 1056412, + "tx_bytes_per_upload": 7840, + "max_delta_rss_bytes": 0 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "outcomes": { + "ok": 50 + }, + "duration_s": 0.486, + "latency_ms": { + "p50": 67.0, + "p95": 107.3, + "p99": 117.3 + }, + "replicas": [ + { + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 26407608, + "delta_tx_bytes": 187247, + "baseline_rss_bytes": 255631360, + "peak_memory_bytes": { + "rss": 255631360, + "heap_used": 54714120, + "external": 29734772, + "array_buffers": 25926248 + }, + "delta_rss_bytes": 0, + "counters": { + "attachments.count_pending_direct": 25, + "attachments.insert_pending": 25, + "attachments.direct.initiated": 25, + "attachments.find_for_complete": 25, + "attachments.direct.verify_bytes": 26214400, + "attachments.decode.ms": 129.6924299999373, + "attachments.mark_ready": 25, + "attachments.direct.completed": 25 + } + }, + { + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 26411452, + "delta_tx_bytes": 197525, + "baseline_rss_bytes": 220901376, + "peak_memory_bytes": { + "rss": 220901376, + "heap_used": 50436872, + "external": 20154009, + "array_buffers": 16352314 + }, + "delta_rss_bytes": 0, + "counters": { + "attachments.count_pending_direct": 25, + "attachments.insert_pending": 25, + "attachments.direct.initiated": 25, + "attachments.find_for_complete": 25, + "attachments.direct.verify_bytes": 26214400, + "attachments.decode.ms": 146.63997799990466, + "attachments.mark_ready": 25, + "attachments.direct.completed": 25 + } + } + ], + "total_delta_rx_bytes": 52819060, + "total_delta_tx_bytes": 384772, + "rx_bytes_per_upload": 1056381, + "tx_bytes_per_upload": 7695, + "max_delta_rss_bytes": 0 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "outcomes": { + "ok": 50 + }, + "duration_s": 0.588, + "latency_ms": { + "p50": 79.7, + "p95": 122.1, + "p99": 146.3 + }, + "replicas": [ + { + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 24306748, + "delta_tx_bytes": 183976, + "baseline_rss_bytes": 255631360, + "peak_memory_bytes": { + "rss": 256024576, + "heap_used": 55222760, + "external": 27656537, + "array_buffers": 23848029 + }, + "delta_rss_bytes": 393216, + "counters": { + "attachments.count_pending_direct": 27, + "attachments.insert_pending": 27, + "attachments.direct.initiated": 27, + "attachments.find_for_complete": 23, + "attachments.direct.verify_bytes": 24117248, + "attachments.decode.ms": 164.5750180000323, + "attachments.mark_ready": 23, + "attachments.direct.completed": 23 + } + }, + { + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 28515559, + "delta_tx_bytes": 188283, + "baseline_rss_bytes": 220901376, + "peak_memory_bytes": { + "rss": 220901376, + "heap_used": 51242112, + "external": 23325182, + "array_buffers": 19516705 + }, + "delta_rss_bytes": 0, + "counters": { + "attachments.count_pending_direct": 23, + "attachments.insert_pending": 23, + "attachments.direct.initiated": 23, + "attachments.find_for_complete": 27, + "attachments.direct.verify_bytes": 28311552, + "attachments.decode.ms": 181.22829800000181, + "attachments.mark_ready": 27, + "attachments.direct.completed": 27 + } + } + ], + "total_delta_rx_bytes": 52822307, + "total_delta_tx_bytes": 372259, + "rx_bytes_per_upload": 1056446, + "tx_bytes_per_upload": 7445, + "max_delta_rss_bytes": 393216 } ] } diff --git a/evidence/lab4/bench/direct-131072-c10.json b/evidence/lab4/bench/direct-131072-c10.json index da94832a..719e33cb 100644 --- a/evidence/lab4/bench/direct-131072-c10.json +++ b/evidence/lab4/bench/direct-131072-c10.json @@ -1,6 +1,6 @@ { - "date": "2026-10-23T14:13:55+00:00", - "git": "4b53e03", + "date": "2026-10-23T14:19:05+00:00", + "git": "9caa031", "params": { "mode": "direct", "size_bytes": 131072, @@ -23,193 +23,202 @@ "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.243, + "outcomes": { + "ok": 50 + }, + "duration_s": 0.225, "latency_ms": { - "p50": 43.7, - "p95": 53.9, - "p99": 61.8 + "p50": 39.1, + "p95": 67.1, + "p99": 70.2 }, "replicas": [ { "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 3172400, - "delta_tx_bytes": 183678, - "baseline_rss_bytes": 156618752, + "delta_rx_bytes": 3306246, + "delta_tx_bytes": 183847, + "baseline_rss_bytes": 255115264, "peak_memory_bytes": { - "rss": 158715904, - "heap_used": 54191144, - "external": 9449376, - "array_buffers": 5653126 + "rss": 255115264, + "heap_used": 52168040, + "external": 11980507, + "array_buffers": 8188021 }, - "delta_rss_bytes": 2097152, + "delta_rss_bytes": 0, "counters": { - "attachments.count_pending_direct": 27, - "attachments.insert_pending": 27, - "attachments.direct.initiated": 27, - "attachments.find_for_complete": 23, - "attachments.direct.verify_bytes": 3014656, - "attachments.decode.ms": 76.10400699995807, - "attachments.mark_ready": 23, - "attachments.direct.completed": 23 + "attachments.count_pending_direct": 26, + "attachments.insert_pending": 26, + "attachments.direct.initiated": 26, + "attachments.find_for_complete": 24, + "attachments.direct.verify_bytes": 3145728, + "attachments.decode.ms": 76.04879400000209, + "attachments.mark_ready": 24, + "attachments.direct.completed": 24 } }, { "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 3707187, - "delta_tx_bytes": 186902, - "baseline_rss_bytes": 156594176, + "delta_rx_bytes": 3572465, + "delta_tx_bytes": 185987, + "baseline_rss_bytes": 410796032, "peak_memory_bytes": { - "rss": 157773824, - "heap_used": 53887688, - "external": 8848676, - "array_buffers": 5052846 + "rss": 413024256, + "heap_used": 61028552, + "external": 11110575, + "array_buffers": 7314315 }, - "delta_rss_bytes": 1179648, + "delta_rss_bytes": 2228224, "counters": { - "attachments.count_pending_direct": 23, - "attachments.insert_pending": 23, - "attachments.direct.initiated": 23, - "attachments.find_for_complete": 27, - "attachments.direct.verify_bytes": 3538944, - "attachments.decode.ms": 104.25295099997311, - "attachments.mark_ready": 27, - "attachments.direct.completed": 27 + "attachments.count_pending_direct": 24, + "attachments.insert_pending": 24, + "attachments.direct.initiated": 24, + "attachments.find_for_complete": 26, + "attachments.direct.verify_bytes": 3407872, + "attachments.decode.ms": 95.17834699997911, + "attachments.mark_ready": 26, + "attachments.direct.completed": 26 } } ], - "total_delta_rx_bytes": 6879587, - "total_delta_tx_bytes": 370580, - "rx_bytes_per_upload": 137592, - "tx_bytes_per_upload": 7412, - "max_delta_rss_bytes": 2097152 + "total_delta_rx_bytes": 6878711, + "total_delta_tx_bytes": 369834, + "rx_bytes_per_upload": 137574, + "tx_bytes_per_upload": 7397, + "max_delta_rss_bytes": 2228224 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.277, + "outcomes": { + "ok": 50 + }, + "duration_s": 0.237, "latency_ms": { - "p50": 44.7, - "p95": 89.7, - "p99": 95.4 + "p50": 39.7, + "p95": 70.8, + "p99": 71.9 }, "replicas": [ { "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 3172155, - "delta_tx_bytes": 182647, - "baseline_rss_bytes": 158715904, + "delta_rx_bytes": 3305361, + "delta_tx_bytes": 182735, + "baseline_rss_bytes": 255115264, "peak_memory_bytes": { - "rss": 159240192, - "heap_used": 54550992, - "external": 9440830, - "array_buffers": 5644565 + "rss": 255115264, + "heap_used": 52870848, + "external": 12917408, + "array_buffers": 8731525 }, - "delta_rss_bytes": 524288, + "delta_rss_bytes": 0, "counters": { - "attachments.count_pending_direct": 27, - "attachments.insert_pending": 27, - "attachments.direct.initiated": 27, - "attachments.find_for_complete": 23, - "attachments.direct.verify_bytes": 3014656, - "attachments.decode.ms": 78.99052299992763, - "attachments.mark_ready": 23, - "attachments.direct.completed": 23 + "attachments.count_pending_direct": 26, + "attachments.insert_pending": 26, + "attachments.direct.initiated": 26, + "attachments.find_for_complete": 24, + "attachments.direct.verify_bytes": 3145728, + "attachments.decode.ms": 74.47586199996294, + "attachments.mark_ready": 24, + "attachments.direct.completed": 24 } }, { "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 3706467, - "delta_tx_bytes": 186009, - "baseline_rss_bytes": 157396992, + "delta_rx_bytes": 3572269, + "delta_tx_bytes": 183875, + "baseline_rss_bytes": 413024256, "peak_memory_bytes": { - "rss": 157790208, - "heap_used": 54303864, - "external": 8848749, - "array_buffers": 5052919 + "rss": 413417472, + "heap_used": 59807944, + "external": 10703911, + "array_buffers": 6908083 }, "delta_rss_bytes": 393216, "counters": { - "attachments.count_pending_direct": 23, - "attachments.insert_pending": 23, - "attachments.direct.initiated": 23, - "attachments.find_for_complete": 27, - "attachments.direct.verify_bytes": 3538944, - "attachments.decode.ms": 96.7698720000626, - "attachments.mark_ready": 27, - "attachments.direct.completed": 27 + "attachments.count_pending_direct": 24, + "attachments.insert_pending": 24, + "attachments.direct.initiated": 24, + "attachments.find_for_complete": 26, + "attachments.direct.verify_bytes": 3407872, + "attachments.decode.ms": 80.40512400015723, + "attachments.mark_ready": 26, + "attachments.direct.completed": 26 } } ], - "total_delta_rx_bytes": 6878622, - "total_delta_tx_bytes": 368656, - "rx_bytes_per_upload": 137572, - "tx_bytes_per_upload": 7373, - "max_delta_rss_bytes": 524288 + "total_delta_rx_bytes": 6877630, + "total_delta_tx_bytes": 366610, + "rx_bytes_per_upload": 137553, + "tx_bytes_per_upload": 7332, + "max_delta_rss_bytes": 393216 }, { "uploads": 50, "succeeded": 50, "failed": 0, + "outcomes": { + "ok": 50 + }, "duration_s": 0.266, "latency_ms": { - "p50": 46.8, - "p95": 70.1, - "p99": 72.4 + "p50": 45.7, + "p95": 73.8, + "p99": 80.1 }, "replicas": [ { "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 3839887, - "delta_tx_bytes": 184887, - "baseline_rss_bytes": 159240192, + "delta_rx_bytes": 3306421, + "delta_tx_bytes": 183391, + "baseline_rss_bytes": 255115264, "peak_memory_bytes": { - "rss": 165924864, - "heap_used": 56746264, - "external": 9177437, - "array_buffers": 5381598 + "rss": 255377408, + "heap_used": 55403296, + "external": 12765653, + "array_buffers": 8973582 }, - "delta_rss_bytes": 6684672, + "delta_rss_bytes": 262144, "counters": { - "attachments.count_pending_direct": 22, - "attachments.insert_pending": 22, - "attachments.direct.initiated": 22, - "attachments.find_for_complete": 28, - "attachments.direct.verify_bytes": 3670016, - "attachments.decode.ms": 115.71663299991633, - "attachments.mark_ready": 28, - "attachments.direct.completed": 28 + "attachments.count_pending_direct": 26, + "attachments.insert_pending": 26, + "attachments.direct.initiated": 26, + "attachments.find_for_complete": 24, + "attachments.direct.verify_bytes": 3145728, + "attachments.decode.ms": 113.08572699979413, + "attachments.mark_ready": 24, + "attachments.direct.completed": 24 } }, { "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 3037580, - "delta_tx_bytes": 179535, - "baseline_rss_bytes": 157790208, + "delta_rx_bytes": 3572203, + "delta_tx_bytes": 184215, + "baseline_rss_bytes": 413417472, "peak_memory_bytes": { - "rss": 159514624, - "heap_used": 55134936, - "external": 8340329, - "array_buffers": 4545339 + "rss": 413548544, + "heap_used": 60296808, + "external": 10700258, + "array_buffers": 6904444 }, - "delta_rss_bytes": 1724416, + "delta_rss_bytes": 131072, "counters": { - "attachments.count_pending_direct": 28, - "attachments.insert_pending": 28, - "attachments.direct.initiated": 28, - "attachments.find_for_complete": 22, - "attachments.direct.verify_bytes": 2883584, - "attachments.decode.ms": 78.47993500009761, - "attachments.mark_ready": 22, - "attachments.direct.completed": 22 + "attachments.count_pending_direct": 24, + "attachments.insert_pending": 24, + "attachments.direct.initiated": 24, + "attachments.find_for_complete": 26, + "attachments.direct.verify_bytes": 3407872, + "attachments.decode.ms": 102.82485899998574, + "attachments.mark_ready": 26, + "attachments.direct.completed": 26 } } ], - "total_delta_rx_bytes": 6877467, - "total_delta_tx_bytes": 364422, - "rx_bytes_per_upload": 137549, - "tx_bytes_per_upload": 7288, - "max_delta_rss_bytes": 6684672 + "total_delta_rx_bytes": 6878624, + "total_delta_tx_bytes": 367606, + "rx_bytes_per_upload": 137572, + "tx_bytes_per_upload": 7352, + "max_delta_rss_bytes": 262144 } ] } diff --git a/evidence/lab4/bench/direct-9961472-c10.json b/evidence/lab4/bench/direct-9961472-c10.json index 19ab4861..43a23c55 100644 --- a/evidence/lab4/bench/direct-9961472-c10.json +++ b/evidence/lab4/bench/direct-9961472-c10.json @@ -1,6 +1,6 @@ { - "date": "2026-10-23T14:14:37+00:00", - "git": "4b53e03", + "date": "2026-10-23T14:19:48+00:00", + "git": "9caa031", "params": { "mode": "direct", "size_bytes": 9961472, @@ -23,193 +23,202 @@ "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 3.609, + "outcomes": { + "ok": 50 + }, + "duration_s": 3.75, "latency_ms": { - "p50": 437.2, - "p95": 593.2, - "p99": 654.5 + "p50": 448.3, + "p95": 674.2, + "p99": 702.9 }, "replicas": [ { "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 249509901, - "delta_tx_bytes": 287547, - "baseline_rss_bytes": 195174400, + "delta_rx_bytes": 259479426, + "delta_tx_bytes": 287642, + "baseline_rss_bytes": 280027136, "peak_memory_bytes": { - "rss": 288415744, - "heap_used": 54409488, - "external": 117617657, - "array_buffers": 113825666 + "rss": 322101248, + "heap_used": 54779008, + "external": 104107482, + "array_buffers": 100313819 }, - "delta_rss_bytes": 93241344, - "counters": { - "attachments.count_pending_direct": 25, - "attachments.insert_pending": 25, - "attachments.direct.initiated": 25, - "attachments.find_for_complete": 25, - "attachments.direct.verify_bytes": 249036800, - "attachments.decode.ms": 315.7971269999689, - "attachments.mark_ready": 25, - "attachments.direct.completed": 25 - } - }, - { - "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 249507617, - "delta_tx_bytes": 274665, - "baseline_rss_bytes": 214401024, - "peak_memory_bytes": { - "rss": 289472512, - "heap_used": 51210776, - "external": 78987756, - "array_buffers": 75194088 - }, - "delta_rss_bytes": 75071488, - "counters": { - "attachments.count_pending_direct": 25, - "attachments.insert_pending": 25, - "attachments.direct.initiated": 25, - "attachments.find_for_complete": 25, - "attachments.direct.verify_bytes": 249036800, - "attachments.decode.ms": 276.87352200000896, - "attachments.mark_ready": 25, - "attachments.direct.completed": 25 - } - } - ], - "total_delta_rx_bytes": 499017518, - "total_delta_tx_bytes": 562212, - "rx_bytes_per_upload": 9980350, - "tx_bytes_per_upload": 11244, - "max_delta_rss_bytes": 93241344 - }, - { - "uploads": 50, - "succeeded": 50, - "failed": 0, - "duration_s": 3.4, - "latency_ms": { - "p50": 424.6, - "p95": 661.8, - "p99": 810.6 - }, - "replicas": [ - { - "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 239528101, - "delta_tx_bytes": 272852, - "baseline_rss_bytes": 205328384, - "peak_memory_bytes": { - "rss": 300617728, - "heap_used": 50698680, - "external": 103322639, - "array_buffers": 99528980 - }, - "delta_rss_bytes": 95289344, - "counters": { - "attachments.count_pending_direct": 26, - "attachments.insert_pending": 26, - "attachments.direct.initiated": 26, - "attachments.find_for_complete": 24, - "attachments.direct.verify_bytes": 239075328, - "attachments.decode.ms": 398.21300999989035, - "attachments.mark_ready": 24, - "attachments.direct.completed": 24 - } - }, - { - "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 259470789, - "delta_tx_bytes": 262770, - "baseline_rss_bytes": 246329344, - "peak_memory_bytes": { - "rss": 286126080, - "heap_used": 50197744, - "external": 84091903, - "array_buffers": 80294845 - }, - "delta_rss_bytes": 39796736, + "delta_rss_bytes": 42074112, "counters": { "attachments.count_pending_direct": 24, "attachments.insert_pending": 24, "attachments.direct.initiated": 24, "attachments.find_for_complete": 26, "attachments.direct.verify_bytes": 258998272, - "attachments.decode.ms": 379.7956310000154, + "attachments.decode.ms": 498.32417600008193, "attachments.mark_ready": 26, "attachments.direct.completed": 26 } + }, + { + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 239524438, + "delta_tx_bytes": 268169, + "baseline_rss_bytes": 243490816, + "peak_memory_bytes": { + "rss": 326799360, + "heap_used": 54201104, + "external": 106161894, + "array_buffers": 102364928 + }, + "delta_rss_bytes": 83308544, + "counters": { + "attachments.count_pending_direct": 26, + "attachments.insert_pending": 26, + "attachments.direct.initiated": 26, + "attachments.find_for_complete": 24, + "attachments.direct.verify_bytes": 239075328, + "attachments.decode.ms": 373.651800000167, + "attachments.mark_ready": 24, + "attachments.direct.completed": 24 + } } ], - "total_delta_rx_bytes": 498998890, - "total_delta_tx_bytes": 535622, - "rx_bytes_per_upload": 9979978, - "tx_bytes_per_upload": 10712, - "max_delta_rss_bytes": 95289344 + "total_delta_rx_bytes": 499003864, + "total_delta_tx_bytes": 555811, + "rx_bytes_per_upload": 9980077, + "tx_bytes_per_upload": 11116, + "max_delta_rss_bytes": 83308544 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 3.356, + "outcomes": { + "ok": 50 + }, + "duration_s": 3.749, "latency_ms": { - "p50": 420.6, - "p95": 614.8, - "p99": 658.8 + "p50": 471.3, + "p95": 672.0, + "p99": 739.0 }, "replicas": [ { "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 279414785, - "delta_tx_bytes": 268777, - "baseline_rss_bytes": 247771136, + "delta_rx_bytes": 229545332, + "delta_tx_bytes": 272949, + "baseline_rss_bytes": 322101248, "peak_memory_bytes": { - "rss": 275718144, - "heap_used": 51721152, - "external": 97550522, - "array_buffers": 92510562 + "rss": 322101248, + "heap_used": 53139240, + "external": 120388652, + "array_buffers": 115495375 }, - "delta_rss_bytes": 27947008, + "delta_rss_bytes": 0, "counters": { - "attachments.count_pending_direct": 22, - "attachments.insert_pending": 22, - "attachments.direct.initiated": 22, - "attachments.find_for_complete": 28, - "attachments.direct.verify_bytes": 278921216, - "attachments.decode.ms": 460.6956299999729, - "attachments.mark_ready": 28, - "attachments.direct.completed": 28 + "attachments.count_pending_direct": 27, + "attachments.insert_pending": 27, + "attachments.direct.initiated": 27, + "attachments.find_for_complete": 23, + "attachments.direct.verify_bytes": 229113856, + "attachments.decode.ms": 295.2854530001059, + "attachments.mark_ready": 23, + "attachments.direct.completed": 23 } }, { "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 219572364, - "delta_tx_bytes": 248203, - "baseline_rss_bytes": 246599680, + "delta_rx_bytes": 269451762, + "delta_tx_bytes": 274913, + "baseline_rss_bytes": 294375424, "peak_memory_bytes": { - "rss": 280461312, - "heap_used": 51774984, - "external": 90380520, - "array_buffers": 86585199 + "rss": 360865792, + "heap_used": 53636296, + "external": 157544946, + "array_buffers": 153746128 }, - "delta_rss_bytes": 33861632, + "delta_rss_bytes": 66490368, + "counters": { + "attachments.count_pending_direct": 23, + "attachments.insert_pending": 23, + "attachments.direct.initiated": 23, + "attachments.find_for_complete": 27, + "attachments.direct.verify_bytes": 268959744, + "attachments.decode.ms": 467.34784599993145, + "attachments.mark_ready": 27, + "attachments.direct.completed": 27 + } + } + ], + "total_delta_rx_bytes": 498997094, + "total_delta_tx_bytes": 547862, + "rx_bytes_per_upload": 9979942, + "tx_bytes_per_upload": 10957, + "max_delta_rss_bytes": 66490368 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "outcomes": { + "ok": 50 + }, + "duration_s": 3.501, + "latency_ms": { + "p50": 404.2, + "p95": 599.0, + "p99": 605.8 + }, + "replicas": [ + { + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 219577054, + "delta_tx_bytes": 272143, + "baseline_rss_bytes": 270405632, + "peak_memory_bytes": { + "rss": 290258944, + "heap_used": 52555024, + "external": 103954247, + "array_buffers": 100162235 + }, + "delta_rss_bytes": 19853312, "counters": { "attachments.count_pending_direct": 28, "attachments.insert_pending": 28, "attachments.direct.initiated": 28, "attachments.find_for_complete": 22, "attachments.direct.verify_bytes": 219152384, - "attachments.decode.ms": 303.119670999964, + "attachments.decode.ms": 273.8368729999056, "attachments.mark_ready": 22, "attachments.direct.completed": 22 } + }, + { + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 279433430, + "delta_tx_bytes": 286105, + "baseline_rss_bytes": 223891456, + "peak_memory_bytes": { + "rss": 294211584, + "heap_used": 50865176, + "external": 84552392, + "array_buffers": 80757048 + }, + "delta_rss_bytes": 70320128, + "counters": { + "attachments.count_pending_direct": 22, + "attachments.insert_pending": 22, + "attachments.direct.initiated": 22, + "attachments.find_for_complete": 28, + "attachments.direct.verify_bytes": 278921216, + "attachments.decode.ms": 406.8028439999907, + "attachments.mark_ready": 28, + "attachments.direct.completed": 28 + } } ], - "total_delta_rx_bytes": 498987149, - "total_delta_tx_bytes": 516980, - "rx_bytes_per_upload": 9979743, - "tx_bytes_per_upload": 10340, - "max_delta_rss_bytes": 33861632 + "total_delta_rx_bytes": 499010484, + "total_delta_tx_bytes": 558248, + "rx_bytes_per_upload": 9980210, + "tx_bytes_per_upload": 11165, + "max_delta_rss_bytes": 70320128 } ] } diff --git a/evidence/lab4/bench/direct-worst-c32.json b/evidence/lab4/bench/direct-worst-c32.json index 59f53a19..07081154 100644 --- a/evidence/lab4/bench/direct-worst-c32.json +++ b/evidence/lab4/bench/direct-worst-c32.json @@ -1,6 +1,6 @@ { - "date": "2026-10-23T14:17:56+00:00", - "git": "4b53e03", + "date": "2026-10-23T14:23:13+00:00", + "git": "9caa031", "params": { "mode": "direct", "size_bytes": 10485760, @@ -8,7 +8,7 @@ "uploads_per_worker": 2, "repeat": 3, "users": 32, - "image": "tmp.n0I8NPEIWj.png" + "image": "worst-40mp-rgba16-adam7.png" }, "host": { "nproc": 8, @@ -23,195 +23,207 @@ "uploads": 64, "succeeded": 48, "failed": 16, - "duration_s": 25.799, + "outcomes": { + "ok": 48, + "complete:429": 16 + }, + "duration_s": 25.881, "latency_ms": { - "p50": 10903.2, - "p95": 13413.2, - "p99": 14173.1 + "p50": 11067.1, + "p95": 13423.0, + "p99": 14220.4 }, "replicas": [ { "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 168207096, - "delta_tx_bytes": 377593, - "baseline_rss_bytes": 413126656, + "delta_rx_bytes": 168217561, + "delta_tx_bytes": 384114, + "baseline_rss_bytes": 428978176, "peak_memory_bytes": { - "rss": 811970560, - "heap_used": 51684264, - "external": 224794743, - "array_buffers": 221004399 + "rss": 823418880, + "heap_used": 52305208, + "external": 243338213, + "array_buffers": 239547869 }, - "delta_rss_bytes": 398843904, + "delta_rss_bytes": 394440704, "counters": { "attachments.count_pending_direct": 48, "attachments.insert_pending": 48, "attachments.direct.initiated": 48, "attachments.find_for_complete": 16, "attachments.direct.verify_bytes": 167772160, - "attachments.decode.ms": 12822.89115199988, + "attachments.decode.ms": 13205.84250300005, "attachments.mark_ready": 16, "attachments.direct.completed": 16 } }, { "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 336356397, - "delta_tx_bytes": 437597, - "baseline_rss_bytes": 273133568, + "delta_rx_bytes": 336236648, + "delta_tx_bytes": 458338, + "baseline_rss_bytes": 288284672, "peak_memory_bytes": { - "rss": 811171840, - "heap_used": 50554752, - "external": 236627771, - "array_buffers": 232837243 + "rss": 803422208, + "heap_used": 51748952, + "external": 236179385, + "array_buffers": 232389041 }, - "delta_rss_bytes": 538038272, + "delta_rss_bytes": 515137536, "counters": { "attachments.count_pending_direct": 16, "attachments.insert_pending": 16, "attachments.direct.initiated": 16, "attachments.find_for_complete": 48, "attachments.direct.verify_bytes": 335544320, - "attachments.decode.ms": 24913.963424000074, + "attachments.decode.ms": 24842.089320000494, "attachments.mark_ready": 32, "attachments.direct.completed": 32 } } ], - "total_delta_rx_bytes": 504563493, - "total_delta_tx_bytes": 815190, - "rx_bytes_per_upload": 7883805, - "tx_bytes_per_upload": 12737, - "max_delta_rss_bytes": 538038272 + "total_delta_rx_bytes": 504454209, + "total_delta_tx_bytes": 842452, + "rx_bytes_per_upload": 7882097, + "tx_bytes_per_upload": 13163, + "max_delta_rss_bytes": 515137536 }, { "uploads": 64, - "succeeded": 48, - "failed": 16, - "duration_s": 25.734, + "succeeded": 60, + "failed": 4, + "outcomes": { + "ok": 60, + "complete:429": 4 + }, + "duration_s": 26.523, "latency_ms": { - "p50": 11194.6, - "p95": 13476.1, - "p99": 14262.3 + "p50": 11841.6, + "p95": 13541.3, + "p99": 14293.7 }, "replicas": [ { "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 168183438, - "delta_tx_bytes": 346932, - "baseline_rss_bytes": 458866688, + "delta_rx_bytes": 294214487, + "delta_tx_bytes": 425744, + "baseline_rss_bytes": 470261760, "peak_memory_bytes": { - "rss": 790888448, - "heap_used": 51757664, - "external": 233673177, - "array_buffers": 229882833 + "rss": 828153856, + "heap_used": 51846456, + "external": 242086934, + "array_buffers": 238296517 }, - "delta_rss_bytes": 332021760, + "delta_rss_bytes": 357892096, "counters": { - "attachments.count_pending_direct": 48, - "attachments.insert_pending": 48, - "attachments.direct.initiated": 48, - "attachments.find_for_complete": 16, - "attachments.direct.verify_bytes": 167772160, - "attachments.decode.ms": 12989.242685000005, - "attachments.mark_ready": 16, - "attachments.direct.completed": 16, - "attachments.claim_expired": 1 + "attachments.count_pending_direct": 36, + "attachments.insert_pending": 36, + "attachments.direct.initiated": 36, + "attachments.find_for_complete": 28, + "attachments.direct.verify_bytes": 293601280, + "attachments.decode.ms": 22602.63425100036, + "attachments.mark_ready": 28, + "attachments.claim_expired": 1, + "attachments.direct.completed": 28 } }, { "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 336214769, - "delta_tx_bytes": 436112, - "baseline_rss_bytes": 457699328, + "delta_rx_bytes": 336212832, + "delta_tx_bytes": 461394, + "baseline_rss_bytes": 429502464, "peak_memory_bytes": { - "rss": 825307136, - "heap_used": 54086928, - "external": 219073224, - "array_buffers": 208987973 + "rss": 814202880, + "heap_used": 51503296, + "external": 256575006, + "array_buffers": 212949888 }, - "delta_rss_bytes": 367607808, + "delta_rss_bytes": 384700416, "counters": { - "attachments.count_pending_direct": 16, - "attachments.insert_pending": 16, - "attachments.direct.initiated": 16, - "attachments.find_for_complete": 48, + "attachments.count_pending_direct": 28, + "attachments.insert_pending": 28, + "attachments.direct.initiated": 28, + "attachments.find_for_complete": 36, "attachments.direct.verify_bytes": 335544320, - "attachments.decode.ms": 24466.148074000026, + "attachments.decode.ms": 25502.105729999603, "attachments.mark_ready": 32, "attachments.direct.completed": 32, "attachments.claim_expired": 1 } } ], - "total_delta_rx_bytes": 504398207, - "total_delta_tx_bytes": 783044, - "rx_bytes_per_upload": 7881222, - "tx_bytes_per_upload": 12235, - "max_delta_rss_bytes": 367607808 + "total_delta_rx_bytes": 630427319, + "total_delta_tx_bytes": 887138, + "rx_bytes_per_upload": 9850427, + "tx_bytes_per_upload": 13862, + "max_delta_rss_bytes": 384700416 }, { "uploads": 64, - "succeeded": 48, - "failed": 16, - "duration_s": 25.623, + "succeeded": 59, + "failed": 5, + "outcomes": { + "complete:429": 5, + "ok": 59 + }, + "duration_s": 26.673, "latency_ms": { - "p50": 10789.6, - "p95": 13221.5, - "p99": 14052.1 + "p50": 10563.3, + "p95": 13343.1, + "p99": 14265.7 }, "replicas": [ { "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 168209005, - "delta_tx_bytes": 348167, - "baseline_rss_bytes": 437620736, + "delta_rx_bytes": 283773903, + "delta_tx_bytes": 418163, + "baseline_rss_bytes": 474800128, "peak_memory_bytes": { - "rss": 822276096, - "heap_used": 51899912, - "external": 234753853, - "array_buffers": 230961509 + "rss": 829358080, + "heap_used": 51810024, + "external": 242621863, + "array_buffers": 228344296 }, - "delta_rss_bytes": 384655360, + "delta_rss_bytes": 354557952, "counters": { - "attachments.count_pending_direct": 48, - "attachments.insert_pending": 48, - "attachments.direct.initiated": 48, - "attachments.find_for_complete": 16, - "attachments.direct.verify_bytes": 167772160, - "attachments.decode.ms": 12794.351691999997, - "attachments.mark_ready": 16, - "attachments.direct.completed": 16 + "attachments.count_pending_direct": 37, + "attachments.insert_pending": 37, + "attachments.direct.initiated": 37, + "attachments.find_for_complete": 27, + "attachments.direct.verify_bytes": 283115520, + "attachments.decode.ms": 22160.10410899995, + "attachments.mark_ready": 27, + "attachments.direct.completed": 27 } }, { "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 336206395, - "delta_tx_bytes": 391291, - "baseline_rss_bytes": 472084480, + "delta_rx_bytes": 336214318, + "delta_tx_bytes": 426666, + "baseline_rss_bytes": 461180928, "peak_memory_bytes": { - "rss": 803594240, - "heap_used": 54432464, - "external": 237968850, - "array_buffers": 234178395 + "rss": 814313472, + "heap_used": 54614560, + "external": 256831606, + "array_buffers": 229984560 }, - "delta_rss_bytes": 331509760, + "delta_rss_bytes": 353132544, "counters": { - "attachments.count_pending_direct": 16, - "attachments.insert_pending": 16, - "attachments.direct.initiated": 16, - "attachments.find_for_complete": 48, + "attachments.count_pending_direct": 27, + "attachments.insert_pending": 27, + "attachments.direct.initiated": 27, + "attachments.find_for_complete": 37, "attachments.direct.verify_bytes": 335544320, - "attachments.decode.ms": 24526.03154399991, + "attachments.decode.ms": 25823.93422999978, "attachments.mark_ready": 32, "attachments.direct.completed": 32 } } ], - "total_delta_rx_bytes": 504415400, - "total_delta_tx_bytes": 739458, - "rx_bytes_per_upload": 7881491, - "tx_bytes_per_upload": 11554, - "max_delta_rss_bytes": 384655360 + "total_delta_rx_bytes": 619988221, + "total_delta_tx_bytes": 844829, + "rx_bytes_per_upload": 9687316, + "tx_bytes_per_upload": 13200, + "max_delta_rss_bytes": 354557952 } ] } diff --git a/evidence/lab4/bench/proxy-1048576-c10.json b/evidence/lab4/bench/proxy-1048576-c10.json index 7f312bf6..19e6321c 100644 --- a/evidence/lab4/bench/proxy-1048576-c10.json +++ b/evidence/lab4/bench/proxy-1048576-c10.json @@ -1,6 +1,6 @@ { - "date": "2026-10-23T14:14:01+00:00", - "git": "4b53e03", + "date": "2026-10-23T14:19:11+00:00", + "git": "9caa031", "params": { "mode": "proxy", "size_bytes": 1048576, @@ -23,29 +23,32 @@ "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.392, + "outcomes": { + "ok": 50 + }, + "duration_s": 0.402, "latency_ms": { - "p50": 56.0, - "p95": 100.2, - "p99": 108.3 + "p50": 48.4, + "p95": 84.1, + "p99": 92.3 }, "replicas": [ { "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 26387282, - "delta_tx_bytes": 26396329, - "baseline_rss_bytes": 167575552, + "delta_rx_bytes": 26376487, + "delta_tx_bytes": 26404723, + "baseline_rss_bytes": 255217664, "peak_memory_bytes": { - "rss": 180232192, - "heap_used": 54305016, - "external": 22415054, - "array_buffers": 18606583 + "rss": 255610880, + "heap_used": 52221216, + "external": 23026820, + "array_buffers": 19216043 }, - "delta_rss_bytes": 12656640, + "delta_rss_bytes": 393216, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, - "attachments.decode.ms": 161.38972300002933, + "attachments.decode.ms": 156.9926100000739, "attachments.proxy.bytes_to_s3": 26214400, "attachments.mark_ready": 25, "attachments.upload.created": 25 @@ -53,59 +56,62 @@ }, { "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 26380621, - "delta_tx_bytes": 26397967, - "baseline_rss_bytes": 164233216, + "delta_rx_bytes": 26386314, + "delta_tx_bytes": 26402341, + "baseline_rss_bytes": 413614080, "peak_memory_bytes": { - "rss": 182816768, - "heap_used": 55081640, - "external": 25150489, - "array_buffers": 21337451 + "rss": 413876224, + "heap_used": 55746224, + "external": 28951897, + "array_buffers": 25131678 }, - "delta_rss_bytes": 18583552, + "delta_rss_bytes": 262144, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, - "attachments.decode.ms": 153.55793299997458, + "attachments.decode.ms": 162.94164999981876, "attachments.proxy.bytes_to_s3": 26214400, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 52767903, - "total_delta_tx_bytes": 52794296, - "rx_bytes_per_upload": 1055358, - "tx_bytes_per_upload": 1055886, - "max_delta_rss_bytes": 18583552 + "total_delta_rx_bytes": 52762801, + "total_delta_tx_bytes": 52807064, + "rx_bytes_per_upload": 1055256, + "tx_bytes_per_upload": 1056141, + "max_delta_rss_bytes": 393216 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.44, + "outcomes": { + "ok": 50 + }, + "duration_s": 0.38, "latency_ms": { - "p50": 57.0, - "p95": 123.6, - "p99": 164.4 + "p50": 50.7, + "p95": 82.2, + "p99": 88.5 }, "replicas": [ { "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 26400102, - "delta_tx_bytes": 26408679, - "baseline_rss_bytes": 180232192, + "delta_rx_bytes": 26388819, + "delta_tx_bytes": 26402419, + "baseline_rss_bytes": 255610880, "peak_memory_bytes": { - "rss": 186654720, - "heap_used": 52146632, - "external": 28489237, - "array_buffers": 24678454 + "rss": 255741952, + "heap_used": 53542032, + "external": 30837329, + "array_buffers": 27022020 }, - "delta_rss_bytes": 6422528, + "delta_rss_bytes": 131072, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, - "attachments.decode.ms": 200.20289300006698, + "attachments.decode.ms": 149.34638900024584, "attachments.proxy.bytes_to_s3": 26214400, "attachments.mark_ready": 25, "attachments.upload.created": 25 @@ -113,59 +119,62 @@ }, { "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 26378813, - "delta_tx_bytes": 26400238, - "baseline_rss_bytes": 182816768, + "delta_rx_bytes": 26377403, + "delta_tx_bytes": 26400247, + "baseline_rss_bytes": 220905472, "peak_memory_bytes": { - "rss": 191991808, - "heap_used": 53527584, - "external": 35009900, - "array_buffers": 31190059 + "rss": 221036544, + "heap_used": 51357984, + "external": 22079805, + "array_buffers": 18271239 }, - "delta_rss_bytes": 9175040, + "delta_rss_bytes": 131072, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, - "attachments.decode.ms": 137.82972499995958, + "attachments.decode.ms": 137.65105199965183, "attachments.proxy.bytes_to_s3": 26214400, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 52778915, - "total_delta_tx_bytes": 52808917, - "rx_bytes_per_upload": 1055578, - "tx_bytes_per_upload": 1056178, - "max_delta_rss_bytes": 9175040 + "total_delta_rx_bytes": 52766222, + "total_delta_tx_bytes": 52802666, + "rx_bytes_per_upload": 1055324, + "tx_bytes_per_upload": 1056053, + "max_delta_rss_bytes": 131072 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.37, + "outcomes": { + "ok": 50 + }, + "duration_s": 0.385, "latency_ms": { - "p50": 46.4, - "p95": 81.6, - "p99": 99.1 + "p50": 49.7, + "p95": 73.2, + "p99": 80.6 }, "replicas": [ { "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 26383217, - "delta_tx_bytes": 26399979, - "baseline_rss_bytes": 181960704, + "delta_rx_bytes": 26383716, + "delta_tx_bytes": 26401715, + "baseline_rss_bytes": 255741952, "peak_memory_bytes": { - "rss": 188776448, - "heap_used": 52208392, - "external": 28664130, - "array_buffers": 24846506 + "rss": 255873024, + "heap_used": 52957000, + "external": 26930642, + "array_buffers": 23117596 }, - "delta_rss_bytes": 6815744, + "delta_rss_bytes": 131072, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, - "attachments.decode.ms": 139.54196999999112, + "attachments.decode.ms": 139.30256199993892, "attachments.proxy.bytes_to_s3": 26214400, "attachments.mark_ready": 25, "attachments.upload.created": 25 @@ -173,31 +182,31 @@ }, { "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 26394762, - "delta_tx_bytes": 26403375, - "baseline_rss_bytes": 179302400, + "delta_rx_bytes": 26386387, + "delta_tx_bytes": 26402657, + "baseline_rss_bytes": 221036544, "peak_memory_bytes": { - "rss": 184086528, - "heap_used": 50413992, - "external": 24938566, - "array_buffers": 21130086 + "rss": 221036544, + "heap_used": 51459840, + "external": 22079805, + "array_buffers": 16097979 }, - "delta_rss_bytes": 4784128, + "delta_rss_bytes": 0, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 26214400, - "attachments.decode.ms": 202.13070199999493, + "attachments.decode.ms": 120.35195299994666, "attachments.proxy.bytes_to_s3": 26214400, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 52777979, - "total_delta_tx_bytes": 52803354, - "rx_bytes_per_upload": 1055560, - "tx_bytes_per_upload": 1056067, - "max_delta_rss_bytes": 6815744 + "total_delta_rx_bytes": 52770103, + "total_delta_tx_bytes": 52804372, + "rx_bytes_per_upload": 1055402, + "tx_bytes_per_upload": 1056087, + "max_delta_rss_bytes": 131072 } ] } diff --git a/evidence/lab4/bench/proxy-131072-c10.json b/evidence/lab4/bench/proxy-131072-c10.json index e8d40dff..39e183e8 100644 --- a/evidence/lab4/bench/proxy-131072-c10.json +++ b/evidence/lab4/bench/proxy-131072-c10.json @@ -1,6 +1,6 @@ { - "date": "2026-10-23T14:13:50+00:00", - "git": "4b53e03", + "date": "2026-10-23T14:18:59+00:00", + "git": "9caa031", "params": { "mode": "proxy", "size_bytes": 131072, @@ -23,29 +23,32 @@ "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.166, + "outcomes": { + "ok": 50 + }, + "duration_s": 0.169, "latency_ms": { - "p50": 26.0, - "p95": 43.4, - "p99": 53.2 + "p50": 26.1, + "p95": 46.2, + "p99": 49.0 }, "replicas": [ { "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 3383029, - "delta_tx_bytes": 3398057, - "baseline_rss_bytes": 140619776, + "delta_rx_bytes": 3382850, + "delta_tx_bytes": 3398303, + "baseline_rss_bytes": 468705280, "peak_memory_bytes": { - "rss": 149794816, - "heap_used": 51367680, - "external": 8055768, - "array_buffers": 4261819 + "rss": 468705280, + "heap_used": 50851544, + "external": 134219881, + "array_buffers": 130427173 }, - "delta_rss_bytes": 9175040, + "delta_rss_bytes": 0, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, - "attachments.decode.ms": 83.07460599998012, + "attachments.decode.ms": 100.31424599990714, "attachments.proxy.bytes_to_s3": 3276800, "attachments.mark_ready": 25, "attachments.upload.created": 25 @@ -53,59 +56,62 @@ }, { "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 3381990, - "delta_tx_bytes": 3399067, - "baseline_rss_bytes": 139079680, + "delta_rx_bytes": 3382858, + "delta_tx_bytes": 3398701, + "baseline_rss_bytes": 449990656, "peak_memory_bytes": { - "rss": 148328448, - "heap_used": 51262864, - "external": 7893259, - "array_buffers": 4099697 + "rss": 451563520, + "heap_used": 58537824, + "external": 181003027, + "array_buffers": 177201619 }, - "delta_rss_bytes": 9248768, + "delta_rss_bytes": 1572864, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, - "attachments.decode.ms": 89.15959899991867, + "attachments.decode.ms": 102.65141499997117, "attachments.proxy.bytes_to_s3": 3276800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 6765019, - "total_delta_tx_bytes": 6797124, - "rx_bytes_per_upload": 135300, - "tx_bytes_per_upload": 135942, - "max_delta_rss_bytes": 9248768 + "total_delta_rx_bytes": 6765708, + "total_delta_tx_bytes": 6797004, + "rx_bytes_per_upload": 135314, + "tx_bytes_per_upload": 135940, + "max_delta_rss_bytes": 1572864 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.173, + "outcomes": { + "ok": 50 + }, + "duration_s": 0.198, "latency_ms": { - "p50": 27.7, - "p95": 49.1, - "p99": 49.5 + "p50": 24.7, + "p95": 79.6, + "p99": 87.8 }, "replicas": [ { "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 3377379, - "delta_tx_bytes": 3394793, - "baseline_rss_bytes": 149794816, + "delta_rx_bytes": 3378497, + "delta_tx_bytes": 3395989, + "baseline_rss_bytes": 468705280, "peak_memory_bytes": { - "rss": 149925888, - "heap_used": 50693344, - "external": 7902800, - "array_buffers": 4109077 + "rss": 468705280, + "heap_used": 51433088, + "external": 135937131, + "array_buffers": 132143156 }, - "delta_rss_bytes": 131072, + "delta_rss_bytes": 0, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, - "attachments.decode.ms": 85.17745499999728, + "attachments.decode.ms": 133.3207659999607, "attachments.proxy.bytes_to_s3": 3276800, "attachments.mark_ready": 25, "attachments.upload.created": 25 @@ -113,59 +119,62 @@ }, { "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 3377406, - "delta_tx_bytes": 3395327, - "baseline_rss_bytes": 148328448, + "delta_rx_bytes": 3377682, + "delta_tx_bytes": 3396121, + "baseline_rss_bytes": 410624000, "peak_memory_bytes": { - "rss": 149770240, - "heap_used": 51549096, - "external": 8924915, - "array_buffers": 4317559 + "rss": 410624000, + "heap_used": 57652400, + "external": 13565945, + "array_buffers": 9765488 }, - "delta_rss_bytes": 1441792, + "delta_rss_bytes": 0, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, - "attachments.decode.ms": 96.18780900008278, + "attachments.decode.ms": 68.74197999993339, "attachments.proxy.bytes_to_s3": 3276800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 6754785, - "total_delta_tx_bytes": 6790120, - "rx_bytes_per_upload": 135096, - "tx_bytes_per_upload": 135802, - "max_delta_rss_bytes": 1441792 + "total_delta_rx_bytes": 6756179, + "total_delta_tx_bytes": 6792110, + "rx_bytes_per_upload": 135124, + "tx_bytes_per_upload": 135842, + "max_delta_rss_bytes": 0 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 0.206, + "outcomes": { + "ok": 50 + }, + "duration_s": 0.161, "latency_ms": { - "p50": 33.9, - "p95": 57.9, - "p99": 66.3 + "p50": 26.1, + "p95": 42.7, + "p99": 45.7 }, "replicas": [ { "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 3376104, - "delta_tx_bytes": 3395515, - "baseline_rss_bytes": 149925888, + "delta_rx_bytes": 3374905, + "delta_tx_bytes": 3395785, + "baseline_rss_bytes": 254783488, "peak_memory_bytes": { - "rss": 156610560, - "heap_used": 52936520, - "external": 10702533, - "array_buffers": 6907528 + "rss": 254783488, + "heap_used": 51574496, + "external": 12158693, + "array_buffers": 8364940 }, - "delta_rss_bytes": 6684672, + "delta_rss_bytes": 0, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, - "attachments.decode.ms": 92.25257400004193, + "attachments.decode.ms": 77.51481299975421, "attachments.proxy.bytes_to_s3": 3276800, "attachments.mark_ready": 25, "attachments.upload.created": 25 @@ -173,31 +182,31 @@ }, { "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 3375521, - "delta_tx_bytes": 3395653, - "baseline_rss_bytes": 149770240, + "delta_rx_bytes": 3376331, + "delta_tx_bytes": 3394989, + "baseline_rss_bytes": 410624000, "peak_memory_bytes": { - "rss": 155930624, - "heap_used": 52559728, - "external": 11541159, - "array_buffers": 7744900 + "rss": 410624000, + "heap_used": 58715704, + "external": 14697744, + "array_buffers": 10896445 }, - "delta_rss_bytes": 6160384, + "delta_rss_bytes": 0, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 3276800, - "attachments.decode.ms": 134.16439100005664, + "attachments.decode.ms": 79.76343099982478, "attachments.proxy.bytes_to_s3": 3276800, "attachments.mark_ready": 25, "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 6751625, - "total_delta_tx_bytes": 6791168, - "rx_bytes_per_upload": 135032, - "tx_bytes_per_upload": 135823, - "max_delta_rss_bytes": 6684672 + "total_delta_rx_bytes": 6751236, + "total_delta_tx_bytes": 6790774, + "rx_bytes_per_upload": 135025, + "tx_bytes_per_upload": 135815, + "max_delta_rss_bytes": 0 } ] } diff --git a/evidence/lab4/bench/proxy-9961472-c10.json b/evidence/lab4/bench/proxy-9961472-c10.json index 71871734..cfe1f948 100644 --- a/evidence/lab4/bench/proxy-9961472-c10.json +++ b/evidence/lab4/bench/proxy-9961472-c10.json @@ -1,6 +1,6 @@ { - "date": "2026-10-23T14:14:21+00:00", - "git": "4b53e03", + "date": "2026-10-23T14:19:32+00:00", + "git": "9caa031", "params": { "mode": "proxy", "size_bytes": 9961472, @@ -23,29 +23,33 @@ "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 2.855, + "outcomes": { + "ok": 50 + }, + "duration_s": 2.923, "latency_ms": { - "p50": 254.6, - "p95": 441.6, - "p99": 469.3 + "p50": 245.8, + "p95": 426.3, + "p99": 473.7 }, "replicas": [ { "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 249684122, - "delta_tx_bytes": 249819648, - "baseline_rss_bytes": 194351104, + "delta_rx_bytes": 249684975, + "delta_tx_bytes": 249854149, + "baseline_rss_bytes": 257658880, "peak_memory_bytes": { - "rss": 243703808, - "heap_used": 49360872, - "external": 68770063, - "array_buffers": 64974750 + "rss": 258445312, + "heap_used": 50586328, + "external": 54821684, + "array_buffers": 51025026 }, - "delta_rss_bytes": 49352704, + "delta_rss_bytes": 786432, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, - "attachments.decode.ms": 317.76610400003847, + "attachments.claim_expired": 1, + "attachments.decode.ms": 319.71605499990983, "attachments.proxy.bytes_to_s3": 249036800, "attachments.mark_ready": 25, "attachments.upload.created": 25 @@ -53,153 +57,158 @@ }, { "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 249687515, - "delta_tx_bytes": 249813144, - "baseline_rss_bytes": 212090880, + "delta_rx_bytes": 249696173, + "delta_tx_bytes": 249850753, + "baseline_rss_bytes": 242159616, "peak_memory_bytes": { - "rss": 245616640, - "heap_used": 49395480, - "external": 62511358, - "array_buffers": 58716046 + "rss": 263458816, + "heap_used": 50272920, + "external": 64509948, + "array_buffers": 60710825 }, - "delta_rss_bytes": 33525760, + "delta_rss_bytes": 21299200, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, - "attachments.decode.ms": 328.639833000052, + "attachments.decode.ms": 417.5356929998379, "attachments.proxy.bytes_to_s3": 249036800, "attachments.mark_ready": 25, - "attachments.upload.created": 25 + "attachments.upload.created": 25, + "attachments.claim_expired": 1 } } ], - "total_delta_rx_bytes": 499371637, - "total_delta_tx_bytes": 499632792, - "rx_bytes_per_upload": 9987433, - "tx_bytes_per_upload": 9992656, - "max_delta_rss_bytes": 49352704 + "total_delta_rx_bytes": 499381148, + "total_delta_tx_bytes": 499704902, + "rx_bytes_per_upload": 9987623, + "tx_bytes_per_upload": 9994098, + "max_delta_rss_bytes": 21299200 }, { "uploads": 50, "succeeded": 50, "failed": 0, - "duration_s": 2.859, + "outcomes": { + "ok": 50 + }, + "duration_s": 2.962, "latency_ms": { - "p50": 218.9, - "p95": 429.5, - "p99": 473.5 + "p50": 218.3, + "p95": 399.3, + "p99": 460.0 }, "replicas": [ { "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 249691287, - "delta_tx_bytes": 249848369, - "baseline_rss_bytes": 243703808, + "delta_rx_bytes": 249696535, + "delta_tx_bytes": 249834513, + "baseline_rss_bytes": 258445312, "peak_memory_bytes": { - "rss": 247758848, - "heap_used": 49779768, - "external": 74267235, - "array_buffers": 70471924 - }, - "delta_rss_bytes": 4055040, - "counters": { - "attachments.insert_pending": 25, - "attachments.proxy.bytes_in": 249036800, - "attachments.decode.ms": 323.61892599996645, - "attachments.proxy.bytes_to_s3": 249036800, - "attachments.mark_ready": 25, - "attachments.upload.created": 25 - } - }, - { - "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 249684697, - "delta_tx_bytes": 249842962, - "baseline_rss_bytes": 204165120, - "peak_memory_bytes": { - "rss": 244056064, - "heap_used": 50327648, - "external": 69652092, - "array_buffers": 65858420 - }, - "delta_rss_bytes": 39890944, - "counters": { - "attachments.insert_pending": 25, - "attachments.proxy.bytes_in": 249036800, - "attachments.decode.ms": 374.5309960000159, - "attachments.proxy.bytes_to_s3": 249036800, - "attachments.mark_ready": 25, - "attachments.upload.created": 25 - } - } - ], - "total_delta_rx_bytes": 499375984, - "total_delta_tx_bytes": 499691331, - "rx_bytes_per_upload": 9987520, - "tx_bytes_per_upload": 9993827, - "max_delta_rss_bytes": 39890944 - }, - { - "uploads": 50, - "succeeded": 50, - "failed": 0, - "duration_s": 2.833, - "latency_ms": { - "p50": 232.3, - "p95": 371.9, - "p99": 484.0 - }, - "replicas": [ - { - "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 249693755, - "delta_tx_bytes": 249824387, - "baseline_rss_bytes": 213168128, - "peak_memory_bytes": { - "rss": 233091072, - "heap_used": 49724808, - "external": 74286513, - "array_buffers": 58931141 + "rss": 278368256, + "heap_used": 51479592, + "external": 64969358, + "array_buffers": 60432585 }, "delta_rss_bytes": 19922944, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, - "attachments.decode.ms": 245.89502999989782, + "attachments.decode.ms": 418.99375499994494, "attachments.proxy.bytes_to_s3": 249036800, "attachments.mark_ready": 25, - "attachments.upload.created": 25, - "attachments.claim_expired": 1 + "attachments.upload.created": 25 } }, { "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 249643327, - "delta_tx_bytes": 249823027, - "baseline_rss_bytes": 214241280, + "delta_rx_bytes": 249668505, + "delta_tx_bytes": 249828657, + "baseline_rss_bytes": 263458816, "peak_memory_bytes": { - "rss": 245899264, - "heap_used": 50003816, - "external": 74661871, - "array_buffers": 52933830 + "rss": 286236672, + "heap_used": 50811912, + "external": 98237420, + "array_buffers": 75492114 }, - "delta_rss_bytes": 31657984, + "delta_rss_bytes": 22777856, "counters": { "attachments.insert_pending": 25, "attachments.proxy.bytes_in": 249036800, - "attachments.decode.ms": 375.14921199998935, + "attachments.decode.ms": 377.89479400013806, "attachments.proxy.bytes_to_s3": 249036800, "attachments.mark_ready": 25, - "attachments.upload.created": 25, - "attachments.claim_expired": 1 + "attachments.upload.created": 25 } } ], - "total_delta_rx_bytes": 499337082, - "total_delta_tx_bytes": 499647414, - "rx_bytes_per_upload": 9986742, - "tx_bytes_per_upload": 9992948, - "max_delta_rss_bytes": 31657984 + "total_delta_rx_bytes": 499365040, + "total_delta_tx_bytes": 499663170, + "rx_bytes_per_upload": 9987301, + "tx_bytes_per_upload": 9993263, + "max_delta_rss_bytes": 22777856 + }, + { + "uploads": 50, + "succeeded": 50, + "failed": 0, + "outcomes": { + "ok": 50 + }, + "duration_s": 2.985, + "latency_ms": { + "p50": 244.7, + "p95": 375.1, + "p99": 434.8 + }, + "replicas": [ + { + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 249713919, + "delta_tx_bytes": 249869668, + "baseline_rss_bytes": 278368256, + "peak_memory_bytes": { + "rss": 280072192, + "heap_used": 51096488, + "external": 54668040, + "array_buffers": 50874378 + }, + "delta_rss_bytes": 1703936, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 249036800, + "attachments.decode.ms": 335.8925800000434, + "attachments.proxy.bytes_to_s3": 249036800, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 + } + }, + { + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 249686633, + "delta_tx_bytes": 249847874, + "baseline_rss_bytes": 243417088, + "peak_memory_bytes": { + "rss": 253378560, + "heap_used": 50078992, + "external": 54471131, + "array_buffers": 50675083 + }, + "delta_rss_bytes": 9961472, + "counters": { + "attachments.insert_pending": 25, + "attachments.proxy.bytes_in": 249036800, + "attachments.decode.ms": 318.2283639999805, + "attachments.proxy.bytes_to_s3": 249036800, + "attachments.mark_ready": 25, + "attachments.upload.created": 25 + } + } + ], + "total_delta_rx_bytes": 499400552, + "total_delta_tx_bytes": 499717542, + "rx_bytes_per_upload": 9988011, + "tx_bytes_per_upload": 9994351, + "max_delta_rss_bytes": 9961472 } ] } diff --git a/evidence/lab4/bench/proxy-9961472-c20.json b/evidence/lab4/bench/proxy-9961472-c20.json index d21da563..7dc09983 100644 --- a/evidence/lab4/bench/proxy-9961472-c20.json +++ b/evidence/lab4/bench/proxy-9961472-c20.json @@ -1,6 +1,6 @@ { - "date": "2026-10-23T14:15:00+00:00", - "git": "4b53e03", + "date": "2026-10-23T14:20:13+00:00", + "git": "9caa031", "params": { "mode": "proxy", "size_bytes": 9961472, @@ -23,29 +23,32 @@ "uploads": 100, "succeeded": 100, "failed": 0, - "duration_s": 5.725, + "outcomes": { + "ok": 100 + }, + "duration_s": 6.03, "latency_ms": { - "p50": 386.4, - "p95": 694.0, - "p99": 1065.1 + "p50": 446.3, + "p95": 781.2, + "p99": 875.5 }, "replicas": [ { "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 499431062, - "delta_tx_bytes": 499720016, - "baseline_rss_bytes": 219865088, + "delta_rx_bytes": 499450818, + "delta_tx_bytes": 499682679, + "baseline_rss_bytes": 260186112, "peak_memory_bytes": { - "rss": 256589824, - "heap_used": 50949776, - "external": 78382688, - "array_buffers": 74585512 + "rss": 270147584, + "heap_used": 50815808, + "external": 74823876, + "array_buffers": 71026869 }, - "delta_rss_bytes": 36724736, + "delta_rss_bytes": 9961472, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, - "attachments.decode.ms": 752.4353919999558, + "attachments.decode.ms": 747.5779010000988, "attachments.proxy.bytes_to_s3": 498073600, "attachments.mark_ready": 50, "attachments.upload.created": 50 @@ -53,59 +56,62 @@ }, { "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 499402749, - "delta_tx_bytes": 499684515, - "baseline_rss_bytes": 205688832, + "delta_rx_bytes": 499478040, + "delta_tx_bytes": 499706687, + "baseline_rss_bytes": 233414656, "peak_memory_bytes": { - "rss": 253865984, - "heap_used": 50007064, - "external": 77441306, - "array_buffers": 73644321 + "rss": 272007168, + "heap_used": 51073272, + "external": 81928377, + "array_buffers": 78003733 }, - "delta_rss_bytes": 48177152, + "delta_rss_bytes": 38592512, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, - "attachments.decode.ms": 689.5382070000051, + "attachments.decode.ms": 729.9557609999902, "attachments.proxy.bytes_to_s3": 498073600, "attachments.mark_ready": 50, "attachments.upload.created": 50 } } ], - "total_delta_rx_bytes": 998833811, - "total_delta_tx_bytes": 999404531, - "rx_bytes_per_upload": 9988338, - "tx_bytes_per_upload": 9994045, - "max_delta_rss_bytes": 48177152 + "total_delta_rx_bytes": 998928858, + "total_delta_tx_bytes": 999389366, + "rx_bytes_per_upload": 9989289, + "tx_bytes_per_upload": 9993894, + "max_delta_rss_bytes": 38592512 }, { "uploads": 100, "succeeded": 100, "failed": 0, - "duration_s": 5.595, + "outcomes": { + "ok": 100 + }, + "duration_s": 5.959, "latency_ms": { - "p50": 416.1, - "p95": 850.5, - "p99": 1043.3 + "p50": 433.3, + "p95": 826.3, + "p99": 1157.3 }, "replicas": [ { "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 499433153, - "delta_tx_bytes": 499703916, - "baseline_rss_bytes": 232402944, + "delta_rx_bytes": 499374042, + "delta_tx_bytes": 499651950, + "baseline_rss_bytes": 270147584, "peak_memory_bytes": { - "rss": 259272704, - "heap_used": 51280096, - "external": 72760119, - "array_buffers": 68966438 + "rss": 272506880, + "heap_used": 51829328, + "external": 83084989, + "array_buffers": 79288011 }, - "delta_rss_bytes": 26869760, + "delta_rss_bytes": 2359296, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, - "attachments.decode.ms": 696.6430249999976, + "attachments.decode.ms": 779.4219730002806, "attachments.proxy.bytes_to_s3": 498073600, "attachments.mark_ready": 50, "attachments.upload.created": 50 @@ -113,59 +119,62 @@ }, { "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 499356462, - "delta_tx_bytes": 499635353, - "baseline_rss_bytes": 218791936, + "delta_rx_bytes": 499493122, + "delta_tx_bytes": 499744106, + "baseline_rss_bytes": 223895552, "peak_memory_bytes": { - "rss": 269750272, - "heap_used": 50527976, - "external": 84610578, - "array_buffers": 80809839 + "rss": 268492800, + "heap_used": 51545968, + "external": 74440258, + "array_buffers": 70643266 }, - "delta_rss_bytes": 50958336, + "delta_rss_bytes": 44597248, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, - "attachments.decode.ms": 679.306210000097, + "attachments.decode.ms": 863.9362580000306, "attachments.proxy.bytes_to_s3": 498073600, "attachments.mark_ready": 50, "attachments.upload.created": 50 } } ], - "total_delta_rx_bytes": 998789615, - "total_delta_tx_bytes": 999339269, - "rx_bytes_per_upload": 9987896, - "tx_bytes_per_upload": 9993393, - "max_delta_rss_bytes": 50958336 + "total_delta_rx_bytes": 998867164, + "total_delta_tx_bytes": 999396056, + "rx_bytes_per_upload": 9988672, + "tx_bytes_per_upload": 9993961, + "max_delta_rss_bytes": 44597248 }, { "uploads": 100, "succeeded": 100, "failed": 0, - "duration_s": 5.614, + "outcomes": { + "ok": 100 + }, + "duration_s": 5.867, "latency_ms": { - "p50": 428.0, - "p95": 804.7, - "p99": 1004.9 + "p50": 425.4, + "p95": 748.6, + "p99": 899.5 }, "replicas": [ { "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 499425024, - "delta_tx_bytes": 499698391, - "baseline_rss_bytes": 229511168, + "delta_rx_bytes": 499413858, + "delta_tx_bytes": 499718735, + "baseline_rss_bytes": 272506880, "peak_memory_bytes": { - "rss": 276029440, - "heap_used": 50966520, - "external": 81342826, - "array_buffers": 77549156 + "rss": 282468352, + "heap_used": 51214136, + "external": 94183394, + "array_buffers": 90388084 }, - "delta_rss_bytes": 46518272, + "delta_rss_bytes": 9961472, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, - "attachments.decode.ms": 690.9916989999474, + "attachments.decode.ms": 737.3356790000107, "attachments.proxy.bytes_to_s3": 498073600, "attachments.mark_ready": 50, "attachments.upload.created": 50 @@ -173,31 +182,31 @@ }, { "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 499340690, - "delta_tx_bytes": 499623342, - "baseline_rss_bytes": 209854464, + "delta_rx_bytes": 499436776, + "delta_tx_bytes": 499691520, + "baseline_rss_bytes": 224206848, "peak_memory_bytes": { - "rss": 269647872, - "heap_used": 50830664, - "external": 84194138, - "array_buffers": 71282017 + "rss": 287236096, + "heap_used": 51412744, + "external": 94514510, + "array_buffers": 90719177 }, - "delta_rss_bytes": 59793408, + "delta_rss_bytes": 63029248, "counters": { "attachments.insert_pending": 50, "attachments.proxy.bytes_in": 498073600, - "attachments.decode.ms": 772.5123690000619, + "attachments.decode.ms": 632.1155839997809, "attachments.proxy.bytes_to_s3": 498073600, "attachments.mark_ready": 50, "attachments.upload.created": 50 } } ], - "total_delta_rx_bytes": 998765714, - "total_delta_tx_bytes": 999321733, - "rx_bytes_per_upload": 9987657, - "tx_bytes_per_upload": 9993217, - "max_delta_rss_bytes": 59793408 + "total_delta_rx_bytes": 998850634, + "total_delta_tx_bytes": 999410255, + "rx_bytes_per_upload": 9988506, + "tx_bytes_per_upload": 9994103, + "max_delta_rss_bytes": 63029248 } ] } diff --git a/evidence/lab4/bench/proxy-worst-c32.json b/evidence/lab4/bench/proxy-worst-c32.json index baf34847..58fac4ca 100644 --- a/evidence/lab4/bench/proxy-worst-c32.json +++ b/evidence/lab4/bench/proxy-worst-c32.json @@ -1,6 +1,6 @@ { - "date": "2026-10-23T14:16:28+00:00", - "git": "4b53e03", + "date": "2026-10-23T14:21:43+00:00", + "git": "9caa031", "params": { "mode": "proxy", "size_bytes": 10485760, @@ -8,7 +8,7 @@ "uploads_per_worker": 2, "repeat": 3, "users": 32, - "image": "tmp.n0I8NPEIWj.png" + "image": "worst-40mp-rgba16-adam7.png" }, "host": { "nproc": 8, @@ -23,91 +23,33 @@ "uploads": 64, "succeeded": 63, "failed": 1, - "duration_s": 25.819, + "outcomes": { + "ok": 63, + "upload:429": 1 + }, + "duration_s": 26.314, "latency_ms": { - "p50": 11818.4, - "p95": 12931.4, - "p99": 13553.9 + "p50": 11982.1, + "p95": 13221.2, + "p99": 13881.3 }, "replicas": [ { "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 337133327, - "delta_tx_bytes": 326730589, - "baseline_rss_bytes": 242167808, + "delta_rx_bytes": 337116624, + "delta_tx_bytes": 326709435, + "baseline_rss_bytes": 280637440, "peak_memory_bytes": { - "rss": 764227584, - "heap_used": 53277928, - "external": 205747809, - "array_buffers": 201957465 + "rss": 794800128, + "heap_used": 52577168, + "external": 200629533, + "array_buffers": 196839189 }, - "delta_rss_bytes": 522059776, + "delta_rss_bytes": 514162688, "counters": { "attachments.insert_pending": 31, "attachments.proxy.bytes_in": 325058560, - "attachments.decode.ms": 25036.73668600002, - "attachments.proxy.bytes_to_s3": 325058560, - "attachments.mark_ready": 31, - "attachments.upload.created": 31, - "attachments.claim_expired": 1 - } - }, - { - "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 337211779, - "delta_tx_bytes": 337283965, - "baseline_rss_bytes": 228610048, - "peak_memory_bytes": { - "rss": 778199040, - "heap_used": 51989272, - "external": 236791924, - "array_buffers": 233001507 - }, - "delta_rss_bytes": 549588992, - "counters": { - "attachments.insert_pending": 32, - "attachments.proxy.bytes_in": 335544320, - "attachments.decode.ms": 25586.631086000038, - "attachments.proxy.bytes_to_s3": 335544320, - "attachments.mark_ready": 32, - "attachments.upload.created": 32, - "attachments.claim_expired": 1 - } - } - ], - "total_delta_rx_bytes": 674345106, - "total_delta_tx_bytes": 664014554, - "rx_bytes_per_upload": 10536642, - "tx_bytes_per_upload": 10375227, - "max_delta_rss_bytes": 549588992 - }, - { - "uploads": 64, - "succeeded": 63, - "failed": 1, - "duration_s": 25.757, - "latency_ms": { - "p50": 11572.1, - "p95": 12715.5, - "p99": 13392.7 - }, - "replicas": [ - { - "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 334592209, - "delta_tx_bytes": 326276198, - "baseline_rss_bytes": 398258176, - "peak_memory_bytes": { - "rss": 783015936, - "heap_used": 55518080, - "external": 207730225, - "array_buffers": 203939881 - }, - "delta_rss_bytes": 384757760, - "counters": { - "attachments.insert_pending": 31, - "attachments.proxy.bytes_in": 325058560, - "attachments.decode.ms": 24831.425972000143, + "attachments.decode.ms": 25555.52753299987, "attachments.proxy.bytes_to_s3": 325058560, "attachments.mark_ready": 31, "attachments.upload.created": 31 @@ -115,81 +57,148 @@ }, { "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 336487647, - "delta_tx_bytes": 336637754, - "baseline_rss_bytes": 402874368, + "delta_rx_bytes": 337265287, + "delta_tx_bytes": 337358402, + "baseline_rss_bytes": 243548160, "peak_memory_bytes": { - "rss": 798023680, - "heap_used": 53729504, - "external": 238180613, - "array_buffers": 234390237 + "rss": 810434560, + "heap_used": 53145984, + "external": 236705259, + "array_buffers": 220341467 }, - "delta_rss_bytes": 395149312, + "delta_rss_bytes": 566886400, "counters": { "attachments.insert_pending": 32, "attachments.proxy.bytes_in": 335544320, - "attachments.decode.ms": 25634.232347999874, + "attachments.decode.ms": 26139.059334000223, "attachments.proxy.bytes_to_s3": 335544320, "attachments.mark_ready": 32, "attachments.upload.created": 32 } } ], - "total_delta_rx_bytes": 671079856, - "total_delta_tx_bytes": 662913952, - "rx_bytes_per_upload": 10485623, - "tx_bytes_per_upload": 10358030, - "max_delta_rss_bytes": 395149312 + "total_delta_rx_bytes": 674381911, + "total_delta_tx_bytes": 664067837, + "rx_bytes_per_upload": 10537217, + "tx_bytes_per_upload": 10376060, + "max_delta_rss_bytes": 566886400 }, { "uploads": 64, "succeeded": 63, "failed": 1, - "duration_s": 25.464, + "outcomes": { + "ok": 63, + "upload:429": 1 + }, + "duration_s": 26.067, "latency_ms": { - "p50": 11705.5, - "p95": 12780.4, - "p99": 13430.4 + "p50": 11840.4, + "p95": 12960.2, + "p99": 13468.5 }, "replicas": [ { "instance_id": "90e2e1d73b23", - "delta_rx_bytes": 336576208, - "delta_tx_bytes": 326212836, - "baseline_rss_bytes": 429645824, + "delta_rx_bytes": 336715328, + "delta_tx_bytes": 326375446, + "baseline_rss_bytes": 440582144, "peak_memory_bytes": { - "rss": 788910080, - "heap_used": 51970176, - "external": 237910954, - "array_buffers": 234120537 + "rss": 792059904, + "heap_used": 56538592, + "external": 222265987, + "array_buffers": 218475643 }, - "delta_rss_bytes": 359264256, + "delta_rss_bytes": 351477760, "counters": { "attachments.insert_pending": 31, "attachments.proxy.bytes_in": 325058560, - "attachments.decode.ms": 24706.14007100009, + "attachments.decode.ms": 25179.0629260001, "attachments.proxy.bytes_to_s3": 325058560, "attachments.mark_ready": 31, - "attachments.upload.created": 31, + "attachments.upload.created": 31 + } + }, + { + "instance_id": "9bb9a19b4693", + "delta_rx_bytes": 336711646, + "delta_tx_bytes": 336796533, + "baseline_rss_bytes": 456798208, + "peak_memory_bytes": { + "rss": 804114432, + "heap_used": 56361496, + "external": 227834931, + "array_buffers": 224044587 + }, + "delta_rss_bytes": 347316224, + "counters": { + "attachments.insert_pending": 32, + "attachments.proxy.bytes_in": 335544320, + "attachments.decode.ms": 25936.202234999975, + "attachments.proxy.bytes_to_s3": 335544320, + "attachments.mark_ready": 32, + "attachments.upload.created": 32 + } + } + ], + "total_delta_rx_bytes": 673426974, + "total_delta_tx_bytes": 663171979, + "rx_bytes_per_upload": 10522296, + "tx_bytes_per_upload": 10362062, + "max_delta_rss_bytes": 351477760 + }, + { + "uploads": 64, + "succeeded": 64, + "failed": 0, + "outcomes": { + "ok": 64 + }, + "duration_s": 26.191, + "latency_ms": { + "p50": 12369.3, + "p95": 13068.5, + "p99": 13838.5 + }, + "replicas": [ + { + "instance_id": "90e2e1d73b23", + "delta_rx_bytes": 336907021, + "delta_tx_bytes": 336990630, + "baseline_rss_bytes": 438906880, + "peak_memory_bytes": { + "rss": 812994560, + "heap_used": 53308256, + "external": 217363492, + "array_buffers": 213573148 + }, + "delta_rss_bytes": 374087680, + "counters": { + "attachments.insert_pending": 32, + "attachments.proxy.bytes_in": 335544320, + "attachments.decode.ms": 25964.192683000234, + "attachments.proxy.bytes_to_s3": 335544320, + "attachments.mark_ready": 32, + "attachments.upload.created": 32, "attachments.claim_expired": 1 } }, { "instance_id": "9bb9a19b4693", - "delta_rx_bytes": 336605411, - "delta_tx_bytes": 336677870, - "baseline_rss_bytes": 444702720, + "delta_rx_bytes": 336764548, + "delta_tx_bytes": 336853328, + "baseline_rss_bytes": 451035136, "peak_memory_bytes": { - "rss": 810758144, - "heap_used": 54356496, - "external": 217451321, - "array_buffers": 213660977 + "rss": 822910976, + "heap_used": 51718280, + "external": 238155032, + "array_buffers": 234364688 }, - "delta_rss_bytes": 366055424, + "delta_rss_bytes": 371875840, "counters": { "attachments.insert_pending": 32, "attachments.proxy.bytes_in": 335544320, - "attachments.decode.ms": 25312.452498999774, + "attachments.decode.ms": 25902.83660300006, "attachments.proxy.bytes_to_s3": 335544320, "attachments.mark_ready": 32, "attachments.upload.created": 32, @@ -197,11 +206,11 @@ } } ], - "total_delta_rx_bytes": 673181619, - "total_delta_tx_bytes": 662890706, - "rx_bytes_per_upload": 10518463, - "tx_bytes_per_upload": 10357667, - "max_delta_rss_bytes": 366055424 + "total_delta_rx_bytes": 673671569, + "total_delta_tx_bytes": 673843958, + "rx_bytes_per_upload": 10526118, + "tx_bytes_per_upload": 10528812, + "max_delta_rss_bytes": 374087680 } ] } diff --git a/evidence/lab4/consistency.txt b/evidence/lab4/consistency.txt index fe77da37..cde6d533 100644 --- a/evidence/lab4/consistency.txt +++ b/evidence/lab4/consistency.txt @@ -1,9 +1,9 @@ scripts/lab4/consistency_check.sh bucket: messenger-attachments -objects: 5066 +objects: 8398 rows by status: - 11 pending - 5065 ready + 84 pending + 8324 ready 4 rejected orphans: 0 missing: 0 diff --git a/evidence/lab4/failover-attachment.txt b/evidence/lab4/failover-attachment.txt index 8a642656..228475c3 100644 --- a/evidence/lab4/failover-attachment.txt +++ b/evidence/lab4/failover-attachment.txt @@ -1,11 +1,11 @@ -# attachment download survives the stop of either replica (sha256 of sample.png: 99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75) +# commit 9caa031; attachment download survives the stop of either replica (sha256 of sample.png: 99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75) stopped mtusi-lab4-api-1 - GET content -> HTTP/1.1 200 OK x-instance-id: fc61f806b880 sha256=99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75 - GET content -> HTTP/1.1 200 OK x-instance-id: fc61f806b880 sha256=99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75 - GET content -> HTTP/1.1 200 OK x-instance-id: fc61f806b880 sha256=99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75 + GET content -> HTTP/1.1 200 OK x-instance-id: 9bb9a19b4693 sha256=99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75 + GET content -> HTTP/1.1 200 OK x-instance-id: 9bb9a19b4693 sha256=99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75 + GET content -> HTTP/1.1 200 OK x-instance-id: 9bb9a19b4693 sha256=99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75 stopped mtusi-lab4-api-2 - GET content -> HTTP/1.1 200 OK x-instance-id: b50bb8514a7b sha256=99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75 - GET content -> HTTP/1.1 200 OK x-instance-id: b50bb8514a7b sha256=99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75 - GET content -> HTTP/1.1 200 OK x-instance-id: b50bb8514a7b sha256=99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75 + GET content -> HTTP/1.1 200 OK x-instance-id: 90e2e1d73b23 sha256=99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75 + GET content -> HTTP/1.1 200 OK x-instance-id: 90e2e1d73b23 sha256=99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75 + GET content -> HTTP/1.1 200 OK x-instance-id: 90e2e1d73b23 sha256=99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75 mtusi-lab4-api-1 Up 14 seconds (healthy) mtusi-lab4-api-2 Up 5 seconds (healthy) diff --git a/evidence/lab4/failover.txt b/evidence/lab4/failover.txt index c2f9f401..0478cc62 100644 --- a/evidence/lab4/failover.txt +++ b/evidence/lab4/failover.txt @@ -1,21 +1,13 @@ +# commit 9caa031 # failover round 1 -python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "http://localhost:8080" -Executing explicit failover hook; hook output suppressed to avoid leaking secrets. -{"observed_instances_before": 2, "successful_writes": 140, "failed_attempts": 0, "first_recovery_seconds": 3.331} +{"observed_instances_before": 2, "successful_writes": 133, "failed_attempts": 0, "first_recovery_seconds": 3.184} PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence. -api mtusi-lab4-api-1 Up 26 seconds (healthy) - Container mtusi-lab4-api-1 Running +mtusi-lab4-api-1 Exited (0) 12 seconds ago +mtusi-lab4-api-2 Up 31 seconds (healthy) # failover round 2 -Executing explicit failover hook; hook output suppressed to avoid leaking secrets. -{"observed_instances_before": 2, "successful_writes": 134, "failed_attempts": 0, "first_recovery_seconds": 3.359} +{"observed_instances_before": 2, "successful_writes": 141, "failed_attempts": 0, "first_recovery_seconds": 3.249} PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence. -mtusi-lab4-api-1 Up 50 seconds (healthy) -mtusi-lab4-api-2 Exited (0) 12 seconds ago -# failover round 3 -Executing explicit failover hook; hook output suppressed to avoid leaking secrets. -{"observed_instances_before": 2, "successful_writes": 134, "failed_attempts": 0, "first_recovery_seconds": 3.328} -PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence. -mtusi-lab4-api-1 Up About a minute (healthy) -mtusi-lab4-api-2 Exited (0) 12 seconds ago -mtusi-lab4-api-1 Up About a minute (healthy) -mtusi-lab4-api-2 Up 5 seconds (healthy) +mtusi-lab4-api-1 Exited (0) 12 seconds ago +mtusi-lab4-api-2 Up 53 seconds (healthy) +mtusi-lab4-api-1 Up 5 seconds (healthy) +mtusi-lab4-api-2 Up 58 seconds (healthy) diff --git a/evidence/lab4/persistence.txt b/evidence/lab4/persistence.txt index 1d5f8889..c5b981e2 100644 --- a/evidence/lab4/persistence.txt +++ b/evidence/lab4/persistence.txt @@ -1,29 +1,18 @@ +# commit 9caa031 # before -api Up 19 seconds (healthy) -api Up 19 seconds (healthy) -haproxy Up 11 minutes -postgres Up 2 minutes (healthy) -redis Up 3 minutes (healthy) -s3 Up 3 minutes (healthy) -/mtusi-lab4-postgres-1 2026-10-22T19:38:19.352217508Z -/mtusi-lab4-redis-1 2026-10-22T19:37:15.343086395Z -/mtusi-lab4-s3-1 2026-10-22T19:37:46.289807129Z -/mtusi-lab4-api-1 2026-10-22T19:40:39.879853813Z -/mtusi-lab4-api-2 2026-10-22T19:40:39.774525559Z -/mtusi-lab4-haproxy-1 2026-10-22T19:29:53.978761189Z +/mtusi-lab4-postgres-1 2026-10-23T14:13:29.263262079Z +/mtusi-lab4-redis-1 2026-10-23T14:11:34.042926489Z +/mtusi-lab4-s3-1 2026-10-23T14:12:05.200412031Z +/mtusi-lab4-api-1 2026-10-23T14:11:19.011665615Z +/mtusi-lab4-api-2 2026-10-23T14:11:19.118116521Z +/mtusi-lab4-haproxy-1 2026-10-22T19:41:00.434084255Z python3 tests/resilience.py --mode persistence --action-script "scripts/restart.sh" --base-url "http://localhost:8080" Executing explicit persistence hook; hook output suppressed to avoid leaking secrets. PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence. # after -api Up 6 seconds (healthy) -api Up 6 seconds (healthy) -haproxy Up 9 seconds -postgres Up 9 seconds (healthy) -redis Up 9 seconds (healthy) -s3 Up 9 seconds (healthy) -/mtusi-lab4-postgres-1 2026-10-22T19:41:00.616425802Z -/mtusi-lab4-redis-1 2026-10-22T19:41:00.545701172Z -/mtusi-lab4-s3-1 2026-10-22T19:41:00.507714044Z -/mtusi-lab4-api-1 2026-10-22T19:41:03.631509569Z -/mtusi-lab4-api-2 2026-10-22T19:41:03.665389961Z -/mtusi-lab4-haproxy-1 2026-10-22T19:41:00.434084255Z +/mtusi-lab4-postgres-1 2026-10-23T14:23:26.500579665Z +/mtusi-lab4-redis-1 2026-10-23T14:23:26.233233745Z +/mtusi-lab4-s3-1 2026-10-23T14:23:26.420908434Z +/mtusi-lab4-api-1 2026-10-23T14:23:29.194759152Z +/mtusi-lab4-api-2 2026-10-23T14:23:29.224476065Z +/mtusi-lab4-haproxy-1 2026-10-23T14:23:26.32966444Z diff --git a/evidence/lab4/summary.md b/evidence/lab4/summary.md index 679f503e..632d95f2 100644 --- a/evidence/lab4/summary.md +++ b/evidence/lab4/summary.md @@ -1,11 +1,11 @@ -| mode | size, MiB | C | ok | API rx/upload, MiB | API tx/upload, MiB | max Δrss, MiB | peak RSS, MiB | p50, ms | p95, ms | -|---|---|---|---|---|---|---|---|---|---| -| direct | 0.12 | 10 | 150/150 | 0.13 | 0.01 | 2.00 | 158.24 | 45 | 70 | -| proxy | 0.12 | 10 | 150/150 | 0.13 | 0.13 | 6.38 | 149.36 | 28 | 49 | -| direct | 1.00 | 10 | 150/150 | 1.01 | 0.01 | 16.06 | 199.36 | 76 | 104 | -| proxy | 1.00 | 10 | 150/150 | 1.01 | 1.01 | 8.75 | 183.10 | 56 | 100 | -| direct | 9.50 | 10 | 150/150 | 9.52 | 0.01 | 88.92 | 286.69 | 425 | 615 | -| proxy | 9.50 | 10 | 150/150 | 9.52 | 9.53 | 38.04 | 236.28 | 232 | 430 | -| proxy | 9.50 | 20 | 300/300 | 9.53 | 9.53 | 48.60 | 263.24 | 416 | 805 | -| direct (tmp.n0I8NPEIWj.png) | 10.00 | 32 | 144/192 | 7.52 | 0.01 | 366.84 | 787.07 | 10903 | 13413 | -| proxy (tmp.n0I8NPEIWj.png) | 10.00 | 32 | 189/192 | 10.03 | 9.88 | 376.84 | 773.20 | 11706 | 12780 | +| mode | size, MiB | C | ok | failures | API rx/upload, MiB | API tx/upload, MiB | max Δrss, MiB | peak RSS, MiB | p50, ms | p95, ms | +|---|---|---|---|---|---|---|---|---|---|---| +| direct | 0.12 | 10 | 150/150 | — | 0.13 | 0.01 | 0.38 | 394.39 | 40 | 71 | +| proxy | 0.12 | 10 | 150/150 | — | 0.13 | 0.13 | 0.00 | 446.99 | 26 | 46 | +| direct | 1.00 | 10 | 150/150 | — | 1.01 | 0.01 | 0.00 | 244.16 | 71 | 107 | +| proxy | 1.00 | 10 | 150/150 | — | 1.01 | 1.01 | 0.12 | 394.70 | 50 | 82 | +| direct | 9.50 | 10 | 150/150 | — | 9.52 | 0.01 | 67.06 | 344.15 | 448 | 672 | +| proxy | 9.50 | 10 | 150/150 | — | 9.52 | 9.53 | 20.31 | 272.98 | 245 | 399 | +| proxy | 9.50 | 20 | 300/300 | — | 9.53 | 9.53 | 42.53 | 273.93 | 433 | 781 | +| direct (worst-40mp-rgba16-adam7.png) | 10.00 | 32 | 167/192 | complete:429×25 | 9.24 | 0.01 | 366.88 | 790.94 | 11067 | 13423 | +| proxy (worst-40mp-rgba16-adam7.png) | 10.00 | 32 | 190/192 | upload:429×2 | 10.04 | 9.90 | 356.76 | 784.79 | 11982 | 13068 | -- 2.54.0 From abba248020df502730bb3a8dba0a03dacf2ec4fe Mon Sep 17 00:00:00 2001 From: Ilya Date: Fri, 23 Oct 2026 17:27:48 +0300 Subject: [PATCH 15/15] =?UTF-8?q?lab4:=20REPORT=20=E2=80=94=20=D0=B1=D0=B5?= =?UTF-8?q?=D0=B7=D0=BE=D0=BF=D0=B0=D1=81=D0=BD=D0=B0=D1=8F=20=D1=81=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D0=BA=D0=B0=20.env?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- REPORT.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/REPORT.md b/REPORT.md index 91828976..0855bebf 100644 --- a/REPORT.md +++ b/REPORT.md @@ -37,9 +37,10 @@ make test-failover ACTION_SCRIPT=scripts/stop-one.sh && scripts/start-replica.sh ``` Действия оператора: только `make init-env`. Он не перезаписывает существующий `.env`: при обновлении с -предыдущей версии сверьте его с `.env.example` (`diff <(grep -o '^[A-Z_0-9]*=[^#]*' .env.example) .env`), -иначе останутся старые лимиты (так один из прогонов этой работы шёл с `UPLOAD_MAX_IN_FLIGHT=32`). -Далее — (секреты создаются локально в `secrets/`, каталог в +предыдущей версии сверьте несекретные значения с `.env.example` (команда не печатает секреты): +`diff <(grep -vE '^(POSTGRES_PASSWORD|DATABASE_URL|METRICS_TOKEN)=' .env.example) <(grep -vE '^(POSTGRES_PASSWORD|DATABASE_URL|METRICS_TOKEN)=' .env)` +— иначе останутся старые лимиты (так один из прогонов этой работы шёл с `UPLOAD_MAX_IN_FLIGHT=32`). +Секреты создаются локально в `secrets/` (каталог в `.gitignore`; `secrets/` и `.env` нельзя коммитить). Остановка с сохранением данных — `make stand-down` (тома `postgres-data`, `redis-data`, `s3-data` сохраняются). **Намеренное удаление учебных данных:** `docker compose --env-file .env down -v` (удаляет все три тома, включая загруженные файлы; следующий -- 2.54.0