diff --git a/.dockerignore b/.dockerignore index bc16e556..4fc15f64 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,8 +1,8 @@ .git .github +.gitignore .env .env.* -!.env.example secrets certs volumes @@ -17,4 +17,22 @@ backups __pycache__ node_modules evidence +examples +scripts +tests +*.md +Dockerfile* +Makefile +requirements-dev.txt +lab.json .DS_Store + +.idea +.vscode +.agents +.codex + +**/.env +**/.env.* +**/.idea +**/.vscode diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..69970d6c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,67 @@ +FROM golang:1.26.4-alpine3.23@sha256:18b460dd17542c2ba43299a633cf6ebfc1115101509531471d7cfce1019af083 AS goose-builder +RUN GOMAXPROCS=2 GOFLAGS=-p=1 GOBIN=/out CGO_ENABLED=0 go install \ + -tags='no_clickhouse no_libsql no_mssql no_mysql no_sqlite3 no_vertica no_ydb no_spanner' \ + github.com/pressly/goose/v3/cmd/goose@v3.27.1 + +FROM alpine:3.23@sha256:075c2c1a4068c1e251228ca2b0ea8b163f835ca5d66e758b93c7fc89b1995616 AS migrations +COPY --from=goose-builder /out/goose /usr/local/bin/goose +COPY migrations /migrations +COPY infra/migrate.sh /usr/local/bin/migrate +USER 10001:10001 +ENTRYPOINT ["/usr/local/bin/migrate"] +CMD ["up"] + +FROM golang:1.26.4-alpine3.23@sha256:18b460dd17542c2ba43299a633cf6ebfc1115101509531471d7cfce1019af083 AS builder + +WORKDIR /src + +RUN apk add --no-cache gcc musl-dev + +COPY go.mod go.sum ./ +RUN go mod download + +COPY cmd ./cmd +COPY contracts ./contracts +COPY dto ./dto +COPY internal ./internal +COPY migrations ./migrations +ENV GOFLAGS=-p=1 GOMAXPROCS=2 + +RUN CGO_ENABLED=0 GOOS=linux go build \ + -trimpath \ + -ldflags="-s -w" \ + -o /out/messenger ./cmd +RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/reconcile ./cmd/reconcile + +RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/worker ./cmd/worker + +FROM builder AS tests +COPY --from=goose-builder /out/goose /usr/local/bin/goose +ENV GOOSE_MIGRATION_DIR=/src/migrations +CMD ["go", "test", "-p=1", "-race", "-count=1", "-v", "./..."] + +FROM alpine:3.23@sha256:075c2c1a4068c1e251228ca2b0ea8b163f835ca5d66e758b93c7fc89b1995616 + +RUN apk add --no-cache libwebp-tools=1.6.0-r0 + +RUN addgroup -S messenger \ + && adduser -S -D -H -u 10001 -G messenger messenger + +COPY --from=builder --chown=messenger:messenger /out/messenger /usr/local/bin/messenger + +COPY --from=builder --chown=messenger:messenger /out/reconcile /usr/local/bin/reconcile + +COPY --from=builder --chown=messenger:messenger /out/worker /usr/local/bin/worker + +ENV PORT=8080 + +EXPOSE 8080 + +USER messenger:messenger + +HEALTHCHECK --interval=10s --timeout=3s --start-period=3s --retries=3 \ + CMD wget -q -O /dev/null "http://127.0.0.1:${PORT}/health/ready" || exit 1 + +STOPSIGNAL SIGTERM + +ENTRYPOINT ["/usr/local/bin/messenger"] diff --git a/Dockerfile.storage b/Dockerfile.storage new file mode 100644 index 00000000..8b7f7d0a --- /dev/null +++ b/Dockerfile.storage @@ -0,0 +1,34 @@ +FROM golang:1.26.4-alpine3.23@sha256:18b460dd17542c2ba43299a633cf6ebfc1115101509531471d7cfce1019af083 AS minio-builder +ADD --checksum=sha256:8b11129f6a6830768bcdebab569290ad956618f5ff6ef4857b633acb64f95126 https://codeload.github.com/minio/minio/tar.gz/01ce918d8279a20e4706b96a64396146894adee4 /tmp/source.tar.gz +RUN mkdir /src && tar -xzf /tmp/source.tar.gz -C /src --strip-components=1 +WORKDIR /src +RUN CGO_ENABLED=0 go build -trimpath -ldflags='-s -w' -o /out/minio . +RUN echo '8b11129f6a6830768bcdebab569290ad956618f5ff6ef4857b633acb64f95126 /tmp/source.tar.gz' | sha256sum -c - + +FROM golang:1.26.4-alpine3.23@sha256:18b460dd17542c2ba43299a633cf6ebfc1115101509531471d7cfce1019af083 AS mc-builder +ADD --checksum=sha256:4cea8ed209c8f96e59ea1a5cc4901019b54c2be6d6f5f16c6749ea8bdcf4172e https://codeload.github.com/minio/mc/tar.gz/d6541ea280b73a834b64d4097e21f2be77676104 /tmp/source.tar.gz +RUN mkdir /src && tar -xzf /tmp/source.tar.gz -C /src --strip-components=1 +WORKDIR /src +RUN CGO_ENABLED=0 go build -trimpath -ldflags='-s -w' -o /out/mc . +RUN echo '4cea8ed209c8f96e59ea1a5cc4901019b54c2be6d6f5f16c6749ea8bdcf4172e /tmp/source.tar.gz' | sha256sum -c - + +FROM alpine:3.23@sha256:075c2c1a4068c1e251228ca2b0ea8b163f835ca5d66e758b93c7fc89b1995616 AS minio +LABEL org.opencontainers.image.source="https://github.com/minio/minio" \ + org.opencontainers.image.revision="01ce918d8279a20e4706b96a64396146894adee4" \ + org.opencontainers.image.version="RELEASE.2025-09-07T16-13-09Z" \ + org.opencontainers.image.licenses="AGPL-3.0" +RUN mkdir /data && chown 10001:10001 /data +COPY --from=minio-builder /out/minio /usr/local/bin/minio +COPY infra/minio-entrypoint.sh /usr/local/bin/start-minio +USER 10001:10001 +EXPOSE 9000 +ENTRYPOINT ["/usr/local/bin/start-minio"] + +FROM alpine:3.23@sha256:075c2c1a4068c1e251228ca2b0ea8b163f835ca5d66e758b93c7fc89b1995616 AS mc +LABEL org.opencontainers.image.source="https://github.com/minio/mc" \ + org.opencontainers.image.revision="d6541ea280b73a834b64d4097e21f2be77676104" \ + org.opencontainers.image.version="RELEASE.2025-08-13T08-35-41Z" \ + org.opencontainers.image.licenses="AGPL-3.0" +COPY --from=mc-builder /out/mc /usr/local/bin/mc +USER 10001:10001 +ENTRYPOINT ["mc"] diff --git a/Makefile b/Makefile index 5d86d171..6f2aa27c 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,21 @@ -PYTHON ?= python3 -BASE_URL ?= http://localhost:8080 +PYTHON ?= $(if $(wildcard .venv/bin/python),.venv/bin/python,python3) +GO ?= go +PORT ?= 18085 +BASE_URL ?= http://localhost:$(PORT) +IMAGE ?= mtusi-messenger:lab5 CA_FILE ?= -ACTION_SCRIPT ?= +ACTION_SCRIPT ?= scripts/restart.sh +FAILOVER_SCRIPT ?= scripts/stop-one.sh +RECONCILE_ARGS ?= +export PYTHONDONTWRITEBYTECODE=1 TLS_ARGS = $(if $(CA_FILE),--ca-file "$(CA_FILE)",) -.PHONY: help check validate test load test-persistence test-failover +.PHONY: help run docker-build docker-run check validate test test-own test-all load test-persistence bootstrap up down migrate test-integration test-grade4 test-lab4 test-reconcile measure-uploads measure-load migrate-status rolling-update test-failover wait bootstrap-s3 reconcile reconcile-apply + +export PORT BASE_URL help: - @echo "check: offline structure; validate: full OpenAPI (requirements-dev.txt); test: running API; load: synthetic writes" + @echo "up: build and deploy isolated lab5 stack; test-lab5: pipeline faults; benchmark: queue research; down: keep volumes; test-integration: PostgreSQL race/rollback/EXPLAIN; test-grade4: cross-replica idempotency, both failures and rolling update; check: offline structure; validate: full OpenAPI (requirements-dev.txt); test: running API; load: synthetic writes" check: $(PYTHON) scripts/check_contract.py @@ -18,6 +26,11 @@ validate: test: $(PYTHON) tests/smoke.py --base-url "$(BASE_URL)" $(TLS_ARGS) +test-own: + $(GO) test -race ./... + +test-all: check validate test-own + load: $(PYTHON) tests/load.py --base-url "$(BASE_URL)" $(TLS_ARGS) @@ -25,6 +38,82 @@ test-persistence: @test -n "$(ACTION_SCRIPT)" || (echo "Set ACTION_SCRIPT to your implemented executable restart hook"; exit 2) $(PYTHON) tests/resilience.py --mode persistence --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS) +bootstrap: + ./scripts/bootstrap.sh + +up: + $(PYTHON) scripts/swarm.py up + +down: + $(PYTHON) scripts/swarm.py down + +migrate: + $(PYTHON) scripts/swarm.py migrate + +migrate-status: + $(PYTHON) scripts/swarm.py migrate-status + +rolling-update: + $(PYTHON) scripts/swarm.py update + +run: + PORT="$(PORT)" $(GO) run ./cmd + +docker-build: + docker build -t "$(IMAGE)" . + +test-integration: + $(PYTHON) scripts/swarm.py test-integration + +test-grade4: + $(PYTHON) tests/own/swarm_grade4.py + +test-lab4: + $(PYTHON) tests/own/lab5.py + +test-reconcile: + $(PYTHON) tests/own/lab5.py + +measure-uploads: + $(PYTHON) scripts/measure_uploads.py + +bootstrap-s3: + $(PYTHON) scripts/swarm.py bootstrap-s3 + +reconcile: + $(PYTHON) scripts/swarm.py reconcile $(RECONCILE_ARGS) + +reconcile-apply: + $(PYTHON) scripts/swarm.py reconcile --apply $(RECONCILE_ARGS) + +measure-load: + $(PYTHON) scripts/measure_load.py --base-url "$(BASE_URL)" + 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) + $(PYTHON) tests/resilience.py --mode failover --action-script "$(if $(filter command line,$(origin ACTION_SCRIPT)),$(ACTION_SCRIPT),$(FAILOVER_SCRIPT))" --base-url "$(BASE_URL)" $(TLS_ARGS) + +wait: + $(PYTHON) scripts/swarm.py wait + +.PHONY: test-lab5 benchmark plot-research worker-stop worker-start +test-lab5: + $(PYTHON) tests/own/lab5.py + +benchmark: + $(PYTHON) scripts/benchmark_pipeline.py --base-url "$(BASE_URL)" + +plot-research: + $(PYTHON) scripts/plot_pipeline.py + +worker-stop: + $(PYTHON) scripts/swarm.py worker-stop + +worker-start: + $(PYTHON) scripts/swarm.py worker-start + +.PHONY: failed-jobs replay +failed-jobs: + $(PYTHON) scripts/swarm.py failed-jobs + +replay: + $(PYTHON) scripts/swarm.py replay --replay "$(JOB_ID)" --operator "$(OPERATOR)" --reason "$(REASON)" diff --git a/PORTING.md b/PORTING.md new file mode 100644 index 00000000..447b5208 --- /dev/null +++ b/PORTING.md @@ -0,0 +1,19 @@ +# Переход с lab4 на lab5 + +Исходный проект `mtusi2026lab4` сохранён без изменений. +Go module path сохранён для существующих импортов. +Нормативные контракты и публичные проверки lab5 восстановлены из исходного skeleton. + +Загрузка теперь возвращает `202 queued` после staging PUT и PostgreSQL COMMIT. +Старая строка ready без вариантов проходит backfill 009 и получает все три варианта. +При обновлении `make up` останавливает только API своего стека перед backfill. +Это исключает запись старым процессом после миграции. +Volumes и Docker secrets сохраняются. + +Стек, образы и секреты используют имена lab5. Внешний порт по умолчанию — 18085. +Стенд lab4 на 8080 не изменяется. +Redis хранит сессии и durable Streams в одном AOF volume. +Worker работает отдельным сервисом; API не выполняет resize. + +Новая схема, команды и проверки описаны в [REPORT.md](REPORT.md). +Старые `evidence/lab4-*` относятся к исходному проекту и не доказывают выполнение lab5. diff --git a/README.md b/README.md index 009d6997..d178c9ef 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,13 @@ Отделить приём файла от тяжёлой обработки, корректно переживать повторную доставку и остановку worker. -Это **skeleton**, а не готовый сервер. Здесь есть задание, контракт и публичные проверки. Реализацию приложения, Dockerfile и требуемую инфраструктуру пишет студент. Язык и framework свободные; UI не обязателен. +Реализация использует Redis Streams, PostgreSQL outbox и отдельный worker. +API сохраняет оригинал в приватный MinIO staging и возвращает `202 queued`. +Worker создаёт JPEG thumbnail, JPEG crop и WebP optimized. +Запуск: `make up`; адрес: http://localhost:18085; Swagger: `/swagger/`. +Проверки: `make test`, `make test-integration`, `make test-lab5`. +Инструкции и доказательства находятся в [REPORT.md](REPORT.md). +Исследование перегрузки описано в [RESEARCH.md](RESEARCH.md). [Карта курса](COURSE.md) · [Процесс fork/PR](CONTRIBUTING.md) · [OpenAPI](contracts/openapi.json) · [Семантика API](contracts/README.md) · [Проверки](tests/README.md) · [Отчёт](REPORT.md) · [Примеры JSON](contracts/examples.json) · [Памятка преподавателю](MAINTAINERS.md) @@ -52,16 +58,17 @@ make check # После реализации запустите свой сервер/стенд по REPORT.md. -# По умолчанию тест использует http://localhost:8080. +# По умолчанию Makefile использует http://localhost:18085. make test ``` -`.env.example`, `compose.example.yaml` и `contracts/infrastructure.json` описывают настройки и роли компонентов. **compose.example.yaml — список ролей с пустым services, не запускаемый стенд.** Реализуйте свой `compose.yaml`/`stack.yaml`, закрепите версии образов, заполните локальный `.env` и опишите bootstrap/миграции. Все зависимости поднимаются из этого репозитория; ссылка «у меня БД уже установлена» не заменяет воспроизводимость. +`compose.yaml` и `stack.yaml` запускают готовый стенд с закреплёнными версиями образов. Роли компонентов описаны в `contracts/infrastructure.json`. `make bootstrap` создаёт секреты в исключённом из Git каталоге `secrets/`; Swarm использует Docker secrets. Миграции выполняются перед запуском API. Все зависимости поднимаются из этого репозитория. Порядок запуска описан в [REPORT.md](REPORT.md). ```sh # Compose-вариант после реализации: -docker compose --env-file .env config --quiet -docker compose --env-file .env up -d --build +./scripts/compose.sh config --quiet +make bootstrap +./scripts/compose.sh up -d --build --wait # Дождитесь /health/ready; затем make test. # Для Swarm укажите эквивалентные build/push/deploy-команды в REPORT.md. ``` diff --git a/REPORT.md b/REPORT.md index e98f75e9..49fa5eff 100644 --- a/REPORT.md +++ b/REPORT.md @@ -1,37 +1,268 @@ -# Отчёт — лабораторная 5 +# Лабораторная 5: очередь изображений -- Автор, группа: TODO -- Целевая оценка; выбранный трек 5, если нужен: TODO -- Commit/PR: TODO после публикации -- Использованные источники, библиотеки и помощь ИИ: TODO +Целевая оценка: **5**, исследование — **трек 1, очередь под перегрузкой**. +Redis уже хранит сессии. Redis Streams добавляет очередь без второго брокера. +Исследование сравнивает три настройки concurrency/prefetch. Методика и результаты: [RESEARCH.md](RESEARCH.md). +Публичные контракты и проверки lab5 сохранены. -## Запуск из чистого clone +## Запуск -TODO: версии runtime/образов, prerequisites, команды создания локальных secrets/.env, build, миграций, запуска, ожидания готовности, тестов и остановки. Указать необходимые действия оператора. Не вставлять секреты. Отдельно указать безопасную остановку и команду намеренного удаления учебных данных. +Установите Docker с поддержкой Swarm и Python 3.9+. +Локальные Go-проверки требуют Go 1.26.4 или новее. +Запустите стенд: -## Архитектура и решения +```sh +make up +make wait +make test +``` -TODO: схема процессов/хранилищ, источник истины, транзакционные границы, ограничения. Что перенесено из lab4, что изменено в этой работе. Соответствие переменных из .env.example реальной конфигурации. +API: http://localhost:18085. Swagger: http://localhost:18085/swagger/. +Стек `mtusi-lab5` не использует volumes, секреты и порт исходного стенда lab4. +Скрипт поддерживает один узел Swarm. Порты хранилищ не опубликованы. -## Доказательства критериев +Bootstrap создаёт случайные секреты в локальном каталоге `secrets/` и Docker secrets. +Каталог исключён из Git и Docker context. Скрипты не загружают `.env`. +Версии закреплены в Dockerfile/stack.yaml: -| Критерий README | Команда/сценарий | Наблюдаемый результат | Файл доказательства | -| --- | --- | --- | --- | -| Публичный smoke | make test | TODO | TODO | -| Остальные пункты уровня 3 | TODO | TODO | TODO | -| Все пункты уровня 4, если заявлен | TODO | TODO | TODO | -| Выбранный трек 5, если заявлен | TODO | TODO | TODO | +| Компонент | Версия | +| --- | --- | +| Go / Alpine | 1.26.4 / 3.23, базовые digest в Dockerfile | +| PostgreSQL | 17.6-alpine3.22 | +| Redis | 7.4.5-alpine3.21 | +| HAProxy | 3.2.6-alpine | +| MinIO | RELEASE.2025-09-07T16-13-09Z, фиксированный commit и SHA-256 | +| mc | RELEASE.2025-08-13T08-35-41Z, фиксированный commit и SHA-256 | +| libwebp-tools | 1.6.0-r0 | -TODO: добавить отдельную строку для каждого заявленного критерия. PASS без команды и наблюдения не является доказательством. Проверка инфраструктурного hook требует подтверждения, какие реальные процессы/хранилища перезапущены. +Go compiler использует `-p=1` и `GOMAXPROCS=2` при сборке контейнеров. +Это ограничивает память сборки на Docker VM с 1,91GiB RAM. +Первый параллельный build получил OOM; последовательный build устранил эту ошибку. +`SKIP_STORAGE_BUILD=1 make up` повторно использует уже собранные образы MinIO/mc. +Обычный `make up` собирает все образы из репозитория. -## Эксперименты и отказы +Compose запускает те же роли с одной API-репликой: -TODO: гипотеза, hardware/лимиты, версии, объём данных, профиль нагрузки, concurrency/arrival rate, длительность/прогрев, повторы, успешные RPS, ошибки, p50/p95/p99, CPU/RAM. Сохранить raw summary без tokens и объяснить ограничения измерения. +```sh +make bootstrap +./scripts/compose.sh up -d --build --wait +make test +./scripts/compose.sh down +``` -| Воздействие | Что ожидаем | Что наблюдали | Время восстановления / потеря данных | -| --- | --- | --- | --- | -| TODO | TODO | TODO | TODO | +Остановите один стенд перед запуском другого на том же порту. +`make down` сохраняет volumes и Docker secrets. +При обновлении `make up` останавливает API перед миграциями 005–010. +Миграция 009 переводит старые ready-оригиналы lab4 в очередь без повторной загрузки. +Старый object key временно становится staging key. +Worker удаляет этот staging только после публикации готовых вариантов. +Эта пауза исключает запись старой API-версией после backfill. +Откат миграций удаляет jobs/outbox; сохранять принятые задачи при downgrade нельзя. -## Ограничения и следующие шаги +## Путь принятой загрузки -TODO: какие отказы выдерживаются и какие нет; что не реализовано; где учебное упрощение; какое улучшение подтверждено, а какое пока гипотеза. +1. API проверяет сессию, членство в чате, имя, bytes, MIME и пиксели. +2. API сохраняет проверенный оригинал в приватный `staging/`. +3. PostgreSQL одной транзакцией сохраняет attachment, job и outbox. +4. API возвращает `202` со снимком `queued` после COMMIT. +5. Publisher читает outbox через `FOR UPDATE SKIP LOCKED` и делает XADD. +6. Worker получает сообщение через XREADGROUP и арендует job в PostgreSQL. +7. Renderer создаёт варианты в отдельном процессе с deadline. +8. Worker сохраняет оригинал и три варианта по постоянным versioned keys. +9. PostgreSQL атомарно публикует ready и метаданные всех вариантов. +10. Worker подтверждает запись через XACK и удаляет подтверждённую запись XDEL. + +API не выполняет resize. Проверка входного изображения в API сохраняет требования lab4. +Она включает полный decode для обнаружения повреждений, но не создаёт варианты. +Каждая API-реплика проверяет не более одного upload одновременно. +Локальный spool ограничен 10MiB и удаляется после staging PUT или ошибки. + +API publisher работает независимо от worker. Worker также может опубликовать ожидающий outbox. +Row locks исключают конкурентную публикацию одной outbox-строки. +Разрыв между XADD и PostgreSQL COMMIT может создать дубль; потеря принятой задачи не возникает. +Подтверждение XADD означает durable запись Redis с `appendfsync always`. +XACK означает устойчивый результат обработки либо устойчивую запись следующего состояния. +Это at-least-once доставка с идемпотентным эффектом, а не exactly-once доставка. + +Redis хранит stream `attachments:jobs:v1`, группа — `image-workers-v1`. +Одно поле stream `job` содержит JSON по `contracts/jobs.schema.json`. +Поля включают UUID job/attachment, version, attempt, type, schema_version и created_at. +Сообщение не содержит bytes, credentials, filename, URL или S3 key. +Worker берёт доверенные storage metadata из PostgreSQL. + +## Состояния, retry и защита результата + +PostgreSQL — источник истины состояний queued/processing/ready/failed. +Queued и processing можно прикрепить к сообщению своего чата. +Content до ready и после failed возвращает 409. Метаданные доступны во всех состояниях. +Failed нельзя прикрепить заново. Ранее подтверждённые сообщения и их idempotency replay сохраняются. + +Claim увеличивает attempts и fence, задаёт lease_until. +Фиксация результата требует текущий fence, pipeline_version и ещё действующий lease. +Она также требует ровно одну изменённую строку attachment нужной версии и состояния. +Старый процесс не публикует ready после аренды новой попыткой. +Объекты используют ключ `original//v/`. +Имена эффектов: original, thumbnail, crop, optimized. +Повтор той же версии пишет те же байты в те же четыре ключа. +Новая версия получает другой prefix. Стандартный pipeline_version равен 1. + +XAUTOCLAIM возвращает pending-доставки умерших consumers после lease. +Истёкший processing возвращается в queued через устойчивую транзакцию и новый outbox. +Attempts учитывают управляемые попытки обработки; простой дубль ready не увеличивает attempts. +Перед ack дубля ready проверяются метаданные и наличие четырёх S3-объектов нужного размера. +Дубль не изменяет updated_at, варианты или готовый результат. + +Временные ошибки хранилищ, timeout и worker crash используют ограниченный retry. +Постоянные ошибки изображения и исчезнувший staging дают failed сразу. +Backoff после попытки n: `2^min(n,5)` секунд плюс случайные 0–499ms. +По умолчанию разрешено пять попыток. Финальный public error_code безопасен и не содержит внутренних данных. +Реестр failed хранится в attachment_jobs; последняя причина сохраняется в last_error. + +```sh +make failed-jobs +make replay JOB_ID= OPERATOR= REASON='Причина повторной обработки' +``` + +Replay принимает только failed с доступным staging и свободным admission slot. +Он сохраняет job_id и versioned effect identity, сбрасывает счётчик попыток и увеличивает fence. +Транзакция записывает operator, reason, предыдущую ошибку и время в attachment_replays. +Replay ready или ещё активной работы отклоняется. После истечения retention replay отклоняется. + +## Изображения и пределы ресурсов + +Thumbnail — JPEG quality85, вписан в 256×256 без увеличения, размеры округляются вниз. +Crop — центрированный квадрат JPEG128×128 quality85, малые исходники увеличиваются. +Optimized — WebP quality80, method4, вписан в 1280×1280 без увеличения. +JPEG/PNG EXIF orientation1–8 применяется до изменения размеров. +Alpha компонуется на белый. Варианты не сохраняют EXIF; cwebp получает `-metadata none`. +Уменьшение каждого маленького файла не обещается. Оригинал сохраняется побайтно. + +API ограничивает bytes10MiB и 40 миллионов пикселей до полного decode. +Worker повторно проверяет размер, SHA-256, DecodeConfig и pixel budget. +Resize/decode/cwebp работают в дочернем renderer; CommandContext ограничивает весь процесс. +Renderer создаёт отдельную process group. Deadline убивает renderer и потомков, включая cwebp. +Общий pixel semaphore ограничивает одновременно распакованные исходники 40Mpx на worker service. +Orientation использует представление исходника, без второй копии полного изображения. +Renderer получает GOMEMLIMIT384MiB; worker service ограничен cgroup1536MiB и1CPU. +GOMEMLIMIT является мягким Go-лимитом; жёсткий предел задаёт cgroup всей службы. + +| Настройка | По умолчанию | Назначение | +| --- | --- | --- | +| WORKER_CONCURRENCY | 2 | Одновременные обработки, максимум8 | +| WORKER_PREFETCH | 4 | Ёмкость локальной очереди, максимум32 | +| WORKER_TIMEOUT_SECONDS | 25 | Вся попытка: admission пикселей, download, renderer и PUT | +| WORKER_LEASE_SECONDS | 40 | Lease; минимум timeout+5s | +| WORKER_PIXEL_BUDGET | 40000000 | Общий pixel budget, максимум80000000 | +| WORKER_MAX_ATTEMPTS | 5 | Число попыток новой job, задаётся API при upload | +| MAX_OUTSTANDING_JOBS | 200 | Максимум queued+processing на весь стенд | + +Prefetch ограничивает ожидающую локальную очередь. Активные процессы добавляют concurrency к числу полученных сообщений. +Настройки bounded; число принятых незавершённых jobs ограничено отдельно. +Admission использует общий PostgreSQL advisory lock и count queued/processing. +Этот lock также защищает replay. Превышение возвращает 429 с Retry-After. +Проверка и вставка выполняются в одной транзакции, поэтому две API-реплики не превышают лимит. +Lock удерживается во время staging PUT. Это ограничивает throughput upload и измеряется в исследовании. + +## Retention и согласованность S3 + +Очистка выполняется каждые пять секунд, не более100 metadata rows за проход. +Ready staging удаляется после устойчивой публикации всех вариантов. +Failed staging и частичные конечные объекты сохраняются семь дней для расследования и replay. +После семи дней cleanup удаляет bytes и ставит storage_cleaned_at, но сохраняет metadata/job/audit. +Replay и cleanup блокируют одну metadata row; очистка не удаляет текущую работу. +Старый stage без metadata имеет grace90s и общий с upload advisory lock. +После PUT без COMMIT API возвращает ошибку; такой stage удаляется после grace. +Готовые конечные вложения сохраняются бессрочно, включая ещё не привязанные к сообщению. +Их staging очищается одинаково. Автоматическое удаление готовых конечных вложений не реализовано. + +Reconciler lab4 сохранён: `make reconcile`, `make reconcile-apply`. +Он защищает текущий versioned prefix и staging_key, включая legacy staging в original-prefix. +Отсутствующий ready-оригинал атомарно переводит attachment и job в failed. +Reconciler не удаляет ссылки из подтверждённых сообщений. +Reconciler контролирует original; внешняя утрата отдельного варианта требует ручного восстановления. +Проверка дубля пишет безопасный retry-log, если готовый эффект недоступен. +Автоматический ремонт внешних удалений вариантов не реализован. + +## Проверки и исследование + +Подготовьте зависимости проверок: + +```sh +python3 -m venv .venv +.venv/bin/python -m pip install -r requirements-dev.txt -r requirements-research.txt +make check validate +make test-own +make test-integration +make test +make test-lab5 +make test-persistence +make test-failover +make benchmark +make plot-research +``` + +Go-тесты проверяют геометрию, EXIF1–8, alpha, повреждения, MIME, concurrency и транзакции. +Интеграционный тест проверяет stale/expired fence и защиту более новой pipeline_version. +Fault suite внедряет ошибку после staging, разрыв COMMIT/publish и два broker restart. +Он останавливает worker после S3 effects и после result COMMIT перед ack. +Проверяются повторная доставка, lease recovery, bounded retry, permanent failure и audit replay. +Отдельный renderer_timeout блокирует настоящий cwebp на FIFO и проверяет уничтожение потомков. +Очистка проверяется для ready, unconfirmed и expired failed staging. +Все пользователи и изображения синтетические. Токены и секреты в evidence не сохраняются. +Запускайте fault, persistence и benchmark последовательно на учебном стенде. + +Исследование трека1 использует реальные свежие измерения, а не результаты исходного проекта. +Пары concurrency/prefetch: (1,1), (2,4), (4,8); размеры PNG512² и1536². +Отдельный опыт проверяет предел admission при остановленном worker и последующее восстановление. +Raw данные, графики, ограничения методики и объяснение для защиты находятся в [RESEARCH.md](RESEARCH.md). +Исследование завершено: все 120 измеряемых загрузок стали ready, шесть сочетаний настроек и размеров проверены. +Пара concurrency=2, prefetch=4 дала лучший throughput для обоих размеров: 4,013 и 0,851 изображения/с. +При остановленном worker лимит 8 принял 8 из 16 загрузок; остальные получили 429. +После запуска все 8 заданий завершились, очередь опустела, новая загрузка прошла. +Текстовое сообщение сохранилось при полной очереди. Исходные настройки восстановлены. +Итог `PASS` и наблюдения: `evidence/lab5-research.json`; таблица: `evidence/lab5-research.csv`. +Исторические evidence/lab4-* не считаются доказательством lab5. + +`make test` прошёл на новом API lab5. Журнал: `evidence/lab5-smoke.txt`. +Host race-тесты и контейнерные интеграционные тесты прошли. +Интеграционный журнал: `evidence/lab5-integration.txt`; исходная ошибка fixture сохранена отдельно. +Прежний fixture удалял migration journal из уже обновлённой схемы. +Теперь он сначала возвращает физическую схему lab4, затем проверяет её импорт. + +Все обязательные fault cases проверены на реальных PostgreSQL, Redis Streams и MinIO. +Первый полный вызов подтвердил основные durability/crash/retry сценарии и выявил гонку тестового stop helper. +Desired replicas=0 ещё не означает остановку старого consumer-контейнера. +Helper и `make worker-stop` теперь ожидают фактическое отсутствие работающих контейнеров. +Поздние независимые cases повторены через `--tail-only` с новыми пользователями и изображениями. +Повтор завершился exit0; прежние успешные cases и время продолжения сохранены в JSON. +Исходный полный вызов завершился exit1 и не объявляется успешным полным прогоном. +Журналы: `evidence/lab5-faults-main.txt`, `evidence/lab5-faults-tail.txt`. +Все case-level результаты находятся в `evidence/lab5-faults.json`. + +Отдельный initial fault обнаружил старый worker при обновлении образа с прежним tag. +`make up` теперь принудительно обновляет worker вместе с API. +После исправления фактические JPEG/PNG EXIF проверки прошли. +Статические проверки и команды воспроизведения собраны в `evidence/lab5-validation.txt`. +`make test-persistence` прошёл после перезапуска компонентов собственного стенда. +Подтверждённые данные и существующая сессия сохранились: `evidence/lab5-persistence.txt`. +`make test-failover` прошёл при остановке одной из двух API-реплик. +Зафиксированы 123 успешные записи, одна неудачная попытка и восстановление за 0,696s. +Подтверждённые данные и сессия сохранились: `evidence/lab5-failover.txt`. + +## Соответствие критериям + +| Уровень | Критерий | Реализация и доказательство | +| --- | --- | --- | +| 3 | Возможности lab4 и переход upload на 202 | `PORTING.md`, публичный smoke, persistence/failover | +| 3 | Устойчивый приём до ответа | MinIO staging + PostgreSQL attachment/job/outbox; cases `stage_before_commit`, `commit_publish_and_restarts` | +| 3 | Отдельный broker/worker, durable at-least-once | Redis Streams/AOF; два broker restart, worker stop/start | +| 3 | Четыре состояния, оригинал и thumbnail | Контракт API; smoke, `small_alpha_exif`, `bounded_retry_replay` | +| 3 | Ограниченные повторы и единый результат | `max_attempts`, versioned keys; cases `crash_after_objects`, `commit_before_ack_and_duplicate` | +| 4 | Crop/WebP, качество и ограничения | Renderer, pixel budget, process deadline; EXIF/alpha/geometry tests и `renderer_process_group_timeout` | +| 4 | Восстановление разрыва COMMIT/publish | Transactional outbox; case `commit_publish_and_restarts` | +| 4 | Backoff/jitter, permanent failure, failed registry/replay | Cases `bounded_retry_replay`, `permanent_stage_error`; audit replay | +| 4 | Crash после S3, lease/fence, bounded concurrency/prefetch | Crash cases, `TestFenceIntegration`, конфигурация worker | +| 4 | Безопасная очистка staging | Case `staging_cleanup`; ready/failed/unconfirmed retention | +| 5 | Трек 1: настройки, размеры, backpressure и восстановление | Методика, raw данные, графики и ограничения в `RESEARCH.md` | + +Источники case-level результатов: `evidence/lab5-faults.json` и журналы split-run выше. diff --git a/RESEARCH.md b/RESEARCH.md new file mode 100644 index 00000000..742a681b --- /dev/null +++ b/RESEARCH.md @@ -0,0 +1,185 @@ +# Исследование: очередь под перегрузкой + +Выбран трек 1 лабораторной 5. Исследование сравнивает скорость, задержку и память при разных настройках обработки. +Отдельный сценарий проверяет ограничение очереди и восстановление после перегрузки. + +## Гипотеза + +Рост числа параллельных обработок уменьшает ожидание, пока хватает процессора. +После насыщения процессора дополнительные обработки увеличивают память и конкурируют за вычисления. +Ограничение очереди сохраняет конечное число принятых заданий, когда worker остановлен. + +## Что означают настройки + +- `WORKER_CONCURRENCY` ограничивает число параллельных обработок внутри одного worker. +- `WORKER_PREFETCH` ограничивает буфер заданий перед обработкой. +- `WORKER_PIXEL_BUDGET` ограничивает суммарное число пикселей у активных обработок. +- `MAX_OUTSTANDING_JOBS` ограничивает число заданий со статусом `queued` или `processing` в PostgreSQL. + +Redis Streams хранит сообщения до подтверждения. PostgreSQL хранит состояние задания и намерение публикации. +Сообщение Redis содержит идентификаторы. Байты изображения остаются в S3. +Полная очередь приводит к HTTP `429`. Текстовые сообщения продолжают работать. + +## Методика + +Стенд включает один worker, две API-реплики, PostgreSQL, Redis и MinIO. +Ограничения CPU и памяти worker сохраняются между запусками. +Исходные изображения — PNG с псевдослучайными RGB-пикселями. Генератор использует фиксированное начальное значение. +SHA-256 каждого изображения записывается в результат. + +Скрипт сравнивает шесть запусков: + +| Размер PNG | Concurrency | Prefetch | Число изображений | +| --- | ---: | ---: | ---: | +| 512×512 | 1 | 1 | 20 | +| 512×512 | 2 | 4 | 20 | +| 512×512 | 4 | 8 | 20 | +| 1536×1536 | 1 | 1 | 20 | +| 1536×1536 | 2 | 4 | 20 | +| 1536×1536 | 4 | 8 | 20 | + +Перед каждым запуском worker завершает все задания. Одно изображение прогревает pipeline после изменения настройки. +Измерение начинается после прогрева. Восемь HTTP-потоков отправляют двадцать изображений. +Скрипт опрашивает метаданные до `ready` для всех принятых вложений. +После измерения скрипт проверяет оригинал и контрольные суммы трёх вариантов у одного вложения. + +## Метрики + +| Метрика | Определение | +| --- | --- | +| Throughput | Число готовых изображений / время всего пакета, включая upload и опрос | +| p95 до ready | 95-й процентиль времени от начала POST до первого ответа `ready` | +| p95 после 202 | 95-й процентиль времени от ответа `202` до первого ответа `ready` | +| Queue lag | Возраст старейшего задания `queued` из текущего чата; `processing` исключается | +| RSS | Сумма `VmRSS` worker, процессов обработки и `cwebp` | +| Размер очереди | Число заданий `queued` и `processing` в PostgreSQL | + +Процентиль рассчитывается методом ближайшего ранга. Для двадцати изображений p95 соответствует девятнадцатому значению после сортировки. +Скрипт снимает RSS и queue lag между опросами API. Пауза между циклами составляет минимум 250 мс. +Фактические интервалы содержатся в JSON. Команды Docker и запросы API увеличивают этот интервал. + +## Результаты измерений + +Дата измерений: 10 ноября 2026 года. Архитектура — arm64, Docker Engine — 29.5.2. +Docker VM располагает двумя CPU и 1,91 GiB RAM. +Worker ограничен одним CPU и 1536 MiB памяти. Эти ограничения одинаковы во всех шести запусках. +Размеры входных файлов составили 787252 и 7081647 байт. +Все 120 измеряемых загрузок вернули `202` и завершились статусом `ready`. + +| PNG | Concurrency / prefetch | Throughput, изобр./с | p95 до ready, с | Queue lag max, с | RSS max, МиБ | +| --- | ---: | ---: | ---: | ---: | ---: | +| 512×512 | 1/1 | 3.316 | 4.76 | 4.08 | 32.2 | +| 512×512 | 2/4 | 4.013 | 4.33 | 3.17 | 54.2 | +| 512×512 | 4/8 | 3.903 | 4.45 | 2.67 | 90.3 | +| 1536×1536 | 1/1 | 0.774 | 22.79 | 21.48 | 74.2 | +| 1536×1536 | 2/4 | 0.851 | 21.47 | 18.20 | 134.3 | +| 1536×1536 | 4/8 | 0.847 | 20.74 | 16.60 | 224.2 | + +![Результаты шести измерений](evidence/lab5-research.svg) + +PNG-версия графика: [lab5-research.png](evidence/lab5-research.png). +Точные значения, дополнительные метрики и исходные наблюдения доступны в JSON и CSV. + +Для этого стенда рекомендована пара **concurrency=2, prefetch=4**. Она совпадает с настройкой по умолчанию. +Она дала максимальный измеренный throughput для обоих размеров. +Относительно 1/1 throughput вырос примерно на 21% для маленьких изображений и на 10% для крупных. +Пиковый RSS при этом вырос с 32,2 до 54,2 МиБ и с 74,2 до 134,3 МиБ. + +Переход от 2/4 к 4/8 не увеличил throughput. +Для крупных изображений p95 улучшился примерно на 3,4%, а RSS вырос примерно на 67%. +Для маленьких изображений выросли и RSS, и p95. +Выбор 1/1 уменьшает расход памяти ценой большей задержки и меньшей скорости. + +Результат согласуется с гипотезой об ограниченной пользе параллелизма при одном CPU. +Он не доказывает причину насыщения: upload, S3 и PostgreSQL также входят в измерение. +Меньший queue lag при 4/8 не означает пропорционального ускорения pipeline. +Метрика исключает задания `processing`, число которых может расти вместе с concurrency. +Разницу в несколько процентов следует проверить повторными сериями перед изменением рабочих настроек. + +## Перегрузка и восстановление + +Скрипт останавливает worker и устанавливает лимит восемь заданий на обеих API-репликах. +Затем шестнадцать запросов конкурируют за этот общий лимит. +Проверка требует восемь ответов `202`, восемь ответов `429` и восемь заданий в PostgreSQL. +Заголовки `X-Instance-Id` подтверждают участие обеих API-реплик. + +После запуска worker все восемь принятых заданий завершаются. +Скрипт проверяет пустую очередь и новый успешный upload. +Скрипт восстанавливает исходные настройки после эксперимента, в том числе при ошибке проверки. + +Фактический результат: + +| Проверка | Результат | +| --- | --- | +| Остановленный worker, лимит 8, предложено 16 | 8 ответов `202`, 8 ответов `429` | +| Участие API | Подтверждены две разные реплики | +| Незавершённые задания при остановленном worker | Ровно 8 | +| Текстовое сообщение при полной очереди | Сохранено успешно | +| Принятые задания после запуска worker | Все 8 стали `ready` | +| Незавершённые задания после восстановления | 0 | +| Следующая загрузка после освобождения очереди | `202`, затем `ready` | + +Счётчик завершения проверяется после ожидания готовности worker. +Часть обработки проходит во время этого ожидания, поэтому отдельное поле drain не измеряет полное время восстановления. +Опыт подтверждает общий лимит между репликами и сохранность принятой работы после `202`. +Эксперимент завершился с `PASS`. Исходные настройки worker и API восстановлены и проверены отдельно. + +## Повторение + +Запустите стенд: + +```sh +make up +make test +``` + +Остановите другие нагрузочные проверки. Запустите исследование: + +```sh +make benchmark +``` + +Установите зависимости для графика: + +```sh +.venv/bin/python -m pip install -r requirements-research.txt +``` + +Создайте график: + +```sh +make plot-research +``` + +Скрипт сохраняет исходные наблюдения в `evidence/lab5-research.json`. +Таблица находится в `evidence/lab5-research.csv`. Графики сохраняются в SVG и PNG рядом с таблицей. +JSON содержит версию Docker, число CPU, память, образ worker и ограничения контейнера. + +## Ограничения + +Измерения относятся к одному локальному стенду. Пакет из двадцати изображений не определяет производственный SLA. +В каждом запуске есть прогрев, но независимых повторений для доверительного интервала нет. +Concurrency и prefetch меняются вместе. Результат сравнивает пары настроек и не изолирует влияние каждого параметра. + +HTTP upload, проверка изображения, S3 и PostgreSQL также влияют на throughput. +Глобальная блокировка при приёме задания сериализует участок записи staging и регистрации задания. +Увеличение concurrency не устраняет это ограничение API. +Admission ограничивает незавершённую работу. Concurrency и бюджет пикселей ограничивают память обработки. +Этот лимит не ограничивает общий размер готовых вложений на диске. + +Опрос добавляет задержку к наблюдаемому времени до `ready`. +Выборка RSS может пропустить короткий пик. Общие страницы памяти могут учитываться несколько раз. +Небольшая часть RSS относится к самой команде наблюдения внутри контейнера. +Значение RSS не равно использованию памяти cgroup с файловым кешем. + +## Объяснение для защиты + +1. API возвращает `202` после сохранения файла и задания. Обработка изображения продолжается отдельно. +2. Redis хранит очередь доставки. PostgreSQL хранит состояние и восстанавливает публикацию через outbox. +3. Concurrency задаёт число одновременных обработок. Prefetch задаёт запас заданий перед обработкой. +4. Задержка растёт, когда задания поступают быстрее обработки. Бесконечная очередь увеличивает ожидание и расход ресурсов. +5. Лимит очереди возвращает `429` для новой работы. Работа после уже выданного `202` сохраняется. +6. После запуска worker очередь завершается. Повторный upload проходит без изменения принятого ранее задания. +7. Подтверждение Redis происходит после устойчивого результата. Повтор доставки безопасен благодаря состоянию задания и ключам вариантов. + +Это доставка at least once. Повтор доставки возможен, поэтому результат защищён от повторного применения. diff --git a/cmd/main.go b/cmd/main.go new file mode 100644 index 00000000..f3be9581 --- /dev/null +++ b/cmd/main.go @@ -0,0 +1,113 @@ +package main + +import ( + "context" + "errors" + "fmt" + "log" + "net/http" + "os" + "os/signal" + "syscall" + "time" + + "github.com/jackc/pgx/v5/pgxpool" + "github.com/redis/go-redis/v9" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/app/chat" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/attachment" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/config" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/repository/postgres" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/session" + chatusecase "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/usecase/chat" +) + +const shutdownTimeout = 8 * time.Second + +func main() { + cfg, err := config.Load() + if err != nil { + log.Fatal(err) + } + poolConfig, err := pgxpool.ParseConfig("sslmode=disable") + if err != nil { + log.Fatal("invalid PostgreSQL config") + } + poolConfig.ConnConfig.Host = cfg.PostgresHost + poolConfig.ConnConfig.Port = cfg.PostgresPort + poolConfig.ConnConfig.User = cfg.PostgresUser + poolConfig.ConnConfig.Database = cfg.PostgresDatabase + poolConfig.ConnConfig.Password = cfg.PostgresPassword + poolConfig.ConnConfig.ConnectTimeout = cfg.QueryTimeout + poolConfig.ConnConfig.RuntimeParams["timezone"] = "UTC" + poolConfig.ConnConfig.RuntimeParams["statement_timeout"] = fmt.Sprint(cfg.QueryTimeout.Milliseconds()) + poolConfig.MaxConns = cfg.PostgresMaxConns + poolConfig.MinConns = 1 + poolConfig.MaxConnLifetime = time.Hour + poolConfig.MaxConnIdleTime = 5 * time.Minute + pool, err := pgxpool.NewWithConfig(context.Background(), poolConfig) + if err != nil { + log.Fatal("cannot create PostgreSQL pool") + } + defer pool.Close() + redisClient := redis.NewClient(&redis.Options{ + Addr: cfg.RedisAddr, PoolSize: 10, MaxActiveConns: 10, PoolTimeout: cfg.QueryTimeout, + DialTimeout: cfg.QueryTimeout, ReadTimeout: cfg.QueryTimeout, WriteTimeout: cfg.QueryTimeout, + MaxRetries: -1, ContextTimeoutEnabled: true, + }) + defer redisClient.Close() + repo := postgres.New(pool, cfg.QueryTimeout) + sessions := session.NewRedis(redisClient, cfg.QueryTimeout) + useCase := chatusecase.New(repo, sessions, cfg.SessionTTL) + objectStore, err := attachment.NewStore(cfg.S3Endpoint, cfg.S3Bucket, cfg.S3AccessKey, cfg.S3SecretKey, cfg.S3UseSSL) + if err != nil { + log.Fatal("invalid S3 config") + } + options, err := attachment.LoadOptions() + if err != nil { + log.Fatal(err) + } + attachments := attachment.NewAsync(pool, objectStore, options) + background, stopPublisher := context.WithCancel(context.Background()) + defer stopPublisher() + go attachments.RunPublisher(background, redisClient) + handler := chat.NewChat(useCase, cfg.CursorKey).WithAttachments(attachments) + port := cfg.Port + e := handler.Router() + e.Server.ReadHeaderTimeout = 5 * time.Second + e.Server.ReadTimeout = 50 * time.Second + e.Server.WriteTimeout = 55 * time.Second + e.Server.IdleTimeout = 60 * time.Second + + serverErrors := make(chan error, 1) + go func() { + log.Printf("HTTP server is listening on :%s", port) + serverErrors <- e.Start(":" + port) + }() + + stop := make(chan os.Signal, 1) + signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM) + select { + case sig := <-stop: + log.Printf("received %s, shutting down", sig) + case err := <-serverErrors: + if !errors.Is(err, http.ErrServerClosed) { + log.Fatalf("HTTP server failed: %v", err) + } + return + } + + handler.Drain() + // Allow two 1-second LB checks to remove this backend before closing the listener. + time.Sleep(3 * time.Second) + ctx, cancel := context.WithTimeout(context.Background(), shutdownTimeout) + defer cancel() + if err := e.Shutdown(ctx); err != nil { + log.Printf("graceful shutdown failed: %v", err) + if closeErr := e.Close(); closeErr != nil { + log.Printf("forced shutdown failed: %v", closeErr) + } + return + } + log.Printf("shutdown complete") +} diff --git a/cmd/reconcile/main.go b/cmd/reconcile/main.go new file mode 100644 index 00000000..2534aa6c --- /dev/null +++ b/cmd/reconcile/main.go @@ -0,0 +1,57 @@ +package main + +import ( + "context" + "encoding/json" + "flag" + "log" + "os" + "time" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/attachment" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/config" + "github.com/jackc/pgx/v5/pgxpool" +) + +func main() { + apply := flag.Bool("apply", false, "apply safe repairs; default dry-run") + grace := flag.Duration("grace", 2*time.Minute, "minimum object/metadata age (at least 90s)") + timeout := flag.Duration("timeout", 10*time.Minute, "whole scan deadline") + flag.Parse() + if *grace < attachment.MinimumGrace { + log.Fatal("grace must be at least 90s") + } + cfg, err := config.Load() + if err != nil { + log.Fatal(err) + } + pc, err := pgxpool.ParseConfig("sslmode=disable") + if err != nil { + log.Fatal("invalid DB config") + } + pc.ConnConfig.Host = cfg.PostgresHost + pc.ConnConfig.Port = cfg.PostgresPort + pc.ConnConfig.User = cfg.PostgresUser + pc.ConnConfig.Password = cfg.PostgresPassword + pc.ConnConfig.Database = cfg.PostgresDatabase + pc.ConnConfig.ConnectTimeout = 3 * time.Second + pc.ConnConfig.RuntimeParams["statement_timeout"] = "5000" + pc.MaxConns = 2 + ctx, cancel := context.WithTimeout(context.Background(), *timeout) + defer cancel() + pool, err := pgxpool.NewWithConfig(ctx, pc) + if err != nil { + log.Fatal("cannot create DB pool") + } + defer pool.Close() + store, err := attachment.NewStore(cfg.S3Endpoint, cfg.S3Bucket, cfg.S3AccessKey, cfg.S3SecretKey, cfg.S3UseSSL) + if err != nil { + log.Fatal("invalid S3 config") + } + result, err := attachment.New(pool, store).Reconcile(ctx, *apply, *grace) + _ = json.NewEncoder(os.Stdout).Encode(result) + if err != nil { + log.Print(err) + os.Exit(1) + } +} diff --git a/cmd/worker/main.go b/cmd/worker/main.go new file mode 100644 index 00000000..2d5de868 --- /dev/null +++ b/cmd/worker/main.go @@ -0,0 +1,115 @@ +package main + +import ( + "context" + "encoding/json" + "errors" + "flag" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/attachment" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/config" + "github.com/jackc/pgx/v5/pgxpool" + "github.com/redis/go-redis/v9" + "log" + "os" + "os/signal" + "syscall" + "time" +) + +func main() { + if len(os.Args) > 1 && os.Args[1] == "render" { + if len(os.Args) != 5 { + os.Exit(2) + } + if err := attachment.Render(context.Background(), os.Args[2], os.Args[3], os.Args[4]); err != nil { + if errors.Is(err, attachment.ErrInvalidImage) { + os.Exit(2) + } + os.Exit(1) + } + return + } + failed := flag.Bool("failed", false, "list failed job registry") + replay := flag.String("replay", "", "failed job UUID to replay") + operator := flag.String("operator", "", "operator identity") + reason := flag.String("reason", "", "replay reason") + flag.Parse() + cfg, err := config.Load() + if err != nil { + log.Fatal(err) + } + options, err := attachment.LoadOptions() + if err != nil { + log.Fatal(err) + } + pc, err := pgxpool.ParseConfig("sslmode=disable") + if err != nil { + log.Fatal("invalid DB config") + } + pc.ConnConfig.Host = cfg.PostgresHost + pc.ConnConfig.Port = cfg.PostgresPort + pc.ConnConfig.User = cfg.PostgresUser + pc.ConnConfig.Password = cfg.PostgresPassword + pc.ConnConfig.Database = cfg.PostgresDatabase + pc.ConnConfig.ConnectTimeout = 3 * time.Second + pc.ConnConfig.RuntimeParams["timezone"] = "UTC" + pc.ConnConfig.RuntimeParams["statement_timeout"] = "5000" + pc.MaxConns = int32(options.Concurrency + 4) + ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + defer cancel() + pool, err := pgxpool.NewWithConfig(ctx, pc) + if err != nil { + log.Fatal("DB configuration failed") + } + defer pool.Close() + store, err := attachment.NewStore(cfg.S3Endpoint, cfg.S3Bucket, cfg.S3AccessKey, cfg.S3SecretKey, cfg.S3UseSSL) + if err != nil { + log.Fatal("S3 configuration failed") + } + service := attachment.NewAsync(pool, store, options) + if *failed { + rows, e := pool.Query(ctx, `SELECT id::text,attachment_id::text,attempts,max_attempts,coalesce(last_error,''),updated_at FROM attachment_jobs WHERE state='failed' ORDER BY updated_at DESC LIMIT 100`) + if e != nil { + log.Fatal("cannot query failed jobs") + } + defer rows.Close() + records := []map[string]interface{}{} + for rows.Next() { + var id, att, code string + var attempt, max int + var updated time.Time + if e = rows.Scan(&id, &att, &attempt, &max, &code, &updated); e != nil { + log.Fatal("invalid failed job") + } + records = append(records, map[string]interface{}{"job_id": id, "attachment_id": att, "attempts": attempt, "max_attempts": max, "error_code": code, "updated_at": updated.UTC()}) + } + if rows.Err() != nil { + log.Fatal("failed jobs query interrupted") + } + json.NewEncoder(os.Stdout).Encode(records) + return + } + if *replay != "" { + operation, stop := context.WithTimeout(ctx, 10*time.Second) + defer stop() + if err = service.Replay(operation, *replay, *operator, *reason); err != nil { + log.Fatal(err) + } + log.Print("Replay committed with audit record") + return + } + r := redis.NewClient(&redis.Options{Addr: cfg.RedisAddr, DialTimeout: 2 * time.Second, ReadTimeout: 2 * time.Second, WriteTimeout: 2 * time.Second, MaxRetries: -1, ContextTimeoutEnabled: true}) + defer r.Close() + log.Printf("Worker started: concurrency=%d prefetch=%d timeout=%s lease=%s pixel_budget=%d", options.Concurrency, options.Prefetch, options.Timeout, options.Lease, options.PixelBudget) + for ctx.Err() == nil { + err = service.RunWorker(ctx, r) + if err != nil { + log.Print("worker broker connection will retry") + } + select { + case <-ctx.Done(): + return + case <-time.After(time.Second): + } + } +} diff --git a/compose.example.yaml b/compose.example.yaml index 792b3f4e..76a785ff 100644 --- a/compose.example.yaml +++ b/compose.example.yaml @@ -1,14 +1,12 @@ # Topology worksheet, deliberately NOT a runnable stack (no application supplied). # Implement compose.yaml or stack.yaml; do not submit this empty file as deployment. # Service names below are logical roles, not imposed container names. -x-lab-number: 5 +x-lab-number: 4 x-required-roles: - api - postgres - load_balancer - s3 - - broker - - worker # TODO: implement real images/builds, network wiring, volumes, healthchecks, # credentials and bootstrap. Details: contracts/infrastructure.json and README.md. services: {} diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 00000000..7d43834e --- /dev/null +++ b/compose.yaml @@ -0,0 +1,182 @@ +name: mtusi2026lab5 +services: + postgres: + image: postgres:17.6-alpine3.22 + environment: + POSTGRES_USER: messenger + POSTGRES_DB: messenger + POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password + secrets: + - postgres_password + volumes: + - postgres_data:/var/lib/postgresql/data + healthcheck: + test: [CMD-SHELL, 'pg_isready -U messenger -d messenger'] + interval: 2s + timeout: 2s + retries: 30 + cpus: 1.0 + mem_limit: 512m + redis: + image: redis:7.4.5-alpine3.21 + command: [redis-server, /usr/local/etc/redis/redis.conf] + volumes: + - redis_data:/data + - ./infra/redis.conf:/usr/local/etc/redis/redis.conf:ro + healthcheck: + test: [CMD, redis-cli, ping] + interval: 2s + timeout: 2s + retries: 30 + cpus: 0.5 + mem_limit: 384m + minio: + image: mtusi-minio:RELEASE.2025-09-07T16-13-09Z + build: + context: . + dockerfile: Dockerfile.storage + target: minio + secrets: [s3_root_access_key, s3_root_secret_key] + volumes: [s3_data:/data] + healthcheck: + test: [CMD, wget, -q, -T, '2', -O, /dev/null, 'http://127.0.0.1:9000/minio/health/live'] + interval: 2s + timeout: 3s + start_period: 15s + retries: 30 + cpus: 1.0 + mem_limit: 512m + stop_grace_period: 20s + s3_bootstrap: + image: mtusi-mc:RELEASE.2025-08-13T08-35-41Z + build: + context: . + dockerfile: Dockerfile.storage + target: mc + entrypoint: [/bin/sh, /bootstrap.sh] + configs: + - source: s3_bootstrap + target: /bootstrap.sh + - source: s3_policy + target: /policy.json + secrets: [s3_root_access_key, s3_root_secret_key, s3_access_key, s3_secret_key] + depends_on: + minio: + condition: service_healthy + cpus: 0.5 + mem_limit: 512m + migrations: + image: mtusi-migrations:lab5 + build: + context: . + target: migrations + environment: + GOOSE_DRIVER: postgres + GOOSE_DBSTRING: host=postgres user=messenger dbname=messenger sslmode=disable connect_timeout=5 + POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password + secrets: + - postgres_password + depends_on: + postgres: + condition: service_healthy + cpus: 0.5 + mem_limit: 128m + api: + build: . + image: mtusi-messenger:lab5 + environment: &api_environment + POSTGRES_HOST: postgres + POSTGRES_USER: messenger + POSTGRES_DB: messenger + POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password + POSTGRES_MAX_CONNS: '10' + REDIS_ADDR: redis:6379 + CURSOR_KEY_FILE: /run/secrets/cursor_key + SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} + QUERY_TIMEOUT_MS: '2000' + S3_ENDPOINT: minio:9000 + S3_BUCKET: attachments + S3_ACCESS_KEY_FILE: /run/secrets/s3_access_key + S3_SECRET_KEY_FILE: /run/secrets/s3_secret_key + S3_USE_SSL: 'false' + GOMEMLIMIT: 1152MiB + GOGC: '50' + secrets: &api_secrets + - postgres_password + - cursor_key + - s3_access_key + - s3_secret_key + ports: + - '127.0.0.1:${PORT:-18085}:8080' + depends_on: + postgres: + condition: service_healthy + redis: + condition: service_healthy + migrations: + condition: service_completed_successfully + s3_bootstrap: + condition: service_completed_successfully + cpus: 1.0 + mem_limit: 1536m + stop_grace_period: 10s + worker: + image: mtusi-messenger:lab5 + build: . + entrypoint: [/usr/local/bin/worker] + environment: + <<: *api_environment + WORKER_CONCURRENCY: '2' + WORKER_PREFETCH: '4' + WORKER_MAX_ATTEMPTS: '5' + WORKER_TIMEOUT_SECONDS: '25' + WORKER_LEASE_SECONDS: '40' + WORKER_PIXEL_BUDGET: '40000000' + secrets: *api_secrets + healthcheck: {disable: true} + depends_on: + migrations: {condition: service_completed_successfully} + s3_bootstrap: {condition: service_completed_successfully} + redis: {condition: service_healthy} + cpus: 1.0 + mem_limit: 1536m + stop_grace_period: 10s + tests: + image: mtusi-messenger-tests:lab5 + profiles: [test] + build: + context: . + target: tests + environment: + <<: *api_environment + INTEGRATION_TESTS: '1' + secrets: *api_secrets + depends_on: + postgres: + condition: service_healthy + redis: + condition: service_healthy + cpus: 1.0 + mem_limit: 1g +configs: + s3_bootstrap: + file: ./infra/s3-bootstrap.sh + s3_policy: + file: ./infra/s3-policy.json +secrets: + s3_root_access_key: + file: ./secrets/s3_root_access_key + s3_root_secret_key: + file: ./secrets/s3_root_secret_key + s3_access_key: + file: ./secrets/s3_access_key + s3_secret_key: + file: ./secrets/s3_secret_key + postgres_password: + file: ./secrets/postgres_password + cursor_key: + file: ./secrets/cursor_key +volumes: + postgres_data: + redis_data: + s3_data: diff --git a/contracts/embed.go b/contracts/embed.go new file mode 100644 index 00000000..ef4b85ae --- /dev/null +++ b/contracts/embed.go @@ -0,0 +1,9 @@ +package contracts + +import _ "embed" + +// OpenAPI is embedded so Swagger UI works from a compiled binary and does not +// depend on the process working directory. +// +//go:embed openapi.json +var OpenAPI []byte diff --git a/dto/create_chat.go b/dto/create_chat.go new file mode 100644 index 00000000..25c42a03 --- /dev/null +++ b/dto/create_chat.go @@ -0,0 +1,13 @@ +package dto + +type CreateChatRequest struct { + Title string `json:"title"` + MemberIDs []string `json:"member_ids"` +} + +type CreateChatResponse struct { + ID string `json:"id"` + Title string `json:"title"` + MemberIDs []string `json:"member_ids"` + CreatedAt Timestamp `json:"created_at"` +} diff --git a/dto/create_message.go b/dto/create_message.go new file mode 100644 index 00000000..f89c57c2 --- /dev/null +++ b/dto/create_message.go @@ -0,0 +1,16 @@ +package dto + +type CreateMessageRequest struct { + ChatID string `json:"-"` + Text string `json:"text"` + AttachmentIDs []string `json:"attachment_ids"` +} + +type CreateMessageResponse struct { + ID string `json:"id"` + ChatID string `json:"chat_id"` + SenderID string `json:"sender_id"` + Text string `json:"text"` + AttachmentIDs []string `json:"attachment_ids"` + CreatedAt Timestamp `json:"created_at"` +} diff --git a/dto/create_message_json.go b/dto/create_message_json.go new file mode 100644 index 00000000..b92e99d4 --- /dev/null +++ b/dto/create_message_json.go @@ -0,0 +1,33 @@ +package dto + +import ( + "bytes" + "encoding/json" + "errors" +) + +// Keep absent attachment_ids equivalent to [], while rejecting JSON null and +// wrong types rather than quietly treating them as an empty message body. +func (r *CreateMessageRequest) UnmarshalJSON(data []byte) error { + type payload CreateMessageRequest + var fields map[string]json.RawMessage + if err := json.Unmarshal(data, &fields); err != nil || fields == nil { + return errors.New("Ожидается JSON-объект") + } + text, exists := fields["text"] + if !exists || bytes.Equal(bytes.TrimSpace(text), []byte("null")) { + return errors.New("Требуется строка text") + } + if ids, exists := fields["attachment_ids"]; exists && bytes.Equal(bytes.TrimSpace(ids), []byte("null")) { + return errors.New("attachment_ids должен быть массивом") + } + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + var decoded payload + if err := decoder.Decode(&decoded); err != nil { + return err + } + decoded.ChatID = r.ChatID + *r = CreateMessageRequest(decoded) + return nil +} diff --git a/dto/create_message_json_test.go b/dto/create_message_json_test.go new file mode 100644 index 00000000..0d97cd09 --- /dev/null +++ b/dto/create_message_json_test.go @@ -0,0 +1,21 @@ +package dto + +import ( + "encoding/json" + "testing" +) + +func TestMessageStrictFields(t *testing.T) { + for _, body := range []string{`null`, `[]`, `{}`, `{"text":null}`, `{"text":"x","attachment_ids":null}`, `{"text":"x","attachment_ids":"x"}`, `{"text":"x","extra":1}`} { + var r CreateMessageRequest + if err := json.Unmarshal([]byte(body), &r); err == nil { + t.Fatalf("accepted %s", body) + } + } + for _, body := range []string{`{"text":"x"}`, `{"text":"x","attachment_ids":[]}`, `{"text":"","attachment_ids":["id"]}`} { + var r CreateMessageRequest + if err := json.Unmarshal([]byte(body), &r); err != nil { + t.Fatalf("rejected %s: %v", body, err) + } + } +} diff --git a/dto/create_user.go b/dto/create_user.go new file mode 100644 index 00000000..af41015a --- /dev/null +++ b/dto/create_user.go @@ -0,0 +1,14 @@ +package dto + +type CreateUserRequest struct { + Password string `json:"password"` + Username string `json:"username"` + DisplayName string `json:"display_name"` +} + +type CreateUserResponse struct { + ID string `json:"id"` + Username string `json:"username"` + DisplayName string `json:"display_name"` + CreatedAt Timestamp `json:"created_at"` +} diff --git a/dto/current_user.go b/dto/current_user.go new file mode 100644 index 00000000..b82a032d --- /dev/null +++ b/dto/current_user.go @@ -0,0 +1,10 @@ +package dto + +type CurrentUserRequest struct{} + +type CurrentUserResponse struct { + ID string `json:"id"` + Username string `json:"username"` + DisplayName string `json:"display_name"` + CreatedAt Timestamp `json:"created_at"` +} diff --git a/dto/error.go b/dto/error.go new file mode 100644 index 00000000..c8c17c4d --- /dev/null +++ b/dto/error.go @@ -0,0 +1,11 @@ +package dto + +type ErrorResponse struct { + Error ErrorDetails `json:"error"` +} + +type ErrorDetails struct { + Code string `json:"code"` + Message string `json:"message"` + RequestID string `json:"request_id"` +} diff --git a/dto/get_chat.go b/dto/get_chat.go new file mode 100644 index 00000000..6ed9e1ef --- /dev/null +++ b/dto/get_chat.go @@ -0,0 +1,12 @@ +package dto + +type GetChatRequest struct { + ChatID string `json:"-"` +} + +type GetChatResponse struct { + ID string `json:"id"` + Title string `json:"title"` + MemberIDs []string `json:"member_ids"` + CreatedAt Timestamp `json:"created_at"` +} diff --git a/dto/list_chats.go b/dto/list_chats.go new file mode 100644 index 00000000..43f9eb16 --- /dev/null +++ b/dto/list_chats.go @@ -0,0 +1,18 @@ +package dto + +type ListChatsRequest struct { + Limit int `json:"-"` + Cursor string `json:"-"` +} + +type ListChatsResponse struct { + Items []ListChatsItem `json:"items"` + NextCursor *string `json:"next_cursor"` +} + +type ListChatsItem struct { + ID string `json:"id"` + Title string `json:"title"` + MemberIDs []string `json:"member_ids"` + CreatedAt Timestamp `json:"created_at"` +} diff --git a/dto/list_messages.go b/dto/list_messages.go new file mode 100644 index 00000000..35a38428 --- /dev/null +++ b/dto/list_messages.go @@ -0,0 +1,21 @@ +package dto + +type ListMessagesRequest struct { + ChatID string `json:"-"` + Limit int `json:"-"` + Cursor string `json:"-"` +} + +type ListMessagesResponse struct { + Items []ListMessagesItem `json:"items"` + NextCursor *string `json:"next_cursor"` +} + +type ListMessagesItem struct { + ID string `json:"id"` + ChatID string `json:"chat_id"` + SenderID string `json:"sender_id"` + Text string `json:"text"` + AttachmentIDs []string `json:"attachment_ids"` + CreatedAt Timestamp `json:"created_at"` +} diff --git a/dto/liveness.go b/dto/liveness.go new file mode 100644 index 00000000..830955e9 --- /dev/null +++ b/dto/liveness.go @@ -0,0 +1,7 @@ +package dto + +type LivenessRequest struct{} + +type LivenessResponse struct { + Status string `json:"status"` +} diff --git a/dto/readiness.go b/dto/readiness.go new file mode 100644 index 00000000..21573b78 --- /dev/null +++ b/dto/readiness.go @@ -0,0 +1,7 @@ +package dto + +type ReadinessRequest struct{} + +type ReadinessResponse struct { + Status string `json:"status"` +} diff --git a/dto/session.go b/dto/session.go new file mode 100644 index 00000000..bd2c8807 --- /dev/null +++ b/dto/session.go @@ -0,0 +1,8 @@ +package dto + +type CreateSessionResponse struct { + Token string `json:"token"` + TokenType string `json:"token_type"` + ExpiresAt Timestamp `json:"expires_at"` + User CreateUserResponse `json:"user"` +} diff --git a/dto/timestamp.go b/dto/timestamp.go new file mode 100644 index 00000000..9dab3e29 --- /dev/null +++ b/dto/timestamp.go @@ -0,0 +1,11 @@ +package dto + +import "time" + +// Timestamp preserves PostgreSQL microseconds and is readable by Python 3.9 clients. +// time.Time's variable-length fractional part is not supported by those clients. +type Timestamp time.Time + +func (t Timestamp) MarshalJSON() ([]byte, error) { + return []byte(`"` + time.Time(t).UTC().Format("2006-01-02T15:04:05.000000Z") + `"`), nil +} diff --git a/dto/timestamp_test.go b/dto/timestamp_test.go new file mode 100644 index 00000000..1b48033a --- /dev/null +++ b/dto/timestamp_test.go @@ -0,0 +1,15 @@ +package dto + +import ( + "encoding/json" + "testing" + "time" +) + +func TestTimestampFixedMicroseconds(t *testing.T) { + timestamp := Timestamp(time.Date(2026, 1, 2, 3, 4, 5, 123400000, time.UTC)) + encoded, err := json.Marshal(timestamp) + if err != nil || string(encoded) != `"2026-01-02T03:04:05.123400Z"` { + t.Fatalf("timestamp=%s err=%v", encoded, err) + } +} diff --git a/evidence/lab4-acceptance.json b/evidence/lab4-acceptance.json new file mode 100644 index 00000000..8f453015 --- /dev/null +++ b/evidence/lab4-acceptance.json @@ -0,0 +1,104 @@ +{ + "negative_cases": [ + { + "case": "oversized_bytes", + "status": 413 + }, + { + "case": "damaged_png", + "status": 415 + }, + { + "case": "corrupt_crc", + "status": 415 + }, + { + "case": "mime_spoof", + "status": 415 + }, + { + "case": "not_image", + "status": 415 + }, + { + "case": "unsupported_mime", + "status": 415 + }, + { + "case": "pixel_budget", + "status": 413 + }, + { + "case": "unsafe_slash", + "status": 400 + }, + { + "case": "unsafe_backslash", + "status": 400 + }, + { + "case": "unsafe_control", + "status": 400 + }, + { + "case": "empty_filename", + "status": 400 + }, + { + "case": "foreign_attachment", + "status": 404 + }, + { + "case": "foreign_chat_link", + "status": 404 + }, + { + "case": "unknown_attachment", + "status": 404 + }, + { + "case": "duplicate_ids", + "status": 400 + }, + { + "case": "missing_authentication", + "status": 401 + }, + { + "case": "unknown_variant", + "status": 404 + }, + { + "case": "chunked_oversized", + "status": 413 + } + ], + "failures": { + "client_disconnect": { + "metadata_added": 0, + "spool_files_remaining": 0 + }, + "upload_replica_failure": { + "upload_instance": "alixbvpbjnzvtqvo5hhfpokc6", + "download_instance": "h6fc30dhoabp0jcfl6zrpjdzx", + "recovery_seconds": 0.51, + "sha256": "8502afe2cc5bab33ac834c834874369d29e7896599b5a256d68d80c5395d99c3" + }, + "s3_outage": { + "liveness": 200, + "readiness": 503, + "recovery_seconds": 19.285 + } + }, + "checksums": { + "image/png": "8502afe2cc5bab33ac834c834874369d29e7896599b5a256d68d80c5395d99c3", + "image/jpeg": "41feb40d75a595386c72cfc8a5bc013c2dedc445b73316ebbd3b3eac13491c5d" + }, + "bucket_security": { + "anonymous_get_status": 403, + "create_bucket_denied": true, + "write_outside_prefix_denied": true, + "console_published": false, + "bootstrap_repeats": 2 + } +} diff --git a/evidence/lab4-acceptance.txt b/evidence/lab4-acceptance.txt new file mode 100644 index 00000000..3a0ea764 --- /dev/null +++ b/evidence/lab4-acceptance.txt @@ -0,0 +1,2 @@ +.venv/bin/python tests/own/lab4.py +PASS: PNG/JPEG, bounded uploads, MIME/damage/ACL/link errors, disconnect, private S3, repeat bootstrap, S3 outage. diff --git a/evidence/lab4-bucket-bootstrap.txt b/evidence/lab4-bucket-bootstrap.txt new file mode 100644 index 00000000..533378d4 --- /dev/null +++ b/evidence/lab4-bucket-bootstrap.txt @@ -0,0 +1,8 @@ +image mtusi-mc:RELEASE.2025-08-13T08-35-41Z could not be accessed on a registry to record +its digest. Each node will access mtusi-mc:RELEASE.2025-08-13T08-35-41Z independently, +possibly leading to different nodes running different +versions of the image. + +0pza81k652zzumhh8w5zfuxw8 +mtusi-lab4_s3-bootstrap.0.jjp4j3jx92l1@colima | PASS: private bucket and restricted API account configured. +mtusi-lab4_s3-bootstrap diff --git a/evidence/lab4-build.txt b/evidence/lab4-build.txt new file mode 100644 index 00000000..41301955 --- /dev/null +++ b/evidence/lab4-build.txt @@ -0,0 +1,112 @@ +DEPRECATED: The legacy builder is deprecated and will be removed in a future release. + Install the buildx component to build images with BuildKit: + https://docs.docker.com/go/buildx/ + +Sending build context to Docker daemon 401.9kB +Step 1/35 : FROM golang:1.26.4-alpine3.23@sha256:18b460dd17542c2ba43299a633cf6ebfc1115101509531471d7cfce1019af083 AS goose-builder + ---> 18b460dd1754 +Step 2/35 : RUN GOBIN=/out CGO_ENABLED=0 go install -tags='no_clickhouse no_libsql no_mssql no_mysql no_sqlite3 no_vertica no_ydb no_spanner' github.com/pressly/goose/v3/cmd/goose@v3.27.1 + ---> Using cache + ---> 7012ef857c0c +Step 3/35 : FROM alpine:3.23@sha256:075c2c1a4068c1e251228ca2b0ea8b163f835ca5d66e758b93c7fc89b1995616 AS migrations + ---> 075c2c1a4068 +Step 4/35 : COPY --from=goose-builder /out/goose /usr/local/bin/goose + ---> Using cache + ---> 6a0ad52336c1 +Step 5/35 : COPY migrations /migrations + ---> Using cache + ---> 19018c7bfac9 +Step 6/35 : COPY infra/migrate.sh /usr/local/bin/migrate + ---> Using cache + ---> 0cc075ba3459 +Step 7/35 : USER 10001:10001 + ---> Using cache + ---> 37de51af32cd +Step 8/35 : ENTRYPOINT ["/usr/local/bin/migrate"] + ---> Using cache + ---> e7539a967679 +Step 9/35 : CMD ["up"] + ---> Using cache + ---> 841d9bb239cd +Step 10/35 : FROM golang:1.26.4-alpine3.23@sha256:18b460dd17542c2ba43299a633cf6ebfc1115101509531471d7cfce1019af083 AS builder + ---> 18b460dd1754 +Step 11/35 : WORKDIR /src + ---> Using cache + ---> 1ba013278a4a +Step 12/35 : RUN apk add --no-cache gcc musl-dev + ---> Using cache + ---> a0ea65f0bded +Step 13/35 : COPY go.mod go.sum ./ + ---> Using cache + ---> e98ccecfb093 +Step 14/35 : RUN go mod download + ---> Using cache + ---> 91d546c71507 +Step 15/35 : COPY cmd ./cmd + ---> Using cache + ---> b4e431a9d5f2 +Step 16/35 : COPY contracts ./contracts + ---> Using cache + ---> 958477d6c98e +Step 17/35 : COPY dto ./dto + ---> Using cache + ---> d115fe2e1af4 +Step 18/35 : COPY internal ./internal + ---> 2f61826e3774 +Step 19/35 : COPY migrations ./migrations + ---> d96dd811bc83 +Step 20/35 : RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/messenger ./cmd + ---> Running in 3d7cd429d659 + ---> Removed intermediate container 3d7cd429d659 + ---> 2ad69db4c288 +Step 21/35 : RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/reconcile ./cmd/reconcile + ---> Running in 7b9a510ed472 + ---> Removed intermediate container 7b9a510ed472 + ---> 4a49dc2719a3 +Step 22/35 : FROM builder AS tests + ---> 4a49dc2719a3 +Step 23/35 : COPY --from=goose-builder /out/goose /usr/local/bin/goose + ---> 5df1413dfc44 +Step 24/35 : ENV GOOSE_MIGRATION_DIR=/src/migrations + ---> Running in c30eee45a5e7 + ---> Removed intermediate container c30eee45a5e7 + ---> 173325b59e7d +Step 25/35 : CMD ["go", "test", "-p=1", "-race", "-count=1", "-v", "./..."] + ---> Running in 384e08125582 + ---> Removed intermediate container 384e08125582 + ---> 187ea6b3bcac +Step 26/35 : FROM alpine:3.23@sha256:075c2c1a4068c1e251228ca2b0ea8b163f835ca5d66e758b93c7fc89b1995616 + ---> 075c2c1a4068 +Step 27/35 : RUN addgroup -S messenger && adduser -S -D -H -u 10001 -G messenger messenger + ---> Using cache + ---> 33192b561bfc +Step 28/35 : COPY --from=builder --chown=messenger:messenger /out/messenger /usr/local/bin/messenger + ---> 37a18e0c6edf +Step 29/35 : COPY --from=builder --chown=messenger:messenger /out/reconcile /usr/local/bin/reconcile + ---> b0e79d0416ba +Step 30/35 : ENV PORT=8080 + ---> Running in 48da45f81d52 + ---> Removed intermediate container 48da45f81d52 + ---> a7c04e9ff97b +Step 31/35 : EXPOSE 8080 + ---> Running in 671ff92f3fad + ---> Removed intermediate container 671ff92f3fad + ---> e56b07b42f04 +Step 32/35 : USER messenger:messenger + ---> Running in 8003e4ea3b5d + ---> Removed intermediate container 8003e4ea3b5d + ---> 48b4424b156b +Step 33/35 : HEALTHCHECK --interval=10s --timeout=3s --start-period=3s --retries=3 CMD wget -q -O /dev/null "http://127.0.0.1:${PORT}/health/ready" || exit 1 + ---> Running in c05d11001e2b + ---> Removed intermediate container c05d11001e2b + ---> 563fbe4dcd7d +Step 34/35 : STOPSIGNAL SIGTERM + ---> Running in 8fb80a0e0f6c + ---> Removed intermediate container 8fb80a0e0f6c + ---> c5a0a88ba147 +Step 35/35 : ENTRYPOINT ["/usr/local/bin/messenger"] + ---> Running in 9e51b29d5939 + ---> Removed intermediate container 9e51b29d5939 + ---> c28dcd6e4410 +Successfully built c28dcd6e4410 +Successfully tagged mtusi-messenger:lab4 diff --git a/evidence/lab4-deploy.txt b/evidence/lab4-deploy.txt new file mode 100644 index 00000000..6a3e6ce5 --- /dev/null +++ b/evidence/lab4-deploy.txt @@ -0,0 +1,313 @@ +.venv/bin/python scripts/swarm.py up +vphhh79vd5ti8501q6m9lzulj +Local secrets are ready. +DEPRECATED: The legacy builder is deprecated and will be removed in a future release. + Install the buildx component to build images with BuildKit: + https://docs.docker.com/go/buildx/ + +Sending build context to Docker daemon 398.8kB +Step 1/20 : FROM golang:1.26.4-alpine3.23@sha256:18b460dd17542c2ba43299a633cf6ebfc1115101509531471d7cfce1019af083 AS minio-builder + ---> 18b460dd1754 +Step 2/20 : ADD --checksum=sha256:8b11129f6a6830768bcdebab569290ad956618f5ff6ef4857b633acb64f95126 https://codeload.github.com/minio/minio/tar.gz/01ce918d8279a20e4706b96a64396146894adee4 /tmp/source.tar.gz + + + ---> Using cache + ---> 4a2b9310629e +Step 3/20 : RUN mkdir /src && tar -xzf /tmp/source.tar.gz -C /src --strip-components=1 + ---> Using cache + ---> 5166de215d05 +Step 4/20 : WORKDIR /src + ---> Using cache + ---> 1f12c7444ff0 +Step 5/20 : RUN CGO_ENABLED=0 go build -trimpath -ldflags='-s -w' -o /out/minio . + ---> Using cache + ---> 8477e9d7324c +Step 6/20 : RUN echo '8b11129f6a6830768bcdebab569290ad956618f5ff6ef4857b633acb64f95126 /tmp/source.tar.gz' | sha256sum -c - + ---> Using cache + ---> 94162de69c8c +Step 7/20 : FROM golang:1.26.4-alpine3.23@sha256:18b460dd17542c2ba43299a633cf6ebfc1115101509531471d7cfce1019af083 AS mc-builder + ---> 18b460dd1754 +Step 8/20 : ADD --checksum=sha256:4cea8ed209c8f96e59ea1a5cc4901019b54c2be6d6f5f16c6749ea8bdcf4172e https://codeload.github.com/minio/mc/tar.gz/d6541ea280b73a834b64d4097e21f2be77676104 /tmp/source.tar.gz + + + ---> Using cache + ---> 5e135fc72a2c +Step 9/20 : RUN mkdir /src && tar -xzf /tmp/source.tar.gz -C /src --strip-components=1 + ---> Using cache + ---> cbffdcf35dd5 +Step 10/20 : WORKDIR /src + ---> Using cache + ---> 3322378e2ebd +Step 11/20 : RUN CGO_ENABLED=0 go build -trimpath -ldflags='-s -w' -o /out/mc . + ---> Using cache + ---> 0aba858f1d48 +Step 12/20 : RUN echo '4cea8ed209c8f96e59ea1a5cc4901019b54c2be6d6f5f16c6749ea8bdcf4172e /tmp/source.tar.gz' | sha256sum -c - + ---> Using cache + ---> af0a57fdfed1 +Step 13/20 : FROM alpine:3.23@sha256:075c2c1a4068c1e251228ca2b0ea8b163f835ca5d66e758b93c7fc89b1995616 AS minio + ---> 075c2c1a4068 +Step 14/20 : LABEL org.opencontainers.image.source="https://github.com/minio/minio" org.opencontainers.image.revision="01ce918d8279a20e4706b96a64396146894adee4" org.opencontainers.image.version="RELEASE.2025-09-07T16-13-09Z" org.opencontainers.image.licenses="AGPL-3.0" + ---> Using cache + ---> 57200264604d +Step 15/20 : RUN mkdir /data && chown 10001:10001 /data + ---> Using cache + ---> c7024406f9a9 +Step 16/20 : COPY --from=minio-builder /out/minio /usr/local/bin/minio + ---> Using cache + ---> 0d1965ab7125 +Step 17/20 : COPY infra/minio-entrypoint.sh /usr/local/bin/start-minio + ---> Using cache + ---> e5c21da70a4f +Step 18/20 : USER 10001:10001 + ---> Using cache + ---> 9bc52122d9f2 +Step 19/20 : EXPOSE 9000 + ---> Using cache + ---> 2ca448e77273 +Step 20/20 : ENTRYPOINT ["/usr/local/bin/start-minio"] + ---> Using cache + ---> 3a0797aa5ead +Successfully built 3a0797aa5ead +Successfully tagged mtusi-minio:RELEASE.2025-09-07T16-13-09Z +DEPRECATED: The legacy builder is deprecated and will be removed in a future release. + Install the buildx component to build images with BuildKit: + https://docs.docker.com/go/buildx/ + +Sending build context to Docker daemon 398.8kB +Step 1/25 : FROM golang:1.26.4-alpine3.23@sha256:18b460dd17542c2ba43299a633cf6ebfc1115101509531471d7cfce1019af083 AS minio-builder + ---> 18b460dd1754 +Step 2/25 : ADD --checksum=sha256:8b11129f6a6830768bcdebab569290ad956618f5ff6ef4857b633acb64f95126 https://codeload.github.com/minio/minio/tar.gz/01ce918d8279a20e4706b96a64396146894adee4 /tmp/source.tar.gz + + + ---> Using cache + ---> 4a2b9310629e +Step 3/25 : RUN mkdir /src && tar -xzf /tmp/source.tar.gz -C /src --strip-components=1 + ---> Using cache + ---> 5166de215d05 +Step 4/25 : WORKDIR /src + ---> Using cache + ---> 1f12c7444ff0 +Step 5/25 : RUN CGO_ENABLED=0 go build -trimpath -ldflags='-s -w' -o /out/minio . + ---> Using cache + ---> 8477e9d7324c +Step 6/25 : RUN echo '8b11129f6a6830768bcdebab569290ad956618f5ff6ef4857b633acb64f95126 /tmp/source.tar.gz' | sha256sum -c - + ---> Using cache + ---> 94162de69c8c +Step 7/25 : FROM golang:1.26.4-alpine3.23@sha256:18b460dd17542c2ba43299a633cf6ebfc1115101509531471d7cfce1019af083 AS mc-builder + ---> 18b460dd1754 +Step 8/25 : ADD --checksum=sha256:4cea8ed209c8f96e59ea1a5cc4901019b54c2be6d6f5f16c6749ea8bdcf4172e https://codeload.github.com/minio/mc/tar.gz/d6541ea280b73a834b64d4097e21f2be77676104 /tmp/source.tar.gz + + + ---> Using cache + ---> 5e135fc72a2c +Step 9/25 : RUN mkdir /src && tar -xzf /tmp/source.tar.gz -C /src --strip-components=1 + ---> Using cache + ---> cbffdcf35dd5 +Step 10/25 : WORKDIR /src + ---> Using cache + ---> 3322378e2ebd +Step 11/25 : RUN CGO_ENABLED=0 go build -trimpath -ldflags='-s -w' -o /out/mc . + ---> Using cache + ---> 0aba858f1d48 +Step 12/25 : RUN echo '4cea8ed209c8f96e59ea1a5cc4901019b54c2be6d6f5f16c6749ea8bdcf4172e /tmp/source.tar.gz' | sha256sum -c - + ---> Using cache + ---> af0a57fdfed1 +Step 13/25 : FROM alpine:3.23@sha256:075c2c1a4068c1e251228ca2b0ea8b163f835ca5d66e758b93c7fc89b1995616 AS minio + ---> 075c2c1a4068 +Step 14/25 : LABEL org.opencontainers.image.source="https://github.com/minio/minio" org.opencontainers.image.revision="01ce918d8279a20e4706b96a64396146894adee4" org.opencontainers.image.version="RELEASE.2025-09-07T16-13-09Z" org.opencontainers.image.licenses="AGPL-3.0" + ---> Using cache + ---> 57200264604d +Step 15/25 : RUN mkdir /data && chown 10001:10001 /data + ---> Using cache + ---> c7024406f9a9 +Step 16/25 : COPY --from=minio-builder /out/minio /usr/local/bin/minio + ---> Using cache + ---> 0d1965ab7125 +Step 17/25 : COPY infra/minio-entrypoint.sh /usr/local/bin/start-minio + ---> Using cache + ---> e5c21da70a4f +Step 18/25 : USER 10001:10001 + ---> Using cache + ---> 9bc52122d9f2 +Step 19/25 : EXPOSE 9000 + ---> Using cache + ---> 2ca448e77273 +Step 20/25 : ENTRYPOINT ["/usr/local/bin/start-minio"] + ---> Using cache + ---> 3a0797aa5ead +Step 21/25 : FROM alpine:3.23@sha256:075c2c1a4068c1e251228ca2b0ea8b163f835ca5d66e758b93c7fc89b1995616 AS mc + ---> 075c2c1a4068 +Step 22/25 : LABEL org.opencontainers.image.source="https://github.com/minio/mc" org.opencontainers.image.revision="d6541ea280b73a834b64d4097e21f2be77676104" org.opencontainers.image.version="RELEASE.2025-08-13T08-35-41Z" org.opencontainers.image.licenses="AGPL-3.0" + ---> Using cache + ---> 9257dca2de26 +Step 23/25 : COPY --from=mc-builder /out/mc /usr/local/bin/mc + ---> Using cache + ---> 4bea21e69e8d +Step 24/25 : USER 10001:10001 + ---> Using cache + ---> 45d00b9fce3e +Step 25/25 : ENTRYPOINT ["mc"] + ---> Using cache + ---> 0713832dbf4a +Successfully built 0713832dbf4a +Successfully tagged mtusi-mc:RELEASE.2025-08-13T08-35-41Z +DEPRECATED: The legacy builder is deprecated and will be removed in a future release. + Install the buildx component to build images with BuildKit: + https://docs.docker.com/go/buildx/ + +Sending build context to Docker daemon 398.3kB +Step 1/35 : FROM golang:1.26.4-alpine3.23@sha256:18b460dd17542c2ba43299a633cf6ebfc1115101509531471d7cfce1019af083 AS goose-builder + ---> 18b460dd1754 +Step 2/35 : RUN GOBIN=/out CGO_ENABLED=0 go install -tags='no_clickhouse no_libsql no_mssql no_mysql no_sqlite3 no_vertica no_ydb no_spanner' github.com/pressly/goose/v3/cmd/goose@v3.27.1 + ---> Using cache + ---> 7012ef857c0c +Step 3/35 : FROM alpine:3.23@sha256:075c2c1a4068c1e251228ca2b0ea8b163f835ca5d66e758b93c7fc89b1995616 AS migrations + ---> 075c2c1a4068 +Step 4/35 : COPY --from=goose-builder /out/goose /usr/local/bin/goose + ---> Using cache + ---> 6a0ad52336c1 +Step 5/35 : COPY migrations /migrations + ---> Using cache + ---> 19018c7bfac9 +Step 6/35 : COPY infra/migrate.sh /usr/local/bin/migrate + ---> Using cache + ---> 0cc075ba3459 +Step 7/35 : USER 10001:10001 + ---> Using cache + ---> 37de51af32cd +Step 8/35 : ENTRYPOINT ["/usr/local/bin/migrate"] + ---> Using cache + ---> e7539a967679 +Step 9/35 : CMD ["up"] + ---> Using cache + ---> 841d9bb239cd +Step 10/35 : FROM golang:1.26.4-alpine3.23@sha256:18b460dd17542c2ba43299a633cf6ebfc1115101509531471d7cfce1019af083 AS builder + ---> 18b460dd1754 +Step 11/35 : WORKDIR /src + ---> Using cache + ---> 1ba013278a4a +Step 12/35 : RUN apk add --no-cache gcc musl-dev + ---> Using cache + ---> a0ea65f0bded +Step 13/35 : COPY go.mod go.sum ./ + ---> Using cache + ---> e98ccecfb093 +Step 14/35 : RUN go mod download + ---> Using cache + ---> 91d546c71507 +Step 15/35 : COPY cmd ./cmd + ---> Using cache + ---> b4e431a9d5f2 +Step 16/35 : COPY contracts ./contracts + ---> Using cache + ---> 958477d6c98e +Step 17/35 : COPY dto ./dto + ---> Using cache + ---> d115fe2e1af4 +Step 18/35 : COPY internal ./internal + ---> Using cache + ---> 72552b328db4 +Step 19/35 : COPY migrations ./migrations + ---> Using cache + ---> a68ac4a31860 +Step 20/35 : RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/messenger ./cmd + ---> Using cache + ---> 7303ceff230d +Step 21/35 : RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/reconcile ./cmd/reconcile + ---> Using cache + ---> e6cc7991dac9 +Step 22/35 : FROM builder AS tests + ---> e6cc7991dac9 +Step 23/35 : COPY --from=goose-builder /out/goose /usr/local/bin/goose + ---> Using cache + ---> 5749aa2abe35 +Step 24/35 : ENV GOOSE_MIGRATION_DIR=/src/migrations + ---> Using cache + ---> ca0a6f733ba8 +Step 25/35 : CMD ["go", "test", "-p=1", "-race", "-count=1", "-v", "./..."] + ---> Using cache + ---> c643755b8aac +Step 26/35 : FROM alpine:3.23@sha256:075c2c1a4068c1e251228ca2b0ea8b163f835ca5d66e758b93c7fc89b1995616 + ---> 075c2c1a4068 +Step 27/35 : RUN addgroup -S messenger && adduser -S -D -H -u 10001 -G messenger messenger + ---> Using cache + ---> 33192b561bfc +Step 28/35 : COPY --from=builder --chown=messenger:messenger /out/messenger /usr/local/bin/messenger + ---> Using cache + ---> 136320eda1d3 +Step 29/35 : COPY --from=builder --chown=messenger:messenger /out/reconcile /usr/local/bin/reconcile + ---> Using cache + ---> 4acf2a8fc638 +Step 30/35 : ENV PORT=8080 + ---> Using cache + ---> 6fbea06a8135 +Step 31/35 : EXPOSE 8080 + ---> Using cache + ---> 333a62acf202 +Step 32/35 : USER messenger:messenger + ---> Using cache + ---> 60a29210a7f2 +Step 33/35 : HEALTHCHECK --interval=10s --timeout=3s --start-period=3s --retries=3 CMD wget -q -O /dev/null "http://127.0.0.1:${PORT}/health/ready" || exit 1 + ---> Using cache + ---> 803ac1f944e5 +Step 34/35 : STOPSIGNAL SIGTERM + ---> Using cache + ---> 40299d0a0f9f +Step 35/35 : ENTRYPOINT ["/usr/local/bin/messenger"] + ---> Using cache + ---> c81ae0702578 +Successfully built c81ae0702578 +Successfully tagged mtusi-messenger:lab4 +DEPRECATED: The legacy builder is deprecated and will be removed in a future release. + Install the buildx component to build images with BuildKit: + https://docs.docker.com/go/buildx/ + +Sending build context to Docker daemon 398.3kB +Step 1/9 : FROM golang:1.26.4-alpine3.23@sha256:18b460dd17542c2ba43299a633cf6ebfc1115101509531471d7cfce1019af083 AS goose-builder + ---> 18b460dd1754 +Step 2/9 : RUN GOBIN=/out CGO_ENABLED=0 go install -tags='no_clickhouse no_libsql no_mssql no_mysql no_sqlite3 no_vertica no_ydb no_spanner' github.com/pressly/goose/v3/cmd/goose@v3.27.1 + ---> Using cache + ---> 7012ef857c0c +Step 3/9 : FROM alpine:3.23@sha256:075c2c1a4068c1e251228ca2b0ea8b163f835ca5d66e758b93c7fc89b1995616 AS migrations + ---> 075c2c1a4068 +Step 4/9 : COPY --from=goose-builder /out/goose /usr/local/bin/goose + ---> Using cache + ---> 6a0ad52336c1 +Step 5/9 : COPY migrations /migrations + ---> Using cache + ---> 19018c7bfac9 +Step 6/9 : COPY infra/migrate.sh /usr/local/bin/migrate + ---> Using cache + ---> 0cc075ba3459 +Step 7/9 : USER 10001:10001 + ---> Using cache + ---> 37de51af32cd +Step 8/9 : ENTRYPOINT ["/usr/local/bin/migrate"] + ---> Using cache + ---> e7539a967679 +Step 9/9 : CMD ["up"] + ---> Using cache + ---> 841d9bb239cd +Successfully built 841d9bb239cd +Successfully tagged mtusi-migrations:lab4 +kkk3r78zn9bb09xudyehchs4p +mtusi-lab4_migrations.0.mzx2ds4dsbyh@colima | 2026/10/28 19:14:47 OK 001_initial.sql (17.71ms) +mtusi-lab4_migrations.0.mzx2ds4dsbyh@colima | 2026/10/28 19:14:47 OK 002_idempotency.sql (2.54ms) +mtusi-lab4_migrations.0.mzx2ds4dsbyh@colima | 2026/10/28 19:14:47 OK 003_attachments.sql (5.13ms) +mtusi-lab4_migrations.0.mzx2ds4dsbyh@colima | 2026/10/28 19:14:47 OK 004_message_attachments.sql (2.34ms) +mtusi-lab4_migrations.0.mzx2ds4dsbyh@colima | 2026/10/28 19:14:47 goose: successfully migrated database to version: 4 +mtusi-lab4_migrations +Since --detach=false was not specified, tasks will be created in the background. +In a future release, --detach=false will become the default. +Updating service mtusi-lab4_redis (id: zlhenabo1vgqarsazgqa6d897) +Updating service mtusi-lab4_minio (id: ygvoo1fje6vqlxw02ugw7awa8) +Updating service mtusi-lab4_api (id: xiueb8lcewfukmzn8wocqcmjh) +Updating service mtusi-lab4_lb (id: uo65o8allz5azrqbx4zchi811) +Updating service mtusi-lab4_postgres (id: vxi6yu73ah85o0xog5w8r1t5k) +f6qbximmjnxx8ezv05jxgsngz +mtusi-lab4_s3-bootstrap.0.p9vksdlsfz2l@colima | PASS: private bucket and restricted API account configured. +mtusi-lab4_s3-bootstrap +mtusi-lab4_api scaled to 2 +mtusi-lab4_api +PASS: rolling update completed +PASS: Swarm stack ready at http://localhost:8080 diff --git a/evidence/lab4-environment.json b/evidence/lab4-environment.json new file mode 100644 index 00000000..d2856953 --- /dev/null +++ b/evidence/lab4-environment.json @@ -0,0 +1,81 @@ +{ + "docker_engine": { + "cpus": 2, + "memory_bytes": 2053644288, + "os": "Ubuntu 24.04.4 LTS", + "kernel": "6.8.0-117-generic", + "architecture": "aarch64", + "version": "29.5.2" + }, + "host": { + "architecture": "arm64", + "system": "Darwin", + "model": "MacBookPro18,3", + "cpu_cores": 8, + "memory_bytes": 17179869184 + }, + "host_go": "go version go1.27.2 darwin/arm64", + "host_python": "3.9.6", + "images": [ + { + "tag": "mtusi-messenger:lab4", + "image_id": "sha256:c28dcd6e4410ee011a827852286b93296c8a0f20ddb268524b4d92371014403e", + "repo_digests": [ + "mtusi-messenger@sha256:c28dcd6e4410ee011a827852286b93296c8a0f20ddb268524b4d92371014403e" + ], + "source_labels": {} + }, + { + "tag": "mtusi-minio:RELEASE.2025-09-07T16-13-09Z", + "image_id": "sha256:3a0797aa5eadafe23e8a7b205c39511a9280b7500da6ef0e5d604cc74f46c3ed", + "repo_digests": [ + "mtusi-minio@sha256:3a0797aa5eadafe23e8a7b205c39511a9280b7500da6ef0e5d604cc74f46c3ed" + ], + "source_labels": { + "org.opencontainers.image.licenses": "AGPL-3.0", + "org.opencontainers.image.revision": "01ce918d8279a20e4706b96a64396146894adee4", + "org.opencontainers.image.source": "https://github.com/minio/minio", + "org.opencontainers.image.version": "RELEASE.2025-09-07T16-13-09Z" + } + }, + { + "tag": "mtusi-mc:RELEASE.2025-08-13T08-35-41Z", + "image_id": "sha256:0713832dbf4ab9a3b716ab0a4cca6629fec96224bc1425f26ab6ba42c5463a99", + "repo_digests": [ + "mtusi-mc@sha256:0713832dbf4ab9a3b716ab0a4cca6629fec96224bc1425f26ab6ba42c5463a99" + ], + "source_labels": { + "org.opencontainers.image.licenses": "AGPL-3.0", + "org.opencontainers.image.revision": "d6541ea280b73a834b64d4097e21f2be77676104", + "org.opencontainers.image.source": "https://github.com/minio/mc", + "org.opencontainers.image.version": "RELEASE.2025-08-13T08-35-41Z" + } + }, + { + "tag": "postgres:17.6-alpine3.22", + "image_id": "sha256:ef257d85f76e48da1c64832459b59fcaba1a4dac97bf5d7450c77753542eee94", + "repo_digests": [ + "postgres@sha256:ef257d85f76e48da1c64832459b59fcaba1a4dac97bf5d7450c77753542eee94" + ], + "source_labels": {} + }, + { + "tag": "redis:7.4.5-alpine3.21", + "image_id": "sha256:bb186d083732f669da90be8b0f975a37812b15e913465bb14d845db72a4e3e08", + "repo_digests": [ + "redis@sha256:bb186d083732f669da90be8b0f975a37812b15e913465bb14d845db72a4e3e08" + ], + "source_labels": {} + }, + { + "tag": "haproxy:3.2.6-alpine", + "image_id": "sha256:3a819392f5a6af2a9203d1c63ff0feba74f0c940623a558511be06d7d85e361c", + "repo_digests": [ + "haproxy@sha256:3a819392f5a6af2a9203d1c63ff0feba74f0c940623a558511be06d7d85e361c" + ], + "source_labels": {} + } + ], + "go_container_version": "1.26.4", + "test_data": "synthetic; no credentials/tokens saved" +} diff --git a/evidence/lab4-failover.txt b/evidence/lab4-failover.txt new file mode 100644 index 00000000..946745b7 --- /dev/null +++ b/evidence/lab4-failover.txt @@ -0,0 +1,4 @@ +.venv/bin/python 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": 112, "failed_attempts": 2, "first_recovery_seconds": 2.061} +PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence. diff --git a/evidence/lab4-go-tests.txt b/evidence/lab4-go-tests.txt new file mode 100644 index 00000000..d915cb26 --- /dev/null +++ b/evidence/lab4-go-tests.txt @@ -0,0 +1,13 @@ +? gitflic.ru/akselbant/mtusi2026lab1-fork/cmd [no test files] +? gitflic.ru/akselbant/mtusi2026lab1-fork/cmd/reconcile [no test files] +? gitflic.ru/akselbant/mtusi2026lab1-fork/contracts [no test files] +ok gitflic.ru/akselbant/mtusi2026lab1-fork/dto (cached) +ok gitflic.ru/akselbant/mtusi2026lab1-fork/internal/app/chat 13.184s +ok gitflic.ru/akselbant/mtusi2026lab1-fork/internal/attachment 2.905s +? gitflic.ru/akselbant/mtusi2026lab1-fork/internal/config [no test files] +? gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain [no test files] +ok gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/password (cached) +? gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/repository [no test files] +ok gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/repository/postgres 2.388s +? gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/session [no test files] +ok gitflic.ru/akselbant/mtusi2026lab1-fork/internal/usecase/chat (cached) diff --git a/evidence/lab4-integration.txt b/evidence/lab4-integration.txt new file mode 100644 index 00000000..9b82a00d --- /dev/null +++ b/evidence/lab4-integration.txt @@ -0,0 +1,338 @@ +.venv/bin/python scripts/swarm.py test-integration +DEPRECATED: The legacy builder is deprecated and will be removed in a future release. + Install the buildx component to build images with BuildKit: + https://docs.docker.com/go/buildx/ + +Sending build context to Docker daemon 398.3kB +Step 1/25 : FROM golang:1.26.4-alpine3.23@sha256:18b460dd17542c2ba43299a633cf6ebfc1115101509531471d7cfce1019af083 AS goose-builder + ---> 18b460dd1754 +Step 2/25 : RUN GOBIN=/out CGO_ENABLED=0 go install -tags='no_clickhouse no_libsql no_mssql no_mysql no_sqlite3 no_vertica no_ydb no_spanner' github.com/pressly/goose/v3/cmd/goose@v3.27.1 + ---> Using cache + ---> 7012ef857c0c +Step 3/25 : FROM alpine:3.23@sha256:075c2c1a4068c1e251228ca2b0ea8b163f835ca5d66e758b93c7fc89b1995616 AS migrations + ---> 075c2c1a4068 +Step 4/25 : COPY --from=goose-builder /out/goose /usr/local/bin/goose + ---> Using cache + ---> 6a0ad52336c1 +Step 5/25 : COPY migrations /migrations + ---> Using cache + ---> 19018c7bfac9 +Step 6/25 : COPY infra/migrate.sh /usr/local/bin/migrate + ---> Using cache + ---> 0cc075ba3459 +Step 7/25 : USER 10001:10001 + ---> Using cache + ---> 37de51af32cd +Step 8/25 : ENTRYPOINT ["/usr/local/bin/migrate"] + ---> Using cache + ---> e7539a967679 +Step 9/25 : CMD ["up"] + ---> Using cache + ---> 841d9bb239cd +Step 10/25 : FROM golang:1.26.4-alpine3.23@sha256:18b460dd17542c2ba43299a633cf6ebfc1115101509531471d7cfce1019af083 AS builder + ---> 18b460dd1754 +Step 11/25 : WORKDIR /src + ---> Using cache + ---> 1ba013278a4a +Step 12/25 : RUN apk add --no-cache gcc musl-dev + ---> Using cache + ---> a0ea65f0bded +Step 13/25 : COPY go.mod go.sum ./ + ---> Using cache + ---> e98ccecfb093 +Step 14/25 : RUN go mod download + ---> Using cache + ---> 91d546c71507 +Step 15/25 : COPY cmd ./cmd + ---> Using cache + ---> b4e431a9d5f2 +Step 16/25 : COPY contracts ./contracts + ---> Using cache + ---> 958477d6c98e +Step 17/25 : COPY dto ./dto + ---> Using cache + ---> d115fe2e1af4 +Step 18/25 : COPY internal ./internal + ---> Using cache + ---> 72552b328db4 +Step 19/25 : COPY migrations ./migrations + ---> Using cache + ---> a68ac4a31860 +Step 20/25 : RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/messenger ./cmd + ---> Using cache + ---> 7303ceff230d +Step 21/25 : RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/reconcile ./cmd/reconcile + ---> Using cache + ---> e6cc7991dac9 +Step 22/25 : FROM builder AS tests + ---> e6cc7991dac9 +Step 23/25 : COPY --from=goose-builder /out/goose /usr/local/bin/goose + ---> Using cache + ---> 5749aa2abe35 +Step 24/25 : ENV GOOSE_MIGRATION_DIR=/src/migrations + ---> Using cache + ---> ca0a6f733ba8 +Step 25/25 : CMD ["go", "test", "-p=1", "-race", "-count=1", "-v", "./..."] + ---> Using cache + ---> c643755b8aac +Successfully built c643755b8aac +Successfully tagged mtusi-messenger-tests:lab4 +qs9c5xskdu6nyjiv287eg68b8 +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | ? gitflic.ru/akselbant/mtusi2026lab1-fork/cmd [no test files] +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | ? gitflic.ru/akselbant/mtusi2026lab1-fork/cmd/reconcile [no test files] +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | ? gitflic.ru/akselbant/mtusi2026lab1-fork/contracts [no test files] +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | === RUN TestMessageStrictFields +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | --- PASS: TestMessageStrictFields (0.00s) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | === RUN TestTimestampFixedMicroseconds +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | --- PASS: TestTimestampFixedMicroseconds (0.00s) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | PASS +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | ok gitflic.ru/akselbant/mtusi2026lab1-fork/dto 1.013s +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | === RUN TestRejectsMalformedJSON +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:40 request_id=94533522-1e48-4953-9857-91c107c2aac7 method=POST path=/api/v1/users status=400 response_bytes=140 latency=130.671µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | --- PASS: TestRejectsMalformedJSON (0.01s) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | === RUN TestHidesForeignChat +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:40 request_id=8b136f4b-a1b6-4756-9dda-92871979845c method=POST path=/api/v1/users status=201 response_bytes=141 latency=369.112982ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:41 request_id=df98ca4b-5f1f-4ef1-a8eb-7708ccfe2367 method=POST path=/api/v1/auth/sessions status=201 response_bytes=269 latency=397.145342ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:41 request_id=c535a54a-6ce6-49b0-8ec7-47e70ea04799 method=POST path=/api/v1/users status=201 response_bytes=147 latency=364.216754ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:41 request_id=fea0410a-7349-4fc3-8541-f479066736b7 method=POST path=/api/v1/auth/sessions status=201 response_bytes=275 latency=359.930021ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:41 request_id=b7201791-c957-4ee8-8237-2aab675777ec method=POST path=/api/v1/chats status=201 response_bytes=163 latency=174.381µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:41 request_id=30b379c6-e33c-42bc-963a-54de252a1e44 method=GET path=/api/v1/chats/:chat_id status=404 response_bytes=126 latency=53.002µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | --- PASS: TestHidesForeignChat (1.50s) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | === RUN TestRejectsEmptyMessage +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:42 request_id=92d81694-3fcf-452b-be3d-24e21f938fb8 method=POST path=/api/v1/users status=201 response_bytes=157 latency=411.707889ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:42 request_id=792cc573-4974-4744-86bc-7ce29f78c5a2 method=POST path=/api/v1/auth/sessions status=201 response_bytes=285 latency=357.462544ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:42 request_id=4aec085d-f3fe-4b56-a0f2-b6bb55c32fd5 method=POST path=/api/v1/chats status=201 response_bytes=163 latency=135.922µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:42 request_id=bae49af4-9cb9-414e-8227-7991f680a0ab method=POST path=/api/v1/chats/:chat_id/messages status=400 response_bytes=172 latency=150.047µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | --- PASS: TestRejectsEmptyMessage (0.77s) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | === RUN TestRejectsDuplicateUsername +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:42 request_id=c6f9b126-b2a0-4672-b4de-a59183cffe86 method=POST path=/api/v1/users status=201 response_bytes=149 latency=370.366912ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:43 request_id=c174982c-6a8d-4fc7-8d4b-6cbe68b34d70 method=POST path=/api/v1/auth/sessions status=201 response_bytes=277 latency=365.829696ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:43 request_id=b8771b83-4e05-4335-a6bd-4de115eb5e20 method=POST path=/api/v1/users status=409 response_bytes=170 latency=358.448604ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | --- PASS: TestRejectsDuplicateUsername (1.10s) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | === RUN TestPaginatesMessagesAcrossMultiplePages +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:44 request_id=fb5f658b-7688-4017-9758-bea1d60af1cf method=POST path=/api/v1/users status=201 response_bytes=151 latency=366.583521ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:44 request_id=ddf8c2e9-34d2-4b17-aaa5-66ee679b9a4b method=POST path=/api/v1/auth/sessions status=201 response_bytes=279 latency=393.325397ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:44 request_id=32abde1e-d2e7-46fe-ad10-210533f83bd5 method=POST path=/api/v1/chats status=201 response_bytes=163 latency=136.838µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:44 request_id=227b702f-3d9d-4307-a1a8-30ab4f7aa8f2 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=228 latency=217.05µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:44 request_id=edc8c38d-6beb-4353-b6c1-d1c8f337282b method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=228 latency=132.629µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:44 request_id=27b25c6f-8b85-4f74-9a26-bc175b6e490f method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=228 latency=120.337µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:44 request_id=148f8872-b793-4898-a57f-78f66d57fbb6 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=228 latency=115.879µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:44 request_id=d2b4fae7-2633-4406-920a-af6bad40e7c9 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=228 latency=113.254µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:44 request_id=65190391-2026-4f9e-b907-b52379ad8afe method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=228 latency=141.005µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:44 request_id=094c52b2-7bb7-4ba0-be47-2695d64f4867 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=228 latency=181.464µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:44 request_id=ebf5592b-9a0e-4ea4-8fa7-b7d2eb14639e method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=725 latency=304.594µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:44 request_id=c0d34ec3-f7c3-4639-8160-d6e32d09ff42 method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=725 latency=180.132µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:44 request_id=0e2daae8-eec7-4e5e-a222-2f11927517a0 method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=725 latency=168.339µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:44 request_id=b8dc3150-f39e-4d7b-a0af-38ffa5a8936d method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=259 latency=110.796µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | --- PASS: TestPaginatesMessagesAcrossMultiplePages (0.77s) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | === RUN TestConcurrentMessagesAreUnique +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:44 request_id=a35f6c93-191f-4fe2-8640-6390ceab09fc method=POST path=/api/v1/users status=201 response_bytes=153 latency=372.343576ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:45 request_id=4dd49805-f2ef-4166-b188-ebbbc1924d9a method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=371.622652ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:45 request_id=745e9e01-1f34-4e95-81fe-6a3ae7cf9ea4 method=POST path=/api/v1/users status=201 response_bytes=153 latency=394.884355ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:45 request_id=95ac49aa-2560-42da-90c1-902d76341ccd method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=358.911214ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:46 request_id=249bef9d-e9fb-462a-99c3-1946037d1d0c method=POST path=/api/v1/users status=201 response_bytes=153 latency=374.597959ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:46 request_id=ef3349aa-4db5-4ab6-998e-50fa2f3262bb method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=364.93841ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:47 request_id=3007dbff-cdb7-42b9-ac50-77dc7c2ebc4f method=POST path=/api/v1/users status=201 response_bytes=153 latency=396.618954ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:47 request_id=01f269ef-e3c5-4240-9070-37312feb0e6b method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=372.262695ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:47 request_id=ab7c6c66-e836-4704-a516-3c4b51322e74 method=POST path=/api/v1/users status=201 response_bytes=153 latency=358.500208ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:48 request_id=b5f8edd3-d534-401f-8e68-fac601795f3f method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=369.620285ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:48 request_id=1362a848-874b-4b9b-b7fe-735ae74cc76d method=POST path=/api/v1/users status=201 response_bytes=153 latency=401.141119ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:49 request_id=953f6f2b-9fd3-49c5-b660-94a56615c24c method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=376.048273ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:49 request_id=56532a32-ca19-4238-b539-486b339d0bbb method=POST path=/api/v1/users status=201 response_bytes=153 latency=365.0437ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:49 request_id=89c7cf01-2523-4ae6-9a85-dd1a76a61039 method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=362.393272ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:50 request_id=0af98040-fde9-4694-a646-c60f794e097f method=POST path=/api/v1/users status=201 response_bytes=153 latency=360.604883ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:50 request_id=92c16b19-7579-47aa-9fb0-a3595b644fc7 method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=373.615906ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:50 request_id=460293e1-83ce-4a90-9255-cea43854fe3f method=POST path=/api/v1/users status=201 response_bytes=153 latency=366.494027ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=f564332d-7da7-40c0-9842-20cf89412495 method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=375.265646ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=62b8365d-f837-4354-8383-1456f1b72154 method=POST path=/api/v1/users status=201 response_bytes=153 latency=358.727985ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=a2a37a46-5e62-41e6-bfa3-2bce4c2e3ad8 method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=395.19545ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=5267f89c-aaf1-47b4-8c6a-9714ca727915 method=POST path=/api/v1/chats status=201 response_bytes=514 latency=188.799µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=c5b24f54-0511-46a1-82e5-0061ec77cb32 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=208.924µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=f72ec60f-87ae-4bf6-b996-ce192a118119 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=159.047µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=8afe7b58-5dce-42a1-adf2-1145ac360d45 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=148.63µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=7b09b2e8-26b4-42af-bee4-016a8e269a6b method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=160.922µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=81276d1e-5a76-4f9b-a7aa-f9857012dc26 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=260.717µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=8904e3d2-be95-47dc-a2fa-d3eaf50a3578 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=142.714µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=a03ae327-db89-4091-b3af-578a51335de2 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=216.716µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=a498db7b-49fb-4935-bb51-891c908fa4f8 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=139.089µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=2c981e76-6d36-494c-89ba-3336d357095d method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=140.255µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=b9b68e40-c117-4bc7-8f41-b16dd197571a method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=150.047µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=7223bf26-18da-419a-a853-3b50f5f04a4b method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=132.047µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=16cc739c-a6a1-4c4c-a0bb-ec393bab1534 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=162.423µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=0aef904a-3e95-41de-b5b4-0bff73ed6722 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=153.297µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=25534c61-60fe-4374-bfda-db1354ea6012 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=145.714µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=53c00161-1317-49e3-84db-eb7c99300efa method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=146.422µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=1adf4594-5a16-4773-bff0-1b097ab75276 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=133.63µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=78902daf-2bbe-4307-a4d3-e6e9042a6291 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=180.09µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=7d53cfa6-047a-48c8-8fef-59024e131a96 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=185.173µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=b2942d4f-3e6a-4c91-8dbf-a32c6af07f43 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=206.424µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=5760c94c-8ecd-4067-832b-11909584e440 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=266.593µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=2b89e564-7bdd-4d5f-9e78-78445d1cbf70 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=153.922µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=f8fe6364-dab9-4122-9364-cc8a4e8e3d75 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=208.757µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=3af65a8b-625c-4fc7-ac62-bfbc353ac7a6 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=151.214µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=755c991e-1d9e-4279-b187-d607b13823ff method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=159.422µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=c36f80e6-63d2-4dc5-a2ee-01e6ab546ef3 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=245.509µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=e03d69f4-1738-49f5-b579-cdf4a632cc45 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=153.131µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=05255c0a-5b54-4b53-b714-08f15260687e method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=180.423µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=70f18e4c-0cdf-40a9-9e45-048f73171b1d method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=126.796µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=ed2a3480-d27e-44eb-bc85-bd088d0cd3a3 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=192.631µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=51c5b7ad-f0a6-4127-aca2-1d300b973d21 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=214.091µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=e8718af1-4fbd-4b3b-8189-9c066828773c method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=151.922µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=cd61dc79-f672-45c5-91a5-797ac5bd8680 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=170.214µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=e9226bfb-5572-4513-9a97-0e90e532cec1 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=129.838µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=8286f6ba-c4cc-4eb9-8b10-da07785cf32a method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=164.173µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=d85b2fd6-05bf-4f9b-818a-09ca9ae2df48 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=142.005µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=0ba6f4c9-0162-48d9-b610-bf28b56d39cd method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=144.339µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=296d49e0-2b8b-4493-9835-bee0c4f23261 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=243.426µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=9cf7e296-e25f-4d63-a1db-de1c262e2b8c method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=208.632µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=8fa7d17d-40d0-4dc6-a4bd-b6c514bceb4a method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=133.171µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=9e1b6e9b-7487-446f-b948-175f7d88e714 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=163.506µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=3cf21baa-455a-4dac-b8c2-732150d32af8 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=323.762µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=688c501c-30c9-46bc-ba4d-9d6a9202200d method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=572.521µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=65eefba1-b010-405b-b534-8e30d577d755 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=503.852µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=988807ed-875a-4d13-be2c-eb083546e583 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=193.299µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=0ae6f088-d7cb-4d57-a3db-bedb1d222bc7 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=129.088µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=038588a3-1ed6-4c91-bb8c-de5e55113175 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=320.887µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=ff151126-07e7-4100-a2af-e9765d071ca2 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=762.652µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=4cf0b177-670d-41b1-aa74-dafd209611e3 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=202.549µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=f893e111-2ccc-49a7-a34e-38c8248d5f3b method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=145.422µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=ece5e0f5-e795-4d1e-8bfe-2722feed55f7 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=150.047µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=45f9158b-a65f-4527-a741-2a8b3af800ac method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=165.089µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=ddc311c8-9d3f-4977-a159-a4d1daff9bf9 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=166.298µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=a0ab6cc9-4a7d-471e-9b65-932e3089cbc7 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=165.84µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=76e8f478-d9dc-4443-9bb8-310b8e9dd45a method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=266.51µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=96cb53f0-70bd-45aa-b735-6b5003310461 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=353.721µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=f1dda2fb-4016-440f-9fb6-c95a024038e6 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=169.048µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=e553ec3c-0ab2-4007-8363-48f94f36f000 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=141.796µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=78043ec3-1ec7-4c62-970c-950382757345 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=187.298µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=6222f780-9cdf-4d85-b99b-2897e61cbc43 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=808.862µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=73702805-906e-46ed-b38a-0206be2646dc method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=695.567µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=1186e970-9cb0-4db8-a44e-6d823c940ba7 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=410.557µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=98aaedba-db19-4504-a633-8a057f94d54e method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=311.22µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=92a3bfc9-1577-4a57-9bdd-351208fd7d93 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=1.151249ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=015c2bd0-266c-478a-99c8-516c482aeebe method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=266.801µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=664b2b6c-39ae-46d5-bed9-72caa9acb7f2 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=249.759µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=286c54ea-04d6-4af2-b00e-8ab00720b2ac method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=273.885µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=89ab422c-a181-43b7-8e4c-cbcdfe3c18b0 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=1.459927ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=9bbdd304-3f76-4f00-85bb-3c964aefb553 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=334.178µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:51 request_id=52dcf62b-df81-4c8f-8b60-c54965aaa140 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=1.887567ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=68f8ee3e-6eec-4f40-9428-dbeff99fd58a method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=1.955945ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=efa4cdeb-c02b-4332-a745-9ba14b490f76 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=2.642094ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=73f2e45a-8d59-4540-b193-98f1a4dca76a method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=486.101µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=c74d1c30-bde3-46d2-9b37-566419bf5376 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=507.602µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=65789068-cb57-4684-82d8-e201be139913 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=2.130868ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=fcffe674-7c32-4ee1-b34f-3841ac041030 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=191.966µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=5ea31e02-1c46-4305-ad02-1fa2217b9738 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=4.155481ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=b281c62b-cbeb-4e81-9c96-40757c5a88bf method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=150.547µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=5aceee05-4b98-45ca-974a-1e919fdde991 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=131.963µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=f82374a1-7d40-403d-aa70-5de8f913d2cc method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=167.798µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=5a725d61-e66a-445b-9b40-57ba6183a195 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=207.841µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=8ab66e91-8556-454b-913e-7b2c130dfd8e method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=152.631µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=423f02cb-0169-42fd-a1ed-5b6952cb262d method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=132.88µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=7da7d9d5-13e8-4495-9ec8-18ef6966bd41 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=160.839µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=870557ee-8823-4a7a-b78e-a440a1d8a0f7 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=146.588µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=52f91333-d9c9-4365-9453-cdfcb0c3f5a7 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=146.172µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=af8b17fd-7edc-4208-a40d-84ca21e160f3 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=167.798µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=d4c625e7-5ebf-4eea-8d60-45af463edf4c method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=165.798µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=083768b9-8f2a-4681-bcd4-5ae52228e0bb method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=186.59µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=46101c43-7641-481a-869d-3543f25ef54d method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=436.099µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=ba6ff758-a13f-4580-8ba2-da63a2351ca8 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=162.255µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=e6379b05-1acd-4b5a-b5a6-99e7bccc5f01 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=134.672µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=d9fb6747-2b9e-41cf-b53c-1a7750fc91f0 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=202.966µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=e5e5ec36-88eb-412f-8c2c-3f82c87c4590 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=171.006µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=8c2d9c31-df32-49d8-9c38-780f4fab1746 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=184.465µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=95fd52ea-b8d8-45df-a68a-ceba9d27b133 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=135.922µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=ae9ee763-096d-480c-b24b-cd349cb18978 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=384.431µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=088337f5-bb46-4911-80fd-fa855dc98200 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=145.463µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=2aa7e674-07c8-4282-8798-fcf641d08133 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=138.797µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=e0339717-77bb-4bd7-a321-34eaf1984fb9 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=163.923µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=74331de8-09a1-4057-8604-bd04d68465f4 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=145.922µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=da1793af-1f78-46eb-8751-52961c9bd4af method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=4332 latency=865.156µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=41cc821a-71d8-48f3-a2ec-618e8d6370b3 method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=4332 latency=796.404µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=58db51d8-2b41-4a61-9f48-e28a79b88470 method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=4332 latency=728.859µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=6b05dcf0-ee67-43cf-96d4-ef406c94761e method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=4332 latency=616.272µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=8bbd35fc-09c2-4ede-af22-3fb7147d5620 method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=4332 latency=611.938µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:52 request_id=10bfa4c2-537d-442a-8e5b-0da397c81cc0 method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=3616 latency=446.391µs +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | --- PASS: TestConcurrentMessagesAreUnique (7.52s) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | PASS +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | ok gitflic.ru/akselbant/mtusi2026lab1-fork/internal/app/chat 12.755s +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | === RUN TestSpoolOriginalAndFullValidation +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | --- PASS: TestSpoolOriginalAndFullValidation (0.00s) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | === RUN TestSpoolLimitsBeforeDecode +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | --- PASS: TestSpoolLimitsBeforeDecode (0.02s) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | === RUN TestFilenameAndCancelledUpload +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | --- PASS: TestFilenameAndCancelledUpload (0.00s) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | === RUN TestReconcileRejectsUnsafeGrace +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | --- PASS: TestReconcileRejectsUnsafeGrace (0.00s) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | === RUN TestValid16BitWidePNG +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | --- PASS: TestValid16BitWidePNG (0.08s) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | PASS +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | ok gitflic.ru/akselbant/mtusi2026lab1-fork/internal/attachment 1.160s +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | ? gitflic.ru/akselbant/mtusi2026lab1-fork/internal/config [no test files] +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | ? gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain [no test files] +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | === RUN TestUnicodeAndSalt +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | --- PASS: TestUnicodeAndSalt (2.23s) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | PASS +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | ok gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/password 3.266s +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | ? gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/repository [no test files] +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | === RUN TestS3WireFixture +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | --- PASS: TestS3WireFixture (0.00s) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | === RUN TestIntegration +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | storage_test.go:84: goose up: 2026/10/28 19:17:59 OK 001_initial.sql (24.32ms) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:59 OK 002_idempotency.sql (1.98ms) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:59 OK 003_attachments.sql (4.14ms) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:59 OK 004_message_attachments.sql (1.77ms) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:59 goose: successfully migrated database to version: 4 +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | storage_test.go:85: goose up: 2026/10/28 19:17:59 goose: no migrations to run. current version: 4 +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | === RUN TestIntegration/registration_race +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | storage_test.go:121: 12 concurrent INSERTs: 1 success, 11 unique conflicts +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | === RUN TestIntegration/rollback +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | storage_test.go:139: failed second member INSERT left 0 chats and 0 members +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | === RUN TestIntegration/lab4_attachments_and_reconciliation +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | lab4_test.go:248: ACL, original bytes, cross-chat attachment rejection, ordered/concurrent idempotency and absent=[] passed +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | lab4_test.go:316: dry-run={Apply:false GraceSeconds:90 ObjectsScanned:4 MetadataScanned:2 BytesScanned:94 ListRequestsEstimate:1 StatRequests:3 DBQueries:12 Orphans:1 Missing:1 FreshSkipped:1 LockedSkipped:1 ReferencedMissing:1 Deleted:0 MarkedFailed:0 DurationMS:7 Actions:[{Kind:orphan Key:original/9da5bf1b-bbc2-4c8e-8816-d473c908db4a Applied:false} {Kind:missing Key:original/65f5dff4-bc2f-469b-8b6b-6bc1275f8d6a Applied:false}]} apply={Apply:true GraceSeconds:90 ObjectsScanned:4 MetadataScanned:2 BytesScanned:94 ListRequestsEstimate:1 StatRequests:3 DBQueries:13 Orphans:1 Missing:1 FreshSkipped:1 LockedSkipped:1 ReferencedMissing:1 Deleted:1 MarkedFailed:1 DurationMS:5 Actions:[{Kind:orphan Key:original/9da5bf1b-bbc2-4c8e-8816-d473c908db4a Applied:true} {Kind:missing Key:original/65f5dff4-bc2f-469b-8b6b-6bc1275f8d6a Applied:true}]} repeat={Apply:true GraceSeconds:90 ObjectsScanned:3 MetadataScanned:2 BytesScanned:88 ListRequestsEstimate:1 StatRequests:1 DBQueries:7 Orphans:0 Missing:0 FreshSkipped:1 LockedSkipped:1 ReferencedMissing:0 Deleted:0 MarkedFailed:0 DurationMS:2 Actions:[]}; fresh, locked and referenced objects retained +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | === RUN TestIntegration/keyset_and_explain +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | storage_test.go:193: EXPLAIN on 10,000 messages, cursor near the end (9,000): +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | storage_test.go:199: Limit (cost=0.29..18.05 rows=51 width=142) (actual time=0.011..0.032 rows=51 loops=1) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | storage_test.go:199: Buffers: shared hit=10 +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | storage_test.go:199: -> Index Scan using messages_history_idx on messages m (cost=0.29..348.68 rows=1000 width=142) (actual time=0.011..0.028 rows=51 loops=1) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | storage_test.go:199: Index Cond: ((chat_id = '3945a437-ac3b-4af6-a505-e156a979dd08'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.9+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid))) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | storage_test.go:199: Buffers: shared hit=10 +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | storage_test.go:199: Planning Time: 0.031 ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | storage_test.go:199: Execution Time: 0.061 ms +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | storage_test.go:204: keyset traversal returned 10,000 distinct messages, including equal timestamps +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | === RUN TestIntegration/idempotency_race +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | storage_test.go:254: 16 concurrent PostgreSQL requests: one effect, identical replay, changed body conflicts +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | === RUN TestIntegration/goose_legacy_and_down +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | storage_test.go:268: goose up: 2026/10/28 19:17:59 OK 001_initial.sql (1.62ms) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:59 OK 002_idempotency.sql (1.13ms) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:59 OK 003_attachments.sql (583.4µs) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:59 OK 004_message_attachments.sql (2.74ms) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:59 goose: successfully migrated database to version: 4 +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | storage_test.go:269: goose up: 2026/10/28 19:17:59 goose: no migrations to run. current version: 4 +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | storage_test.go:276: adopted legacy schema: all existing messages are unchanged +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | storage_test.go:277: goose reset: 2026/10/28 19:17:59 OK 004_message_attachments.sql (5.92ms) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:59 OK 003_attachments.sql (3.96ms) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:59 OK 002_idempotency.sql (2.73ms) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:59 OK 001_initial.sql (9.78ms) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | storage_test.go:282: goose up: 2026/10/28 19:17:59 OK 001_initial.sql (10.62ms) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:59 OK 002_idempotency.sql (1.69ms) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:59 OK 003_attachments.sql (3.22ms) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:59 OK 004_message_attachments.sql (1.21ms) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | 2026/10/28 19:17:59 goose: successfully migrated database to version: 4 +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | storage_test.go:286: down and up succeeded in isolated schema +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | --- PASS: TestIntegration (0.64s) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | --- PASS: TestIntegration/registration_race (0.04s) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | --- PASS: TestIntegration/rollback (0.00s) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | --- PASS: TestIntegration/lab4_attachments_and_reconciliation (0.04s) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | --- PASS: TestIntegration/keyset_and_explain (0.08s) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | --- PASS: TestIntegration/idempotency_race (0.01s) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | --- PASS: TestIntegration/goose_legacy_and_down (0.12s) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | PASS +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | ok gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/repository/postgres 1.675s +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | ? gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/session [no test files] +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | === RUN TestPasswordContract +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | --- PASS: TestPasswordContract (0.00s) +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | PASS +mtusi-lab4_tests.0.lks3m3xxmw5s@colima | ok gitflic.ru/akselbant/mtusi2026lab1-fork/internal/usecase/chat 1.011s +mtusi-lab4_tests diff --git a/evidence/lab4-persistence.txt b/evidence/lab4-persistence.txt new file mode 100644 index 00000000..4ba6d9c2 --- /dev/null +++ b/evidence/lab4-persistence.txt @@ -0,0 +1,3 @@ +.venv/bin/python 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. diff --git a/evidence/lab4-reconciliation.json b/evidence/lab4-reconciliation.json new file mode 100644 index 00000000..0a57b41d --- /dev/null +++ b/evidence/lab4-reconciliation.json @@ -0,0 +1,1226 @@ +{ + "hypothesis": "fixed grace plus per-object transaction lock permits repeatable repair without deleting fresh or linked data", + "grace_seconds": 90, + "faults": { + "s3_put_db_insert_failure": { + "upload_status": 503, + "objects_without_metadata": 1 + }, + "minio_unavailable": { + "exit_nonzero": true, + "summary": { + "apply": true, + "grace_seconds": 90, + "objects_scanned": 0, + "metadata_scanned": 0, + "bytes_scanned": 0, + "list_requests_estimate": 0, + "stat_requests": 0, + "db_queries": 0, + "orphans": 0, + "missing": 0, + "fresh_skipped": 0, + "locked_skipped": 0, + "referenced_missing": 0, + "deleted": 0, + "marked_failed": 0, + "duration_ms": 201, + "actions": [] + } + }, + "postgres_unavailable": { + "exit_nonzero": true, + "summary": { + "apply": true, + "grace_seconds": 90, + "objects_scanned": 1, + "metadata_scanned": 0, + "bytes_scanned": 837, + "list_requests_estimate": 1, + "stat_requests": 0, + "db_queries": 0, + "orphans": 0, + "missing": 0, + "fresh_skipped": 0, + "locked_skipped": 0, + "referenced_missing": 0, + "deleted": 0, + "marked_failed": 0, + "duration_ms": 48, + "actions": [] + } + } + }, + "cost": [ + { + "phase": "fresh", + "synthetic_objects": 100, + "apply": false, + "grace_seconds": 90, + "objects_scanned": 130, + "metadata_scanned": 30, + "bytes_scanned": 31825703, + "list_requests_estimate": 1, + "stat_requests": 7, + "db_queries": 30, + "orphans": 0, + "missing": 0, + "fresh_skipped": 146, + "locked_skipped": 0, + "referenced_missing": 0, + "deleted": 0, + "marked_failed": 0, + "duration_ms": 27, + "actions": [] + }, + { + "phase": "fresh", + "synthetic_objects": 1100, + "apply": false, + "grace_seconds": 90, + "objects_scanned": 1130, + "metadata_scanned": 30, + "bytes_scanned": 31826703, + "list_requests_estimate": 2, + "stat_requests": 7, + "db_queries": 30, + "orphans": 0, + "missing": 0, + "fresh_skipped": 1146, + "locked_skipped": 0, + "referenced_missing": 0, + "deleted": 0, + "marked_failed": 0, + "duration_ms": 64, + "actions": [] + }, + { + "phase": "aged", + "synthetic_objects": 1100, + "apply": false, + "grace_seconds": 90, + "objects_scanned": 1130, + "metadata_scanned": 30, + "bytes_scanned": 31826703, + "list_requests_estimate": 2, + "stat_requests": 1131, + "db_queries": 2323, + "orphans": 1101, + "missing": 1, + "fresh_skipped": 0, + "locked_skipped": 0, + "referenced_missing": 1, + "deleted": 0, + "marked_failed": 0, + "duration_ms": 999, + "actions": [ + { + "kind": "orphan", + "key": "original/337521a8-44be-4941-a1b1-0eec2ada2b3c", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/1", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/10", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/100", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/1000", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/101", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/102", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/103", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/104", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/105", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/106", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/107", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/108", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/109", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/11", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/110", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/111", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/112", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/113", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/114", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/115", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/116", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/117", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/118", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/119", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/12", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/120", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/121", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/122", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/123", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/124", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/125", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/126", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/127", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/128", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/129", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/13", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/130", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/131", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/132", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/133", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/134", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/135", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/136", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/137", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/138", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/139", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/14", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/140", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/141", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/142", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/143", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/144", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/145", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/146", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/147", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/148", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/149", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/15", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/150", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/151", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/152", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/153", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/154", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/155", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/156", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/157", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/158", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/159", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/16", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/160", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/161", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/162", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/163", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/164", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/165", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/166", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/167", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/168", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/169", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/17", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/170", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/171", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/172", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/173", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/174", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/175", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/176", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/177", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/178", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/179", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/18", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/180", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/181", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/182", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/183", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/184", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/185", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/186", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/extra/187", + "applied": false + } + ] + }, + { + "phase": "aged", + "synthetic_objects": 100, + "apply": false, + "grace_seconds": 90, + "objects_scanned": 130, + "metadata_scanned": 30, + "bytes_scanned": 31825703, + "list_requests_estimate": 1, + "stat_requests": 131, + "db_queries": 323, + "orphans": 101, + "missing": 1, + "fresh_skipped": 0, + "locked_skipped": 0, + "referenced_missing": 1, + "deleted": 0, + "marked_failed": 0, + "duration_ms": 129, + "actions": [ + { + "kind": "orphan", + "key": "original/337521a8-44be-4941-a1b1-0eec2ada2b3c", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/1", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/10", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/100", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/11", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/12", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/13", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/14", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/15", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/16", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/17", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/18", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/19", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/2", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/20", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/21", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/22", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/23", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/24", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/25", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/26", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/27", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/28", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/29", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/3", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/30", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/31", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/32", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/33", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/34", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/35", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/36", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/37", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/38", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/39", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/4", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/40", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/41", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/42", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/43", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/44", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/45", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/46", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/47", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/48", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/49", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/5", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/50", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/51", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/52", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/53", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/54", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/55", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/56", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/57", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/58", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/59", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/6", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/60", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/61", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/62", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/63", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/64", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/65", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/66", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/67", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/68", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/69", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/7", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/70", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/71", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/72", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/73", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/74", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/75", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/76", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/77", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/78", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/79", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/8", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/80", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/81", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/82", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/83", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/84", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/85", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/86", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/87", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/88", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/89", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/9", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/90", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/91", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/92", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/93", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/94", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/95", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/96", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/97", + "applied": false + }, + { + "kind": "orphan", + "key": "original/cost-7c25c21102134be3935726555c66ed93/small/98", + "applied": false + } + ] + } + ], + "fresh_orphan_preserved": true, + "fresh_metadata_preserved": true, + "locked_candidate_preserved": true, + "dry_run": { + "apply": false, + "grace_seconds": 90, + "objects_scanned": 30, + "metadata_scanned": 30, + "bytes_scanned": 31825603, + "list_requests_estimate": 1, + "stat_requests": 31, + "db_queries": 123, + "orphans": 1, + "missing": 1, + "fresh_skipped": 0, + "locked_skipped": 0, + "referenced_missing": 1, + "deleted": 0, + "marked_failed": 0, + "duration_ms": 54, + "actions": [ + { + "kind": "orphan", + "key": "original/337521a8-44be-4941-a1b1-0eec2ada2b3c", + "applied": false + }, + { + "kind": "missing", + "key": "original/780437df-ef67-4bc1-82e1-209c619b6a3a", + "applied": false + } + ] + }, + "apply": { + "apply": true, + "grace_seconds": 90, + "objects_scanned": 30, + "metadata_scanned": 30, + "bytes_scanned": 31825603, + "list_requests_estimate": 1, + "stat_requests": 31, + "db_queries": 124, + "orphans": 1, + "missing": 1, + "fresh_skipped": 0, + "locked_skipped": 0, + "referenced_missing": 1, + "deleted": 1, + "marked_failed": 1, + "duration_ms": 54, + "actions": [ + { + "kind": "orphan", + "key": "original/337521a8-44be-4941-a1b1-0eec2ada2b3c", + "applied": true + }, + { + "kind": "missing", + "key": "original/780437df-ef67-4bc1-82e1-209c619b6a3a", + "applied": true + } + ] + }, + "repeat_apply": { + "apply": true, + "grace_seconds": 90, + "objects_scanned": 29, + "metadata_scanned": 30, + "bytes_scanned": 31824766, + "list_requests_estimate": 1, + "stat_requests": 29, + "db_queries": 118, + "orphans": 0, + "missing": 0, + "fresh_skipped": 0, + "locked_skipped": 0, + "referenced_missing": 0, + "deleted": 0, + "marked_failed": 0, + "duration_ms": 40, + "actions": [] + }, + "live_linked_preserved": true, + "missing_linked_reference_preserved": true +} diff --git a/evidence/lab4-reconciliation.txt b/evidence/lab4-reconciliation.txt new file mode 100644 index 00000000..7a1e6fb5 --- /dev/null +++ b/evidence/lab4-reconciliation.txt @@ -0,0 +1,7 @@ +.venv/bin/python tests/own/reconcile.py +Fresh scan cost: {"objects_scanned": 130, "metadata_scanned": 30, "list_requests_estimate": 1, "stat_requests": 7, "db_queries": 30, "duration_ms": 27} +Fresh scan cost: {"objects_scanned": 1130, "metadata_scanned": 30, "list_requests_estimate": 2, "stat_requests": 7, "db_queries": 30, "duration_ms": 64} +Waiting92s for actual S3 timestamps: measuring aged-object locking, DB and HEAD cost next. +Aged scan cost: {"objects_scanned": 1130, "metadata_scanned": 30, "list_requests_estimate": 2, "stat_requests": 1131, "db_queries": 2323, "duration_ms": 999} +Aged scan cost: {"objects_scanned": 130, "metadata_scanned": 30, "list_requests_estimate": 1, "stat_requests": 131, "db_queries": 323, "duration_ms": 129} +PASS: real two-store faults, grace, lock, dry-run/apply/repeat, linked data preserved and paginated scan cost. diff --git a/evidence/lab4-restart-verification.json b/evidence/lab4-restart-verification.json new file mode 100644 index 00000000..9702392e --- /dev/null +++ b/evidence/lab4-restart-verification.json @@ -0,0 +1,54 @@ +{ + "api": { + "all_original_tasks_replaced": true, + "mounts_unchanged": true, + "before": [ + "05qp70hqicx1m3uten0t88c9p", + "1diq18xi0jmwpzqzhhq39hjad" + ], + "after": [ + "g2s34c3zuztbxehcxyypsyrxy", + "rz3qizaxp0s2bguzbs57me0op" + ] + }, + "lb": { + "all_original_tasks_replaced": true, + "mounts_unchanged": true, + "before": [ + "psq3iyz4kraq9u3n2mtkyfijf" + ], + "after": [ + "oaiciqwjik1afkel0hdgwvhwy" + ] + }, + "postgres": { + "all_original_tasks_replaced": true, + "mounts_unchanged": true, + "before": [ + "7xbetpe47jvp1uuu2di2uk7vy" + ], + "after": [ + "i3scdtmsi49zwytqye6hc3k15" + ] + }, + "redis": { + "all_original_tasks_replaced": true, + "mounts_unchanged": true, + "before": [ + "x8ejqk47qyz4rgtgygq48wos7" + ], + "after": [ + "tqq4m5ygv0nohjefvbdprapzz" + ] + }, + "minio": { + "all_original_tasks_replaced": true, + "mounts_unchanged": true, + "before": [ + "ww19llqoe6yjvteqx3by0i4r1" + ], + "after": [ + "lfmr13mco26ik0a37xk2ntene" + ] + } +} diff --git a/evidence/lab4-scaling.txt b/evidence/lab4-scaling.txt new file mode 100644 index 00000000..9dad5410 --- /dev/null +++ b/evidence/lab4-scaling.txt @@ -0,0 +1,6 @@ +.venv/bin/python tests/own/swarm_grade4.py +PASS: shared-key race on two replicas; replay/conflict/scope/validation/access/logout +{"action": "stop-one", "target": "rz3qizaxp0s2bguzbs57me0op", "duration_seconds": 15.458, "successful_writes": 1078, "failed_attempts": 7, "successful_rps": 69.739, "first_recovery_seconds": 1.349, "max_success_gap_seconds": 1.055, "instances_before": ["rz3qizaxp0s2bguzbs57me0op", "xcgz2hubz1xrzmrkoyrgwq0tq"], "instances_after": ["j7awgfnedlt9ne1esywrappxx", "xcgz2hubz1xrzmrkoyrgwq0tq"], "confirmed_messages_checked": 1229, "duplicate_bodies": 0} +{"action": "stop-one", "target": "xcgz2hubz1xrzmrkoyrgwq0tq", "duration_seconds": 15.467, "successful_writes": 1091, "failed_attempts": 7, "successful_rps": 70.537, "first_recovery_seconds": 1.384, "max_success_gap_seconds": 1.057, "instances_before": ["j7awgfnedlt9ne1esywrappxx", "xcgz2hubz1xrzmrkoyrgwq0tq"], "instances_after": ["5vy560hk6k0q3eicqodd9dp2z", "j7awgfnedlt9ne1esywrappxx"], "confirmed_messages_checked": 1251, "duplicate_bodies": 0} +{"action": "update", "target": null, "duration_seconds": 44.156, "successful_writes": 3362, "failed_attempts": 0, "successful_rps": 76.139, "first_recovery_seconds": null, "max_success_gap_seconds": 0.152, "instances_before": ["5vy560hk6k0q3eicqodd9dp2z", "j7awgfnedlt9ne1esywrappxx"], "instances_after": ["j201rqxerkxdq0vbcw3armc3m", "uqyjmps3u9fyl976lpj944pc5"], "confirmed_messages_checked": 3519, "duplicate_bodies": 0} +PASS: each original replica stopped and replaced; rolling update under load; confirmations and sessions preserved diff --git a/evidence/lab4-smoke.txt b/evidence/lab4-smoke.txt new file mode 100644 index 00000000..607ff815 --- /dev/null +++ b/evidence/lab4-smoke.txt @@ -0,0 +1,2 @@ +.venv/bin/python tests/smoke.py --base-url "http://localhost:8080" +PASS: lab4 public API scenario; infrastructure and grading evidence remain separate. diff --git a/evidence/lab4-status-after-restart.json b/evidence/lab4-status-after-restart.json new file mode 100644 index 00000000..be72be0f --- /dev/null +++ b/evidence/lab4-status-after-restart.json @@ -0,0 +1,146 @@ +{ + "stack": "mtusi-lab4", + "docker": "29.5.2", + "services": { + "lb": { + "image": "haproxy:3.2.6-alpine", + "limits": { + "NanoCPUs": 500000000, + "MemoryBytes": 134217728 + }, + "published_ports": [ + { + "Protocol": "tcp", + "TargetPort": 8080, + "PublishedPort": 8080, + "PublishMode": "host" + } + ], + "secret_names": [], + "mounts": [], + "tasks": [ + { + "id": "oaiciqwjik1afkel0hdgwvhwy", + "state": "running", + "container": "ace6b5a9ab2ac3a291bca557e7eb89ba6354ed586625332b99dc3d1cdfaab6b5" + } + ] + }, + "api": { + "image": "mtusi-messenger:lab4", + "limits": { + "NanoCPUs": 1000000000, + "MemoryBytes": 1610612736 + }, + "published_ports": [], + "secret_names": [ + "mtusi-lab4_cursor_key", + "mtusi-lab4_postgres_password", + "mtusi-lab4_s3_access_key", + "mtusi-lab4_s3_secret_key" + ], + "mounts": [], + "tasks": [ + { + "id": "g2s34c3zuztbxehcxyypsyrxy", + "state": "running", + "container": "303dc53972fde0fe71990f644cb1b56658441a4d1cb6410ffc351ccceb0cd3a7" + }, + { + "id": "rz3qizaxp0s2bguzbs57me0op", + "state": "running", + "container": "f69bf37c2237e13f08bf4aa397936d4fed84a17395410f0af469b2cbc3e41699" + } + ] + }, + "postgres": { + "image": "postgres:17.6-alpine3.22", + "limits": { + "NanoCPUs": 1000000000, + "MemoryBytes": 536870912 + }, + "published_ports": [], + "secret_names": [ + "mtusi-lab4_postgres_password" + ], + "mounts": [ + { + "Type": "volume", + "Source": "mtusi-lab4_postgres_data", + "Target": "/var/lib/postgresql/data", + "VolumeOptions": { + "Labels": { + "com.docker.stack.namespace": "mtusi-lab4" + } + } + } + ], + "tasks": [ + { + "id": "i3scdtmsi49zwytqye6hc3k15", + "state": "running", + "container": "1622ddce8784f7dc1092ba808f05583898e08ba57a5c390d227265e4243744dc" + } + ] + }, + "redis": { + "image": "redis:7.4.5-alpine3.21", + "limits": { + "NanoCPUs": 500000000, + "MemoryBytes": 134217728 + }, + "published_ports": [], + "secret_names": [], + "mounts": [ + { + "Type": "volume", + "Source": "mtusi-lab4_redis_data", + "Target": "/data", + "VolumeOptions": { + "Labels": { + "com.docker.stack.namespace": "mtusi-lab4" + } + } + } + ], + "tasks": [ + { + "id": "tqq4m5ygv0nohjefvbdprapzz", + "state": "running", + "container": "dfe7c35a3887061560c608484e33ce1036222d8f683a5729599fb0a4e33065f3" + } + ] + }, + "minio": { + "image": "mtusi-minio:RELEASE.2025-09-07T16-13-09Z", + "limits": { + "NanoCPUs": 1000000000, + "MemoryBytes": 536870912 + }, + "published_ports": [], + "secret_names": [ + "mtusi-lab4_s3_root_access_key", + "mtusi-lab4_s3_root_secret_key" + ], + "mounts": [ + { + "Type": "volume", + "Source": "mtusi-lab4_s3_data", + "Target": "/data", + "VolumeOptions": { + "Labels": { + "com.docker.stack.namespace": "mtusi-lab4" + } + } + } + ], + "tasks": [ + { + "id": "lfmr13mco26ik0a37xk2ntene", + "state": "running", + "container": "8110ff5d0c7a776005653182ecfd927fe59a8b38b02b4645e1bd03fa1c6fdeff" + } + ] + } + } +} diff --git a/evidence/lab4-status-before-restart.json b/evidence/lab4-status-before-restart.json new file mode 100644 index 00000000..e2dd3804 --- /dev/null +++ b/evidence/lab4-status-before-restart.json @@ -0,0 +1,146 @@ +{ + "stack": "mtusi-lab4", + "docker": "29.5.2", + "services": { + "lb": { + "image": "haproxy:3.2.6-alpine", + "limits": { + "NanoCPUs": 500000000, + "MemoryBytes": 134217728 + }, + "published_ports": [ + { + "Protocol": "tcp", + "TargetPort": 8080, + "PublishedPort": 8080, + "PublishMode": "host" + } + ], + "secret_names": [], + "mounts": [], + "tasks": [ + { + "id": "psq3iyz4kraq9u3n2mtkyfijf", + "state": "running", + "container": "c9246107dbeb5aa78d3574865ddb2e9ac2d117c87830ca7be5214bdc8e8768b4" + } + ] + }, + "api": { + "image": "mtusi-messenger:lab4", + "limits": { + "NanoCPUs": 1000000000, + "MemoryBytes": 1610612736 + }, + "published_ports": [], + "secret_names": [ + "mtusi-lab4_cursor_key", + "mtusi-lab4_postgres_password", + "mtusi-lab4_s3_access_key", + "mtusi-lab4_s3_secret_key" + ], + "mounts": [], + "tasks": [ + { + "id": "05qp70hqicx1m3uten0t88c9p", + "state": "running", + "container": "0beaa8438aa0f61c069729d0d3e83220df07e49288451658d3c92f698c1b7fbc" + }, + { + "id": "1diq18xi0jmwpzqzhhq39hjad", + "state": "running", + "container": "bc1d5078efd2145c84e341ae457360f490f32539d7e4f6d5155378c918da69c8" + } + ] + }, + "postgres": { + "image": "postgres:17.6-alpine3.22", + "limits": { + "NanoCPUs": 1000000000, + "MemoryBytes": 536870912 + }, + "published_ports": [], + "secret_names": [ + "mtusi-lab4_postgres_password" + ], + "mounts": [ + { + "Type": "volume", + "Source": "mtusi-lab4_postgres_data", + "Target": "/var/lib/postgresql/data", + "VolumeOptions": { + "Labels": { + "com.docker.stack.namespace": "mtusi-lab4" + } + } + } + ], + "tasks": [ + { + "id": "7xbetpe47jvp1uuu2di2uk7vy", + "state": "running", + "container": "7a24978349b4630091ba38d365fcd74b20c60bd9a27fc15d5cb967e3874e09de" + } + ] + }, + "redis": { + "image": "redis:7.4.5-alpine3.21", + "limits": { + "NanoCPUs": 500000000, + "MemoryBytes": 134217728 + }, + "published_ports": [], + "secret_names": [], + "mounts": [ + { + "Type": "volume", + "Source": "mtusi-lab4_redis_data", + "Target": "/data", + "VolumeOptions": { + "Labels": { + "com.docker.stack.namespace": "mtusi-lab4" + } + } + } + ], + "tasks": [ + { + "id": "x8ejqk47qyz4rgtgygq48wos7", + "state": "running", + "container": "33a57e377891ce0c82807b12757cf0103ef9461502d1a64efdeec506744d9c27" + } + ] + }, + "minio": { + "image": "mtusi-minio:RELEASE.2025-09-07T16-13-09Z", + "limits": { + "NanoCPUs": 1000000000, + "MemoryBytes": 536870912 + }, + "published_ports": [], + "secret_names": [ + "mtusi-lab4_s3_root_access_key", + "mtusi-lab4_s3_root_secret_key" + ], + "mounts": [ + { + "Type": "volume", + "Source": "mtusi-lab4_s3_data", + "Target": "/data", + "VolumeOptions": { + "Labels": { + "com.docker.stack.namespace": "mtusi-lab4" + } + } + } + ], + "tasks": [ + { + "id": "ww19llqoe6yjvteqx3by0i4r1", + "state": "running", + "container": "d71ce1a062fe9ba9060f5266a9f00d89a34583f133a609769bb2510deaa52470" + } + ] + } + } +} diff --git a/evidence/lab4-status-final.json b/evidence/lab4-status-final.json new file mode 100644 index 00000000..73fc9e08 --- /dev/null +++ b/evidence/lab4-status-final.json @@ -0,0 +1,146 @@ +{ + "stack": "mtusi-lab4", + "docker": "29.5.2", + "services": { + "lb": { + "image": "haproxy:3.2.6-alpine", + "limits": { + "NanoCPUs": 500000000, + "MemoryBytes": 134217728 + }, + "published_ports": [ + { + "Protocol": "tcp", + "TargetPort": 8080, + "PublishedPort": 8080, + "PublishMode": "host" + } + ], + "secret_names": [], + "mounts": [], + "tasks": [ + { + "id": "oaiciqwjik1afkel0hdgwvhwy", + "state": "running", + "container": "ace6b5a9ab2ac3a291bca557e7eb89ba6354ed586625332b99dc3d1cdfaab6b5" + } + ] + }, + "api": { + "image": "mtusi-messenger:lab4", + "limits": { + "NanoCPUs": 1000000000, + "MemoryBytes": 1610612736 + }, + "published_ports": [], + "secret_names": [ + "mtusi-lab4_cursor_key", + "mtusi-lab4_postgres_password", + "mtusi-lab4_s3_access_key", + "mtusi-lab4_s3_secret_key" + ], + "mounts": [], + "tasks": [ + { + "id": "uqyjmps3u9fyl976lpj944pc5", + "state": "running", + "container": "2f98c5810a5f8557476af364186cb66e02c46003fece8827e200313d27f2fd74" + }, + { + "id": "j201rqxerkxdq0vbcw3armc3m", + "state": "running", + "container": "68730a58baf57c19b9919e752e34b7ad247ff29d94918f28fb7ede200c1a95f1" + } + ] + }, + "postgres": { + "image": "postgres:17.6-alpine3.22", + "limits": { + "NanoCPUs": 1000000000, + "MemoryBytes": 536870912 + }, + "published_ports": [], + "secret_names": [ + "mtusi-lab4_postgres_password" + ], + "mounts": [ + { + "Type": "volume", + "Source": "mtusi-lab4_postgres_data", + "Target": "/var/lib/postgresql/data", + "VolumeOptions": { + "Labels": { + "com.docker.stack.namespace": "mtusi-lab4" + } + } + } + ], + "tasks": [ + { + "id": "i3scdtmsi49zwytqye6hc3k15", + "state": "running", + "container": "1622ddce8784f7dc1092ba808f05583898e08ba57a5c390d227265e4243744dc" + } + ] + }, + "redis": { + "image": "redis:7.4.5-alpine3.21", + "limits": { + "NanoCPUs": 500000000, + "MemoryBytes": 134217728 + }, + "published_ports": [], + "secret_names": [], + "mounts": [ + { + "Type": "volume", + "Source": "mtusi-lab4_redis_data", + "Target": "/data", + "VolumeOptions": { + "Labels": { + "com.docker.stack.namespace": "mtusi-lab4" + } + } + } + ], + "tasks": [ + { + "id": "tqq4m5ygv0nohjefvbdprapzz", + "state": "running", + "container": "dfe7c35a3887061560c608484e33ce1036222d8f683a5729599fb0a4e33065f3" + } + ] + }, + "minio": { + "image": "mtusi-minio:RELEASE.2025-09-07T16-13-09Z", + "limits": { + "NanoCPUs": 1000000000, + "MemoryBytes": 536870912 + }, + "published_ports": [], + "secret_names": [ + "mtusi-lab4_s3_root_access_key", + "mtusi-lab4_s3_root_secret_key" + ], + "mounts": [ + { + "Type": "volume", + "Source": "mtusi-lab4_s3_data", + "Target": "/data", + "VolumeOptions": { + "Labels": { + "com.docker.stack.namespace": "mtusi-lab4" + } + } + } + ], + "tasks": [ + { + "id": "lfmr13mco26ik0a37xk2ntene", + "state": "running", + "container": "8110ff5d0c7a776005653182ecfd927fe59a8b38b02b4645e1bd03fa1c6fdeff" + } + ] + } + } +} diff --git a/evidence/lab4-status-initial.json b/evidence/lab4-status-initial.json new file mode 100644 index 00000000..80982359 --- /dev/null +++ b/evidence/lab4-status-initial.json @@ -0,0 +1,146 @@ +{ + "stack": "mtusi-lab4", + "docker": "29.5.2", + "services": { + "lb": { + "image": "haproxy:3.2.6-alpine", + "limits": { + "NanoCPUs": 500000000, + "MemoryBytes": 134217728 + }, + "published_ports": [ + { + "Protocol": "tcp", + "TargetPort": 8080, + "PublishedPort": 8080, + "PublishMode": "host" + } + ], + "secret_names": [], + "mounts": [], + "tasks": [ + { + "id": "psq3iyz4kraq9u3n2mtkyfijf", + "state": "running", + "container": "c9246107dbeb5aa78d3574865ddb2e9ac2d117c87830ca7be5214bdc8e8768b4" + } + ] + }, + "api": { + "image": "mtusi-messenger:lab4", + "limits": { + "NanoCPUs": 1000000000, + "MemoryBytes": 1610612736 + }, + "published_ports": [], + "secret_names": [ + "mtusi-lab4_cursor_key", + "mtusi-lab4_postgres_password", + "mtusi-lab4_s3_access_key", + "mtusi-lab4_s3_secret_key" + ], + "mounts": [], + "tasks": [ + { + "id": "0gwv6ha33wg3dao0mqxl9gu0n", + "state": "running", + "container": "f37c59b0556d4bc5b3f5c0432e8c58da4888ca5286635954131ea37c0714ead1" + }, + { + "id": "rbtm0mbmnbzr2oqcz8icho3qr", + "state": "running", + "container": "17d5f64c6fdd70ac3cdc27e655308909d4670ca0a7b743384ac7fe34e172d428" + } + ] + }, + "postgres": { + "image": "postgres:17.6-alpine3.22", + "limits": { + "NanoCPUs": 1000000000, + "MemoryBytes": 536870912 + }, + "published_ports": [], + "secret_names": [ + "mtusi-lab4_postgres_password" + ], + "mounts": [ + { + "Type": "volume", + "Source": "mtusi-lab4_postgres_data", + "Target": "/var/lib/postgresql/data", + "VolumeOptions": { + "Labels": { + "com.docker.stack.namespace": "mtusi-lab4" + } + } + } + ], + "tasks": [ + { + "id": "uy9m8wn36msy9qzttodwobkez", + "state": "running", + "container": "41c7c4bb6a37b443982f168a8e8494847581c2e30d1d6f5bf817284aebaf96b9" + } + ] + }, + "redis": { + "image": "redis:7.4.5-alpine3.21", + "limits": { + "NanoCPUs": 500000000, + "MemoryBytes": 134217728 + }, + "published_ports": [], + "secret_names": [], + "mounts": [ + { + "Type": "volume", + "Source": "mtusi-lab4_redis_data", + "Target": "/data", + "VolumeOptions": { + "Labels": { + "com.docker.stack.namespace": "mtusi-lab4" + } + } + } + ], + "tasks": [ + { + "id": "x8ejqk47qyz4rgtgygq48wos7", + "state": "running", + "container": "33a57e377891ce0c82807b12757cf0103ef9461502d1a64efdeec506744d9c27" + } + ] + }, + "minio": { + "image": "mtusi-minio:RELEASE.2025-09-07T16-13-09Z", + "limits": { + "NanoCPUs": 1000000000, + "MemoryBytes": 536870912 + }, + "published_ports": [], + "secret_names": [ + "mtusi-lab4_s3_root_access_key", + "mtusi-lab4_s3_root_secret_key" + ], + "mounts": [ + { + "Type": "volume", + "Source": "mtusi-lab4_s3_data", + "Target": "/data", + "VolumeOptions": { + "Labels": { + "com.docker.stack.namespace": "mtusi-lab4" + } + } + } + ], + "tasks": [ + { + "id": "jafk96quou17emokdyfk1qi4t", + "state": "running", + "container": "a04bf799191faea4386533680968586c90d67adeef8f37166824aa4723f8ac03" + } + ] + } + } +} diff --git a/evidence/lab4-update.txt b/evidence/lab4-update.txt new file mode 100644 index 00000000..2c2ec68f --- /dev/null +++ b/evidence/lab4-update.txt @@ -0,0 +1,3 @@ +.venv/bin/python scripts/swarm.py update +mtusi-lab4_api +PASS: rolling update completed diff --git a/evidence/lab4-upload-memory.json b/evidence/lab4-upload-memory.json new file mode 100644 index 00000000..5b2026b6 --- /dev/null +++ b/evidence/lab4-upload-memory.json @@ -0,0 +1,105 @@ +{ + "concurrency": 10, + "warmup_uploads": 1, + "memory_method": "cgroup v2 memory.current sampled every >=100ms; values include file cache", + "runs": [ + { + "width": 512, + "height": 512, + "size_bytes": 787252, + "sha256": "1a09c45b4a706ff8009c1adf0e9f10e428d8059d335e074cf4ad456680d4b473", + "requests": 10, + "successful": 10, + "errors": 0, + "duration_seconds": 0.325, + "successful_rps": 30.816, + "latency_ms": { + "0.5": 120.287, + "0.95": 172.127, + "0.99": 172.127 + }, + "baseline_bytes": { + "a43c3f7e6e92": 45240320, + "007b52fbba64": 45174784 + }, + "sampled_peak_bytes": { + "a43c3f7e6e92": 47005696, + "007b52fbba64": 46907392 + }, + "kernel_lifetime_peak_before_bytes": { + "a43c3f7e6e92": 46804992, + "007b52fbba64": 46718976 + }, + "kernel_lifetime_peak_after_bytes": { + "a43c3f7e6e92": 48623616, + "007b52fbba64": 48693248 + }, + "sampled_peak_sum_bytes": 93913088, + "samples": [ + { + "seconds": 0.045, + "bytes": { + "a43c3f7e6e92": 47005696, + "007b52fbba64": 46907392 + } + }, + { + "seconds": 0.325, + "bytes": { + "a43c3f7e6e92": 46116864, + "007b52fbba64": 46080000 + } + } + ] + }, + { + "width": 1024, + "height": 768, + "size_bytes": 2360847, + "sha256": "ad94bc1d209135dea4d3caa0712cee92cfaa97ba3ccdd5797aff6664fcce4a2a", + "requests": 10, + "successful": 10, + "errors": 0, + "duration_seconds": 0.401, + "successful_rps": 24.957, + "latency_ms": { + "0.5": 258.573, + "0.95": 324.694, + "0.99": 324.694 + }, + "baseline_bytes": { + "a43c3f7e6e92": 46067712, + "007b52fbba64": 46063616 + }, + "sampled_peak_bytes": { + "a43c3f7e6e92": 41107456, + "007b52fbba64": 13651968 + }, + "kernel_lifetime_peak_before_bytes": { + "a43c3f7e6e92": 48623616, + "007b52fbba64": 48693248 + }, + "kernel_lifetime_peak_after_bytes": { + "a43c3f7e6e92": 49119232, + "007b52fbba64": 49922048 + }, + "sampled_peak_sum_bytes": 54759424, + "samples": [ + { + "seconds": 0.043, + "bytes": { + "a43c3f7e6e92": 41107456, + "007b52fbba64": 13651968 + } + }, + { + "seconds": 0.401, + "bytes": { + "a43c3f7e6e92": 13234176, + "007b52fbba64": 10956800 + } + } + ] + } + ] +} diff --git a/evidence/lab4-upload-memory.txt b/evidence/lab4-upload-memory.txt new file mode 100644 index 00000000..8077fe94 --- /dev/null +++ b/evidence/lab4-upload-memory.txt @@ -0,0 +1,4 @@ +.venv/bin/python scripts/measure_uploads.py +{"width": 512, "height": 512, "size_bytes": 787252, "sha256": "1a09c45b4a706ff8009c1adf0e9f10e428d8059d335e074cf4ad456680d4b473", "requests": 10, "successful": 10, "errors": 0, "duration_seconds": 0.325, "successful_rps": 30.816, "latency_ms": {"0.5": 120.287, "0.95": 172.127, "0.99": 172.127}, "baseline_bytes": {"a43c3f7e6e92": 45240320, "007b52fbba64": 45174784}, "sampled_peak_bytes": {"a43c3f7e6e92": 47005696, "007b52fbba64": 46907392}, "kernel_lifetime_peak_before_bytes": {"a43c3f7e6e92": 46804992, "007b52fbba64": 46718976}, "kernel_lifetime_peak_after_bytes": {"a43c3f7e6e92": 48623616, "007b52fbba64": 48693248}, "sampled_peak_sum_bytes": 93913088} +{"width": 1024, "height": 768, "size_bytes": 2360847, "sha256": "ad94bc1d209135dea4d3caa0712cee92cfaa97ba3ccdd5797aff6664fcce4a2a", "requests": 10, "successful": 10, "errors": 0, "duration_seconds": 0.401, "successful_rps": 24.957, "latency_ms": {"0.5": 258.573, "0.95": 324.694, "0.99": 324.694}, "baseline_bytes": {"a43c3f7e6e92": 46067712, "007b52fbba64": 46063616}, "sampled_peak_bytes": {"a43c3f7e6e92": 41107456, "007b52fbba64": 13651968}, "kernel_lifetime_peak_before_bytes": {"a43c3f7e6e92": 48623616, "007b52fbba64": 48693248}, "kernel_lifetime_peak_after_bytes": {"a43c3f7e6e92": 49119232, "007b52fbba64": 49922048}, "sampled_peak_sum_bytes": 54759424} +PASS: ten simultaneous uploads at two sizes; all originals verified; memory samples saved. diff --git a/evidence/lab4-validation.txt b/evidence/lab4-validation.txt new file mode 100644 index 00000000..f973c727 --- /dev/null +++ b/evidence/lab4-validation.txt @@ -0,0 +1,8 @@ +python3 scripts/check_contract.py +PASS: offline skeleton structure, local refs and Python syntax; application NOT tested. +.venv/bin/python scripts/validate_openapi.py +/Users/dkhakimovig/mtusi2026lab4/.venv/lib/python3.9/site-packages/urllib3/__init__.py:35: NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'. See: https://github.com/urllib3/urllib3/issues/3020 + warnings.warn( +PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested. +PASS: goose3.27.1 migration syntax validated. +PASS: mandatory lab4 contract and public checks unchanged. diff --git a/evidence/lab5-deploy.txt b/evidence/lab5-deploy.txt new file mode 100644 index 00000000..e3d056c2 --- /dev/null +++ b/evidence/lab5-deploy.txt @@ -0,0 +1,176 @@ +.venv/bin/python scripts/swarm.py up +vphhh79vd5ti8501q6m9lzulj +Local secrets are ready. +DEPRECATED: The legacy builder is deprecated and will be removed in a future release. + Install the buildx component to build images with BuildKit: + https://docs.docker.com/go/buildx/ + +Sending build context to Docker daemon 461.3kB +Step 1/39 : FROM golang:1.26.4-alpine3.23@sha256:18b460dd17542c2ba43299a633cf6ebfc1115101509531471d7cfce1019af083 AS goose-builder + ---> 18b460dd1754 +Step 2/39 : RUN GOMAXPROCS=2 GOFLAGS=-p=1 GOBIN=/out CGO_ENABLED=0 go install -tags='no_clickhouse no_libsql no_mssql no_mysql no_sqlite3 no_vertica no_ydb no_spanner' github.com/pressly/goose/v3/cmd/goose@v3.27.1 + ---> Using cache + ---> 15f4b2e3468a +Step 3/39 : FROM alpine:3.23@sha256:075c2c1a4068c1e251228ca2b0ea8b163f835ca5d66e758b93c7fc89b1995616 AS migrations + ---> 075c2c1a4068 +Step 4/39 : COPY --from=goose-builder /out/goose /usr/local/bin/goose + ---> Using cache + ---> 6a0ad52336c1 +Step 5/39 : COPY migrations /migrations + ---> Using cache + ---> 01a2e64cbb7d +Step 6/39 : COPY infra/migrate.sh /usr/local/bin/migrate + ---> Using cache + ---> 7382e24476ff +Step 7/39 : USER 10001:10001 + ---> Using cache + ---> 6c54ddff6a36 +Step 8/39 : ENTRYPOINT ["/usr/local/bin/migrate"] + ---> Using cache + ---> 7e8134892cf2 +Step 9/39 : CMD ["up"] + ---> Using cache + ---> adb6e8d9b58a +Step 10/39 : FROM golang:1.26.4-alpine3.23@sha256:18b460dd17542c2ba43299a633cf6ebfc1115101509531471d7cfce1019af083 AS builder + ---> 18b460dd1754 +Step 11/39 : WORKDIR /src + ---> Using cache + ---> 1ba013278a4a +Step 12/39 : RUN apk add --no-cache gcc musl-dev + ---> Using cache + ---> a0ea65f0bded +Step 13/39 : COPY go.mod go.sum ./ + ---> Using cache + ---> e98ccecfb093 +Step 14/39 : RUN go mod download + ---> Using cache + ---> 91d546c71507 +Step 15/39 : COPY cmd ./cmd + ---> Using cache + ---> 7d74a0366782 +Step 16/39 : COPY contracts ./contracts + ---> Using cache + ---> 89e9eb49cf2e +Step 17/39 : COPY dto ./dto + ---> Using cache + ---> b3608ba9d910 +Step 18/39 : COPY internal ./internal + ---> Using cache + ---> 420381f245d1 +Step 19/39 : COPY migrations ./migrations + ---> Using cache + ---> 244708889b45 +Step 20/39 : ENV GOFLAGS=-p=1 GOMAXPROCS=2 + ---> Using cache + ---> a86cf22e4c7d +Step 21/39 : RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/messenger ./cmd + ---> Using cache + ---> e1ea9cbf840a +Step 22/39 : RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/reconcile ./cmd/reconcile + ---> Using cache + ---> 4669d728553f +Step 23/39 : RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/worker ./cmd/worker + ---> Using cache + ---> fe51ba375215 +Step 24/39 : FROM builder AS tests + ---> fe51ba375215 +Step 25/39 : COPY --from=goose-builder /out/goose /usr/local/bin/goose + ---> Using cache + ---> 3ef73620b0a6 +Step 26/39 : ENV GOOSE_MIGRATION_DIR=/src/migrations + ---> Using cache + ---> 43905e46829a +Step 27/39 : CMD ["go", "test", "-p=1", "-race", "-count=1", "-v", "./..."] + ---> Using cache + ---> 037b4f43fd3c +Step 28/39 : FROM alpine:3.23@sha256:075c2c1a4068c1e251228ca2b0ea8b163f835ca5d66e758b93c7fc89b1995616 + ---> 075c2c1a4068 +Step 29/39 : RUN apk add --no-cache libwebp-tools=1.6.0-r0 + ---> Using cache + ---> 3a741cc26d52 +Step 30/39 : RUN addgroup -S messenger && adduser -S -D -H -u 10001 -G messenger messenger + ---> Using cache + ---> 444b794708dc +Step 31/39 : COPY --from=builder --chown=messenger:messenger /out/messenger /usr/local/bin/messenger + ---> 32fc6da7172f +Step 32/39 : COPY --from=builder --chown=messenger:messenger /out/reconcile /usr/local/bin/reconcile + ---> 49b1f874a5e0 +Step 33/39 : COPY --from=builder --chown=messenger:messenger /out/worker /usr/local/bin/worker + ---> f7ab6619c5c8 +Step 34/39 : ENV PORT=8080 + ---> Running in 0f8f2d74139c + ---> Removed intermediate container 0f8f2d74139c + ---> ab0764165606 +Step 35/39 : EXPOSE 8080 + ---> Running in 082ca714270a + ---> Removed intermediate container 082ca714270a + ---> 9a16ff1522d8 +Step 36/39 : USER messenger:messenger + ---> Running in 2fa42c5d86db + ---> Removed intermediate container 2fa42c5d86db + ---> 50c7d9a72042 +Step 37/39 : HEALTHCHECK --interval=10s --timeout=3s --start-period=3s --retries=3 CMD wget -q -O /dev/null "http://127.0.0.1:${PORT}/health/ready" || exit 1 + ---> Running in 8b938c89cf6d + ---> Removed intermediate container 8b938c89cf6d + ---> 74607fcd70f9 +Step 38/39 : STOPSIGNAL SIGTERM + ---> Running in e747d914802f + ---> Removed intermediate container e747d914802f + ---> 95748bec26d8 +Step 39/39 : ENTRYPOINT ["/usr/local/bin/messenger"] + ---> Running in b502e1c9cff0 + ---> Removed intermediate container b502e1c9cff0 + ---> 66e3c9bc004e +Successfully built 66e3c9bc004e +Successfully tagged mtusi-messenger:lab5 +DEPRECATED: The legacy builder is deprecated and will be removed in a future release. + Install the buildx component to build images with BuildKit: + https://docs.docker.com/go/buildx/ + +Sending build context to Docker daemon 461.3kB +Step 1/9 : FROM golang:1.26.4-alpine3.23@sha256:18b460dd17542c2ba43299a633cf6ebfc1115101509531471d7cfce1019af083 AS goose-builder + ---> 18b460dd1754 +Step 2/9 : RUN GOMAXPROCS=2 GOFLAGS=-p=1 GOBIN=/out CGO_ENABLED=0 go install -tags='no_clickhouse no_libsql no_mssql no_mysql no_sqlite3 no_vertica no_ydb no_spanner' github.com/pressly/goose/v3/cmd/goose@v3.27.1 + ---> Using cache + ---> 15f4b2e3468a +Step 3/9 : FROM alpine:3.23@sha256:075c2c1a4068c1e251228ca2b0ea8b163f835ca5d66e758b93c7fc89b1995616 AS migrations + ---> 075c2c1a4068 +Step 4/9 : COPY --from=goose-builder /out/goose /usr/local/bin/goose + ---> Using cache + ---> 6a0ad52336c1 +Step 5/9 : COPY migrations /migrations + ---> Using cache + ---> 01a2e64cbb7d +Step 6/9 : COPY infra/migrate.sh /usr/local/bin/migrate + ---> Using cache + ---> 7382e24476ff +Step 7/9 : USER 10001:10001 + ---> Using cache + ---> 6c54ddff6a36 +Step 8/9 : ENTRYPOINT ["/usr/local/bin/migrate"] + ---> Using cache + ---> 7e8134892cf2 +Step 9/9 : CMD ["up"] + ---> Using cache + ---> adb6e8d9b58a +Successfully built adb6e8d9b58a +Successfully tagged mtusi-migrations:lab5 +mtusi-lab5_api scaled to 0 +9mm30n5f5blu6kdfvhvartwr0 +mtusi-lab5_migrations.0.1hb6hxpeyw5j@colima | 2026/11/10 18:25:49 goose: no migrations to run. current version: 10 +mtusi-lab5_migrations +Since --detach=false was not specified, tasks will be created in the background. +In a future release, --detach=false will become the default. +Updating service mtusi-lab5_lb (id: tnlj2tzpx91wj066wqi3y5k44) +Updating service mtusi-lab5_postgres (id: f4xn3ammg3isejqsm9cqng6yo) +Updating service mtusi-lab5_redis (id: kz94wxnzhqwettqixbya643dl) +Updating service mtusi-lab5_minio (id: oaf1v50i58o60qnbk5flk0k59) +Updating service mtusi-lab5_api (id: oey97yu6vv15p4dn10pptf3b8) +Updating service mtusi-lab5_worker (id: lctq7ul45bu47a6vjbvt6xgeo) +hs7eigkxh4jah526bbx4nlt0t +mtusi-lab5_s3-bootstrap.0.veoz00w0hdfq@colima | PASS: private bucket and restricted API account configured. +mtusi-lab5_s3-bootstrap +mtusi-lab5_api scaled to 2 +mtusi-lab5_api +PASS: rolling update completed +PASS: Swarm stack ready at http://localhost:18085 diff --git a/evidence/lab5-failover.txt b/evidence/lab5-failover.txt new file mode 100644 index 00000000..b3f3d790 --- /dev/null +++ b/evidence/lab5-failover.txt @@ -0,0 +1,4 @@ +.venv/bin/python tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "http://localhost:18085" +Executing explicit failover hook; hook output suppressed to avoid leaking secrets. +{"observed_instances_before": 2, "successful_writes": 123, "failed_attempts": 1, "first_recovery_seconds": 0.696} +PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence. diff --git a/evidence/lab5-faults-initial.txt b/evidence/lab5-faults-initial.txt new file mode 100644 index 00000000..757ddf02 --- /dev/null +++ b/evidence/lab5-faults-initial.txt @@ -0,0 +1,12 @@ +.venv/bin/python tests/own/lab5.py +Traceback (most recent call last): + File "/Users/dkhakimovig/mtusi2026lab5/tests/own/lab5.py", line 302, in + main() + File "/Users/dkhakimovig/mtusi2026lab5/tests/own/lab5.py", line 156, in main + variant_check(c,bob,item,body,shape) + File "/Users/dkhakimovig/mtusi2026lab5/tests/own/lab5.py", line 101, in variant_check + check((variants['thumbnail']['width'],variants['thumbnail']['height'])==expected_thumb,'thumbnail geometry') + File "/Users/dkhakimovig/mtusi2026lab5/tests/client.py", line 24, in check + raise Failure(message) +client.Failure: thumbnail geometry +make: *** [test-lab5] Error 1 diff --git a/evidence/lab5-faults-main.txt b/evidence/lab5-faults-main.txt new file mode 100644 index 00000000..34926db2 --- /dev/null +++ b/evidence/lab5-faults-main.txt @@ -0,0 +1,17 @@ +.venv/bin/python tests/own/lab5.py +PASS: input/ACL, three actual formats, geometry, EXIF, alpha +PASS: COMMIT/publish gap, queued link, API/broker restarts, worker recovery +PASS: crash after objects, expired lease/fencing, same four keys +PASS: COMMIT before ack, duplicate no-op and ready replay rejection +PASS: bounded retry/backoff, failed registry, safe audited replay +Traceback (most recent call last): + File "/Users/dkhakimovig/mtusi2026lab5/tests/own/lab5.py", line 310, in + main() + File "/Users/dkhakimovig/mtusi2026lab5/tests/own/lab5.py", line 277, in main + failed=wait_state(item,'failed') + File "/Users/dkhakimovig/mtusi2026lab5/tests/own/lab5.py", line 100, in wait_state + return until(lambda: job(att), lambda j: j['state']==state, timeout) + File "/Users/dkhakimovig/mtusi2026lab5/tests/own/lab5.py", line 39, in until + raise AssertionError('condition deadline exceeded; last='+str(last)) +AssertionError: condition deadline exceeded; last={'id': '4fc5ab5e-3e10-4e78-a6ea-9599d6f941be', 'attachment_id': '7122d895-5b38-480f-8238-8df26958810f', 'pipeline_version': 1, 'state': 'ready', 'attempts': 1, 'max_attempts': 2, 'available_at': '2026-11-10T18:47:28.488754+00:00', 'lease_until': None, 'fence': 1, 'last_error': None, 'created_at': '2026-11-10T18:47:28.33972+00:00', 'updated_at': '2026-11-10T18:47:28.488935+00:00'} +make: *** [test-lab5] Error 1 diff --git a/evidence/lab5-faults-tail.txt b/evidence/lab5-faults-tail.txt new file mode 100644 index 00000000..474922c1 --- /dev/null +++ b/evidence/lab5-faults-tail.txt @@ -0,0 +1,2 @@ +PASS: input/ACL, three actual formats, geometry, EXIF, alpha +PASS: all lab5 fault, retry, replay, durability, rendering and cleanup checks diff --git a/evidence/lab5-faults.json b/evidence/lab5-faults.json new file mode 100644 index 00000000..2fba181a --- /dev/null +++ b/evidence/lab5-faults.json @@ -0,0 +1,86 @@ +{ + "stack": "mtusi-lab5", + "cases": { + "input_and_acl": [ + { + "name": "oversized", + "status": 413 + }, + { + "name": "damaged", + "status": 415 + }, + { + "name": "pixel_budget", + "status": 413 + }, + { + "name": "mime_spoof", + "status": 415 + }, + { + "name": "filename", + "status": 400 + }, + { + "name": "unsupported", + "status": 415 + } + ], + "small_alpha_exif": "PASS", + "private_s3": { + "anonymous_get": 403, + "outside_prefix_denied": true + }, + "stage_before_commit": { + "upload_status": 503, + "metadata": 0, + "fresh_orphan_preserved": true + }, + "commit_publish_and_restarts": { + "job_id": "51f7ee76-3566-4837-a91d-74d5a0afec7b", + "api_restart": true, + "broker_restarts": 2, + "link_queued": true + }, + "crash_after_objects": { + "attempts": 2, + "objects": 4, + "fence": 2 + }, + "commit_before_ack_and_duplicate": { + "ready_unchanged": true, + "ready_replay_rejected": true + }, + "bounded_retry_replay": { + "max_attempts": 2, + "retry_available_at": "2026-11-10T18:47:14.297456+00:00", + "first_backoff_seconds": 2.492, + "failed_attempts": 2, + "audits": 1 + }, + "permanent_stage_error": { + "attempts": 1, + "error_code": "invalid_image" + }, + "renderer_process_group_timeout": { + "deadline_seconds": 2, + "elapsed_seconds": 2.27, + "cwebp_observed": true, + "descendants_after_failure": 0 + }, + "staging_cleanup": { + "ready_stages_remaining": 0, + "linked_original_preserved": true, + "failed_retention_days": 7, + "expired_failed_stage_removed": true, + "expired_replay_rejected": true, + "unconfirmed_orphan_removed": true + } + }, + "started_at": 1794336125.445686, + "resumed_at": [ + 1794336751.851368 + ], + "finished_at": 1794336891.683626 +} diff --git a/evidence/lab5-go-tests.txt b/evidence/lab5-go-tests.txt new file mode 100644 index 00000000..b0e96060 --- /dev/null +++ b/evidence/lab5-go-tests.txt @@ -0,0 +1,14 @@ +? gitflic.ru/akselbant/mtusi2026lab1-fork/cmd [no test files] +? gitflic.ru/akselbant/mtusi2026lab1-fork/cmd/reconcile [no test files] +? gitflic.ru/akselbant/mtusi2026lab1-fork/cmd/worker [no test files] +? gitflic.ru/akselbant/mtusi2026lab1-fork/contracts [no test files] +ok gitflic.ru/akselbant/mtusi2026lab1-fork/dto (cached) +ok gitflic.ru/akselbant/mtusi2026lab1-fork/internal/app/chat 14.228s +ok gitflic.ru/akselbant/mtusi2026lab1-fork/internal/attachment 2.227s +? gitflic.ru/akselbant/mtusi2026lab1-fork/internal/config [no test files] +? gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain [no test files] +ok gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/password (cached) +? gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/repository [no test files] +ok gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/repository/postgres 1.666s +? gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/session [no test files] +ok gitflic.ru/akselbant/mtusi2026lab1-fork/internal/usecase/chat (cached) diff --git a/evidence/lab5-integration-initial.txt b/evidence/lab5-integration-initial.txt new file mode 100644 index 00000000..0b97ef45 --- /dev/null +++ b/evidence/lab5-integration-initial.txt @@ -0,0 +1,355 @@ +.venv/bin/python scripts/swarm.py test-integration +DEPRECATED: The legacy builder is deprecated and will be removed in a future release. + Install the buildx component to build images with BuildKit: + https://docs.docker.com/go/buildx/ + +Sending build context to Docker daemon 460.3kB +Step 1/27 : FROM golang:1.26.4-alpine3.23@sha256:18b460dd17542c2ba43299a633cf6ebfc1115101509531471d7cfce1019af083 AS goose-builder + ---> 18b460dd1754 +Step 2/27 : RUN GOMAXPROCS=2 GOFLAGS=-p=1 GOBIN=/out CGO_ENABLED=0 go install -tags='no_clickhouse no_libsql no_mssql no_mysql no_sqlite3 no_vertica no_ydb no_spanner' github.com/pressly/goose/v3/cmd/goose@v3.27.1 + ---> Using cache + ---> 15f4b2e3468a +Step 3/27 : FROM alpine:3.23@sha256:075c2c1a4068c1e251228ca2b0ea8b163f835ca5d66e758b93c7fc89b1995616 AS migrations + ---> 075c2c1a4068 +Step 4/27 : COPY --from=goose-builder /out/goose /usr/local/bin/goose + ---> Using cache + ---> 6a0ad52336c1 +Step 5/27 : COPY migrations /migrations + ---> Using cache + ---> 01a2e64cbb7d +Step 6/27 : COPY infra/migrate.sh /usr/local/bin/migrate + ---> Using cache + ---> 7382e24476ff +Step 7/27 : USER 10001:10001 + ---> Using cache + ---> 6c54ddff6a36 +Step 8/27 : ENTRYPOINT ["/usr/local/bin/migrate"] + ---> Using cache + ---> 7e8134892cf2 +Step 9/27 : CMD ["up"] + ---> Using cache + ---> adb6e8d9b58a +Step 10/27 : FROM golang:1.26.4-alpine3.23@sha256:18b460dd17542c2ba43299a633cf6ebfc1115101509531471d7cfce1019af083 AS builder + ---> 18b460dd1754 +Step 11/27 : WORKDIR /src + ---> Using cache + ---> 1ba013278a4a +Step 12/27 : RUN apk add --no-cache gcc musl-dev + ---> Using cache + ---> a0ea65f0bded +Step 13/27 : COPY go.mod go.sum ./ + ---> Using cache + ---> e98ccecfb093 +Step 14/27 : RUN go mod download + ---> Using cache + ---> 91d546c71507 +Step 15/27 : COPY cmd ./cmd + ---> Using cache + ---> 7d74a0366782 +Step 16/27 : COPY contracts ./contracts + ---> Using cache + ---> 89e9eb49cf2e +Step 17/27 : COPY dto ./dto + ---> Using cache + ---> b3608ba9d910 +Step 18/27 : COPY internal ./internal + ---> 44f1a9efcc66 +Step 19/27 : COPY migrations ./migrations + ---> acefcd8a83af +Step 20/27 : ENV GOFLAGS=-p=1 GOMAXPROCS=2 + ---> Running in 6f0922eb42d3 + ---> Removed intermediate container 6f0922eb42d3 + ---> 2cda01161c62 +Step 21/27 : RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/messenger ./cmd + ---> Running in 26952912ceb7 + ---> Removed intermediate container 26952912ceb7 + ---> 889afe1963f8 +Step 22/27 : RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/reconcile ./cmd/reconcile + ---> Running in 04665a280741 + ---> Removed intermediate container 04665a280741 + ---> 43cd9030aa04 +Step 23/27 : RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/worker ./cmd/worker + ---> Running in 5b0325120af9 + ---> Removed intermediate container 5b0325120af9 + ---> 66906c7f16a8 +Step 24/27 : FROM builder AS tests + ---> 66906c7f16a8 +Step 25/27 : COPY --from=goose-builder /out/goose /usr/local/bin/goose + ---> 7e67bb289391 +Step 26/27 : ENV GOOSE_MIGRATION_DIR=/src/migrations + ---> Running in 1b5b33f07921 + ---> Removed intermediate container 1b5b33f07921 + ---> 3aba3008d340 +Step 27/27 : CMD ["go", "test", "-p=1", "-race", "-count=1", "-v", "./..."] + ---> Running in bb4863e04cfd + ---> Removed intermediate container bb4863e04cfd + ---> 471b66a42df0 +Successfully built 471b66a42df0 +Successfully tagged mtusi-messenger-tests:lab5 +e5yt4nofpygdupx0vhbijo6dj +mtusi-lab5_tests.0.wqzm1lukwaby@colima | ? gitflic.ru/akselbant/mtusi2026lab1-fork/cmd [no test files] +mtusi-lab5_tests.0.wqzm1lukwaby@colima | ? gitflic.ru/akselbant/mtusi2026lab1-fork/cmd/reconcile [no test files] +mtusi-lab5_tests.0.wqzm1lukwaby@colima | ? gitflic.ru/akselbant/mtusi2026lab1-fork/cmd/worker [no test files] +mtusi-lab5_tests.0.wqzm1lukwaby@colima | ? gitflic.ru/akselbant/mtusi2026lab1-fork/contracts [no test files] +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestMessageStrictFields +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestMessageStrictFields (0.00s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestTimestampFixedMicroseconds +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestTimestampFixedMicroseconds (0.00s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | PASS +mtusi-lab5_tests.0.wqzm1lukwaby@colima | ok gitflic.ru/akselbant/mtusi2026lab1-fork/dto 1.013s +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestRejectsMalformedJSON +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:44 request_id=78adaf84-7aaa-42f4-a084-a2db8cffcf98 method=POST path=/api/v1/users status=400 response_bytes=140 latency=131.98µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestRejectsMalformedJSON (0.00s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestHidesForeignChat +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:45 request_id=1bf6ff0c-9371-4b01-9941-77e94d023b10 method=POST path=/api/v1/users status=201 response_bytes=141 latency=365.251444ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:45 request_id=f50eb79b-cca7-4993-8191-8734738e9c40 method=POST path=/api/v1/auth/sessions status=201 response_bytes=269 latency=398.873152ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:45 request_id=5a967846-e8a8-449a-a09d-c8d365025b46 method=POST path=/api/v1/users status=201 response_bytes=147 latency=381.399429ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:46 request_id=714a25ea-10d1-4b85-8c24-ec4d371bb7b6 method=POST path=/api/v1/auth/sessions status=201 response_bytes=275 latency=422.991476ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:46 request_id=2345f91f-0c23-45d3-a491-8dfd5556d174 method=POST path=/api/v1/chats status=201 response_bytes=163 latency=188.281µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:46 request_id=0336f4ad-d624-4ecf-9cdf-51301294d0e8 method=GET path=/api/v1/chats/:chat_id status=404 response_bytes=126 latency=284.797µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestHidesForeignChat (1.57s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestRejectsEmptyMessage +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:46 request_id=44c2744c-4cd0-4c7e-992d-a4dfb0b061b6 method=POST path=/api/v1/users status=201 response_bytes=157 latency=368.07845ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:47 request_id=af848f3f-b52b-4af3-85f8-bd965300d1ee method=POST path=/api/v1/auth/sessions status=201 response_bytes=285 latency=366.256457ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:47 request_id=23df23c7-578f-4c76-a10b-104f2426b9cd method=POST path=/api/v1/chats status=201 response_bytes=163 latency=133.647µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:47 request_id=b90bf297-9272-4bfb-a83f-47b326cb5ce1 method=POST path=/api/v1/chats/:chat_id/messages status=400 response_bytes=172 latency=152.233µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestRejectsEmptyMessage (0.74s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestRejectsDuplicateUsername +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:47 request_id=178aa11a-597f-493f-b227-c667f089540b method=POST path=/api/v1/users status=201 response_bytes=149 latency=351.691662ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:47 request_id=2f3ba9cf-b14c-4ae9-adfd-ec9f3028a50e method=POST path=/api/v1/auth/sessions status=201 response_bytes=277 latency=367.085423ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:48 request_id=0a727f2e-dc6b-4c93-8639-de50d77626b5 method=POST path=/api/v1/users status=409 response_bytes=170 latency=359.315715ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestRejectsDuplicateUsername (1.08s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestPaginatesMessagesAcrossMultiplePages +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:48 request_id=b3142e33-707a-46f5-b178-35509037b4cc method=POST path=/api/v1/users status=201 response_bytes=151 latency=409.355414ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:48 request_id=448e921b-0b3a-434c-8961-b6aa51530d88 method=POST path=/api/v1/auth/sessions status=201 response_bytes=279 latency=387.814711ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:48 request_id=8cf5775f-be80-476a-8f65-1fae6ba4d114 method=POST path=/api/v1/chats status=201 response_bytes=163 latency=162.61µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:48 request_id=9e3a4eaf-e3f0-4c1c-88a7-651b43fde65c method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=228 latency=266.503µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:48 request_id=57d23cd6-2482-4656-8621-670b43ef8d3d method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=228 latency=186.906µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:48 request_id=92183f25-6ab2-4c74-a970-9cf52a20d989 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=228 latency=167.945µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:48 request_id=8da17cdd-9817-47dd-89e5-156bf0009a30 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=228 latency=167.528µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:48 request_id=364216f6-407d-4f49-97ac-1d79491067b4 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=228 latency=176.779µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:48 request_id=7abdd979-4157-4d85-bdb7-41b31fdb5612 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=228 latency=130.438µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:48 request_id=30e71f25-5fcc-47fa-9349-eaa52423b428 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=228 latency=134.814µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:48 request_id=17a01d04-e615-4d86-8016-fbf560e6f1e6 method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=725 latency=380.521µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:48 request_id=f9ebd8b6-f40a-49b9-8c46-03524ae60c7e method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=725 latency=183.197µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:48 request_id=ec02dec4-7e4c-4fdd-b05e-0115f5485111 method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=725 latency=174.862µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:48 request_id=90cae6ae-fe4e-4e2a-8765-2ad81c9abaf1 method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=259 latency=114.519µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestPaginatesMessagesAcrossMultiplePages (0.81s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestConcurrentMessagesAreUnique +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:49 request_id=0430c49b-26f0-4036-b772-e6267ecd0b14 method=POST path=/api/v1/users status=201 response_bytes=153 latency=370.09502ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:49 request_id=7f5a51e7-7002-4917-84b0-dc9725be54a9 method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=360.387497ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:50 request_id=a349814a-0888-445e-9726-a33a6712c43c method=POST path=/api/v1/users status=201 response_bytes=153 latency=360.66339ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:50 request_id=fb3e86ae-a739-4e7d-bc78-559fadbbf787 method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=394.640836ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:50 request_id=0fc70956-e867-4377-96e5-329dda30cd31 method=POST path=/api/v1/users status=201 response_bytes=153 latency=367.006565ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:51 request_id=0f9813dc-7c0d-4163-9793-882e84468d33 method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=353.933555ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:51 request_id=4440bfa8-9d31-4297-9343-80ded2259f6a method=POST path=/api/v1/users status=201 response_bytes=153 latency=375.799206ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:51 request_id=56c0bfa7-4938-47a5-ac31-543cddca96e9 method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=366.48411ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:52 request_id=36983337-938e-4c9f-868a-7cc2f1525f5e method=POST path=/api/v1/users status=201 response_bytes=153 latency=373.712012ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:52 request_id=a2853b02-5099-4cbd-aa6c-cbfb617a289d method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=505.163831ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:53 request_id=2170619b-d50a-41a7-a77f-d38fa3fe45a2 method=POST path=/api/v1/users status=201 response_bytes=153 latency=379.44649ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:53 request_id=7fccfc33-4433-459d-929d-c59c71d7d620 method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=440.462082ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:54 request_id=f235d12f-6bf2-4483-93e5-5515c87d8b68 method=POST path=/api/v1/users status=201 response_bytes=153 latency=467.557845ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:54 request_id=c039f7d0-879a-4c87-aa6f-b26a7b0be534 method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=380.753972ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:54 request_id=e084cc17-3e34-4b4d-a505-8ee4ee3c2ed9 method=POST path=/api/v1/users status=201 response_bytes=153 latency=430.362118ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:55 request_id=77f5d7ed-f8a4-44bb-a7c6-35105b72861c method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=361.400539ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:55 request_id=2cee44b0-3bde-4274-a345-2a450e37d592 method=POST path=/api/v1/users status=201 response_bytes=153 latency=387.358501ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:56 request_id=8351a9bb-2d81-485e-9461-d3e1e180b1c7 method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=478.984823ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:56 request_id=4784bfab-a8bd-47ce-b569-4b7e519d4f38 method=POST path=/api/v1/users status=201 response_bytes=153 latency=694.465485ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=0876d022-4dd6-45ff-9a5d-74b7b4dece6e method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=507.870998ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=1af0e642-3a02-4cd6-88eb-295353c88b7c method=POST path=/api/v1/chats status=201 response_bytes=514 latency=303.26µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=72b9ccc9-d30f-4da3-9662-05f15722602f method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=651.443µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=81eb5c5b-f9a3-4403-9b8a-5ed360f4a78d method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=359.06µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=95416f6f-e84b-4532-bf7e-4c70850733ca method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=594.975µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=c52d75be-211a-414e-bf1d-ce287a437a5a method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=253.001µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=3acdd29e-915f-4252-9928-1bb1561a6f8a method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=266.628µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=401c57a7-dda1-45a8-854e-1f90fec29b4d method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=1.086266ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=b1a2a6f0-d442-425a-9185-b06af53e0287 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=495.209µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=e28e56e9-5b4b-4634-83a9-8ffa261246d8 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=3.567434ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=1be19fc0-187a-4240-b396-51f254a28846 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=1.795385ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=83f80360-8ebb-40c8-b3f9-83b596a60dba method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=201.617µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=f56ff57c-7170-41f5-b81f-ace5f259000d method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=2.246253ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=51e5b495-8329-4087-afb7-be0ec16db915 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=1.059136ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=cdc680e8-fda4-45ab-9cc2-976891d745cb method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=3.058181ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=4f378cb9-5335-4a3f-a204-c04c512bc1ac method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=270.587µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=d15ea22e-b4d5-44ba-ad3f-a0d1cbded11d method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=3.963708ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=ff677057-1037-4998-a7ee-d3ed7516cc16 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=1.902029ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=2edd5096-e6f7-41ef-a265-8ec8beeae9f5 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=1.739251ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=75d1f157-564b-46f0-80f0-a88d7da83642 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=2.940161ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=61cdfd52-4d67-4af2-a3cc-b7384ef86be9 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=191.199µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=fc5faa10-3c15-4e66-9f27-4de48fefa69a method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=161.194µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=6dec8a6b-f059-4615-9f28-7c0e265bdced method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=168.403µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=0ba37f3e-5012-4648-9cb9-fe6a9e391286 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=263.753µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=13417c22-fafc-481a-abd5-456111490e41 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=229.539µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=19f8ac4f-fc2a-4a64-9096-3a6cb8c0dc12 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=443.95µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=f1ca84e3-d6f6-4a64-bd98-e2aa24f96793 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=171.696µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=b6ab587d-f519-469f-88e8-9aa15221cfb1 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=160.111µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=12ec636a-0fbf-4c26-9834-59363cc0e5d9 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=346.683µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=94742954-5139-412c-940f-19dde72f8d50 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=217.537µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=2e6d7919-71d0-4411-9f86-a5312c7ea148 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=237.707µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=2acd4a86-79d3-47ac-9370-490faba63dd8 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=222.621µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=9fd113a4-8b1f-487d-83a0-98f21d3106a7 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=356.06µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=51e37132-149a-4c3b-98c9-cfade19a3ecc method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=299.883µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=056f9612-6681-49cb-be83-a5188a4ad784 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=198.45µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=f0933a5e-5e7d-4f67-9d21-b3cdc26b5ee7 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=367.978µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=fd5381a8-23d5-4e49-a2b3-a7446b8dc94a method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=368.145µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=18cb05e3-b296-47b9-b011-996dd1069d13 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=680.406µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=8b636c5e-df70-4e1c-907c-8a516890d49e method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=1.473581ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=5b7fa9d4-2545-4b7a-bd14-e2a0391d895d method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=219.078µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=7e5258f4-6322-4d5d-857d-7724852f18a5 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=179.405µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=700838c9-da94-4e08-889e-e3346b73d285 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=197.325µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=cc55fc35-3e25-4d9c-b4ce-1aa9f7a296ed method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=193.741µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=d21bae1c-8414-4fef-ae5e-59ecc5c8e481 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=171.612µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=9ae11a53-4372-4cf8-9459-bb9055e5bb9f method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=268.212µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=4ae0bd79-fb34-41fa-aaff-47459dead558 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=177.614µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=c49603b9-6709-4f40-826b-0cb39c439bb5 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=170.237µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=ef856d83-34ef-46ee-b047-82ceaa8c3813 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=195.325µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=948df662-0eea-4e28-ac14-15d972735bfe method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=277.755µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=6e05a773-85ea-4308-873b-f413fc23ab67 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=210.077µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=741af3a0-5dbf-48ad-a053-d941cd97ee49 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=180.989µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=81450fe0-2922-4349-9f40-d3eb9199456d method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=153.193µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=47bffcec-6f7f-4bba-8fc5-321e6d954324 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=167.028µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=4fe65afb-595d-4227-b676-ff0745afdc77 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=22.151061ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=a30669a7-089e-497a-b5ac-d7e3a3330b59 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=221.871µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=7f746257-b6b6-464c-a964-f4b666230e3b method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=278.297µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=cb03cc55-07b0-4c0f-8ff6-73ca6916e076 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=252.209µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=92d14786-6c5f-4cdd-89cb-fb75ef8a2375 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=225.58µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=3c195e16-268b-494b-ad32-9135c3ea6b9e method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=388.899µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=e1f9a9e4-3ae3-477c-8fd6-c8d068d8f68a method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=636.358µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=e230085e-920a-4cda-ac31-5a08e846406d method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=502.085µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=b26a0e99-c1cf-4895-8a7c-b87f9010e4bf method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=962.245µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=eab81116-9035-4834-8d33-f179a4fc5757 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=1.862814ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=d8226a69-ff35-4e40-99dd-8c0c42cd15ba method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=358.143µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=a1d94b08-0423-4a8e-985e-8a62e07c0071 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=2.488835ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=ce158939-7a9b-4829-9e30-a9570247b067 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=309.719µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=7694a9dd-aad5-4b96-9d52-bf022c2d6101 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=2.671325ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=a75cbf2d-24f5-44ff-8b3e-2efc8858daeb method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=3.563808ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=cccd74dd-6055-4538-b589-6439bb2e2249 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=199.409µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=682cf78c-492a-4e2e-8d0f-600709d40332 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=268.004µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=b0fe5b42-55a9-4080-b152-17958d1f9f72 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=180.447µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=01ea3680-f345-41b6-9cf5-eaf5a42f98ce method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=201.368µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=41a3b666-77e0-45cd-903a-59c37d094a19 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=209.66µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=52fb0977-6696-48ed-914f-56bb16207ec5 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=314.261µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=a306642c-bb87-41a5-9c51-8d3dea67923b method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=266.67µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=47909112-0b12-4627-a977-eabc090eec23 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=277.297µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=628fa77e-5549-4bca-8ffb-671089e4a4e4 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=227.83µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=115e720e-d906-4299-a557-478100f07ffa method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=561.136µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=fdffc6bf-74ff-4e02-a849-d86f8469edf9 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=180.823µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=70c555f2-9f81-45c3-9cb1-85b4e80106f7 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=188.031µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=897b8deb-775f-4a0d-ac02-b8eca6e6a4ca method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=168.445µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=5b02ee7d-ae2b-45fa-8e5d-e796648368a4 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=278.255µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=59aff7ee-4d4d-487f-89dd-a9b9e1df8705 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=228.664µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=6d858392-c3f1-403d-82d7-3790e81b96da method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=232.164µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=5f077336-b854-49e5-8642-22dddecd1680 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=287.299µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=44d32f91-3883-4a4f-9722-4718d1f29ed6 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=363.228µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=b043468b-dcd8-4085-b21b-72427260aa7e method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=265.67µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=c4c49e7c-e296-4263-beb6-232f11a79069 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=178.071µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=22a15da2-c0e5-42ca-b117-18ecea6f4be5 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=178.155µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=9c6590f9-f07f-4bdd-a3fa-ccbfa2b34080 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=296.383µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=06413c5e-5e2f-4a5a-b3d8-72e79e095b1d method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=213.16µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=c4fdcea5-2cb3-4852-a3e6-8f2cca4150c6 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=235.748µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=1e5ec364-bd31-459a-9e20-4df15f9201e5 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=162.861µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=97042c78-9f32-4690-bed4-3fdd12e6f90c method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=169.237µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=1294c60c-07eb-49e2-9688-8273b867a7b0 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=410.319µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=6b1d6ba4-31d5-4eca-a5cf-f4ab203fc38f method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=150.275µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=c9717b03-a4c6-437b-80b3-319a1b010200 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=293.008µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=e8d813c8-6743-4004-a193-4f9517cc29f0 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=237.081µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=7163a415-e1ce-4c92-88e9-87d3e7b5ebc4 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=993.375µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=e52dfded-ef1e-4815-9507-8b4c57b32403 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=368.062µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=8c03578f-5787-409f-b5ab-e61013240c28 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=330.056µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=ea8a1f84-ab01-4d6b-b4b2-1edd2745ea4a method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=362.228µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=7bd598d0-dfbe-4226-9d16-8815ace71d18 method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=4332 latency=1.28755ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=a36de45d-8bf9-4ec2-ae7a-ab0d5badfd91 method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=4332 latency=970.455µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=79982f51-85fd-4e19-b8df-6c6865ed1929 method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=4332 latency=1.137775ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=6045807f-6a92-440d-b54e-dc7b4eee2e76 method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=4332 latency=879.523µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=c4eadc24-2b1e-4318-81cc-90c604831194 method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=4332 latency=669.904µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:19:57 request_id=0eb733fc-c439-41b9-b979-c46d54fd5a5b method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=3616 latency=583.306µs +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestConcurrentMessagesAreUnique (8.46s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | PASS +mtusi-lab5_tests.0.wqzm1lukwaby@colima | ok gitflic.ru/akselbant/mtusi2026lab1-fork/internal/app/chat 13.752s +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestSpoolOriginalAndFullValidation +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestSpoolOriginalAndFullValidation (0.00s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestSpoolLimitsBeforeDecode +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestSpoolLimitsBeforeDecode (0.02s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestFilenameAndCancelledUpload +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestFilenameAndCancelledUpload (0.00s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestReconcileRejectsUnsafeGrace +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestReconcileRejectsUnsafeGrace (0.00s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestValid16BitWidePNG +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestValid16BitWidePNG (0.11s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestAttachmentTimestampsUseFixedMicroseconds +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestAttachmentTimestampsUseFixedMicroseconds (0.00s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestFitGeometry +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestFitGeometry (0.00s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestOrientationsAndAlpha +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestOrientationsAndAlpha (0.00s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestEXIFOrientation +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestEXIFOrientation (0.00s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestFenceIntegration +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestFenceIntegration (0.07s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | PASS +mtusi-lab5_tests.0.wqzm1lukwaby@colima | ok gitflic.ru/akselbant/mtusi2026lab1-fork/internal/attachment 1.223s +mtusi-lab5_tests.0.wqzm1lukwaby@colima | ? gitflic.ru/akselbant/mtusi2026lab1-fork/internal/config [no test files] +mtusi-lab5_tests.0.wqzm1lukwaby@colima | ? gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain [no test files] +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestUnicodeAndSalt +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestUnicodeAndSalt (2.38s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | PASS +mtusi-lab5_tests.0.wqzm1lukwaby@colima | ok gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/password 3.400s +mtusi-lab5_tests.0.wqzm1lukwaby@colima | ? gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/repository [no test files] +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestS3WireFixture +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestS3WireFixture (0.01s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestIntegration +mtusi-lab5_tests.0.wqzm1lukwaby@colima | storage_test.go:84: goose up: 2026/11/10 18:20:05 OK 001_initial.sql (21.11ms) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:20:05 OK 002_idempotency.sql (1.75ms) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:20:05 OK 003_attachments.sql (5.64ms) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:20:05 OK 004_message_attachments.sql (1.97ms) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:20:05 OK 005_async_attachments.sql (5.92ms) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:20:05 OK 006_attachment_jobs.sql (4ms) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:20:05 OK 007_attachment_outbox.sql (2.56ms) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:20:05 OK 008_attachment_replays.sql (3.23ms) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:20:05 OK 009_backfill_pipeline.sql (2.32ms) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:20:05 OK 010_storage_cleanup.sql (817.31µs) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:20:05 goose: successfully migrated database to version: 10 +mtusi-lab5_tests.0.wqzm1lukwaby@colima | storage_test.go:85: goose up: 2026/11/10 18:20:05 goose: no migrations to run. current version: 10 +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestIntegration/registration_race +mtusi-lab5_tests.0.wqzm1lukwaby@colima | storage_test.go:121: 12 concurrent INSERTs: 1 success, 11 unique conflicts +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestIntegration/rollback +mtusi-lab5_tests.0.wqzm1lukwaby@colima | storage_test.go:139: failed second member INSERT left 0 chats and 0 members +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestIntegration/lab4_attachments_and_reconciliation +mtusi-lab5_tests.0.wqzm1lukwaby@colima | lab4_test.go:248: ACL, original bytes, cross-chat attachment rejection, ordered/concurrent idempotency and absent=[] passed +mtusi-lab5_tests.0.wqzm1lukwaby@colima | lab4_test.go:321: dry-run={Apply:false GraceSeconds:90 ObjectsScanned:5 MetadataScanned:2 BytesScanned:106 ListRequestsEstimate:1 StatRequests:3 DBQueries:14 Orphans:1 Missing:1 FreshSkipped:1 LockedSkipped:1 ReferencedMissing:1 Deleted:0 MarkedFailed:0 DurationMS:15 Actions:[{Kind:orphan Key:original/7a8e9f88-b271-4b9e-9431-b9aa433f1489 Applied:false} {Kind:missing Key:original/76f08381-064d-45b3-afa7-3e8bcb6a5dc3 Applied:false}]} apply={Apply:true GraceSeconds:90 ObjectsScanned:5 MetadataScanned:2 BytesScanned:106 ListRequestsEstimate:1 StatRequests:3 DBQueries:15 Orphans:1 Missing:1 FreshSkipped:1 LockedSkipped:1 ReferencedMissing:1 Deleted:1 MarkedFailed:1 DurationMS:7 Actions:[{Kind:orphan Key:original/7a8e9f88-b271-4b9e-9431-b9aa433f1489 Applied:true} {Kind:missing Key:original/76f08381-064d-45b3-afa7-3e8bcb6a5dc3 Applied:true}]} repeat={Apply:true GraceSeconds:90 ObjectsScanned:4 MetadataScanned:2 BytesScanned:100 ListRequestsEstimate:1 StatRequests:1 DBQueries:9 Orphans:0 Missing:0 FreshSkipped:1 LockedSkipped:1 ReferencedMissing:0 Deleted:0 MarkedFailed:0 DurationMS:3 Actions:[]}; fresh, locked and referenced objects retained +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestIntegration/keyset_and_explain +mtusi-lab5_tests.0.wqzm1lukwaby@colima | storage_test.go:193: EXPLAIN on 10,000 messages, cursor near the end (9,000): +mtusi-lab5_tests.0.wqzm1lukwaby@colima | storage_test.go:199: Limit (cost=0.29..17.99 rows=51 width=142) (actual time=0.013..0.032 rows=51 loops=1) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | storage_test.go:199: Buffers: shared hit=10 +mtusi-lab5_tests.0.wqzm1lukwaby@colima | storage_test.go:199: -> Index Scan using messages_history_idx on messages m (cost=0.29..347.47 rows=1000 width=142) (actual time=0.012..0.027 rows=51 loops=1) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | storage_test.go:199: Index Cond: ((chat_id = 'f74d97f7-bb21-47ea-9177-5f171f6cead5'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.9+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid))) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | storage_test.go:199: Buffers: shared hit=10 +mtusi-lab5_tests.0.wqzm1lukwaby@colima | storage_test.go:199: Planning Time: 0.034 ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | storage_test.go:199: Execution Time: 0.054 ms +mtusi-lab5_tests.0.wqzm1lukwaby@colima | storage_test.go:204: keyset traversal returned 10,000 distinct messages, including equal timestamps +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestIntegration/idempotency_race +mtusi-lab5_tests.0.wqzm1lukwaby@colima | storage_test.go:254: 16 concurrent PostgreSQL requests: one effect, identical replay, changed body conflicts +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestIntegration/goose_legacy_and_down +mtusi-lab5_tests.0.wqzm1lukwaby@colima | storage_test.go:268: goose up: exit status 1: 2026/11/10 18:20:06 OK 001_initial.sql (2.39ms) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:20:06 OK 002_idempotency.sql (1.26ms) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:20:06 OK 003_attachments.sql (2.48ms) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:20:06 OK 004_message_attachments.sql (2.81ms) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | 2026/11/10 18:20:06 goose run: ERROR 005_async_attachments.sql: failed to run SQL migration: failed to execute SQL query "ALTER TABLE attachments\n DROP CONSTRAINT attachments_status_check,\n ADD CONSTRAINT attachments_status_check CHECK (status IN ('queued','processing','ready','failed')),\n DROP CONSTRAINT attachments_check,\n ADD CONSTRAINT attachments_check CHECK ((status='failed' AND error_code IS NOT NULL) OR (status<>'failed' AND error_code IS NULL)),\n ADD COLUMN variants jsonb NOT NULL DEFAULT '[]',\n ADD COLUMN updated_at timestamptz NOT NULL DEFAULT clock_timestamp(),\n ADD COLUMN pipeline_version integer NOT NULL DEFAULT 1,\n ADD COLUMN staging_key text;": ERROR: column "variants" of relation "attachments" already exists (SQLSTATE 42701) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- FAIL: TestIntegration (0.64s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestIntegration/registration_race (0.03s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestIntegration/rollback (0.00s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestIntegration/lab4_attachments_and_reconciliation (0.07s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestIntegration/keyset_and_explain (0.09s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestIntegration/idempotency_race (0.02s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- FAIL: TestIntegration/goose_legacy_and_down (0.05s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | FAIL +mtusi-lab5_tests.0.wqzm1lukwaby@colima | FAIL gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/repository/postgres 0.667s +mtusi-lab5_tests.0.wqzm1lukwaby@colima | ? gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/session [no test files] +mtusi-lab5_tests.0.wqzm1lukwaby@colima | === RUN TestPasswordContract +mtusi-lab5_tests.0.wqzm1lukwaby@colima | --- PASS: TestPasswordContract (0.00s) +mtusi-lab5_tests.0.wqzm1lukwaby@colima | PASS +mtusi-lab5_tests.0.wqzm1lukwaby@colima | ok gitflic.ru/akselbant/mtusi2026lab1-fork/internal/usecase/chat 1.013s +mtusi-lab5_tests.0.wqzm1lukwaby@colima | FAIL +mtusi-lab5_tests +FAIL: tests failed +make: *** [test-integration] Error 1 diff --git a/evidence/lab5-integration.txt b/evidence/lab5-integration.txt new file mode 100644 index 00000000..0069f7b7 --- /dev/null +++ b/evidence/lab5-integration.txt @@ -0,0 +1,389 @@ +.venv/bin/python scripts/swarm.py test-integration +DEPRECATED: The legacy builder is deprecated and will be removed in a future release. + Install the buildx component to build images with BuildKit: + https://docs.docker.com/go/buildx/ + +Sending build context to Docker daemon 461.3kB +Step 1/27 : FROM golang:1.26.4-alpine3.23@sha256:18b460dd17542c2ba43299a633cf6ebfc1115101509531471d7cfce1019af083 AS goose-builder + ---> 18b460dd1754 +Step 2/27 : RUN GOMAXPROCS=2 GOFLAGS=-p=1 GOBIN=/out CGO_ENABLED=0 go install -tags='no_clickhouse no_libsql no_mssql no_mysql no_sqlite3 no_vertica no_ydb no_spanner' github.com/pressly/goose/v3/cmd/goose@v3.27.1 + ---> Using cache + ---> 15f4b2e3468a +Step 3/27 : FROM alpine:3.23@sha256:075c2c1a4068c1e251228ca2b0ea8b163f835ca5d66e758b93c7fc89b1995616 AS migrations + ---> 075c2c1a4068 +Step 4/27 : COPY --from=goose-builder /out/goose /usr/local/bin/goose + ---> Using cache + ---> 6a0ad52336c1 +Step 5/27 : COPY migrations /migrations + ---> Using cache + ---> 01a2e64cbb7d +Step 6/27 : COPY infra/migrate.sh /usr/local/bin/migrate + ---> Using cache + ---> 7382e24476ff +Step 7/27 : USER 10001:10001 + ---> Using cache + ---> 6c54ddff6a36 +Step 8/27 : ENTRYPOINT ["/usr/local/bin/migrate"] + ---> Using cache + ---> 7e8134892cf2 +Step 9/27 : CMD ["up"] + ---> Using cache + ---> adb6e8d9b58a +Step 10/27 : FROM golang:1.26.4-alpine3.23@sha256:18b460dd17542c2ba43299a633cf6ebfc1115101509531471d7cfce1019af083 AS builder + ---> 18b460dd1754 +Step 11/27 : WORKDIR /src + ---> Using cache + ---> 1ba013278a4a +Step 12/27 : RUN apk add --no-cache gcc musl-dev + ---> Using cache + ---> a0ea65f0bded +Step 13/27 : COPY go.mod go.sum ./ + ---> Using cache + ---> e98ccecfb093 +Step 14/27 : RUN go mod download + ---> Using cache + ---> 91d546c71507 +Step 15/27 : COPY cmd ./cmd + ---> Using cache + ---> 7d74a0366782 +Step 16/27 : COPY contracts ./contracts + ---> Using cache + ---> 89e9eb49cf2e +Step 17/27 : COPY dto ./dto + ---> Using cache + ---> b3608ba9d910 +Step 18/27 : COPY internal ./internal + ---> 420381f245d1 +Step 19/27 : COPY migrations ./migrations + ---> 244708889b45 +Step 20/27 : ENV GOFLAGS=-p=1 GOMAXPROCS=2 + ---> Running in bf624bf36a2e + ---> Removed intermediate container bf624bf36a2e + ---> a86cf22e4c7d +Step 21/27 : RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/messenger ./cmd + ---> Running in f0e750b5bd34 + ---> Removed intermediate container f0e750b5bd34 + ---> e1ea9cbf840a +Step 22/27 : RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/reconcile ./cmd/reconcile + ---> Running in d70ebca4dc47 + ---> Removed intermediate container d70ebca4dc47 + ---> 4669d728553f +Step 23/27 : RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/worker ./cmd/worker + ---> Running in e5f260b0016c + ---> Removed intermediate container e5f260b0016c + ---> fe51ba375215 +Step 24/27 : FROM builder AS tests + ---> fe51ba375215 +Step 25/27 : COPY --from=goose-builder /out/goose /usr/local/bin/goose + ---> 3ef73620b0a6 +Step 26/27 : ENV GOOSE_MIGRATION_DIR=/src/migrations + ---> Running in 4b59132a45e1 + ---> Removed intermediate container 4b59132a45e1 + ---> 43905e46829a +Step 27/27 : CMD ["go", "test", "-p=1", "-race", "-count=1", "-v", "./..."] + ---> Running in 9d6cbda904bc + ---> Removed intermediate container 9d6cbda904bc + ---> 037b4f43fd3c +Successfully built 037b4f43fd3c +Successfully tagged mtusi-messenger-tests:lab5 +4sbaveec2mbbm7q290z3mc4bh +mtusi-lab5_tests.0.ei8mkr461zio@colima | ? gitflic.ru/akselbant/mtusi2026lab1-fork/cmd [no test files] +mtusi-lab5_tests.0.ei8mkr461zio@colima | ? gitflic.ru/akselbant/mtusi2026lab1-fork/cmd/reconcile [no test files] +mtusi-lab5_tests.0.ei8mkr461zio@colima | ? gitflic.ru/akselbant/mtusi2026lab1-fork/cmd/worker [no test files] +mtusi-lab5_tests.0.ei8mkr461zio@colima | ? gitflic.ru/akselbant/mtusi2026lab1-fork/contracts [no test files] +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestMessageStrictFields +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestMessageStrictFields (0.00s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestTimestampFixedMicroseconds +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestTimestampFixedMicroseconds (0.00s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | PASS +mtusi-lab5_tests.0.ei8mkr461zio@colima | ok gitflic.ru/akselbant/mtusi2026lab1-fork/dto 1.016s +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestRejectsMalformedJSON +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:34 request_id=a120ebf4-66d8-4d9e-b9ef-404d1f0b8ad1 method=POST path=/api/v1/users status=400 response_bytes=140 latency=186.094µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestRejectsMalformedJSON (0.01s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestHidesForeignChat +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:35 request_id=525ea333-7fbc-4427-8ae2-082330c0b56f method=POST path=/api/v1/users status=201 response_bytes=141 latency=429.523996ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:35 request_id=3a55c465-0b19-4fe6-884c-12b97845202c method=POST path=/api/v1/auth/sessions status=201 response_bytes=269 latency=400.777506ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:36 request_id=91bc227a-7b92-459b-a9c7-c4a640a1ca3c method=POST path=/api/v1/users status=201 response_bytes=147 latency=384.621416ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:36 request_id=da2274f8-4ab2-4c54-981b-4b6375c89c48 method=POST path=/api/v1/auth/sessions status=201 response_bytes=275 latency=418.414288ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:36 request_id=d5be3cdc-dab8-48ae-8e97-027a7839b8d0 method=POST path=/api/v1/chats status=201 response_bytes=163 latency=196.223µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:36 request_id=c68e4735-48e5-4446-acbc-b756b3f00c63 method=GET path=/api/v1/chats/:chat_id status=404 response_bytes=126 latency=55.016µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestHidesForeignChat (1.64s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestRejectsEmptyMessage +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:36 request_id=f144edb2-0a71-4953-9712-670b4307d049 method=POST path=/api/v1/users status=201 response_bytes=157 latency=406.815108ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:37 request_id=a7cab490-48fc-49d4-8104-8eb04cb0e41f method=POST path=/api/v1/auth/sessions status=201 response_bytes=285 latency=405.008764ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:37 request_id=41a94031-c08c-4c45-9b9b-8ad54a797f9b method=POST path=/api/v1/chats status=201 response_bytes=163 latency=106.863µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:37 request_id=f2a1b6f2-94d2-4f39-9bac-ebae19dab481 method=POST path=/api/v1/chats/:chat_id/messages status=400 response_bytes=172 latency=151.21µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestRejectsEmptyMessage (0.82s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestRejectsDuplicateUsername +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:37 request_id=a4e26cce-1333-49cf-ac98-37aba8e40cf9 method=POST path=/api/v1/users status=201 response_bytes=149 latency=384.550494ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:38 request_id=bf6b6a52-a044-4104-b8df-71842f061941 method=POST path=/api/v1/auth/sessions status=201 response_bytes=277 latency=370.705527ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:38 request_id=53201beb-d49c-4fc0-8f28-815f7579b8f5 method=POST path=/api/v1/users status=409 response_bytes=170 latency=370.869332ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestRejectsDuplicateUsername (1.13s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestPaginatesMessagesAcrossMultiplePages +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:38 request_id=ac404967-cf50-4886-ab88-75fba0d66fbe method=POST path=/api/v1/users status=201 response_bytes=151 latency=399.448651ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:39 request_id=f4f96a97-08ed-49bb-8074-506429860102 method=POST path=/api/v1/auth/sessions status=201 response_bytes=279 latency=471.634839ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:39 request_id=eadaf592-9287-4360-86c8-4387b3829097 method=POST path=/api/v1/chats status=201 response_bytes=163 latency=126.203µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:39 request_id=2ac4a3fa-0fb8-40f0-b3a1-7af36163d37a method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=228 latency=197.723µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:39 request_id=52535278-cbce-435e-bd1e-37a433e56dfa method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=228 latency=179.885µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:39 request_id=5b11d2a6-386b-47be-aff7-317eb4fa2707 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=228 latency=160.38µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:39 request_id=861d72de-e7b9-4bbc-a5e5-b366f4387472 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=228 latency=140.582µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:39 request_id=0bddc2b2-b304-498d-9e09-1470cc7d31a7 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=228 latency=119.618µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:39 request_id=2dc5031e-2f06-46e2-8ac7-0761ddad5e4d method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=228 latency=153.17µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:39 request_id=0d0e5d73-d66f-4083-a5d0-686c6dec4c3c method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=228 latency=159.254µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:39 request_id=ac89c25b-9da9-42e3-9cd1-0c1e1f264ee1 method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=725 latency=390.862µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:39 request_id=de3853f3-74ae-4083-bcc8-598bb45ab9b9 method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=725 latency=242.07µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:39 request_id=43b8dc81-f545-4a36-a052-6dea583fdff4 method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=725 latency=175.425µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:39 request_id=305b99d8-fcb8-4fed-a648-24c5f4e817dc method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=259 latency=121.993µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestPaginatesMessagesAcrossMultiplePages (0.88s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestConcurrentMessagesAreUnique +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:39 request_id=f62e7a14-b7ae-4c24-bc64-cc47ac50dc93 method=POST path=/api/v1/users status=201 response_bytes=153 latency=376.003337ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:40 request_id=9922e1a1-b272-4cb4-807e-9c872404a471 method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=371.739811ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:40 request_id=413c97b5-8149-4c0d-92d5-4d9120882e9a method=POST path=/api/v1/users status=201 response_bytes=153 latency=371.796731ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:40 request_id=417099fe-cbba-430c-ba5f-694776a15347 method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=401.933506ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:41 request_id=2cd09de2-85fe-4ad0-bc87-8187a366a970 method=POST path=/api/v1/users status=201 response_bytes=153 latency=395.859968ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:41 request_id=409307c0-72d4-44c4-9aa5-33b3c5752aa8 method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=396.505304ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:41 request_id=ebec8d8c-e6a1-4c8c-8122-e0130516d2fc method=POST path=/api/v1/users status=201 response_bytes=153 latency=373.820076ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:42 request_id=385f8376-dbcc-4c0f-bd5b-22e6cbf989a4 method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=408.30886ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:42 request_id=2e8f957b-af2d-4f82-890c-17ee5ddd9bdc method=POST path=/api/v1/users status=201 response_bytes=153 latency=401.205396ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:43 request_id=41a56fb0-e2cb-4312-a57c-6457c00f79fe method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=381.081401ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:43 request_id=121e271b-7634-48e5-8395-90b992a18b75 method=POST path=/api/v1/users status=201 response_bytes=153 latency=400.063202ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:43 request_id=cf890726-06a9-4a26-b148-48ad9d16c1f4 method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=377.397779ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:44 request_id=1d7ed2cb-025a-487e-9995-06a61e6ea59f method=POST path=/api/v1/users status=201 response_bytes=153 latency=380.557862ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:44 request_id=fb4f8e2f-725e-4559-beb8-d828632a0f1e method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=395.192982ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:45 request_id=357d86d1-d0be-479a-83df-b91f0da90c9f method=POST path=/api/v1/users status=201 response_bytes=153 latency=371.774229ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:45 request_id=38b565f2-da72-489b-8149-9e55aa927f0d method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=442.382653ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:45 request_id=b7b29434-a765-45ab-a3df-bcd2b31e5642 method=POST path=/api/v1/users status=201 response_bytes=153 latency=372.279093ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=731b7f36-a09c-46b0-beb5-69cec9ba6abe method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=370.335795ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=42c59da2-0dcb-4be0-a7f4-0de2f6a388a6 method=POST path=/api/v1/users status=201 response_bytes=153 latency=375.164369ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=b59fa1d6-c07f-4b0c-a80f-df0c91db11da method=POST path=/api/v1/auth/sessions status=201 response_bytes=281 latency=405.93703ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=092cd05e-deb7-4378-b811-25c9f7cd0bad method=POST path=/api/v1/chats status=201 response_bytes=514 latency=186.533µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=8ca6b6d5-4ae2-4464-8b7c-abdb8835cadd method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=208.303µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=9904aa19-424a-4c52-bcba-ec103dae6fab method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=158.803µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=439132c6-6030-45ae-bb6b-032782ad78d8 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=162.073µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=62bee418-056f-4d68-ad0b-d1494dae9149 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=169.233µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=6f1c1df5-2e1a-4a1f-a1e2-07c9b356c41b method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=168.571µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=e7097d00-0825-45a0-9703-43848b1b86f2 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=187.857µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=94a4778a-b603-4947-99e6-7262cb63a02c method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=178.462µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=61f7f04e-7749-4007-80fa-5348d23cc79b method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=158.596µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=339f3ebd-f56b-46c4-afb4-d838b6d19e22 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=202.095µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=664575f1-de2b-4035-8290-02621be7def0 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=567.213µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=c6933c53-6a84-4462-bd1b-a27c6104dce5 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=276.674µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=0d005f58-b73e-4c0c-80ef-90333f841d6d method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=1.219435ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=571fead6-abcc-4205-a7fd-7d48ce65449a method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=875.838µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=ebb9eb40-526f-4139-a951-eb89822d28d7 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=1.808419ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=8328795d-6c01-4702-831b-9679f1c66839 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=153.215µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=b3030fcc-c444-49d7-a1c2-6132b1baa8da method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=142.662µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=2c933d51-f44b-4fac-a675-72c85774c512 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=484.438µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=c41778c0-56b2-49c1-9a82-1159463cffc6 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=2.414535ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=38ff6efb-454d-4772-8ba8-20683532d351 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=1.087575ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=4610cbff-d3c7-4083-a7b1-01621d4129cb method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=1.651312ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=8c2687e3-8b73-4720-bfa5-7596c6fdd5ed method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=3.211241ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=86372bfa-614a-4f92-bf1e-df5b302505bc method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=3.222457ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=a7cd6676-8436-4544-966b-bbc0c0241148 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=766.079µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=70bdf943-11df-447a-bfe1-3a5c22172a0d method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=153.299µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=41665126-c28d-4623-943b-12c375e7cd4e method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=187.898µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=f53ba09b-53a2-4071-b898-f828b948e171 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=153.423µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=673d03d2-6c91-435f-8b8c-8aff5b58c314 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=142.455µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=fea6b8ec-d431-492d-b61b-9403f165f818 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=143.863µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=74604d89-3eac-4ee0-8ff1-a70255fe6908 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=167.908µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=42cf5708-e2e9-45c7-addc-375633b507eb method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=157.106µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=d7d86eee-ce6b-4c36-8b29-559b33612678 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=143.241µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=694a46d1-d858-4046-96b4-832eaa0f9983 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=147.09µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=c8afd69d-af62-4dd5-a275-b9446299c738 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=135.378µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=4cf77251-b87b-445b-b1b4-14096daa4bc4 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=135.543µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=2fb59757-2e18-4d3d-855a-2e258a19414f method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=144.856µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=f1d91a2c-c587-49ea-9868-7c70f1abffeb method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=148.415µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=1d2a1995-c266-4a4b-9544-b54480cebd2c method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=139.31µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=3912cb0a-9060-4302-84a5-5d7c786d71c4 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=137.861µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=93908403-558e-450b-866a-58f5a321c88d method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=286.317µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=5ee59046-acf0-48c8-bb7d-5f21abe094d8 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=198.163µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=23c591a6-d56b-4018-b130-861d8e0589c8 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=135.999µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=31bbf0d9-a4af-4848-aefa-a771dcd55c40 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=309.453µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=1198591d-c43b-4c9b-bc76-4fad9f4bc40c method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=150.153µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=17e0a733-80ae-4f83-ae88-2fab97a5f044 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=156.734µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=7f40a24a-d447-45d6-beae-8b920e9bdbc7 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=134.592µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=bb29dbe8-0483-400a-9b60-02cd83c15485 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=505.546µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=e0da57fa-9e99-4f0c-8516-abdd4af85e46 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=725.602µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=428d1db9-9475-44e5-9eb6-c2c0b92bf418 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=491.226µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=eea31235-f85e-43df-bc23-9f6f0e7e7adb method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=1.944666ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=57a62d96-2f93-408e-9eb2-ce3e13c70a29 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=1.149243ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=1f5dd0c0-80f3-443d-a7ae-62c5aed88439 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=1.051817ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=2de77a11-98c7-45f5-91da-31b23e2d91c5 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=468.836µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=ac732004-5639-4c64-a815-de0e49ed3321 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=2.150691ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=54228bc8-0df7-4a23-b2d1-03ae892bd7f2 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=1.314626ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=d0d42de0-7fb6-46ae-b3bf-ca0d5950b03f method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=1.556204ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=68605d50-22f1-4dcb-88b3-a956b64e5cb3 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=366.981µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=d1b73e5c-4917-4a78-9c82-8add850b5079 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=282.924µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=dddebfc6-6f64-479f-80c3-87030922367c method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=295.381µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=4f3b527c-4137-4cb2-9473-49d56a420bbb method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=147.049µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=b9b06cbc-f7ac-44d6-9811-0fa2543cca70 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=153.34µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=e732f927-fe6d-40b9-a9ad-7782274e3650 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=345.377µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=0f10e634-118c-4cef-990c-1a7abb919ab5 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=360.07µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=4be5aad6-3a1d-494e-b0de-29e3a2972552 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=183.76µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=eddafdc2-c9b9-43d1-88f4-10f1c56071d2 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=134.964µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=b6c0615f-dce5-4631-aa5f-7dc2bf061681 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=290.705µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=a6c82fb3-0419-4bfb-badb-e4f45ca50d92 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=347.984µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=41704ab7-1120-4aba-84e8-628dc70275b1 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=589.562µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=76201778-5847-487a-b229-629354621449 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=1.083023ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=c0d50461-50d5-45a9-aaad-5af34d30a440 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=120.52µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=c1d344b9-dba4-4392-9e54-1efa06170360 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=169.605µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=f64ae733-f80b-4c1c-a953-e9ff5d10113b method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=128.011µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=6e66ae23-1cdf-4620-a8eb-0c12e6f01495 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=128.425µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=fb60631d-2a25-4a80-bddf-6667c0e12e2c method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=144.111µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=17c0b29d-7dd4-4b61-ade5-695194f19a68 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=124.824µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=6aa57338-428c-45a8-9d77-bd8c524f58d0 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=151.685µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=c886be6f-ee67-44a8-abe6-84e489cf975c method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=196.921µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=de16609f-4c14-412f-a4f1-f28d527599db method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=145.891µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=6876ce9a-90c3-4431-a056-7508ae43b034 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=118.988µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=2849e735-0d5e-4ab1-9932-d8be2bcdf65c method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=126.603µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=a883d328-3055-45f2-b971-ce43be573940 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=125.445µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=9f5f45ed-6b88-458d-9525-9326030919e1 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=126.356µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=0f74d6b0-8931-464a-aa5a-f26ad12daec4 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=119.94µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=fbdc3ebd-e88b-4864-8131-8ad4b89eb410 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=143.158µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=a7ba86ee-181b-4476-a7ab-a734c4ee266c method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=134.84µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=5e51912a-012a-4c56-9313-ceb9d44c4cc5 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=261.485µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=a3130f83-d27c-4ec2-87d3-59027067ea6a method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=124.245µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=b9e5b9b3-bbd6-4568-8753-d4351dc96839 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=147.545µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=4565e89e-caa9-4e4d-a078-a7ba9cbc479d method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=140.593µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=3df97f91-bacf-4194-a2df-e91b8a94d2a8 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=176.723µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:46 request_id=27f66f60-b97d-4d3e-9503-1af72c291662 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=127.225µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:47 request_id=64e38cb8-6eb5-4a3a-a01d-090dccca1035 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=152.636µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:47 request_id=ae0c3b4f-fa7e-4f02-abf9-c4e5ca5f4236 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=199.983µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:47 request_id=58d8552c-cda1-47d2-8881-d1a43b03ad3e method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=129.335µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:47 request_id=1dab28fb-6c71-4aa4-b8d5-da8e86da9e8a method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=172.743µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:47 request_id=ce0e5337-dc4f-4b11-8afc-1edf7653bf7f method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=347.195µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:47 request_id=28900f9b-33f1-4266-8950-5b7ed26d3867 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=143.56µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:47 request_id=cfcd75a4-9fc8-4bd7-82ff-929b69ce829a method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=131.59µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:47 request_id=9fd19029-673f-4935-9668-84a2d0e683d5 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=124.839µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:47 request_id=4ef3f1ae-50c1-413e-8c4e-1dafa5fb2d1c method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=137.803µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:47 request_id=cbcb3daa-1979-4392-bc47-6f5b20ea3070 method=POST path=/api/v1/chats/:chat_id/messages status=201 response_bytes=239 latency=289.151µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:47 request_id=a5ea6313-9465-4d20-b068-2553d3bee370 method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=4332 latency=776.079µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:47 request_id=48187e18-3ecd-4fbd-a062-c6de8a354daf method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=4332 latency=1.41448ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:47 request_id=1fc7fb98-1c6d-4376-832c-530e21630c58 method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=4332 latency=694.317µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:47 request_id=abfeb221-d940-4411-a679-64678c036f6e method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=4332 latency=606.963µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:47 request_id=b0e89015-1603-402a-939c-eb16b757c1a6 method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=4332 latency=536.633µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:47 request_id=01fed6c0-16a3-4df6-9b1b-bb20b74d7fe2 method=GET path=/api/v1/chats/:chat_id/messages status=200 response_bytes=3616 latency=481.751µs +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestConcurrentMessagesAreUnique (7.82s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | PASS +mtusi-lab5_tests.0.ei8mkr461zio@colima | ok gitflic.ru/akselbant/mtusi2026lab1-fork/internal/app/chat 13.393s +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestSpoolOriginalAndFullValidation +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestSpoolOriginalAndFullValidation (0.00s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestSpoolLimitsBeforeDecode +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestSpoolLimitsBeforeDecode (0.03s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestFilenameAndCancelledUpload +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestFilenameAndCancelledUpload (0.01s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestReconcileRejectsUnsafeGrace +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestReconcileRejectsUnsafeGrace (0.00s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestValid16BitWidePNG +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestValid16BitWidePNG (0.10s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestAttachmentTimestampsUseFixedMicroseconds +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestAttachmentTimestampsUseFixedMicroseconds (0.00s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestFitGeometry +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestFitGeometry (0.00s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestOrientationsAndAlpha +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestOrientationsAndAlpha (0.00s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestEXIFOrientation +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestEXIFOrientation (0.00s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestFenceIntegration +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestFenceIntegration (0.07s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | PASS +mtusi-lab5_tests.0.ei8mkr461zio@colima | ok gitflic.ru/akselbant/mtusi2026lab1-fork/internal/attachment 1.244s +mtusi-lab5_tests.0.ei8mkr461zio@colima | ? gitflic.ru/akselbant/mtusi2026lab1-fork/internal/config [no test files] +mtusi-lab5_tests.0.ei8mkr461zio@colima | ? gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain [no test files] +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestUnicodeAndSalt +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestUnicodeAndSalt (2.70s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | PASS +mtusi-lab5_tests.0.ei8mkr461zio@colima | ok gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/password 3.754s +mtusi-lab5_tests.0.ei8mkr461zio@colima | ? gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/repository [no test files] +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestS3WireFixture +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestS3WireFixture (0.00s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestIntegration +mtusi-lab5_tests.0.ei8mkr461zio@colima | storage_test.go:85: goose up: 2026/11/10 18:24:55 OK 001_initial.sql (16.88ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:55 OK 002_idempotency.sql (1.65ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:55 OK 003_attachments.sql (3.72ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:55 OK 004_message_attachments.sql (1.35ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:55 OK 005_async_attachments.sql (4.89ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:55 OK 006_attachment_jobs.sql (2.81ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:55 OK 007_attachment_outbox.sql (2.14ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:55 OK 008_attachment_replays.sql (3.36ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:55 OK 009_backfill_pipeline.sql (1.54ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:55 OK 010_storage_cleanup.sql (431.27µs) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:55 goose: successfully migrated database to version: 10 +mtusi-lab5_tests.0.ei8mkr461zio@colima | storage_test.go:86: goose up: 2026/11/10 18:24:55 goose: no migrations to run. current version: 10 +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestIntegration/registration_race +mtusi-lab5_tests.0.ei8mkr461zio@colima | storage_test.go:122: 12 concurrent INSERTs: 1 success, 11 unique conflicts +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestIntegration/rollback +mtusi-lab5_tests.0.ei8mkr461zio@colima | storage_test.go:140: failed second member INSERT left 0 chats and 0 members +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestIntegration/lab4_attachments_and_reconciliation +mtusi-lab5_tests.0.ei8mkr461zio@colima | lab4_test.go:248: ACL, original bytes, cross-chat attachment rejection, ordered/concurrent idempotency and absent=[] passed +mtusi-lab5_tests.0.ei8mkr461zio@colima | lab4_test.go:321: dry-run={Apply:false GraceSeconds:90 ObjectsScanned:5 MetadataScanned:2 BytesScanned:106 ListRequestsEstimate:1 StatRequests:3 DBQueries:14 Orphans:1 Missing:1 FreshSkipped:1 LockedSkipped:1 ReferencedMissing:1 Deleted:0 MarkedFailed:0 DurationMS:9 Actions:[{Kind:orphan Key:original/93a9cd5a-2728-4884-9071-a77f1e762d68 Applied:false} {Kind:missing Key:original/fc633700-4e23-4d86-a40c-6242cfad8d27 Applied:false}]} apply={Apply:true GraceSeconds:90 ObjectsScanned:5 MetadataScanned:2 BytesScanned:106 ListRequestsEstimate:1 StatRequests:3 DBQueries:15 Orphans:1 Missing:1 FreshSkipped:1 LockedSkipped:1 ReferencedMissing:1 Deleted:1 MarkedFailed:1 DurationMS:7 Actions:[{Kind:orphan Key:original/93a9cd5a-2728-4884-9071-a77f1e762d68 Applied:true} {Kind:missing Key:original/fc633700-4e23-4d86-a40c-6242cfad8d27 Applied:true}]} repeat={Apply:true GraceSeconds:90 ObjectsScanned:4 MetadataScanned:2 BytesScanned:100 ListRequestsEstimate:1 StatRequests:1 DBQueries:9 Orphans:0 Missing:0 FreshSkipped:1 LockedSkipped:1 ReferencedMissing:0 Deleted:0 MarkedFailed:0 DurationMS:2 Actions:[]}; fresh, locked and referenced objects retained +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestIntegration/keyset_and_explain +mtusi-lab5_tests.0.ei8mkr461zio@colima | storage_test.go:194: EXPLAIN on 10,000 messages, cursor near the end (9,000): +mtusi-lab5_tests.0.ei8mkr461zio@colima | storage_test.go:200: Limit (cost=0.29..17.99 rows=51 width=142) (actual time=0.023..0.041 rows=51 loops=1) +mtusi-lab5_tests.0.ei8mkr461zio@colima | storage_test.go:200: Buffers: shared hit=10 +mtusi-lab5_tests.0.ei8mkr461zio@colima | storage_test.go:200: -> Index Scan using messages_history_idx on messages m (cost=0.29..347.47 rows=1000 width=142) (actual time=0.022..0.036 rows=51 loops=1) +mtusi-lab5_tests.0.ei8mkr461zio@colima | storage_test.go:200: Index Cond: ((chat_id = '4f6f6bd1-9d3d-4b0a-b567-b15a8a04c64f'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.9+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid))) +mtusi-lab5_tests.0.ei8mkr461zio@colima | storage_test.go:200: Buffers: shared hit=10 +mtusi-lab5_tests.0.ei8mkr461zio@colima | storage_test.go:200: Planning Time: 0.027 ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | storage_test.go:200: Execution Time: 0.068 ms +mtusi-lab5_tests.0.ei8mkr461zio@colima | storage_test.go:205: keyset traversal returned 10,000 distinct messages, including equal timestamps +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestIntegration/idempotency_race +mtusi-lab5_tests.0.ei8mkr461zio@colima | storage_test.go:255: 16 concurrent PostgreSQL requests: one effect, identical replay, changed body conflicts +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestIntegration/goose_legacy_and_down +mtusi-lab5_tests.0.ei8mkr461zio@colima | storage_test.go:265: goose down-to: 2026/11/10 18:24:56 OK 010_storage_cleanup.sql (2.55ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 009_backfill_pipeline.sql (467.83µs) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 008_attachment_replays.sql (3.28ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 007_attachment_outbox.sql (3.2ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 006_attachment_jobs.sql (3.22ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 005_async_attachments.sql (2.97ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 goose: no migrations to run. current version: 4 +mtusi-lab5_tests.0.ei8mkr461zio@colima | storage_test.go:271: goose up: 2026/11/10 18:24:56 OK 001_initial.sql (1.76ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 002_idempotency.sql (1.26ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 003_attachments.sql (478.98µs) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 004_message_attachments.sql (2.98ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 005_async_attachments.sql (6.7ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 006_attachment_jobs.sql (2.98ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 007_attachment_outbox.sql (1.94ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 008_attachment_replays.sql (2.86ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 009_backfill_pipeline.sql (2.12ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 010_storage_cleanup.sql (485.17µs) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 goose: successfully migrated database to version: 10 +mtusi-lab5_tests.0.ei8mkr461zio@colima | storage_test.go:272: goose up: 2026/11/10 18:24:56 goose: no migrations to run. current version: 10 +mtusi-lab5_tests.0.ei8mkr461zio@colima | storage_test.go:279: adopted legacy schema: all existing messages are unchanged +mtusi-lab5_tests.0.ei8mkr461zio@colima | storage_test.go:280: goose reset: 2026/11/10 18:24:56 OK 010_storage_cleanup.sql (2.13ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 009_backfill_pipeline.sql (705.12µs) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 008_attachment_replays.sql (2.89ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 007_attachment_outbox.sql (2.62ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 006_attachment_jobs.sql (3.52ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 005_async_attachments.sql (3.49ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 004_message_attachments.sql (4.03ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 003_attachments.sql (3.47ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 002_idempotency.sql (961.4µs) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 001_initial.sql (8.51ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | storage_test.go:285: goose up: 2026/11/10 18:24:56 OK 001_initial.sql (10.59ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 002_idempotency.sql (1.5ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 003_attachments.sql (3.42ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 004_message_attachments.sql (1.18ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 005_async_attachments.sql (3.95ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 006_attachment_jobs.sql (2.66ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 007_attachment_outbox.sql (1.8ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 008_attachment_replays.sql (2.38ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 009_backfill_pipeline.sql (1.43ms) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 OK 010_storage_cleanup.sql (484.05µs) +mtusi-lab5_tests.0.ei8mkr461zio@colima | 2026/11/10 18:24:56 goose: successfully migrated database to version: 10 +mtusi-lab5_tests.0.ei8mkr461zio@colima | storage_test.go:289: down and up succeeded in isolated schema +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestIntegration (0.72s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestIntegration/registration_race (0.03s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestIntegration/rollback (0.00s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestIntegration/lab4_attachments_and_reconciliation (0.06s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestIntegration/keyset_and_explain (0.08s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestIntegration/idempotency_race (0.01s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestIntegration/goose_legacy_and_down (0.20s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | PASS +mtusi-lab5_tests.0.ei8mkr461zio@colima | ok gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/repository/postgres 1.752s +mtusi-lab5_tests.0.ei8mkr461zio@colima | ? gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/session [no test files] +mtusi-lab5_tests.0.ei8mkr461zio@colima | === RUN TestPasswordContract +mtusi-lab5_tests.0.ei8mkr461zio@colima | --- PASS: TestPasswordContract (0.00s) +mtusi-lab5_tests.0.ei8mkr461zio@colima | PASS +mtusi-lab5_tests.0.ei8mkr461zio@colima | ok gitflic.ru/akselbant/mtusi2026lab1-fork/internal/usecase/chat 1.018s +mtusi-lab5_tests diff --git a/evidence/lab5-persistence.txt b/evidence/lab5-persistence.txt new file mode 100644 index 00000000..c7cc5f34 --- /dev/null +++ b/evidence/lab5-persistence.txt @@ -0,0 +1,3 @@ +.venv/bin/python tests/resilience.py --mode persistence --action-script "scripts/restart.sh" --base-url "http://localhost:18085" +Executing explicit persistence hook; hook output suppressed to avoid leaking secrets. +PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence. diff --git a/evidence/lab5-research.csv b/evidence/lab5-research.csv new file mode 100644 index 00000000..c1c4fb8a --- /dev/null +++ b/evidence/lab5-research.csv @@ -0,0 +1,7 @@ +width,height,concurrency,prefetch,offered,accepted,completed,throughput_rps,ready_p95_ms,after_accept_p95_ms,upload_p95_ms,queue_lag_peak_seconds,rss_peak_bytes +512,512,1,1,20,20,20,3.316,4761.802,4554.64,328.115,4.078925,33816576 +512,512,2,4,20,20,20,4.013,4327.625,4169.426,173.305,3.172338,56823808 +512,512,4,8,20,20,20,3.903,4453.48,4281.149,191.95,2.665913,94711808 +1536,1536,1,1,20,20,20,0.774,22792.626,21836.999,1073.912,21.476154,77754368 +1536,1536,2,4,20,20,20,0.851,21471.061,20489.723,1147.664,18.202527,140812288 +1536,1536,4,8,20,20,20,0.847,20744.497,19885.435,1134.032,16.602282,235130880 diff --git a/evidence/lab5-research.json b/evidence/lab5-research.json new file mode 100644 index 00000000..61be85ed --- /dev/null +++ b/evidence/lab5-research.json @@ -0,0 +1,2099 @@ +{ + "track": 1, + "started_at": "2026-11-10T19:03:13.613546+00:00", + "stack": "mtusi-lab5", + "worker_image": "mtusi-messenger:lab5", + "worker_image_id": "sha256:66e3c9bc004e8a21f70f7f537d56d64b847ea099719a3b756cd8da9e3bfad5f7", + "environment": { + "docker_server": "29.5.2", + "docker_cpus": 2, + "docker_memory_bytes": 2053644288, + "architecture": "arm64", + "python": "3.9.6" + }, + "worker_limits": { + "NanoCPUs": 1000000000, + "MemoryBytes": 1610612736 + }, + "initial_settings": { + "worker": { + "WORKER_CONCURRENCY": "2", + "WORKER_PREFETCH": "4" + }, + "api": { + "MAX_OUTSTANDING_JOBS": null + } + }, + "requests_per_case": 20, + "upload_concurrency": 8, + "sampling_interval_min_seconds": 0.25, + "method": { + "throughput": "completed / burst makespan including client upload and polling", + "ready_latency": "client POST start to first observed ready; nearest-rank p95", + "queue_lag": "age of oldest queued PostgreSQL job in this chat; excludes processing", + "rss": "sum VmRSS for worker, renderers and cwebp; shared pages may count repeatedly", + "limitations": "single host; warmup per case; sampled peaks and polling latency; finite burst, no production SLA" + }, + "cases": [ + { + "concurrency": 1, + "prefetch": 1, + "width": 512, + "height": 512, + "size_bytes": 787252, + "input_sha256": "205c1114728681c54a23968d77501d0948b5abea6dfa6522bee2f91eeac3dfe2", + "offered": 20, + "accepted": 20, + "rejected": 0, + "completed": 20, + "makespan_seconds": 6.031, + "throughput_rps": 3.316, + "ready_p50_ms": 3005.016, + "ready_p95_ms": 4761.802, + "after_accept_p95_ms": 4554.64, + "upload_p95_ms": 328.115, + "queue_lag_peak_seconds": 4.078925, + "outstanding_peak": 19, + "rss_baseline_bytes": 15818752, + "rss_peak_bytes": 33816576, + "samples": [ + { + "seconds": 0.583, + "outstanding": 2, + "queued": 1, + "processing": 1, + "queue_lag_seconds": 0.01802, + "rss_bytes": 29978624 + }, + { + "seconds": 1.136, + "outstanding": 19, + "queued": 18, + "processing": 1, + "queue_lag_seconds": 0.573877, + "rss_bytes": 33816576 + }, + { + "seconds": 1.71, + "outstanding": 17, + "queued": 16, + "processing": 1, + "queue_lag_seconds": 1.10088, + "rss_bytes": 30461952 + }, + { + "seconds": 2.245, + "outstanding": 14, + "queued": 13, + "processing": 1, + "queue_lag_seconds": 1.551341, + "rss_bytes": 30990336 + }, + { + "seconds": 2.733, + "outstanding": 12, + "queued": 11, + "processing": 1, + "queue_lag_seconds": 1.994326, + "rss_bytes": 31334400 + }, + { + "seconds": 3.207, + "outstanding": 10, + "queued": 9, + "processing": 1, + "queue_lag_seconds": 2.390667, + "rss_bytes": 31141888 + }, + { + "seconds": 3.691, + "outstanding": 8, + "queued": 7, + "processing": 1, + "queue_lag_seconds": 2.818544, + "rss_bytes": 30248960 + }, + { + "seconds": 4.178, + "outstanding": 6, + "queued": 5, + "processing": 1, + "queue_lag_seconds": 3.272491, + "rss_bytes": 31404032 + }, + { + "seconds": 4.708, + "outstanding": 4, + "queued": 3, + "processing": 1, + "queue_lag_seconds": 3.762719, + "rss_bytes": 30318592 + }, + { + "seconds": 5.157, + "outstanding": 3, + "queued": 2, + "processing": 1, + "queue_lag_seconds": 4.078925, + "rss_bytes": 28913664 + }, + { + "seconds": 5.598, + "outstanding": 1, + "queued": 0, + "processing": 1, + "queue_lag_seconds": 0, + "rss_bytes": 15974400 + }, + { + "seconds": 6.03, + "outstanding": 0, + "queued": 0, + "processing": 0, + "queue_lag_seconds": 0, + "rss_bytes": 15974400 + } + ], + "observations": [ + { + "attachment_id": "646b2385-3ab6-445d-8b78-d1a8814c4e80", + "ready_ms": 662.87, + "upload_ms": 189.316 + }, + { + "attachment_id": "dd9a1cba-9a24-4de8-be88-5ab566c354f4", + "ready_ms": 1202.492, + "upload_ms": 229.308 + }, + { + "attachment_id": "f118b697-73b8-4c02-b5cb-a32c2c26c4c7", + "ready_ms": 1211.582, + "upload_ms": 252.032 + }, + { + "attachment_id": "0b3b8787-4622-4244-9f62-2f017ac7b36f", + "ready_ms": 1782.331, + "upload_ms": 269.074 + }, + { + "attachment_id": "5158f4c7-9a48-439f-a55d-d102a6b62b72", + "ready_ms": 1782.638, + "upload_ms": 288.937 + }, + { + "attachment_id": "9c04af07-d559-47a6-8141-07fa3600f1ae", + "ready_ms": 2283.593, + "upload_ms": 301.658 + }, + { + "attachment_id": "1c5eb5a6-4c88-46ae-bbe2-5775aa37a0dd", + "ready_ms": 2291.712, + "upload_ms": 328.115 + }, + { + "attachment_id": "75f0c388-755d-42f5-963d-cf4a5d2e3a3e", + "ready_ms": 2742.883, + "upload_ms": 341.367 + }, + { + "attachment_id": "4e5b2b2f-a535-4d4d-ad66-b044d3591611", + "ready_ms": 2602.965, + "upload_ms": 218.028 + }, + { + "attachment_id": "2906e543-876e-4573-9589-b34ccd299a16", + "ready_ms": 3005.016, + "upload_ms": 232.298 + }, + { + "attachment_id": "9d93b13c-aad0-488b-964b-69eee71b6c7e", + "ready_ms": 3043.318, + "upload_ms": 205.818 + }, + { + "attachment_id": "b2b3b8fe-087b-48fe-8e1a-ac63a2af9995", + "ready_ms": 3427.563, + "upload_ms": 255.924 + }, + { + "attachment_id": "ebed9087-a7e7-4747-a007-bde8811e6835", + "ready_ms": 3459.608, + "upload_ms": 254.825 + }, + { + "attachment_id": "bf03b424-088c-4524-b987-cd3412d8f7a2", + "ready_ms": 3862.413, + "upload_ms": 233.23 + }, + { + "attachment_id": "4ea92ffb-c786-4cf6-aea9-928187c709d7", + "ready_ms": 3903.646, + "upload_ms": 258.777 + }, + { + "attachment_id": "c63b7647-09ad-4c51-9288-d96b96053ea8", + "ready_ms": 4367.295, + "upload_ms": 230.246 + }, + { + "attachment_id": "72468d5c-21c3-474e-9c9c-975580cdb287", + "ready_ms": 4347.311, + "upload_ms": 215.974 + }, + { + "attachment_id": "697018a9-f526-4d61-8d76-4ad2cd59ad70", + "ready_ms": 4761.802, + "upload_ms": 207.163 + }, + { + "attachment_id": "2bb19513-f2c9-4b58-a06d-f338afb9598c", + "ready_ms": 4715.44, + "upload_ms": 167.403 + }, + { + "attachment_id": "b9005407-6f57-4553-8521-1acc7b0fbafe", + "ready_ms": 5106.537, + "upload_ms": 142.814 + } + ] + }, + { + "concurrency": 2, + "prefetch": 4, + "width": 512, + "height": 512, + "size_bytes": 787252, + "input_sha256": "205c1114728681c54a23968d77501d0948b5abea6dfa6522bee2f91eeac3dfe2", + "offered": 20, + "accepted": 20, + "rejected": 0, + "completed": 20, + "makespan_seconds": 4.983, + "throughput_rps": 4.013, + "ready_p50_ms": 2356.701, + "ready_p95_ms": 4327.625, + "after_accept_p95_ms": 4169.426, + "upload_p95_ms": 173.305, + "queue_lag_peak_seconds": 3.172338, + "outstanding_peak": 18, + "rss_baseline_bytes": 15888384, + "rss_peak_bytes": 56823808, + "samples": [ + { + "seconds": 0.485, + "outstanding": 6, + "queued": 4, + "processing": 2, + "queue_lag_seconds": 0.069336, + "rss_bytes": 44666880 + }, + { + "seconds": 1.083, + "outstanding": 18, + "queued": 16, + "processing": 2, + "queue_lag_seconds": 0.611984, + "rss_bytes": 46854144 + }, + { + "seconds": 1.67, + "outstanding": 16, + "queued": 14, + "processing": 2, + "queue_lag_seconds": 1.192728, + "rss_bytes": 56823808 + }, + { + "seconds": 2.252, + "outstanding": 12, + "queued": 10, + "processing": 2, + "queue_lag_seconds": 1.705331, + "rss_bytes": 46981120 + }, + { + "seconds": 2.843, + "outstanding": 10, + "queued": 8, + "processing": 2, + "queue_lag_seconds": 2.197292, + "rss_bytes": 56717312 + }, + { + "seconds": 3.499, + "outstanding": 7, + "queued": 6, + "processing": 1, + "queue_lag_seconds": 2.749598, + "rss_bytes": 44724224 + }, + { + "seconds": 4.037, + "outstanding": 4, + "queued": 2, + "processing": 2, + "queue_lag_seconds": 3.172338, + "rss_bytes": 49577984 + }, + { + "seconds": 4.537, + "outstanding": 2, + "queued": 0, + "processing": 2, + "queue_lag_seconds": 0, + "rss_bytes": 38957056 + }, + { + "seconds": 4.983, + "outstanding": 0, + "queued": 0, + "processing": 0, + "queue_lag_seconds": 0, + "rss_bytes": 16973824 + } + ], + "observations": [ + { + "attachment_id": "ce826562-f2d7-4646-a8cc-666fdc0e3445", + "ready_ms": 648.575, + "upload_ms": 93.272 + }, + { + "attachment_id": "14901dea-5a21-4972-b727-483944df4289", + "ready_ms": 1200.2, + "upload_ms": 75.948 + }, + { + "attachment_id": "f47aaab9-212f-4e51-96b4-a5f6560f8705", + "ready_ms": 1203.505, + "upload_ms": 110.701 + }, + { + "attachment_id": "099ea578-7850-4f8d-8405-5ded1065fda3", + "ready_ms": 1193.826, + "upload_ms": 122.626 + }, + { + "attachment_id": "408f9f25-d253-457b-ab48-c721d7009ef2", + "ready_ms": 1770.196, + "upload_ms": 158.926 + }, + { + "attachment_id": "e20381b7-ba3a-4c55-9101-0f04ac9d1146", + "ready_ms": 1807.439, + "upload_ms": 156.373 + }, + { + "attachment_id": "ef819d0c-67b9-4807-8aad-135d313de3a2", + "ready_ms": 2323.718, + "upload_ms": 172.673 + }, + { + "attachment_id": "1e74c982-9b68-4daf-bc86-b245cf8b3f55", + "ready_ms": 2243.281, + "upload_ms": 173.305 + }, + { + "attachment_id": "d1ce4c95-59b1-4f54-92f8-be6d4492b320", + "ready_ms": 2302.181, + "upload_ms": 166.344 + }, + { + "attachment_id": "4d512530-df1e-4cb7-854a-acd1b637eeae", + "ready_ms": 2356.701, + "upload_ms": 183.129 + }, + { + "attachment_id": "ab8f6f91-fd57-4358-91e7-4bd066c8cb63", + "ready_ms": 2899.235, + "upload_ms": 168.626 + }, + { + "attachment_id": "b775bd82-d85b-43b2-99e8-5c83564b3372", + "ready_ms": 2871.317, + "upload_ms": 170.58 + }, + { + "attachment_id": "49e64a58-dd48-4f80-a751-945ba319225a", + "ready_ms": 3432.304, + "upload_ms": 165.885 + }, + { + "attachment_id": "04a04ce5-153c-46be-9a61-db23f60cc080", + "ready_ms": 3456.342, + "upload_ms": 168.861 + }, + { + "attachment_id": "138ec4c7-c9ca-4588-aafb-156b0d09668c", + "ready_ms": 3868.115, + "upload_ms": 159.786 + }, + { + "attachment_id": "5bd994da-1dd8-4203-b31a-11038114d25c", + "ready_ms": 3935.046, + "upload_ms": 162.486 + }, + { + "attachment_id": "304e9528-c937-49c4-b218-2503fa608921", + "ready_ms": 3923.622, + "upload_ms": 160.39 + }, + { + "attachment_id": "ea458347-e9ac-4e16-bdc1-8bd337b7a51f", + "ready_ms": 3903.069, + "upload_ms": 153.094 + }, + { + "attachment_id": "9ba18ea9-13c3-433d-a446-a16b0e13dd19", + "ready_ms": 4344.972, + "upload_ms": 161.284 + }, + { + "attachment_id": "e96a7be8-9b5c-4711-9c52-45da94063afe", + "ready_ms": 4327.625, + "upload_ms": 158.199 + } + ] + }, + { + "concurrency": 4, + "prefetch": 8, + "width": 512, + "height": 512, + "size_bytes": 787252, + "input_sha256": "205c1114728681c54a23968d77501d0948b5abea6dfa6522bee2f91eeac3dfe2", + "offered": 20, + "accepted": 20, + "rejected": 0, + "completed": 20, + "makespan_seconds": 5.124, + "throughput_rps": 3.903, + "ready_p50_ms": 2900.885, + "ready_p95_ms": 4453.48, + "after_accept_p95_ms": 4281.149, + "upload_p95_ms": 191.95, + "queue_lag_peak_seconds": 2.665913, + "outstanding_peak": 20, + "rss_baseline_bytes": 15736832, + "rss_peak_bytes": 94711808, + "samples": [ + { + "seconds": 0.556, + "outstanding": 5, + "queued": 5, + "processing": 0, + "queue_lag_seconds": 0.095001, + "rss_bytes": 65802240 + }, + { + "seconds": 1.102, + "outstanding": 20, + "queued": 16, + "processing": 4, + "queue_lag_seconds": 0.658051, + "rss_bytes": 94711808 + }, + { + "seconds": 1.807, + "outstanding": 16, + "queued": 12, + "processing": 4, + "queue_lag_seconds": 1.258819, + "rss_bytes": 82518016 + }, + { + "seconds": 2.391, + "outstanding": 13, + "queued": 9, + "processing": 4, + "queue_lag_seconds": 1.72038, + "rss_bytes": 73089024 + }, + { + "seconds": 2.982, + "outstanding": 11, + "queued": 7, + "processing": 4, + "queue_lag_seconds": 2.266387, + "rss_bytes": 66252800 + }, + { + "seconds": 3.593, + "outstanding": 7, + "queued": 3, + "processing": 4, + "queue_lag_seconds": 2.665913, + "rss_bytes": 78663680 + }, + { + "seconds": 4.172, + "outstanding": 4, + "queued": 0, + "processing": 4, + "queue_lag_seconds": 0, + "rss_bytes": 59797504 + }, + { + "seconds": 4.669, + "outstanding": 2, + "queued": 0, + "processing": 2, + "queue_lag_seconds": 0, + "rss_bytes": 16719872 + }, + { + "seconds": 5.123, + "outstanding": 0, + "queued": 0, + "processing": 0, + "queue_lag_seconds": 0, + "rss_bytes": 16781312 + } + ], + "observations": [ + { + "attachment_id": "6fb4bcdb-d3a6-422e-aadf-5114682fbf6c", + "ready_ms": 1168.149, + "upload_ms": 118.86 + }, + { + "attachment_id": "38bd01ea-2541-4e0a-9273-a9056a7546e4", + "ready_ms": 1214.942, + "upload_ms": 114.237 + }, + { + "attachment_id": "9f617f89-4585-47be-a0e5-f55ce010b21b", + "ready_ms": 1243.659, + "upload_ms": 78.523 + }, + { + "attachment_id": "3248421b-96f1-423b-8c6e-ab29cbab2829", + "ready_ms": 1263.479, + "upload_ms": 102.431 + }, + { + "attachment_id": "ae7fb249-3399-4e9f-8d51-afc46c98e7f7", + "ready_ms": 2434.688, + "upload_ms": 155.371 + }, + { + "attachment_id": "84e866c0-c4a1-4996-898b-e19f90bf28f9", + "ready_ms": 2449.042, + "upload_ms": 163.852 + }, + { + "attachment_id": "0a3ebb63-4cd5-44d7-aa17-edf8972ea240", + "ready_ms": 2386.365, + "upload_ms": 166.507 + }, + { + "attachment_id": "655decd7-e199-45b0-9084-9242cba0fb63", + "ready_ms": 2489.014, + "upload_ms": 133.543 + }, + { + "attachment_id": "8ff95066-f752-49c2-832a-30f6f5aa7fc9", + "ready_ms": 2484.853, + "upload_ms": 178.776 + }, + { + "attachment_id": "5ee41346-dc3b-45ab-ab40-fab1b40a4b66", + "ready_ms": 2900.885, + "upload_ms": 191.95 + }, + { + "attachment_id": "689cfe15-7c9d-4917-a09c-67f7009e8f07", + "ready_ms": 2953.14, + "upload_ms": 146.877 + }, + { + "attachment_id": "f72ee233-7d79-4d9f-9dd8-2a1914974fd6", + "ready_ms": 2976.284, + "upload_ms": 143.164 + }, + { + "attachment_id": "60de5aea-2dc6-4e9e-9834-cde5d7da064a", + "ready_ms": 2954.715, + "upload_ms": 183.028 + }, + { + "attachment_id": "8c2bb984-9c2c-4c1f-9da7-d0ff68f4a6a2", + "ready_ms": 4023.765, + "upload_ms": 187.25 + }, + { + "attachment_id": "0dd7d082-238b-4865-b1cb-02424d3d783e", + "ready_ms": 4064.043, + "upload_ms": 182.425 + }, + { + "attachment_id": "82a36d66-a13f-415b-b54d-e900af9997c2", + "ready_ms": 4057.21, + "upload_ms": 183.918 + }, + { + "attachment_id": "8f59adc2-b335-42b5-844e-93c1fa2526ed", + "ready_ms": 4031.183, + "upload_ms": 193.777 + }, + { + "attachment_id": "cd599cbe-b96b-4d28-8120-0ab9a8e90242", + "ready_ms": 4453.48, + "upload_ms": 172.33 + }, + { + "attachment_id": "d8ca0870-e258-4e7e-a244-ffa672e85bdb", + "ready_ms": 4426.811, + "upload_ms": 148.3 + }, + { + "attachment_id": "35abe4b6-19fd-437c-befc-1dc4d4d41cf8", + "ready_ms": 4497.526, + "upload_ms": 186.67 + } + ] + }, + { + "concurrency": 1, + "prefetch": 1, + "width": 1536, + "height": 1536, + "size_bytes": 7081647, + "input_sha256": "015b73f610b2145516211f8039594f43e64dfdaf0326b2874b294727f114de02", + "offered": 20, + "accepted": 20, + "rejected": 0, + "completed": 20, + "makespan_seconds": 25.854, + "throughput_rps": 0.774, + "ready_p50_ms": 12939.763, + "ready_p95_ms": 22792.626, + "after_accept_p95_ms": 21836.999, + "upload_p95_ms": 1073.912, + "queue_lag_peak_seconds": 21.476154, + "outstanding_peak": 20, + "rss_baseline_bytes": 15982592, + "rss_peak_bytes": 77754368, + "samples": [ + { + "seconds": 1.02, + "outstanding": 0, + "queued": 0, + "processing": 0, + "queue_lag_seconds": 0, + "rss_bytes": 33550336 + }, + { + "seconds": 1.8, + "outstanding": 10, + "queued": 9, + "processing": 1, + "queue_lag_seconds": 0.688855, + "rss_bytes": 53231616 + }, + { + "seconds": 2.378, + "outstanding": 15, + "queued": 14, + "processing": 1, + "queue_lag_seconds": 1.426091, + "rss_bytes": 53948416 + }, + { + "seconds": 2.879, + "outstanding": 20, + "queued": 19, + "processing": 1, + "queue_lag_seconds": 1.947211, + "rss_bytes": 16060416 + }, + { + "seconds": 3.423, + "outstanding": 19, + "queued": 18, + "processing": 1, + "queue_lag_seconds": 2.417889, + "rss_bytes": 53731328 + }, + { + "seconds": 4.011, + "outstanding": 19, + "queued": 18, + "processing": 1, + "queue_lag_seconds": 2.991099, + "rss_bytes": 74772480 + }, + { + "seconds": 4.552, + "outstanding": 18, + "queued": 17, + "processing": 1, + "queue_lag_seconds": 3.494125, + "rss_bytes": 53624832 + }, + { + "seconds": 5.073, + "outstanding": 18, + "queued": 17, + "processing": 1, + "queue_lag_seconds": 4.010811, + "rss_bytes": 74854400 + }, + { + "seconds": 5.596, + "outstanding": 17, + "queued": 16, + "processing": 1, + "queue_lag_seconds": 4.539016, + "rss_bytes": 53174272 + }, + { + "seconds": 6.251, + "outstanding": 17, + "queued": 16, + "processing": 1, + "queue_lag_seconds": 5.130687, + "rss_bytes": 64868352 + }, + { + "seconds": 6.763, + "outstanding": 16, + "queued": 15, + "processing": 1, + "queue_lag_seconds": 5.607154, + "rss_bytes": 48951296 + }, + { + "seconds": 7.335, + "outstanding": 16, + "queued": 15, + "processing": 1, + "queue_lag_seconds": 6.118839, + "rss_bytes": 60424192 + }, + { + "seconds": 7.84, + "outstanding": 15, + "queued": 14, + "processing": 1, + "queue_lag_seconds": 6.573697, + "rss_bytes": 50601984 + }, + { + "seconds": 8.348, + "outstanding": 15, + "queued": 14, + "processing": 1, + "queue_lag_seconds": 7.107352, + "rss_bytes": 53428224 + }, + { + "seconds": 8.827, + "outstanding": 15, + "queued": 14, + "processing": 1, + "queue_lag_seconds": 7.583777, + "rss_bytes": 16121856 + }, + { + "seconds": 9.337, + "outstanding": 14, + "queued": 13, + "processing": 1, + "queue_lag_seconds": 7.987629, + "rss_bytes": 52092928 + }, + { + "seconds": 9.826, + "outstanding": 14, + "queued": 13, + "processing": 1, + "queue_lag_seconds": 8.50605, + "rss_bytes": 64462848 + }, + { + "seconds": 10.355, + "outstanding": 13, + "queued": 12, + "processing": 1, + "queue_lag_seconds": 8.956849, + "rss_bytes": 50950144 + }, + { + "seconds": 10.835, + "outstanding": 13, + "queued": 12, + "processing": 1, + "queue_lag_seconds": 9.439881, + "rss_bytes": 57647104 + }, + { + "seconds": 11.36, + "outstanding": 12, + "queued": 11, + "processing": 1, + "queue_lag_seconds": 9.732071, + "rss_bytes": 48742400 + }, + { + "seconds": 11.899, + "outstanding": 12, + "queued": 11, + "processing": 1, + "queue_lag_seconds": 10.240891, + "rss_bytes": 53321728 + }, + { + "seconds": 12.396, + "outstanding": 12, + "queued": 11, + "processing": 1, + "queue_lag_seconds": 10.797879, + "rss_bytes": 16224256 + }, + { + "seconds": 12.877, + "outstanding": 11, + "queued": 10, + "processing": 1, + "queue_lag_seconds": 11.191622, + "rss_bytes": 53665792 + }, + { + "seconds": 13.351, + "outstanding": 11, + "queued": 10, + "processing": 1, + "queue_lag_seconds": 11.66977, + "rss_bytes": 77754368 + }, + { + "seconds": 13.824, + "outstanding": 10, + "queued": 9, + "processing": 1, + "queue_lag_seconds": 11.950794, + "rss_bytes": 52498432 + }, + { + "seconds": 14.358, + "outstanding": 10, + "queued": 9, + "processing": 1, + "queue_lag_seconds": 12.498662, + "rss_bytes": 57901056 + }, + { + "seconds": 14.837, + "outstanding": 9, + "queued": 8, + "processing": 1, + "queue_lag_seconds": 12.758517, + "rss_bytes": 47919104 + }, + { + "seconds": 15.313, + "outstanding": 9, + "queued": 8, + "processing": 1, + "queue_lag_seconds": 13.243371, + "rss_bytes": 53309440 + }, + { + "seconds": 15.775, + "outstanding": 9, + "queued": 8, + "processing": 1, + "queue_lag_seconds": 13.706933, + "rss_bytes": 62353408 + }, + { + "seconds": 16.325, + "outstanding": 8, + "queued": 7, + "processing": 1, + "queue_lag_seconds": 14.200687, + "rss_bytes": 53628928 + }, + { + "seconds": 16.786, + "outstanding": 8, + "queued": 7, + "processing": 1, + "queue_lag_seconds": 14.666856, + "rss_bytes": 70582272 + }, + { + "seconds": 17.278, + "outstanding": 7, + "queued": 6, + "processing": 1, + "queue_lag_seconds": 15.03883, + "rss_bytes": 49065984 + }, + { + "seconds": 17.734, + "outstanding": 7, + "queued": 6, + "processing": 1, + "queue_lag_seconds": 15.50651, + "rss_bytes": 52953088 + }, + { + "seconds": 18.344, + "outstanding": 7, + "queued": 6, + "processing": 1, + "queue_lag_seconds": 16.077438, + "rss_bytes": 16084992 + }, + { + "seconds": 18.792, + "outstanding": 6, + "queued": 5, + "processing": 1, + "queue_lag_seconds": 16.479718, + "rss_bytes": 53477376 + }, + { + "seconds": 19.245, + "outstanding": 6, + "queued": 5, + "processing": 1, + "queue_lag_seconds": 16.930317, + "rss_bytes": 76738560 + }, + { + "seconds": 19.695, + "outstanding": 5, + "queued": 4, + "processing": 1, + "queue_lag_seconds": 17.31214, + "rss_bytes": 48459776 + }, + { + "seconds": 20.195, + "outstanding": 5, + "queued": 4, + "processing": 1, + "queue_lag_seconds": 17.799775, + "rss_bytes": 60489728 + }, + { + "seconds": 20.648, + "outstanding": 5, + "queued": 4, + "processing": 1, + "queue_lag_seconds": 18.259385, + "rss_bytes": 15990784 + }, + { + "seconds": 21.143, + "outstanding": 4, + "queued": 3, + "processing": 1, + "queue_lag_seconds": 18.717576, + "rss_bytes": 53784576 + }, + { + "seconds": 21.606, + "outstanding": 4, + "queued": 3, + "processing": 1, + "queue_lag_seconds": 19.175829, + "rss_bytes": 73236480 + }, + { + "seconds": 22.058, + "outstanding": 3, + "queued": 2, + "processing": 1, + "queue_lag_seconds": 19.563274, + "rss_bytes": 52822016 + }, + { + "seconds": 22.516, + "outstanding": 3, + "queued": 2, + "processing": 1, + "queue_lag_seconds": 20.017596, + "rss_bytes": 66035712 + }, + { + "seconds": 23.125, + "outstanding": 2, + "queued": 2, + "processing": 0, + "queue_lag_seconds": 20.531987, + "rss_bytes": 47538176 + }, + { + "seconds": 23.606, + "outstanding": 2, + "queued": 1, + "processing": 1, + "queue_lag_seconds": 21.033856, + "rss_bytes": 53334016 + }, + { + "seconds": 24.05, + "outstanding": 2, + "queued": 1, + "processing": 1, + "queue_lag_seconds": 21.476154, + "rss_bytes": 66752512 + }, + { + "seconds": 24.52, + "outstanding": 1, + "queued": 0, + "processing": 1, + "queue_lag_seconds": 0, + "rss_bytes": 51838976 + }, + { + "seconds": 24.956, + "outstanding": 1, + "queued": 0, + "processing": 1, + "queue_lag_seconds": 0, + "rss_bytes": 63279104 + }, + { + "seconds": 25.408, + "outstanding": 1, + "queued": 0, + "processing": 1, + "queue_lag_seconds": 0, + "rss_bytes": 16261120 + }, + { + "seconds": 25.854, + "outstanding": 0, + "queued": 0, + "processing": 0, + "queue_lag_seconds": 0, + "rss_bytes": 16261120 + } + ], + "observations": [ + { + "attachment_id": "72ff9bf3-1dff-4644-a4d6-ae4bd7a617a8", + "ready_ms": 2978.062, + "upload_ms": 489.72 + }, + { + "attachment_id": "abe6a64b-f1e5-40d5-8ceb-3a7da3999640", + "ready_ms": 4113.182, + "upload_ms": 582.949 + }, + { + "attachment_id": "1dadde6d-8831-4035-91d1-00dd21897af4", + "ready_ms": 5167.355, + "upload_ms": 651.946 + }, + { + "attachment_id": "408e49cd-a346-42b2-8c8c-9ef1613ff231", + "ready_ms": 6855.691, + "upload_ms": 771.882 + }, + { + "attachment_id": "8277e968-cb19-42b4-9d1d-99d4221e1545", + "ready_ms": 7948.368, + "upload_ms": 855.385 + }, + { + "attachment_id": "e26f1421-f2a4-4427-a07e-af265f8f0b65", + "ready_ms": 8890.393, + "upload_ms": 944.604 + }, + { + "attachment_id": "e19e3655-8a95-4379-b94f-224ec7b3855e", + "ready_ms": 9851.15, + "upload_ms": 1016.483 + }, + { + "attachment_id": "6ef71b51-44a7-4423-b9e3-89541b97e970", + "ready_ms": 11385.961, + "upload_ms": 1105.276 + }, + { + "attachment_id": "110f5859-5437-4fc5-90c9-81791efeab6b", + "ready_ms": 11913.871, + "upload_ms": 658.419 + }, + { + "attachment_id": "c8a362ec-ea03-4cd2-8eba-3438a6debef2", + "ready_ms": 12939.763, + "upload_ms": 850.829 + }, + { + "attachment_id": "64ded537-4b0a-4745-b4dc-3900ca79c812", + "ready_ms": 14150.284, + "upload_ms": 670.543 + }, + { + "attachment_id": "bf549960-5414-4d26-96f3-dd6431f6a987", + "ready_ms": 15205.165, + "upload_ms": 1006.479 + }, + { + "attachment_id": "cb4c3dbb-75b0-458e-873a-69fec2a480e4", + "ready_ms": 15905.145, + "upload_ms": 891.157 + }, + { + "attachment_id": "14436df8-d3da-4b50-8e68-7b724da9be51", + "ready_ms": 17584.614, + "upload_ms": 1045.919 + }, + { + "attachment_id": "0ed68cb8-e3e6-45c2-9773-bf934db75454", + "ready_ms": 18110.868, + "upload_ms": 791.025 + }, + { + "attachment_id": "30515ce8-61dc-4211-ad60-f09c2da702dd", + "ready_ms": 19659.633, + "upload_ms": 1046.097 + }, + { + "attachment_id": "cca7e14a-127d-4deb-8e52-7dc87a7ad36b", + "ready_ms": 20262.643, + "upload_ms": 750.774 + }, + { + "attachment_id": "7a185ba2-5492-45d6-bfcf-ddd7fdaf04d1", + "ready_ms": 22053.501, + "upload_ms": 1073.912 + }, + { + "attachment_id": "978ae03a-8e42-4bdf-9beb-9ae487f82651", + "ready_ms": 22792.626, + "upload_ms": 955.627 + }, + { + "attachment_id": "c428751a-9273-415a-86d7-2f7f69d0664b", + "ready_ms": 23836.824, + "upload_ms": 721.881 + } + ] + }, + { + "concurrency": 2, + "prefetch": 4, + "width": 1536, + "height": 1536, + "size_bytes": 7081647, + "input_sha256": "015b73f610b2145516211f8039594f43e64dfdaf0326b2874b294727f114de02", + "offered": 20, + "accepted": 20, + "rejected": 0, + "completed": 20, + "makespan_seconds": 23.508, + "throughput_rps": 0.851, + "ready_p50_ms": 12230.053, + "ready_p95_ms": 21471.061, + "after_accept_p95_ms": 20489.723, + "upload_p95_ms": 1147.664, + "queue_lag_peak_seconds": 18.202527, + "outstanding_peak": 20, + "rss_baseline_bytes": 15872000, + "rss_peak_bytes": 140812288, + "samples": [ + { + "seconds": 0.804, + "outstanding": 0, + "queued": 0, + "processing": 0, + "queue_lag_seconds": 0, + "rss_bytes": 15970304 + }, + { + "seconds": 1.609, + "outstanding": 7, + "queued": 5, + "processing": 2, + "queue_lag_seconds": 0.522618, + "rss_bytes": 85676032 + }, + { + "seconds": 2.335, + "outstanding": 13, + "queued": 11, + "processing": 2, + "queue_lag_seconds": 1.388412, + "rss_bytes": 91406336 + }, + { + "seconds": 2.964, + "outstanding": 20, + "queued": 18, + "processing": 2, + "queue_lag_seconds": 2.023378, + "rss_bytes": 102551552 + }, + { + "seconds": 3.531, + "outstanding": 20, + "queued": 18, + "processing": 2, + "queue_lag_seconds": 2.574746, + "rss_bytes": 62296064 + }, + { + "seconds": 4.141, + "outstanding": 18, + "queued": 16, + "processing": 2, + "queue_lag_seconds": 2.974395, + "rss_bytes": 86925312 + }, + { + "seconds": 4.741, + "outstanding": 18, + "queued": 16, + "processing": 2, + "queue_lag_seconds": 3.553895, + "rss_bytes": 90320896 + }, + { + "seconds": 5.322, + "outstanding": 18, + "queued": 16, + "processing": 2, + "queue_lag_seconds": 4.137822, + "rss_bytes": 117186560 + }, + { + "seconds": 6.059, + "outstanding": 18, + "queued": 16, + "processing": 2, + "queue_lag_seconds": 4.877053, + "rss_bytes": 24940544 + }, + { + "seconds": 6.63, + "outstanding": 16, + "queued": 14, + "processing": 2, + "queue_lag_seconds": 5.248695, + "rss_bytes": 91217920 + }, + { + "seconds": 7.249, + "outstanding": 16, + "queued": 14, + "processing": 2, + "queue_lag_seconds": 5.841495, + "rss_bytes": 91856896 + }, + { + "seconds": 7.835, + "outstanding": 16, + "queued": 14, + "processing": 2, + "queue_lag_seconds": 6.43863, + "rss_bytes": 140812288 + }, + { + "seconds": 8.424, + "outstanding": 14, + "queued": 12, + "processing": 2, + "queue_lag_seconds": 6.719826, + "rss_bytes": 79773696 + }, + { + "seconds": 9.003, + "outstanding": 14, + "queued": 12, + "processing": 2, + "queue_lag_seconds": 7.268924, + "rss_bytes": 93224960 + }, + { + "seconds": 9.723, + "outstanding": 14, + "queued": 12, + "processing": 2, + "queue_lag_seconds": 7.961311, + "rss_bytes": 109162496 + }, + { + "seconds": 10.343, + "outstanding": 14, + "queued": 12, + "processing": 2, + "queue_lag_seconds": 8.675691, + "rss_bytes": 66420736 + }, + { + "seconds": 10.913, + "outstanding": 12, + "queued": 10, + "processing": 2, + "queue_lag_seconds": 8.881136, + "rss_bytes": 89284608 + }, + { + "seconds": 11.473, + "outstanding": 12, + "queued": 10, + "processing": 2, + "queue_lag_seconds": 9.410813, + "rss_bytes": 92332032 + }, + { + "seconds": 12.095, + "outstanding": 12, + "queued": 10, + "processing": 2, + "queue_lag_seconds": 10.044173, + "rss_bytes": 120737792 + }, + { + "seconds": 12.639, + "outstanding": 12, + "queued": 10, + "processing": 2, + "queue_lag_seconds": 10.643923, + "rss_bytes": 47562752 + }, + { + "seconds": 13.156, + "outstanding": 10, + "queued": 8, + "processing": 2, + "queue_lag_seconds": 10.865062, + "rss_bytes": 90583040 + }, + { + "seconds": 13.667, + "outstanding": 10, + "queued": 8, + "processing": 2, + "queue_lag_seconds": 11.419681, + "rss_bytes": 93134848 + }, + { + "seconds": 14.213, + "outstanding": 10, + "queued": 8, + "processing": 2, + "queue_lag_seconds": 11.932928, + "rss_bytes": 117977088 + }, + { + "seconds": 14.717, + "outstanding": 10, + "queued": 8, + "processing": 2, + "queue_lag_seconds": 12.476196, + "rss_bytes": 16855040 + }, + { + "seconds": 15.259, + "outstanding": 8, + "queued": 6, + "processing": 2, + "queue_lag_seconds": 12.747498, + "rss_bytes": 89051136 + }, + { + "seconds": 15.805, + "outstanding": 8, + "queued": 6, + "processing": 2, + "queue_lag_seconds": 13.312622, + "rss_bytes": 92135424 + }, + { + "seconds": 16.369, + "outstanding": 8, + "queued": 6, + "processing": 2, + "queue_lag_seconds": 13.827427, + "rss_bytes": 119685120 + }, + { + "seconds": 16.916, + "outstanding": 8, + "queued": 6, + "processing": 2, + "queue_lag_seconds": 14.41196, + "rss_bytes": 61480960 + }, + { + "seconds": 17.474, + "outstanding": 6, + "queued": 4, + "processing": 2, + "queue_lag_seconds": 14.838173, + "rss_bytes": 91725824 + }, + { + "seconds": 17.982, + "outstanding": 6, + "queued": 4, + "processing": 2, + "queue_lag_seconds": 15.313376, + "rss_bytes": 93421568 + }, + { + "seconds": 18.543, + "outstanding": 6, + "queued": 4, + "processing": 2, + "queue_lag_seconds": 15.910134, + "rss_bytes": 125739008 + }, + { + "seconds": 19.008, + "outstanding": 6, + "queued": 4, + "processing": 2, + "queue_lag_seconds": 16.389491, + "rss_bytes": 16818176 + }, + { + "seconds": 19.538, + "outstanding": 4, + "queued": 2, + "processing": 2, + "queue_lag_seconds": 16.706092, + "rss_bytes": 89124864 + }, + { + "seconds": 20.023, + "outstanding": 4, + "queued": 2, + "processing": 2, + "queue_lag_seconds": 17.209332, + "rss_bytes": 91959296 + }, + { + "seconds": 20.522, + "outstanding": 4, + "queued": 2, + "processing": 2, + "queue_lag_seconds": 17.719409, + "rss_bytes": 108560384 + }, + { + "seconds": 21.036, + "outstanding": 4, + "queued": 2, + "processing": 2, + "queue_lag_seconds": 18.202527, + "rss_bytes": 69586944 + }, + { + "seconds": 21.526, + "outstanding": 2, + "queued": 0, + "processing": 2, + "queue_lag_seconds": 0, + "rss_bytes": 86437888 + }, + { + "seconds": 22.05, + "outstanding": 2, + "queued": 0, + "processing": 2, + "queue_lag_seconds": 0, + "rss_bytes": 92631040 + }, + { + "seconds": 22.568, + "outstanding": 2, + "queued": 0, + "processing": 2, + "queue_lag_seconds": 0, + "rss_bytes": 112336896 + }, + { + "seconds": 23.064, + "outstanding": 2, + "queued": 0, + "processing": 2, + "queue_lag_seconds": 0, + "rss_bytes": 78319616 + }, + { + "seconds": 23.507, + "outstanding": 0, + "queued": 0, + "processing": 0, + "queue_lag_seconds": 0, + "rss_bytes": 16228352 + } + ], + "observations": [ + { + "attachment_id": "99688333-40bf-4d41-a4fe-323fad0904e9", + "ready_ms": 3560.499, + "upload_ms": 408.011 + }, + { + "attachment_id": "f147a922-d1fc-42cc-a66b-142d571f82df", + "ready_ms": 3554.025, + "upload_ms": 457.303 + }, + { + "attachment_id": "7658c2fe-3bb2-4ca4-8412-d0eb20a2b8ef", + "ready_ms": 6052.072, + "upload_ms": 679.643 + }, + { + "attachment_id": "89f86138-8fcd-4105-9892-c9dfe9dbecdc", + "ready_ms": 6066.401, + "upload_ms": 583.962 + }, + { + "attachment_id": "ceb8fe8c-a841-495e-bd34-5aad13dd6d75", + "ready_ms": 8403.356, + "upload_ms": 771.179 + }, + { + "attachment_id": "bf6a320d-9cfd-4029-a1d5-6ffd3c558aed", + "ready_ms": 8440.405, + "upload_ms": 887.69 + }, + { + "attachment_id": "3ac7646a-b9ca-4e27-8aa3-763ac97e994b", + "ready_ms": 10349.01, + "upload_ms": 981.57 + }, + { + "attachment_id": "00c411bc-e7e7-4ac4-90d9-2fa2d2c98a1c", + "ready_ms": 10339.33, + "upload_ms": 1076.033 + }, + { + "attachment_id": "71e1a5b8-497c-4c4e-958e-28e0ae2ca882", + "ready_ms": 12230.053, + "upload_ms": 833.319 + }, + { + "attachment_id": "821c31eb-38ce-4a1c-9955-e9fcc2859ff8", + "ready_ms": 12176.461, + "upload_ms": 1020.951 + }, + { + "attachment_id": "ae840ffa-f8c9-4fbc-b7bc-bd59ba5e9e72", + "ready_ms": 14133.905, + "upload_ms": 1012.104 + }, + { + "attachment_id": "5ffb85c0-0441-46c8-9f39-21b3138ce662", + "ready_ms": 14053.062, + "upload_ms": 1005.261 + }, + { + "attachment_id": "70dcb558-6257-4a9d-83bb-1494a55a9ef2", + "ready_ms": 16140.026, + "upload_ms": 1082.357 + }, + { + "attachment_id": "4e0240ab-c8c8-494d-8bcc-1c43cd447738", + "ready_ms": 15936.966, + "upload_ms": 985.338 + }, + { + "attachment_id": "8d0b3749-7ace-412c-9b19-e8a28eabb84f", + "ready_ms": 18123.235, + "upload_ms": 1204.862 + }, + { + "attachment_id": "d1236a0d-6869-4930-a6a2-e90ede460170", + "ready_ms": 17782.071, + "upload_ms": 926.795 + }, + { + "attachment_id": "acfc46ce-c102-4b10-b483-c820ce2dc416", + "ready_ms": 19926.281, + "upload_ms": 1147.664 + }, + { + "attachment_id": "7b22deab-2e71-4a84-92bb-135d3b5f2fbf", + "ready_ms": 19347.044, + "upload_ms": 652.552 + }, + { + "attachment_id": "c35b9a9b-1241-4a6d-895a-99773d78f318", + "ready_ms": 21471.061, + "upload_ms": 981.339 + }, + { + "attachment_id": "a83f78fc-4201-4da9-8519-1bdcf403aa21", + "ready_ms": 21587.644, + "upload_ms": 936.535 + } + ] + }, + { + "concurrency": 4, + "prefetch": 8, + "width": 1536, + "height": 1536, + "size_bytes": 7081647, + "input_sha256": "015b73f610b2145516211f8039594f43e64dfdaf0326b2874b294727f114de02", + "offered": 20, + "accepted": 20, + "rejected": 0, + "completed": 20, + "makespan_seconds": 23.602, + "throughput_rps": 0.847, + "ready_p50_ms": 13459.561, + "ready_p95_ms": 20744.497, + "after_accept_p95_ms": 19885.435, + "upload_p95_ms": 1134.032, + "queue_lag_peak_seconds": 16.602282, + "outstanding_peak": 20, + "rss_baseline_bytes": 16134144, + "rss_peak_bytes": 235130880, + "samples": [ + { + "seconds": 0.813, + "outstanding": 0, + "queued": 0, + "processing": 0, + "queue_lag_seconds": 0, + "rss_bytes": 45719552 + }, + { + "seconds": 1.493, + "outstanding": 6, + "queued": 2, + "processing": 4, + "queue_lag_seconds": 0.174778, + "rss_bytes": 143278080 + }, + { + "seconds": 2.202, + "outstanding": 13, + "queued": 9, + "processing": 4, + "queue_lag_seconds": 0.968807, + "rss_bytes": 155238400 + }, + { + "seconds": 2.933, + "outstanding": 19, + "queued": 15, + "processing": 4, + "queue_lag_seconds": 1.613169, + "rss_bytes": 165273600 + }, + { + "seconds": 3.638, + "outstanding": 20, + "queued": 16, + "processing": 4, + "queue_lag_seconds": 2.323971, + "rss_bytes": 168144896 + }, + { + "seconds": 4.287, + "outstanding": 20, + "queued": 16, + "processing": 4, + "queue_lag_seconds": 3.036557, + "rss_bytes": 182329344 + }, + { + "seconds": 4.921, + "outstanding": 20, + "queued": 16, + "processing": 4, + "queue_lag_seconds": 3.659427, + "rss_bytes": 209608704 + }, + { + "seconds": 5.538, + "outstanding": 20, + "queued": 16, + "processing": 4, + "queue_lag_seconds": 4.347039, + "rss_bytes": 208084992 + }, + { + "seconds": 6.12, + "outstanding": 17, + "queued": 14, + "processing": 3, + "queue_lag_seconds": 4.708041, + "rss_bytes": 146980864 + }, + { + "seconds": 6.721, + "outstanding": 16, + "queued": 12, + "processing": 4, + "queue_lag_seconds": 5.034121, + "rss_bytes": 155770880 + }, + { + "seconds": 7.302, + "outstanding": 16, + "queued": 12, + "processing": 4, + "queue_lag_seconds": 5.617518, + "rss_bytes": 165101568 + }, + { + "seconds": 7.836, + "outstanding": 16, + "queued": 12, + "processing": 4, + "queue_lag_seconds": 6.172094, + "rss_bytes": 169320448 + }, + { + "seconds": 8.419, + "outstanding": 16, + "queued": 12, + "processing": 4, + "queue_lag_seconds": 6.723611, + "rss_bytes": 184619008 + }, + { + "seconds": 9.004, + "outstanding": 16, + "queued": 12, + "processing": 4, + "queue_lag_seconds": 7.310578, + "rss_bytes": 225910784 + }, + { + "seconds": 9.585, + "outstanding": 16, + "queued": 12, + "processing": 4, + "queue_lag_seconds": 7.892007, + "rss_bytes": 0 + }, + { + "seconds": 10.185, + "outstanding": 14, + "queued": 10, + "processing": 4, + "queue_lag_seconds": 8.34158, + "rss_bytes": 144318464 + }, + { + "seconds": 10.798, + "outstanding": 12, + "queued": 8, + "processing": 4, + "queue_lag_seconds": 8.711244, + "rss_bytes": 154238976 + }, + { + "seconds": 11.505, + "outstanding": 12, + "queued": 8, + "processing": 4, + "queue_lag_seconds": 9.414926, + "rss_bytes": 165646336 + }, + { + "seconds": 12.073, + "outstanding": 12, + "queued": 8, + "processing": 4, + "queue_lag_seconds": 9.9939, + "rss_bytes": 178364416 + }, + { + "seconds": 12.684, + "outstanding": 12, + "queued": 8, + "processing": 4, + "queue_lag_seconds": 10.584393, + "rss_bytes": 196341760 + }, + { + "seconds": 13.288, + "outstanding": 12, + "queued": 8, + "processing": 4, + "queue_lag_seconds": 11.205643, + "rss_bytes": 200409088 + }, + { + "seconds": 13.831, + "outstanding": 11, + "queued": 7, + "processing": 4, + "queue_lag_seconds": 11.641966, + "rss_bytes": 150261760 + }, + { + "seconds": 14.407, + "outstanding": 10, + "queued": 6, + "processing": 4, + "queue_lag_seconds": 12.033763, + "rss_bytes": 193028096 + }, + { + "seconds": 15.067, + "outstanding": 9, + "queued": 5, + "processing": 4, + "queue_lag_seconds": 12.521832, + "rss_bytes": 176140288 + }, + { + "seconds": 15.668, + "outstanding": 8, + "queued": 4, + "processing": 4, + "queue_lag_seconds": 13.11874, + "rss_bytes": 158498816 + }, + { + "seconds": 16.187, + "outstanding": 8, + "queued": 4, + "processing": 4, + "queue_lag_seconds": 13.66311, + "rss_bytes": 170463232 + }, + { + "seconds": 16.776, + "outstanding": 8, + "queued": 4, + "processing": 4, + "queue_lag_seconds": 14.235394, + "rss_bytes": 197406720 + }, + { + "seconds": 17.333, + "outstanding": 8, + "queued": 4, + "processing": 4, + "queue_lag_seconds": 14.829522, + "rss_bytes": 196517888 + }, + { + "seconds": 17.899, + "outstanding": 7, + "queued": 3, + "processing": 4, + "queue_lag_seconds": 15.288305, + "rss_bytes": 209166336 + }, + { + "seconds": 18.463, + "outstanding": 7, + "queued": 3, + "processing": 4, + "queue_lag_seconds": 15.737111, + "rss_bytes": 130351104 + }, + { + "seconds": 18.99, + "outstanding": 5, + "queued": 1, + "processing": 4, + "queue_lag_seconds": 16.061496, + "rss_bytes": 180559872 + }, + { + "seconds": 19.488, + "outstanding": 5, + "queued": 1, + "processing": 4, + "queue_lag_seconds": 16.602282, + "rss_bytes": 184385536 + }, + { + "seconds": 20.008, + "outstanding": 4, + "queued": 0, + "processing": 4, + "queue_lag_seconds": 0, + "rss_bytes": 159518720 + }, + { + "seconds": 20.47, + "outstanding": 4, + "queued": 0, + "processing": 4, + "queue_lag_seconds": 0, + "rss_bytes": 175730688 + }, + { + "seconds": 20.953, + "outstanding": 4, + "queued": 0, + "processing": 4, + "queue_lag_seconds": 0, + "rss_bytes": 184320000 + }, + { + "seconds": 21.55, + "outstanding": 4, + "queued": 0, + "processing": 4, + "queue_lag_seconds": 0, + "rss_bytes": 235130880 + }, + { + "seconds": 22.051, + "outstanding": 4, + "queued": 0, + "processing": 4, + "queue_lag_seconds": 0, + "rss_bytes": 111206400 + }, + { + "seconds": 22.708, + "outstanding": 1, + "queued": 0, + "processing": 1, + "queue_lag_seconds": 0, + "rss_bytes": 59723776 + }, + { + "seconds": 23.178, + "outstanding": 1, + "queued": 0, + "processing": 1, + "queue_lag_seconds": 0, + "rss_bytes": 17543168 + }, + { + "seconds": 23.601, + "outstanding": 0, + "queued": 0, + "processing": 0, + "queue_lag_seconds": 0, + "rss_bytes": 17477632 + } + ], + "observations": [ + { + "attachment_id": "09e001f8-6730-41fd-bd5c-0105e0a519a1", + "ready_ms": 5635.479, + "upload_ms": 379.774 + }, + { + "attachment_id": "fa2633da-3cfe-4d74-b345-d01ecee4c603", + "ready_ms": 6197.281, + "upload_ms": 811.621 + }, + { + "attachment_id": "06ab46de-9fe5-4294-8667-3697727ec660", + "ready_ms": 6192.099, + "upload_ms": 643.883 + }, + { + "attachment_id": "8b125e8a-db3f-48fc-a2a6-70fc90f0da7d", + "ready_ms": 6211.204, + "upload_ms": 465.159 + }, + { + "attachment_id": "7b8a17f9-71cc-452d-b05b-b04a109e0f86", + "ready_ms": 9635.43, + "upload_ms": 1295.364 + }, + { + "attachment_id": "3a216daa-9184-4143-aa24-c2fb26fe65b7", + "ready_ms": 9654.948, + "upload_ms": 898.299 + }, + { + "attachment_id": "3428eb34-cd42-4c1c-9bab-5733561fd44a", + "ready_ms": 10266.06, + "upload_ms": 1051.242 + }, + { + "attachment_id": "ff49cac4-62c3-4005-b114-71f116d51d29", + "ready_ms": 10847.423, + "upload_ms": 1134.032 + }, + { + "attachment_id": "9fae56a4-ba64-4947-809e-34c10051205c", + "ready_ms": 12577.222, + "upload_ms": 751.709 + }, + { + "attachment_id": "c627cf28-b4e7-42e9-bdf9-83d6ef9f780b", + "ready_ms": 13459.561, + "upload_ms": 949.39 + }, + { + "attachment_id": "cd56a914-37d4-4b51-bb19-60f6a3378ced", + "ready_ms": 14769.857, + "upload_ms": 1113.794 + }, + { + "attachment_id": "9ff00757-950e-4fad-83ab-f1fecbc97cfa", + "ready_ms": 15101.025, + "upload_ms": 1013.618 + }, + { + "attachment_id": "928fadf0-75c4-45ce-9718-91d7101cf7c5", + "ready_ms": 16911.15, + "upload_ms": 739.552 + }, + { + "attachment_id": "da2cbbd5-3afa-42d0-9a37-2b7fbe6629dc", + "ready_ms": 17620.17, + "upload_ms": 1059.124 + }, + { + "attachment_id": "973b6abd-880b-49d3-accd-101d9cc87c3e", + "ready_ms": 17220.489, + "upload_ms": 772.069 + }, + { + "attachment_id": "9ff48419-a077-4b62-a0dc-f779ccd7f87b", + "ready_ms": 18925.466, + "upload_ms": 1036.736 + }, + { + "attachment_id": "45f54fd6-1c3c-44e8-9a69-f34f28e31be5", + "ready_ms": 20580.767, + "upload_ms": 858.08 + }, + { + "attachment_id": "36296a7a-7fda-4b12-b026-c6fc433d9753", + "ready_ms": 20744.497, + "upload_ms": 933.986 + }, + { + "attachment_id": "ceefd3ec-372a-4264-a35a-7944b2717699", + "ready_ms": 20668.569, + "upload_ms": 783.134 + }, + { + "attachment_id": "0389dd0c-e1f0-4c01-a5ad-08c3e93af110", + "ready_ms": 21584.932, + "upload_ms": 901.456 + } + ] + } + ], + "overload": { + "limit": 8, + "offered": 16, + "accepted": 8, + "rejected_429": 8, + "observed_api_instances": 2, + "outstanding_worker_stopped": 8, + "ready_after_resume": 8, + "observed_drain_after_worker_healthy_seconds": 0.062, + "outstanding_after_recovery": 0, + "followup_upload": 202, + "text_messages_during_overload": "PASS" + }, + "result": "PASS", + "restored_initial_settings": true, + "finished_at": "2026-11-10T19:08:13.363296+00:00" +} diff --git a/evidence/lab5-research.png b/evidence/lab5-research.png new file mode 100644 index 00000000..aa5eaaab Binary files /dev/null and b/evidence/lab5-research.png differ diff --git a/evidence/lab5-research.svg b/evidence/lab5-research.svg new file mode 100644 index 00000000..27ec2d8c --- /dev/null +++ b/evidence/lab5-research.svg @@ -0,0 +1,2752 @@ + + + + + + + + 2026-11-10T22:08:55.028824 + image/svg+xml + + + Matplotlib + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/evidence/lab5-smoke.txt b/evidence/lab5-smoke.txt new file mode 100644 index 00000000..c1bf3fc7 --- /dev/null +++ b/evidence/lab5-smoke.txt @@ -0,0 +1,2 @@ +.venv/bin/python tests/smoke.py --base-url "http://localhost:18085" +PASS: lab5 public API scenario; infrastructure and grading evidence remain separate. diff --git a/evidence/lab5-validation.txt b/evidence/lab5-validation.txt new file mode 100644 index 00000000..3f7f5878 --- /dev/null +++ b/evidence/lab5-validation.txt @@ -0,0 +1,19 @@ +Fresh lab5 validation, 2026-11-10. +Root independent checks: + make check validate: exit 0. + go vet ./...: exit 0. + ./scripts/compose.sh config --quiet: exit 0. + docker stack config -c stack.yaml: exit 0. + sh -n scripts/*.sh infra/*.sh: exit 0. +Worker checks: + go test -race ./...: exit 0. + make test: exit 0, lab5 scenario on port18085. + make test-integration: exit 0 on repeat, including 005-010 up/down-to4/legacy/reset/up. + Integration initial failure was an inherited fixture that dropped the migration journal from an already-lab5 schema. + The fixture now models an actual lab4 schema (down-to4) before legacy-journal adoption. + Fault cases: all 11 groups verified across the initial main phase and --tail-only repeat. + The original full invocation exited 1 due to a test stop-helper race; it is not claimed as a full green run. + make test-persistence: exit 0; own stack restart preserved confirmed data and existing session. + make test-failover: exit 0; one of two API replicas stopped, 123 successful writes, 1 failed attempt, recovery 0.696s. +Public contracts and tests match skeleton276dbda; optional private tests cover added requirements. +Historical evidence/lab4-* is not used as current lab5 evidence. diff --git a/evidence/swarm-grade4.json b/evidence/swarm-grade4.json new file mode 100644 index 00000000..419dfe10 --- /dev/null +++ b/evidence/swarm-grade4.json @@ -0,0 +1,72 @@ +{ + "idempotency": { + "parallel_requests": 16, + "instances": [ + "rz3qizaxp0s2bguzbs57me0op", + "xcgz2hubz1xrzmrkoyrgwq0tq" + ], + "unique_message_ids": 1 + }, + "failovers": [ + { + "action": "stop-one", + "target": "rz3qizaxp0s2bguzbs57me0op", + "duration_seconds": 15.458, + "successful_writes": 1078, + "failed_attempts": 7, + "successful_rps": 69.739, + "first_recovery_seconds": 1.349, + "max_success_gap_seconds": 1.055, + "instances_before": [ + "rz3qizaxp0s2bguzbs57me0op", + "xcgz2hubz1xrzmrkoyrgwq0tq" + ], + "instances_after": [ + "j7awgfnedlt9ne1esywrappxx", + "xcgz2hubz1xrzmrkoyrgwq0tq" + ], + "confirmed_messages_checked": 1229, + "duplicate_bodies": 0 + }, + { + "action": "stop-one", + "target": "xcgz2hubz1xrzmrkoyrgwq0tq", + "duration_seconds": 15.467, + "successful_writes": 1091, + "failed_attempts": 7, + "successful_rps": 70.537, + "first_recovery_seconds": 1.384, + "max_success_gap_seconds": 1.057, + "instances_before": [ + "j7awgfnedlt9ne1esywrappxx", + "xcgz2hubz1xrzmrkoyrgwq0tq" + ], + "instances_after": [ + "5vy560hk6k0q3eicqodd9dp2z", + "j7awgfnedlt9ne1esywrappxx" + ], + "confirmed_messages_checked": 1251, + "duplicate_bodies": 0 + } + ], + "rolling_update": { + "action": "update", + "target": null, + "duration_seconds": 44.156, + "successful_writes": 3362, + "failed_attempts": 0, + "successful_rps": 76.139, + "first_recovery_seconds": null, + "max_success_gap_seconds": 0.152, + "instances_before": [ + "5vy560hk6k0q3eicqodd9dp2z", + "j7awgfnedlt9ne1esywrappxx" + ], + "instances_after": [ + "j201rqxerkxdq0vbcw3armc3m", + "uqyjmps3u9fyl976lpj944pc5" + ], + "confirmed_messages_checked": 3519, + "duplicate_bodies": 0 + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..7e3203b3 --- /dev/null +++ b/go.mod @@ -0,0 +1,42 @@ +module gitflic.ru/akselbant/mtusi2026lab1-fork + +go 1.26.4 + +require ( + github.com/google/uuid v1.6.0 + github.com/jackc/pgx/v5 v5.7.6 + github.com/labstack/echo/v4 v4.13.4 + github.com/minio/minio-go/v7 v7.0.95 + github.com/redis/go-redis/v9 v9.12.1 + github.com/swaggest/swgui v1.8.9 + golang.org/x/crypto v0.39.0 +) + +require ( + github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect + github.com/dustin/go-humanize v1.0.1 // indirect + github.com/go-ini/ini v1.67.0 // indirect + github.com/goccy/go-json v0.10.5 // indirect + github.com/jackc/pgpassfile v1.0.0 // indirect + github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect + github.com/jackc/puddle/v2 v2.2.2 // indirect + github.com/klauspost/compress v1.18.0 // indirect + github.com/klauspost/cpuid/v2 v2.2.11 // indirect + github.com/labstack/gommon v0.4.2 // indirect + github.com/mattn/go-colorable v0.1.14 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/minio/crc64nvme v1.0.2 // indirect + github.com/minio/md5-simd v1.1.2 // indirect + github.com/philhofer/fwd v1.2.0 // indirect + github.com/rs/xid v1.6.0 // indirect + github.com/tinylib/msgp v1.3.0 // indirect + github.com/valyala/bytebufferpool v1.0.0 // indirect + github.com/valyala/fasttemplate v1.2.2 // indirect + github.com/vearutop/statigz v1.4.0 // indirect + golang.org/x/net v0.41.0 // indirect + golang.org/x/sync v0.15.0 // indirect + golang.org/x/sys v0.33.0 // indirect + golang.org/x/text v0.26.0 // indirect + golang.org/x/time v0.11.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 00000000..f7913261 --- /dev/null +++ b/go.sum @@ -0,0 +1,90 @@ +github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= +github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= +github.com/bool64/dev v0.2.45 h1:3nLKhAS/6Oklk3Mt2lHYSN/Cb4tdAD77KLwzeP+6eYE= +github.com/bool64/dev v0.2.45/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg= +github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= +github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= +github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= +github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= +github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= +github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A= +github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= +github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= +github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= +github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgx/v5 v5.7.6 h1:rWQc5FwZSPX58r1OQmkuaNicxdmExaEz5A2DO2hUuTk= +github.com/jackc/pgx/v5 v5.7.6/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M= +github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo= +github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= +github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= +github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.11 h1:0OwqZRYI2rFrjS4kvkDnqJkKHdHaRnCm68/DY4OxRzU= +github.com/klauspost/cpuid/v2 v2.2.11/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= +github.com/labstack/echo/v4 v4.13.4 h1:oTZZW+T3s9gAu5L8vmzihV7/lkXGZuITzTQkTEhcXEA= +github.com/labstack/echo/v4 v4.13.4/go.mod h1:g63b33BZ5vZzcIUF8AtRH40DrTlXnx4UMC8rBdndmjQ= +github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0= +github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU= +github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= +github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/minio/crc64nvme v1.0.2 h1:6uO1UxGAD+kwqWWp7mBFsi5gAse66C4NXO8cmcVculg= +github.com/minio/crc64nvme v1.0.2/go.mod h1:eVfm2fAzLlxMdUGc0EEBGSMmPwmXD5XiNRpnu9J3bvg= +github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34= +github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM= +github.com/minio/minio-go/v7 v7.0.95 h1:ywOUPg+PebTMTzn9VDsoFJy32ZuARN9zhB+K3IYEvYU= +github.com/minio/minio-go/v7 v7.0.95/go.mod h1:wOOX3uxS334vImCNRVyIDdXX9OsXDm89ToynKgqUKlo= +github.com/philhofer/fwd v1.2.0 h1:e6DnBTl7vGY+Gz322/ASL4Gyp1FspeMvx1RNDoToZuM= +github.com/philhofer/fwd v1.2.0/go.mod h1:RqIHx9QI14HlwKwm98g9Re5prTQ6LdeRQn+gXJFxsJM= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/redis/go-redis/v9 v9.12.1 h1:k5iquqv27aBtnTm2tIkROUDp8JBXhXZIVu1InSgvovg= +github.com/redis/go-redis/v9 v9.12.1/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw= +github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU= +github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/swaggest/swgui v1.8.9 h1:cxAgIwouPpZPlvX68jY5fpwarzLbkc8/IL6DMj+H460= +github.com/swaggest/swgui v1.8.9/go.mod h1:eTJfgwudbyw9xMwqO26vs82ei2u6//JnUAofx2vGB3M= +github.com/tinylib/msgp v1.3.0 h1:ULuf7GPooDaIlbyvgAxBV/FI7ynli6LZ1/nVUNu+0ww= +github.com/tinylib/msgp v1.3.0/go.mod h1:ykjzy2wzgrlvpDCRc4LA8UXy6D8bzMSuAF3WD57Gok0= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo= +github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= +github.com/vearutop/statigz v1.4.0 h1:RQL0KG3j/uyA/PFpHeZ/L6l2ta920/MxlOAIGEOuwmU= +github.com/vearutop/statigz v1.4.0/go.mod h1:LYTolBLiz9oJISwiVKnOQoIwhO1LWX1A7OECawGS8XE= +golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM= +golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U= +golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw= +golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA= +golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8= +golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M= +golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA= +golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0= +golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/infra/README.md b/infra/README.md index 5a39e862..3504ad78 100644 --- a/infra/README.md +++ b/infra/README.md @@ -1,7 +1,24 @@ -# Инфраструктура студента +# Инфраструктура lab5 -Здесь разместите конфигурации выбранных сервисов; основную топологию — в корневом compose.yaml/stack.yaml. `compose.example.yaml` — только worksheet ролей и намеренно не запускается. `contracts/infrastructure.json` задаёт минимальные роли, не готовые образы/пароли. +HAProxy направляет HTTP в две API-реплики. +PostgreSQL хранит сообщения, метаданные, jobs, outbox и audit replay. +Redis хранит сессии и Streams с consumer group `image-workers-v1`. +Redis использует AOF и `appendfsync always`; Pub/Sub не используется. +MinIO хранит приватные staging и конечные варианты. Worker работает отдельным сервисом. -В REPORT.md сопоставьте роль → service name → версия/digest → health/readiness → volume → сеть/порт → способ передачи credentials. Приведите bootstrap (schema, bucket, broker topology, а с lab6 provisioning) и безопасное повторение этих команд. +Основной запуск: `make up`. API: http://localhost:18085. +Остановка с сохранением volumes: `make down`. +Compose запускает те же роли с одной API-репликой. +Скрипты не читают `.env`; bootstrap создаёт Docker secrets. +Redis имеет лимит памяти 384MiB и `maxmemory 256mb`, политика `noeviction`. +Worker имеет лимит 1CPU/1536MiB; API — по 1CPU/1536MiB. -Приложение строится из исходников. Не используйте заранее существующий образ преподавательского сервера вместо своей реализации. Restart hook перезапускает все соответствующие stores с volumes; failover hook останавливает только заданную API-реплику. +Миграции goose 005–010 добавляют состояния, jobs, outbox, audit и cleanup. +Миграция 009 переводит прежние оригиналы в устойчивый staging без потери байтов. +При обновлении API останавливаются перед миграциями, затем запускается новая версия. +Swarm configs Redis и S3 policy используют суффикс `_v5`. +Это позволяет обновить прежний стенд без изменения immutable configs. + +Порты PostgreSQL, Redis, MinIO и worker не опубликованы. +S3 policy разрешает API/worker только `original/*` и `staging/*` своего bucket. +Версии образов, протокол отказов и команды находятся в [REPORT.md](../REPORT.md). diff --git a/infra/haproxy.cfg b/infra/haproxy.cfg new file mode 100644 index 00000000..6a3fb1fd --- /dev/null +++ b/infra/haproxy.cfg @@ -0,0 +1,36 @@ +global + log stdout format raw local0 + maxconn 1024 + +defaults + log global + mode http + timeout connect 1s + timeout client 55s + timeout server 55s + timeout check 1s + retries 0 + option http-server-close + +resolvers docker + nameserver dns 127.0.0.11:53 + resolve_retries 3 + timeout resolve 1s + timeout retry 1s + hold valid 1s + hold obsolete 1s + hold nx 1s + hold refused 1s + hold timeout 1s + +frontend public + bind :8080 + default_backend api + +backend api + balance roundrobin + option httpchk + http-check send meth GET uri /health/ready ver HTTP/1.1 hdr Host api + http-check expect status 200 + default-server inter 1s fastinter 500ms downinter 1s fall 2 rise 1 + server-template replica 1-8 tasks.api:8080 check resolvers docker init-addr none diff --git a/infra/migrate.sh b/infra/migrate.sh new file mode 100755 index 00000000..70a11b2f --- /dev/null +++ b/infra/migrate.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -eu +# Keep the password out of argv and disable automatic dotenv loading. +if [ -n "${POSTGRES_PASSWORD_FILE:-}" ]; then + PGPASSWORD=$(cat "$POSTGRES_PASSWORD_FILE") + export PGPASSWORD +fi +exec goose -env /dev/null -dir /migrations -timeout 30s "$@" diff --git a/infra/minio-entrypoint.sh b/infra/minio-entrypoint.sh new file mode 100755 index 00000000..ba249937 --- /dev/null +++ b/infra/minio-entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/sh +set -eu +export MINIO_ROOT_USER="$(cat /run/secrets/s3_root_access_key)" +export MINIO_ROOT_PASSWORD="$(cat /run/secrets/s3_root_secret_key)" +exec minio server /data --address :9000 --console-address 127.0.0.1:9001 diff --git a/infra/redis.conf b/infra/redis.conf new file mode 100644 index 00000000..0b8eb4c4 --- /dev/null +++ b/infra/redis.conf @@ -0,0 +1,9 @@ +bind 0.0.0.0 +protected-mode no +port 6379 +dir /data +appendonly yes +appendfsync always +save "" +maxmemory 256mb +maxmemory-policy noeviction diff --git a/infra/s3-bootstrap.sh b/infra/s3-bootstrap.sh new file mode 100755 index 00000000..4251f8fd --- /dev/null +++ b/infra/s3-bootstrap.sh @@ -0,0 +1,11 @@ +#!/bin/sh +set -eu +export MC_CONFIG_DIR=/tmp/mc +mc alias set admin http://minio:9000 "$(cat /run/secrets/s3_root_access_key)" "$(cat /run/secrets/s3_root_secret_key)" >/dev/null +mc ready admin >/dev/null +mc mb --ignore-existing admin/attachments >/dev/null +mc anonymous set none admin/attachments >/dev/null +mc admin policy create admin attachments-api /policy.json >/dev/null +mc admin user add admin "$(cat /run/secrets/s3_access_key)" "$(cat /run/secrets/s3_secret_key)" >/dev/null +mc admin policy attach admin attachments-api --user "$(cat /run/secrets/s3_access_key)" >/dev/null +printf '%s\n' 'PASS: private bucket and restricted API account configured.' diff --git a/infra/s3-policy.json b/infra/s3-policy.json new file mode 100644 index 00000000..20797ca1 --- /dev/null +++ b/infra/s3-policy.json @@ -0,0 +1,21 @@ +{ + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": ["s3:GetBucketLocation"], + "Resource": ["arn:aws:s3:::attachments"] + }, + { + "Effect": "Allow", + "Action": ["s3:ListBucket"], + "Resource": ["arn:aws:s3:::attachments"], + "Condition": {"StringLike": {"s3:prefix": ["original/*", "staging/*"]}} + }, + { + "Effect": "Allow", + "Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"], + "Resource": ["arn:aws:s3:::attachments/original/*", "arn:aws:s3:::attachments/staging/*"] + } + ] +} diff --git a/infra/schema.md b/infra/schema.md new file mode 100644 index 00000000..9b214069 --- /dev/null +++ b/infra/schema.md @@ -0,0 +1,25 @@ +# Схема и транзакционные границы + +PostgreSQL — источник истины пользователей, чатов, участников и сообщений. +Redis — источник истины сессий: SHA-256 токена → user_id, expires_at; TTL до +абсолютного expires_at, без продления при чтении. Logout удаляет ключ. +Redis использует AOF с appendfsync always и отдельный именованный volume. + +- users: UUID PK, UNIQUE(username), password_hash (Argon2id), display_name, created_at. +- chats: UUID PK, title, created_at; индекс (created_at, id). +- chat_members: PK(chat_id, user_id), FK к chats/users; ordinal сохраняет порядок + участников; UNIQUE(chat_id, ordinal); индекс (user_id, chat_id). +- messages: UUID PK, FK chat_id/sender_id через членство; text, created_at. + Индекс (chat_id, created_at, id) отвечает равенству по чату и keyset-предикату + (created_at, id) > ($timestamp, $id), ORDER BY created_at, id LIMIT $limit. +- goose_db_version: журнал goose CLI; SQL-миграция и запись её версии + коммитятся в одной транзакции. Сервис migrations завершается до старта API. + +Регистрация — один INSERT, гонка разрешается UNIQUE, проигравшие получают 409. +Создание чата — одна транзакция: INSERT чата, затем участников; любой неверный +FK откатывает всю операцию, включая уже вставленных участников. +Отправка сообщения — один INSERT с FK на членство. Чтения идут в PostgreSQL, +кэша истории нет, подтверждённый COMMIT виден следующему запросу. +При конкурентной записи keyset не даёт snapshot: поздний COMMIT с ключом до +уже прочитанного cursor может быть пропущен. created_at задаёт PostgreSQL, +UUID разрешает совпадения времени; часы не используются как уникальный ID. diff --git a/internal/app/chat/access.go b/internal/app/chat/access.go new file mode 100644 index 00000000..36f71a5b --- /dev/null +++ b/internal/app/chat/access.go @@ -0,0 +1,31 @@ +package chat + +import ( + "errors" + + "github.com/labstack/echo/v4" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" +) + +func (h *Chat) authorizedChat(c echo.Context, requestedChat domain.Chat) (domain.Chat, bool, error) { + chat, err := h.useCase.GetChat(c.Request().Context(), authenticatedUser(c).ID, requestedChat) + if err != nil { + return domain.Chat{}, false, h.useCaseError(c, err) + } + return chat, true, nil +} + +func (h *Chat) cursorPosition(raw string, present bool, scope, owner string) (*domain.Position, error) { + if !present { + return nil, nil + } + if raw == "" { + return nil, errors.New("empty cursor") + } + createdAt, id, err := h.cursor.decode(raw, scope, owner) + if err != nil { + return nil, err + } + return &domain.Position{CreatedAt: createdAt, ID: id}, nil +} diff --git a/internal/app/chat/attachments.go b/internal/app/chat/attachments.go new file mode 100644 index 00000000..c345e177 --- /dev/null +++ b/internal/app/chat/attachments.go @@ -0,0 +1,75 @@ +package chat + +import ( + "context" + "mime" + "net/http" + "time" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/attachment" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" + "github.com/labstack/echo/v4" +) + +func (h *Chat) WithAttachments(service *attachment.Service) *Chat { h.attachments = service; return h } +func (h *Chat) uploadAttachment(c echo.Context) error { + chat, ok, err := h.authorizedChat(c, domain.Chat{ID: c.Param("chat_id")}) + if err != nil || !ok { + return err + } + filename, present, err := oneQueryValue(c, "filename") + if err != nil || !present { + return h.invalid(c, "Требуется один filename") + } + if c.Request().ContentLength > attachment.MaxBytes { + return h.writeError(c, 413, "payload_too_large", "Файл превышает 10 MiB") + } + // Both socket reads and the application operation have a fixed deadline. + deadline := time.Now().Add(attachment.UploadTimeout) + _ = http.NewResponseController(c.Response().Writer).SetReadDeadline(deadline) + defer http.NewResponseController(c.Response().Writer).SetReadDeadline(time.Time{}) + c.Request().Body = http.MaxBytesReader(c.Response(), c.Request().Body, attachment.MaxBytes+1) + a, err := h.attachments.Upload(c.Request().Context(), chat.ID, authenticatedUser(c).ID, filename, c.Request().Header.Get("Content-Type"), c.Request().Body) + if err != nil { + return h.useCaseError(c, err) + } + return c.JSON(http.StatusAccepted, a) +} +func (h *Chat) getAttachment(c echo.Context) error { + a, err := h.attachments.Get(c.Request().Context(), c.Param("attachment_id"), authenticatedUser(c).ID) + if err != nil { + return h.useCaseError(c, err) + } + return c.JSON(http.StatusOK, a) +} +func (h *Chat) attachmentContent(c echo.Context) error { + a, err := h.attachments.Get(c.Request().Context(), c.Param("attachment_id"), authenticatedUser(c).ID) + if err != nil { + return h.useCaseError(c, err) + } + variant, present, err := oneQueryValue(c, "variant") + if err != nil { + return h.invalid(c, "Некорректный variant") + } + if a.Status != "ready" { + return h.writeError(c, 409, "conflict", "Вложение не готово") + } + if !present { + variant = "original" + } + a, err = h.attachments.Variant(a, variant) + if err != nil { + return h.useCaseError(c, err) + } + ctx, cancel := context.WithTimeout(c.Request().Context(), 45*time.Second) + defer cancel() + obj, err := h.attachments.Content(ctx, a) + if err != nil { + return h.useCaseError(c, err) + } + defer obj.Close() + c.Response().Header().Set("Content-Disposition", mime.FormatMediaType("attachment", map[string]string{"filename": a.Filename})) + c.Response().Header().Set("X-Content-Type-Options", "nosniff") + c.Response().Header().Set("Cache-Control", "private, no-store") + return c.Stream(http.StatusOK, a.ContentType, obj) +} diff --git a/internal/app/chat/create_chat.go b/internal/app/chat/create_chat.go new file mode 100644 index 00000000..7e57b2e5 --- /dev/null +++ b/internal/app/chat/create_chat.go @@ -0,0 +1,33 @@ +package chat + +import ( + "net/http" + + "github.com/labstack/echo/v4" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/dto" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" +) + +func (h *Chat) createChat(c echo.Context) error { + var request dto.CreateChatRequest + if err := decodeJSON(c, &request); err != nil { + return h.jsonError(c, err) + } + callerID := authenticatedUser(c).ID + chat, err := h.useCase.CreateChat(c.Request().Context(), callerID, createChatRequestToDomain(request)) + if err != nil { + return h.useCaseError(c, err) + } + return c.JSON(http.StatusCreated, createChatResponseFromDomain(chat)) +} + +func createChatRequestToDomain(request dto.CreateChatRequest) domain.Chat { + return domain.Chat{Title: request.Title, MemberIDs: request.MemberIDs} +} + +func createChatResponseFromDomain(chat domain.Chat) dto.CreateChatResponse { + return dto.CreateChatResponse{ + ID: chat.ID, Title: chat.Title, MemberIDs: chat.MemberIDs, CreatedAt: dto.Timestamp(chat.CreatedAt), + } +} diff --git a/internal/app/chat/create_message.go b/internal/app/chat/create_message.go new file mode 100644 index 00000000..3c0c27b7 --- /dev/null +++ b/internal/app/chat/create_message.go @@ -0,0 +1,58 @@ +package chat + +import ( + "net/http" + "regexp" + + "github.com/labstack/echo/v4" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/dto" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" +) + +var idempotencyKeyPattern = regexp.MustCompile(`^[A-Za-z0-9._:-]{1,128}$`) + +func (h *Chat) createMessage(c echo.Context) error { + request := dto.CreateMessageRequest{ChatID: c.Param("chat_id")} + chat, ok, err := h.authorizedChat(c, domain.Chat{ID: request.ChatID}) + if err != nil { + return err + } + if !ok { + return nil + } + if err := decodeJSON(c, &request); err != nil { + return h.jsonError(c, err) + } + request.ChatID = chat.ID + + keys := c.Request().Header.Values("Idempotency-Key") + if len(keys) != 1 || !idempotencyKeyPattern.MatchString(keys[0]) { + return h.invalid(c, "Требуется Idempotency-Key: ASCII [A-Za-z0-9._:-]{1,128}") + } + input := createMessageRequestToDomain(request) + input.IdempotencyKey = keys[0] + message, err := h.useCase.CreateMessage(c.Request().Context(), authenticatedUser(c).ID, input) + if err != nil { + return h.useCaseError(c, err) + } + return c.JSON(http.StatusCreated, createMessageResponseFromDomain(message)) +} + +func createMessageRequestToDomain(request dto.CreateMessageRequest) domain.Message { + return domain.Message{ChatID: request.ChatID, Text: request.Text, AttachmentIDs: request.AttachmentIDs} +} + +func createMessageResponseFromDomain(message domain.Message) dto.CreateMessageResponse { + return dto.CreateMessageResponse{ + ID: message.ID, ChatID: message.ChatID, SenderID: message.SenderID, + Text: message.Text, AttachmentIDs: nonnilIDs(message.AttachmentIDs), CreatedAt: dto.Timestamp(message.CreatedAt), + } +} + +func nonnilIDs(ids []string) []string { + if ids == nil { + return []string{} + } + return ids +} diff --git a/internal/app/chat/create_user.go b/internal/app/chat/create_user.go new file mode 100644 index 00000000..f6078178 --- /dev/null +++ b/internal/app/chat/create_user.go @@ -0,0 +1,32 @@ +package chat + +import ( + "net/http" + + "github.com/labstack/echo/v4" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/dto" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" +) + +func (h *Chat) createUser(c echo.Context) error { + var request dto.CreateUserRequest + if err := decodeJSON(c, &request); err != nil { + return h.jsonError(c, err) + } + user, err := h.useCase.CreateUser(c.Request().Context(), createUserRequestToDomain(request), request.Password) + if err != nil { + return h.useCaseError(c, err) + } + return c.JSON(http.StatusCreated, createUserResponseFromDomain(user)) +} + +func createUserRequestToDomain(request dto.CreateUserRequest) domain.User { + return domain.User{Username: request.Username, DisplayName: request.DisplayName} +} + +func createUserResponseFromDomain(user domain.User) dto.CreateUserResponse { + return dto.CreateUserResponse{ + ID: user.ID, Username: user.Username, DisplayName: user.DisplayName, CreatedAt: dto.Timestamp(user.CreatedAt), + } +} diff --git a/internal/app/chat/current_user.go b/internal/app/chat/current_user.go new file mode 100644 index 00000000..23277dea --- /dev/null +++ b/internal/app/chat/current_user.go @@ -0,0 +1,21 @@ +package chat + +import ( + "net/http" + + "github.com/labstack/echo/v4" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/dto" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" +) + +func (h *Chat) currentUser(c echo.Context) error { + user := authenticatedUser(c) + return c.JSON(http.StatusOK, currentUserResponseFromDomain(user)) +} + +func currentUserResponseFromDomain(user domain.User) dto.CurrentUserResponse { + return dto.CurrentUserResponse{ + ID: user.ID, Username: user.Username, DisplayName: user.DisplayName, CreatedAt: dto.Timestamp(user.CreatedAt), + } +} diff --git a/internal/app/chat/cursor.go b/internal/app/chat/cursor.go new file mode 100644 index 00000000..83836f11 --- /dev/null +++ b/internal/app/chat/cursor.go @@ -0,0 +1,75 @@ +package chat + +import ( + "crypto/hmac" + "crypto/sha256" + "encoding/base64" + "encoding/json" + "errors" + "strings" + "time" + + "github.com/google/uuid" +) + +type cursorPayload struct { + Scope string `json:"scope"` + Owner string `json:"owner"` + CreatedAt string `json:"created_at"` + ID string `json:"id"` +} + +type cursorCodec struct { + secret [32]byte +} + +func (c cursorCodec) encode(scope, owner string, createdAt time.Time, id string) string { + payload, err := json.Marshal(cursorPayload{ + Scope: scope, + Owner: owner, + CreatedAt: createdAt.UTC().Format(time.RFC3339Nano), + ID: id, + }) + if err != nil { + panic("cannot encode cursor: " + err.Error()) + } + signature := c.sign(payload) + return base64.RawURLEncoding.EncodeToString(payload) + "." + base64.RawURLEncoding.EncodeToString(signature) +} + +func (c cursorCodec) decode(raw, scope, owner string) (time.Time, string, error) { + parts := strings.Split(raw, ".") + if len(parts) != 2 { + return time.Time{}, "", errors.New("malformed cursor") + } + payload, err := base64.RawURLEncoding.DecodeString(parts[0]) + if err != nil { + return time.Time{}, "", errors.New("malformed cursor") + } + signature, err := base64.RawURLEncoding.DecodeString(parts[1]) + if err != nil || !hmac.Equal(signature, c.sign(payload)) { + return time.Time{}, "", errors.New("invalid cursor signature") + } + var value cursorPayload + if err := json.Unmarshal(payload, &value); err != nil { + return time.Time{}, "", errors.New("malformed cursor payload") + } + if value.Scope != scope || value.Owner != owner { + return time.Time{}, "", errors.New("cursor belongs to another resource") + } + parsedID, err := uuid.Parse(value.ID) + if err != nil || parsedID.String() != value.ID { + return time.Time{}, "", errors.New("malformed cursor id") + } + createdAt, err := time.Parse(time.RFC3339Nano, value.CreatedAt) + if err != nil { + return time.Time{}, "", errors.New("malformed cursor timestamp") + } + return createdAt, value.ID, nil +} + +func (c cursorCodec) sign(payload []byte) []byte { + mac := hmac.New(sha256.New, c.secret[:]) + _, _ = mac.Write(payload) + return mac.Sum(nil) +} diff --git a/internal/app/chat/errors.go b/internal/app/chat/errors.go new file mode 100644 index 00000000..7c532f81 --- /dev/null +++ b/internal/app/chat/errors.go @@ -0,0 +1,98 @@ +package chat + +import ( + "errors" + "net/http" + + "github.com/google/uuid" + "github.com/labstack/echo/v4" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/dto" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" +) + +func (h *Chat) invalid(c echo.Context, message string) error { + return h.writeError(c, http.StatusBadRequest, "invalid_request", message) +} + +func (h *Chat) jsonError(c echo.Context, err error) error { + if errors.Is(err, errUnsupportedMediaType) { + return h.writeError(c, http.StatusUnsupportedMediaType, "unsupported_media_type", "Content-Type должен быть application/json") + } + var tooLarge *http.MaxBytesError + if errors.As(err, &tooLarge) { + return h.writeError(c, http.StatusRequestEntityTooLarge, "payload_too_large", "Тело запроса слишком большое") + } + return h.invalid(c, err.Error()) +} + +func (h *Chat) useCaseError(c echo.Context, err error) error { + applicationError, ok := domain.AsApplicationError(err) + if !ok { + return err + } + status := http.StatusInternalServerError + switch applicationError.Code { + case "unsupported_media_type": + status = http.StatusUnsupportedMediaType + case "rate_limited": + status = http.StatusTooManyRequests + c.Response().Header().Set("Retry-After", "2") + case "payload_too_large": + status = http.StatusRequestEntityTooLarge + case domain.ErrorUnavailable: + status = http.StatusServiceUnavailable + case domain.ErrorInvalid: + status = http.StatusBadRequest + case domain.ErrorUnauthorized: + status = http.StatusUnauthorized + challenge := `Bearer realm="messenger"` + if c.Path() == "/api/v1/auth/sessions" { + challenge = `Basic realm="messenger", charset="UTF-8"` + } + c.Response().Header().Set("WWW-Authenticate", challenge) + case domain.ErrorNotFound: + status = http.StatusNotFound + case domain.ErrorConflict: + status = http.StatusConflict + } + return h.writeError(c, status, string(applicationError.Code), applicationError.Message) +} + +func (h *Chat) writeError(c echo.Context, status int, code, message string) error { + return c.JSON(status, dto.ErrorResponse{Error: dto.ErrorDetails{ + Code: code, + Message: message, + RequestID: requestID(c), + }}) +} + +func (h *Chat) httpErrorHandler(err error, c echo.Context) { + if c.Response().Committed { + return + } + status := http.StatusInternalServerError + code := "internal_error" + message := "Внутренняя ошибка сервера" + var httpError *echo.HTTPError + if errors.As(err, &httpError) { + status = httpError.Code + switch status { + case http.StatusNotFound: + code, message = "not_found", "Объект не найден" + case http.StatusMethodNotAllowed, http.StatusBadRequest: + code, message = "invalid_request", "Некорректный запрос" + } + } + _ = h.writeError(c, status, code, message) +} + +func requestID(c echo.Context) string { + value, _ := c.Get(requestIDKey).(string) + if value == "" { + value = uuid.NewString() + c.Set(requestIDKey, value) + c.Response().Header().Set("X-Request-Id", value) + } + return value +} diff --git a/internal/app/chat/get_chat.go b/internal/app/chat/get_chat.go new file mode 100644 index 00000000..eaddd9eb --- /dev/null +++ b/internal/app/chat/get_chat.go @@ -0,0 +1,32 @@ +package chat + +import ( + "net/http" + + "github.com/labstack/echo/v4" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/dto" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" +) + +func (h *Chat) getChat(c echo.Context) error { + request := dto.GetChatRequest{ChatID: c.Param("chat_id")} + chat, ok, err := h.authorizedChat(c, getChatRequestToDomain(request)) + if err != nil { + return err + } + if !ok { + return nil + } + return c.JSON(http.StatusOK, getChatResponseFromDomain(chat)) +} + +func getChatRequestToDomain(request dto.GetChatRequest) domain.Chat { + return domain.Chat{ID: request.ChatID} +} + +func getChatResponseFromDomain(chat domain.Chat) dto.GetChatResponse { + return dto.GetChatResponse{ + ID: chat.ID, Title: chat.Title, MemberIDs: chat.MemberIDs, CreatedAt: dto.Timestamp(chat.CreatedAt), + } +} diff --git a/internal/app/chat/list_chats.go b/internal/app/chat/list_chats.go new file mode 100644 index 00000000..1a02d5fa --- /dev/null +++ b/internal/app/chat/list_chats.go @@ -0,0 +1,53 @@ +package chat + +import ( + "net/http" + + "github.com/labstack/echo/v4" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/dto" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" +) + +func (h *Chat) listChats(c echo.Context) error { + limit, err := parseLimit(c) + if err != nil { + return h.invalid(c, err.Error()) + } + rawCursor, cursorPresent, err := oneQueryValue(c, "cursor") + if err != nil { + return h.invalid(c, "cursor должен быть указан один раз") + } + request := dto.ListChatsRequest{Limit: limit, Cursor: rawCursor} + userID := authenticatedUser(c).ID + position, err := h.cursorPosition(request.Cursor, cursorPresent, "chats", userID) + if err != nil { + return h.invalid(c, "Некорректный cursor") + } + + page, err := h.useCase.ListChats(c.Request().Context(), userID, listChatsRequestToDomain(request, position)) + if err != nil { + return h.useCaseError(c, err) + } + var next *string + if page.HasMore { + last := page.Items[len(page.Items)-1] + encoded := h.cursor.encode("chats", userID, last.CreatedAt, last.ID) + next = &encoded + } + return c.JSON(http.StatusOK, listChatsResponseFromDomain(page, next)) +} + +func listChatsRequestToDomain(request dto.ListChatsRequest, position *domain.Position) domain.Pagination { + return domain.Pagination{After: position, Limit: request.Limit} +} + +func listChatsResponseFromDomain(page domain.ChatPage, nextCursor *string) dto.ListChatsResponse { + items := make([]dto.ListChatsItem, 0, len(page.Items)) + for _, chat := range page.Items { + items = append(items, dto.ListChatsItem{ + ID: chat.ID, Title: chat.Title, MemberIDs: chat.MemberIDs, CreatedAt: dto.Timestamp(chat.CreatedAt), + }) + } + return dto.ListChatsResponse{Items: items, NextCursor: nextCursor} +} diff --git a/internal/app/chat/list_messages.go b/internal/app/chat/list_messages.go new file mode 100644 index 00000000..1d7f2520 --- /dev/null +++ b/internal/app/chat/list_messages.go @@ -0,0 +1,70 @@ +package chat + +import ( + "net/http" + + "github.com/labstack/echo/v4" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/dto" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" +) + +func (h *Chat) listMessages(c echo.Context) error { + request := dto.ListMessagesRequest{ChatID: c.Param("chat_id")} + chat, ok, err := h.authorizedChat(c, domain.Chat{ID: request.ChatID}) + if err != nil { + return err + } + if !ok { + return nil + } + limit, err := parseLimit(c) + if err != nil { + return h.invalid(c, err.Error()) + } + rawCursor, cursorPresent, err := oneQueryValue(c, "cursor") + if err != nil { + return h.invalid(c, "cursor должен быть указан один раз") + } + request.ChatID = chat.ID + request.Limit = limit + request.Cursor = rawCursor + position, err := h.cursorPosition(request.Cursor, cursorPresent, "messages", request.ChatID) + if err != nil { + return h.invalid(c, "Некорректный cursor") + } + + page, err := h.useCase.ListMessages( + c.Request().Context(), authenticatedUser(c).ID, + listMessagesChatToDomain(request), listMessagesPaginationToDomain(request, position), + ) + if err != nil { + return h.useCaseError(c, err) + } + var next *string + if page.HasMore { + last := page.Items[len(page.Items)-1] + encoded := h.cursor.encode("messages", request.ChatID, last.CreatedAt, last.ID) + next = &encoded + } + return c.JSON(http.StatusOK, listMessagesResponseFromDomain(page, next)) +} + +func listMessagesChatToDomain(request dto.ListMessagesRequest) domain.Chat { + return domain.Chat{ID: request.ChatID} +} + +func listMessagesPaginationToDomain(request dto.ListMessagesRequest, position *domain.Position) domain.Pagination { + return domain.Pagination{After: position, Limit: request.Limit} +} + +func listMessagesResponseFromDomain(page domain.MessagePage, nextCursor *string) dto.ListMessagesResponse { + items := make([]dto.ListMessagesItem, 0, len(page.Items)) + for _, message := range page.Items { + items = append(items, dto.ListMessagesItem{ + ID: message.ID, ChatID: message.ChatID, SenderID: message.SenderID, + Text: message.Text, AttachmentIDs: nonnilIDs(message.AttachmentIDs), CreatedAt: dto.Timestamp(message.CreatedAt), + }) + } + return dto.ListMessagesResponse{Items: items, NextCursor: nextCursor} +} diff --git a/internal/app/chat/liveness.go b/internal/app/chat/liveness.go new file mode 100644 index 00000000..6b6029f9 --- /dev/null +++ b/internal/app/chat/liveness.go @@ -0,0 +1,13 @@ +package chat + +import ( + "net/http" + + "github.com/labstack/echo/v4" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/dto" +) + +func (h *Chat) liveness(c echo.Context) error { + return c.JSON(http.StatusOK, dto.LivenessResponse{Status: "ok"}) +} diff --git a/internal/app/chat/middleware.go b/internal/app/chat/middleware.go new file mode 100644 index 00000000..353b517c --- /dev/null +++ b/internal/app/chat/middleware.go @@ -0,0 +1,43 @@ +package chat + +import ( + "net/http" + + "github.com/google/uuid" + "github.com/labstack/echo/v4" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" +) + +const ( + requestIDKey = "request_id" + userKey = "current_user" +) + +func (h *Chat) requestIDMiddleware(next echo.HandlerFunc) echo.HandlerFunc { + return func(c echo.Context) error { + requestID := uuid.NewString() + c.Set(requestIDKey, requestID) + c.Response().Header().Set("X-Request-Id", requestID) + c.Response().Header().Set("X-Instance-Id", h.instanceID) + if h.draining.Load() && c.Request().URL.Path != "/health/live" { + return h.writeError(c, http.StatusServiceUnavailable, "unavailable", "Реплика завершает работу") + } + return next(c) + } +} + +func (h *Chat) authenticate(next echo.HandlerFunc) echo.HandlerFunc { + return func(c echo.Context) error { + user, err := h.useCase.Authenticate(c.Request().Context(), bearerToken(c)) + if err != nil { + return h.useCaseError(c, err) + } + c.Set(userKey, user) + return next(c) + } +} + +func authenticatedUser(c echo.Context) domain.User { + return c.Get(userKey).(domain.User) +} diff --git a/internal/app/chat/readiness.go b/internal/app/chat/readiness.go new file mode 100644 index 00000000..950ca172 --- /dev/null +++ b/internal/app/chat/readiness.go @@ -0,0 +1,25 @@ +package chat + +import ( + "context" + "net/http" + "time" + + "github.com/labstack/echo/v4" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/dto" +) + +func (h *Chat) readiness(c echo.Context) error { + ctx, cancel := context.WithTimeout(c.Request().Context(), 2*time.Second) + defer cancel() + if err := h.useCase.Ready(ctx); err != nil { + return h.useCaseError(c, err) + } + if h.attachments != nil { + if err := h.attachments.Ready(ctx); err != nil { + return h.useCaseError(c, err) + } + } + return c.JSON(http.StatusOK, dto.ReadinessResponse{Status: "ok"}) +} diff --git a/internal/app/chat/request.go b/internal/app/chat/request.go new file mode 100644 index 00000000..2cb05d4d --- /dev/null +++ b/internal/app/chat/request.go @@ -0,0 +1,74 @@ +package chat + +import ( + "encoding/json" + "errors" + "fmt" + "io" + "mime" + "net/http" + "strconv" + + "github.com/labstack/echo/v4" +) + +const ( + defaultLimit = 50 + maxLimit = 100 + maxJSONBody = 1 << 20 +) + +var errUnsupportedMediaType = errors.New("unsupported media type") + +func decodeJSON(c echo.Context, target any) error { + mediaType, _, err := mime.ParseMediaType(c.Request().Header.Get(echo.HeaderContentType)) + if err != nil || mediaType != echo.MIMEApplicationJSON { + return errUnsupportedMediaType + } + reader := http.MaxBytesReader(c.Response(), c.Request().Body, maxJSONBody) + decoder := json.NewDecoder(reader) + decoder.DisallowUnknownFields() + if err := decoder.Decode(target); err != nil { + var tooLarge *http.MaxBytesError + if errors.As(err, &tooLarge) { + return err + } + return errors.New("Некорректное JSON-тело") + } + var extra any + err = decoder.Decode(&extra) + var tooLarge *http.MaxBytesError + if errors.As(err, &tooLarge) { + return err + } + if !errors.Is(err, io.EOF) { + return errors.New("JSON-тело должно содержать ровно один объект") + } + return nil +} + +func parseLimit(c echo.Context) (int, error) { + raw, present, err := oneQueryValue(c, "limit") + if err != nil { + return 0, errors.New("limit должен быть указан один раз") + } + if !present { + return defaultLimit, nil + } + limit, err := strconv.Atoi(raw) + if err != nil || limit < 1 || limit > maxLimit { + return 0, fmt.Errorf("limit должен быть целым числом от 1 до %d", maxLimit) + } + return limit, nil +} + +func oneQueryValue(c echo.Context, name string) (string, bool, error) { + values, present := c.QueryParams()[name] + if !present { + return "", false, nil + } + if len(values) != 1 { + return "", true, errors.New("query parameter must occur once") + } + return values[0], true, nil +} diff --git a/internal/app/chat/service.go b/internal/app/chat/service.go new file mode 100644 index 00000000..0e4115c0 --- /dev/null +++ b/internal/app/chat/service.go @@ -0,0 +1,93 @@ +package chat + +import ( + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/attachment" + "log" + "os" + "sync/atomic" + + "github.com/google/uuid" + "github.com/labstack/echo/v4" + "github.com/labstack/echo/v4/middleware" + "github.com/swaggest/swgui/v5emb" +) + +// Chat is the HTTP handler and depends only on the application boundary. +type Chat struct { + attachments *attachment.Service + instanceID string + draining atomic.Bool + useCase UseCase + cursor cursorCodec +} + +func NewChat(useCase UseCase, cursorKey [32]byte) *Chat { + instanceID := os.Getenv("INSTANCE_ID") + if instanceID == "" { + instanceID = uuid.NewString() + } + return &Chat{useCase: useCase, cursor: cursorCodec{secret: cursorKey}, instanceID: instanceID} +} + +func (h *Chat) Drain() { h.draining.Store(true) } + +func (h *Chat) Router() *echo.Echo { + e := echo.New() + e.HideBanner = true + e.HidePort = true + e.HTTPErrorHandler = h.httpErrorHandler + e.Use(h.requestIDMiddleware) + e.Use(middleware.RequestLoggerWithConfig(middleware.RequestLoggerConfig{ + HandleError: true, + LogLatency: true, + LogMethod: true, + LogRoutePath: true, + LogURIPath: true, + LogRequestID: true, + LogStatus: true, + LogResponseSize: true, + LogValuesFunc: func(_ echo.Context, values middleware.RequestLoggerValues) error { + path := values.RoutePath + if path == "" { + path = values.URIPath + } + log.Printf( + "request_id=%s method=%s path=%s status=%d response_bytes=%d latency=%s", + values.RequestID, values.Method, path, values.Status, values.ResponseSize, values.Latency, + ) + return nil + }, + })) + e.Use(middleware.Recover()) + + e.GET("/health/live", h.liveness) + e.GET("/health/ready", h.readiness) + swaggerUI := echo.WrapHandler(v5emb.New( + "MTUSI Messenger", + "/swagger/openapi.json", + "/swagger/", + )) + e.GET("/swagger", h.swagger) + e.GET("/swagger/", swaggerUI) + e.GET("/swagger/openapi.json", h.swaggerSpec) + e.GET("/swagger/*", swaggerUI) + e.POST("/api/v1/users", h.createUser) + + e.POST("/api/v1/auth/sessions", h.createSession) + + api := e.Group("/api/v1", h.authenticate) + api.GET("/users/me", h.currentUser) + api.DELETE("/auth/sessions/current", h.deleteSession) + api.POST("/chats", h.createChat) + api.GET("/chats", h.listChats) + api.GET("/chats/:chat_id", h.getChat) + api.POST("/chats/:chat_id/messages", h.createMessage) + api.GET("/chats/:chat_id/messages", h.listMessages) + if h.attachments != nil { + api.POST("/chats/:chat_id/attachments", h.uploadAttachment) + api.GET("/attachments/:attachment_id", h.getAttachment) + api.GET("/attachments/:attachment_id/content", h.attachmentContent) + } + + return e +} diff --git a/internal/app/chat/service_test.go b/internal/app/chat/service_test.go new file mode 100644 index 00000000..bf582c2c --- /dev/null +++ b/internal/app/chat/service_test.go @@ -0,0 +1,353 @@ +package chat_test + +import ( + "bytes" + "context" + "encoding/base64" + "encoding/json" + "fmt" + "io" + "net/http" + "net/http/httptest" + "net/url" + "sync" + "testing" + "time" + + "github.com/google/uuid" + + chathandler "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/app/chat" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/repository" + chatusecase "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/usecase/chat" +) + +type testAPI struct { + server *httptest.Server + tokens sync.Map +} + +type userResponse struct { + ID string `json:"id"` +} + +type chatResponse struct { + ID string `json:"id"` +} + +type messageResponse struct { + ID string `json:"id"` + Text string `json:"text"` +} + +type messagePageResponse struct { + Items []messageResponse `json:"items"` + NextCursor *string `json:"next_cursor"` +} + +type errorResponse struct { + Error struct { + Code string `json:"code"` + } `json:"error"` +} + +func newTestAPI(t *testing.T) *testAPI { + t.Helper() + useCase := chatusecase.New(repository.NewMemory(), &testSessions{values: map[string]domain.Session{}}, time.Hour) + server := httptest.NewServer(chathandler.NewChat(useCase, [32]byte{1}).Router()) + t.Cleanup(server.Close) + return &testAPI{server: server} +} + +func (a *testAPI) request(t *testing.T, client *http.Client, method, path, actorID, body string, wantStatus int, target any) { + t.Helper() + request, err := http.NewRequest(method, a.server.URL+path, bytes.NewBufferString(body)) + if err != nil { + t.Fatalf("create request: %v", err) + } + if body != "" { + request.Header.Set("Content-Type", "application/json") + request.Header.Set("Idempotency-Key", uuid.NewString()) + } + if actorID != "" { + token, _ := a.tokens.Load(actorID) + request.Header.Set("Authorization", "Bearer "+token.(string)) + } + response, err := client.Do(request) + if err != nil { + t.Fatalf("%s %s: %v", method, path, err) + } + defer response.Body.Close() + responseBody, err := io.ReadAll(response.Body) + if err != nil { + t.Fatalf("read response: %v", err) + } + if response.StatusCode != wantStatus { + t.Fatalf("%s %s: status=%d, want=%d, body=%s", method, path, response.StatusCode, wantStatus, responseBody) + } + if response.Header.Get("X-Request-Id") == "" { + t.Fatalf("%s %s: missing X-Request-Id", method, path) + } + if target != nil { + if err := json.Unmarshal(responseBody, target); err != nil { + t.Fatalf("decode response %q: %v", responseBody, err) + } + } +} + +func (a *testAPI) createUser(t *testing.T, username string) userResponse { + t.Helper() + var user userResponse + a.request(t, http.DefaultClient, http.MethodPost, "/api/v1/users", "", + fmt.Sprintf(`{"username":%q,"display_name":%q,"password":"test-password-12345"}`, username, username), http.StatusCreated, &user) + req, err := http.NewRequest(http.MethodPost, a.server.URL+"/api/v1/auth/sessions", nil) + if err != nil { + t.Fatal(err) + } + req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(username+":test-password-12345"))) + response, err := http.DefaultClient.Do(req) + if err != nil { + t.Fatal(err) + } + defer response.Body.Close() + var login struct { + Token string `json:"token"` + } + if response.StatusCode != http.StatusCreated { + t.Fatalf("login status: %d", response.StatusCode) + } + if err = json.NewDecoder(response.Body).Decode(&login); err != nil { + t.Fatal(err) + } + a.tokens.Store(user.ID, login.Token) + return user +} + +func (a *testAPI) requestError(t *testing.T, method, path, actorID, body string, wantStatus int, wantCode string) { + t.Helper() + var response errorResponse + a.request(t, http.DefaultClient, method, path, actorID, body, wantStatus, &response) + if response.Error.Code != wantCode { + t.Fatalf("%s %s: error code=%q, want=%q", method, path, response.Error.Code, wantCode) + } +} + +func (a *testAPI) createChat(t *testing.T, ownerID string, memberIDs []string) chatResponse { + t.Helper() + body, err := json.Marshal(map[string]any{"title": "test chat", "member_ids": memberIDs}) + if err != nil { + t.Fatalf("encode chat: %v", err) + } + var chat chatResponse + a.request(t, http.DefaultClient, http.MethodPost, "/api/v1/chats", ownerID, string(body), http.StatusCreated, &chat) + return chat +} + +func (a *testAPI) createMessage(t *testing.T, client *http.Client, actorID, chatID, text string) messageResponse { + t.Helper() + body, err := json.Marshal(map[string]string{"text": text}) + if err != nil { + t.Fatalf("encode message: %v", err) + } + var message messageResponse + a.request(t, client, http.MethodPost, "/api/v1/chats/"+chatID+"/messages", actorID, string(body), http.StatusCreated, &message) + return message +} + +func TestRejectsMalformedJSON(t *testing.T) { + api := newTestAPI(t) + api.requestError(t, http.MethodPost, "/api/v1/users", "", + `{"username":`, http.StatusBadRequest, "invalid_request") +} + +func TestHidesForeignChat(t *testing.T) { + api := newTestAPI(t) + owner := api.createUser(t, "owner_user") + outsider := api.createUser(t, "outsider_user") + chat := api.createChat(t, owner.ID, []string{owner.ID}) + api.requestError(t, http.MethodGet, "/api/v1/chats/"+chat.ID, outsider.ID, + "", http.StatusNotFound, "not_found") +} + +func TestRejectsEmptyMessage(t *testing.T) { + api := newTestAPI(t) + user := api.createUser(t, "empty_message_user") + chat := api.createChat(t, user.ID, []string{user.ID}) + api.requestError(t, http.MethodPost, "/api/v1/chats/"+chat.ID+"/messages", user.ID, + `{"text":" "}`, http.StatusBadRequest, "invalid_request") +} + +func TestRejectsDuplicateUsername(t *testing.T) { + api := newTestAPI(t) + api.createUser(t, "duplicate_user") + api.requestError(t, http.MethodPost, "/api/v1/users", "", + `{"username":"duplicate_user","display_name":"Duplicate","password":"test-password-12345"}`, http.StatusConflict, "conflict") +} + +func TestPaginatesMessagesAcrossMultiplePages(t *testing.T) { + api := newTestAPI(t) + user := api.createUser(t, "pagination_user") + chat := api.createChat(t, user.ID, []string{user.ID}) + for index := 0; index < 7; index++ { + api.createMessage(t, http.DefaultClient, user.ID, chat.ID, fmt.Sprintf("message-%d", index)) + } + + seen := make(map[string]struct{}) + cursor := "" + pageSizes := make([]int, 0, 4) + for { + path := "/api/v1/chats/" + chat.ID + "/messages?limit=2" + if cursor != "" { + path += "&cursor=" + url.QueryEscape(cursor) + } + var page messagePageResponse + api.request(t, http.DefaultClient, http.MethodGet, path, user.ID, "", http.StatusOK, &page) + pageSizes = append(pageSizes, len(page.Items)) + for _, message := range page.Items { + if _, duplicate := seen[message.ID]; duplicate { + t.Fatalf("message %s appeared on multiple pages", message.ID) + } + seen[message.ID] = struct{}{} + } + if page.NextCursor == nil { + break + } + cursor = *page.NextCursor + } + if len(seen) != 7 { + t.Fatalf("received %d unique messages, want 7", len(seen)) + } + wantPageSizes := []int{2, 2, 2, 1} + if fmt.Sprint(pageSizes) != fmt.Sprint(wantPageSizes) { + t.Fatalf("page sizes=%v, want=%v", pageSizes, wantPageSizes) + } +} + +func TestConcurrentMessagesAreUnique(t *testing.T) { + api := newTestAPI(t) + + users := make([]userResponse, 10) + memberIDs := make([]string, 10) + for index := range users { + users[index] = api.createUser(t, fmt.Sprintf("parallel_user_%02d", index)) + memberIDs[index] = users[index].ID + } + chat := api.createChat(t, users[0].ID, memberIDs) + + start := make(chan struct{}) + errors := make(chan error, 10) + var waitGroup sync.WaitGroup + + for clientIndex := 0; clientIndex < 10; clientIndex++ { + waitGroup.Add(1) + go func(clientIndex int) { + defer waitGroup.Done() + client := &http.Client{Transport: &http.Transport{}, Timeout: 5 * time.Second} + defer client.CloseIdleConnections() + <-start + for messageIndex := 0; messageIndex < 10; messageIndex++ { + body, err := json.Marshal(map[string]string{ + "text": fmt.Sprintf("client-%02d-message-%02d", clientIndex, messageIndex), + }) + if err != nil { + errors <- err + return + } + request, err := http.NewRequest(http.MethodPost, + api.server.URL+"/api/v1/chats/"+chat.ID+"/messages", bytes.NewReader(body)) + if err != nil { + errors <- err + return + } + request.Header.Set("Content-Type", "application/json") + request.Header.Set("Idempotency-Key", uuid.NewString()) + token, _ := api.tokens.Load(users[clientIndex].ID) + request.Header.Set("Authorization", "Bearer "+token.(string)) + response, err := client.Do(request) + if err != nil { + errors <- err + return + } + _, readErr := io.Copy(io.Discard, response.Body) + closeErr := response.Body.Close() + if readErr != nil { + errors <- readErr + return + } + if closeErr != nil { + errors <- closeErr + return + } + if response.StatusCode != http.StatusCreated { + errors <- fmt.Errorf("client %d message %d: status=%d", clientIndex, messageIndex, response.StatusCode) + return + } + } + }(clientIndex) + } + close(start) + waitGroup.Wait() + close(errors) + for err := range errors { + if err != nil { + t.Fatal(err) + } + } + + seenIDs := make(map[string]struct{}, 10*10) + seenTexts := make(map[string]struct{}, 10*10) + cursor := "" + for { + path := "/api/v1/chats/" + chat.ID + "/messages?limit=17" + if cursor != "" { + path += "&cursor=" + url.QueryEscape(cursor) + } + var page messagePageResponse + api.request(t, http.DefaultClient, http.MethodGet, path, users[0].ID, "", http.StatusOK, &page) + for _, message := range page.Items { + if _, duplicate := seenIDs[message.ID]; duplicate { + t.Fatalf("duplicate message ID %s", message.ID) + } + if _, duplicate := seenTexts[message.Text]; duplicate { + t.Fatalf("duplicate message text %q", message.Text) + } + seenIDs[message.ID] = struct{}{} + seenTexts[message.Text] = struct{}{} + } + if page.NextCursor == nil { + break + } + cursor = *page.NextCursor + } + if len(seenIDs) != 10*10 || len(seenTexts) != 10*10 { + t.Fatalf("received %d unique IDs and %d unique texts, want %d of each", + len(seenIDs), len(seenTexts), 10*10) + } +} + +// Session fake is only used by HTTP unit tests; the server always uses Redis. +type testSessions struct { + mu sync.Mutex + values map[string]domain.Session +} + +func (s *testSessions) Ready(context.Context) error { return nil } +func (s *testSessions) Put(_ context.Context, key string, value domain.Session) error { + s.mu.Lock() + defer s.mu.Unlock() + s.values[key] = value + return nil +} +func (s *testSessions) Get(_ context.Context, key string) (domain.Session, bool, error) { + s.mu.Lock() + defer s.mu.Unlock() + value, ok := s.values[key] + return value, ok, nil +} +func (s *testSessions) Delete(_ context.Context, key string) (bool, error) { + s.mu.Lock() + defer s.mu.Unlock() + _, ok := s.values[key] + delete(s.values, key) + return ok, nil +} diff --git a/internal/app/chat/session.go b/internal/app/chat/session.go new file mode 100644 index 00000000..29ce755c --- /dev/null +++ b/internal/app/chat/session.go @@ -0,0 +1,45 @@ +package chat + +import ( + "io" + "net/http" + "strings" + + "github.com/labstack/echo/v4" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/dto" +) + +func bearerToken(c echo.Context) string { + parts := strings.Fields(c.Request().Header.Get("Authorization")) + if len(parts) != 2 || !strings.EqualFold(parts[0], "Bearer") { + return "" + } + return parts[1] +} + +func (h *Chat) createSession(c echo.Context) error { + username, password, ok := c.Request().BasicAuth() + if !ok { + c.Response().Header().Set("WWW-Authenticate", `Basic realm="messenger", charset="UTF-8"`) + return h.writeError(c, http.StatusUnauthorized, "unauthorized", "Неверные учётные данные") + } + body, err := io.ReadAll(io.LimitReader(c.Request().Body, 1)) + if err != nil || len(body) != 0 { + return h.invalid(c, "Тело запроса входа должно быть пустым") + } + login, err := h.useCase.CreateSession(c.Request().Context(), username, password) + if err != nil { + return h.useCaseError(c, err) + } + return c.JSON(http.StatusCreated, dto.CreateSessionResponse{ + Token: login.Token, TokenType: "Bearer", ExpiresAt: dto.Timestamp(login.ExpiresAt), User: createUserResponseFromDomain(login.User), + }) +} + +func (h *Chat) deleteSession(c echo.Context) error { + if err := h.useCase.DeleteSession(c.Request().Context(), bearerToken(c)); err != nil { + return h.useCaseError(c, err) + } + return c.NoContent(http.StatusNoContent) +} diff --git a/internal/app/chat/swagger.go b/internal/app/chat/swagger.go new file mode 100644 index 00000000..fc87c65e --- /dev/null +++ b/internal/app/chat/swagger.go @@ -0,0 +1,38 @@ +package chat + +import ( + "encoding/json" + "net/http" + + "github.com/labstack/echo/v4" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/contracts" +) + +var swaggerOpenAPI = makeSwaggerOpenAPI() + +func (h *Chat) swagger(c echo.Context) error { + return c.Redirect(http.StatusTemporaryRedirect, "/swagger/") +} + +func (h *Chat) swaggerSpec(c echo.Context) error { + return c.Blob(http.StatusOK, echo.MIMEApplicationJSON, swaggerOpenAPI) +} + +func makeSwaggerOpenAPI() []byte { + var document map[string]any + if err := json.Unmarshal(contracts.OpenAPI, &document); err != nil { + panic("cannot decode embedded OpenAPI contract: " + err.Error()) + } + // A relative URL keeps Swagger requests on the same scheme, host and port + // as the UI. This also works behind a reverse proxy and on a custom PORT. + document["servers"] = []map[string]string{{ + "url": "/", + "description": "Текущий адрес Swagger UI", + }} + encoded, err := json.Marshal(document) + if err != nil { + panic("cannot encode Swagger OpenAPI contract: " + err.Error()) + } + return encoded +} diff --git a/internal/app/chat/usecase.go b/internal/app/chat/usecase.go new file mode 100644 index 00000000..811a6ef0 --- /dev/null +++ b/internal/app/chat/usecase.go @@ -0,0 +1,21 @@ +package chat + +import ( + "context" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" +) + +// UseCase is the application boundary required by the HTTP handler. +type UseCase interface { + Ready(context.Context) error + CreateSession(context.Context, string, string) (domain.Login, error) + DeleteSession(context.Context, string) error + Authenticate(ctx context.Context, token string) (domain.User, error) + CreateUser(ctx context.Context, user domain.User, password string) (domain.User, error) + CreateChat(ctx context.Context, callerID string, chat domain.Chat) (domain.Chat, error) + GetChat(ctx context.Context, callerID string, chat domain.Chat) (domain.Chat, error) + ListChats(ctx context.Context, callerID string, pagination domain.Pagination) (domain.ChatPage, error) + CreateMessage(ctx context.Context, callerID string, message domain.Message) (domain.Message, error) + ListMessages(ctx context.Context, callerID string, chat domain.Chat, pagination domain.Pagination) (domain.MessagePage, error) +} diff --git a/internal/attachment/async.go b/internal/attachment/async.go new file mode 100644 index 00000000..3e9faa69 --- /dev/null +++ b/internal/attachment/async.go @@ -0,0 +1,156 @@ +package attachment + +import ( + "context" + "encoding/json" + "fmt" + "os" + "strconv" + "time" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" + "github.com/google/uuid" + "github.com/jackc/pgx/v5/pgxpool" +) + +type Options struct { + Concurrency, Prefetch, MaxOutstanding, MaxAttempts, PixelBudget int + Timeout, Lease time.Duration +} + +func LoadOptions() (Options, error) { + o := Options{} + for _, v := range []struct { + name string + target *int + def, max int + }{ + {"WORKER_CONCURRENCY", &o.Concurrency, 2, 8}, {"WORKER_PREFETCH", &o.Prefetch, 4, 32}, + {"MAX_OUTSTANDING_JOBS", &o.MaxOutstanding, 200, 10000}, {"WORKER_MAX_ATTEMPTS", &o.MaxAttempts, 5, 20}, + {"WORKER_PIXEL_BUDGET", &o.PixelBudget, 40000000, 80000000}, + } { + n := v.def + if raw := os.Getenv(v.name); raw != "" { + var err error + n, err = strconv.Atoi(raw) + if err != nil { + return o, fmt.Errorf("invalid %s", v.name) + } + } + if n < 1 || n > v.max { + return o, fmt.Errorf("invalid %s", v.name) + } + *v.target = n + } + for _, v := range []struct { + name string + target *time.Duration + def int + }{{"WORKER_TIMEOUT_SECONDS", &o.Timeout, 25}, {"WORKER_LEASE_SECONDS", &o.Lease, 40}} { + n := v.def + if raw := os.Getenv(v.name); raw != "" { + var e error + n, e = strconv.Atoi(raw) + if e != nil { + return o, fmt.Errorf("invalid %s", v.name) + } + } + if n < 1 || n > 300 { + return o, fmt.Errorf("invalid %s", v.name) + } + *v.target = time.Duration(n) * time.Second + } + if o.Lease < o.Timeout+5*time.Second { + return o, fmt.Errorf("worker lease must exceed timeout by at least 5s") + } + if o.PixelBudget < int(MaxPixels) { + return o, fmt.Errorf("WORKER_PIXEL_BUDGET must allow one 40MP image") + } + return o, nil +} +func NewAsync(pool *pgxpool.Pool, store *Store, o Options) *Service { + s := New(pool, store) + s.Async = true + s.Options = o + return s +} +func (s *Service) Upload(ctx context.Context, chatID, userID, name, contentType string, body interface{ Read([]byte) (int, error) }) (Attachment, error) { + if !s.Async { + return s.uploadSync(ctx, chatID, userID, name, contentType, body) + } + if err := ValidateFilename(name); err != nil { + return Attachment{}, err + } + ctx, cancel := context.WithTimeout(ctx, UploadTimeout) + defer cancel() + select { + case s.slots <- struct{}{}: + defer func() { <-s.slots }() + case <-ctx.Done(): + return Attachment{}, unavailable() + } + original, err := Spool(ctx, body, contentType) + if err != nil { + return Attachment{}, err + } + defer original.Close() + tx, err := s.Pool.Begin(ctx) + if err != nil { + return Attachment{}, unavailable() + } + defer tx.Rollback(context.Background()) + // All API replicas serialize admission, including inserts before their COMMIT. + if _, err = tx.Exec(ctx, `SELECT pg_advisory_xact_lock(578903551)`); err != nil { + return Attachment{}, unavailable() + } + var pending int + if err = tx.QueryRow(ctx, `SELECT count(*) FROM attachment_jobs WHERE state IN ('queued','processing')`).Scan(&pending); err != nil { + return Attachment{}, unavailable() + } + if pending >= s.Options.MaxOutstanding { + return Attachment{}, appError("rate_limited", "Очередь заполнена; повторите загрузку позднее") + } + a := Attachment{ID: uuid.NewString(), ChatID: chatID, OwnerID: userID, Filename: name, ContentType: original.ContentType, Size: original.Size, SHA256: original.SHA256, Status: "queued", Variants: []any{}, PipelineVersion: 1} + stage := "staging/" + a.ID + a.Key = effectKey(a.ID, 1, "original") + // The stage lock protects even a slow PUT from the orphan cleaner. + if _, err = tx.Exec(ctx, `SELECT pg_advisory_xact_lock(hashtextextended($1,0))`, stage); err != nil { + return Attachment{}, unavailable() + } + if err = s.put(ctx, stage, original.File, original.Size, original.ContentType); err != nil { + return Attachment{}, unavailable() + } + err = tx.QueryRow(ctx, `INSERT INTO attachments(id,chat_id,uploader_id,filename,object_key,content_type,size_bytes,sha256,width,height,status,staging_key) VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,'queued',$11) RETURNING created_at,updated_at`, a.ID, chatID, userID, name, a.Key, a.ContentType, a.Size, a.SHA256, original.Width, original.Height, stage).Scan(&a.CreatedAt, &a.UpdatedAt) + if err != nil { + return Attachment{}, unavailable() + } + job := uuid.NewString() + if _, err = tx.Exec(ctx, `INSERT INTO attachment_jobs(id,attachment_id,state,max_attempts) VALUES($1,$2,'queued',$3)`, job, a.ID, s.Options.MaxAttempts); err != nil { + return Attachment{}, unavailable() + } + if _, err = tx.Exec(ctx, `INSERT INTO attachment_outbox(job_id) VALUES($1)`, job); err != nil { + return Attachment{}, unavailable() + } + if err = tx.Commit(ctx); err != nil { + return Attachment{}, unavailable() + } + return a, nil +} +func effectKey(id string, version int, name string) string { + return fmt.Sprintf("original/%s/v%d/%s", id, version, name) +} +func (s *Service) Variant(a Attachment, name string) (Attachment, error) { + if name == "original" { + return a, nil + } + for _, item := range a.Variants { + raw, _ := json.Marshal(item) + var v Variant + if json.Unmarshal(raw, &v) == nil && v.Name == name { + a.Key = effectKey(a.ID, a.PipelineVersion, name) + a.ContentType = v.ContentType + return a, nil + } + } + return Attachment{}, appError(domain.ErrorNotFound, "Вариант не найден") +} diff --git a/internal/attachment/image.go b/internal/attachment/image.go new file mode 100644 index 00000000..3e688cfc --- /dev/null +++ b/internal/attachment/image.go @@ -0,0 +1,128 @@ +package attachment + +import ( + "context" + "crypto/sha256" + "encoding/hex" + "errors" + "image" + _ "image/jpeg" + _ "image/png" + "io" + "mime" + "os" + "strings" + "unicode" + "unicode/utf8" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" +) + +const MaxBytes int64 = 10 * 1024 * 1024 +const MaxPixels int64 = 40_000_000 + +func appError(code domain.ErrorCode, message string) error { + return domain.NewApplicationError(code, message) +} +func unavailable() error { + return appError(domain.ErrorUnavailable, "Хранилище вложений недоступно") +} +func ValidateFilename(name string) error { + if !utf8.ValidString(name) || strings.TrimSpace(name) == "" || utf8.RuneCountInString(name) > 255 { + return appError(domain.ErrorInvalid, "Некорректный filename") + } + for _, r := range name { + if r == '/' || r == '\\' || unicode.IsControl(r) { + return appError(domain.ErrorInvalid, "Недопустимые символы filename") + } + } + return nil +} + +type Original struct { + File *os.File + Size int64 + SHA256, ContentType string + Width, Height int +} + +func (o *Original) Close() { name := o.File.Name(); o.File.Close(); os.Remove(name) } + +// Spool bounds compressed bytes on disk before any decode. DecodeConfig checks the +// pixel budget before a full decode verifies CRCs/truncated scan data. +func Spool(ctx context.Context, body io.Reader, declared string) (*Original, error) { + media, _, err := mime.ParseMediaType(declared) + if err != nil || (media != "image/png" && media != "image/jpeg") { + return nil, appError("unsupported_media_type", "Допустимы PNG и JPEG") + } + f, err := os.CreateTemp("", "messenger-upload-*") + if err != nil { + return nil, unavailable() + } + o := &Original{File: f} + good := false + defer func() { + if !good { + o.Close() + } + }() + hash := sha256.New() + n, err := io.Copy(io.MultiWriter(f, hash), io.LimitReader(&contextReader{ctx: ctx, r: body}, MaxBytes+1)) + if n > MaxBytes { + return nil, appError("payload_too_large", "Файл превышает 10 MiB") + } + if err != nil { + return nil, appError(domain.ErrorInvalid, "Загрузка прервана") + } + o.Size = n + o.SHA256 = hex.EncodeToString(hash.Sum(nil)) + if _, err = f.Seek(0, 0); err != nil { + return nil, unavailable() + } + cfg, format, err := image.DecodeConfig(f) + if err != nil { + return nil, appError("unsupported_media_type", "Повреждённое изображение") + } + actual := "image/" + format + if actual != media { + return nil, appError("unsupported_media_type", "MIME не соответствует содержимому") + } + if cfg.Width <= 0 || cfg.Height <= 0 || int64(cfg.Width) > MaxPixels/int64(cfg.Height) { + return nil, appError("payload_too_large", "Изображение превышает 40 миллионов пикселей") + } + if _, err = f.Seek(0, 0); err != nil { + return nil, unavailable() + } + decoded, format, err := image.Decode(f) + if err != nil || decoded == nil || "image/"+format != actual { + return nil, appError("unsupported_media_type", "Повреждённое изображение") + } + if decoded.Bounds().Dx() != cfg.Width || decoded.Bounds().Dy() != cfg.Height { + return nil, appError("unsupported_media_type", "Некорректные размеры изображения") + } + decoded = nil + if _, err = f.Seek(0, 0); err != nil { + return nil, unavailable() + } + o.ContentType = actual + o.Width = cfg.Width + o.Height = cfg.Height + good = true + return o, nil +} + +type contextReader struct { + ctx context.Context + r io.Reader +} + +func (r *contextReader) Read(p []byte) (int, error) { + if err := r.ctx.Err(); err != nil { + return 0, err + } + n, err := r.r.Read(p) + if errors.Is(err, context.Canceled) { + return n, err + } + return n, err +} diff --git a/internal/attachment/image_test.go b/internal/attachment/image_test.go new file mode 100644 index 00000000..30700b77 --- /dev/null +++ b/internal/attachment/image_test.go @@ -0,0 +1,139 @@ +package attachment + +import ( + "bytes" + "context" + "encoding/binary" + "hash/crc32" + "image" + "image/color" + "image/jpeg" + "image/png" + "io" + "testing" + "time" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" +) + +func pngFixture(t *testing.T) []byte { + t.Helper() + m := image.NewRGBA(image.Rect(0, 0, 10, 8)) + m.Set(1, 1, color.RGBA{R: 255, A: 255}) + var b bytes.Buffer + if err := png.Encode(&b, m); err != nil { + t.Fatal(err) + } + return b.Bytes() +} +func code(t *testing.T, err error, want domain.ErrorCode) { + t.Helper() + app, ok := domain.AsApplicationError(err) + if !ok || app.Code != want { + t.Fatalf("want %s, got %v", want, err) + } +} +func TestSpoolOriginalAndFullValidation(t *testing.T) { + original := pngFixture(t) + good, err := Spool(context.Background(), bytes.NewReader(original), "image/png") + if err != nil { + t.Fatal(err) + } + defer good.Close() + got, err := io.ReadAll(good.File) + if err != nil || !bytes.Equal(got, original) { + t.Fatal("original changed") + } + if good.Width != 10 || good.Height != 8 || good.Size != int64(len(original)) || len(good.SHA256) != 64 { + t.Fatalf("wrong metadata %+v", good) + } + _, err = Spool(context.Background(), bytes.NewReader(original), "image/jpeg") + code(t, err, "unsupported_media_type") + _, err = Spool(context.Background(), bytes.NewReader(original[:len(original)-12]), "image/png") + code(t, err, "unsupported_media_type") + corrupted := bytes.Clone(original) + corrupted[len(corrupted)-18] ^= 0x80 + _, err = Spool(context.Background(), bytes.NewReader(corrupted), "image/png") + code(t, err, "unsupported_media_type") + var jpegBytes bytes.Buffer + if err = jpeg.Encode(&jpegBytes, image.NewRGBA(image.Rect(0, 0, 12, 9)), nil); err != nil { + t.Fatal(err) + } + jpegOriginal, err := Spool(context.Background(), bytes.NewReader(jpegBytes.Bytes()), "image/jpeg") + if err != nil { + t.Fatal(err) + } + jpegOriginal.Close() + _, err = Spool(context.Background(), bytes.NewReader(jpegBytes.Bytes()[:jpegBytes.Len()/2]), "image/jpeg") + code(t, err, "unsupported_media_type") +} +func TestSpoolLimitsBeforeDecode(t *testing.T) { + // Oversized compressed input is stopped after exactly MaxBytes+1 reads. + source := &countingReader{remaining: MaxBytes + 100_000} + _, err := Spool(context.Background(), source, "image/png") + code(t, err, "payload_too_large") + if source.read != MaxBytes+1 { + t.Fatalf("read %d bytes", source.read) + } + bomb := bytes.Clone(pngFixture(t)) + binary.BigEndian.PutUint32(bomb[16:20], 40001) + binary.BigEndian.PutUint32(bomb[20:24], 1000) + binary.BigEndian.PutUint32(bomb[29:33], crc32.ChecksumIEEE(bomb[12:29])) + _, err = Spool(context.Background(), bytes.NewReader(bomb), "image/png") + code(t, err, "payload_too_large") +} + +type countingReader struct{ remaining, read int64 } + +func (c *countingReader) Read(p []byte) (int, error) { + if c.remaining == 0 { + return 0, io.EOF + } + n := min(int64(len(p)), c.remaining) + clear(p[:n]) + c.remaining -= n + c.read += n + return int(n), nil +} +func TestFilenameAndCancelledUpload(t *testing.T) { + for _, name := range []string{"", "../x.png", "x\\photo.jpg", "a\x00b", "a\nb", "\t"} { + code(t, ValidateFilename(name), domain.ErrorInvalid) + } + for _, name := range []string{"фото.png", "image.jpg", ".."} { + if err := ValidateFilename(name); err != nil { + t.Fatal(err) + } + } + ctx, cancel := context.WithCancel(context.Background()) + cancel() + _, err := Spool(ctx, bytes.NewReader(pngFixture(t)), "image/png") + code(t, err, domain.ErrorInvalid) +} +func TestReconcileRejectsUnsafeGrace(t *testing.T) { + s := &Service{} + if _, err := s.Reconcile(context.Background(), true, 89*time.Second); err == nil { + t.Fatal("unsafe grace accepted") + } + if MinimumGrace <= UploadTimeout { + t.Fatal("grace does not cover in-flight PUT") + } +} + +func TestValid16BitWidePNG(t *testing.T) { + // Exercise the same RGBA64 + scanline allocation path as an extreme-aspect + // 40M image, at 1/1000 of that pixel count to keep the unit suite small. + img := image.NewNRGBA64(image.Rect(0, 0, 40000, 1)) + img.SetNRGBA64(1, 0, color.NRGBA64{R: 65535, G: 12345, B: 4, A: 32000}) + var encoded bytes.Buffer + if err := png.Encode(&encoded, img); err != nil { + t.Fatal(err) + } + original, err := Spool(context.Background(), bytes.NewReader(encoded.Bytes()), "image/png") + if err != nil { + t.Fatal(err) + } + defer original.Close() + if original.Width != 40000 || original.Height != 1 { + t.Fatal("wide PNG dimensions changed") + } +} diff --git a/internal/attachment/json.go b/internal/attachment/json.go new file mode 100644 index 00000000..cb3958fb --- /dev/null +++ b/internal/attachment/json.go @@ -0,0 +1,18 @@ +package attachment + +import ( + "encoding/json" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/dto" +) + +// MarshalJSON uses the API's fixed microsecond precision instead of time.Time's +// variable fractional precision, which Python 3.9 clients cannot always parse. +func (a Attachment) MarshalJSON() ([]byte, error) { + type fields Attachment + return json.Marshal(struct { + fields + CreatedAt dto.Timestamp `json:"created_at"` + UpdatedAt dto.Timestamp `json:"updated_at"` + }{fields: fields(a), CreatedAt: dto.Timestamp(a.CreatedAt), UpdatedAt: dto.Timestamp(a.UpdatedAt)}) +} diff --git a/internal/attachment/json_test.go b/internal/attachment/json_test.go new file mode 100644 index 00000000..4812d608 --- /dev/null +++ b/internal/attachment/json_test.go @@ -0,0 +1,37 @@ +package attachment + +import ( + "encoding/json" + "testing" + "time" +) + +func TestAttachmentTimestampsUseFixedMicroseconds(t *testing.T) { + value := Attachment{ID: "attachment-id", CreatedAt: time.Date(2026, 1, 2, 3, 4, 5, 123400000, time.UTC), UpdatedAt: time.Date(2026, 1, 2, 6, 4, 5, 0, time.FixedZone("MSK", 3*60*60)), Key: "original/private", Variants: []any{}} + encoded, err := json.Marshal(value) + if err != nil { + t.Fatal(err) + } + var fields map[string]any + if err = json.Unmarshal(encoded, &fields); err != nil { + t.Fatal(err) + } + if fields["created_at"] != "2026-01-02T03:04:05.123400Z" { + t.Fatalf("created_at=%v", fields["created_at"]) + } + if fields["updated_at"] != "2026-01-02T03:04:05.000000Z" { + t.Fatalf("updated_at=%v", fields["updated_at"]) + } + if fields["id"] != value.ID { + t.Fatal("serialization lost metadata") + } + if _, exposed := fields["Key"]; exposed { + t.Fatal("serialization exposed private object key") + } + if _, exposed := fields["key"]; exposed { + t.Fatal("serialization exposed private object key") + } + if fields["error_code"] != nil { + t.Fatal("ready error_code must be null") + } +} diff --git a/internal/attachment/reconcile.go b/internal/attachment/reconcile.go new file mode 100644 index 00000000..755338f4 --- /dev/null +++ b/internal/attachment/reconcile.go @@ -0,0 +1,225 @@ +package attachment + +import ( + "context" + "fmt" + "time" + + "github.com/jackc/pgx/v5" + "github.com/minio/minio-go/v7" +) + +type Summary struct { + Apply bool `json:"apply"` + GraceSeconds float64 `json:"grace_seconds"` + ObjectsScanned int `json:"objects_scanned"` + MetadataScanned int `json:"metadata_scanned"` + BytesScanned int64 `json:"bytes_scanned"` + ListRequestsEstimate int `json:"list_requests_estimate"` + StatRequests int `json:"stat_requests"` + DBQueries int `json:"db_queries"` + Orphans int `json:"orphans"` + Missing int `json:"missing"` + FreshSkipped int `json:"fresh_skipped"` + LockedSkipped int `json:"locked_skipped"` + ReferencedMissing int `json:"referenced_missing"` + Deleted int `json:"deleted"` + MarkedFailed int `json:"marked_failed"` + DurationMS int64 `json:"duration_ms"` + Actions []Action `json:"actions"` +} +type Action struct { + Kind string `json:"kind"` + Key string `json:"key"` + Applied bool `json:"applied"` +} + +// Reconcile scans a fixed cutoff and rechecks each candidate while holding the +// same transaction-scoped advisory lock as upload. Metadata, including message +// references, is never deleted. Missing originals become failed tombstones. +func (s *Service) Reconcile(ctx context.Context, apply bool, grace time.Duration) (result Summary, err error) { + started := time.Now() + result = Summary{Apply: apply, GraceSeconds: grace.Seconds(), Actions: []Action{}} + defer func() { result.DurationMS = time.Since(started).Milliseconds() }() + if grace < MinimumGrace { + return result, fmt.Errorf("grace must be at least %s (upload timeout %s)", MinimumGrace, UploadTimeout) + } + cutoff := started.Add(-grace) + for obj := range s.Store.Client.ListObjects(ctx, s.Store.Bucket, minio.ListObjectsOptions{Prefix: "original/", Recursive: true, MaxKeys: 1000}) { + if obj.Err != nil { + return result, fmt.Errorf("S3 listing failed") + } + result.ObjectsScanned++ + result.BytesScanned += obj.Size + if result.ObjectsScanned%1000 == 1 { + result.ListRequestsEstimate++ + } + if !obj.LastModified.Before(cutoff) { + result.FreshSkipped++ + continue + } + err = s.reconcileObject(ctx, obj.Key, cutoff, apply, &result) + if err != nil { + return result, err + } + } + // Bounded keyset pages avoid retaining the entire bucket or a DB cursor while + // making per-object transactions. A later run picks up concurrent new rows. + last := "00000000-0000-0000-0000-000000000000" + for { + result.DBQueries++ + rows, e := s.Pool.Query(ctx, `SELECT id::text,object_key,created_at,status FROM attachments WHERE id>$1 ORDER BY id LIMIT 100`, last) + if e != nil { + return result, fmt.Errorf("metadata scan failed") + } + type metadata struct { + id, key, status string + created time.Time + } + page := []metadata{} + for rows.Next() { + var m metadata + if e = rows.Scan(&m.id, &m.key, &m.created, &m.status); e != nil { + rows.Close() + return result, e + } + page = append(page, m) + } + e = rows.Err() + rows.Close() + if e != nil { + return result, e + } + if len(page) == 0 { + break + } + for _, m := range page { + last = m.id + result.MetadataScanned++ + if m.status != "ready" { + continue + } + if !m.created.Before(cutoff) { + result.FreshSkipped++ + continue + } + if e = s.reconcileMetadata(ctx, m.id, m.key, cutoff, apply, &result); e != nil { + return result, e + } + } + } + if ctx.Err() != nil { + return result, ctx.Err() + } + return result, nil +} +func (s *Service) locked(ctx context.Context, key string, r *Summary) (pgx.Tx, bool, error) { + tx, err := s.Pool.Begin(ctx) + if err != nil { + return nil, false, fmt.Errorf("DB unavailable") + } + var locked bool + r.DBQueries++ + if err = tx.QueryRow(ctx, `SELECT pg_try_advisory_xact_lock(hashtextextended($1,0))`, key).Scan(&locked); err != nil { + tx.Rollback(context.Background()) + return nil, false, fmt.Errorf("lock failed") + } + if !locked { + r.LockedSkipped++ + tx.Rollback(context.Background()) + return nil, false, nil + } + return tx, true, nil +} +func (s *Service) reconcileObject(ctx context.Context, key string, cutoff time.Time, apply bool, r *Summary) error { + tx, ok, err := s.locked(ctx, key, r) + if err != nil || !ok { + return err + } + defer tx.Rollback(context.Background()) + var exists bool + r.DBQueries++ + if err = tx.QueryRow(ctx, `SELECT EXISTS(SELECT 1 FROM attachments WHERE object_key=$1 OR staging_key=$1 OR $1 LIKE 'original/'||id::text||'/v'||pipeline_version::text||'/%')`, key).Scan(&exists); err != nil { + return fmt.Errorf("metadata recheck failed") + } + if exists { + return nil + } + r.StatRequests++ + obj, err := s.Store.Client.StatObject(ctx, s.Store.Bucket, key, minio.StatObjectOptions{}) + if IsMissing(err) { + return nil + } + if err != nil { + return fmt.Errorf("object recheck failed") + } + if !obj.LastModified.Before(cutoff) { + r.FreshSkipped++ + return nil + } + r.Orphans++ + if apply { + if err = s.Store.Client.RemoveObject(ctx, s.Store.Bucket, key, minio.RemoveObjectOptions{}); err != nil { + return fmt.Errorf("orphan deletion failed") + } + r.Deleted++ + } + if len(r.Actions) < 100 { + r.Actions = append(r.Actions, Action{Kind: "orphan", Key: key, Applied: apply}) + } + return nil +} +func (s *Service) reconcileMetadata(ctx context.Context, id, key string, cutoff time.Time, apply bool, r *Summary) error { + tx, ok, err := s.locked(ctx, key, r) + if err != nil || !ok { + return err + } + defer tx.Rollback(context.Background()) + var created time.Time + var status string + r.DBQueries++ + err = tx.QueryRow(ctx, `SELECT created_at,status FROM attachments WHERE id=$1 FOR UPDATE`, id).Scan(&created, &status) + if err == pgx.ErrNoRows { + return nil + } + if err != nil { + return fmt.Errorf("metadata recheck failed") + } + if status != "ready" || !created.Before(cutoff) { + return nil + } + r.StatRequests++ + _, err = s.Store.Client.StatObject(ctx, s.Store.Bucket, key, minio.StatObjectOptions{}) + if err == nil { + return nil + } + if !IsMissing(err) { + return fmt.Errorf("object stat failed (no mutation)") + } + var referenced bool + r.DBQueries++ + if err = tx.QueryRow(ctx, `SELECT EXISTS(SELECT 1 FROM messages WHERE $1::uuid=ANY(attachment_ids))`, id).Scan(&referenced); err != nil { + return fmt.Errorf("reference check failed") + } + r.Missing++ + if referenced { + r.ReferencedMissing++ + } + if apply { + r.DBQueries++ + if _, err = tx.Exec(ctx, `UPDATE attachments SET status='failed',error_code='original_missing',updated_at=clock_timestamp() WHERE id=$1 AND status='ready'`, id); err != nil { + return fmt.Errorf("mark missing failed") + } + if _, err = tx.Exec(ctx, `UPDATE attachment_jobs SET state='failed',last_error='original_missing',fence=fence+1,updated_at=clock_timestamp() WHERE attachment_id=$1 AND state='ready'`, id); err != nil { + return fmt.Errorf("mark job missing failed") + } + if err = tx.Commit(ctx); err != nil { + return fmt.Errorf("commit missing failed") + } + r.MarkedFailed++ + } + if len(r.Actions) < 100 { + r.Actions = append(r.Actions, Action{Kind: "missing", Key: key, Applied: apply}) + } + return nil +} diff --git a/internal/attachment/render.go b/internal/attachment/render.go new file mode 100644 index 00000000..e6cebce9 --- /dev/null +++ b/internal/attachment/render.go @@ -0,0 +1,267 @@ +package attachment + +import ( + "bytes" + "context" + "crypto/sha256" + "encoding/binary" + "encoding/hex" + "encoding/json" + "errors" + "image" + "image/color" + "image/jpeg" + "image/png" + "math" + "os" + "os/exec" + "path/filepath" + "syscall" +) + +var ErrInvalidImage = errors.New("invalid image") + +type oriented struct { + image.Image + orientation int +} + +func (o oriented) Bounds() image.Rectangle { + b := o.Image.Bounds() + w, h := b.Dx(), b.Dy() + if o.orientation >= 5 && o.orientation <= 8 { + w, h = h, w + } + return image.Rect(0, 0, w, h) +} +func (o oriented) At(x, y int) color.Color { + b := o.Image.Bounds() + w, h := b.Dx(), b.Dy() + sx, sy := x, y + switch o.orientation { + case 2: + sx = w - 1 - x + case 3: + sx, sy = w-1-x, h-1-y + case 4: + sy = h - 1 - y + case 5: + sx, sy = y, x + case 6: + sx, sy = y, h-1-x + case 7: + sx, sy = w-1-y, h-1-x + case 8: + sx, sy = w-1-y, x + } + r, g, blue, a := o.Image.At(b.Min.X+sx, b.Min.Y+sy).RGBA() + white := uint32(65535) - a + return color.RGBA{uint8((r + white) / 257), uint8((g + white) / 257), uint8((blue + white) / 257), 255} +} + +// EXIF IFD0 orientation; bounded segment parsing does not follow client offsets outside APP1. +func tiffOrientation(t []byte) int { + if len(t) < 8 { + return 1 + } + var order binary.ByteOrder + if string(t[:2]) == "II" { + order = binary.LittleEndian + } else if string(t[:2]) == "MM" { + order = binary.BigEndian + } else { + return 1 + } + if order.Uint16(t[2:4]) != 42 { + return 1 + } + offset := uint64(order.Uint32(t[4:8])) + if offset+2 > uint64(len(t)) { + return 1 + } + count := uint64(order.Uint16(t[offset : offset+2])) + for k := uint64(0); k < count; k++ { + p := offset + 2 + k*12 + if p+12 > uint64(len(t)) { + break + } + entry := t[p : p+12] + if order.Uint16(entry[:2]) == 0x112 && order.Uint16(entry[2:4]) == 3 && order.Uint32(entry[4:8]) == 1 { + v := int(order.Uint16(entry[8:10])) + if v >= 1 && v <= 8 { + return v + } + } + } + return 1 +} +func Orientation(data []byte) int { + if len(data) >= 8 && bytes.Equal(data[:8], []byte{137, 80, 78, 71, 13, 10, 26, 10}) { + for i := 8; i+12 <= len(data); { + n := uint64(binary.BigEndian.Uint32(data[i : i+4])) + if n > uint64(len(data)-i-12) { + return 1 + } + end := i + 8 + int(n) + if string(data[i+4:i+8]) == "eXIf" { + return tiffOrientation(data[i+8 : end]) + } + i = end + 4 + } + return 1 + } + if len(data) < 4 || data[0] != 255 || data[1] != 216 { + return 1 + } + for i := 2; i+4 <= len(data); { + if data[i] != 255 { + return 1 + } + for i+1 < len(data) && data[i+1] == 255 { + i++ + } + if i+3 >= len(data) { + return 1 + } + marker := data[i+1] + i += 2 + if marker == 0xda || marker == 0xd9 { + return 1 + } + if marker == 0x01 || marker >= 0xd0 && marker <= 0xd7 { + continue + } + n := int(binary.BigEndian.Uint16(data[i : i+2])) + if n < 2 || i+n > len(data) { + return 1 + } + body := data[i+2 : i+n] + i += n + if marker == 0xe1 && len(body) >= 14 && bytes.Equal(body[:6], []byte("Exif\x00\x00")) { + return tiffOrientation(body[6:]) + } + } + return 1 +} + +func fit(w, h, maxSide int) (int, int) { + if w <= maxSide && h <= maxSide { + return w, h + } + if w >= h { + return maxSide, max(1, int(int64(h)*int64(maxSide)/int64(w))) + } + return max(1, int(int64(w)*int64(maxSide)/int64(h))), maxSide +} + +func resize(src image.Image, region image.Rectangle, w, h int) *image.RGBA { + out := image.NewRGBA(image.Rect(0, 0, w, h)) + for y := 0; y < h; y++ { + fy := (float64(y)+.5)*float64(region.Dy())/float64(h) - .5 + fy = math.Max(0, fy) + y0 := min(int(fy), region.Dy()-1) + y1 := min(y0+1, region.Dy()-1) + dy := fy - float64(y0) + for x := 0; x < w; x++ { + fx := (float64(x)+.5)*float64(region.Dx())/float64(w) - .5 + fx = math.Max(0, fx) + x0 := min(int(fx), region.Dx()-1) + x1 := min(x0+1, region.Dx()-1) + dx := fx - float64(x0) + colors := [4]color.RGBA{color.RGBAModel.Convert(src.At(region.Min.X+x0, region.Min.Y+y0)).(color.RGBA), color.RGBAModel.Convert(src.At(region.Min.X+x1, region.Min.Y+y0)).(color.RGBA), color.RGBAModel.Convert(src.At(region.Min.X+x0, region.Min.Y+y1)).(color.RGBA), color.RGBAModel.Convert(src.At(region.Min.X+x1, region.Min.Y+y1)).(color.RGBA)} + blend := func(a, b, c, d uint8) uint8 { + return uint8(math.Round(float64(a)*(1-dx)*(1-dy) + float64(b)*dx*(1-dy) + float64(c)*(1-dx)*dy + float64(d)*dx*dy)) + } + out.SetRGBA(x, y, color.RGBA{blend(colors[0].R, colors[1].R, colors[2].R, colors[3].R), blend(colors[0].G, colors[1].G, colors[2].G, colors[3].G), blend(colors[0].B, colors[1].B, colors[2].B, colors[3].B), 255}) + } + } + return out +} + +// Render runs only inside a deadline-killed child, never in the HTTP process. +func Render(ctx context.Context, source, dir, expectedSHA string) error { + raw, err := os.ReadFile(source) + if err != nil { + return err + } + sum := sha256.Sum256(raw) + if int64(len(raw)) > MaxBytes || hex.EncodeToString(sum[:]) != expectedSHA { + return ErrInvalidImage + } + cfg, _, err := image.DecodeConfig(bytes.NewReader(raw)) + if err != nil || cfg.Width < 1 || cfg.Height < 1 || int64(cfg.Width) > MaxPixels/int64(cfg.Height) { + return ErrInvalidImage + } + if os.Getenv("PIPELINE_FAILPOINT") == "renderer_timeout" { + fifo := filepath.Join(dir, "blocked-input.png") + if err = syscall.Mkfifo(fifo, 0600); err != nil { + return err + } + return exec.CommandContext(ctx, "cwebp", "-quiet", fifo, "-o", filepath.Join(dir, "blocked.webp")).Run() + } + decoded, _, err := image.Decode(bytes.NewReader(raw)) + if err != nil { + return ErrInvalidImage + } + src := oriented{decoded, Orientation(raw)} + bounds := src.Bounds() + tw, th := fit(bounds.Dx(), bounds.Dy(), 256) + ow, oh := fit(bounds.Dx(), bounds.Dy(), 1280) + variants := []Variant{} + for _, name := range []string{"thumbnail", "crop", "optimized"} { + w, h := tw, th + region := bounds + if name == "crop" { + w, h = 128, 128 + side := min(bounds.Dx(), bounds.Dy()) + left, top := (bounds.Dx()-side)/2, (bounds.Dy()-side)/2 + region = image.Rect(left, top, left+side, top+side) + } + if name == "optimized" { + w, h = ow, oh + } + img := resize(src, region, w, h) + path := filepath.Join(dir, name) + if name == "optimized" { + input := filepath.Join(dir, "webp-input.png") + f, e := os.Create(input) + if e != nil { + return e + } + e = png.Encode(f, img) + f.Close() + if e != nil { + return e + } + command := exec.CommandContext(ctx, "cwebp", "-quiet", "-q", "80", "-m", "4", "-metadata", "none", input, "-o", path) + if err = command.Run(); err != nil { + return err + } + } else { + f, e := os.Create(path) + if e != nil { + return e + } + e = jpeg.Encode(f, img, &jpeg.Options{Quality: 85}) + f.Close() + if e != nil { + return e + } + } + data, e := os.ReadFile(path) + if e != nil { + return e + } + hash := sha256.Sum256(data) + mime := "image/jpeg" + if name == "optimized" { + mime = "image/webp" + } + variants = append(variants, Variant{Name: name, ContentType: mime, Width: w, Height: h, Size: int64(len(data)), SHA256: hex.EncodeToString(hash[:])}) + } + data, err := json.Marshal(variants) + if err != nil { + return err + } + return os.WriteFile(filepath.Join(dir, "manifest.json"), data, 0600) +} diff --git a/internal/attachment/render_test.go b/internal/attachment/render_test.go new file mode 100644 index 00000000..a5ab246d --- /dev/null +++ b/internal/attachment/render_test.go @@ -0,0 +1,81 @@ +package attachment + +import ( + "bytes" + "encoding/binary" + "image" + "image/color" + "testing" +) + +func TestFitGeometry(t *testing.T) { + for _, c := range []struct{ w, h, limit, x, y int }{{320, 200, 256, 256, 160}, {513, 257, 256, 256, 128}, {257, 513, 256, 128, 256}, {12, 8, 256, 12, 8}, {1, 40000, 256, 1, 256}} { + w, h := fit(c.w, c.h, c.limit) + if w != c.x || h != c.y { + t.Fatalf("fit(%d,%d)=%d,%d", c.w, c.h, w, h) + } + } +} +func TestOrientationsAndAlpha(t *testing.T) { + img := image.NewNRGBA(image.Rect(0, 0, 3, 2)) + for y := 0; y < 2; y++ { + for x := 0; x < 3; x++ { + img.SetNRGBA(x, y, color.NRGBA{R: uint8(1 + x + y*3), A: 255}) + } + } + expected := [][]uint8{{1, 2, 3, 4, 5, 6}, {3, 2, 1, 6, 5, 4}, {6, 5, 4, 3, 2, 1}, {4, 5, 6, 1, 2, 3}, {1, 4, 2, 5, 3, 6}, {4, 1, 5, 2, 6, 3}, {6, 3, 5, 2, 4, 1}, {3, 6, 2, 5, 1, 4}} + for i, want := range expected { + src := oriented{img, i + 1} + got := []uint8{} + for y := 0; y < src.Bounds().Dy(); y++ { + for x := 0; x < src.Bounds().Dx(); x++ { + got = append(got, src.At(x, y).(color.RGBA).R) + } + } + if !bytes.Equal(got, want) { + t.Fatalf("orientation %d: %v want %v", i+1, got, want) + } + } + img.SetNRGBA(0, 0, color.NRGBA{R: 255, A: 128}) + got := oriented{img, 1}.At(0, 0).(color.RGBA) + if got != (color.RGBA{255, 127, 127, 255}) { + t.Fatalf("white alpha: %v", got) + } +} +func TestEXIFOrientation(t *testing.T) { + for _, order := range []binary.ByteOrder{binary.LittleEndian, binary.BigEndian} { + for v := 1; v <= 8; v++ { + tiff := make([]byte, 26) + copy(tiff, "II") + if order == binary.BigEndian { + copy(tiff, "MM") + } + order.PutUint16(tiff[2:], 42) + order.PutUint32(tiff[4:], 8) + order.PutUint16(tiff[8:], 1) + order.PutUint16(tiff[10:], 0x112) + order.PutUint16(tiff[12:], 3) + order.PutUint32(tiff[14:], 1) + order.PutUint16(tiff[18:], uint16(v)) + data := append([]byte{255, 216, 255, 225, 0, 34}, append([]byte("Exif\x00\x00"), tiff...)...) + if Orientation(data) != v { + t.Fatalf("EXIF value %d", v) + } + pngData := []byte{137, 80, 78, 71, 13, 10, 26, 10} + size := make([]byte, 4) + binary.BigEndian.PutUint32(size, uint32(len(tiff))) + pngData = append(pngData, size...) + pngData = append(pngData, []byte("eXIf")...) + pngData = append(pngData, tiff...) + pngData = append(pngData, 0, 0, 0, 0) + if Orientation(pngData) != v { + t.Fatalf("PNG EXIF value %d", v) + } + } + } + for _, b := range [][]byte{nil, {}, {255, 216, 255, 225, 255, 255}, {255, 216, 255, 255, 225, 0, 2}} { + if Orientation(b) != 1 { + t.Fatal("malformed EXIF should be ignored") + } + } +} diff --git a/internal/attachment/s3.go b/internal/attachment/s3.go new file mode 100644 index 00000000..2b1315c9 --- /dev/null +++ b/internal/attachment/s3.go @@ -0,0 +1,44 @@ +package attachment + +import ( + "context" + "crypto/tls" + "net" + "net/http" + "time" + + "github.com/minio/minio-go/v7" + "github.com/minio/minio-go/v7/pkg/credentials" +) + +type Store struct { + Client *minio.Client + Bucket string +} + +func NewStore(endpoint, bucket, access, secret string, secure bool) (*Store, error) { + transport := &http.Transport{Proxy: http.ProxyFromEnvironment, DialContext: (&net.Dialer{Timeout: 3 * time.Second, KeepAlive: 30 * time.Second}).DialContext, MaxIdleConns: 16, MaxIdleConnsPerHost: 8, IdleConnTimeout: 30 * time.Second, ResponseHeaderTimeout: 5 * time.Second, TLSHandshakeTimeout: 5 * time.Second, TLSClientConfig: &tls.Config{MinVersion: tls.VersionTLS12}} + c, err := minio.New(endpoint, &minio.Options{Creds: credentials.NewStaticV4(access, secret, ""), Secure: secure, Region: "us-east-1", Transport: transport, MaxRetries: 1}) + if err != nil { + return nil, err + } + return &Store{Client: c, Bucket: bucket}, nil +} +func (s *Store) Ready(ctx context.Context) error { + ctx, cancel := context.WithTimeout(ctx, 3*time.Second) + defer cancel() + for item := range s.Client.ListObjects(ctx, s.Bucket, minio.ListObjectsOptions{Prefix: "original/", MaxKeys: 1, Recursive: true}) { + if item.Err != nil { + return unavailable() + } + return nil + } + if ctx.Err() != nil { + return unavailable() + } + return nil +} +func IsMissing(err error) bool { + code := minio.ToErrorResponse(err).Code + return code == "NoSuchKey" || code == "NoSuchObject" +} diff --git a/internal/attachment/service.go b/internal/attachment/service.go new file mode 100644 index 00000000..fb0a441d --- /dev/null +++ b/internal/attachment/service.go @@ -0,0 +1,138 @@ +package attachment + +import ( + "context" + "encoding/json" + "errors" + "io" + "log" + "time" + + "github.com/google/uuid" + "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgxpool" + "github.com/minio/minio-go/v7" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" +) + +const UploadTimeout = 45 * time.Second +const MinimumGrace = 90 * time.Second + +type Attachment struct { + ID string `json:"id"` + ChatID string `json:"chat_id"` + OwnerID string `json:"owner_id"` + Filename string `json:"filename"` + ContentType string `json:"content_type"` + Size int64 `json:"size_bytes"` + SHA256 string `json:"sha256"` + Status string `json:"status"` + Variants []any `json:"variants"` + ErrorCode *string `json:"error_code"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + Key string `json:"-"` + PipelineVersion int `json:"-"` +} + +type Service struct { + Pool *pgxpool.Pool + Store *Store + slots chan struct{} + Async bool + Options Options +} + +func New(pool *pgxpool.Pool, store *Store) *Service { + return &Service{Pool: pool, Store: store, slots: make(chan struct{}, 1)} +} +func (s *Service) Ready(ctx context.Context) error { return s.Store.Ready(ctx) } +func (s *Service) uploadSync(ctx context.Context, chatID, userID, name, contentType string, body io.Reader) (Attachment, error) { + if err := ValidateFilename(name); err != nil { + return Attachment{}, err + } + ctx, cancel := context.WithTimeout(ctx, UploadTimeout) + defer cancel() + select { + case s.slots <- struct{}{}: + defer func() { <-s.slots }() + case <-ctx.Done(): + return Attachment{}, unavailable() + } + original, err := Spool(ctx, body, contentType) + if err != nil { + return Attachment{}, err + } + defer original.Close() + a := Attachment{ID: uuid.NewString(), ChatID: chatID, OwnerID: userID, Filename: name, ContentType: original.ContentType, Size: original.Size, SHA256: original.SHA256, Status: "ready", Variants: []any{}} + a.Key = "original/" + a.ID + tx, err := s.Pool.Begin(ctx) + if err != nil { + return Attachment{}, unavailable() + } + defer tx.Rollback(context.Background()) + // Keep the object lock through PUT, metadata insert and COMMIT. A crash releases + // the lock; the grace protects a still-running client PUT at the S3 server. + if _, err = tx.Exec(ctx, `SELECT pg_advisory_xact_lock(hashtextextended($1,0))`, a.Key); err != nil { + return Attachment{}, unavailable() + } + _, err = s.Store.Client.PutObject(ctx, s.Store.Bucket, a.Key, original.File, a.Size, minio.PutObjectOptions{ContentType: a.ContentType, DisableMultipart: true, UserMetadata: map[string]string{"sha256": a.SHA256}}) + if err != nil { + return Attachment{}, unavailable() + } + err = tx.QueryRow(ctx, `INSERT INTO attachments(id,chat_id,uploader_id,filename,object_key,content_type,size_bytes,sha256,width,height) VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10) RETURNING created_at`, a.ID, a.ChatID, a.OwnerID, a.Filename, a.Key, a.ContentType, a.Size, a.SHA256, original.Width, original.Height).Scan(&a.CreatedAt) + if err != nil { + log.Print("attachment metadata failed; orphan retained for grace-period reconciliation") + return Attachment{}, unavailable() + } + // Never DELETE on an ambiguous COMMIT failure: the DB may have committed. A + // later reconciler checks both stores under the same lock before any cleanup. + if err = tx.Commit(ctx); err != nil { + return Attachment{}, unavailable() + } + a.UpdatedAt = a.CreatedAt + return a, nil +} +func (s *Service) Get(ctx context.Context, id, userID string) (Attachment, error) { + parsed, err := uuid.Parse(id) + if err != nil { + return Attachment{}, appError(domain.ErrorInvalid, "Некорректный attachment_id") + } + ctx, cancel := context.WithTimeout(ctx, 3*time.Second) + defer cancel() + a := Attachment{Variants: []any{}} + var variants []byte + err = s.Pool.QueryRow(ctx, `SELECT a.id::text,a.chat_id::text,a.uploader_id::text,a.filename,a.object_key,a.content_type,a.size_bytes,a.sha256,a.status,a.error_code,a.created_at,a.updated_at,a.variants,a.pipeline_version FROM attachments a JOIN chat_members m ON m.chat_id=a.chat_id WHERE a.id=$1 AND m.user_id=$2`, parsed.String(), userID).Scan(&a.ID, &a.ChatID, &a.OwnerID, &a.Filename, &a.Key, &a.ContentType, &a.Size, &a.SHA256, &a.Status, &a.ErrorCode, &a.CreatedAt, &a.UpdatedAt, &variants, &a.PipelineVersion) + if errors.Is(err, pgx.ErrNoRows) { + return Attachment{}, appError(domain.ErrorNotFound, "Объект не найден") + } + if err != nil { + return Attachment{}, unavailable() + } + if err = json.Unmarshal(variants, &a.Variants); err != nil { + return Attachment{}, unavailable() + } + // The legacy fixture service preserves lab4 errors; production Async exposes all states. + if a.Status != "ready" && !s.Async { + return Attachment{}, appError(domain.ErrorConflict, "Оригинал вложения недоступен") + } + return a, nil +} +func (s *Service) Content(ctx context.Context, a Attachment) (*minio.Object, error) { + if a.Status != "ready" { + return nil, appError(domain.ErrorConflict, "Вложение не готово") + } + obj, err := s.Store.Client.GetObject(ctx, s.Store.Bucket, a.Key, minio.GetObjectOptions{}) + if err != nil { + return nil, unavailable() + } + if _, err = obj.Stat(); err != nil { + obj.Close() + if IsMissing(err) { + return nil, appError(domain.ErrorConflict, "Оригинал вложения недоступен") + } + return nil, unavailable() + } + return obj, nil +} diff --git a/internal/attachment/worker.go b/internal/attachment/worker.go new file mode 100644 index 00000000..30c72a7f --- /dev/null +++ b/internal/attachment/worker.go @@ -0,0 +1,618 @@ +package attachment + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "io" + "log" + "math/rand/v2" + "os" + "os/exec" + "path/filepath" + "strings" + "sync" + "syscall" + "time" + + "github.com/google/uuid" + "github.com/jackc/pgx/v5" + "github.com/minio/minio-go/v7" + "github.com/redis/go-redis/v9" + "golang.org/x/sync/semaphore" +) + +const Stream = "attachments:jobs:v1" +const Group = "image-workers-v1" + +type JobMessage struct { + SchemaVersion int `json:"schema_version"` + JobID string `json:"job_id"` + Type string `json:"type"` + AttachmentID string `json:"attachment_id"` + PipelineVersion int `json:"pipeline_version"` + Attempt int `json:"attempt"` + CreatedAt time.Time `json:"created_at"` + Traceparent string `json:"traceparent,omitempty"` + Tracestate string `json:"tracestate,omitempty"` +} +type Variant struct { + Name string `json:"name"` + ContentType string `json:"content_type"` + Width int `json:"width"` + Height int `json:"height"` + Size int64 `json:"size_bytes"` + SHA256 string `json:"sha256"` +} +type claimed struct { + JobMessage + Fence int64 + Stage, Original, MIME, SHA string + Width, Height int + Size int64 +} + +func (s *Service) put(ctx context.Context, key string, r io.Reader, size int64, mime string) error { + _, err := s.Store.Client.PutObject(ctx, s.Store.Bucket, key, r, size, minio.PutObjectOptions{ContentType: mime, DisableMultipart: true}) + return err +} +func (s *Service) Publish(ctx context.Context, r *redis.Client) error { + tx, err := s.Pool.Begin(ctx) + if err != nil { + return err + } + defer tx.Rollback(context.Background()) + rows, err := tx.Query(ctx, `SELECT j.id::text,j.attachment_id::text,j.pipeline_version,j.attempts+1,j.created_at FROM attachment_outbox o JOIN attachment_jobs j ON j.id=o.job_id WHERE o.published_at IS NULL AND o.available_at<=clock_timestamp() AND j.state='queued' ORDER BY o.available_at LIMIT 32 FOR UPDATE OF o SKIP LOCKED`) + if err != nil { + return err + } + messages := []JobMessage{} + for rows.Next() { + m := JobMessage{SchemaVersion: 1, Type: "attachment.process.v1"} + if err = rows.Scan(&m.JobID, &m.AttachmentID, &m.PipelineVersion, &m.Attempt, &m.CreatedAt); err != nil { + rows.Close() + return err + } + m.CreatedAt = m.CreatedAt.UTC() + messages = append(messages, m) + } + err = rows.Err() + rows.Close() + if err != nil { + return err + } + for _, m := range messages { + raw, _ := json.Marshal(m) + id, e := r.XAdd(ctx, &redis.XAddArgs{Stream: Stream, Values: map[string]interface{}{"job": string(raw)}}).Result() + if e != nil { + return e + } + if _, e = tx.Exec(ctx, `UPDATE attachment_outbox SET published_at=clock_timestamp(),stream_id=$2 WHERE job_id=$1`, m.JobID, id); e != nil { + return e + } + } + return tx.Commit(ctx) +} +func (s *Service) recover(ctx context.Context) error { + tx, err := s.Pool.Begin(ctx) + if err != nil { + return err + } + defer tx.Rollback(context.Background()) + rows, err := tx.Query(ctx, `SELECT id::text,attachment_id::text,attempts,max_attempts FROM attachment_jobs WHERE state='processing' AND lease_until= l.max { + state = "failed" + v := "retry_exhausted" + code = &v + } + if _, err = tx.Exec(ctx, `UPDATE attachment_jobs SET state=$2,lease_until=NULL,available_at=clock_timestamp(),updated_at=clock_timestamp(),last_error='worker_lost' WHERE id=$1`, l.id, state); err != nil { + return err + } + if _, err = tx.Exec(ctx, `UPDATE attachments SET status=$2,error_code=$3,updated_at=clock_timestamp() WHERE id=$1`, l.att, state, code); err != nil { + return err + } + if state == "queued" { + if _, err = tx.Exec(ctx, `UPDATE attachment_outbox SET published_at=NULL,available_at=clock_timestamp() WHERE job_id=$1`, l.id); err != nil { + return err + } + } + } + return tx.Commit(ctx) +} +func (s *Service) claim(ctx context.Context, m JobMessage) (claimed, bool, error) { + j := claimed{JobMessage: m} + tx, err := s.Pool.Begin(ctx) + if err != nil { + return j, false, err + } + defer tx.Rollback(context.Background()) + var state string + var attempts, max, version int + var available time.Time + err = tx.QueryRow(ctx, `SELECT state,attempts,max_attempts,available_at,pipeline_version FROM attachment_jobs WHERE id=$1 AND attachment_id=$2 FOR UPDATE`, m.JobID, m.AttachmentID).Scan(&state, &attempts, &max, &available, &version) + if errors.Is(err, pgx.ErrNoRows) { + return j, false, nil + } + if err != nil { + return j, false, err + } + if state == "ready" { + var key, mime string + var size int64 + var raw []byte + if err = tx.QueryRow(ctx, `SELECT object_key,content_type,size_bytes,variants FROM attachments WHERE id=$1 AND status='ready' AND pipeline_version=$2`, m.AttachmentID, version).Scan(&key, &mime, &size, &raw); err != nil { + return j, false, err + } + var variants []Variant + if err = json.Unmarshal(raw, &variants); err != nil || len(variants) != 3 { + return j, false, fmt.Errorf("completed effect metadata incomplete") + } + objects := map[string]int64{key: size} + for _, v := range variants { + objects[effectKey(m.AttachmentID, version, v.Name)] = v.Size + } + for object, n := range objects { + info, e := s.Store.Client.StatObject(ctx, s.Store.Bucket, object, minio.StatObjectOptions{}) + if e != nil { + return j, false, e + } + if info.Size != n { + return j, false, fmt.Errorf("completed effect size mismatch") + } + } + return j, false, nil + } + if state != "queued" || available.After(time.Now()) || m.Attempt != attempts+1 || version != m.PipelineVersion { + return j, false, nil + } + if attempts >= max { + return j, false, fmt.Errorf("attempt invariant violated") + } + err = tx.QueryRow(ctx, `UPDATE attachment_jobs SET state='processing',attempts=attempts+1,fence=fence+1,lease_until=clock_timestamp()+$2*interval '1 second',updated_at=clock_timestamp() WHERE id=$1 RETURNING fence`, m.JobID, s.Options.Lease.Seconds()).Scan(&j.Fence) + if err != nil { + return j, false, err + } + err = tx.QueryRow(ctx, `UPDATE attachments SET status='processing',updated_at=clock_timestamp() WHERE id=$1 AND pipeline_version=$2 AND status IN ('queued','processing') RETURNING staging_key,object_key,content_type,size_bytes,sha256,width,height`, m.AttachmentID, version).Scan(&j.Stage, &j.Original, &j.MIME, &j.Size, &j.SHA, &j.Width, &j.Height) + if err != nil { + return j, false, err + } + return j, true, tx.Commit(ctx) +} + +// finish publishes metadata only for the current, unexpired fencing token. +func (s *Service) finish(ctx context.Context, j claimed, variants []Variant, code string, permanent bool) (bool, error) { + tx, err := s.Pool.Begin(ctx) + if err != nil { + return false, err + } + defer tx.Rollback(context.Background()) + var max int + err = tx.QueryRow(ctx, `SELECT max_attempts FROM attachment_jobs WHERE id=$1 AND fence=$2 AND state='processing' AND lease_until>clock_timestamp() AND pipeline_version=$3 FOR UPDATE`, j.JobID, j.Fence, j.PipelineVersion).Scan(&max) + if errors.Is(err, pgx.ErrNoRows) { + return false, nil + } + if err != nil { + return false, err + } + lastError := code + state := "ready" + var failure *string + available := time.Now() + if code != "" { + state = "queued" + if permanent || j.Attempt >= max { + state = "failed" + if !permanent { + code = "retry_exhausted" + } + failure = &code + } + delay := time.Duration(1< 0 { + op, cancel = context.WithTimeout(ctx, time.Second) + streams, e := r.XReadGroup(op, &redis.XReadGroupArgs{Group: Group, Consumer: consumer, Streams: []string{Stream, ">"}, Count: int64(room), Block: 100 * time.Millisecond}).Result() + cancel() + if e == nil { + for _, stream := range streams { + for _, m := range stream.Messages { + select { + case queue <- m: + case <-ctx.Done(): + return nil + } + } + } + } + } + if time.Since(lastCleanup) >= 5*time.Second { + lastCleanup = time.Now() + op, cancel = context.WithTimeout(ctx, 5*time.Second) + s.cleanStages(op) + cancel() + } + } +} +func ack(ctx context.Context, r *redis.Client, id string) { + if r.XAck(ctx, Stream, Group, id).Err() == nil { + r.XDel(ctx, Stream, id) + } +} + +// Replay is an explicit operator action, serialized with admission and job claims. +// It preserves job/effect identity and refuses already successful work. +func (s *Service) Replay(ctx context.Context, id, operator, reason string) error { + if uuid.Validate(id) != nil || len(operator) < 1 || len(operator) > 100 || len(reason) < 1 || len(reason) > 300 { + return fmt.Errorf("job UUID, operator and reason are required") + } + tx, err := s.Pool.Begin(ctx) + if err != nil { + return err + } + defer tx.Rollback(context.Background()) + if _, err = tx.Exec(ctx, `SELECT pg_advisory_xact_lock(578903551)`); err != nil { + return err + } + var pending int + if err = tx.QueryRow(ctx, `SELECT count(*) FROM attachment_jobs WHERE state IN ('queued','processing')`).Scan(&pending); err != nil { + return err + } + if pending >= s.Options.MaxOutstanding { + return fmt.Errorf("admission limit reached") + } + var att, state, previous string + err = tx.QueryRow(ctx, `SELECT attachment_id::text,state,coalesce(last_error,'processing_failed') FROM attachment_jobs WHERE id=$1 FOR UPDATE`, id).Scan(&att, &state, &previous) + if err != nil { + return err + } + if state != "failed" { + return fmt.Errorf("only failed jobs may be replayed") + } + var stage *string + if err = tx.QueryRow(ctx, `SELECT staging_key FROM attachments WHERE id=$1 FOR UPDATE`, att).Scan(&stage); err != nil { + return err + } + if stage == nil { + return fmt.Errorf("staging retention expired") + } + if _, err = s.Store.Client.StatObject(ctx, s.Store.Bucket, *stage, minio.StatObjectOptions{}); err != nil { + return fmt.Errorf("staging unavailable") + } + if _, err = tx.Exec(ctx, `INSERT INTO attachment_replays(job_id,operator,reason,previous_error) VALUES($1,$2,$3,$4)`, id, operator, reason, previous); err != nil { + return err + } + if _, err = tx.Exec(ctx, `UPDATE attachment_jobs SET state='queued',attempts=0,fence=fence+1,last_error=NULL,available_at=clock_timestamp(),updated_at=clock_timestamp() WHERE id=$1`, id); err != nil { + return err + } + if _, err = tx.Exec(ctx, `UPDATE attachments SET status='queued',error_code=NULL,updated_at=clock_timestamp() WHERE id=$1`, att); err != nil { + return err + } + if _, err = tx.Exec(ctx, `UPDATE attachment_outbox SET published_at=NULL,available_at=clock_timestamp() WHERE job_id=$1`, id); err != nil { + return err + } + return tx.Commit(ctx) +} + +// Keep failed stages for seven days for explicit replay; ready stages are garbage. +func (s *Service) cleanStages(ctx context.Context) { + rows, err := s.Pool.Query(ctx, `SELECT id::text FROM attachments WHERE (status='ready' AND staging_key IS NOT NULL) OR (status='failed' AND updated_at max { + return 0, fmt.Errorf("invalid %s", name) + } + return n, nil +} +func secret(name string) (string, error) { + if file := os.Getenv(name + "_FILE"); file != "" { + data, err := os.ReadFile(file) + if err != nil { + return "", fmt.Errorf("cannot read %s_FILE", name) + } + if s := strings.TrimSpace(string(data)); s != "" { + return s, nil + } + } + if s := os.Getenv(name); s != "" { + return s, nil + } + return "", fmt.Errorf("%s or %s_FILE is required", name, name) +} + +func Load() (Config, error) { + var c Config + port, err := positive("PORT", 8080, 65535) + if err != nil { + return c, err + } + c.Port = strconv.Itoa(port) + pgPort, err := positive("POSTGRES_PORT", 5432, 65535) + if err != nil { + return c, err + } + c.PostgresPort = uint16(pgPort) + max, err := positive("POSTGRES_MAX_CONNS", 10, 100) + if err != nil { + return c, err + } + c.PostgresMaxConns = int32(max) + ttl, err := positive("SESSION_TTL_SECONDS", 3600, 86400*30) + if err != nil { + return c, err + } + c.SessionTTL = time.Duration(ttl) * time.Second + timeout, err := positive("QUERY_TIMEOUT_MS", 2000, 10000) + if err != nil { + return c, err + } + c.QueryTimeout = time.Duration(timeout) * time.Millisecond + c.PostgresHost = value("POSTGRES_HOST", "localhost") + c.PostgresUser = value("POSTGRES_USER", "messenger") + c.PostgresDatabase = value("POSTGRES_DB", "messenger") + c.RedisAddr = value("REDIS_ADDR", "localhost:6379") + c.PostgresPassword, err = secret("POSTGRES_PASSWORD") + if err != nil { + return c, err + } + key, err := secret("CURSOR_KEY") + if err != nil { + return c, err + } + decoded, err := hex.DecodeString(key) + if err != nil || len(decoded) != 32 { + return c, fmt.Errorf("CURSOR_KEY must be 32 random bytes encoded as hex") + } + copy(c.CursorKey[:], decoded) + c.S3Endpoint = value("S3_ENDPOINT", "minio:9000") + c.S3Bucket = value("S3_BUCKET", "attachments") + c.S3UseSSL, err = strconv.ParseBool(value("S3_USE_SSL", "false")) + if err != nil { + return c, fmt.Errorf("invalid S3_USE_SSL") + } + c.S3AccessKey, err = secret("S3_ACCESS_KEY") + if err != nil { + return c, err + } + c.S3SecretKey, err = secret("S3_SECRET_KEY") + if err != nil { + return c, err + } + return c, nil +} diff --git a/internal/pkg/domain/chat.go b/internal/pkg/domain/chat.go new file mode 100644 index 00000000..2de7174e --- /dev/null +++ b/internal/pkg/domain/chat.go @@ -0,0 +1,10 @@ +package domain + +import "time" + +type Chat struct { + ID string + Title string + MemberIDs []string + CreatedAt time.Time +} diff --git a/internal/pkg/domain/errors.go b/internal/pkg/domain/errors.go new file mode 100644 index 00000000..a8447d22 --- /dev/null +++ b/internal/pkg/domain/errors.go @@ -0,0 +1,32 @@ +package domain + +import "errors" + +type ErrorCode string + +const ( + ErrorUnavailable ErrorCode = "unavailable" + ErrorInvalid ErrorCode = "invalid_request" + ErrorUnauthorized ErrorCode = "unauthorized" + ErrorNotFound ErrorCode = "not_found" + ErrorConflict ErrorCode = "conflict" +) + +type ApplicationError struct { + Code ErrorCode + Message string +} + +func (e *ApplicationError) Error() string { + return e.Message +} + +func NewApplicationError(code ErrorCode, message string) error { + return &ApplicationError{Code: code, Message: message} +} + +func AsApplicationError(err error) (*ApplicationError, bool) { + var applicationError *ApplicationError + ok := errors.As(err, &applicationError) + return applicationError, ok +} diff --git a/internal/pkg/domain/message.go b/internal/pkg/domain/message.go new file mode 100644 index 00000000..34879969 --- /dev/null +++ b/internal/pkg/domain/message.go @@ -0,0 +1,13 @@ +package domain + +import "time" + +type Message struct { + IdempotencyKey string + ID string + ChatID string + SenderID string + AttachmentIDs []string + Text string + CreatedAt time.Time +} diff --git a/internal/pkg/domain/pagination.go b/internal/pkg/domain/pagination.go new file mode 100644 index 00000000..d3ab68f4 --- /dev/null +++ b/internal/pkg/domain/pagination.go @@ -0,0 +1,23 @@ +package domain + +import "time" + +type Position struct { + CreatedAt time.Time + ID string +} + +type Pagination struct { + After *Position + Limit int +} + +type ChatPage struct { + Items []Chat + HasMore bool +} + +type MessagePage struct { + Items []Message + HasMore bool +} diff --git a/internal/pkg/domain/session.go b/internal/pkg/domain/session.go new file mode 100644 index 00000000..50029b96 --- /dev/null +++ b/internal/pkg/domain/session.go @@ -0,0 +1,14 @@ +package domain + +import "time" + +type Session struct { + UserID string `json:"user_id"` + ExpiresAt time.Time `json:"expires_at"` +} + +type Login struct { + Token string + ExpiresAt time.Time + User User +} diff --git a/internal/pkg/domain/user.go b/internal/pkg/domain/user.go new file mode 100644 index 00000000..34d52353 --- /dev/null +++ b/internal/pkg/domain/user.go @@ -0,0 +1,10 @@ +package domain + +import "time" + +type User struct { + ID string + Username string + DisplayName string + CreatedAt time.Time +} diff --git a/internal/pkg/password/password.go b/internal/pkg/password/password.go new file mode 100644 index 00000000..1280dca7 --- /dev/null +++ b/internal/pkg/password/password.go @@ -0,0 +1,65 @@ +package password + +import ( + "context" + "crypto/rand" + "crypto/subtle" + "encoding/base64" + "errors" + "strings" + + "golang.org/x/crypto/argon2" +) + +// Bound simultaneous KDF work to 4 * 19 MiB, including concurrent registrations. +var slots = make(chan struct{}, 4) + +const prefix = "$argon2id$v=19$m=19456,t=2,p=1$" + +func derive(ctx context.Context, password string, salt []byte) ([]byte, error) { + select { + case slots <- struct{}{}: + case <-ctx.Done(): + return nil, ctx.Err() + } + defer func() { <-slots }() + if err := ctx.Err(); err != nil { + return nil, err + } + return argon2.IDKey([]byte(password), salt, 2, 19456, 1, 32), nil +} + +func Hash(ctx context.Context, password string) (string, error) { + salt := make([]byte, 16) + if _, err := rand.Read(salt); err != nil { + return "", err + } + key, err := derive(ctx, password, salt) + if err != nil { + return "", err + } + return prefix + base64.RawStdEncoding.EncodeToString(salt) + "$" + base64.RawStdEncoding.EncodeToString(key), nil +} + +func Verify(ctx context.Context, password, encoded string) (bool, error) { + if !strings.HasPrefix(encoded, prefix) { + return false, errors.New("unsupported password hash") + } + parts := strings.Split(strings.TrimPrefix(encoded, prefix), "$") + if len(parts) != 2 { + return false, errors.New("invalid password hash") + } + salt, err := base64.RawStdEncoding.DecodeString(parts[0]) + if err != nil || len(salt) != 16 { + return false, errors.New("invalid salt") + } + expected, err := base64.RawStdEncoding.DecodeString(parts[1]) + if err != nil || len(expected) != 32 { + return false, errors.New("invalid hash") + } + actual, err := derive(ctx, password, salt) + return subtle.ConstantTimeCompare(actual, expected) == 1, err +} + +// A valid fixed encoding for equal-cost verification when username does not exist. +const DummyHash = prefix + "AAAAAAAAAAAAAAAAAAAAAA$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" diff --git a/internal/pkg/password/password_test.go b/internal/pkg/password/password_test.go new file mode 100644 index 00000000..6a0ef969 --- /dev/null +++ b/internal/pkg/password/password_test.go @@ -0,0 +1,35 @@ +package password_test + +import ( + "context" + "strings" + "testing" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/password" +) + +func TestUnicodeAndSalt(t *testing.T) { + ctx := context.Background() + secret := strings.Repeat("🔑", 128) + first, err := password.Hash(ctx, secret) + if err != nil { + t.Fatal(err) + } + second, err := password.Hash(ctx, secret) + if err != nil { + t.Fatal(err) + } + if first == second { + t.Fatal("password hashes reused salt") + } + for _, hash := range []string{first, second} { + ok, err := password.Verify(ctx, secret, hash) + if err != nil || !ok { + t.Fatal("128-code-point UTF-8 password rejected") + } + ok, err = password.Verify(ctx, strings.Repeat("🔑", 127)+"x", hash) + if err != nil || ok { + t.Fatal("password suffix was ignored") + } + } +} diff --git a/internal/pkg/repository/memory.go b/internal/pkg/repository/memory.go new file mode 100644 index 00000000..1c269015 --- /dev/null +++ b/internal/pkg/repository/memory.go @@ -0,0 +1,202 @@ +package repository + +import ( + "context" + "sort" + "sync" + "time" + + "github.com/google/uuid" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" + chatusecase "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/usecase/chat" +) + +// Memory is the lab1 in-memory Repository implementation. +type Memory struct { + mu sync.RWMutex + users map[string]domain.User + hashes map[string]string + userByUsername map[string]string + chats map[string]domain.Chat + messages map[string][]domain.Message +} + +var _ chatusecase.Repository = (*Memory)(nil) + +func NewMemory() *Memory { + return &Memory{ + users: make(map[string]domain.User), + hashes: make(map[string]string), + userByUsername: make(map[string]string), + chats: make(map[string]domain.Chat), + messages: make(map[string][]domain.Message), + } +} + +func (m *Memory) CreateUser(_ context.Context, username, displayName, hash string) (domain.User, error) { + m.mu.Lock() + defer m.mu.Unlock() + + if _, exists := m.userByUsername[username]; exists { + return domain.User{}, chatusecase.ErrUsernameTaken + } + user := domain.User{ + ID: uuid.NewString(), + Username: username, + DisplayName: displayName, + CreatedAt: now(), + } + m.users[user.ID] = user + m.hashes[user.ID] = hash + m.userByUsername[user.Username] = user.ID + return user, nil +} + +func (m *Memory) User(_ context.Context, id string) (domain.User, bool, error) { + m.mu.RLock() + defer m.mu.RUnlock() + user, ok := m.users[id] + return user, ok, nil +} + +func (m *Memory) CreateChat(_ context.Context, title string, memberIDs []string) (domain.Chat, error) { + m.mu.Lock() + defer m.mu.Unlock() + + for _, memberID := range memberIDs { + if _, exists := m.users[memberID]; !exists { + return domain.Chat{}, chatusecase.ErrUserNotFound + } + } + chat := domain.Chat{ + ID: uuid.NewString(), + Title: title, + MemberIDs: append([]string(nil), memberIDs...), + CreatedAt: now(), + } + m.chats[chat.ID] = chat + return cloneChat(chat), nil +} + +func (m *Memory) ChatForUser(_ context.Context, chatID, userID string) (domain.Chat, error) { + m.mu.RLock() + defer m.mu.RUnlock() + chat, exists := m.chats[chatID] + if !exists { + return domain.Chat{}, chatusecase.ErrChatNotFound + } + if !contains(chat.MemberIDs, userID) { + return domain.Chat{}, chatusecase.ErrNotMember + } + return cloneChat(chat), nil +} + +func (m *Memory) ListChats(_ context.Context, userID string, after *domain.Position, limit int) ([]domain.Chat, error) { + m.mu.RLock() + defer m.mu.RUnlock() + + result := make([]domain.Chat, 0) + for _, chat := range m.chats { + if contains(chat.MemberIDs, userID) && isAfter(chat.CreatedAt, chat.ID, after) { + result = append(result, cloneChat(chat)) + } + } + sort.Slice(result, func(i, j int) bool { + return less(result[i].CreatedAt, result[i].ID, result[j].CreatedAt, result[j].ID) + }) + if len(result) > limit { + result = result[:limit] + } + return result, nil +} + +func (m *Memory) CreateMessage(_ context.Context, chatID, senderID, text, key string) (domain.Message, error) { + m.mu.Lock() + defer m.mu.Unlock() + + chat, exists := m.chats[chatID] + if !exists { + return domain.Message{}, chatusecase.ErrChatNotFound + } + if !contains(chat.MemberIDs, senderID) { + return domain.Message{}, chatusecase.ErrNotMember + } + if key != "" { + for _, previous := range m.messages[chatID] { + if previous.SenderID == senderID && previous.IdempotencyKey == key { + if previous.Text != text { + return domain.Message{}, domain.NewApplicationError(domain.ErrorConflict, "Idempotency-Key уже использован с другим телом") + } + return previous, nil + } + } + } + message := domain.Message{ + IdempotencyKey: key, + ID: uuid.NewString(), + ChatID: chatID, + SenderID: senderID, + Text: text, + CreatedAt: now(), + } + m.messages[chatID] = append(m.messages[chatID], message) + return message, nil +} + +func (m *Memory) ListMessages(_ context.Context, chatID string, after *domain.Position, limit int) ([]domain.Message, error) { + m.mu.RLock() + defer m.mu.RUnlock() + + values := m.messages[chatID] + result := make([]domain.Message, 0, min(len(values), limit)) + for _, message := range values { + if isAfter(message.CreatedAt, message.ID, after) { + result = append(result, message) + } + } + sort.Slice(result, func(i, j int) bool { + return less(result[i].CreatedAt, result[i].ID, result[j].CreatedAt, result[j].ID) + }) + if len(result) > limit { + result = result[:limit] + } + return result, nil +} + +func cloneChat(chat domain.Chat) domain.Chat { + chat.MemberIDs = append([]string(nil), chat.MemberIDs...) + return chat +} + +func now() time.Time { + return time.Now().UTC().Truncate(time.Second) +} + +func contains(values []string, target string) bool { + for _, value := range values { + if value == target { + return true + } + } + return false +} + +func isAfter(createdAt time.Time, id string, after *domain.Position) bool { + return after == nil || createdAt.After(after.CreatedAt) || createdAt.Equal(after.CreatedAt) && id > after.ID +} + +func less(leftTime time.Time, leftID string, rightTime time.Time, rightID string) bool { + if leftTime.Equal(rightTime) { + return leftID < rightID + } + return leftTime.Before(rightTime) +} + +func (m *Memory) Ready(context.Context) error { return nil } +func (m *Memory) UserByUsername(_ context.Context, username string) (domain.User, string, bool, error) { + m.mu.RLock() + defer m.mu.RUnlock() + id, ok := m.userByUsername[username] + return m.users[id], m.hashes[id], ok, nil +} diff --git a/internal/pkg/repository/postgres/chats.go b/internal/pkg/repository/postgres/chats.go new file mode 100644 index 00000000..60c9051c --- /dev/null +++ b/internal/pkg/repository/postgres/chats.go @@ -0,0 +1,78 @@ +package postgres + +import ( + "context" + "errors" + + "github.com/google/uuid" + "github.com/jackc/pgx/v5" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" + chatusecase "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/usecase/chat" +) + +func (s *Storage) CreateChat(ctx context.Context, title string, members []string) (domain.Chat, error) { + ctx, cancel := context.WithTimeout(ctx, s.timeout) + defer cancel() + tx, err := s.pool.Begin(ctx) + if err != nil { + return domain.Chat{}, dbError(err) + } + defer tx.Rollback(context.WithoutCancel(ctx)) + chat := domain.Chat{ID: uuid.NewString(), Title: title, MemberIDs: append([]string(nil), members...)} + err = tx.QueryRow(ctx, `INSERT INTO chats(id,title) VALUES($1,$2) RETURNING created_at`, chat.ID, title).Scan(&chat.CreatedAt) + if err != nil { + return domain.Chat{}, dbError(err) + } + for i, member := range members { + if _, err = tx.Exec(ctx, `INSERT INTO chat_members(chat_id,user_id,ordinal) VALUES($1,$2,$3)`, chat.ID, member, i); err != nil { + return domain.Chat{}, dbError(err) + } + } + if err = tx.Commit(ctx); err != nil { + return domain.Chat{}, dbError(err) + } + return chat, nil +} + +const chatColumns = `c.id::text,c.title,c.created_at,ARRAY(SELECT m.user_id::text FROM chat_members m WHERE m.chat_id=c.id ORDER BY m.ordinal)` + +func (s *Storage) ChatForUser(ctx context.Context, chatID, userID string) (domain.Chat, error) { + ctx, cancel := context.WithTimeout(ctx, s.timeout) + defer cancel() + var chat domain.Chat + err := s.pool.QueryRow(ctx, `SELECT `+chatColumns+` FROM chats c + WHERE c.id=$1 AND EXISTS(SELECT 1 FROM chat_members m WHERE m.chat_id=c.id AND m.user_id=$2)`, chatID, userID). + Scan(&chat.ID, &chat.Title, &chat.CreatedAt, &chat.MemberIDs) + if errors.Is(err, pgx.ErrNoRows) { + return chat, chatusecase.ErrChatNotFound + } + return chat, dbError(err) +} + +func (s *Storage) ListChats(ctx context.Context, userID string, after *domain.Position, limit int) ([]domain.Chat, error) { + ctx, cancel := context.WithTimeout(ctx, s.timeout) + defer cancel() + query := `SELECT ` + chatColumns + ` FROM chats c JOIN chat_members member ON member.chat_id=c.id + WHERE member.user_id=$1` + args := []any{userID, limit} + if after != nil { + query += ` AND (c.created_at,c.id)>($3,$4)` + args = append(args, after.CreatedAt, after.ID) + } + query += ` ORDER BY c.created_at,c.id LIMIT $2` + rows, err := s.pool.Query(ctx, query, args...) + if err != nil { + return nil, dbError(err) + } + defer rows.Close() + chats := make([]domain.Chat, 0) + for rows.Next() { + var chat domain.Chat + if err = rows.Scan(&chat.ID, &chat.Title, &chat.CreatedAt, &chat.MemberIDs); err != nil { + return nil, dbError(err) + } + chats = append(chats, chat) + } + return chats, dbError(rows.Err()) +} diff --git a/internal/pkg/repository/postgres/lab4_test.go b/internal/pkg/repository/postgres/lab4_test.go new file mode 100644 index 00000000..c4adf4ef --- /dev/null +++ b/internal/pkg/repository/postgres/lab4_test.go @@ -0,0 +1,346 @@ +package postgres_test + +import ( + "bufio" + "bytes" + "context" + "encoding/xml" + "fmt" + "image" + "image/png" + "io" + "net/http" + "net/http/httptest" + "strconv" + "strings" + "sync" + "testing" + "time" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/attachment" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/repository/postgres" + "github.com/google/uuid" + "github.com/jackc/pgx/v5/pgxpool" + "github.com/minio/minio-go/v7" + "github.com/minio/minio-go/v7/pkg/credentials" +) + +type fakeObject struct { + data []byte + modified time.Time +} +type fakeS3 struct { + mu sync.Mutex + objects map[string]fakeObject + failPUT bool +} + +func (f *fakeS3) ServeHTTP(w http.ResponseWriter, r *http.Request) { + f.mu.Lock() + defer f.mu.Unlock() + key := strings.TrimPrefix(r.URL.Path, "/attachments/") + if r.Method == "GET" && r.URL.Path == "/attachments/" || r.Method == "GET" && r.URL.Path == "/attachments" { + type item struct { + Key string + LastModified string + ETag string + Size int + } + type listing struct { + XMLName xml.Name `xml:"ListBucketResult"` + Xmlns string `xml:"xmlns,attr"` + Name string + Prefix string + MaxKeys int + IsTruncated bool + Contents []item + } + l := listing{Xmlns: "http://s3.amazonaws.com/doc/2006-03-01/", Name: "attachments", Prefix: r.URL.Query().Get("prefix"), MaxKeys: 1000} + for k, v := range f.objects { + if strings.HasPrefix(k, l.Prefix) { + l.Contents = append(l.Contents, item{Key: k, LastModified: v.modified.UTC().Format("2006-01-02T15:04:05.000Z"), ETag: `"abc"`, Size: len(v.data)}) + } + } + w.Header().Set("Content-Type", "application/xml") + xml.NewEncoder(w).Encode(l) + return + } + if r.Method == "PUT" { + if f.failPUT { + w.WriteHeader(503) + fmt.Fprint(w, `ServiceUnavailable`) + return + } + var data []byte + var err error + if strings.Contains(r.Header.Get("Content-Encoding"), "aws-chunked") || strings.HasPrefix(r.Header.Get("X-Amz-Content-Sha256"), "STREAMING-") { + reader := bufio.NewReader(r.Body) + for { + line, e := reader.ReadString('\n') + if e != nil { + err = e + break + } + size, e := strconv.ParseInt(strings.Split(strings.TrimSpace(line), ";")[0], 16, 64) + if e != nil { + err = e + break + } + if size == 0 { + break + } + chunk := make([]byte, size) + if _, e = io.ReadFull(reader, chunk); e != nil { + err = e + break + } + data = append(data, chunk...) + if _, e = reader.Discard(2); e != nil { + err = e + break + } + } + } else { + data, err = io.ReadAll(r.Body) + } + if err != nil { + w.WriteHeader(400) + return + } + f.objects[key] = fakeObject{data: data, modified: time.Now().UTC()} + w.Header().Set("ETag", `"900150983cd24fb0d6963f7d28e17f72"`) + w.WriteHeader(200) + return + } + obj, ok := f.objects[key] + if !ok { + w.WriteHeader(404) + if r.Method != "HEAD" { + fmt.Fprint(w, `NoSuchKey`) + } + return + } + if r.Method == "DELETE" { + delete(f.objects, key) + w.WriteHeader(204) + return + } + w.Header().Set("Last-Modified", obj.modified.UTC().Format(http.TimeFormat)) + w.Header().Set("ETag", `"abc"`) + w.Header().Set("Content-Length", fmt.Sprint(len(obj.data))) + w.Header().Set("Content-Type", "image/png") + if r.Method == "GET" { + w.Write(obj.data) + } +} +func lab4Backend(t *testing.T, pool *pgxpool.Pool, repo *postgres.Storage, user domain.User, chat domain.Chat) { + ctx := context.Background() + fake := &fakeS3{objects: map[string]fakeObject{}} + server := httptest.NewServer(fake) + defer server.Close() + client, err := minio.New(strings.TrimPrefix(server.URL, "http://"), &minio.Options{Creds: credentials.NewStaticV4("test-key", "test-secret", ""), Region: "us-east-1", MaxRetries: 1}) + if err != nil { + t.Fatal(err) + } + service := attachment.New(pool, &attachment.Store{Client: client, Bucket: "attachments"}) + var imageBytes bytes.Buffer + if err = png.Encode(&imageBytes, image.NewRGBA(image.Rect(0, 0, 10, 8))); err != nil { + t.Fatal(err) + } + upload := func(name string) attachment.Attachment { + t.Helper() + a, e := service.Upload(ctx, chat.ID, user.ID, name, "image/png", bytes.NewReader(imageBytes.Bytes())) + if e != nil { + t.Fatal(e) + } + return a + } + first := upload("first.png") + second := upload("second.png") + requireCode := func(err error, want domain.ErrorCode) { + t.Helper() + e, ok := domain.AsApplicationError(err) + if !ok || e.Code != want { + t.Fatalf("expected %s, got %v", want, err) + } + } + outside, err := repo.CreateUser(ctx, "attachment_outsider", "Outside", "hash") + if err != nil { + t.Fatal(err) + } + _, err = service.Get(ctx, first.ID, outside.ID) + requireCode(err, domain.ErrorNotFound) + obj, err := service.Content(ctx, first) + if err != nil { + t.Fatal(err) + } + data, err := io.ReadAll(obj) + obj.Close() + if err != nil || !bytes.Equal(data, imageBytes.Bytes()) { + t.Fatalf("original mismatch: %v", err) + } + otherChat, err := repo.CreateChat(ctx, "Other", []string{user.ID}) + if err != nil { + t.Fatal(err) + } + _, err = repo.CreateMessageWithAttachments(ctx, otherChat.ID, user.ID, "", "cross-chat", []string{first.ID}) + requireCode(err, domain.ErrorNotFound) + _, err = repo.CreateMessageWithAttachments(ctx, chat.ID, user.ID, "", "unknown", []string{uuid.NewString()}) + requireCode(err, domain.ErrorNotFound) + sent, err := repo.CreateMessageWithAttachments(ctx, chat.ID, user.ID, "", "ordered", []string{first.ID, second.ID}) + if err != nil { + t.Fatal(err) + } + replay, err := repo.CreateMessageWithAttachments(ctx, chat.ID, user.ID, "", "ordered", []string{first.ID, second.ID}) + if err != nil || sent.ID != replay.ID { + t.Fatalf("replay failed: %v", err) + } + _, err = repo.CreateMessageWithAttachments(ctx, chat.ID, user.ID, "", "ordered", []string{second.ID, first.ID}) + requireCode(err, domain.ErrorConflict) + textOnly, err := repo.CreateMessageWithAttachments(ctx, chat.ID, user.ID, "text", "empty-equivalent", nil) + if err != nil { + t.Fatal(err) + } + replay, err = repo.CreateMessageWithAttachments(ctx, chat.ID, user.ID, "text", "empty-equivalent", []string{}) + if err != nil || textOnly.ID != replay.ID { + t.Fatalf("absent/empty differs: %v", err) + } + + const callers = 12 + outcomes := make(chan domain.Message, callers) + failures := make(chan error, callers) + var concurrent sync.WaitGroup + start := make(chan struct{}) + for i := 0; i < callers; i++ { + concurrent.Add(1) + go func() { + defer concurrent.Done() + <-start + m, e := repo.CreateMessageWithAttachments(ctx, chat.ID, user.ID, "", "concurrent-attachments", []string{first.ID, second.ID}) + if e != nil { + failures <- e + } else { + outcomes <- m + } + }() + } + close(start) + concurrent.Wait() + close(outcomes) + close(failures) + for e := range failures { + t.Fatal(e) + } + identity := "" + for m := range outcomes { + if identity == "" { + identity = m.ID + } + if m.ID != identity { + t.Fatal("duplicate concurrent attachment message") + } + } + var effects int + if err = pool.QueryRow(ctx, `SELECT count(*) FROM messages WHERE chat_id=$1 AND idempotency_key='concurrent-attachments'`, chat.ID).Scan(&effects); err != nil || effects != 1 { + t.Fatalf("concurrent effects=%d %v", effects, err) + } + t.Log("ACL, original bytes, cross-chat attachment rejection, ordered/concurrent idempotency and absent=[] passed") + + old := time.Now().Add(-3 * time.Minute) + orphan := "original/" + uuid.NewString() + fresh := "original/" + uuid.NewString() + locked := "original/" + uuid.NewString() + fake.mu.Lock() + delete(fake.objects, first.Key) + v := fake.objects[second.Key] + v.modified = old + fake.objects[second.Key] = v + fake.objects[orphan] = fakeObject{data: []byte("orphan"), modified: old} + fake.objects[fresh] = fakeObject{data: []byte("fresh"), modified: time.Now()} + fake.objects[locked] = fakeObject{data: []byte("locked"), modified: old} + fake.objects["original/legacy-staging"] = fakeObject{data: []byte("legacy stage"), modified: old} + fake.mu.Unlock() + if _, err = pool.Exec(ctx, `UPDATE attachments SET staging_key='original/legacy-staging' WHERE id=$1`, second.ID); err != nil { + t.Fatal(err) + } + if _, err = pool.Exec(ctx, `UPDATE attachments SET created_at=$1 WHERE id=ANY($2::uuid[])`, old, []string{first.ID, second.ID}); err != nil { + t.Fatal(err) + } + hold, err := pool.Begin(ctx) + if err != nil { + t.Fatal(err) + } + defer hold.Rollback(ctx) + if _, err = hold.Exec(ctx, `SELECT pg_advisory_xact_lock(hashtextextended($1,0))`, locked); err != nil { + t.Fatal(err) + } + dry, err := service.Reconcile(ctx, false, 90*time.Second) + if err != nil { + t.Fatal(err) + } + if dry.Orphans != 1 || dry.Missing != 1 || dry.ReferencedMissing != 1 || dry.LockedSkipped != 1 || dry.FreshSkipped < 1 || dry.Deleted != 0 || dry.MarkedFailed != 0 { + t.Fatalf("bad dry-run %+v", dry) + } + var status string + if err = pool.QueryRow(ctx, `SELECT status FROM attachments WHERE id=$1`, first.ID).Scan(&status); err != nil || status != "ready" { + t.Fatalf("dry-run mutated metadata %s %v", status, err) + } + applied, err := service.Reconcile(ctx, true, 90*time.Second) + if err != nil { + t.Fatal(err) + } + if applied.Deleted != 1 || applied.MarkedFailed != 1 { + t.Fatalf("bad apply %+v", applied) + } + fake.mu.Lock() + _, hasOrphan := fake.objects[orphan] + _, hasFresh := fake.objects[fresh] + _, hasLinked := fake.objects[second.Key] + _, hasLocked := fake.objects[locked] + _, hasLegacyStage := fake.objects["original/legacy-staging"] + fake.mu.Unlock() + if hasOrphan || !hasFresh || !hasLinked || !hasLocked || !hasLegacyStage { + t.Fatal("unsafe object cleanup") + } + _, err = service.Get(ctx, first.ID, user.ID) + requireCode(err, domain.ErrorConflict) + _, err = repo.CreateMessageWithAttachments(ctx, chat.ID, user.ID, "", "failed-attachment", []string{first.ID}) + requireCode(err, domain.ErrorConflict) + replay, err = repo.CreateMessageWithAttachments(ctx, chat.ID, user.ID, "", "ordered", []string{first.ID, second.ID}) + if err != nil || replay.ID != sent.ID { + t.Fatalf("historical replay changed after missing: %v", err) + } + repeated, err := service.Reconcile(ctx, true, 90*time.Second) + if err != nil { + t.Fatal(err) + } + if repeated.Deleted != 0 || repeated.MarkedFailed != 0 || repeated.Orphans != 0 || repeated.Missing != 0 { + t.Fatalf("not repeatable %+v", repeated) + } + t.Logf("dry-run=%+v apply=%+v repeat=%+v; fresh, locked and referenced objects retained", dry, applied, repeated) +} + +func TestS3WireFixture(t *testing.T) { + fake := &fakeS3{objects: map[string]fakeObject{}} + server := httptest.NewServer(fake) + defer server.Close() + client, err := minio.New(strings.TrimPrefix(server.URL, "http://"), &minio.Options{Creds: credentials.NewStaticV4("test-key", "test-secret", ""), Region: "us-east-1", MaxRetries: 1}) + if err != nil { + t.Fatal(err) + } + payload := []byte("exact object bytes") + _, err = client.PutObject(context.Background(), "attachments", "original/test", bytes.NewReader(payload), int64(len(payload)), minio.PutObjectOptions{ContentType: "image/png", DisableMultipart: true}) + if err != nil { + t.Fatal(err) + } + obj, err := client.GetObject(context.Background(), "attachments", "original/test", minio.GetObjectOptions{}) + if err != nil { + t.Fatal(err) + } + defer obj.Close() + got, err := io.ReadAll(obj) + if err != nil || !bytes.Equal(got, payload) { + t.Fatalf("wire fixture did not store original: %q %v", got, err) + } +} diff --git a/internal/pkg/repository/postgres/messages.go b/internal/pkg/repository/postgres/messages.go new file mode 100644 index 00000000..da695fa0 --- /dev/null +++ b/internal/pkg/repository/postgres/messages.go @@ -0,0 +1,96 @@ +package postgres + +import ( + "context" + "errors" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" + "github.com/google/uuid" + "github.com/jackc/pgx/v5" + "slices" +) + +func (s *Storage) CreateMessage(ctx context.Context, chatID, senderID, text, key string) (domain.Message, error) { + return s.CreateMessageWithAttachments(ctx, chatID, senderID, text, key, nil) +} + +func (s *Storage) CreateMessageWithAttachments(ctx context.Context, chatID, senderID, text, key string, ids []string) (domain.Message, error) { + ctx, cancel := context.WithTimeout(ctx, s.timeout) + defer cancel() + if ids == nil { + ids = []string{} + } + tx, err := s.pool.Begin(ctx) + if err != nil { + return domain.Message{}, dbError(err) + } + defer tx.Rollback(context.Background()) + // Serialize this idempotency scope before validating attachments. A replay remains a + // replay even when reconciliation has since marked an original as missing. + if key != "" { + _, err = tx.Exec(ctx, `SELECT pg_advisory_xact_lock(hashtextextended($1,0))`, senderID+":"+chatID+":"+key) + if err != nil { + return domain.Message{}, dbError(err) + } + old := domain.Message{ChatID: chatID, SenderID: senderID} + err = tx.QueryRow(ctx, `SELECT id::text,text,attachment_ids::text[],created_at FROM messages WHERE sender_id=$1 AND chat_id=$2 AND idempotency_key=$3`, senderID, chatID, key).Scan(&old.ID, &old.Text, &old.AttachmentIDs, &old.CreatedAt) + if err == nil { + if old.Text != text || !slices.Equal(old.AttachmentIDs, ids) { + return domain.Message{}, domain.NewApplicationError(domain.ErrorConflict, "Idempotency-Key уже использован с другим телом") + } + return old, nil + } + if !errors.Is(err, pgx.ErrNoRows) { + return domain.Message{}, dbError(err) + } + } + // Lock each metadata row against reconciler updates until the link is committed. + for _, id := range ids { + var status string + err = tx.QueryRow(ctx, `SELECT status FROM attachments WHERE id=$1 AND chat_id=$2 FOR SHARE`, id, chatID).Scan(&status) + if errors.Is(err, pgx.ErrNoRows) { + return domain.Message{}, domain.NewApplicationError(domain.ErrorNotFound, "Объект не найден") + } + if err != nil { + return domain.Message{}, dbError(err) + } + if status == "failed" { + return domain.Message{}, domain.NewApplicationError(domain.ErrorConflict, "Вложение не готово") + } + } + m := domain.Message{ID: uuid.NewString(), ChatID: chatID, SenderID: senderID, Text: text, AttachmentIDs: ids} + var storedKey *string + if key != "" { + storedKey = &key + } + err = tx.QueryRow(ctx, `INSERT INTO messages(id,chat_id,sender_id,text,idempotency_key,attachment_ids) VALUES($1,$2,$3,$4,$5,$6) RETURNING created_at`, m.ID, chatID, senderID, text, storedKey, ids).Scan(&m.CreatedAt) + if err != nil { + return domain.Message{}, dbError(err) + } + return m, dbError(tx.Commit(ctx)) +} + +func (s *Storage) ListMessages(ctx context.Context, chatID string, after *domain.Position, limit int) ([]domain.Message, error) { + ctx, cancel := context.WithTimeout(ctx, s.timeout) + defer cancel() + query := `SELECT m.id::text,m.chat_id::text,m.sender_id::text,m.text,m.attachment_ids::text[],m.created_at FROM messages m WHERE m.chat_id=$1` + args := []any{chatID, limit} + if after != nil { + query += ` AND (m.created_at,m.id)>($3,$4)` + args = append(args, after.CreatedAt, after.ID) + } + query += ` ORDER BY m.created_at,m.id LIMIT $2` + rows, err := s.pool.Query(ctx, query, args...) + if err != nil { + return nil, dbError(err) + } + defer rows.Close() + result := []domain.Message{} + for rows.Next() { + var m domain.Message + if err = rows.Scan(&m.ID, &m.ChatID, &m.SenderID, &m.Text, &m.AttachmentIDs, &m.CreatedAt); err != nil { + return nil, dbError(err) + } + result = append(result, m) + } + return result, dbError(rows.Err()) +} diff --git a/internal/pkg/repository/postgres/storage.go b/internal/pkg/repository/postgres/storage.go new file mode 100644 index 00000000..22a93b14 --- /dev/null +++ b/internal/pkg/repository/postgres/storage.go @@ -0,0 +1,51 @@ +package postgres + +import ( + "context" + "errors" + "log" + "time" + + "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgconn" + "github.com/jackc/pgx/v5/pgxpool" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" + chatusecase "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/usecase/chat" +) + +type Storage struct { + pool *pgxpool.Pool + timeout time.Duration +} + +var _ chatusecase.Repository = (*Storage)(nil) + +func New(pool *pgxpool.Pool, timeout time.Duration) *Storage { + return &Storage{pool: pool, timeout: timeout} +} + +func (s *Storage) Ready(ctx context.Context) error { + ctx, cancel := context.WithTimeout(ctx, s.timeout) + defer cancel() + return dbError(s.pool.Ping(ctx)) +} + +func dbError(err error) error { + if err == nil { + return nil + } + var pgErr *pgconn.PgError + if errors.As(err, &pgErr) { + switch pgErr.Code { + case "23505": + return chatusecase.ErrUsernameTaken + case "23503": + return chatusecase.ErrUserNotFound + } + log.Printf("postgres operation failed: sqlstate=%s", pgErr.Code) + } else if !errors.Is(err, pgx.ErrNoRows) { + log.Print("postgres operation failed") + } + return domain.NewApplicationError(domain.ErrorUnavailable, "Хранилище недоступно") +} diff --git a/internal/pkg/repository/postgres/storage_test.go b/internal/pkg/repository/postgres/storage_test.go new file mode 100644 index 00000000..f1797478 --- /dev/null +++ b/internal/pkg/repository/postgres/storage_test.go @@ -0,0 +1,292 @@ +package postgres_test + +import ( + "context" + "errors" + "net" + "net/url" + "os" + "os/exec" + "path/filepath" + "strconv" + "strings" + "sync" + "testing" + "time" + + "github.com/google/uuid" + "github.com/jackc/pgx/v5/pgxpool" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/config" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/repository/postgres" + chatusecase "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/usecase/chat" +) + +func TestIntegration(t *testing.T) { + if os.Getenv("INTEGRATION_TESTS") != "1" { + t.Skip("run make test-integration against the Compose stack") + } + ctx := context.Background() + cfg, err := config.Load() + if err != nil { + t.Fatal(err) + } + pc, err := pgxpool.ParseConfig("sslmode=disable") + if err != nil { + t.Fatal(err) + } + pc.ConnConfig.Host = cfg.PostgresHost + pc.ConnConfig.Port = cfg.PostgresPort + pc.ConnConfig.User = cfg.PostgresUser + pc.ConnConfig.Database = cfg.PostgresDatabase + pc.ConnConfig.Password = cfg.PostgresPassword + pc.ConnConfig.RuntimeParams["timezone"] = "UTC" + pc.MaxConns = 4 + admin, err := pgxpool.NewWithConfig(ctx, pc.Copy()) + if err != nil { + t.Fatal("connect failed") + } + defer admin.Close() + // Identifier is generated by the test, never from an API request. + schema := "test_" + uuid.New().String()[:8] + if _, err = admin.Exec(ctx, `CREATE SCHEMA `+schema); err != nil { + t.Fatal(err) + } + defer admin.Exec(ctx, `DROP SCHEMA `+schema+` CASCADE`) + pc.ConnConfig.RuntimeParams["search_path"] = schema + pool, err := pgxpool.NewWithConfig(ctx, pc) + if err != nil { + t.Fatal(err) + } + defer pool.Close() + runGoose := func(t *testing.T, command string, params ...string) { + t.Helper() + migrationDir := os.Getenv("GOOSE_MIGRATION_DIR") + if migrationDir == "" { + migrationDir, err = filepath.Abs("../../../../migrations") + if err != nil { + t.Fatal(err) + } + } + connection := url.URL{Scheme: "postgres", User: url.User(cfg.PostgresUser), Host: net.JoinHostPort(cfg.PostgresHost, strconv.Itoa(int(cfg.PostgresPort))), Path: cfg.PostgresDatabase} + connection.RawQuery = url.Values{"sslmode": {"disable"}, "search_path": {schema}, "connect_timeout": {"5"}}.Encode() + commandCtx, cancel := context.WithTimeout(ctx, 45*time.Second) + defer cancel() + args := append([]string{"-env", "/dev/null", "-dir", migrationDir, "-timeout", "30s", command}, params...) + commandExec := exec.CommandContext(commandCtx, "goose", args...) + commandExec.Env = append(os.Environ(), "GOOSE_DRIVER=postgres", "GOOSE_DBSTRING="+connection.String(), "PGPASSWORD="+cfg.PostgresPassword) + output, err := commandExec.CombinedOutput() + if err != nil { + t.Fatalf("goose %s: %v: %s", command, err, strings.ReplaceAll(string(output), cfg.PostgresPassword, "[redacted]")) + } + t.Logf("goose %s: %s", command, output) + } + runGoose(t, "up") + runGoose(t, "up") + var versions int + if err = pool.QueryRow(ctx, `SELECT count(*) FROM goose_db_version WHERE version_id=1 AND is_applied`).Scan(&versions); err != nil || versions != 1 { + t.Fatalf("migration versions=%d error=%v", versions, err) + } + repo := postgres.New(pool, 2*time.Second) + t.Run("registration_race", func(t *testing.T) { + const count = 12 + results := make(chan error, count) + var wg sync.WaitGroup + start := make(chan struct{}) + for i := 0; i < count; i++ { + wg.Add(1) + go func() { + defer wg.Done() + <-start + _, err := repo.CreateUser(ctx, "same_username", "Same", "test-hash") + results <- err + }() + } + close(start) + wg.Wait() + close(results) + successes, conflicts := 0, 0 + for err := range results { + if err == nil { + successes++ + } else if errors.Is(err, chatusecase.ErrUsernameTaken) { + conflicts++ + } else { + t.Fatal(err) + } + } + if successes != 1 || conflicts != count-1 { + t.Fatalf("successes=%d conflicts=%d", successes, conflicts) + } + t.Logf("12 concurrent INSERTs: %d success, %d unique conflicts", successes, conflicts) + }) + user, err := repo.CreateUser(ctx, "history_owner", "Owner", "test-hash") + if err != nil { + t.Fatal(err) + } + t.Run("rollback", func(t *testing.T) { + _, err := repo.CreateChat(ctx, "must rollback", []string{user.ID, uuid.NewString()}) + if !errors.Is(err, chatusecase.ErrUserNotFound) { + t.Fatalf("unexpected error %v", err) + } + var chats, members int + if err = pool.QueryRow(ctx, `SELECT (SELECT count(*) FROM chats),(SELECT count(*) FROM chat_members)`).Scan(&chats, &members); err != nil { + t.Fatal(err) + } + if chats != 0 || members != 0 { + t.Fatalf("partial transaction: chats=%d members=%d", chats, members) + } + t.Log("failed second member INSERT left 0 chats and 0 members") + }) + chat, err := repo.CreateChat(ctx, "History", []string{user.ID}) + if err != nil { + t.Fatal(err) + } + t.Run("lab4_attachments_and_reconciliation", func(t *testing.T) { + isolated, e := repo.CreateChat(ctx, "Lab4", []string{user.ID}) + if e != nil { + t.Fatal(e) + } + lab4Backend(t, pool, repo, user, isolated) + }) + _, err = pool.Exec(ctx, `INSERT INTO messages(id,chat_id,sender_id,text,created_at) + SELECT md5(i::text)::uuid,$1,$2,'synthetic message '||i, + timestamptz '2026-01-01 00:00:00+00' + (i / 10) * interval '1 millisecond' + FROM generate_series(1,10000) i`, chat.ID, user.ID) + if err != nil { + t.Fatal(err) + } + if _, err = pool.Exec(ctx, `ANALYZE messages`); err != nil { + t.Fatal(err) + } + t.Run("keyset_and_explain", func(t *testing.T) { + seen := make(map[string]bool) + var after *domain.Position + for { + page, err := repo.ListMessages(ctx, chat.ID, after, 97) + if err != nil { + t.Fatal(err) + } + if len(page) == 0 { + break + } + for _, message := range page { + if seen[message.ID] { + t.Fatal("duplicate on page boundary") + } + seen[message.ID] = true + } + last := page[len(page)-1] + after = &domain.Position{CreatedAt: last.CreatedAt, ID: last.ID} + } + if len(seen) != 10000 { + t.Fatalf("history count=%d", len(seen)) + } + rows, err := pool.Query(ctx, `EXPLAIN (ANALYZE, BUFFERS) + SELECT m.id::text,m.chat_id::text,m.sender_id::text,m.text,m.created_at FROM messages m + WHERE m.chat_id=$1 AND (m.created_at,m.id)>($2,$3) ORDER BY m.created_at,m.id LIMIT $4`, + chat.ID, time.Date(2026, 1, 1, 0, 0, 0, 900000000, time.UTC), "00000000-0000-0000-0000-000000000000", 51) + if err != nil { + t.Fatal(err) + } + defer rows.Close() + t.Log("EXPLAIN on 10,000 messages, cursor near the end (9,000):") + for rows.Next() { + var line string + if err = rows.Scan(&line); err != nil { + t.Fatal(err) + } + t.Log(line) + } + if err = rows.Err(); err != nil { + t.Fatal(err) + } + t.Log("keyset traversal returned 10,000 distinct messages, including equal timestamps") + }) + t.Run("idempotency_race", func(t *testing.T) { + isolated, err := repo.CreateChat(ctx, "Idempotency", []string{user.ID}) + if err != nil { + t.Fatal(err) + } + const count = 16 + results := make(chan domain.Message, count) + failures := make(chan error, count) + start := make(chan struct{}) + var wg sync.WaitGroup + for i := 0; i < count; i++ { + wg.Add(1) + go func() { + defer wg.Done() + <-start + message, err := repo.CreateMessage(ctx, isolated.ID, user.ID, "exactly once", "shared-key") + if err != nil { + failures <- err + return + } + results <- message + }() + } + close(start) + wg.Wait() + close(results) + close(failures) + for err := range failures { + t.Fatal(err) + } + var first domain.Message + for message := range results { + if first.ID == "" { + first = message + } + if message.ID != first.ID || !message.CreatedAt.Equal(first.CreatedAt) || message.Text != first.Text { + t.Fatal("concurrent replay changed result") + } + } + var rows int + if err := pool.QueryRow(ctx, `SELECT count(*) FROM messages WHERE chat_id=$1`, isolated.ID).Scan(&rows); err != nil || rows != 1 { + t.Fatalf("expected one durable effect, got %d: %v", rows, err) + } + _, err = repo.CreateMessage(ctx, isolated.ID, user.ID, "different", "shared-key") + applicationError, ok := domain.AsApplicationError(err) + if !ok || applicationError.Code != domain.ErrorConflict { + t.Fatalf("expected conflict, got %v", err) + } + t.Log("16 concurrent PostgreSQL requests: one effect, identical replay, changed body conflicts") + }) + t.Run("goose_legacy_and_down", func(t *testing.T) { + // This is the disposable test schema, never the application's public schema. + const digestSQL = `SELECT md5(string_agg(ROW(id,chat_id,sender_id,text,created_at)::text,',' ORDER BY id)) FROM messages` + var before, after string + if err = pool.QueryRow(ctx, digestSQL).Scan(&before); err != nil { + t.Fatal(err) + } + // Model the actual lab4 physical schema before adopting its legacy journal. + runGoose(t, "down-to", "4") + if _, err = pool.Exec(ctx, `DROP TABLE goose_db_version; + CREATE TABLE schema_migrations(version text PRIMARY KEY,applied_at timestamptz NOT NULL DEFAULT now()); + INSERT INTO schema_migrations(version) VALUES('001_initial.sql')`); err != nil { + t.Fatal(err) + } + runGoose(t, "up") + runGoose(t, "up") + if err = pool.QueryRow(ctx, digestSQL).Scan(&after); err != nil { + t.Fatal(err) + } + if before != after { + t.Fatal("legacy migration changed message data") + } + t.Log("adopted legacy schema: all existing messages are unchanged") + runGoose(t, "reset") + var tables int + if err = pool.QueryRow(ctx, `SELECT count(*) FROM information_schema.tables WHERE table_schema=$1 AND table_name IN ('users','chats','chat_members','messages','schema_migrations')`, schema).Scan(&tables); err != nil || tables != 0 { + t.Fatalf("down left %d application tables: %v", tables, err) + } + runGoose(t, "up") + if err = pool.QueryRow(ctx, `SELECT count(*) FROM messages`).Scan(&tables); err != nil || tables != 0 { + t.Fatalf("up after down failed: %v", err) + } + t.Log("down and up succeeded in isolated schema") + }) + +} diff --git a/internal/pkg/repository/postgres/users.go b/internal/pkg/repository/postgres/users.go new file mode 100644 index 00000000..ad3f8c15 --- /dev/null +++ b/internal/pkg/repository/postgres/users.go @@ -0,0 +1,46 @@ +package postgres + +import ( + "context" + "errors" + + "github.com/google/uuid" + "github.com/jackc/pgx/v5" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" +) + +func (s *Storage) CreateUser(ctx context.Context, username, displayName, hash string) (domain.User, error) { + ctx, cancel := context.WithTimeout(ctx, s.timeout) + defer cancel() + var user domain.User + err := s.pool.QueryRow(ctx, `INSERT INTO users(id,username,display_name,password_hash) VALUES($1,$2,$3,$4) + RETURNING id::text,username,display_name,created_at`, uuid.NewString(), username, displayName, hash). + Scan(&user.ID, &user.Username, &user.DisplayName, &user.CreatedAt) + return user, dbError(err) +} + +func (s *Storage) User(ctx context.Context, id string) (domain.User, bool, error) { + ctx, cancel := context.WithTimeout(ctx, s.timeout) + defer cancel() + var user domain.User + err := s.pool.QueryRow(ctx, `SELECT id::text,username,display_name,created_at FROM users WHERE id=$1`, id). + Scan(&user.ID, &user.Username, &user.DisplayName, &user.CreatedAt) + if errors.Is(err, pgx.ErrNoRows) { + return user, false, nil + } + return user, err == nil, dbError(err) +} + +func (s *Storage) UserByUsername(ctx context.Context, username string) (domain.User, string, bool, error) { + ctx, cancel := context.WithTimeout(ctx, s.timeout) + defer cancel() + var user domain.User + var hash string + err := s.pool.QueryRow(ctx, `SELECT id::text,username,display_name,created_at,password_hash FROM users WHERE username=$1`, username). + Scan(&user.ID, &user.Username, &user.DisplayName, &user.CreatedAt, &hash) + if errors.Is(err, pgx.ErrNoRows) { + return user, "", false, nil + } + return user, hash, err == nil, dbError(err) +} diff --git a/internal/pkg/session/redis.go b/internal/pkg/session/redis.go new file mode 100644 index 00000000..13721b4b --- /dev/null +++ b/internal/pkg/session/redis.go @@ -0,0 +1,71 @@ +package session + +import ( + "context" + "encoding/json" + "errors" + "log" + "time" + + "github.com/redis/go-redis/v9" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" +) + +type Redis struct { + client *redis.Client + timeout time.Duration +} + +func NewRedis(client *redis.Client, timeout time.Duration) *Redis { + return &Redis{client: client, timeout: timeout} +} + +func unavailable(err error) error { + if err == nil { + return nil + } + log.Print("redis operation failed") + return domain.NewApplicationError(domain.ErrorUnavailable, "Хранилище сессий недоступно") +} + +func (s *Redis) Ready(ctx context.Context) error { + ctx, cancel := context.WithTimeout(ctx, s.timeout) + defer cancel() + return unavailable(s.client.Ping(ctx).Err()) +} + +func (s *Redis) Put(ctx context.Context, key string, value domain.Session) error { + ctx, cancel := context.WithTimeout(ctx, s.timeout) + defer cancel() + data, err := json.Marshal(value) + if err != nil { + return err + } + // Absolute expiry prevents TTL extension by network delay or restart. + return unavailable(s.client.Do(ctx, "SET", "session:"+key, data, "PXAT", value.ExpiresAt.UnixMilli()).Err()) +} + +func (s *Redis) Get(ctx context.Context, key string) (domain.Session, bool, error) { + ctx, cancel := context.WithTimeout(ctx, s.timeout) + defer cancel() + var value domain.Session + data, err := s.client.Get(ctx, "session:"+key).Bytes() + if errors.Is(err, redis.Nil) { + return value, false, nil + } + if err != nil { + return value, false, unavailable(err) + } + if err = json.Unmarshal(data, &value); err != nil { + return value, false, unavailable(err) + } + return value, time.Now().Before(value.ExpiresAt), nil +} + +func (s *Redis) Delete(ctx context.Context, key string) (bool, error) { + ctx, cancel := context.WithTimeout(ctx, s.timeout) + defer cancel() + count, err := s.client.Del(ctx, "session:"+key).Result() + return count > 0, unavailable(err) +} diff --git a/internal/usecase/chat/repository.go b/internal/usecase/chat/repository.go new file mode 100644 index 00000000..004d1f67 --- /dev/null +++ b/internal/usecase/chat/repository.go @@ -0,0 +1,28 @@ +package chat + +import ( + "context" + "errors" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" +) + +var ( + ErrUsernameTaken = errors.New("username is already taken") + ErrUserNotFound = errors.New("user not found") + ErrChatNotFound = errors.New("chat not found") + ErrNotMember = errors.New("user is not a chat member") +) + +// Repository is the persistence port required by the chat use case. +type Repository interface { + Ready(ctx context.Context) error + UserByUsername(ctx context.Context, username string) (domain.User, string, bool, error) + CreateUser(ctx context.Context, username, displayName, passwordHash string) (domain.User, error) + User(ctx context.Context, id string) (domain.User, bool, error) + CreateChat(ctx context.Context, title string, memberIDs []string) (domain.Chat, error) + ChatForUser(ctx context.Context, chatID, userID string) (domain.Chat, error) + ListChats(ctx context.Context, userID string, after *domain.Position, limit int) ([]domain.Chat, error) + CreateMessage(ctx context.Context, chatID, senderID, text, key string) (domain.Message, error) + ListMessages(ctx context.Context, chatID string, after *domain.Position, limit int) ([]domain.Message, error) +} diff --git a/internal/usecase/chat/service.go b/internal/usecase/chat/service.go new file mode 100644 index 00000000..0ca9425e --- /dev/null +++ b/internal/usecase/chat/service.go @@ -0,0 +1,182 @@ +package chat + +import ( + "context" + "errors" + "strings" + "time" + "unicode/utf8" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/password" +) + +type UseCase struct { + repository Repository + sessions Sessions + sessionTTL time.Duration +} + +func New(repository Repository, sessions Sessions, ttl time.Duration) *UseCase { + return &UseCase{repository: repository, sessions: sessions, sessionTTL: ttl} +} + +func (u *UseCase) CreateUser(ctx context.Context, user domain.User, secret string) (domain.User, error) { + if !validUsername(user.Username) { + return domain.User{}, invalid("username должен соответствовать [a-z0-9_]{3,32}") + } + if !validRequiredText(user.DisplayName, 100) { + return domain.User{}, invalid("display_name должен содержать от 1 до 100 символов") + } + if !validPassword(secret) { + return domain.User{}, invalid("password должен содержать от 12 до 128 символов") + } + hash, err := password.Hash(ctx, secret) + if err != nil { + return domain.User{}, err + } + created, err := u.repository.CreateUser(ctx, user.Username, user.DisplayName, hash) + if errors.Is(err, ErrUsernameTaken) { + return domain.User{}, domain.NewApplicationError(domain.ErrorConflict, "Пользователь с таким username уже существует") + } + return created, err +} + +func (u *UseCase) CreateChat(ctx context.Context, callerID string, chat domain.Chat) (domain.Chat, error) { + if !validRequiredText(chat.Title, 100) { + return domain.Chat{}, invalid("title должен содержать от 1 до 100 символов") + } + if len(chat.MemberIDs) < 1 || len(chat.MemberIDs) > 100 { + return domain.Chat{}, invalid("member_ids должен содержать от 1 до 100 участников") + } + + normalizedIDs := make([]string, len(chat.MemberIDs)) + seen := make(map[string]struct{}, len(chat.MemberIDs)) + callerIncluded := false + for index, memberID := range chat.MemberIDs { + normalized, valid := normalizeUUID(memberID) + if !valid { + return domain.Chat{}, invalid("member_ids содержит некорректный UUID") + } + if _, duplicate := seen[normalized]; duplicate { + return domain.Chat{}, invalid("member_ids содержит повторяющиеся UUID") + } + normalizedIDs[index] = normalized + seen[normalized] = struct{}{} + callerIncluded = callerIncluded || normalized == callerID + } + if !callerIncluded { + return domain.Chat{}, invalid("текущий пользователь должен входить в member_ids") + } + + created, err := u.repository.CreateChat(ctx, chat.Title, normalizedIDs) + if errors.Is(err, ErrUserNotFound) { + return domain.Chat{}, invalid("member_ids содержит неизвестного пользователя") + } + return created, err +} + +func (u *UseCase) GetChat(ctx context.Context, callerID string, chat domain.Chat) (domain.Chat, error) { + chatID, valid := normalizeUUID(chat.ID) + if !valid { + return domain.Chat{}, invalid("Некорректный chat_id") + } + return u.chatForUser(ctx, chatID, callerID) +} + +func (u *UseCase) ListChats(ctx context.Context, callerID string, pagination domain.Pagination) (domain.ChatPage, error) { + if pagination.Limit < 1 || pagination.Limit > 100 { + return domain.ChatPage{}, invalid("limit должен быть целым числом от 1 до 100") + } + items, err := u.repository.ListChats(ctx, callerID, pagination.After, pagination.Limit+1) + if err != nil { + return domain.ChatPage{}, err + } + page := domain.ChatPage{Items: items, HasMore: len(items) > pagination.Limit} + if page.HasMore { + page.Items = page.Items[:pagination.Limit] + } + return page, nil +} + +func (u *UseCase) CreateMessage(ctx context.Context, callerID string, message domain.Message) (domain.Message, error) { + chatID, valid := normalizeUUID(message.ChatID) + if !valid { + return domain.Message{}, invalid("Некорректный chat_id") + } + if _, err := u.chatForUser(ctx, chatID, callerID); err != nil { + return domain.Message{}, err + } + if !utf8.ValidString(message.Text) || utf8.RuneCountInString(message.Text) > 4000 || (strings.TrimSpace(message.Text) == "" && len(message.AttachmentIDs) == 0) { + return domain.Message{}, invalid("text должен содержать от 1 до 4000 символов") + } + if len(message.AttachmentIDs) > 10 { + return domain.Message{}, invalid("Не более 10 вложений") + } + seen := map[string]bool{} + for i, id := range message.AttachmentIDs { + normalized, ok := normalizeUUID(id) + if !ok || seen[normalized] { + return domain.Message{}, invalid("Некорректные или повторные attachment_ids") + } + seen[normalized] = true + message.AttachmentIDs[i] = normalized + } + var created domain.Message + var err error + if repository, ok := u.repository.(interface { + CreateMessageWithAttachments(context.Context, string, string, string, string, []string) (domain.Message, error) + }); ok { + created, err = repository.CreateMessageWithAttachments(ctx, chatID, callerID, message.Text, message.IdempotencyKey, message.AttachmentIDs) + } else if len(message.AttachmentIDs) > 0 { + return domain.Message{}, notFound() + } else { + created, err = u.repository.CreateMessage(ctx, chatID, callerID, message.Text, message.IdempotencyKey) + } + if errors.Is(err, ErrChatNotFound) || errors.Is(err, ErrNotMember) { + return domain.Message{}, notFound() + } + return created, err +} + +func (u *UseCase) ListMessages(ctx context.Context, callerID string, chat domain.Chat, pagination domain.Pagination) (domain.MessagePage, error) { + chatID, valid := normalizeUUID(chat.ID) + if !valid { + return domain.MessagePage{}, invalid("Некорректный chat_id") + } + if _, err := u.chatForUser(ctx, chatID, callerID); err != nil { + return domain.MessagePage{}, err + } + if pagination.Limit < 1 || pagination.Limit > 100 { + return domain.MessagePage{}, invalid("limit должен быть целым числом от 1 до 100") + } + items, err := u.repository.ListMessages(ctx, chatID, pagination.After, pagination.Limit+1) + if err != nil { + return domain.MessagePage{}, err + } + page := domain.MessagePage{Items: items, HasMore: len(items) > pagination.Limit} + if page.HasMore { + page.Items = page.Items[:pagination.Limit] + } + return page, nil +} + +func (u *UseCase) chatForUser(ctx context.Context, chatID, callerID string) (domain.Chat, error) { + chat, err := u.repository.ChatForUser(ctx, chatID, callerID) + if errors.Is(err, ErrChatNotFound) || errors.Is(err, ErrNotMember) { + return domain.Chat{}, notFound() + } + return chat, err +} + +func invalid(message string) error { + return domain.NewApplicationError(domain.ErrorInvalid, message) +} + +func unauthorized() error { + return domain.NewApplicationError(domain.ErrorUnauthorized, "Требуется действительная сессия") +} + +func notFound() error { + return domain.NewApplicationError(domain.ErrorNotFound, "Объект не найден") +} diff --git a/internal/usecase/chat/session.go b/internal/usecase/chat/session.go new file mode 100644 index 00000000..07d16684 --- /dev/null +++ b/internal/usecase/chat/session.go @@ -0,0 +1,102 @@ +package chat + +import ( + "context" + "crypto/rand" + "crypto/sha256" + "encoding/base64" + "encoding/hex" + "strings" + "time" + "unicode/utf8" + + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain" + "gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/password" +) + +type Sessions interface { + Put(context.Context, string, domain.Session) error + Get(context.Context, string) (domain.Session, bool, error) + Delete(context.Context, string) (bool, error) + Ready(context.Context) error +} + +func validPassword(value string) bool { + n := utf8.RuneCountInString(value) + return utf8.ValidString(value) && n >= 12 && n <= 128 && strings.TrimSpace(value) != "" +} + +func tokenKey(token string) string { + sum := sha256.Sum256([]byte(token)) + return hex.EncodeToString(sum[:]) +} + +func (u *UseCase) Authenticate(ctx context.Context, token string) (domain.User, error) { + decoded, err := base64.RawURLEncoding.DecodeString(token) + if err != nil || len(decoded) != 32 { + return domain.User{}, unauthorized() + } + session, exists, err := u.sessions.Get(ctx, tokenKey(token)) + if err != nil { + return domain.User{}, err + } + if !exists || !time.Now().Before(session.ExpiresAt) { + return domain.User{}, unauthorized() + } + user, exists, err := u.repository.User(ctx, session.UserID) + if err != nil { + return domain.User{}, err + } + if !exists { + return domain.User{}, unauthorized() + } + return user, nil +} + +func (u *UseCase) CreateSession(ctx context.Context, username, secret string) (domain.Login, error) { + if !validUsername(username) || !validPassword(secret) { + return domain.Login{}, unauthorized() + } + user, hash, exists, err := u.repository.UserByUsername(ctx, username) + if err != nil { + return domain.Login{}, err + } + if !exists { + hash = password.DummyHash + } + valid, err := password.Verify(ctx, secret, hash) + if err != nil { + return domain.Login{}, err + } + if !valid || !exists { + return domain.Login{}, unauthorized() + } + var raw [32]byte + if _, err = rand.Read(raw[:]); err != nil { + return domain.Login{}, err + } + token := base64.RawURLEncoding.EncodeToString(raw[:]) + expires := time.Now().UTC().Add(u.sessionTTL) + if err = u.sessions.Put(ctx, tokenKey(token), domain.Session{UserID: user.ID, ExpiresAt: expires}); err != nil { + return domain.Login{}, err + } + return domain.Login{Token: token, ExpiresAt: expires, User: user}, nil +} + +func (u *UseCase) DeleteSession(ctx context.Context, token string) error { + deleted, err := u.sessions.Delete(ctx, tokenKey(token)) + if err != nil { + return err + } + if !deleted { + return unauthorized() + } + return nil +} + +func (u *UseCase) Ready(ctx context.Context) error { + if err := u.repository.Ready(ctx); err != nil { + return err + } + return u.sessions.Ready(ctx) +} diff --git a/internal/usecase/chat/session_test.go b/internal/usecase/chat/session_test.go new file mode 100644 index 00000000..5096e1ba --- /dev/null +++ b/internal/usecase/chat/session_test.go @@ -0,0 +1,19 @@ +package chat + +import ( + "strings" + "testing" +) + +func TestPasswordContract(t *testing.T) { + for _, value := range []string{"", "too-short", strings.Repeat(" ", 12), strings.Repeat("x", 129), strings.Repeat("x", 12) + string([]byte{0xff})} { + if validPassword(value) { + t.Fatal("invalid password accepted") + } + } + for _, value := range []string{strings.Repeat("🔑", 128), "valid:password", " password with spaces "} { + if !validPassword(value) { + t.Fatal("valid Unicode password rejected") + } + } +} diff --git a/internal/usecase/chat/validation.go b/internal/usecase/chat/validation.go new file mode 100644 index 00000000..5fe43df1 --- /dev/null +++ b/internal/usecase/chat/validation.go @@ -0,0 +1,37 @@ +package chat + +import ( + "strings" + "unicode/utf8" + + "github.com/google/uuid" +) + +func normalizeUUID(value string) (string, bool) { + parsed, err := uuid.Parse(value) + if err != nil { + return "", false + } + normalized := parsed.String() + if !strings.EqualFold(value, normalized) { + return "", false + } + return normalized, true +} + +func validUsername(value string) bool { + if len(value) < 3 || len(value) > 32 { + return false + } + for _, char := range value { + if char != '_' && (char < 'a' || char > 'z') && (char < '0' || char > '9') { + return false + } + } + return true +} + +func validRequiredText(value string, maxRunes int) bool { + length := utf8.RuneCountInString(value) + return utf8.ValidString(value) && length >= 1 && length <= maxRunes && strings.TrimSpace(value) != "" +} diff --git a/migrations/001_initial.sql b/migrations/001_initial.sql new file mode 100644 index 00000000..2433b274 --- /dev/null +++ b/migrations/001_initial.sql @@ -0,0 +1,54 @@ +-- +goose Up +-- +goose StatementBegin +DO $$ +BEGIN + -- Adopt the schema created by the previous runner without changing its data. + IF to_regclass('schema_migrations') IS NOT NULL THEN + IF NOT EXISTS (SELECT 1 FROM schema_migrations WHERE version = '001_initial.sql') + OR to_regclass('users') IS NULL OR to_regclass('chats') IS NULL + OR to_regclass('chat_members') IS NULL OR to_regclass('messages') IS NULL THEN + RAISE EXCEPTION 'incomplete legacy schema: cannot adopt migration 1'; + END IF; + RETURN; + END IF; + CREATE TABLE users ( + id uuid PRIMARY KEY, + username text NOT NULL UNIQUE CHECK (username ~ '^[a-z0-9_]{3,32}$'), + display_name text NOT NULL CHECK (char_length(display_name) BETWEEN 1 AND 100), + password_hash text NOT NULL, + created_at timestamptz NOT NULL DEFAULT clock_timestamp() + ); + CREATE TABLE chats ( + id uuid PRIMARY KEY, + title text NOT NULL CHECK (char_length(title) BETWEEN 1 AND 100), + created_at timestamptz NOT NULL DEFAULT clock_timestamp() + ); + CREATE INDEX chats_history_idx ON chats (created_at, id); + CREATE TABLE chat_members ( + chat_id uuid NOT NULL REFERENCES chats(id), + user_id uuid NOT NULL REFERENCES users(id), + ordinal integer NOT NULL CHECK (ordinal >= 0), + PRIMARY KEY (chat_id, user_id), + UNIQUE (chat_id, ordinal) + ); + CREATE INDEX chat_members_user_idx ON chat_members (user_id, chat_id); + CREATE TABLE messages ( + id uuid PRIMARY KEY, + chat_id uuid NOT NULL, + sender_id uuid NOT NULL, + text text NOT NULL CHECK (char_length(text) BETWEEN 1 AND 4000), + created_at timestamptz NOT NULL DEFAULT clock_timestamp(), + FOREIGN KEY (chat_id, sender_id) REFERENCES chat_members(chat_id, user_id) + ); + CREATE INDEX messages_history_idx ON messages (chat_id, created_at, id); +END; +$$; +-- +goose StatementEnd + +-- +goose Down +DROP TABLE messages; +DROP TABLE chat_members; +DROP TABLE chats; +DROP TABLE users; +-- The old journal must not claim that the dropped schema is still applied. +DROP TABLE IF EXISTS schema_migrations; diff --git a/migrations/002_idempotency.sql b/migrations/002_idempotency.sql new file mode 100644 index 00000000..fb02f93c --- /dev/null +++ b/migrations/002_idempotency.sql @@ -0,0 +1,10 @@ +-- +goose Up +-- Additive: old lab2 writers can still insert NULL keys during migration. +ALTER TABLE messages ADD COLUMN IF NOT EXISTS idempotency_key text + CHECK (idempotency_key ~ '^[A-Za-z0-9._:-]{1,128}$'); +CREATE UNIQUE INDEX IF NOT EXISTS messages_idempotency_idx + ON messages(sender_id, chat_id, idempotency_key); + +-- +goose Down +DROP INDEX messages_idempotency_idx; +ALTER TABLE messages DROP COLUMN idempotency_key; diff --git a/migrations/003_attachments.sql b/migrations/003_attachments.sql new file mode 100644 index 00000000..a8b812ad --- /dev/null +++ b/migrations/003_attachments.sql @@ -0,0 +1,20 @@ +-- +goose Up +CREATE TABLE IF NOT EXISTS attachments ( + id uuid PRIMARY KEY, + chat_id uuid NOT NULL REFERENCES chats(id), + uploader_id uuid NOT NULL REFERENCES users(id), + filename text NOT NULL, + object_key text NOT NULL UNIQUE, + content_type text NOT NULL CHECK (content_type IN ('image/png','image/jpeg')), + size_bytes bigint NOT NULL CHECK (size_bytes BETWEEN 1 AND 10485760), + sha256 text NOT NULL CHECK (sha256 ~ '^[0-9a-f]{64}$'), + width integer NOT NULL, + height integer NOT NULL, + status text NOT NULL DEFAULT 'ready' CHECK (status IN ('ready','failed')), + error_code text, + created_at timestamptz NOT NULL DEFAULT clock_timestamp(), + CHECK ((status='ready' AND error_code IS NULL) OR (status='failed' AND error_code IS NOT NULL)) +); + +-- +goose Down +DROP TABLE IF EXISTS attachments; diff --git a/migrations/004_message_attachments.sql b/migrations/004_message_attachments.sql new file mode 100644 index 00000000..1fd41a98 --- /dev/null +++ b/migrations/004_message_attachments.sql @@ -0,0 +1,13 @@ +-- +goose Up +ALTER TABLE messages + DROP CONSTRAINT IF EXISTS messages_text_check, + ADD CONSTRAINT messages_text_check CHECK (char_length(text) BETWEEN 0 AND 4000), + ADD COLUMN IF NOT EXISTS attachment_ids uuid[] NOT NULL DEFAULT '{}'; + +-- +goose Down +-- Attachment-only messages cannot exist in lab3; retain an explicit placeholder when downgrading. +UPDATE messages SET text='[attachment]' WHERE text=''; +ALTER TABLE messages + DROP COLUMN IF EXISTS attachment_ids, + DROP CONSTRAINT IF EXISTS messages_text_check, + ADD CONSTRAINT messages_text_check CHECK (char_length(text) BETWEEN 1 AND 4000); diff --git a/migrations/005_async_attachments.sql b/migrations/005_async_attachments.sql new file mode 100644 index 00000000..e8deb845 --- /dev/null +++ b/migrations/005_async_attachments.sql @@ -0,0 +1,18 @@ +-- +goose Up +ALTER TABLE attachments + DROP CONSTRAINT attachments_status_check, + ADD CONSTRAINT attachments_status_check CHECK (status IN ('queued','processing','ready','failed')), + DROP CONSTRAINT attachments_check, + ADD CONSTRAINT attachments_check CHECK ((status='failed' AND error_code IS NOT NULL) OR (status<>'failed' AND error_code IS NULL)), + ADD COLUMN variants jsonb NOT NULL DEFAULT '[]', + ADD COLUMN updated_at timestamptz NOT NULL DEFAULT clock_timestamp(), + ADD COLUMN pipeline_version integer NOT NULL DEFAULT 1, + ADD COLUMN staging_key text; + +-- +goose Down +UPDATE attachments SET status='failed',error_code='pipeline_downgrade' WHERE status IN ('queued','processing'); +ALTER TABLE attachments DROP CONSTRAINT attachments_status_check, + ADD CONSTRAINT attachments_status_check CHECK (status IN ('ready','failed')), + DROP CONSTRAINT attachments_check, + ADD CONSTRAINT attachments_check CHECK ((status='ready' AND error_code IS NULL) OR (status='failed' AND error_code IS NOT NULL)), + DROP COLUMN variants, DROP COLUMN updated_at, DROP COLUMN pipeline_version, DROP COLUMN staging_key; diff --git a/migrations/006_attachment_jobs.sql b/migrations/006_attachment_jobs.sql new file mode 100644 index 00000000..96fe8715 --- /dev/null +++ b/migrations/006_attachment_jobs.sql @@ -0,0 +1,18 @@ +-- +goose Up +CREATE TABLE attachment_jobs ( + id uuid PRIMARY KEY, + attachment_id uuid NOT NULL UNIQUE REFERENCES attachments(id), + pipeline_version integer NOT NULL DEFAULT 1, + state text NOT NULL CHECK (state IN ('queued','processing','ready','failed')), + attempts integer NOT NULL DEFAULT 0, + max_attempts integer NOT NULL CHECK (max_attempts BETWEEN 1 AND 20), + available_at timestamptz NOT NULL DEFAULT clock_timestamp(), + lease_until timestamptz, + fence bigint NOT NULL DEFAULT 0, + last_error text, + created_at timestamptz NOT NULL DEFAULT clock_timestamp(), + updated_at timestamptz NOT NULL DEFAULT clock_timestamp() +); + +-- +goose Down +DROP TABLE attachment_jobs; diff --git a/migrations/007_attachment_outbox.sql b/migrations/007_attachment_outbox.sql new file mode 100644 index 00000000..4aa021c3 --- /dev/null +++ b/migrations/007_attachment_outbox.sql @@ -0,0 +1,10 @@ +-- +goose Up +CREATE TABLE attachment_outbox ( + job_id uuid PRIMARY KEY REFERENCES attachment_jobs(id), + available_at timestamptz NOT NULL DEFAULT clock_timestamp(), + published_at timestamptz, + stream_id text +); + +-- +goose Down +DROP TABLE attachment_outbox; diff --git a/migrations/008_attachment_replays.sql b/migrations/008_attachment_replays.sql new file mode 100644 index 00000000..2587f83c --- /dev/null +++ b/migrations/008_attachment_replays.sql @@ -0,0 +1,12 @@ +-- +goose Up +CREATE TABLE attachment_replays ( + id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + job_id uuid NOT NULL REFERENCES attachment_jobs(id), + operator text NOT NULL CHECK (char_length(operator) BETWEEN 1 AND 100), + reason text NOT NULL CHECK (char_length(reason) BETWEEN 1 AND 300), + previous_error text NOT NULL, + created_at timestamptz NOT NULL DEFAULT clock_timestamp() +); + +-- +goose Down +DROP TABLE attachment_replays; diff --git a/migrations/009_backfill_pipeline.sql b/migrations/009_backfill_pipeline.sql new file mode 100644 index 00000000..ac2b71e7 --- /dev/null +++ b/migrations/009_backfill_pipeline.sql @@ -0,0 +1,12 @@ +-- +goose Up +-- Re-process accepted lab4 originals; original keys remain durable staging until ready. +INSERT INTO attachment_jobs(id,attachment_id,state,max_attempts) +SELECT id,id,'queued',5 FROM attachments WHERE status='ready' AND variants='[]'::jsonb; +UPDATE attachments SET staging_key=object_key, + object_key='original/'||id::text||'/v1/original',status='queued',updated_at=clock_timestamp() +WHERE id IN (SELECT attachment_id FROM attachment_jobs); +INSERT INTO attachment_outbox(job_id) SELECT id FROM attachment_jobs; + +-- +goose Down +-- Do not erase accepted processing jobs during a downgrade. Schema Down is destructive. +SELECT 1; diff --git a/migrations/010_storage_cleanup.sql b/migrations/010_storage_cleanup.sql new file mode 100644 index 00000000..62cbac50 --- /dev/null +++ b/migrations/010_storage_cleanup.sql @@ -0,0 +1,5 @@ +-- +goose Up +ALTER TABLE attachments ADD COLUMN storage_cleaned_at timestamptz; + +-- +goose Down +ALTER TABLE attachments DROP COLUMN storage_cleaned_at; diff --git a/requirements-research.txt b/requirements-research.txt new file mode 100644 index 00000000..129feb00 --- /dev/null +++ b/requirements-research.txt @@ -0,0 +1,2 @@ +# Only for rendering the measured lab5 research charts. +matplotlib==3.9.4 diff --git a/scripts/benchmark_pipeline.py b/scripts/benchmark_pipeline.py new file mode 100644 index 00000000..191ce11c --- /dev/null +++ b/scripts/benchmark_pipeline.py @@ -0,0 +1,332 @@ +#!/usr/bin/env python3 +"""Repeatable lab5 track 1 experiment against the isolated Swarm stack. + +Uses synthetic users and PNGs. Changes only worker knobs and admission limits, +then restores their original values. Never deletes volumes or accepted jobs. +""" +import argparse +from concurrent.futures import ThreadPoolExecutor +import csv +import datetime as dt +import hashlib +import json +import math +import os +from pathlib import Path +import platform +import random +import struct +import subprocess +import sys +import time +import zlib + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT / 'tests')) +from client import Client, check + + +def docker(*args): + return subprocess.check_output(['docker', *args], text=True).strip() + + +def service_spec(name): + return json.loads(docker('service', 'inspect', name))[0]['Spec'] + + +def containers(service): + return docker('ps', '--filter', 'label=com.docker.swarm.service.name=' + service, + '--format', '{{.ID}}').split() + + +def wait_service(name, timeout=120): + deadline, stable, previous = time.monotonic() + timeout, None, None + while time.monotonic() < deadline: + inspected = json.loads(docker('service', 'inspect', name))[0] + spec = inspected['Spec'] + update_state = inspected.get('UpdateStatus', {}).get('State') + check(update_state not in ('paused', 'rollback_started', 'rollback_paused', 'rollback_completed'), + 'service configuration update failed: ' + name) + expected = spec['Mode']['Replicated']['Replicas'] + ids = docker('service', 'ps', '--filter', 'desired-state=running', '-q', name).split() + healthy = expected > 0 and len(ids) == expected and update_state in (None, 'completed') + if healthy: + tasks = json.loads(docker('inspect', *ids)) + healthy = all(t['Status']['State'] == 'running' for t in tasks) + if healthy: + states = json.loads(docker('inspect', *[t['Status']['ContainerStatus']['ContainerID'] for t in tasks])) + healthy = all(c['State'].get('Health', {}).get('Status', 'healthy') == 'healthy' for c in states) + now, identity = time.monotonic(), frozenset(ids) + if healthy: + if stable is None or identity != previous: + stable = now + if stable is not None and now - stable >= 5: + return + else: + stable = None + previous = identity + time.sleep(.5) + raise AssertionError('service did not stabilize: ' + name) + + +def update_env(service, values): + args = ['service', 'update', '--detach'] + for name, value in values.items(): + args += ['--env-rm', name] if value is None else ['--env-add', name + '=' + str(value)] + docker(*args, service) + wait_service(service) + + +def old_env(spec, names): + values = dict(entry.split('=', 1) for entry in spec['TaskTemplate']['ContainerSpec'].get('Env', [])) + return {name: values.get(name) for name in names} + + +def png(width, height): + rng = random.Random(20261110 + width) + def chunk(kind, value): + return struct.pack('>I', len(value)) + kind + value + struct.pack('>I', zlib.crc32(kind + value)) + pixels = b''.join(b'\0' + rng.randbytes(width * 3) for _ in range(height)) + return (b'\x89PNG\r\n\x1a\n' + chunk(b'IHDR', struct.pack('>IIBBBBB', width, height, 8, 2, 0, 0, 0)) + + chunk(b'IDAT', zlib.compress(pixels)) + chunk(b'IEND', b'')) + + +def percentile(values, fraction): + check(bool(values), 'no observations for percentile') + return sorted(values)[max(0, math.ceil(len(values) * fraction) - 1)] + + +class Experiment: + def __init__(self, args): + self.args = args + self.api = args.stack + '_api' + self.worker = args.stack + '_worker' + self.pg = args.stack + '_postgres' + self.client = Client(args.base_url, timeout=60) + + def sql(self, statement): + ids = containers(self.pg) + check(len(ids) == 1, 'expected one PostgreSQL container') + return docker('exec', ids[0], 'psql', '-U', 'messenger', '-d', 'messenger', + '-At', '-v', 'ON_ERROR_STOP=1', '-c', statement) + + def outstanding(self): + return int(self.sql("SELECT count(*) FROM attachment_jobs WHERE state IN ('queued','processing')")) + + def sample(self, chat): + # chat is a UUID generated by the API, never an arbitrary SQL fragment. + from uuid import UUID + chat_id = str(UUID(chat['id'])) + query = """SELECT json_build_object( + 'outstanding', count(*) FILTER (WHERE j.state IN ('queued','processing')), + 'queued', count(*) FILTER (WHERE j.state='queued'), + 'processing', count(*) FILTER (WHERE j.state='processing'), + 'queue_lag_seconds', COALESCE(EXTRACT(EPOCH FROM clock_timestamp()-min(j.created_at) + FILTER (WHERE j.state='queued')),0)) + FROM attachment_jobs j JOIN attachments a ON a.id=j.attachment_id + WHERE a.chat_id='""" + chat_id + "'" + result = json.loads(self.sql(query)) + total_rss = 0 + for container in containers(self.worker): + # Only process status counters; no command lines, environment or credentials. + raw = docker('exec', container, 'sh', '-c', + "awk '/^VmRSS:/{s+=$2} END{printf \"%.0f\\n\",s*1024}' /proc/[0-9]*/status 2>/dev/null || true") + total_rss += int(raw or 0) + result['rss_bytes'] = total_rss + return result + + def upload(self, actor, chat, content): + started = time.monotonic() + response = Client(self.args.base_url, timeout=60).call( + 'POST', '/api/v1/chats/' + chat['id'] + '/attachments?filename=research.png', + [202, 429], actor=actor, raw=content, headers={'Content-Type': 'image/png'}, schema='Attachment') + return {'started': started, 'accepted': time.monotonic(), 'status': response['status'], + 'instance': response['headers'].get('X-Instance-Id'), + 'attachment': response['json'] if response['status'] == 202 else None} + + def validate_result(self, actor, attachment, content): + check({v['name'] for v in attachment['variants']} == {'thumbnail', 'crop', 'optimized'}, + 'ready must publish all three variants') + original = self.client.call('GET', '/api/v1/attachments/' + attachment['id'] + '/content', actor=actor) + check(original['bytes'] == content, 'original changed during pipeline') + for variant in attachment['variants']: + response = self.client.call('GET', '/api/v1/attachments/' + attachment['id'] + '/content?variant=' + variant['name'], actor=actor) + check(len(response['bytes']) == variant['size_bytes'], 'variant size differs') + check(hashlib.sha256(response['bytes']).hexdigest() == variant['sha256'], 'variant checksum differs') + + def run_case(self, concurrency, prefetch, width, height): + check(self.outstanding() == 0, 'drain other workloads before research') + update_env(self.worker, {'WORKER_CONCURRENCY': concurrency, 'WORKER_PREFETCH': prefetch}) + alice, bob, _, chat = self.client.bootstrap() + content = png(width, height) + warm = self.upload(alice, chat, content) + check(warm['status'] == 202, 'warmup unexpectedly rejected') + self.client.wait_ready(alice, warm['attachment'], wait_seconds=self.args.timeout) + records, samples, rejected = [], [], 0 + started, deadline = time.monotonic(), time.monotonic() + self.args.timeout + baseline = self.sample(chat) + with ThreadPoolExecutor(max_workers=self.args.uploaders) as pool: + pending = {pool.submit(self.upload, alice, chat, content) for _ in range(self.args.requests)} + polling = {} + while pending or polling: + check(time.monotonic() < deadline, 'pipeline did not drain before research timeout') + done = {future for future in pending if future.done()} + pending -= done + for future in done: + row = future.result() + if row['status'] == 429: + rejected += 1 + else: + check(row['attachment']['status'] == 'queued', 'upload must return a queued snapshot') + polling[row['attachment']['id']] = row + for attachment_id, row in list(polling.items()): + attachment = self.client.call('GET', '/api/v1/attachments/' + attachment_id, + actor=bob, schema='Attachment')['json'] + check(attachment['status'] != 'failed', 'research attachment failed') + if attachment['status'] == 'ready': + now = time.monotonic() + row.update(attachment=attachment, upload_ms=(row['accepted']-row['started'])*1000, + ready_ms=(now-row['started'])*1000, + after_accept_ms=(now-row['accepted'])*1000) + records.append(row) + del polling[attachment_id] + sample = self.sample(chat) + samples.append({'seconds': round(time.monotonic() - started, 3), **sample}) + if pending or polling: + time.sleep(self.args.interval) + elapsed = time.monotonic() - started + check(len(records) == self.args.requests and rejected == 0, 'unexpected rejection in comparison matrix') + check(self.outstanding() == 0, 'comparison workload not drained') + self.validate_result(bob, records[-1]['attachment'], content) + result = {'concurrency': concurrency, 'prefetch': prefetch, 'width': width, 'height': height, + 'size_bytes': len(content), 'input_sha256': hashlib.sha256(content).hexdigest(), + 'offered': self.args.requests, 'accepted': len(records), + 'rejected': rejected, 'completed': len(records), 'makespan_seconds': round(elapsed, 3), + 'throughput_rps': round(len(records) / elapsed, 3), + 'ready_p50_ms': round(percentile([r['ready_ms'] for r in records], .5), 3), + 'ready_p95_ms': round(percentile([r['ready_ms'] for r in records], .95), 3), + 'after_accept_p95_ms': round(percentile([r['after_accept_ms'] for r in records], .95), 3), + 'upload_p95_ms': round(percentile([r['upload_ms'] for r in records], .95), 3), + 'queue_lag_peak_seconds': max(s['queue_lag_seconds'] for s in samples), + 'outstanding_peak': max(s['outstanding'] for s in samples), + 'rss_baseline_bytes': baseline['rss_bytes'], + 'rss_peak_bytes': max([baseline['rss_bytes']] + [s['rss_bytes'] for s in samples]), + 'samples': samples, + 'observations': [{'attachment_id': r['attachment']['id'], 'ready_ms': round(r['ready_ms'], 3), + 'upload_ms': round(r['upload_ms'], 3)} for r in records]} + print(json.dumps({k: v for k, v in result.items() if k not in ('samples', 'observations')}), flush=True) + return result + + def overload(self, limit): + check(self.outstanding() == 0, 'drain other workloads before overload test') + docker('service', 'scale', '--detach', self.worker + '=0') + deadline = time.monotonic() + 60 + while containers(self.worker): + check(time.monotonic() < deadline, 'worker did not stop') + time.sleep(.5) + update_env(self.api, {'MAX_OUTSTANDING_JOBS': limit}) + alice, bob, _, chat = self.client.bootstrap() + content = png(320, 200) + with ThreadPoolExecutor(max_workers=self.args.uploaders) as pool: + rows = list(pool.map(lambda _: self.upload(alice, chat, content), range(limit * 2))) + accepted = [r for r in rows if r['status'] == 202] + rejected = len(rows) - len(accepted) + outstanding = self.outstanding() + check(len({row['instance'] for row in rows}) >= 2, 'overload must exercise both API replicas') + check(len(accepted) == limit and rejected == limit and outstanding == limit, + 'admission limit did not bound accepted work while worker was stopped') + self.client.message(alice, chat, 'text messages remain available during overload') + docker('service', 'scale', '--detach', self.worker + '=1') + wait_service(self.worker) + started = time.monotonic() + for row in accepted: + attachment = self.client.wait_ready(bob, row['attachment'], wait_seconds=self.args.timeout) + check(attachment['error_code'] is None, 'accepted work failed after overload') + recovery = time.monotonic() - started + check(self.outstanding() == 0, 'accepted work remained outstanding after recovery') + followup = self.upload(alice, chat, content) + check(followup['status'] == 202, 'API did not resume admission after drain') + self.client.wait_ready(bob, followup['attachment'], wait_seconds=self.args.timeout) + result = {'limit': limit, 'offered': len(rows), 'accepted': len(accepted), 'rejected_429': rejected, + 'observed_api_instances': len({row['instance'] for row in rows}), + 'outstanding_worker_stopped': outstanding, 'ready_after_resume': len(accepted), + 'observed_drain_after_worker_healthy_seconds': round(recovery, 3), + 'outstanding_after_recovery': self.outstanding(), 'followup_upload': 202, + 'text_messages_during_overload': 'PASS'} + print('OVERLOAD ' + json.dumps(result), flush=True) + return result + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--base-url', default=os.environ.get('BASE_URL', 'http://localhost:18085')) + parser.add_argument('--stack', default=os.environ.get('STACK_NAME', 'mtusi-lab5')) + parser.add_argument('--requests', type=int, default=20) + parser.add_argument('--uploaders', type=int, default=8) + parser.add_argument('--interval', type=float, default=.25) + parser.add_argument('--timeout', type=int, default=240) + parser.add_argument('--limit', type=int, default=8) + parser.add_argument('--output', type=Path, default=ROOT / 'evidence/lab5-research.json') + args = parser.parse_args() + check(args.requests >= 5 and args.uploaders > 0 and 0 < args.limit <= 100, + 'invalid experiment limits') + check(args.interval > 0 and args.timeout > 0, 'sampling interval and timeout must be positive') + experiment = Experiment(args) + initial_worker, initial_api = service_spec(experiment.worker), service_spec(experiment.api) + original_worker_env = old_env(initial_worker, ('WORKER_CONCURRENCY', 'WORKER_PREFETCH')) + original_api_env = old_env(initial_api, ('MAX_OUTSTANDING_JOBS',)) + original_replicas = initial_worker['Mode']['Replicated']['Replicas'] + check(original_replicas == 1, 'experiment expects one worker service replica; concurrency is internal') + report = {'track': 1, 'started_at': dt.datetime.now(dt.timezone.utc).isoformat(), + 'stack': args.stack, 'worker_image': initial_worker['TaskTemplate']['ContainerSpec']['Image'], + 'worker_image_id': docker('inspect', containers(experiment.worker)[0], '--format', '{{.Image}}'), + 'environment': {'docker_server': docker('version', '--format', '{{.Server.Version}}'), + 'docker_cpus': int(docker('info', '--format', '{{.NCPU}}')), + 'docker_memory_bytes': int(docker('info', '--format', '{{.MemTotal}}')), + 'architecture': platform.machine(), 'python': platform.python_version()}, + 'worker_limits': initial_worker['TaskTemplate'].get('Resources', {}).get('Limits', {}), + 'initial_settings': {'worker': original_worker_env, 'api': original_api_env}, + 'requests_per_case': args.requests, 'upload_concurrency': args.uploaders, + 'sampling_interval_min_seconds': args.interval, + 'method': {'throughput': 'completed / burst makespan including client upload and polling', + 'ready_latency': 'client POST start to first observed ready; nearest-rank p95', + 'queue_lag': 'age of oldest queued PostgreSQL job in this chat; excludes processing', + 'rss': 'sum VmRSS for worker, renderers and cwebp; shared pages may count repeatedly', + 'limitations': 'single host; warmup per case; sampled peaks and polling latency; finite burst, no production SLA'}, + 'cases': []} + args.output.parent.mkdir(parents=True, exist_ok=True) + def save(): + args.output.write_text(json.dumps(report, indent=2, ensure_ascii=False, allow_nan=False) + '\n') + try: + for width, height in ((512, 512), (1536, 1536)): + for concurrency, prefetch in ((1, 1), (2, 4), (4, 8)): + report['cases'].append(experiment.run_case(concurrency, prefetch, width, height)) + save() + report['overload'] = experiment.overload(args.limit) + save() + finally: + # Keep every accepted job recoverable, including when an assertion fails. + try: + if not containers(experiment.worker): + docker('service', 'scale', '--detach', experiment.worker + '=' + str(original_replicas)) + wait_service(experiment.worker) + update_env(experiment.worker, original_worker_env) + finally: + update_env(experiment.api, original_api_env) + report['result'] = 'PASS' + report['restored_initial_settings'] = True + report['finished_at'] = dt.datetime.now(dt.timezone.utc).isoformat() + save() + summary = args.output.with_suffix('.csv') + keys = ['width', 'height', 'concurrency', 'prefetch', 'offered', 'accepted', 'completed', + 'throughput_rps', 'ready_p95_ms', 'after_accept_p95_ms', 'upload_p95_ms', + 'queue_lag_peak_seconds', 'rss_peak_bytes'] + with summary.open('w', newline='') as file: + writer = csv.DictWriter(file, fieldnames=keys, extrasaction='ignore') + writer.writeheader() + writer.writerows(report['cases']) + print('PASS: six measured configurations, bounded overload and recovery; ' + str(args.output)) + + +if __name__ == '__main__': + main() diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh new file mode 100755 index 00000000..3a183673 --- /dev/null +++ b/scripts/bootstrap.sh @@ -0,0 +1,20 @@ +#!/bin/sh +set -eu +cd "$(dirname "$0")/.." +umask 077 +mkdir -p secrets +chmod 700 secrets +for name in postgres_password cursor_key s3_root_secret_key s3_secret_key; do + if [ ! -s "secrets/$name" ]; then + openssl rand -hex 32 > "secrets/$name" + fi +done +for name in s3_root_access_key s3_access_key; do + if [ ! -s "secrets/$name" ]; then + openssl rand -hex 8 > "secrets/$name" + fi +done +# Compose mounts files directly on Linux; the unprivileged API must read them. +# The host directory remains private (0700). +chmod 444 secrets/postgres_password secrets/cursor_key secrets/s3_root_access_key secrets/s3_root_secret_key secrets/s3_access_key secrets/s3_secret_key +printf '%s\n' 'Local secrets are ready.' diff --git a/scripts/compose.sh b/scripts/compose.sh new file mode 100755 index 00000000..078e4f0d --- /dev/null +++ b/scripts/compose.sh @@ -0,0 +1,7 @@ +#!/bin/sh +set -eu +cd "$(dirname "$0")/.." +if docker compose version >/dev/null 2>&1; then + exec docker compose --env-file /dev/null -f compose.yaml "$@" +fi +exec docker-compose --env-file /dev/null -f compose.yaml "$@" diff --git a/scripts/measure_load.py b/scripts/measure_load.py new file mode 100644 index 00000000..891b407c --- /dev/null +++ b/scripts/measure_load.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +"""Reproducible local benchmark with resource samples; no credentials in output.""" +import argparse +import json +import os +from pathlib import Path +import subprocess +import sys +import time + +ROOT = Path(__file__).resolve().parents[1] +STACK = os.environ.get('STACK_NAME', 'mtusi-lab5') + +def containers(service=None): + label = 'com.docker.swarm.service.name='+STACK+'_'+service if service else 'com.docker.stack.namespace='+STACK + return subprocess.check_output(['docker','ps','--filter','label='+label,'-q'],text=True).split() + + +def counts(): + sql = 'SELECT json_build_object(\'users\',(SELECT count(*) FROM users),\'chats\',(SELECT count(*) FROM chats),\'messages\',(SELECT count(*) FROM messages))' + return json.loads(subprocess.check_output(['docker', 'exec', containers('postgres')[0], 'psql', '-U', 'messenger', '-d', 'messenger', '-Atc', sql], text=True)) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--base-url', default=os.environ.get('BASE_URL', 'http://localhost:8080')) + parser.add_argument('--duration', type=int, default=30) + parser.add_argument('--concurrency', type=int, default=4) + args = parser.parse_args() + command = [sys.executable, str(ROOT / 'tests/load.py'), '--base-url', args.base_url, '--concurrency', str(args.concurrency)] + subprocess.run(command + ['--duration', '3'], check=True, stdout=subprocess.DEVNULL) + before = counts() + ids = containers() + samples = [] + process = subprocess.Popen(command + ['--duration', str(args.duration), '--output', str(ROOT / 'evidence/swarm-load.json')], stdout=subprocess.DEVNULL) + try: + while process.poll() is None: + stats = subprocess.check_output(['docker', 'stats', '--no-stream', '--format', '{{json .}}', *ids], text=True) + samples.append({'elapsed_sample': len(samples), 'containers': [json.loads(line) for line in stats.splitlines()]}) + time.sleep(1) + finally: + if process.poll() is None: + process.terminate() + code = process.wait() + if code: + raise SystemExit(code) + report = {'warmup_seconds': 3, 'dataset_before': before, 'dataset_after': counts(), 'samples': samples} + (ROOT / 'evidence/swarm-resources.json').write_text(json.dumps(report, indent=2) + '\n') + print((ROOT / 'evidence/swarm-load.json').read_text()) + print('Resource samples and dataset counts: evidence/swarm-resources.json') + + +if __name__ == '__main__': + main() diff --git a/scripts/measure_uploads.py b/scripts/measure_uploads.py new file mode 100644 index 00000000..07bd16f5 --- /dev/null +++ b/scripts/measure_uploads.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 +"""Ten simultaneous proxy uploads, checksums, latency and cgroup memory samples.""" +from concurrent.futures import ThreadPoolExecutor +import hashlib +import json +import math +from pathlib import Path +import sys +import threading +import time + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT/'tests/own')) +from helpers import Client, check, containers, docker, png, save, upload + + +def memory(ids): + result = {} + for container in ids: + raw = docker('exec',container,'cat','/sys/fs/cgroup/memory.current').stdout + result[container] = int(raw) + return result + + +def percentile(values, p): + return sorted(values)[max(0, math.ceil(len(values)*p)-1)] + + +def kernel_peak(ids): + return {container:int(docker('exec',container,'cat','/sys/fs/cgroup/memory.peak').stdout) + for container in ids} + + +def main(): + c = Client(timeout=55) + alice,bob,_,chat = c.bootstrap() + upload(c,alice,chat,png()) + ids = containers('api') + results = {'concurrency':10, 'warmup_uploads':1, 'memory_method':'cgroup v2 memory.current sampled every >=100ms; values include file cache', 'runs':[]} + for width,height in ((512,512),(1024,768)): + content = png(width,height,noisy=True) + sha = hashlib.sha256(content).hexdigest() + baseline = memory(ids) + baseline_kernel_peak = kernel_peak(ids) + samples = [] + barrier = threading.Barrier(11) + def worker(number): + local = Client(timeout=55) + barrier.wait() + return upload(local,alice,chat,content,filename='concurrent-'+str(number)+'.png') + started = time.monotonic() + with ThreadPoolExecutor(max_workers=10) as pool: + futures = [pool.submit(worker,n) for n in range(10)] + barrier.wait() + while not all(f.done() for f in futures): + samples.append({'seconds':round(time.monotonic()-started,3), 'bytes':memory(ids)}) + time.sleep(.1) + responses = [f.result() for f in futures] + elapsed = time.monotonic()-started + samples.append({'seconds':round(elapsed,3), 'bytes':memory(ids)}) + for response in responses: + att = c.wait_ready(bob,response['json']) + check(att['sha256']==sha,'concurrent upload checksum mismatch') + downloaded = c.call('GET','/api/v1/attachments/'+att['id']+'/content',actor=bob) + check(hashlib.sha256(downloaded['bytes']).hexdigest()==sha,'concurrent downloaded bytes changed') + latency = [r['elapsed']*1000 for r in responses] + peak = {container:max(sample['bytes'][container] for sample in samples) for container in ids} + run = {'width':width, 'height':height, 'size_bytes':len(content), 'sha256':sha, + 'requests':10, 'successful':len(responses), 'errors':0, 'duration_seconds':round(elapsed,3), + 'successful_rps':round(len(responses)/elapsed,3), + 'latency_ms':{str(p):round(percentile(latency,p),3) for p in (.5,.95,.99)}, + 'baseline_bytes':baseline, 'sampled_peak_bytes':peak, + 'kernel_lifetime_peak_before_bytes':baseline_kernel_peak, + 'kernel_lifetime_peak_after_bytes':kernel_peak(ids), + 'sampled_peak_sum_bytes':max(sum(sample['bytes'].values()) for sample in samples), + 'samples':samples} + check(all(value<1536*1024*1024 for value in peak.values()),'API exceeded memory limit') + results['runs'].append(run) + print(json.dumps({k:v for k,v in run.items() if k!='samples'}),flush=True) + save('lab5-upload-memory.json',results) + print('PASS: ten simultaneous uploads at two sizes; all originals verified; memory samples saved.') + + +if __name__=='__main__': + main() diff --git a/scripts/plot_pipeline.py b/scripts/plot_pipeline.py new file mode 100644 index 00000000..d07a880d --- /dev/null +++ b/scripts/plot_pipeline.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +"""Render measured pipeline results; install requirements-research.txt first.""" +import argparse +import json +import os +from pathlib import Path +import tempfile + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('input', nargs='?', type=Path, default=Path('evidence/lab5-research.json')) + args = parser.parse_args() + os.environ['MPLCONFIGDIR'] = str(Path(tempfile.gettempdir()) / 'mtusi-lab5-matplotlib') + import matplotlib + matplotlib.use('Agg') + import matplotlib.pyplot as plt + + report = json.loads(args.input.read_text()) + assert report.get('result') == 'PASS', 'plot only completed experiments' + cases = report['cases'] + metrics = [ + ('throughput_rps', 'Throughput, images/s', 1), + ('ready_p95_ms', 'p95 POST start → ready, s', .001), + ('queue_lag_peak_seconds', 'Peak queued job age, s', 1), + ('rss_peak_bytes', 'Sampled worker + child RSS, MiB', 1 / 1024**2), + ] + plt.rcParams.update({'font.size': 10, 'axes.spines.top': False, 'axes.spines.right': False}) + figure, axes = plt.subplots(2, 2, figsize=(10, 7), layout='constrained') + for axis, (metric, label, factor) in zip(axes.flat, metrics): + for width in sorted({case['width'] for case in cases}): + series = sorted([case for case in cases if case['width'] == width], key=lambda c: c['concurrency']) + axis.plot(range(len(series)), [case[metric] * factor for case in series], + marker='o', linewidth=2, label=str(width) + ' × ' + str(series[0]['height'])) + axis.set_xticks(range(len(series)), [str(c['concurrency']) + '/' + str(c['prefetch']) for c in series]) + axis.set_xlabel('Concurrency / prefetch') + axis.set_ylabel(label) + axis.set_ylim(bottom=0) + axis.grid(axis='y', alpha=.25) + axis.legend(title='PNG pixels') + figure.suptitle('Redis Streams image pipeline — finite burst on one host\n' + + str(report['requests_per_case']) + ' images per case; sampled RSS and queue lag', fontsize=13) + for suffix in ('.svg', '.png'): + target = args.input.with_suffix(suffix) + figure.savefig(target, dpi=180, metadata={'Creator': 'Matplotlib'}) + print(target) + plt.close(figure) + + +if __name__ == '__main__': + main() diff --git a/scripts/restart.sh b/scripts/restart.sh new file mode 100755 index 00000000..211f35b4 --- /dev/null +++ b/scripts/restart.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +cd "$(dirname "$0")/.." +exec python3 scripts/swarm.py restart diff --git a/scripts/stop-one.sh b/scripts/stop-one.sh new file mode 100755 index 00000000..8a93f7f0 --- /dev/null +++ b/scripts/stop-one.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +cd "$(dirname "$0")/.." +exec python3 scripts/swarm.py stop-one diff --git a/scripts/swarm.py b/scripts/swarm.py new file mode 100644 index 00000000..e90e26bb --- /dev/null +++ b/scripts/swarm.py @@ -0,0 +1,299 @@ +#!/usr/bin/env python3 +"""Single-node Swarm lab lifecycle; never deletes volumes or prints credentials.""" +import json +import os +from pathlib import Path +import subprocess +import sys +import time +import urllib.request + +ROOT = Path(__file__).resolve().parents[1] +os.chdir(ROOT) +STACK = os.environ.get('STACK_NAME', 'mtusi-lab5') +API = os.environ.get('API_IMAGE', 'mtusi-messenger:lab5') +MIGRATIONS = os.environ.get('MIGRATIONS_IMAGE', 'mtusi-migrations:lab5') +TESTS = os.environ.get('TESTS_IMAGE', 'mtusi-messenger-tests:lab5') +S3 = os.environ.get('S3_IMAGE', 'mtusi-minio:RELEASE.2025-09-07T16-13-09Z') +MC = os.environ.get('S3_CLIENT_IMAGE', 'mtusi-mc:RELEASE.2025-08-13T08-35-41Z') +PORT = os.environ.get('PORT', '18085') +SECRETS = ('postgres_password', 'cursor_key', 's3_root_access_key', + 's3_root_secret_key', 's3_access_key', 's3_secret_key') + + +def docker(*args, capture=False, **kwargs): + return subprocess.run(['docker', *args], check=True, text=True, + stdout=subprocess.PIPE if capture else None, **kwargs).stdout + + +def inspect(kind, name): + return json.loads(docker(kind, 'inspect', name, capture=True))[0] + + +def tasks(service): + ids = docker('service', 'ps', '--filter', 'desired-state=running', '-q', STACK+'_'+service, capture=True).split() + return [json.loads(docker('inspect', task, capture=True))[0] for task in ids] + + +def wait_service(service, count=1, timeout=120): + deadline = time.monotonic() + timeout + while time.monotonic() < deadline: + active = tasks(service) + if len(active) == count and all(t['Status']['State'] == 'running' for t in active): + # This lab pins storage to this manager and runs on one Docker engine. + healthy = True + for task in active: + container = task['Status'].get('ContainerStatus', {}).get('ContainerID') + state = json.loads(docker('inspect', container, capture=True))[0]['State'] + healthy &= state.get('Health', {}).get('Status', 'healthy') == 'healthy' + if healthy: + return + time.sleep(1) + raise RuntimeError('service did not become healthy: '+service) + + +def wait_api(): + wait_service('api', int(os.environ.get('API_REPLICAS', '2'))) + deadline = time.monotonic()+45 + while time.monotonic() < deadline: + try: + with urllib.request.urlopen('http://localhost:'+PORT+'/health/ready', timeout=3) as response: + if response.status == 200: + return + except OSError: + pass + time.sleep(.5) + raise RuntimeError('LB readiness timeout') + + +def job(kind, image, command, integration=False): + name = STACK+'_'+kind + # Fixed service name is a deployment lock: concurrent runners fail to create it. + args = ['service', 'create', '--detach', '--no-resolve-image', '--name', name, '--mode', 'replicated-job', + '--replicas', '1', '--restart-condition', 'none', '--network', STACK+'_data', + '--constraint', 'node.labels.mtusi_lab5_storage==true', + '--limit-cpu', '1', '--limit-memory', '1g' if integration else '128m', + '--secret', 'source='+STACK+'_postgres_password,target=postgres_password', + '--env', 'POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password'] + if integration: + for value in ['INTEGRATION_TESTS=1', 'POSTGRES_HOST=postgres', 'POSTGRES_USER=messenger', + 'POSTGRES_DB=messenger', 'REDIS_ADDR=redis:6379', 'CURSOR_KEY_FILE=/run/secrets/cursor_key', + 'S3_ENDPOINT=minio:9000', 'S3_BUCKET=attachments', + 'S3_ACCESS_KEY_FILE=/run/secrets/s3_access_key', 'S3_SECRET_KEY_FILE=/run/secrets/s3_secret_key']: + args += ['--env', value] + args += ['--secret', 'source='+STACK+'_cursor_key,target=cursor_key'] + for secret in ('s3_access_key', 's3_secret_key'): + args += ['--secret', 'source='+STACK+'_'+secret+',target='+secret] + else: + args += ['--env', 'GOOSE_DRIVER=postgres', '--env', + 'GOOSE_DBSTRING=host=postgres user=messenger dbname=messenger sslmode=disable connect_timeout=5'] + docker(*args, image, *command) + wait_job(name, kind, 300 if integration else 90) + + +def wait_job(name, kind, timeout=90): + try: + deadline = time.monotonic()+timeout + while time.monotonic() < deadline: + ids = docker('service', 'ps', '-q', name, capture=True).split() + states = [json.loads(docker('inspect', i, capture=True))[0]['Status']['State'] for i in ids] + if 'complete' in states: + docker('service', 'logs', name) + return + if any(s in ('failed', 'rejected') for s in states): + docker('service', 'logs', name) + raise RuntimeError(kind+' failed') + time.sleep(1) + raise RuntimeError(kind+' timed out') + finally: + docker('service', 'rm', name) + + +def bootstrap_s3(): + name = STACK+'_s3-bootstrap' + args = ['service', 'create', '--detach', '--no-resolve-image', '--name', name, '--mode', 'replicated-job', + '--replicas', '1', '--restart-condition', 'none', '--network', STACK+'_data', + '--constraint', 'node.labels.mtusi_lab5_storage==true', + '--limit-cpu', '0.5', '--limit-memory', '512m', '--entrypoint', '/bin/sh', + '--config', 'source='+STACK+'_s3_bootstrap,target=/bootstrap.sh', + '--config', 'source='+STACK+'_s3_policy_v5,target=/policy.json'] + for secret in SECRETS[2:]: + args += ['--secret', 'source='+STACK+'_'+secret+',target='+secret] + docker(*args, MC, '/bootstrap.sh') + wait_job(name, 'S3 bootstrap') + + +def reconcile(): + active = tasks('api') + if not active: + raise RuntimeError('no API task available for reconciliation') + container = active[0]['Status']['ContainerStatus']['ContainerID'] + docker('exec', container, '/usr/local/bin/reconcile', *sys.argv[2:]) + + +def worker_cli(args): + active=[t for t in tasks('worker') if t['Status']['State']=='running'] + if not active: raise RuntimeError('start worker before using its operator CLI') + docker('exec',active[0]['Status']['ContainerStatus']['ContainerID'],'/usr/local/bin/worker',*args) + + +def build(): + if os.environ.get('SKIP_STORAGE_BUILD') != '1': + docker('build', '-f', 'Dockerfile.storage', '--target', 'minio', '-t', S3, '.') + docker('build', '-f', 'Dockerfile.storage', '--target', 'mc', '-t', MC, '.') + else: + docker('image','inspect',S3,MC,capture=True) + docker('build', '-t', API, '.') + docker('build', '--target', 'migrations', '-t', MIGRATIONS, '.') + + +def up(): + swarm = json.loads(docker('info', '--format', '{{json .Swarm}}', capture=True)) + if swarm['LocalNodeState'] == 'inactive': + docker('swarm', 'init', capture=True) # join token stays out of logs + swarm = json.loads(docker('info', '--format', '{{json .Swarm}}', capture=True)) + if not swarm['ControlAvailable']: + raise RuntimeError('run on the Swarm manager') + if len(docker('node', 'ls', '-q', capture=True).split()) != 1: + raise RuntimeError('automatic lifecycle supports one Swarm node; see REPORT.md for image distribution') + docker('node', 'update', '--label-add', 'mtusi_lab5_storage=true', swarm['NodeID']) + subprocess.run(['./scripts/bootstrap.sh'], check=True) + for secret in SECRETS: + known = docker('secret', 'ls', '--format', '{{.Name}}', capture=True).split() + if STACK+'_'+secret not in known: + docker('secret', 'create', STACK+'_'+secret, 'secrets/'+secret) + build() + existing = docker('service', 'ls', '--format', '{{.Name}}', capture=True).split() + # Upgrade the shared schema before replacing any running API image. + fresh = STACK+'_api' not in existing + if not fresh: + # A maintenance barrier prevents old lab4 writers inserting ready-only rows + # after the one-shot async backfill but before the new API image starts. + docker('service','scale','--detach',STACK+'_api=0') + deadline=time.monotonic()+45 + while docker('ps','--filter','label=com.docker.swarm.service.name='+STACK+'_api','-q',capture=True).strip(): + if time.monotonic()>deadline: raise RuntimeError('old API did not drain before migrations') + time.sleep(.5) + job('migrations', MIGRATIONS, ['up']) + # Initial deployment keeps API at zero until the one-shot migration succeeds. + env = dict(os.environ) + env['STACK_NAME'] = STACK + if fresh: + env['API_REPLICAS'] = '0' + docker('stack', 'deploy', '--resolve-image', 'never', '-c', 'stack.yaml', STACK, env=env) + wait_service('postgres') + wait_service('redis') + wait_service('minio') + bootstrap_s3() + if fresh: + job('migrations', MIGRATIONS, ['up']) + docker('service', 'scale', '--detach', STACK+'_api='+os.environ.get('API_REPLICAS', '2')) + if fresh: + wait_api() + else: + update() + wait_service('worker') + print('PASS: Swarm stack ready at http://localhost:'+PORT) + + +def restart(): + # Force replaces every task while retaining the same Swarm secrets and volumes. + services = ('postgres', 'redis', 'minio', 'api', 'lb', 'worker') + previous = {name: {t['ID'] for t in tasks(name)} for name in services} + for service in services: + docker('service', 'update', '--detach', '--force', STACK+'_'+service) + deadline = time.monotonic()+75 + while any(previous[name].intersection(t['ID'] for t in tasks(name)) for name in services): + if time.monotonic() > deadline: + raise RuntimeError('restart did not replace every original task') + time.sleep(1) + wait_service('lb') + wait_service('postgres') + wait_service('redis') + wait_service('minio') + wait_api() + + +def stop_one(): + target = os.environ['TARGET_INSTANCE_ID'] + matches = [t for t in tasks('api') if t['ID'] == target] + if len(matches) != 1: + raise RuntimeError('TARGET_INSTANCE_ID is not a running API task in this stack') + task = matches[0] + container = task['Status']['ContainerStatus']['ContainerID'] + print('Stopping task '+target+' container '+container, flush=True) + docker('kill', container) # Swarm replaces it with a different task/instance ID. + + +def update(): + previous = {t['ID'] for t in tasks('api')} + docker('service', 'update', '--detach', '--force', '--no-resolve-image', '--image', API, STACK+'_api') + deadline = time.monotonic()+180 + while time.monotonic() < deadline: + state = inspect('service', STACK+'_api').get('UpdateStatus', {}).get('State') + if state == 'completed' and previous.isdisjoint(t['ID'] for t in tasks('api')): + wait_api() + docker('service','update','--detach','--force','--no-resolve-image','--image',API,STACK+'_worker') + wait_service('worker') + print('PASS: rolling update completed (API and worker image refreshed)') + return + if state in ('paused', 'rollback_started', 'rollback_paused', 'rollback_completed'): + raise RuntimeError('rolling update: '+state) + time.sleep(1) + raise RuntimeError('rolling update timed out') + + +def status(): + result = {'stack': STACK, 'docker': docker('version','--format','{{.Server.Version}}',capture=True).strip(), 'services': {}} + for name in ('lb','api','worker','postgres','redis','minio'): + service = inspect('service', STACK+'_'+name) + spec = service['Spec'] + template = spec['TaskTemplate'] + result['services'][name] = { + 'image': template['ContainerSpec']['Image'], + 'limits': template.get('Resources',{}).get('Limits',{}), + 'published_ports': spec.get('EndpointSpec',{}).get('Ports',[]), + 'secret_names': [x['SecretName'] for x in template['ContainerSpec'].get('Secrets',[])], + 'mounts': template['ContainerSpec'].get('Mounts',[]), + 'tasks': [{'id':t['ID'],'state':t['Status']['State'], + 'container':t['Status'].get('ContainerStatus',{}).get('ContainerID')} + for t in tasks(name)]} + print(json.dumps(result,indent=2)) + +def main(): + action = sys.argv[1] + if action == 'status': status() + elif action == 'up': up() + elif action == 'build': build() + elif action == 'bootstrap-s3': bootstrap_s3() + elif action == 'reconcile': reconcile() + elif action == 'worker-stop': + docker('service','scale','--detach',STACK+'_worker=0') + deadline=time.monotonic()+30 + while docker('ps','--filter','label=com.docker.swarm.service.name='+STACK+'_worker','-q',capture=True).strip(): + if time.monotonic()>deadline: raise RuntimeError('worker did not stop') + time.sleep(.2) + elif action == 'worker-start': + docker('service','scale','--detach',STACK+'_worker=1') + wait_service('worker') + elif action == 'failed-jobs': worker_cli(['--failed']) + elif action == 'replay': worker_cli(sys.argv[2:]) + elif action == 'wait': wait_api() + elif action == 'restart': restart() + elif action == 'stop-one': stop_one() + elif action == 'update': update() + elif action == 'migrate': job('migrations', MIGRATIONS, ['up']) + elif action == 'migrate-status': job('migrations', MIGRATIONS, ['status']) + elif action == 'test-integration': + docker('build', '--target', 'tests', '-t', TESTS, '.') + job('tests', TESTS, [], integration=True) + elif action == 'down': docker('stack', 'rm', STACK) + else: raise RuntimeError('unknown action: '+action) + + +if __name__ == '__main__': + try: + main() + except (RuntimeError, subprocess.CalledProcessError) as error: + print('FAIL: '+str(error), file=sys.stderr) + sys.exit(1) diff --git a/stack.yaml b/stack.yaml new file mode 100644 index 00000000..d984126d --- /dev/null +++ b/stack.yaml @@ -0,0 +1,187 @@ +version: '3.8' +services: + postgres: + image: postgres:17.6-alpine3.22 + environment: + POSTGRES_USER: messenger + POSTGRES_DB: messenger + POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password + secrets: [postgres_password] + volumes: [postgres_data:/var/lib/postgresql/data] + networks: [data] + healthcheck: + test: [CMD-SHELL, 'pg_isready -U messenger -d messenger'] + interval: 2s + timeout: 2s + retries: 15 + stop_grace_period: 20s + deploy: + replicas: 1 + placement: + constraints: [node.labels.mtusi_lab5_storage == true] + resources: + limits: {cpus: '1.0', memory: 512M} + update_config: {parallelism: 1, order: stop-first} + redis: + image: redis:7.4.5-alpine3.21 + command: [redis-server, /usr/local/etc/redis/redis.conf] + configs: + - source: redis + target: /usr/local/etc/redis/redis.conf + volumes: [redis_data:/data] + networks: [data] + healthcheck: + test: [CMD, redis-cli, ping] + interval: 2s + timeout: 1s + retries: 15 + stop_grace_period: 20s + deploy: + replicas: 1 + placement: + constraints: [node.labels.mtusi_lab5_storage == true] + resources: + limits: {cpus: '0.5', memory: 384M} + update_config: {parallelism: 1, order: stop-first} + minio: + image: ${S3_IMAGE:-mtusi-minio:RELEASE.2025-09-07T16-13-09Z} + secrets: [s3_root_access_key, s3_root_secret_key] + volumes: [s3_data:/data] + networks: [data] + healthcheck: + test: [CMD, wget, -q, -T, '2', -O, /dev/null, 'http://127.0.0.1:9000/minio/health/live'] + interval: 2s + timeout: 3s + start_period: 15s + retries: 15 + stop_grace_period: 20s + deploy: + replicas: 1 + placement: + constraints: [node.labels.mtusi_lab5_storage == true] + resources: + limits: {cpus: '1.0', memory: 512M} + update_config: {parallelism: 1, order: stop-first} + api: + image: ${API_IMAGE:-mtusi-messenger:lab5} + environment: &api_environment + INSTANCE_ID: '{{.Task.ID}}' + POSTGRES_HOST: postgres + POSTGRES_USER: messenger + POSTGRES_DB: messenger + POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password + CURSOR_KEY_FILE: /run/secrets/cursor_key + POSTGRES_MAX_CONNS: '10' + REDIS_ADDR: redis:6379 + SESSION_TTL_SECONDS: '3600' + QUERY_TIMEOUT_MS: '1000' + S3_ENDPOINT: minio:9000 + S3_BUCKET: attachments + S3_ACCESS_KEY_FILE: /run/secrets/s3_access_key + S3_SECRET_KEY_FILE: /run/secrets/s3_secret_key + S3_USE_SSL: 'false' + GOMEMLIMIT: 1152MiB + GOGC: '50' + secrets: [postgres_password, cursor_key, s3_access_key, s3_secret_key] + networks: [backend, data] + stop_grace_period: 15s + healthcheck: + test: [CMD, wget, -q, -T, '2', -O, /dev/null, 'http://127.0.0.1:8080/health/ready'] + interval: 2s + timeout: 3s + start_period: 10s + retries: 3 + deploy: + replicas: ${API_REPLICAS:-2} + endpoint_mode: dnsrr + resources: + limits: {cpus: '1.0', memory: 1536M} + restart_policy: {condition: any, delay: 1s} + update_config: + parallelism: 1 + order: start-first + delay: 5s + monitor: 15s + failure_action: rollback + rollback_config: {parallelism: 1, order: start-first} + worker: + image: ${API_IMAGE:-mtusi-messenger:lab5} + entrypoint: [/usr/local/bin/worker] + environment: + <<: *api_environment + WORKER_CONCURRENCY: '2' + WORKER_PREFETCH: '4' + WORKER_MAX_ATTEMPTS: '5' + WORKER_TIMEOUT_SECONDS: '25' + WORKER_LEASE_SECONDS: '40' + WORKER_PIXEL_BUDGET: '40000000' + secrets: [postgres_password, cursor_key, s3_access_key, s3_secret_key] + networks: [data] + healthcheck: {disable: true} + stop_grace_period: 10s + deploy: + replicas: 1 + resources: + limits: {cpus: '1.0', memory: 1536M} + restart_policy: {condition: any, delay: 1s} + update_config: {parallelism: 1, order: stop-first} + lb: + image: haproxy:3.2.6-alpine + configs: + - source: haproxy + target: /usr/local/etc/haproxy/haproxy.cfg + networks: [backend] + ports: + - target: 8080 + published: ${PORT:-18085} + protocol: tcp + mode: host + healthcheck: + test: [CMD, haproxy, -c, -f, /usr/local/etc/haproxy/haproxy.cfg] + interval: 5s + timeout: 2s + retries: 3 + deploy: + replicas: 1 + resources: + limits: {cpus: '0.5', memory: 128M} + update_config: {parallelism: 1, order: stop-first} +networks: + backend: + driver: overlay + data: + driver: overlay +volumes: + postgres_data: + redis_data: + s3_data: +configs: + haproxy: + file: ./infra/haproxy.cfg + redis: + name: ${STACK_NAME:-mtusi-lab5}_redis_v5 + file: ./infra/redis.conf + s3_bootstrap: + file: ./infra/s3-bootstrap.sh + s3_policy: + name: ${STACK_NAME:-mtusi-lab5}_s3_policy_v5 + file: ./infra/s3-policy.json +secrets: + postgres_password: + external: true + name: ${STACK_NAME:-mtusi-lab5}_postgres_password + cursor_key: + external: true + name: ${STACK_NAME:-mtusi-lab5}_cursor_key + s3_root_access_key: + external: true + name: ${STACK_NAME:-mtusi-lab5}_s3_root_access_key + s3_root_secret_key: + external: true + name: ${STACK_NAME:-mtusi-lab5}_s3_root_secret_key + s3_access_key: + external: true + name: ${STACK_NAME:-mtusi-lab5}_s3_access_key + s3_secret_key: + external: true + name: ${STACK_NAME:-mtusi-lab5}_s3_secret_key diff --git a/tests/own/README.md b/tests/own/README.md new file mode 100644 index 00000000..31e10eb5 --- /dev/null +++ b/tests/own/README.md @@ -0,0 +1,20 @@ +# Проверки lab5 + +`make test` запускает неизменённый публичный smoke lab5. +`make test-own` запускает Go-тесты с race detector. +`make test-integration` проверяет реальные миграции, транзакции, гонки, пагинацию, fencing и версии. +`make test-lab5` проверяет реальные Redis Streams, MinIO и PostgreSQL. +Сценарий проверяет границы staging/COMMIT/publish/objects/COMMIT/ack и восстановление после остановки компонентов. +Он проверяет retry, failed registry, audit replay, process timeout и cleanup. +Проверки JPEG/WebP, EXIF, alpha и малых изображений используют Pillow из `requirements-research.txt`. +Сценарии изменяют только свой стек и синтетические данные. +Запускайте проверки отказов последовательно. + +`make test-lab4` и `make test-reconcile` оставлены как совместимые имена для полного `test-lab5`. +Старые `reconcile.py` и `grade4.py` сохраняют исторические сценарии; напрямую их не запускайте. +`make test-persistence` проверяет общий restart; `make test-failover` проверяет остановку одной API-реплики. + +`make benchmark` измеряет очередь под перегрузкой для трёх настроек и двух размеров изображений. +`make plot-research` строит графики по фактическому JSON. +Методика и результаты находятся в [RESEARCH.md](../../RESEARCH.md). +Новые доказательства используют имена `evidence/lab5-*`; исходные lab4 evidence считаются историческими. diff --git a/tests/own/grade4.py b/tests/own/grade4.py new file mode 100644 index 00000000..60f89b87 --- /dev/null +++ b/tests/own/grade4.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python3 +"""Additional lab2 acceptance checks. Never print credentials or session tokens.""" +import base64 +from concurrent.futures import ThreadPoolExecutor +import os +from pathlib import Path +import subprocess +import sys +import time +import uuid + +sys.path.insert(0, str(Path(__file__).resolve().parents[1])) +from client import Client, Failure, check, run + +ROOT = Path(__file__).resolve().parents[2] + + +def compose(*args, ttl=None): + env = dict(os.environ) + if ttl is not None: + env['SESSION_TTL_SECONDS'] = str(ttl) + result = subprocess.run([str(ROOT / 'scripts/compose.sh'), *args], env=env, + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=180) + check(result.returncode == 0, 'compose operation failed: ' + args[0]) + + +def login(c, username, password, expected=201): + basic = base64.b64encode((username + ':' + password).encode()).decode() + return c.call('POST', '/api/v1/auth/sessions', expected, + headers={'Authorization': 'Basic ' + basic}, schema='Session' if expected == 201 else None) + + +def main(): + c = Client(timeout=5) + alice, bob, eve, chat = c.bootstrap() + credentials = alice['registration'] + login(c, credentials['username'], 'incorrect-password', 401) + login(c, 'unknown_' + uuid.uuid4().hex[:12], 'incorrect-password', 401) + c.call('GET', '/api/v1/users/me', 401, headers={'X-User-Id': alice['id']}) + basic = base64.b64encode((credentials['username'] + ':' + credentials['password']).encode()).decode() + c.call('GET', '/api/v1/users/me', 401, headers={'Authorization': 'Basic ' + basic}) + response = c.call('GET', '/api/v1/users/me', actor=alice, headers={'X-User-Id': bob['id']}, schema='User') + check(response['json']['id'] == alice['id'], 'X-User-Id changed session owner') + c.call('DELETE', '/api/v1/auth/sessions/current', 204, actor=alice) + c.call('GET', '/api/v1/users/me', 401, actor=alice) + c.call('DELETE', '/api/v1/auth/sessions/current', 401, actor=alice) + print('PASS: wrong password, unknown user, Bearer-only access, X-User-Id ignored, logout') + + # Maximum UTF-8 password length and a colon are supported without truncation. + username = 'unicode_' + uuid.uuid4().hex[:12] + password = '🔑' * 127 + ':' + c.call('POST', '/api/v1/users', 201, body={'username': username, 'display_name': 'Unicode', 'password': password}, schema='User') + login(c, username, password) + login(c, username, '🔑' * 127 + 'x', 401) + print('PASS: 128-code-point Unicode password including colon; suffix verified') + + username = 'race_' + uuid.uuid4().hex[:12] + def register(_): + return Client().call('POST', '/api/v1/users', [201, 409], body={ + 'username': username, 'display_name': 'Concurrent', 'password': 'synthetic-password-123' + })['status'] + with ThreadPoolExecutor(max_workers=8) as pool: + statuses = list(pool.map(register, range(8))) + check(statuses.count(201) == 1 and statuses.count(409) == 7, 'registration race broken') + print('PASS: HTTP registration race: one 201, seven 409') + + # Revoke before restart: absence must also survive AOF recovery. + for service in ('redis', 'postgres'): + compose('stop', service) + try: + c.call('GET', '/health/live', schema='Health') + start = time.monotonic() + c.call('GET', '/health/ready', 503) + check(time.monotonic() - start < 4, 'readiness error exceeded timeout budget') + c.call('GET', '/api/v1/users/me', 503, actor=bob) + c.call('GET', '/api/v1/users/me', 401, headers={'X-User-Id': bob['id']}) + login(c, bob['registration']['username'], bob['registration']['password'], 503) + c.call('POST', '/api/v1/chats/' + chat['id'] + '/messages', 503, actor=bob, body={'text': 'must fail'}) + finally: + compose('up', '-d', '--wait', service) + c.call('GET', '/health/ready', schema='Health') + c.call('GET', '/api/v1/users/me', actor=bob, schema='User') + c.call('GET', '/api/v1/users/me', 401, actor=alice) + print('PASS: ' + service + ' outage bounded; live=200, ready=503, protected=503, anonymous=401; session recovered, logout retained') + + # The same signed cursor remains valid across an API process restart. + c.message(bob, chat, 'cursor before restart 1') + c.message(bob, chat, 'cursor before restart 2') + page = c.call('GET', '/api/v1/chats/' + chat['id'] + '/messages?limit=1', actor=bob, schema='MessagePage')['json'] + check(page['next_cursor'] is not None, 'missing cursor') + compose('restart', 'api') + deadline = time.monotonic() + 30 + while True: + try: + c.call('GET', '/health/ready', schema='Health') + break + except Failure: + check(time.monotonic() < deadline, 'API did not recover') + time.sleep(.2) + from urllib.parse import quote + c.call('GET', '/api/v1/chats/' + chat['id'] + '/messages?cursor=' + quote(page['next_cursor']), actor=bob, schema='MessagePage') + print('PASS: cursor and existing session survive API restart') + + try: + compose('up', '-d', '--wait', '--force-recreate', 'api', ttl=2) + short = c.user('expiry') + c.call('GET', '/api/v1/users/me', actor=short, schema='User') + time.sleep(2.2) + c.call('GET', '/api/v1/users/me', 401, actor=short) + compose('restart', 'redis') + compose('up', '-d', '--wait', 'redis') + c.call('GET', '/api/v1/users/me', 401, actor=short) + print('PASS: SESSION_TTL_SECONDS=2 expires; Redis restart does not revive expired session') + finally: + compose('up', '-d', '--wait', '--force-recreate', 'api', ttl=3600) + print('PASS: all grade-4 HTTP checks; normal TTL restored to 3600') + + +if __name__ == '__main__': + run(main) diff --git a/tests/own/helpers.py b/tests/own/helpers.py new file mode 100644 index 00000000..d8032414 --- /dev/null +++ b/tests/own/helpers.py @@ -0,0 +1,129 @@ +"""Local lab4 experiment helpers. Never print credentials or session tokens.""" +import json +import os +from pathlib import Path +import random +import struct +import subprocess +import sys +import time +import uuid +import zlib + +ROOT = Path(__file__).resolve().parents[2] +sys.path.insert(0, str(ROOT / 'tests')) +from client import Client, check + +STACK = os.environ.get('STACK_NAME', 'mtusi-lab5') +MC = os.environ.get('S3_CLIENT_IMAGE', 'mtusi-mc:RELEASE.2025-08-13T08-35-41Z') + + +def docker(*args, data=None, check_result=True): + return subprocess.run(['docker', *args], input=data, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, check=check_result) + + +def containers(service): + ids = docker('ps', '--filter', 'label=com.docker.swarm.service.name='+STACK+'_'+service, + '--format', '{{.ID}}').stdout.decode().split() + check(bool(ids), 'no container for '+service) + return ids + + +def sql(statement): + result = docker('exec', '-i', containers('postgres')[0], 'psql', '-U', 'messenger', + '-d', 'messenger', '-At', '-v', 'ON_ERROR_STOP=1', data=statement.encode()) + return result.stdout.decode().strip() + + +def reconcile(apply=False, grace='90s'): + args = ['exec', containers('api')[0], '/usr/local/bin/reconcile', '--grace='+grace] + if apply: + args.append('--apply') + return json.loads(docker(*args).stdout) + + +def upload(c, actor, chat, content, filename='sample.png', mime='image/png', expected=202): + from urllib.parse import quote + return c.call('POST', '/api/v1/chats/'+chat['id']+'/attachments?filename='+quote(filename, safe=''), + expected, actor=actor, raw=content, headers={'Content-Type': mime}, + schema='Attachment' if expected == 202 else None) + + +def png(width=320, height=200, noisy=False): + def chunk(kind, body): + return struct.pack('>I', len(body))+kind+body+struct.pack('>I', zlib.crc32(kind+body)) + rng = random.Random(419) + lines = b''.join(b'\0'+(rng.randbytes(width*3) if noisy else b'\x18\x60\xc0'*width) + for _ in range(height)) + return (b'\x89PNG\r\n\x1a\n'+chunk(b'IHDR', struct.pack('>IIBBBBB', width, height, 8, 2, 0, 0, 0)) + +chunk(b'IDAT', zlib.compress(lines))+chunk(b'IEND', b'')) + + +def oversized_dimensions(): + body = struct.pack('>IIBBBBB', 10000, 4001, 8, 2, 0, 0, 0) + return b'\x89PNG\r\n\x1a\n'+struct.pack('>I', len(body))+b'IHDR'+body+struct.pack('>I', zlib.crc32(b'IHDR'+body)) + + +def save(name, result): + (ROOT / 'evidence').mkdir(exist_ok=True) + (ROOT / 'evidence' / name).write_text(json.dumps(result, indent=2, ensure_ascii=False)+'\n') + + +def wait_ready(timeout=90): + deadline = time.monotonic()+timeout + stable_since = None + previous = None + while time.monotonic() < deadline: + try: + ids=docker('service','ps','--filter','desired-state=running','-q',STACK+'_api').stdout.decode().split() + wanted=json.loads(docker('service','inspect',STACK+'_api').stdout)[0]['Spec']['Mode']['Replicated']['Replicas'] + check(wanted>0 and len(ids)==wanted,'API count') + ts=json.loads(docker('inspect',*ids).stdout) + check(all(t['Status']['State']=='running' for t in ts),'API task state') + cs=json.loads(docker('inspect',*[t['Status']['ContainerStatus']['ContainerID'] for t in ts]).stdout) + check(all(c['State'].get('Health',{}).get('Status')=='healthy' for c in cs),'API health') + Client(timeout=2).call('GET','/health/ready',schema='Health') + current=frozenset(ids) + if current!=previous: stable_since=time.monotonic() + previous=current + if stable_since is not None and time.monotonic()-stable_since>=5:return + except (AssertionError,subprocess.CalledProcessError,KeyError): + stable_since=None;previous=None + time.sleep(.5) + raise AssertionError('all API replicas and LB did not stabilize') + + +class Probe: + """Short-lived mc service; root secrets remain inside Docker secrets.""" + def __enter__(self): + self.name = STACK+'_probe_'+uuid.uuid4().hex[:8] + args = ['service', 'create', '--detach', '--no-resolve-image', '--name', self.name, '--network', STACK+'_data', + '--restart-condition', 'none', '--limit-memory', '512m', '--limit-cpu', '0.5', + '--entrypoint', '/bin/sh'] + for secret in ('s3_root_access_key', 's3_root_secret_key', 's3_access_key', 's3_secret_key'): + args += ['--secret', 'source='+STACK+'_'+secret+',target='+secret] + docker(*args, MC, '-c', 'sleep 3600') + deadline = time.monotonic()+45 + while time.monotonic() < deadline: + ids = docker('ps', '--filter', 'label=com.docker.swarm.service.name='+self.name, '-q').stdout.decode().split() + if ids: + self.container = ids[0] + return self + time.sleep(.3) + docker('service', 'rm', self.name, check_result=False) + raise AssertionError('probe did not start') + + def mc(self, *args, data=None, admin=False, expected=0): + access = 's3_root_access_key' if admin else 's3_access_key' + secret = 's3_root_secret_key' if admin else 's3_secret_key' + script = ('set -eu; export MC_CONFIG_DIR=/tmp/mc; ' + 'mc alias set local http://minio:9000 "$(cat /run/secrets/'+access+')" ' + '"$(cat /run/secrets/'+secret+')" >/dev/null; exec mc "$@"') + result = docker('exec', '-i', self.container, '/bin/sh', '-c', script, 'sh', *args, + data=data, check_result=False) + check((result.returncode == 0) == (expected == 0), 'unexpected mc outcome: '+args[0]) + return result + + def __exit__(self, *args): + docker('service', 'rm', self.name, check_result=False) diff --git a/tests/own/lab5.py b/tests/own/lab5.py new file mode 100644 index 00000000..abf16c6c --- /dev/null +++ b/tests/own/lab5.py @@ -0,0 +1,327 @@ +#!/usr/bin/env python3 +"""Real Redis Streams/S3/PostgreSQL fault tests; only the isolated lab5 stack.""" +import hashlib +import datetime as dt +import io +import json +import os +from pathlib import Path +import subprocess +import sys +import time +import uuid + +from helpers import Client, Probe, ROOT, STACK, check, containers, docker, png, oversized_dimensions, sql, upload +sys.path.insert(0, str(ROOT/'tests')) +from client import Failure +from image_probe import jpeg_size + +STREAM = 'attachments:jobs:v1' +GROUP = 'image-workers-v1' +RESULT = {'stack': STACK, 'cases': {}, 'started_at': time.time()} +if '--tail-only' in sys.argv: + previous=ROOT/'evidence/lab5-faults.json' + check(previous.is_file(),'tail-only needs previously saved successful fault cases') + RESULT=json.loads(previous.read_text()) + RESULT.setdefault('resumed_at',[]).append(time.time()) + + +def save(): + (ROOT/'evidence/lab5-faults.json').write_text(json.dumps(RESULT, indent=2)+'\n') + + +def until(operation, predicate=bool, timeout=90): + deadline = time.monotonic()+timeout + last = None + while time.monotonic() < deadline: + try: + last = operation() + if predicate(last): + return last + except (AssertionError, subprocess.CalledProcessError, KeyError, IndexError): + pass + time.sleep(.2) + raise AssertionError('condition deadline exceeded; last='+str(last)) + + +def tasks(service): + ids = docker('service','ps','--filter','desired-state=running','-q',STACK+'_'+service).stdout.decode().split() + if not ids: + return [] + return json.loads(docker('inspect',*ids).stdout) + + +def settled(service, count): + stable = [None, None] + def ready(): + spec=json.loads(docker('service','inspect',STACK+'_'+service).stdout)[0] + check(spec.get('UpdateStatus',{}).get('State','completed')=='completed','service update not completed') + ts = tasks(service) + check(len(ts)==count, 'wrong task count') + if not count: + live=docker('ps','--filter','label=com.docker.swarm.service.name='+STACK+'_'+service,'-q').stdout.strip() + check(not live,'old worker container still running') + return True + check(all(t['Status']['State']=='running' for t in ts), 'task not running') + states = json.loads(docker('inspect',*[t['Status']['ContainerStatus']['ContainerID'] for t in ts]).stdout) + check(all(s['State'].get('Health',{}).get('Status','healthy')=='healthy' for s in states), 'unhealthy container') + if service=='api': + Client(timeout=2).call('GET','/health/ready',schema='Health') + ids = frozenset(t['ID'] for t in ts) + if ids != stable[0]: + stable[:] = [ids,time.monotonic()] + return time.monotonic()-stable[1]>=4 + def observe(): + try: + return ready() + except (AssertionError,subprocess.CalledProcessError,KeyError,IndexError): + stable[:]=[None,None] + raise + until(observe, timeout=120) + + +def control(service, values=None, replicas=None, force=False): + args = ['service','update','--detach'] + for key,value in (values or {}).items(): + args += ['--env-rm',key] if value is None else ['--env-add',key+'='+str(value)] + if replicas is not None: + args += ['--replicas',str(replicas)] + if force: + args += ['--force'] + docker(*args,STACK+'_'+service) + if replicas is None: + spec = json.loads(docker('service','inspect',STACK+'_'+service).stdout)[0] + replicas = spec['Spec']['Mode']['Replicated']['Replicas'] + settled(service,replicas) + + +def redis(*args): + return json.loads(docker('exec',containers('redis')[0],'redis-cli','--json',*args).stdout) + + +def job(att): + return json.loads(sql("SELECT row_to_json(j) FROM attachment_jobs j WHERE attachment_id='"+att['id']+"';")) + + +def wait_state(att, state, timeout=90): + return until(lambda: job(att), lambda j: j['state']==state, timeout) + + +def variant_check(c, actor, att, original, expected_thumb=(256,160)): + ready = c.wait_ready(actor,att) + check(ready['error_code'] is None, 'ready has error') + check(c.call('GET','/api/v1/attachments/'+att['id']+'/content',actor=actor)['bytes']==original,'original changed') + variants = {v['name']:v for v in ready['variants']} + check(set(variants)=={'thumbnail','crop','optimized'},'incomplete variants') + check((variants['thumbnail']['width'],variants['thumbnail']['height'])==expected_thumb,'thumbnail geometry') + check((variants['crop']['width'],variants['crop']['height'])==(128,128),'crop geometry') + for name,v in variants.items(): + response = c.call('GET','/api/v1/attachments/'+att['id']+'/content?variant='+name,actor=actor) + body = response['bytes'] + check(len(body)==v['size_bytes'] and hashlib.sha256(body).hexdigest()==v['sha256'],'variant checksum') + check(response['headers'].get_content_type()==v['content_type'],'variant MIME') + if name=='optimized': + check(body[:4]==b'RIFF' and body[8:12]==b'WEBP','not WebP') + else: + check(jpeg_size(body)==(v['width'],v['height']),'JPEG actual geometry') + return ready + + +def replay(j, expected=True): + result = docker('exec',containers('worker')[0],'/usr/local/bin/worker','--replay',j['id'], + '--operator','synthetic-fault-test','--reason','restore synthetic fixture',check_result=False) + check((result.returncode==0)==expected,'unexpected replay result') + + +def main(): + check(STACK!='mtusi-lab4','refuse source stack') + c = Client(timeout=55) + alice,bob,eve,chat = c.bootstrap() + data = png() + # Inherited lab4 obligations remain public: input validation and access control. + negatives=[] + for name,body,mime,filename,status in ( + ('oversized',b'x'*(10485760+1),'image/png','large.png',413), + ('damaged',data[:45],'image/png','broken.png',415), + ('pixel_budget',oversized_dimensions(),'image/png','huge.png',413), + ('mime_spoof',data,'image/jpeg','fake.jpg',415), + ('filename',data,'image/png','../evil.png',400), + ('unsupported',data,'application/octet-stream','file.png',415)): + upload(c,alice,chat,body,filename,mime,status) + negatives.append({'name':name,'status':status}) + att = upload(c,alice,chat,data)['json'] + variant_check(c,bob,att,data) + c.message(alice,chat,'',attachments=[att['id']]) + c.call('GET','/api/v1/attachments/'+att['id'],404,actor=eve) + c.call('GET','/api/v1/attachments/'+att['id']+'/content',401) + upload(c,eve,chat,data,expected=404) + RESULT['cases']['input_and_acl'] = negatives + # Real small image, alpha and EXIF orientation exercise the actual renderer. + from PIL import Image + for name,im,exif,shape in ( + ('small.png',Image.new('RGBA',(12,8),(255,0,0,0)),None,(12,8)), + ('oriented.jpg',Image.new('RGB',(320,200),(40,120,200)),6,(160,256)), + ('oriented.png',Image.new('RGB',(320,200),(40,120,200)),6,(160,256))): + out=io.BytesIO();kwargs={} + if exif: + tags=Image.Exif();tags[274]=exif;kwargs['exif']=tags + is_jpeg=name.endswith('.jpg') + im.save(out,format='JPEG' if is_jpeg else 'PNG',**kwargs) + body=out.getvalue();item=upload(c,alice,chat,body,name,'image/jpeg' if is_jpeg else 'image/png')['json'] + variant_check(c,bob,item,body,shape) + if name=='small.png': + raw=c.call('GET','/api/v1/attachments/'+item['id']+'/content?variant=thumbnail',actor=bob)['bytes'] + pixel=Image.open(io.BytesIO(raw)).getpixel((0,0));check(min(pixel)>250,'alpha was not white') + RESULT['cases']['small_alpha_exif']='PASS' + print('PASS: input/ACL, three actual formats, geometry, EXIF, alpha',flush=True) + with Probe() as probe: + key=sql("SELECT object_key FROM attachments WHERE id='"+att['id']+"';") + anonymous=docker('exec',containers('minio')[0],'wget','-S','-O','/dev/null','http://127.0.0.1:9000/attachments/'+key,check_result=False) + check(b'403' in anonymous.stderr,'bucket public') + probe.mc('pipe','local/attachments/outside-prefix',data=b'x',expected=1) + RESULT['cases']['private_s3']={'anonymous_get':403,'outside_prefix_denied':True} + + # A stage PUT without metadata COMMIT must never produce a 202 or a job. + until(lambda:sql("SELECT count(*) FROM attachments WHERE status='ready' AND staging_key IS NOT NULL;")=='0',timeout=45) + def stage_keys(): + lines=probe.mc('ls','--recursive','--json','local/attachments/staging/').stdout.decode().splitlines() + return {json.loads(line)['key'] for line in lines if json.loads(line).get('type')=='file'} + old=stage_keys() + filename='db-fault-'+uuid.uuid4().hex+'.png' + sql("CREATE FUNCTION lab5_reject_metadata() RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN IF NEW.filename='"+filename+"' THEN RAISE EXCEPTION 'synthetic metadata failure'; END IF; RETURN NEW; END; $$; CREATE TRIGGER lab5_reject_metadata BEFORE INSERT ON attachments FOR EACH ROW EXECUTE FUNCTION lab5_reject_metadata();") + try: + upload(c,alice,chat,data,filename=filename,expected=503) + finally: + sql('DROP TRIGGER lab5_reject_metadata ON attachments; DROP FUNCTION lab5_reject_metadata();') + unconfirmed=stage_keys()-old + check(len(unconfirmed)==1,'expected one unconfirmed stage') + check(sql("SELECT count(*) FROM attachments WHERE filename='"+filename+"';")=='0','failed upload published metadata') + orphan=next(iter(unconfirmed)) + time.sleep(6) + check(orphan in stage_keys(),'fresh unconfirmed stage deleted before grace') + RESULT['cases']['stage_before_commit']={'upload_status':503,'metadata':0,'fresh_orphan_preserved':True} + + if '--tail-only' not in sys.argv: + # COMMIT without publish, then API and broker restart with worker absent. + control('worker',replicas=0) + control('api',{'PIPELINE_PAUSE_PUBLISH':'1'}) + item=upload(c,alice,chat,data)['json'] + c.message(alice,chat,'',attachments=[item['id']]) + c.call('GET','/api/v1/attachments/'+item['id']+'/content',409,actor=bob) + j=job(item) + check(sql("SELECT published_at IS NULL FROM attachment_outbox WHERE job_id='"+j['id']+"';")=='t','publish not paused') + control('api',force=True) + control('redis',force=True) + settled('api',2) + control('api',{'PIPELINE_PAUSE_PUBLISH':None}) + until(lambda:sql("SELECT published_at IS NOT NULL FROM attachment_outbox WHERE job_id='"+j['id']+"';")=='t') + before=redis('XRANGE',STREAM,'-','+') + check(any(json.loads(row[1][1])['job_id']==j['id'] for row in before),'job not in stream') + control('redis',force=True) + settled('api',2) + check(any(json.loads(row[1][1])['job_id']==j['id'] for row in redis('XRANGE',STREAM,'-','+')),'broker lost durable job') + control('worker',replicas=1) + variant_check(c,bob,item,data) + RESULT['cases']['commit_publish_and_restarts']={'job_id':j['id'],'api_restart':True,'broker_restarts':2,'link_queued':True} + save();print('PASS: COMMIT/publish gap, queued link, API/broker restarts, worker recovery',flush=True) + + # A killed worker leaves deterministic objects before metadata COMMIT/ack. + control('worker',{'WORKER_TIMEOUT_SECONDS':'5','WORKER_LEASE_SECONDS':'12','PIPELINE_FAILPOINT':'after_objects'}) + item=upload(c,alice,chat,data)['json'] + until(lambda:job(item)['state']=='processing') + until(lambda:probe.mc('stat','local/attachments/original/'+item['id']+'/v1/optimized').returncode==0) + control('worker',{'PIPELINE_FAILPOINT':None}) + variant_check(c,bob,item,data) + j=job(item);check(j['attempts']>=2,'expired processing was not retried') + objects=probe.mc('ls','--recursive','--json','local/attachments/original/'+item['id']+'/').stdout.decode().splitlines() + check(sum(json.loads(x).get('type')=='file' for x in objects)==4,'duplicate objects created') + RESULT['cases']['crash_after_objects']={'attempts':j['attempts'],'objects':4,'fence':j['fence']} + save();print('PASS: crash after objects, expired lease/fencing, same four keys',flush=True) + + # Ready COMMIT before ack: redelivery must leave metadata unchanged. + control('worker',{'PIPELINE_FAILPOINT':'after_commit'}) + item=upload(c,alice,chat,data)['json'];wait_state(item,'ready') + snapshot=c.call('GET','/api/v1/attachments/'+item['id'],actor=bob,schema='Attachment')['json'] + check(redis('XPENDING',STREAM,GROUP)[0]>0,'ack happened before crash') + control('worker',{'PIPELINE_FAILPOINT':None}) + until(lambda:redis('XPENDING',STREAM,GROUP)[0]==0,timeout=30) + check(c.call('GET','/api/v1/attachments/'+item['id'],actor=bob,schema='Attachment')['json']==snapshot,'ready replay changed metadata') + j=job(item) + envelope={'schema_version':1,'job_id':j['id'],'type':'attachment.process.v1','attachment_id':item['id'],'pipeline_version':1,'attempt':1,'created_at':j['created_at']} + redis('XADD',STREAM,'*','job',json.dumps(envelope)) + until(lambda:redis('XLEN',STREAM)==0,timeout=30) + check(c.call('GET','/api/v1/attachments/'+item['id'],actor=bob,schema='Attachment')['json']==snapshot,'duplicate changed ready') + replay(j,False) + RESULT['cases']['commit_before_ack_and_duplicate']={'ready_unchanged':True,'ready_replay_rejected':True} + save();print('PASS: COMMIT before ack, duplicate no-op and ready replay rejection',flush=True) + + # Temporary storage error, bounded attempts/backoff, failed registry and audit replay. + control('api',{'WORKER_MAX_ATTEMPTS':'2'}) + control('worker',{'PIPELINE_FAILPOINT':'transient'}) + item=upload(c,alice,chat,data)['json'] + retry=until(lambda:job(item),lambda j:j['state']=='queued' and j['attempts']==1) + delay=(dt.datetime.fromisoformat(retry['available_at'].replace('Z','+00:00'))-dt.datetime.fromisoformat(retry['updated_at'].replace('Z','+00:00'))).total_seconds() + check(1.5<=delay<=2.6,'retry backoff/jitter outside configured range') + failed=wait_state(item,'failed',timeout=30) + check(failed['attempts']==2,'retry limit') + meta=c.call('GET','/api/v1/attachments/'+item['id'],actor=bob,schema='Attachment')['json'] + check(meta['error_code']=='retry_exhausted','unsafe final code') + c.call('GET','/api/v1/attachments/'+item['id']+'/content',409,actor=bob) + c.call('POST','/api/v1/chats/'+chat['id']+'/messages',409,actor=alice,body={'text':'','attachment_ids':[item['id']]},headers={'Idempotency-Key':uuid.uuid4().hex}) + registry=json.loads(docker('exec',containers('worker')[0],'/usr/local/bin/worker','--failed').stdout) + check(any(row['job_id']==failed['id'] for row in registry),'failed registry missing') + control('worker',{'PIPELINE_FAILPOINT':None}) + replay(failed) + variant_check(c,bob,item,data) + check(sql("SELECT count(*) FROM attachment_replays WHERE job_id='"+failed['id']+"';")=='1','replay audit missing') + RESULT['cases']['bounded_retry_replay']={'max_attempts':2,'retry_available_at':retry['available_at'],'first_backoff_seconds':round(delay,3),'failed_attempts':failed['attempts'],'audits':1} + save();print('PASS: bounded retry/backoff, failed registry, safe audited replay',flush=True) + + # A permanently corrupted durable stage is not retried endlessly. + control('worker',replicas=0) + item=upload(c,alice,chat,data)['json'] + probe.mc('pipe','local/attachments/staging/'+item['id'],data=b'damaged synthetic stage') + control('worker',replicas=1) + failed=wait_state(item,'failed') + check(failed['attempts']==1,'permanent error retried') + check(c.call('GET','/api/v1/attachments/'+item['id'],actor=bob,schema='Attachment')['json']['error_code']=='invalid_image','permanent classification') + RESULT['cases']['permanent_stage_error']={'attempts':1,'error_code':'invalid_image'} + permanent_att=item + permanent_job=failed + + # Deadline kills the renderer AND its real cwebp child blocked on a FIFO. + control('api',{'WORKER_MAX_ATTEMPTS':'1'}) + control('worker',{'WORKER_TIMEOUT_SECONDS':'2','WORKER_LEASE_SECONDS':'7','PIPELINE_FAILPOINT':'renderer_timeout'}) + item=upload(c,alice,chat,data)['json'];started=time.monotonic() + seen=until(lambda:docker('exec',containers('worker')[0],'ps','-o','pid,args').stdout.decode(),lambda text:'cwebp -quiet' in text,timeout=10) + wait_state(item,'failed',timeout=15) + elapsed=time.monotonic()-started + processes=docker('exec',containers('worker')[0],'ps','-o','pid,args').stdout.decode() + check('cwebp -quiet' not in processes and '/worker render' not in processes,'renderer descendant survived timeout') + RESULT['cases']['renderer_process_group_timeout']={'deadline_seconds':2,'elapsed_seconds':round(elapsed,3),'cwebp_observed':True,'descendants_after_failure':0} + control('worker',{'PIPELINE_FAILPOINT':None,'WORKER_TIMEOUT_SECONDS':'25','WORKER_LEASE_SECONDS':'40'}) + control('api',{'WORKER_MAX_ATTEMPTS':None}) + # Every ready stage is eventually collected; linked final objects remain. + until(lambda:sql("SELECT count(*) FROM attachments WHERE status='ready' AND staging_key IS NOT NULL;")=='0',timeout=45) + check(c.call('GET','/api/v1/attachments/'+att['id']+'/content',actor=bob)['bytes']==data,'cleanup removed ready original') + sql("UPDATE attachments SET created_at=created_at-interval '8 days',updated_at=clock_timestamp()-interval '8 days' WHERE id='"+permanent_att['id']+"';") + until(lambda:sql("SELECT storage_cleaned_at IS NOT NULL AND staging_key IS NULL FROM attachments WHERE id='"+permanent_att['id']+"';")=='t',timeout=45) + replay(permanent_job,False) + until(lambda:orphan not in stage_keys(),timeout=100) + RESULT['cases']['staging_cleanup']={'ready_stages_remaining':0,'linked_original_preserved':True,'failed_retention_days':7,'expired_failed_stage_removed':True,'expired_replay_rejected':True,'unconfirmed_orphan_removed':True} + required={'input_and_acl','small_alpha_exif','private_s3','stage_before_commit','commit_publish_and_restarts','crash_after_objects','commit_before_ack_and_duplicate','bounded_retry_replay','permanent_stage_error','renderer_process_group_timeout','staging_cleanup'} + check(required.issubset(RESULT['cases']),'incomplete fault evidence') + RESULT['finished_at']=time.time();save() + print('PASS: all lab5 fault, retry, replay, durability, rendering and cleanup checks',flush=True) + + +if __name__=='__main__': + try: + main() + finally: + # Restore ordinary service configuration even if an assertion fails. + try: + control('worker',{'PIPELINE_FAILPOINT':None,'WORKER_TIMEOUT_SECONDS':'25','WORKER_LEASE_SECONDS':'40'},replicas=1) + control('api',{'WORKER_MAX_ATTEMPTS':None,'PIPELINE_PAUSE_PUBLISH':None}) + finally: + save() diff --git a/tests/own/reconcile.py b/tests/own/reconcile.py new file mode 100644 index 00000000..1cfe0833 --- /dev/null +++ b/tests/own/reconcile.py @@ -0,0 +1,137 @@ +#!/usr/bin/env python3 +"""Track2: actual DB/S3 failures, grace, locking, repeat repairs and scan cost.""" +import json +import subprocess +import time +import uuid + +from helpers import Client, Probe, ROOT, STACK, check, containers, docker, png, reconcile, save, sql, upload, wait_ready + + +def objects(probe): + raw = probe.mc('ls','--recursive','--json','local/attachments',admin=True).stdout.decode() + return {json.loads(line)['key'] for line in raw.splitlines() if json.loads(line).get('type')=='file'} + + +def main(): + c = Client(timeout=55) + alice,bob,_,chat = c.bootstrap() + data = png() + experiment = uuid.uuid4().hex + result = {'hypothesis':'fixed grace plus per-object transaction lock permits repeatable repair without deleting fresh or linked data', + 'grace_seconds':90, 'faults':{}, 'cost':[]} + with Probe() as probe: + # Inject a failure exactly between successful S3 PUT and PostgreSQL INSERT. + before = objects(probe) + filename = 'db-fault-'+experiment+'.png' + sql("CREATE FUNCTION lab4_inject_failure() RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN IF NEW.filename='"+filename+"' THEN RAISE EXCEPTION 'lab4 injected DB failure'; END IF; RETURN NEW; END; $$; CREATE TRIGGER lab4_inject_failure BEFORE INSERT ON attachments FOR EACH ROW EXECUTE FUNCTION lab4_inject_failure();") + try: + upload(c,alice,chat,data,filename=filename,expected=503) + finally: + sql('DROP TRIGGER lab4_inject_failure ON attachments; DROP FUNCTION lab4_inject_failure();') + orphans = objects(probe)-before + check(len(orphans)==1,'DB failure did not leave the expected one unconfirmed S3 object') + orphan = next(iter(orphans)) + check(sql("SELECT count(*) FROM attachments WHERE filename='"+filename+"';")=='0','failed metadata INSERT published a row') + born = time.monotonic() + result['faults']['s3_put_db_insert_failure'] = {'upload_status':503, 'objects_without_metadata':1} + fresh = reconcile(apply=True) + check(orphan in objects(probe),'fresh orphan removed before grace') + result['fresh_orphan_preserved'] = fresh['fresh_skipped']>0 + + # Keep one old linked object and remove a second original behind PostgreSQL. + live = upload(c,alice,chat,data)['json'] + c.message(alice,chat,'keep live original',attachments=[live['id']]) + missing = upload(c,alice,chat,data)['json'] + message = c.message(alice,chat,'keep missing reference',attachments=[missing['id']])['json'] + missing_key = sql("SELECT object_key FROM attachments WHERE id='"+missing['id']+"';") + probe.mc('rm','local/attachments/'+missing_key,admin=True) + current = reconcile(apply=True) + check(sql("SELECT status FROM attachments WHERE id='"+missing['id']+"';")=='ready','fresh metadata changed before grace') + result['fresh_metadata_preserved'] = current['fresh_skipped']>0 + + # Measure a real scan at two bucket sizes, crossing an S3 page boundary. + cost_prefix = 'original/cost-'+experiment+'/' + try: + for group,count,total in (('small',100,100),('extra',1000,1100)): + script = ('mkdir -p /tmp/cost/"$1"; i=1; while [ "$i" -le "$2" ]; do ' + 'printf x > /tmp/cost/"$1"/"$i"; i=$((i+1)); done') + docker('exec',probe.container,'/bin/sh','-c',script,'sh',group,str(count)) + probe.mc('mirror','--quiet','/tmp/cost/'+group,'local/attachments/'+cost_prefix+group,admin=True) + summary = reconcile() + check(summary['objects_scanned']>=total,'scan skipped S3 objects') + result['cost'].append({'phase':'fresh', 'synthetic_objects':total, **summary}) + print('Fresh scan cost:',json.dumps({k:summary[k] for k in ('objects_scanned','metadata_scanned','list_requests_estimate','stat_requests','db_queries','duration_ms')}),flush=True) + print('Waiting92s for actual S3 timestamps: measuring aged-object locking, DB and HEAD cost next.',flush=True) + time.sleep(92) + for total in (1100,100): + summary = reconcile() + check(summary['orphans']>=total,'aged scan did not inspect all orphan fixtures') + result['cost'].append({'phase':'aged', 'synthetic_objects':total, **summary}) + print('Aged scan cost:',json.dumps({k:summary[k] for k in ('objects_scanned','metadata_scanned','list_requests_estimate','stat_requests','db_queries','duration_ms')}),flush=True) + if total==1100: + probe.mc('rm','--recursive','--force','local/attachments/'+cost_prefix+'extra/',admin=True) + finally: + probe.mc('rm','--recursive','--force','local/attachments/'+cost_prefix,admin=True) + + # S3/DB unavailability must stop reconciliation without destructive guesses. + for service in ('minio','postgres'): + try: + docker('service','scale','--detach',STACK+'_'+service+'=0') + deadline=time.monotonic()+30 + while time.monotonic()0: + print('Waiting for actual S3 object age to exceed90s grace:',round(remaining,1),'seconds',flush=True) + time.sleep(remaining) + sql("UPDATE attachments SET created_at=clock_timestamp()-interval '10 minutes' WHERE id IN ('"+live['id']+"','"+missing['id']+"');") + + # A second process holds the upload lock: even an old orphan is protected. + lock_script = "BEGIN; SELECT pg_advisory_xact_lock(hashtextextended('"+orphan+"',0));\n" + lock = subprocess.Popen(['docker','exec','-i',containers('postgres')[0],'psql','-U','messenger','-d','messenger','-At','-v','ON_ERROR_STOP=1'],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE) + lock.stdin.write(lock_script.encode()); lock.stdin.flush() + try: + deadline = time.monotonic()+10 + while sql("SELECT pg_try_advisory_xact_lock(hashtextextended('"+orphan+"',0));") != 'f': + check(time.monotonic()=1 and orphan in objects(probe),'upload lock did not protect orphan') + finally: + lock.stdin.write(b'ROLLBACK;\n'); lock.stdin.close() + lock.wait(timeout=15) + result['locked_candidate_preserved'] = True + # The apply above may mark the aged missing row; restore only its internal state + # to compare the following dry-run with an unchanged, well-defined fixture. + sql("UPDATE attachments SET status='ready',error_code=NULL WHERE id='"+missing['id']+"';") + dry = reconcile() + check(dry['orphans']>=1 and dry['missing']>=1,'dry-run did not detect injected inconsistencies') + check(orphan in objects(probe),'dry-run deleted an object') + check(sql("SELECT status FROM attachments WHERE id='"+missing['id']+"';")=='ready','dry-run modified metadata') + applied = reconcile(apply=True) + check(orphan not in objects(probe),'apply did not delete old orphan') + check(sql("SELECT status FROM attachments WHERE id='"+missing['id']+"';")=='failed','missing original not marked failed') + check(sql("SELECT count(*) FROM messages WHERE id='"+message['id']+"' AND '"+missing['id']+"'::uuid=ANY(attachment_ids);")=='1','repair deleted linked metadata or reference') + c.call('GET','/api/v1/attachments/'+missing['id'],409,actor=alice) + check(c.call('GET','/api/v1/attachments/'+live['id']+'/content',actor=bob)['bytes']==data,'repair deleted a live linked original') + repeated = reconcile(apply=True) + check(repeated['deleted']==0 and repeated['marked_failed']==0,'repeat apply was not idempotent') + result.update({'dry_run':dry, 'apply':applied, 'repeat_apply':repeated, + 'live_linked_preserved':True, 'missing_linked_reference_preserved':True}) + save('lab4-reconciliation.json',result) + print('PASS: real two-store faults, grace, lock, dry-run/apply/repeat, linked data preserved and paginated scan cost.') + + +if __name__=='__main__': + main() diff --git a/tests/own/swarm_grade4.py b/tests/own/swarm_grade4.py new file mode 100644 index 00000000..5b9c5bd7 --- /dev/null +++ b/tests/own/swarm_grade4.py @@ -0,0 +1,165 @@ +#!/usr/bin/env python3 +"""Grade-4 acceptance through the public LB; writes only synthetic test data.""" +from concurrent.futures import ThreadPoolExecutor +import json +import os +from pathlib import Path +import subprocess +import sys +import threading +import time +import uuid + +ROOT = Path(__file__).resolve().parents[2] +sys.path.insert(0, str(ROOT/'tests')) +from client import Client, Failure, check, run +from resilience import history + +STACK = os.environ.get('STACK_NAME', 'mtusi-lab5') + + +def docker_json(*args): + return json.loads(subprocess.check_output(['docker', *args], text=True)) + + +def task_ids(): + ids = subprocess.check_output(['docker','service','ps','--filter','desired-state=running','-q',STACK+'_api'], text=True).split() + return {i for i in ids if docker_json('inspect',i)[0]['Status']['State']=='running'} + + +def wait_ready(): + subprocess.run([sys.executable, str(ROOT/'scripts/swarm.py'), 'wait'], check=True, stdout=subprocess.DEVNULL) + time.sleep(3) # DNS and HAProxy rise interval + + +def idempotency(c, alice, bob, eve, chat): + key = uuid.uuid4().hex + barrier = threading.Barrier(16) + def send(_): + local = Client(timeout=5) + barrier.wait() + return local.message(alice, chat, 'one concurrent effect', key=key) + with ThreadPoolExecutor(max_workers=16) as pool: + results = list(pool.map(send, range(16))) + expected = results[0]['json'] + check(all(r['json']==expected and r['status']==201 for r in results), 'concurrent replay changed result') + instances = {r['headers']['X-Instance-Id'] for r in results} + check(len(instances)>=2, 'same-key race did not reach two replicas') + path = '/api/v1/chats/'+chat['id']+'/messages' + c.call('POST', path, 409, actor=alice, body={'text':'changed'}, headers={'Idempotency-Key':key}) + c.call('POST', path, 404, actor=eve, body={'text':expected['text']}, headers={'Idempotency-Key':key}) + other = c.message(bob, chat, expected['text'], key=key)['json'] + check(other['id']!=expected['id'], 'key leaked across users') + second_chat = c.call('POST','/api/v1/chats',201,actor=alice,body={'title':'Key scope','member_ids':[alice['id'],bob['id']]},schema='Chat')['json'] + separate = c.message(alice,second_chat,expected['text'],key=key)['json'] + check(separate['id']!=expected['id'], 'key leaked across chats') + for bad in ['', 'x'*129, 'bad key', 'bad,key', 'bad/key']: + c.call('POST', path, 400, actor=alice, body={'text':'invalid key'}, headers={'Idempotency-Key':bad}) + c.message(alice,chat,'128 ASCII characters',key='x'*128) + retry = uuid.uuid4().hex + c.call('POST',path,400,actor=alice,body={'text':''},headers={'Idempotency-Key':retry}) + c.message(alice,chat,'valid after invalid',key=retry) + check(sum(m['id']==expected['id'] for m in history(c,bob,chat))==1, 'race created duplicate') + # Revocation must be rechecked even for an already committed key. + c.call('DELETE','/api/v1/auth/sessions/current',204,actor=alice) + c.call('POST',path,401,actor=alice,body={'text':expected['text']},headers={'Idempotency-Key':key}) + print('PASS: shared-key race on two replicas; replay/conflict/scope/validation/access/logout', flush=True) + return {'parallel_requests':16, 'instances':sorted(instances), 'unique_message_ids':1} + + +def exercise(action, target=None): + c = Client(timeout=2) + alice,bob,eve,chat = c.bootstrap() + original_key = uuid.uuid4().hex + original = c.message(alice,chat,'confirmed before '+action,key=original_key)['json'] + before = task_ids() + stop = threading.Event() + events = [] + confirmations = [] + lock = threading.Lock() + def worker(number): + local = Client(timeout=2) + key = uuid.uuid4().hex + body = 'load-'+key + while not stop.is_set(): + started = time.monotonic() + try: + result = local.message(alice,chat,body,key=key) + with lock: + confirmations.append(result['json']) + local.call('GET','/api/v1/users/me',actor=bob,schema='User') + event = (started,time.monotonic(),result['json'],result['headers']['X-Instance-Id'],None) + key = uuid.uuid4().hex + body = 'load-'+key + except Failure as exc: + event = (started,time.monotonic(),None,None,str(exc)) + with lock: + events.append(event) + time.sleep(.03) + threads = [threading.Thread(target=worker,args=(i,)) for i in range(4)] + for thread in threads: thread.start() + time.sleep(2) + env = dict(os.environ) + if target: env['TARGET_INSTANCE_ID'] = target + started = time.monotonic() + proc = subprocess.Popen([sys.executable,str(ROOT/'scripts/swarm.py'),action],env=env,stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL) + try: + code = proc.wait(timeout=180) + check(code==0, action+' command failed') + completed = time.monotonic() + time.sleep(15 if target else 5) + finally: + stop.set() + for thread in threads: thread.join(timeout=10) + if proc.poll() is None: + proc.kill(); proc.wait() + ended = time.monotonic() + wait_ready() + window = [e for e in events if e[0]>=started] + successes = [e for e in window if e[2] is not None] + failures = [e for e in window if e[2] is None] + check(bool(successes), 'no writes during '+action) + recovery = min(e[1] for e in successes if e[0]>=completed)-started if target else None + if target: + check(recovery<=10, 'failure recovery exceeded 10 seconds') + check(target not in [e[3] for e in successes[-20:]], 'stopped instance returned') + check(target not in task_ids(), 'old task still running') + else: + check(before.isdisjoint(task_ids()), 'rolling update did not replace every replica') + replay = c.message(alice,chat,original['text'],key=original_key)['json'] + check(replay==original, 'committed idempotency result lost after '+action) + all_messages = history(c,bob,chat) + by_id = {m['id']:m for m in all_messages} + check(by_id.get(original['id'])==original, 'pre-action confirmation lost') + check(all(by_id.get(m['id'])==m for m in confirmations), 'confirmation lost/changed') + texts = [m['text'] for m in all_messages] + check(len(texts)==len(set(texts)), 'uncertain retry created duplicate') + times = [started]+sorted(e[1] for e in successes)+[ended] + max_gap = max(b-a for a,b in zip(times,times[1:])) + check(max_gap<=10, 'writes stalled for more than 10 seconds') + report = {'action':action,'target':target,'duration_seconds':round(ended-started,3), + 'successful_writes':len(successes),'failed_attempts':len(failures), + 'successful_rps':round(len(successes)/(ended-started),3), + 'first_recovery_seconds':round(recovery,3) if recovery is not None else None, + 'max_success_gap_seconds':round(max_gap,3), + 'instances_before':sorted(before),'instances_after':sorted(task_ids()), + 'confirmed_messages_checked':len(confirmations)+1, + 'duplicate_bodies':0} + print(json.dumps(report),flush=True) + return report + + +def main(): + wait_ready() + c = Client() + results = {'idempotency':idempotency(c,*c.bootstrap())} + originals = sorted(task_ids()) + check(len(originals)==2,'grade4 scenario expects exactly two API replicas') + results['failovers'] = [exercise('stop-one',target) for target in originals] + results['rolling_update'] = exercise('update') + (ROOT/'evidence/swarm-grade4.json').write_text(json.dumps(results,indent=2)+'\n') + print('PASS: each original replica stopped and replaced; rolling update under load; confirmations and sessions preserved') + + +if __name__=='__main__': + run(main)