Лаб 6 Хакимов Дмитрий БВТ2301 на 5 #43
+19
-1
@@ -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
|
||||
|
||||
@@ -1,18 +1,37 @@
|
||||
## Лабораторная 6
|
||||
## Лабораторная 6: OpenTelemetry и Grafana
|
||||
|
||||
Автор / группа: TODO
|
||||
Целевая оценка (3/4/5): TODO
|
||||
Трек 5, если заявлен: TODO
|
||||
Автор / группа: Хакимов Дмитрий БВТ2301
|
||||
Целевая оценка: **5**. Трек 1: **цена наблюдаемости**.
|
||||
|
||||
Что реализовано и что перенесено: TODO
|
||||
Команды запуска из чистого clone: TODO
|
||||
Результаты проверок и ссылка на REPORT.md: TODO
|
||||
Ограничения / известные ошибки: TODO
|
||||
Источники и использование ИИ: TODO
|
||||
Из lab5 перенесены API, PostgreSQL, Redis Streams, S3 и worker с durable outbox/retry.
|
||||
Добавлены SDK traces/metrics/logs, Collector, Prometheus, Loki, Tempo и Grafana.
|
||||
W3C context сохраняется вместе с job; API, publish, consume, S3/DB и retry видны в одной трассе.
|
||||
Dashboard, datasources и два alerts provisioned из Git. Назначение компонентов и сигналы описаны в REPORT.md.
|
||||
|
||||
- [ ] Весь обязательный минимум текущей и предыдущих работ сохранён с объявленными переходами.
|
||||
- [ ] Контракт и публичные тесты не ослаблены.
|
||||
- [ ] make check и make test выполнены; приложен реальный вывод.
|
||||
- [ ] Сценарии отказов/безопасности своего уровня воспроизведены.
|
||||
- [ ] Все секреты и приватные ключи находятся вне Git; отчёт не содержит tokens.
|
||||
- [ ] README задания сохранён, REPORT.md содержит инструкцию именно моего решения.
|
||||
Запуск из чистого clone: `make up`, `make wait`, `make test`.
|
||||
API: http://localhost:18086. Grafana: http://localhost:13000/d/messenger/messenger-observability.
|
||||
Подробные prerequisites, bootstrap, остановка и удаление учебных данных: [REPORT.md](../REPORT.md).
|
||||
|
||||
Проверки: OpenAPI/contract, Go tests с race detector, public smoke, persistence и API failover прошли.
|
||||
Полный fault suite подтвердил worker backlog, retry при отказе S3, DB timeout и работу API без Tempo.
|
||||
Отдельный backend outage: 35/35 записей успешны, потеряны 3 request traces, queue27/256→0, OOM нет.
|
||||
|
||||
Исследование: 8 опытов,960 запросов,48 изображений ready,0 неожиданных ошибок.
|
||||
Sampling50% уменьшил trace ingest на48,10%; сохранены125/240 request traces.
|
||||
Методика, latency/CPU/RAM/ingest и ограничения: [RESEARCH.md](../RESEARCH.md).
|
||||
Runbook: [RUNBOOK.md](../RUNBOOK.md); разбор отказов: [INCIDENTS.md](../INCIDENTS.md).
|
||||
Все доказательства находятся в evidence/; результаты прежней lab5 не выдаются за результаты lab6.
|
||||
|
||||
Ограничения: один host, head sampling теряет часть ошибок и медленных запросов,
|
||||
короткая нагрузка не доказывает улучшение latency или предельный throughput.
|
||||
Начальный OOM Tempo исправлен увеличением cgroup и ограничением Go heap; неуспешные журналы сохранены.
|
||||
Основа реализации — проект lab5; источники SDK и документации указаны в REPORT.md.
|
||||
|
||||
- [x] Обязательный минимум lab5 и lab6 сохранён.
|
||||
- [x] Контракт и публичные tests не ослаблены.
|
||||
- [x] make check, validate и make test выполнены; реальный вывод приложен.
|
||||
- [x] Сценарии отказов и исследование воспроизведены.
|
||||
- [x] Credentials находятся вне Git; evidence не содержит session tokens или тел сообщений.
|
||||
- [x] README задания сохранён, REPORT.md описывает это решение.
|
||||
|
||||
🤖 Generated with [O3 Agent Codex](https://o3-agent.o3t.ru)
|
||||
|
||||
+67
@@ -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=1 GOMEMLIMIT=192MiB
|
||||
|
||||
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"]
|
||||
@@ -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"]
|
||||
@@ -0,0 +1,67 @@
|
||||
# Разбор контролируемых инцидентов
|
||||
|
||||
Команда: `python3 scripts/observability_faults.py`.
|
||||
Успешный полный прогон: evidence/lab6-faults-run.txt, итог PASS в evidence/lab6-faults.json.
|
||||
Агрегаты: evidence/lab6-incidents-summary.json. История метрик: evidence/lab6-incident-metrics.json.
|
||||
Времена в JSON записаны в UTC. Все данные синтетические.
|
||||
|
||||
## Очередь растёт, HTTP-приём работает
|
||||
|
||||
Наблюдения:6 загрузок получили 202, возраст незавершённых заданий растёт,
|
||||
QueueLagGrowing впервые наблюдался firing через 20,18s. Максимальный возраст в серии до восстановления —26,18s.
|
||||
Worker capacity/busy перестают обновляться. Логи publish уже есть, consumer completion ещё нет.
|
||||
Это указывает на отсутствие обработки после приёма, а не на отказ HTTP-handler или потерю принятой job.
|
||||
|
||||
После запуска worker временно недоступен S3. Ошибочные S3 GET spans и outcomes storage_unavailable
|
||||
отделяют этот второй этап от остановки worker. Контекст исходной загрузки сохраняется при retry.
|
||||
В trace `3c112fa1787d40898e457423046b2e97` видны 4 producer и 4 consumer spans,
|
||||
ошибки S3, затем успешные PUT, UPDATE/COMMIT результата.
|
||||
Сохранены 80 реальных spans и 9 потоков связанных логов.
|
||||
Все 6 заданий стали ready, depth вернулся к 0, QueueLagGrowing снялся.
|
||||
Подтверждённые загрузки не потеряны.202 само по себе этого не доказывало: проверялось конечное ready.
|
||||
|
||||
Файлы: [trace](evidence/trace-3c112fa1787d40898e457423046b2e97.json),
|
||||
[logs](evidence/logs-3c112fa1787d40898e457423046b2e97.json).
|
||||
|
||||
## API отвечает 503 из-за ожидания БД
|
||||
|
||||
Наблюдения:28 запросов получили 503; длительность каждого около 2s, максимум 2,051s.
|
||||
APIHighErrorRate перешёл в firing. В server trace находится ошибочный PostgreSQL SELECT span
|
||||
примерно той же длительности. HTTP span в этой трассе длится 2,008s.
|
||||
Задержка локализуется в обращении к PostgreSQL, а не в отдельной медленной обработке HTTP после БД.
|
||||
|
||||
Воздействие:45-секундная ACCESS EXCLUSIVE блокировка таблицы messages.
|
||||
API ограничивает ожидание запроса примерно 2s. Это объясняет 503 до окончания блокировки.
|
||||
После снятия блокировки новые записи получили 201. Alert очистился на 10-й проверке с шагом 5s
|
||||
после первой успешной записи; восстановление самого сервиса и очистка окна alert — разные моменты.
|
||||
История состояний firing/resolved сохранена в recovery_alerts; финальный список alerts пуст.
|
||||
|
||||
Файлы: [trace](evidence/trace-dbc9b2dc91404a1fa7fae889b013bb34.json),
|
||||
[logs](evidence/logs-dbc9b2dc91404a1fa7fae889b013bb34.json).
|
||||
|
||||
## Недоступно хранилище telemetry
|
||||
|
||||
В основном fault suite Tempo остановлен, но 30 записей сообщений завершились успешно.
|
||||
Очередь Collector выросла и после восстановления опустела. Память остаётся ограниченной cgroup.
|
||||
Отдельный опыт `python3 scripts/observability_backend.py` измеряет реальные отсутствующие request traces
|
||||
после более длительного отказа; результаты находятся в evidence/lab6-backend-outage.json.
|
||||
Он отделяет отсутствие telemetry от потери подтверждённых бизнес-записей.
|
||||
|
||||
Отдельный опыт завершился PASS: 35 успешных записей, 32 найденные request traces и 3 отсутствующие.
|
||||
Максимум очереди — 27 из 256 batches; после восстановления — 0.
|
||||
Максимальный наблюдавшийся RSS Collector — 81666048 bytes при cgroup201326592 bytes, OOM отсутствует.
|
||||
Счётчик failed spans вырос на 312, refused spans — на 0.
|
||||
312 — значение счётчика экспорта, а не число уникальных потерянных request traces.
|
||||
Список 35 trace ID и результаты повторного поиска сохранены в JSON; ID сопоставлены с HTTP201 logs.
|
||||
|
||||
Первый прогон выявил OOM Tempo при лимите 256MiB. Это было настоящей ошибкой стенда:
|
||||
она мешала получить доказательства корреляции. Лимит увеличен до 512MiB, Go heap ограничен 320MiB.
|
||||
Повторный полный fault suite успешно получил обе трассы и соответствующие логи из backend.
|
||||
Неуспешные начальные журналы сохранены как evidence/lab6-faults-initial.* и *-recovery-initial.*.
|
||||
Они не считаются успешным итоговым прогоном.
|
||||
|
||||
## Повторение диагностики
|
||||
|
||||
Пользуйтесь [RUNBOOK.md](RUNBOOK.md): сначала alert/метрики, затем структурный лог и trace.
|
||||
Для вывода о причине достаточно сохранённых наблюдений. Команды внедрения отказа дают независимую проверку диагноза.
|
||||
Задержки в таблицах измерены с шагом 5s и включают задержки SDK/Collector/scrape/evaluation.
|
||||
@@ -1,5 +1,5 @@
|
||||
PYTHON ?= python3
|
||||
BASE_URL ?= http://localhost:8080
|
||||
BASE_URL ?= http://localhost:18086
|
||||
CA_FILE ?=
|
||||
ACTION_SCRIPT ?=
|
||||
TLS_ARGS = $(if $(CA_FILE),--ca-file "$(CA_FILE)",)
|
||||
@@ -28,3 +28,25 @@ test-persistence:
|
||||
test-failover:
|
||||
@test -n "$(ACTION_SCRIPT)" || (echo "Set ACTION_SCRIPT to your implemented executable stop-one hook"; exit 2)
|
||||
$(PYTHON) tests/resilience.py --mode failover --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||||
|
||||
.PHONY: bootstrap up down wait test-own test-observability research verify-observability test-backend
|
||||
bootstrap:
|
||||
./scripts/bootstrap.sh
|
||||
up: bootstrap
|
||||
COMPOSE_PARALLEL_LIMIT=1 ./scripts/compose.sh up -d --build
|
||||
$(MAKE) wait
|
||||
wait:
|
||||
$(PYTHON) scripts/wait_ready.py --base-url "$(BASE_URL)"
|
||||
down:
|
||||
./scripts/compose.sh down
|
||||
test-own:
|
||||
go test ./...
|
||||
test-observability:
|
||||
$(PYTHON) scripts/observability_faults.py
|
||||
research:
|
||||
$(PYTHON) scripts/observability_experiment.py
|
||||
$(PYTHON) scripts/summarize_observability.py
|
||||
verify-observability:
|
||||
$(PYTHON) scripts/verify_observability.py
|
||||
test-backend:
|
||||
$(PYTHON) scripts/observability_backend.py
|
||||
|
||||
@@ -1,37 +1,210 @@
|
||||
# Отчёт — лабораторная 6
|
||||
# Лабораторная 6: наблюдаемость мессенджера
|
||||
|
||||
- Автор, группа: TODO
|
||||
- Целевая оценка; выбранный трек 5, если нужен: TODO
|
||||
- Commit/PR: TODO после публикации
|
||||
- Использованные источники, библиотеки и помощь ИИ: TODO
|
||||
Целевая оценка — **5**, трек 1: **цена наблюдаемости**.
|
||||
Автор и группа заполняются студентом перед сдачей; commit/PR — после публикации.
|
||||
README задания, обязательный API и публичные проверки сохранены.
|
||||
|
||||
## Запуск из чистого clone
|
||||
|
||||
TODO: версии runtime/образов, prerequisites, команды создания локальных secrets/.env, build, миграций, запуска, ожидания готовности, тестов и остановки. Указать необходимые действия оператора. Не вставлять секреты. Отдельно указать безопасную остановку и команду намеренного удаления учебных данных.
|
||||
Требуются Docker Engine, Compose v2 либо `docker-compose`, Python 3.9+.
|
||||
Для локальных Go-тестов требуется Go не старее версии в `go.mod`.
|
||||
Соседняя папка lab5 после переноса не нужна.
|
||||
|
||||
## Архитектура и решения
|
||||
```sh
|
||||
make up
|
||||
make wait
|
||||
make check
|
||||
make test
|
||||
make test-own
|
||||
```
|
||||
|
||||
TODO: схема процессов/хранилищ, источник истины, транзакционные границы, ограничения. Что перенесено из lab5, что изменено в этой работе. Соответствие переменных из .env.example реальной конфигурации.
|
||||
Полная проверка OpenAPI требует отдельной Python-зависимости:
|
||||
|
||||
```sh
|
||||
python3 -m venv .venv
|
||||
.venv/bin/python -m pip install -r requirements-dev.txt
|
||||
make check validate PYTHON=.venv/bin/python
|
||||
```
|
||||
|
||||
Bootstrap создаёт случайные credentials в `secrets/`, goose применяет migrations,
|
||||
S3 bootstrap создаёт приватный bucket и ограниченного пользователя.
|
||||
Повторный запуск сохраняет существующие credentials и данные.
|
||||
Секреты передаются через `/run/secrets`; каталог исключён из Git и Docker context.
|
||||
`scripts/compose.sh` использует `--env-file /dev/null`: локальный файл окружения не требуется.
|
||||
|
||||
| Интерфейс | Адрес |
|
||||
| --- | --- |
|
||||
| API / Swagger | http://localhost:18086 / http://localhost:18086/swagger/ |
|
||||
| Grafana dashboard | http://localhost:13000/d/messenger/messenger-observability |
|
||||
| Prometheus alerts | http://localhost:19090/alerts |
|
||||
| Loki HTTP | http://localhost:13100 |
|
||||
| Tempo HTTP | http://localhost:13200 |
|
||||
|
||||
Порты опубликованы только на loopback. OTLP, DB, Redis и S3 доступны внутри сети Compose.
|
||||
Grafana разрешает локальный анонимный просмотр. Datasources/dashboard загружаются автоматически.
|
||||
Для отдельного импорта используйте `infra/grafana/dashboards/messenger.json`.
|
||||
|
||||
Безопасная остановка: `make down`; named volumes сохраняются.
|
||||
Намеренное удаление **всех учебных данных lab6**: `./scripts/compose.sh down -v`.
|
||||
Не удаляйте `secrets/` при сохранённых volumes: credentials перестанут соответствовать данным.
|
||||
|
||||
## Что перенесено и добавлено
|
||||
|
||||
Из lab5 перенесены `cmd/`, `dto/`, `internal/`, migrations 001–010, Dockerfile приложения/MinIO,
|
||||
конфигурации S3, Redis AOF, HAProxy и мигратора. Сохранены сессии, две API-реплики,
|
||||
идемпотентность сообщений, приватные вложения, durable Redis Streams, отдельный worker,
|
||||
transactional outbox, lease/fence и ограниченные retry.
|
||||
HTTP 202 означает устойчивый приём задания, обработка происходит в worker.
|
||||
|
||||
Добавлены SDK traces/metrics/logs, Collector, три хранилища и Grafana.
|
||||
Migration011 сохраняет W3C traceparent/tracestate в job вместе с durable acceptance.
|
||||
Publisher создаёт producer span и передаёт контекст через Redis Streams.
|
||||
Worker создаёт consumer span; retry продолжает исходную причинную связь.
|
||||
PostgreSQL spans содержат операцию, но не SQL, аргументы или строку подключения.
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
Client --> HAProxy --> API[API x2]
|
||||
API --> DB[(PostgreSQL)]
|
||||
API --> S3[(MinIO)]
|
||||
API --> Broker[(Redis Streams)]
|
||||
Broker --> Worker
|
||||
Worker --> DB
|
||||
Worker --> S3
|
||||
API -->|OTLP| Collector
|
||||
Worker -->|OTLP| Collector
|
||||
Collector --> Prometheus
|
||||
Collector --> Loki
|
||||
Collector --> Tempo
|
||||
Prometheus --> Grafana
|
||||
Loki --> Grafana
|
||||
Tempo --> Grafana
|
||||
```
|
||||
|
||||
PostgreSQL — источник истины бизнес-состояния. S3 хранит bytes изображений.
|
||||
Redis хранит сессии и очередь; AOF обеспечивает её устойчивость.
|
||||
Collector принимает/обрабатывает/пересылает сигналы, но не хранит историю долговременно.
|
||||
Prometheus хранит временные ряды, Loki — логи, Tempo — spans. Grafana запрашивает эти источники.
|
||||
|
||||
## Компоненты и хранение
|
||||
|
||||
| Service | Версия | Volume / готовность |
|
||||
| --- | --- | --- |
|
||||
| api x2, worker | Go из Dockerfile, `mtusi-messenger:lab6` | API `/health/live`, `/health/ready`; worker отдельно |
|
||||
| gateway | HAProxy 3.2.4-alpine | Без состояния; проверяет readiness обеих реплик |
|
||||
| postgres | 17.6-alpine3.22 | postgres_data; pg_isready |
|
||||
| redis | 7.4.5-alpine3.21 | redis_data; redis-cli ping |
|
||||
| minio | RELEASE.2025-09-07T16-13-09Z | s3_data; /minio/health/live |
|
||||
| s3_bootstrap | mc RELEASE.2025-08-13T08-35-41Z | Идемпотентный bootstrap; exit0 |
|
||||
| migrations | goose 3.27.1 | Журнал в PostgreSQL; exit0 |
|
||||
| collector | contrib 0.137.0 | Ограниченные очереди RAM; метрики :8888 |
|
||||
| prometheus | 3.6.0 | prometheus_data; /-/ready; retention7d/1GB |
|
||||
| loki | 3.5.5 | loki_data; /ready; retention7d |
|
||||
| tempo | 2.8.2 | tempo_data, WAL/blocks; /ready; retention7d |
|
||||
| grafana | 12.2.0 | grafana_data; /api/health; provisioning из Git |
|
||||
|
||||
Все компоненты находятся в отдельной сети проекта `mtusi2026lab6`.
|
||||
Лимиты CPU/RAM заданы в compose.yaml. Внешние хранилища или готовый сервер не используются.
|
||||
OTel Go traces/metrics 1.38.0, logs 0.14.0. Имена инструментов зафиксированы явно.
|
||||
Schema URL не заявляется: это собственные сигналы контракта, а не полная реализация semantic conventions.
|
||||
|
||||
## Сигналы и единицы
|
||||
|
||||
| Требование | Метрика | Единица / агрегация |
|
||||
| --- | --- | --- |
|
||||
| HTTP throughput/errors | messenger_http_requests_total | count; labels method/route/status_class |
|
||||
| HTTP latency | messenger_http_duration_seconds_bucket | seconds; histogram_quantile после sum buckets реплик |
|
||||
| Jobs outcomes | messenger_jobs_total | count; job_type/outcome |
|
||||
| Worker duration | messenger_job_duration_seconds_bucket | seconds на попытку |
|
||||
| End-to-end ready | messenger_attachment_ready_seconds_bucket | seconds от durable создания job, включая queue/retry |
|
||||
| Queue | messenger_queue_depth / messenger_queue_oldest_age_seconds | jobs/seconds; max повторных наблюдений общей очереди |
|
||||
| DB pool | messenger_db_pool_used / messenger_db_pool_waiting / messenger_db_pool_max | connections / acquisition calls / connections |
|
||||
| Worker saturation | messenger_worker_busy / messenger_worker_capacity | active jobs / concurrency; отношение busy/capacity |
|
||||
| Go runtime | messenger_process_memory_bytes / messenger_process_cpu_seconds_total | Sys bytes / cumulative CPU seconds |
|
||||
| Контейнеры | docker stats в research JSON | cgroup memory / CPU percent |
|
||||
|
||||
Histogram buckets: .005,.01,.025,.05,.1,.25,.5,1,2,5,10,30,60,120 секунд.
|
||||
p50/p95/p99 вычисляются из объединённых buckets, а не из средних или percentile каждой реплики.
|
||||
Resource attributes: service.name=messenger-api/messenger-worker, service.version=lab6,
|
||||
service.instance.id=hostname, deployment.environment.name=lab.
|
||||
Логи содержат timestamp/severity/service.name/event/trace_id/span_id.
|
||||
X-Request-Id связывает HTTP-ошибку с логом; X-Trace-Id позволяет открыть трассу.
|
||||
UUID, request ID, raw URL и filename отсутствуют в metric labels.
|
||||
Authorization, токены, тела сообщений и изображений не экспортируются.
|
||||
|
||||
## SLI/SLO и alerts
|
||||
|
||||
Учебный SLI API: `1 - sum(rate(messenger_http_requests_total{status_class="5xx"}[5m])) / sum(rate(messenger_http_requests_total[5m]))`.
|
||||
SLO: **не менее 99% бизнес-запросов без 5xx за скользящие 5 минут**, при наличии трафика.
|
||||
Health/Swagger исключены. Неверный пароль не считается серверным отказом;4xx остаются в знаменателе.
|
||||
SLI attachments: доля ready за 10 секунд по end-to-end histogram, дополнительно к возрасту незавершённой очереди.
|
||||
|
||||
APIHighErrorRate: доля 5xx >5% за 1m, for: 5s.
|
||||
QueueLagGrowing: oldest age>10s и depth>0, for: 5s.
|
||||
Пороги сокращены для учебного опыта; трек 2 с burn-rate alerts не заявляется.
|
||||
Правила: infra/prometheus/alerts.yaml; диагностика: [RUNBOOK.md](RUNBOOK.md).
|
||||
Внешняя доставка не требуется; проверяется локальное firing/resolved.
|
||||
|
||||
## Backpressure telemetry
|
||||
|
||||
SDK traces/logs: bounded queue512, batch128, export timeout2s; metrics экспортируется каждые 5s.
|
||||
Collector: memory limiter128MiB/spike32MiB, batch256/max512,
|
||||
exporter queue256, два consumers для каждого backend, retry максимум 20s, cgroup192MiB.
|
||||
Длительный отказ приводит к потерям telemetry. Бизнес-запросы не ожидают записи telemetry в backend.
|
||||
Очереди в памяти Collector теряются при аварийном завершении.
|
||||
|
||||
## Проверки, отказы и исследование
|
||||
|
||||
```sh
|
||||
make test-persistence ACTION_SCRIPT=scripts/restart.sh
|
||||
make test-failover ACTION_SCRIPT=scripts/stop-one.sh
|
||||
./scripts/compose.sh start api
|
||||
python3 scripts/observability_faults.py
|
||||
python3 scripts/observability_backend.py
|
||||
python3 scripts/observability_experiment.py
|
||||
python3 scripts/summarize_observability.py
|
||||
python3 scripts/verify_observability.py
|
||||
```
|
||||
|
||||
Сценарии запускайте последовательно; после failover восстановите две реплики.
|
||||
Fault suite останавливает worker, создаёт backlog, показывает firing/resolved,
|
||||
проверяет retry при недоступном S3, блокирует PostgreSQL и проверяет API при выключенном Tempo.
|
||||
Исторические результаты lab5 не используются как доказательства lab6.
|
||||
Команды и фактические результаты: evidence/lab6-validation.txt, evidence/lab6-smoke.txt,
|
||||
evidence/lab6-faults.json, evidence/lab6-research.json. Исследование: [RESEARCH.md](RESEARCH.md).
|
||||
|
||||
## Доказательства критериев
|
||||
|
||||
| Критерий README | Команда/сценарий | Наблюдаемый результат | Файл доказательства |
|
||||
| --- | --- | --- | --- |
|
||||
| Публичный smoke | make test | TODO | TODO |
|
||||
| Остальные пункты уровня 3 | TODO | TODO | TODO |
|
||||
| Все пункты уровня 4, если заявлен | TODO | TODO | TODO |
|
||||
| Выбранный трек 5, если заявлен | TODO | TODO | TODO |
|
||||
| Критерий README | Проверка / результат | Доказательство |
|
||||
| --- | --- | --- |
|
||||
| Минимум lab5, две API-реплики и отдельный worker | Публичный smoke PASS; PostgreSQL/Redis/MinIO и очередь работают | evidence/lab6-smoke.txt; compose.yaml |
|
||||
| Сохранность после restart | Данные, оригинал вложения и прежняя сессия сохранены | evidence/lab6-persistence.txt; evidence/lab6-container-events.txt |
|
||||
| Отказ API-реплики | 117 успешных записей, 4 неудачные попытки, восстановление за 3,382s; одна реплика остановлена и затем восстановлена | evidence/lab6-failover.txt; evidence/lab6-failover-containers.json |
|
||||
| Collector, три хранилища, Grafana и persistent history | Пять scrape targets UP; dashboard provisioned, 15 панелей, 18 запросов выполняются | evidence/lab6-provisioning.json; infra/ |
|
||||
| OTLP API/worker: counters, histograms, logs и traces | Обязательные сигналы найдены по реальным именам; сохранены server/producer/consumer spans и связанные логи | evidence/lab6-provisioning.json; evidence/trace-*.json; evidence/logs-*.json |
|
||||
| Низкая кардинальность и безопасная telemetry | Проверены labels реальных series; unit tests не допускают SQL/аргументы/тело/Authorization в spans | evidence/lab6-provisioning.json; evidence/lab6-validation.txt; internal/observability/telemetry_test.go |
|
||||
| W3C API → broker → worker → S3/DB, включая retry | В одной трассе upload видны 4 producer/consumer попытки и завершение | evidence/lab6-incidents-summary.json; INCIDENTS.md |
|
||||
| p50/p95/p99, queue lag, pool, saturation и CPU/RAM | Histogram queries объединяют buckets реплик; gauges и process/container ресурсы измерены | infra/grafana/dashboards/messenger.json; evidence/lab6-provisioning.json; evidence/lab6-research.json |
|
||||
| SLI/SLO и два alerts | Определены выше; оба alerts firing, затем resolved | infra/prometheus/alerts.yaml; evidence/lab6-faults.json |
|
||||
| Два инцидента и диагностика | Worker/S3 и DB lock локализованы по метрикам, логам и трассам | INCIDENTS.md; RUNBOOK.md; evidence/lab6-incident-metrics.json |
|
||||
| Ограниченное поведение при отказе backend | 35/35 записей успешны; queue максимум 27/256, затем 0; OOM нет; 3 request traces отсутствуют | evidence/lab6-backend-outage.json |
|
||||
| Законченный трек 1 на 5 | Off/100%/10%/50%, два повтора, 960 запросов, 48 изображений ready; latency, CPU/RAM, ingest и потери; 50% проверено | RESEARCH.md; evidence/lab6-research.json; evidence/lab6-research.csv |
|
||||
|
||||
TODO: добавить отдельную строку для каждого заявленного критерия. PASS без команды и наблюдения не является доказательством. Проверка инфраструктурного hook требует подтверждения, какие реальные процессы/хранилища перезапущены.
|
||||
Полный fault suite завершился PASS. В начале проверки Tempo получил OOM при лимите 256MiB.
|
||||
Лимит исправлен на 512MiB с GOMEMLIMIT=320MiB; после исправления трассы и логи получены, отказы повторены успешно.
|
||||
Подробности и начальные неуспешные журналы сохранены в INCIDENTS.md и evidence/.
|
||||
|
||||
## Эксперименты и отказы
|
||||
## Ограничения и источники
|
||||
|
||||
TODO: гипотеза, hardware/лимиты, версии, объём данных, профиль нагрузки, concurrency/arrival rate, длительность/прогрев, повторы, успешные RPS, ошибки, p50/p95/p99, CPU/RAM. Сохранить raw summary без tokens и объяснить ограничения измерения.
|
||||
Один host и единственные DB/broker/S3 не обеспечивают HA всего стенда.
|
||||
Research измеряет выбранный небольшой профиль, а не предельную пропускную способность.
|
||||
Head sampling может потерять ошибку или редкий медленный запрос: исход неизвестен при принятии решения.
|
||||
При снижении sampling traces метрики и логи продолжают экспортироваться.
|
||||
SDK off оставляет wrapper-код и stdout: измеряется дополнительная стоимость OTLP, не всей инструментации.
|
||||
Waiting учитывает текущие acquisition calls, включая немедленную выдачу соединения.
|
||||
Go Sys — зарезервированная runtime память, не RSS. Cgroup memory измеряется отдельно.
|
||||
Ready histogram содержит завершённые jobs; backlog контролируется отдельной метрикой.
|
||||
|
||||
| Воздействие | Что ожидаем | Что наблюдали | Время восстановления / потеря данных |
|
||||
| --- | --- | --- | --- |
|
||||
| TODO | TODO | TODO | TODO |
|
||||
|
||||
## Ограничения и следующие шаги
|
||||
|
||||
TODO: какие отказы выдерживаются и какие нет; что не реализовано; где учебное упрощение; какое улучшение подтверждено, а какое пока гипотеза.
|
||||
Источники: документация OTel Go/Collector, Prometheus histograms, Grafana provisioning,
|
||||
Loki OTLP ingestion и Tempo configuration; первичные ссылки — в README.
|
||||
Основа — соседний проект lab5. Реализация и проверки выполнены с помощью O3 Agent Codex.
|
||||
|
||||
+154
@@ -0,0 +1,154 @@
|
||||
# Цена наблюдаемости: методика трека 1
|
||||
|
||||
## Гипотеза
|
||||
|
||||
Снижение head sampling уменьшит объём traces и нагрузку telemetry backend.
|
||||
Метрики и логи останутся полными. Цена — потеря части трасс ошибок и медленных запросов.
|
||||
Сравниваются SDK off, sampling 100%,10%,50%. Кандидат сбалансированной настройки —50%.
|
||||
Приоритет учебного стенда: сохранить достаточно трасс для диагностики при меньшем ingest.
|
||||
|
||||
## Повторение
|
||||
|
||||
```sh
|
||||
make up
|
||||
make test
|
||||
python3 scripts/observability_experiment.py --requests 120 --rate 8 --concurrency 4 --repetitions 2
|
||||
python3 scripts/summarize_observability.py
|
||||
```
|
||||
|
||||
Запускайте последовательно с fault suite. Сценарий пересоздаёт API и worker,
|
||||
выставляет OTEL_SDK_DISABLED/OTEL_TRACES_SAMPLER_ARG, затем восстанавливает SDK on/sampling 100% в finally.
|
||||
Collector и backend не пересоздаются между вариантами; их counters сохраняются.
|
||||
Первый повтор: off→100%→10%→50%; второй — в обратном порядке.
|
||||
|
||||
На каждый вариант создаётся один синтетический пользователь, один чат и одинаковый набор данных.
|
||||
Из 120 измеряемых запросов 90 читают пользователя,18 создают сообщения,6 загружают PNG,6 ожидают 401.
|
||||
Размер fixture и текст сообщений одинаковы. Каждая из 6 загрузок должна стать ready.
|
||||
401 — ожидаемая клиентская ошибка; её не следует путать с 5xx и нарушением SLO API.
|
||||
Ошибки сверх ожидаемых статусов считаются отдельно; повтор запроса автоматически не выполняется.
|
||||
|
||||
После пересоздания выдерживаются 8 секунд, затем 20 GET для прогрева и ещё6 секунд.
|
||||
Планировщик задаёт 8 запросов/с и максимум 4 одновременно исполняемых вызова.
|
||||
При перегрузке клиент может отстать от расписания: это ограниченный генератор, не доказательство capacity.
|
||||
Latency измеряется от начала фактического вызова; задержка планировщика в percentile не входит.
|
||||
p50/p95/p99 включают все 120 вызовов, в том числе ожидаемые 401.
|
||||
|
||||
Во время нагрузки docker stats фиксирует CPU/RAM контейнеров примерно каждые 3 секунды.
|
||||
CPU — сумма средних по контейнерам;100% соответствует одному полностью занятому CPU.
|
||||
RAM — сумма наблюдавшихся максимумов, которые могли приходиться на разные моменты времени.
|
||||
Отдельно считаются API+worker и Collector/Prometheus/Loki/Tempo/Grafana.
|
||||
Измеряется не вся стоимость business stack: PostgreSQL/Redis/S3 не включены в группу application.
|
||||
|
||||
Через 12 секунд после нагрузки снимаются счётчики Collector и backend.
|
||||
Ingest traces/logs — прирост *_bytes_received_total, metrics — прирост TSDB appended samples.
|
||||
Это входные bytes/samples, не размер compressed storage и не сетевой трафик всего стенда.
|
||||
В прирост входят фоновые DB spans, health logs и собственные метрики инфраструктуры.
|
||||
SDK off отключает экспорт приложения, но backend и их self-monitoring продолжают работать.
|
||||
Отрицательные дельты counters означали бы restart и делали бы сравнение непригодным.
|
||||
|
||||
ID traces берутся из X-Trace-Id фактических ответов. Каждый ID запрашивается из Tempo.
|
||||
Входящий traceparent не задаётся: иначе parent-based sampler мог бы унаследовать решение клиента.
|
||||
Сохранность trace означает наличие хотя бы одного span по ID, а не доказательство полноты каждого span.
|
||||
Для полного sampling проверяется наличие всех 120 request traces.
|
||||
Отдельно считаются retained traces ожидаемых 401 и самых медленных 5% вызовов каждого опыта.
|
||||
Потери из-за решения sampling отделяются от ошибок exporter/refused spans.
|
||||
Число отсутствующих трасс — измерено; оценка потерь уникальных spans по одним счётчикам невозможна.
|
||||
|
||||
## Среда
|
||||
|
||||
Параметры host/VM и исходный commit записаны в evidence/lab6-environment.json.
|
||||
Docker VM:2 CPU,2053644288 bytes RAM,arm64. Лимиты компонентов — compose.yaml.
|
||||
Старые стенды lab4/lab5 удалены до измерений по просьбе пользователя; их volumes сохранены.
|
||||
Отдельный PostgreSQL вне проекта остаётся работающим и создаёт небольшой фоновый шум.
|
||||
Графики/таблицы не сравниваются с измерениями lab5: это другой профиль нагрузки.
|
||||
|
||||
## Результаты
|
||||
|
||||
Полный прогон завершился PASS:8 опытов,960 запросов,48 изображений ready,0 неожиданных ошибок.
|
||||
Исходные данные: [JSON](evidence/lab6-research.json), [CSV](evidence/lab6-research.csv),
|
||||
[агрегаты](evidence/lab6-research-summary.json), [журнал](evidence/lab6-research-run.txt).
|
||||
Таблица воспроизводится командой `python3 scripts/summarize_observability.py`.
|
||||
|
||||
| Config | Repeat | RPS | p50 ms | p95 ms | p99 ms | App CPU % | App MiB | Telemetry CPU % | Telemetry MiB | Request traces |
|
||||
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
||||
| off | 1 | 8.047 | 11.934 | 29.423 | 42.462 | 8.132 | 70.39 | 4.816 | 616.03 | 0/120 |
|
||||
| full | 1 | 8.053 | 11.856 | 31.41 | 42.052 | 9.962 | 73.733 | 10.37 | 608.78 | 120/120 |
|
||||
| ten_percent | 1 | 8.057 | 9.991 | 52.789 | 168.924 | 8.846 | 71.971 | 10.784 | 502.69 | 17/120 |
|
||||
| balanced | 1 | 8.062 | 10.423 | 30.254 | 52.116 | 8.462 | 71.314 | 10.322 | 651.25 | 72/120 |
|
||||
| balanced | 2 | 8.048 | 11.346 | 37.555 | 72.706 | 8.014 | 59.703 | 7.096 | 600.74 | 53/120 |
|
||||
| ten_percent | 2 | 8.061 | 12.281 | 42.42 | 63.216 | 7.942 | 60.066 | 13.176 | 671.03 | 17/120 |
|
||||
| full | 2 | 8.048 | 12.379 | 31.356 | 45.834 | 9.114 | 74.053 | 7.598 | 676.44 | 120/120 |
|
||||
| off | 2 | 8.05 | 10.728 | 30.012 | 63.853 | 7.404 | 64.176 | 6.616 | 563.21 | 0/120 |
|
||||
|
||||
Ниже суммы двух повторов каждой настройки; workload каждого варианта —240 измеряемых запросов.
|
||||
Объём ingest включает фоновые операции за окно наблюдения.
|
||||
|
||||
| Настройка | Tempo bytes | Loki bytes | TSDB samples | Exported spans | Traces запросов | Traces401 | Traces медленных 5% |
|
||||
| --- | --- | --- | --- | --- | --- | --- | --- |
|
||||
| off | 0 | 0 | 46185 | 0 | 0/240 | 0/12 | 0/12 |
|
||||
| full | 697602 | 198451 | 44282 | 4947 | 240/240 | 12/12 | 12/12 |
|
||||
| ten_percent | 95539 | 196690 | 49391 | 461 | 34/240 | 2/12 | 3/12 |
|
||||
| balanced | 362056 | 184978 | 44897 | 2402 | 125/240 | 7/12 | 8/12 |
|
||||
|
||||
При 50% trace ingest сократился на 48,10% относительно 100%; exported spans — примерно на 51,45%.
|
||||
Найдены 125/240 request traces,7/12 traces ожидаемых 401,8/12 traces самых медленных вызовов.
|
||||
При 10% ingest сократился на 86,30%, но потеряны 10/12 traces401 и 9/12 traces медленных вызовов.
|
||||
Во втором повторе 10% не сохранилась ни одна из 6 трасс upload.
|
||||
Это конкретный пример потери редкого пути, несмотря на успешную обработку всех изображений.
|
||||
Фактические 34/240=14,17% request traces при настройке 10% не обязаны точно совпадать с параметром:
|
||||
решение случайно, выборка небольшая, а byte/span-weighted доля зависит от типа запроса.
|
||||
|
||||
Во всех 8 опытах прирост exporter failed spans и receiver refused spans равен 0.
|
||||
При 100% найдены все 240 request traces, включая все 12 ожидаемых 401 и 12 самых медленных вызовов.
|
||||
Эти наблюдения не доказывают полноту каждого дочернего span.
|
||||
Accepted и sent counters снимаются асинхронно и могут пересекать разные границы batch/scrape;
|
||||
их разность не используется как число потерянных spans.
|
||||
Преднамеренная потеря при sampling показана через запросы по известным trace ID.
|
||||
Отдельно проверяется потеря при недоступном backend в evidence/lab6-backend-outage.json.
|
||||
|
||||
Средний по двум опытам CPU API+worker:off7,768%,100%9,538%,50%8,238%.
|
||||
Разница 100% и off составляет 1,77 процентного пункта одного CPU.
|
||||
Из-за короткого профиля и шума это наблюдение, а не точная оценка причинного overhead.
|
||||
RAM API+worker в варианте 100% достигала 74,053MiB против 70,390MiB в первом off.
|
||||
Backend RAM/CPU меняются с GC, compaction и кешами; sampling не даёт доказанного пропорционального снижения RAM.
|
||||
p99 при 10% колебался 63–169ms, при 100%42–46ms. Ускорение latency снижением sampling не подтверждено.
|
||||
|
||||
Logs ingest сохраняется примерно на одном уровне между on-вариантами:185–198kB за два окна.
|
||||
Metrics ingest в таблице включает self-monitoring backend, который работает и при SDK off.
|
||||
Фаза 5-секундного scrape и короткие окна дают существенную погрешность счётчика samples;
|
||||
по этим значениям нельзя приписать SDK отрицательную или точную дополнительную стоимость метрик.
|
||||
Метрики приложения при sampling traces продолжают экспортироваться; все обязательные сигналы проверены отдельно.
|
||||
|
||||
## Проверенная сбалансированная настройка
|
||||
|
||||
Для обычного учебного трафика предлагается parentbased_traceidratio=0.5 с полными metrics/logs.
|
||||
Оба опыта 50% прошли без неожиданных ошибок, все 12 загрузок этого варианта стали ready,
|
||||
а trace ingest примерно вдвое ниже 100%. Критерий выбора — снижение ingest при сохранении заметной части путей,
|
||||
а не доказанное ускорение HTTP. Цена: потеря 115/240 request traces и части медленных/ошибочных запросов.
|
||||
Эта настройка не подходит как гарантия сохранности всех ошибок.
|
||||
|
||||
```sh
|
||||
OTEL_TRACES_SAMPLER_ARG=0.5 ./scripts/compose.sh up -d --no-deps --force-recreate api worker
|
||||
```
|
||||
|
||||
Для защиты и разбора редкого retry восстановите 100%:
|
||||
|
||||
```sh
|
||||
OTEL_TRACES_SAMPLER_ARG=1.0 ./scripts/compose.sh up -d --no-deps --force-recreate api worker
|
||||
```
|
||||
|
||||
Сценарий исследования сам восстановил SDK on/sampling100% после завершения.
|
||||
|
||||
## Ограничения интерпретации
|
||||
|
||||
Два коротких повтора не дают узкий доверительный интервал для CPU и p99.
|
||||
При 8 RPS результат может определяться сетевой задержкой Docker и клиентом, а не SDK.
|
||||
Поэтому снижение p99 на одном варианте само по себе не доказывает ускорение приложения.
|
||||
Изменение ingest и сохранности traces — более прямое следствие sampling.
|
||||
Пять процентов самых медленных запросов определены относительно этого опыта, не production SLO.
|
||||
|
||||
Head sampling принимает решение до результата операции.50% не гарантирует сохранение 50% ошибок,
|
||||
а тем более всех редких 5xx. При 10% небольшая выборка ошибок может исчезнуть полностью.
|
||||
Сохранённые logs/metrics позволяют увидеть факт ошибки, но не восстановить потерянные spans.
|
||||
Чтобы сохранять почти все ошибки и редкие медленные запросы, нужен проверенный tail sampling
|
||||
либо отдельная политика захвата. Такой эксперимент в этой работе не заявляется.
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
# Диагностика учебного стенда
|
||||
|
||||
Откройте [dashboard](http://localhost:13000/d/messenger/messenger-observability), затем [состояния alerts](http://localhost:19090/alerts).
|
||||
Историю хранит Prometheus. Логи хранит Loki. Трассы хранит Tempo.
|
||||
Collector принимает OTLP и пересылает сигналы. Grafana выполняет запросы к хранилищам.
|
||||
|
||||
## HTTP-запросы завершаются с 5xx
|
||||
|
||||
1. Проверьте `APIHighErrorRate`. Числитель — бизнес-запросы с 5xx; знаменатель — все бизнес-запросы.
|
||||
Health и Swagger исключены из инструментов. Ошибки клиента 4xx входят только в знаменатель.
|
||||
2. Найдите route и status class на dashboard. Сравните p95/p99 с обычным значением.
|
||||
Запрос p95: `histogram_quantile(0.95, sum by (le) (rate(messenger_http_duration_seconds_bucket[1m])))`.
|
||||
Значение измеряется в секундах. Buckets объединяют обе API-реплики.
|
||||
3. В Explore → Loki выполните `{service_name="messenger-api"} | json | status >= 500`.
|
||||
Выберите запись `http.request`. Сохраните `request_id` и `trace_id`; тело сообщения не требуется.
|
||||
4. Откройте Tempo по `trace_id`. У HTTP span найдите дочерние `postgresql SELECT/INSERT`.
|
||||
Длительный ошибочный DB span указывает на ожидание БД. Долгий HTTP span без такого дочернего span требует другого расследования.
|
||||
5. Проверьте `messenger_db_pool_used`, `messenger_db_pool_max` и метрику ожидания пула.
|
||||
Высокая занятость — дополнительный признак, сама по себе она не доказывает блокировку PostgreSQL.
|
||||
6. В лабораторном опыте снимите искусственную блокировку или дождитесь завершения `pg_sleep`.
|
||||
Убедитесь, что новые записи получают 201, DB spans сокращаются, alert исчезает после очистки окна 1m.
|
||||
|
||||
## Вложения долго остаются queued/processing
|
||||
|
||||
1. Проверьте `QueueLagGrowing`, `max(messenger_queue_depth)` и `max(messenger_queue_oldest_age_seconds)`.
|
||||
Для общего backlog используйте max: каждая API-реплика наблюдает одну общую таблицу jobs.
|
||||
2. Сравните worker busy/capacity и свежесть worker-сигналов. Остановленный worker перестаёт экспортировать данные.
|
||||
Отсутствие свежих данных отличается от рабочего процесса с нулевой занятостью.
|
||||
3. В Loki найдите `job.published`, затем `job.completed` в той же трассе.
|
||||
В Tempo проверьте `attachments publish` → `attachments process` → S3 и PostgreSQL.
|
||||
4. Если consumer отсутствует, запустите `./scripts/compose.sh start worker`.
|
||||
Если consumer есть, но S3 span длительный или ошибочный, проверьте доступность MinIO.
|
||||
Повторные producer/consumer spans с той же трассой показывают retry.
|
||||
5. Убедитесь, что вложения стали ready, очередь опустела, возраст равен нулю, alert больше не firing.
|
||||
Полученный HTTP 202 подтверждает приём задания, но не окончание обработки.
|
||||
|
||||
## Не появляются трассы, API работает
|
||||
|
||||
1. Проверьте `up{job="collector"}`, `up{job="tempo"}` и `otelcol_exporter_queue_size`.
|
||||
2. Сравните `otelcol_exporter_sent_spans_total`, `otelcol_exporter_send_failed_spans_total` и `otelcol_receiver_refused_spans_total`.
|
||||
Failed экспорт учитывает неуспешные попытки; он не равен числу окончательно потерянных уникальных spans.
|
||||
3. Восстановите Tempo: `./scripts/compose.sh start tempo`.
|
||||
Убедитесь, что очередь exporter уменьшается и свежий trace находится по ID.
|
||||
4. После длительного отказа возможны потери: SDK и Collector имеют ограниченные очереди и timeout.
|
||||
Повторите запрос для диагностики. Не объявляйте отсутствие старой трассы потерей бизнес-данных.
|
||||
|
||||
## Повторение отказов
|
||||
|
||||
Запускайте только на отдельном учебном проекте lab6, последовательно с исследованием.
|
||||
Сценарий создаёт синтетические данные. Он не обращается к стендам lab4/lab5.
|
||||
|
||||
```sh
|
||||
python3 scripts/observability_faults.py
|
||||
```
|
||||
|
||||
Сценарий восстанавливает worker, MinIO и Tempo в `finally`.
|
||||
Блокировка PostgreSQL автоматически заканчивается через 45 секунд; соединение закрывается при ошибке.
|
||||
Наблюдения сохраняются в `evidence/lab6-faults.json`, связанные spans и логи — в соседних JSON.
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"gitflic.ru/akselbant/mtusi2026lab1-fork/internal/observability"
|
||||
"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() {
|
||||
shutdownTelemetry, telemetryErr := observability.Init(context.Background(), "messenger-api")
|
||||
if telemetryErr != nil {
|
||||
log.Fatal("telemetry configuration failed")
|
||||
}
|
||||
defer shutdownTelemetry()
|
||||
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.ConnConfig.Tracer = observability.DBTracer{}
|
||||
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()
|
||||
observability.ObservePool(pool, 0)
|
||||
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")
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"gitflic.ru/akselbant/mtusi2026lab1-fork/internal/attachment"
|
||||
"gitflic.ru/akselbant/mtusi2026lab1-fork/internal/config"
|
||||
"gitflic.ru/akselbant/mtusi2026lab1-fork/internal/observability"
|
||||
"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()
|
||||
shutdownTelemetry, telemetryErr := observability.Init(context.Background(), "messenger-worker")
|
||||
if telemetryErr != nil {
|
||||
log.Fatal("telemetry configuration failed")
|
||||
}
|
||||
defer shutdownTelemetry()
|
||||
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.ConnConfig.Tracer = observability.DBTracer{}
|
||||
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()
|
||||
observability.ObservePool(pool, options.Concurrency)
|
||||
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):
|
||||
}
|
||||
}
|
||||
}
|
||||
+250
@@ -0,0 +1,250 @@
|
||||
name: mtusi2026lab6
|
||||
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:
|
||||
environment:
|
||||
GOMEMLIMIT: 160MiB
|
||||
GOGC: '50'
|
||||
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:lab6
|
||||
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:lab6
|
||||
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: 384MiB
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT: http://collector:4318
|
||||
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
|
||||
OTEL_SDK_DISABLED: ${OTEL_SDK_DISABLED:-false}
|
||||
OTEL_TRACES_SAMPLER: parentbased_traceidratio
|
||||
OTEL_TRACES_SAMPLER_ARG: ${OTEL_TRACES_SAMPLER_ARG:-1.0}
|
||||
GOGC: '50'
|
||||
secrets: &api_secrets
|
||||
- postgres_password
|
||||
- cursor_key
|
||||
- s3_access_key
|
||||
- s3_secret_key
|
||||
deploy:
|
||||
replicas: 2
|
||||
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: 512m
|
||||
stop_grace_period: 10s
|
||||
worker:
|
||||
image: mtusi-messenger:lab6
|
||||
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: 512m
|
||||
stop_grace_period: 10s
|
||||
gateway:
|
||||
image: haproxy:3.2.4-alpine
|
||||
ports: ['127.0.0.1:${PORT:-18086}:8080']
|
||||
volumes: [./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro]
|
||||
depends_on: [api]
|
||||
mem_limit: 64m
|
||||
collector:
|
||||
image: otel/opentelemetry-collector-contrib:0.137.0
|
||||
command: [--config=/etc/otelcol/config.yaml]
|
||||
volumes: [./infra/otel/collector.yaml:/etc/otelcol/config.yaml:ro]
|
||||
mem_limit: 192m
|
||||
depends_on: [tempo, loki, prometheus]
|
||||
prometheus:
|
||||
image: prom/prometheus:v3.6.0
|
||||
command: [--config.file=/etc/prometheus/prometheus.yaml, --storage.tsdb.retention.time=7d, --storage.tsdb.retention.size=1GB, --web.enable-remote-write-receiver]
|
||||
ports: ['127.0.0.1:19090:9090']
|
||||
volumes:
|
||||
- ./infra/prometheus:/etc/prometheus:ro
|
||||
- prometheus_data:/prometheus
|
||||
mem_limit: 256m
|
||||
loki:
|
||||
image: grafana/loki:3.5.5
|
||||
command: [-config.file=/etc/loki/config.yaml]
|
||||
ports: ['127.0.0.1:13100:3100']
|
||||
volumes:
|
||||
- ./infra/loki.yaml:/etc/loki/config.yaml:ro
|
||||
- loki_data:/loki
|
||||
mem_limit: 192m
|
||||
tempo:
|
||||
image: grafana/tempo:2.8.2
|
||||
command: [-config.file=/etc/tempo/config.yaml]
|
||||
ports: ['127.0.0.1:13200:3200']
|
||||
volumes:
|
||||
- ./infra/tempo.yaml:/etc/tempo/config.yaml:ro
|
||||
- tempo_data:/var/tempo
|
||||
environment:
|
||||
GOMEMLIMIT: 320MiB
|
||||
GOGC: '50'
|
||||
mem_limit: 512m
|
||||
grafana:
|
||||
image: grafana/grafana:12.2.0
|
||||
ports: ['127.0.0.1:13000:3000']
|
||||
environment:
|
||||
GF_PLUGINS_PREINSTALL_DISABLED: 'true'
|
||||
GF_ANALYTICS_CHECK_FOR_UPDATES: 'false'
|
||||
GF_ANALYTICS_REPORTING_ENABLED: 'false'
|
||||
GF_AUTH_ANONYMOUS_ENABLED: 'true'
|
||||
GF_AUTH_ANONYMOUS_ORG_ROLE: Viewer
|
||||
GF_USERS_ALLOW_SIGN_UP: 'false'
|
||||
volumes:
|
||||
- ./infra/grafana/provisioning:/etc/grafana/provisioning:ro
|
||||
- ./infra/grafana/dashboards:/var/lib/grafana/dashboards:ro
|
||||
- grafana_data:/var/lib/grafana
|
||||
mem_limit: 192m
|
||||
depends_on: [prometheus, loki, tempo]
|
||||
tests:
|
||||
image: mtusi-messenger-tests:lab6
|
||||
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:
|
||||
|
||||
prometheus_data:
|
||||
loki_data:
|
||||
tempo_data:
|
||||
grafana_data:
|
||||
@@ -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
|
||||
@@ -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"`
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package dto
|
||||
|
||||
type LivenessRequest struct{}
|
||||
|
||||
type LivenessResponse struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package dto
|
||||
|
||||
type ReadinessRequest struct{}
|
||||
|
||||
type ReadinessResponse struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
+22
-3
@@ -1,5 +1,24 @@
|
||||
# Доказательства
|
||||
# Доказательства lab6
|
||||
|
||||
Храните небольшие обезличенные результаты: команды и stdout проверок, JSON/CSV агрегатов нагрузки, EXPLAIN, dashboard JSON, текст разбора отказа. Укажите дату, commit, аппаратные лимиты и профиль нагрузки.
|
||||
Все результаты получены на стенде этого репозитория. Данные синтетические.
|
||||
Времена JSON указаны в UTC; аппаратная конфигурация и исходный commit — lab6-environment.json.
|
||||
|
||||
Не добавляйте .env, session tokens, cookies, приватные ключи, credentials, реальные сообщения, raw dumps и signed URLs. Для скриншотов скрывайте секреты. Большие логи/бинарные traces сохраняйте отдельно по правилам преподавателя; одного скриншота без методики недостаточно.
|
||||
| Файл | Проверка |
|
||||
| --- | --- |
|
||||
| lab6-validation.txt | Offline contract, OpenAPI и Go race tests |
|
||||
| lab6-final-validation.txt | Повторная проверка контрактов после завершения изменений |
|
||||
| lab6-smoke.txt | Публичный API, включая асинхронные вложения |
|
||||
| lab6-persistence.txt, lab6-container-events.txt | Сохранность и scope restart хранилищ |
|
||||
| lab6-failover.txt, lab6-failover-containers.json | Две реплики, отказ одной, данные/сессия и восстановление |
|
||||
| lab6-provisioning.json | Пять targets UP, 15 панелей, 18 query, metric label policy |
|
||||
| lab6-faults.json, lab6-faults-run.txt | Успешный полный fault suite |
|
||||
| lab6-incident-metrics.json, lab6-incidents-summary.json | Сохранённые наблюдения worker/S3/DB |
|
||||
| trace-*.json, logs-*.json | Реальные связанные spans и структурные логи из Tempo/Loki |
|
||||
| lab6-backend-outage.json, lab6-backend-run.txt | Работа API при отказе Tempo, queue/RAM и потери traces |
|
||||
| lab6-research.json, lab6-research.csv, lab6-research-summary.json | Восемь опытов off/on/sampling, raw summaries, CPU/RAM |
|
||||
| lab6-research-run.txt | Журнал завершённого исследования |
|
||||
| lab6-runtime-state.json | Состояние контейнеров после проверок |
|
||||
|
||||
Файлы *-initial.* содержат начальные или прежние прогоны, включая обнаруженные ошибки.
|
||||
Они не заменяют успешные итоговые журналы. Подробнее: ../INCIDENTS.md и ../RESEARCH.md.
|
||||
Секреты, токены, тела сообщений, bytes изображений и signed URLs сюда не сохраняются.
|
||||
|
||||
@@ -0,0 +1,220 @@
|
||||
{
|
||||
"started_at": "2026-11-11T07:08:27.295682+00:00",
|
||||
"before": {
|
||||
"failed_spans": 10491.0,
|
||||
"refused_spans": 0.0,
|
||||
"queued_batches": 0.0,
|
||||
"rss_bytes": 81518592.0
|
||||
},
|
||||
"during": [
|
||||
{
|
||||
"seconds": 0.01,
|
||||
"failed_spans": 10491.0,
|
||||
"refused_spans": 0.0,
|
||||
"queued_batches": 0.0,
|
||||
"rss_bytes": 81518592.0
|
||||
},
|
||||
{
|
||||
"seconds": 5.2,
|
||||
"failed_spans": 10491.0,
|
||||
"refused_spans": 0.0,
|
||||
"queued_batches": 4.0,
|
||||
"rss_bytes": 81592320.0
|
||||
},
|
||||
{
|
||||
"seconds": 10.52,
|
||||
"failed_spans": 10491.0,
|
||||
"refused_spans": 0.0,
|
||||
"queued_batches": 9.0,
|
||||
"rss_bytes": 81612800.0
|
||||
},
|
||||
{
|
||||
"seconds": 15.79,
|
||||
"failed_spans": 10491.0,
|
||||
"refused_spans": 0.0,
|
||||
"queued_batches": 14.0,
|
||||
"rss_bytes": 81612800.0
|
||||
},
|
||||
{
|
||||
"seconds": 20.94,
|
||||
"failed_spans": 10559.0,
|
||||
"refused_spans": 0.0,
|
||||
"queued_batches": 18.0,
|
||||
"rss_bytes": 81616896.0
|
||||
},
|
||||
{
|
||||
"seconds": 26.07,
|
||||
"failed_spans": 10659.0,
|
||||
"refused_spans": 0.0,
|
||||
"queued_batches": 22.0,
|
||||
"rss_bytes": 81666048.0
|
||||
},
|
||||
{
|
||||
"seconds": 31.28,
|
||||
"failed_spans": 10659.0,
|
||||
"refused_spans": 0.0,
|
||||
"queued_batches": 27.0,
|
||||
"rss_bytes": 81666048.0
|
||||
}
|
||||
],
|
||||
"successful_writes": 35,
|
||||
"after": {
|
||||
"failed_spans": 10803.0,
|
||||
"refused_spans": 0.0,
|
||||
"queued_batches": 0.0,
|
||||
"rss_bytes": 81674240.0
|
||||
},
|
||||
"retained_request_traces": 32,
|
||||
"missing_request_traces": 3,
|
||||
"exporter_failed_spans_delta": 312.0,
|
||||
"receiver_refused_spans_delta": 0.0,
|
||||
"collector": {
|
||||
"oom": false,
|
||||
"memory_limit": 201326592
|
||||
},
|
||||
"status": "PASS",
|
||||
"finished_at": "2026-11-11T07:09:19.947185+00:00",
|
||||
"request_trace_results": [
|
||||
{
|
||||
"trace_id": "004adff807639444e55202464ea93fe3",
|
||||
"found": false
|
||||
},
|
||||
{
|
||||
"trace_id": "08df5dc321e96dc41068b1be56f04687",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "1aeaee387a6b2cbb4ad320c3e34d7b3d",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "1b25416590b8cd69b8063e2fe54d5da6",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "2ea7a14a909ba468bfbe045fcc9ef556",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "332601b1543a4a16827ef181d88efb04",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "3a0f8d48655b7190e4afab69bd9a7357",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "3ae8ac314578b01a61d4f4889d274467",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "41b19f9f0aecc4f4805f90e1c4901384",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "4a2480d683cfbff700d3276502e3f6d0",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "4b9b780f232470232ff61e6e8ea0031e",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "51462d539eb2514fa66727227a3e30c0",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "57b44fd53e4383bfd896fce7c4cb6fa5",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "7281f6cbd7790df5948f7b03fef14d7a",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "7cd8d3c5bec5684f4cadb7569cc40d04",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "7e2ac3261a8a6745667b08c9e6e20314",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "8074d021c476f9ce1eb64c2141e24ffa",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "865556f2adf8a006995f6895c4a82513",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "973fe7d2582609896fb1166313eb219c",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "9d28d77ca28cf24aa3e6fe1607c408a2",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "9fc10f8741f5bf971b80c7d58d7bf936",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "ac5f5b02318a8c2f4a1f4ba129339f56",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "ac8bc1e2d842b25238518ee0a872ae4d",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "ad3e00cc2507be3a6af4cce1ff732311",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "b26abeb379b6568c25f6d0e570978bc6",
|
||||
"found": false
|
||||
},
|
||||
{
|
||||
"trace_id": "b92c8b1f65d944e03623ca05cd013dd5",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "bc795f70921ad071cebb4ce9e053eebe",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "c60cfe77fa24afb2477a776bcf5abd71",
|
||||
"found": false
|
||||
},
|
||||
{
|
||||
"trace_id": "d3359fdbc04ddaa1d3a6275fd4908361",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "dc13a3387339133eea087b6b1371cc46",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "df4b8b322e294fe8b8caf1fe3e14bd5b",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "e5c7704f60b9e8c8d33b91037737eeaa",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "f0fb0084dd1ed1a177eb297ebf213ef5",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "f11bb8dc1d60dd494bf0ed79d834338a",
|
||||
"found": true
|
||||
},
|
||||
{
|
||||
"trace_id": "f953829e6b5b3bfc853fb866a331a1b4",
|
||||
"found": true
|
||||
}
|
||||
],
|
||||
"verification_source": "201 message http.request logs in exact incident time window; query traces again by ID"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"status": "PASS", "successful_writes": 35, "retained_request_traces": 32, "missing_request_traces": 3, "exporter_failed_spans_delta": 312.0}
|
||||
@@ -0,0 +1,60 @@
|
||||
1794339137 kill mtusi2026lab6-minio-1
|
||||
1794339137 kill mtusi2026lab6-loki-1
|
||||
1794339137 kill mtusi2026lab6-redis-1
|
||||
1794339137 kill mtusi2026lab6-api-1
|
||||
1794339137 kill mtusi2026lab6-prometheus-1
|
||||
1794339137 kill mtusi2026lab6-collector-1
|
||||
1794339137 kill mtusi2026lab6-grafana-1
|
||||
1794339137 kill mtusi2026lab6-api-2
|
||||
1794339137 kill mtusi2026lab6-gateway-1
|
||||
1794339137 kill mtusi2026lab6-worker-1
|
||||
1794339137 kill mtusi2026lab6-postgres-1
|
||||
1794339137 kill mtusi2026lab6-tempo-1
|
||||
1794339137 stop mtusi2026lab6-minio-1
|
||||
1794339137 die mtusi2026lab6-minio-1
|
||||
1794339137 stop mtusi2026lab6-collector-1
|
||||
1794339137 die mtusi2026lab6-collector-1
|
||||
1794339137 stop mtusi2026lab6-redis-1
|
||||
1794339137 die mtusi2026lab6-redis-1
|
||||
1794339138 stop mtusi2026lab6-grafana-1
|
||||
1794339138 die mtusi2026lab6-grafana-1
|
||||
1794339138 stop mtusi2026lab6-prometheus-1
|
||||
1794339138 die mtusi2026lab6-prometheus-1
|
||||
1794339138 stop mtusi2026lab6-worker-1
|
||||
1794339138 die mtusi2026lab6-postgres-1
|
||||
1794339138 stop mtusi2026lab6-postgres-1
|
||||
1794339138 die mtusi2026lab6-worker-1
|
||||
1794339138 stop mtusi2026lab6-tempo-1
|
||||
1794339138 die mtusi2026lab6-tempo-1
|
||||
1794339138 stop mtusi2026lab6-gateway-1
|
||||
1794339138 die mtusi2026lab6-gateway-1
|
||||
1794339138 start mtusi2026lab6-minio-1
|
||||
1794339138 restart mtusi2026lab6-minio-1
|
||||
1794339138 start mtusi2026lab6-collector-1
|
||||
1794339138 restart mtusi2026lab6-collector-1
|
||||
1794339138 stop mtusi2026lab6-loki-1
|
||||
1794339138 die mtusi2026lab6-loki-1
|
||||
1794339138 start mtusi2026lab6-redis-1
|
||||
1794339138 restart mtusi2026lab6-redis-1
|
||||
1794339138 start mtusi2026lab6-grafana-1
|
||||
1794339138 restart mtusi2026lab6-grafana-1
|
||||
1794339138 start mtusi2026lab6-postgres-1
|
||||
1794339138 restart mtusi2026lab6-postgres-1
|
||||
1794339138 start mtusi2026lab6-worker-1
|
||||
1794339138 restart mtusi2026lab6-worker-1
|
||||
1794339138 start mtusi2026lab6-prometheus-1
|
||||
1794339138 restart mtusi2026lab6-prometheus-1
|
||||
1794339138 start mtusi2026lab6-gateway-1
|
||||
1794339138 restart mtusi2026lab6-gateway-1
|
||||
1794339139 start mtusi2026lab6-tempo-1
|
||||
1794339139 restart mtusi2026lab6-tempo-1
|
||||
1794339139 start mtusi2026lab6-loki-1
|
||||
1794339139 restart mtusi2026lab6-loki-1
|
||||
1794339140 stop mtusi2026lab6-api-1
|
||||
1794339140 die mtusi2026lab6-api-1
|
||||
1794339140 stop mtusi2026lab6-api-2
|
||||
1794339140 die mtusi2026lab6-api-2
|
||||
1794339140 start mtusi2026lab6-api-1
|
||||
1794339140 restart mtusi2026lab6-api-1
|
||||
1794339140 start mtusi2026lab6-api-2
|
||||
1794339140 restart mtusi2026lab6-api-2
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"at": "2026-11-10T19:28:02.037325+00:00",
|
||||
"host": "macOS-26.6.2-arm64-arm-64bit",
|
||||
"architecture": "arm64",
|
||||
"docker": {
|
||||
"cpus": 2,
|
||||
"memory_bytes": 2053644288,
|
||||
"server_version": "29.5.2"
|
||||
},
|
||||
"base_commit": "470d9d6f1e4fe4f594e37c2ba59550ee5ca54fc1",
|
||||
"note": "Old mtusi-lab4 and mtusi-lab5 Swarm stacks removed at user request before runtime experiments; persistent volumes retained. Standalone postgres remains running.",
|
||||
"old_stacks_removed_at": "2026-11-10T19:29:34.767211+00:00"
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"at": "2026-11-11T07:11:03.337621+00:00",
|
||||
"before": [
|
||||
{
|
||||
"name": "/mtusi2026lab6-api-1",
|
||||
"alias": "00403456e233",
|
||||
"status": "running"
|
||||
},
|
||||
{
|
||||
"name": "/mtusi2026lab6-api-2",
|
||||
"alias": "60b77a464203",
|
||||
"status": "running"
|
||||
}
|
||||
],
|
||||
"after": [
|
||||
{
|
||||
"name": "/mtusi2026lab6-api-1",
|
||||
"alias": "00403456e233",
|
||||
"status": "running"
|
||||
},
|
||||
{
|
||||
"name": "/mtusi2026lab6-api-2",
|
||||
"alias": "60b77a464203",
|
||||
"status": "exited"
|
||||
}
|
||||
],
|
||||
"exit_code": 0,
|
||||
"restored": [
|
||||
{
|
||||
"name": "/mtusi2026lab6-api-1",
|
||||
"alias": "00403456e233",
|
||||
"status": "running"
|
||||
},
|
||||
{
|
||||
"name": "/mtusi2026lab6-api-2",
|
||||
"alias": "60b77a464203",
|
||||
"status": "running"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
$ make test-failover ACTION_SCRIPT=scripts/stop-one.sh
|
||||
python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "http://localhost:18086"
|
||||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||||
{"observed_instances_before": 2, "successful_writes": 118, "failed_attempts": 5, "first_recovery_seconds": 4.062}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
|
||||
exit=0
|
||||
@@ -0,0 +1,7 @@
|
||||
$ make test-failover ACTION_SCRIPT=scripts/stop-one.sh
|
||||
python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "http://localhost:18086"
|
||||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||||
{"observed_instances_before": 2, "successful_writes": 117, "failed_attempts": 4, "first_recovery_seconds": 3.382}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
|
||||
exit=0
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,13 @@
|
||||
Worker outage
|
||||
DB lock
|
||||
Telemetry backend outage
|
||||
Traceback (most recent call last):
|
||||
File "/Users/dkhakimovig/mtusi2026lab6/scripts/observability_faults.py", line 140, in <module>
|
||||
main()
|
||||
File "/Users/dkhakimovig/mtusi2026lab6/scripts/observability_faults.py", line 124, in main
|
||||
report['correlation'] = [collect_trace(t) for t in (traces[0], traces[-1])]
|
||||
File "/Users/dkhakimovig/mtusi2026lab6/scripts/observability_faults.py", line 124, in <listcomp>
|
||||
report['correlation'] = [collect_trace(t) for t in (traces[0], traces[-1])]
|
||||
File "/Users/dkhakimovig/mtusi2026lab6/scripts/observability_faults.py", line 38, in collect_trace
|
||||
raise RuntimeError('trace/log correlation not found in backend')
|
||||
RuntimeError: trace/log correlation not found in backend
|
||||
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"started_at": "2026-11-11T06:52:37.598456+00:00",
|
||||
"cases": {
|
||||
"s3_retry": {
|
||||
"alerts_during": [
|
||||
{
|
||||
"labels": {
|
||||
"alertname": "QueueLagGrowing",
|
||||
"severity": "warning"
|
||||
},
|
||||
"annotations": {
|
||||
"description": "Inspect worker capacity, busy, outcomes and dependency spans; see RUNBOOK.md.",
|
||||
"runbook_url": "http://localhost:13000/d/messenger/messenger-observability",
|
||||
"summary": "Oldest unfinished attachment exceeds 10 seconds"
|
||||
},
|
||||
"state": "firing",
|
||||
"activeAt": "2026-11-11T06:52:54.758725496Z",
|
||||
"value": "7.8294858e+01"
|
||||
}
|
||||
],
|
||||
"jobs": [
|
||||
{
|
||||
"metric": {
|
||||
"__name__": "messenger_jobs_total",
|
||||
"deployment_environment_name": "lab",
|
||||
"exported_instance": "e2edd33d8b58",
|
||||
"exported_job": "messenger-worker",
|
||||
"instance": "collector:8889",
|
||||
"job": "messenger",
|
||||
"job_type": "attachment.process.v1",
|
||||
"otel_scope_name": "messenger",
|
||||
"outcome": "storage_unavailable",
|
||||
"service_instance_id": "e2edd33d8b58",
|
||||
"service_name": "messenger-worker",
|
||||
"service_version": "lab6"
|
||||
},
|
||||
"value": [
|
||||
1794380041.365,
|
||||
"24"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"finished_at": "2026-11-11T06:54:02.143528+00:00"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
Worker outage
|
||||
Traceback (most recent call last):
|
||||
File "/Users/dkhakimovig/mtusi2026lab6/scripts/observability_faults.py", line 148, in <module>
|
||||
main()
|
||||
File "/Users/dkhakimovig/mtusi2026lab6/scripts/observability_faults.py", line 78, in main
|
||||
c.wait_ready(actor, att)
|
||||
File "/Users/dkhakimovig/mtusi2026lab6/tests/client.py", line 196, in wait_ready
|
||||
att = self.call('GET','/api/v1/attachments/'+att['id'],actor=actor,schema='Attachment')['json']
|
||||
File "/Users/dkhakimovig/mtusi2026lab6/tests/client.py", line 132, in call
|
||||
check(status in allowed, method + ' ' + path.split('?')[0] + ': expected ' + str(allowed) + ', received ' + str(status))
|
||||
File "/Users/dkhakimovig/mtusi2026lab6/tests/client.py", line 24, in check
|
||||
raise Failure(message)
|
||||
client.Failure: GET /api/v1/attachments/e377e191-b942-47fa-b691-eefb232588d7: expected [200], received 503
|
||||
@@ -0,0 +1,4 @@
|
||||
Worker outage
|
||||
DB lock
|
||||
Telemetry backend outage
|
||||
{"status": "PASS", "cases": ["s3_retry", "worker_stop", "db_lock", "tempo_stop"]}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,9 @@
|
||||
$ make check validate PYTHON=.venv/bin/python
|
||||
.venv/bin/python scripts/check_contract.py
|
||||
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
|
||||
.venv/bin/python scripts/validate_openapi.py
|
||||
PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested.
|
||||
/Users/dkhakimovig/mtusi2026lab6/.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(
|
||||
|
||||
exit=0
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"queue_first_firing_seconds": 20.18,
|
||||
"queue_max_observed_age_seconds": 26.179077,
|
||||
"ready_jobs": 6,
|
||||
"db_http_status_counts": {
|
||||
"503": 28
|
||||
},
|
||||
"db_max_latency_seconds": 2.0508444580000003,
|
||||
"db_recovery_poll_count": 10,
|
||||
"trace_summary": [
|
||||
{
|
||||
"trace_id": "3c112fa1787d40898e457423046b2e97",
|
||||
"span_names": {
|
||||
"POST /api/v1/chats/{chat_id}/attachments": 1,
|
||||
"postgresql SELECT": 13,
|
||||
"postgresql BEGIN": 9,
|
||||
"s3 PUT": 10,
|
||||
"postgresql INSERT": 3,
|
||||
"postgresql COMMIT": 9,
|
||||
"attachments publish": 4,
|
||||
"attachments process": 4,
|
||||
"postgresql UPDATE": 19,
|
||||
"s3 download and image render": 4,
|
||||
"s3 GET": 4
|
||||
},
|
||||
"longest_span_seconds": 0.169544764,
|
||||
"log_streams": 9
|
||||
},
|
||||
{
|
||||
"trace_id": "dbc9b2dc91404a1fa7fae889b013bb34",
|
||||
"span_names": {
|
||||
"postgresql SELECT": 5,
|
||||
"postgresql BEGIN": 1,
|
||||
"POST /api/v1/chats/{chat_id}/messages": 1
|
||||
},
|
||||
"longest_span_seconds": 2.008227803,
|
||||
"log_streams": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
$ make test-persistence ACTION_SCRIPT=scripts/restart.sh
|
||||
python3 tests/resilience.py --mode persistence --action-script "scripts/restart.sh" --base-url "http://localhost:18086"
|
||||
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
|
||||
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
|
||||
exit=0
|
||||
@@ -0,0 +1,4 @@
|
||||
$ python3 scripts/verify_observability.py
|
||||
{"status": "PASS", "panels": 15, "queries": 18, "label_policy": "PASS"}
|
||||
|
||||
exit=0
|
||||
@@ -0,0 +1,120 @@
|
||||
{
|
||||
"at": "2026-11-11T07:14:35.828099+00:00",
|
||||
"status": "PASS",
|
||||
"targets": {
|
||||
"collector": "up",
|
||||
"loki": "up",
|
||||
"messenger": "up",
|
||||
"prometheus": "up",
|
||||
"tempo": "up"
|
||||
},
|
||||
"dashboard_uid": "messenger",
|
||||
"panel_count": 15,
|
||||
"queries": [
|
||||
{
|
||||
"panel": "API RPS (business routes)",
|
||||
"query": "sum(rate(messenger_http_requests_total[1m])) by (route)",
|
||||
"series": 7
|
||||
},
|
||||
{
|
||||
"panel": "API 5xx / all business requests",
|
||||
"query": "(sum(rate(messenger_http_requests_total{status_class=\"5xx\"}[1m])) or vector(0)) / clamp_min(sum(rate(messenger_http_requests_total[1m])),0.001)",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "API p50 / p95 / p99 (all replicas, histogram)",
|
||||
"query": "histogram_quantile(0.5,sum(rate(messenger_http_duration_seconds_bucket[1m])) by(le))",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "API p50 / p95 / p99 (all replicas, histogram)",
|
||||
"query": "histogram_quantile(0.95,sum(rate(messenger_http_duration_seconds_bucket[1m])) by(le))",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "API p50 / p95 / p99 (all replicas, histogram)",
|
||||
"query": "histogram_quantile(0.99,sum(rate(messenger_http_duration_seconds_bucket[1m])) by(le))",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Worker job outcomes per second",
|
||||
"query": "sum(rate(messenger_jobs_total[1m])) by(outcome)",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Worker job p95 duration",
|
||||
"query": "histogram_quantile(0.95,sum(rate(messenger_job_duration_seconds_bucket[1m])) by(le,outcome))",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Time from durable acceptance to ready p95",
|
||||
"query": "histogram_quantile(0.95,sum(rate(messenger_attachment_ready_seconds_bucket[1m])) by(le))",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Authoritative queue depth (max across observers)",
|
||||
"query": "max(messenger_queue_depth)",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Oldest unfinished job age",
|
||||
"query": "max(messenger_queue_oldest_age_seconds)",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "DB pool acquired / acquiring / max",
|
||||
"query": "messenger_db_pool_used",
|
||||
"series": 3
|
||||
},
|
||||
{
|
||||
"panel": "DB pool acquired / acquiring / max",
|
||||
"query": "messenger_db_pool_waiting",
|
||||
"series": 3
|
||||
},
|
||||
{
|
||||
"panel": "DB pool acquired / acquiring / max",
|
||||
"query": "messenger_db_pool_max",
|
||||
"series": 3
|
||||
},
|
||||
{
|
||||
"panel": "Worker saturation busy / capacity",
|
||||
"query": "sum(messenger_worker_busy{service_name=\"messenger-worker\"}) / clamp_min(sum(messenger_worker_capacity{service_name=\"messenger-worker\"}),1)",
|
||||
"series": 1
|
||||
},
|
||||
{
|
||||
"panel": "Go runtime reserved memory (MemStats.Sys)",
|
||||
"query": "messenger_process_memory_bytes",
|
||||
"series": 3
|
||||
},
|
||||
{
|
||||
"panel": "Process CPU seconds / second",
|
||||
"query": "rate(messenger_process_cpu_seconds_total[1m])",
|
||||
"series": 3
|
||||
},
|
||||
{
|
||||
"panel": "SDK failed telemetry export operations",
|
||||
"query": "messenger_telemetry_export_errors",
|
||||
"series": 3
|
||||
},
|
||||
{
|
||||
"panel": "Exporter failed spans (attempts, not unique loss)",
|
||||
"query": "sum(otelcol_exporter_send_failed_spans_total) by (exporter)",
|
||||
"series": 1
|
||||
}
|
||||
],
|
||||
"metric_series_checked": 2554,
|
||||
"required_metrics": [
|
||||
"messenger_attachment_ready_seconds_bucket",
|
||||
"messenger_db_pool_used",
|
||||
"messenger_db_pool_waiting",
|
||||
"messenger_http_duration_seconds_bucket",
|
||||
"messenger_http_requests_total",
|
||||
"messenger_job_duration_seconds_bucket",
|
||||
"messenger_jobs_total",
|
||||
"messenger_queue_depth",
|
||||
"messenger_queue_oldest_age_seconds",
|
||||
"messenger_worker_busy",
|
||||
"messenger_worker_capacity"
|
||||
],
|
||||
"label_policy": "PASS"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
Running off repetition 1
|
||||
{"configuration": "off", "unexpected_errors": 0, "all_request_latency_ms": {"p50": 11.934, "p95": 29.423, "p99": 42.462}, "trace_retention": {"read": {"sent": 90, "found": 0}, "write": {"sent": 18, "found": 0}, "upload": {"sent": 6, "found": 0}, "client_error": {"sent": 6, "found": 0}}}
|
||||
Running full repetition 1
|
||||
{"configuration": "full", "unexpected_errors": 0, "all_request_latency_ms": {"p50": 11.856, "p95": 31.41, "p99": 42.052}, "trace_retention": {"read": {"sent": 90, "found": 90}, "write": {"sent": 18, "found": 18}, "upload": {"sent": 6, "found": 6}, "client_error": {"sent": 6, "found": 6}}}
|
||||
Running ten_percent repetition 1
|
||||
{"configuration": "ten_percent", "unexpected_errors": 0, "all_request_latency_ms": {"p50": 9.991, "p95": 52.789, "p99": 168.924}, "trace_retention": {"read": {"sent": 90, "found": 13}, "write": {"sent": 18, "found": 2}, "upload": {"sent": 6, "found": 1}, "client_error": {"sent": 6, "found": 1}}}
|
||||
Running balanced repetition 1
|
||||
{"configuration": "balanced", "unexpected_errors": 0, "all_request_latency_ms": {"p50": 10.423, "p95": 30.254, "p99": 52.116}, "trace_retention": {"read": {"sent": 90, "found": 54}, "write": {"sent": 18, "found": 10}, "upload": {"sent": 6, "found": 4}, "client_error": {"sent": 6, "found": 4}}}
|
||||
Running balanced repetition 2
|
||||
{"configuration": "balanced", "unexpected_errors": 0, "all_request_latency_ms": {"p50": 11.346, "p95": 37.555, "p99": 72.706}, "trace_retention": {"read": {"sent": 90, "found": 41}, "write": {"sent": 18, "found": 7}, "upload": {"sent": 6, "found": 2}, "client_error": {"sent": 6, "found": 3}}}
|
||||
Running ten_percent repetition 2
|
||||
{"configuration": "ten_percent", "unexpected_errors": 0, "all_request_latency_ms": {"p50": 12.281, "p95": 42.42, "p99": 63.216}, "trace_retention": {"read": {"sent": 90, "found": 12}, "write": {"sent": 18, "found": 4}, "upload": {"sent": 6, "found": 0}, "client_error": {"sent": 6, "found": 1}}}
|
||||
Running full repetition 2
|
||||
{"configuration": "full", "unexpected_errors": 0, "all_request_latency_ms": {"p50": 12.379, "p95": 31.356, "p99": 45.834}, "trace_retention": {"read": {"sent": 90, "found": 90}, "write": {"sent": 18, "found": 18}, "upload": {"sent": 6, "found": 6}, "client_error": {"sent": 6, "found": 6}}}
|
||||
Running off repetition 2
|
||||
{"configuration": "off", "unexpected_errors": 0, "all_request_latency_ms": {"p50": 10.728, "p95": 30.012, "p99": 63.853}, "trace_retention": {"read": {"sent": 90, "found": 0}, "write": {"sent": 18, "found": 0}, "upload": {"sent": 6, "found": 0}, "client_error": {"sent": 6, "found": 0}}}
|
||||
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"off": {
|
||||
"counter_delta_totals": {
|
||||
"exported_spans": 0,
|
||||
"failed_spans": 0,
|
||||
"accepted_spans": 0,
|
||||
"refused_spans": 0,
|
||||
"tempo_ingested_bytes": 0,
|
||||
"loki_ingested_bytes": 0,
|
||||
"prometheus_samples": 46185.0
|
||||
},
|
||||
"traces_found": 0,
|
||||
"requests": 240,
|
||||
"slow_found": 0,
|
||||
"slow_sent": 12,
|
||||
"client_error_found": 0,
|
||||
"client_error_sent": 12
|
||||
},
|
||||
"full": {
|
||||
"counter_delta_totals": {
|
||||
"exported_spans": 4947.0,
|
||||
"failed_spans": 0,
|
||||
"accepted_spans": 4898.0,
|
||||
"refused_spans": 0,
|
||||
"tempo_ingested_bytes": 697602.0,
|
||||
"loki_ingested_bytes": 198451.0,
|
||||
"prometheus_samples": 44282.0
|
||||
},
|
||||
"traces_found": 240,
|
||||
"requests": 240,
|
||||
"slow_found": 12,
|
||||
"slow_sent": 12,
|
||||
"client_error_found": 12,
|
||||
"client_error_sent": 12
|
||||
},
|
||||
"ten_percent": {
|
||||
"counter_delta_totals": {
|
||||
"exported_spans": 461.0,
|
||||
"failed_spans": 0,
|
||||
"accepted_spans": 453.0,
|
||||
"refused_spans": 0,
|
||||
"tempo_ingested_bytes": 95539.0,
|
||||
"loki_ingested_bytes": 196690.0,
|
||||
"prometheus_samples": 49391.0
|
||||
},
|
||||
"traces_found": 34,
|
||||
"requests": 240,
|
||||
"slow_found": 3,
|
||||
"slow_sent": 12,
|
||||
"client_error_found": 2,
|
||||
"client_error_sent": 12
|
||||
},
|
||||
"balanced": {
|
||||
"counter_delta_totals": {
|
||||
"exported_spans": 2402.0,
|
||||
"failed_spans": 0,
|
||||
"accepted_spans": 2402.0,
|
||||
"refused_spans": 0,
|
||||
"tempo_ingested_bytes": 362056.0,
|
||||
"loki_ingested_bytes": 184978.0,
|
||||
"prometheus_samples": 44897.0
|
||||
},
|
||||
"traces_found": 125,
|
||||
"requests": 240,
|
||||
"slow_found": 8,
|
||||
"slow_sent": 12,
|
||||
"client_error_found": 7,
|
||||
"client_error_sent": 12
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
configuration,repetition,rps,unexpected_errors,p50,p95,p99,app_cpu_percent_sum_mean,app_ram_mib_sum_peak,telemetry_cpu_percent_sum_mean,telemetry_ram_mib_sum_peak,sent_requests,retained_request_traces,missing_request_traces,exported_spans,failed_spans,accepted_spans,refused_spans,tempo_ingested_bytes,loki_ingested_bytes,prometheus_samples
|
||||
off,1,8.047,0,11.934,29.423,42.462,8.132,70.39,4.816,616.03,120,0,120,0.0,0.0,0.0,0.0,0.0,0.0,24720.0
|
||||
full,1,8.053,0,11.856,31.41,42.052,9.962,73.733,10.37,608.78,120,120,0,2663.0,0.0,2615.0,0.0,343731.0,94264.0,21738.0
|
||||
ten_percent,1,8.057,0,9.991,52.789,168.924,8.846,71.971,10.784,502.69,120,17,103,246.0,0.0,241.0,0.0,52631.0,103980.0,26869.0
|
||||
balanced,1,8.062,0,10.423,30.254,52.116,8.462,71.314,10.322,651.25,120,72,48,1214.0,0.0,1214.0,0.0,195601.0,93278.0,22393.0
|
||||
balanced,2,8.048,0,11.346,37.555,72.706,8.014,59.703,7.096,600.74,120,53,67,1188.0,0.0,1188.0,0.0,166455.0,91700.0,22504.0
|
||||
ten_percent,2,8.061,0,12.281,42.42,63.216,7.942,60.066,13.176,671.03,120,17,103,215.0,0.0,212.0,0.0,42908.0,92710.0,22522.0
|
||||
full,2,8.048,0,12.379,31.356,45.834,9.114,74.053,7.598,676.44,120,120,0,2284.0,0.0,2283.0,0.0,353871.0,104187.0,22544.0
|
||||
off,2,8.05,0,10.728,30.012,63.853,7.404,64.176,6.616,563.21,120,0,120,0.0,0.0,0.0,0.0,0.0,0.0,21465.0
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,145 @@
|
||||
{
|
||||
"at": "2026-11-11T07:17:02.023361+00:00",
|
||||
"containers": [
|
||||
{
|
||||
"name": "/mtusi2026lab6-api-1",
|
||||
"image": "mtusi-messenger:lab6",
|
||||
"status": "running",
|
||||
"started_at": "2026-11-11T07:06:34.329528303Z",
|
||||
"oom_killed": false,
|
||||
"exit_code": 0,
|
||||
"memory_limit_bytes": 536870912,
|
||||
"nano_cpus": 1000000000
|
||||
},
|
||||
{
|
||||
"name": "/mtusi2026lab6-api-2",
|
||||
"image": "mtusi-messenger:lab6",
|
||||
"status": "running",
|
||||
"started_at": "2026-11-11T07:11:20.392887139Z",
|
||||
"oom_killed": false,
|
||||
"exit_code": 0,
|
||||
"memory_limit_bytes": 536870912,
|
||||
"nano_cpus": 1000000000
|
||||
},
|
||||
{
|
||||
"name": "/mtusi2026lab6-collector-1",
|
||||
"image": "otel/opentelemetry-collector-contrib:0.137.0",
|
||||
"status": "running",
|
||||
"started_at": "2026-11-10T19:32:17.968197475Z",
|
||||
"oom_killed": false,
|
||||
"exit_code": 0,
|
||||
"memory_limit_bytes": 201326592,
|
||||
"nano_cpus": 0
|
||||
},
|
||||
{
|
||||
"name": "/mtusi2026lab6-gateway-1",
|
||||
"image": "haproxy:3.2.4-alpine",
|
||||
"status": "running",
|
||||
"started_at": "2026-11-10T19:32:18.286616663Z",
|
||||
"oom_killed": false,
|
||||
"exit_code": 0,
|
||||
"memory_limit_bytes": 67108864,
|
||||
"nano_cpus": 0
|
||||
},
|
||||
{
|
||||
"name": "/mtusi2026lab6-grafana-1",
|
||||
"image": "grafana/grafana:12.2.0",
|
||||
"status": "running",
|
||||
"started_at": "2026-11-10T19:32:18.090061627Z",
|
||||
"oom_killed": false,
|
||||
"exit_code": 0,
|
||||
"memory_limit_bytes": 201326592,
|
||||
"nano_cpus": 0
|
||||
},
|
||||
{
|
||||
"name": "/mtusi2026lab6-loki-1",
|
||||
"image": "grafana/loki:3.5.5",
|
||||
"status": "running",
|
||||
"started_at": "2026-11-10T19:32:18.51793344Z",
|
||||
"oom_killed": false,
|
||||
"exit_code": 0,
|
||||
"memory_limit_bytes": 201326592,
|
||||
"nano_cpus": 0
|
||||
},
|
||||
{
|
||||
"name": "/mtusi2026lab6-migrations-1",
|
||||
"image": "mtusi-migrations:lab6",
|
||||
"status": "exited",
|
||||
"started_at": "2026-11-10T19:38:06.556403206Z",
|
||||
"oom_killed": false,
|
||||
"exit_code": 0,
|
||||
"memory_limit_bytes": 134217728,
|
||||
"nano_cpus": 500000000
|
||||
},
|
||||
{
|
||||
"name": "/mtusi2026lab6-minio-1",
|
||||
"image": "mtusi-minio:RELEASE.2025-09-07T16-13-09Z",
|
||||
"status": "running",
|
||||
"started_at": "2026-11-11T06:56:16.504084898Z",
|
||||
"oom_killed": false,
|
||||
"exit_code": 0,
|
||||
"memory_limit_bytes": 536870912,
|
||||
"nano_cpus": 1000000000
|
||||
},
|
||||
{
|
||||
"name": "/mtusi2026lab6-postgres-1",
|
||||
"image": "postgres:17.6-alpine3.22",
|
||||
"status": "running",
|
||||
"started_at": "2026-11-10T19:32:18.144322815Z",
|
||||
"oom_killed": false,
|
||||
"exit_code": 0,
|
||||
"memory_limit_bytes": 536870912,
|
||||
"nano_cpus": 1000000000
|
||||
},
|
||||
{
|
||||
"name": "/mtusi2026lab6-prometheus-1",
|
||||
"image": "prom/prometheus:v3.6.0",
|
||||
"status": "running",
|
||||
"started_at": "2026-11-10T19:32:18.132436Z",
|
||||
"oom_killed": false,
|
||||
"exit_code": 0,
|
||||
"memory_limit_bytes": 268435456,
|
||||
"nano_cpus": 0
|
||||
},
|
||||
{
|
||||
"name": "/mtusi2026lab6-redis-1",
|
||||
"image": "redis:7.4.5-alpine3.21",
|
||||
"status": "running",
|
||||
"started_at": "2026-11-10T19:32:17.96910494Z",
|
||||
"oom_killed": false,
|
||||
"exit_code": 0,
|
||||
"memory_limit_bytes": 402653184,
|
||||
"nano_cpus": 500000000
|
||||
},
|
||||
{
|
||||
"name": "/mtusi2026lab6-s3_bootstrap-1",
|
||||
"image": "mtusi-mc:RELEASE.2025-08-13T08-35-41Z",
|
||||
"status": "exited",
|
||||
"started_at": "2026-11-10T19:38:06.557042047Z",
|
||||
"oom_killed": false,
|
||||
"exit_code": 0,
|
||||
"memory_limit_bytes": 536870912,
|
||||
"nano_cpus": 500000000
|
||||
},
|
||||
{
|
||||
"name": "/mtusi2026lab6-tempo-1",
|
||||
"image": "grafana/tempo:2.8.2",
|
||||
"status": "running",
|
||||
"started_at": "2026-11-11T07:09:04.705778982Z",
|
||||
"oom_killed": false,
|
||||
"exit_code": 0,
|
||||
"memory_limit_bytes": 536870912,
|
||||
"nano_cpus": 0
|
||||
},
|
||||
{
|
||||
"name": "/mtusi2026lab6-worker-1",
|
||||
"image": "mtusi-messenger:lab6",
|
||||
"status": "running",
|
||||
"started_at": "2026-11-11T07:06:34.208498895Z",
|
||||
"oom_killed": false,
|
||||
"exit_code": 0,
|
||||
"memory_limit_bytes": 536870912,
|
||||
"nano_cpus": 1000000000
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
$ make test
|
||||
python3 tests/smoke.py --base-url "http://localhost:18086"
|
||||
PASS: lab6 public API scenario; infrastructure and grading evidence remain separate.
|
||||
|
||||
exit=0
|
||||
@@ -0,0 +1,12 @@
|
||||
$ make check validate PYTHON=.venv/bin/python
|
||||
.venv/bin/python scripts/check_contract.py
|
||||
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
|
||||
.venv/bin/python scripts/validate_openapi.py
|
||||
PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested.
|
||||
/Users/dkhakimovig/mtusi2026lab6/.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(
|
||||
|
||||
exit=0
|
||||
|
||||
$ GOMODCACHE=/private/tmp/lab6-gomodcache GOCACHE=/private/tmp/lab6-gocache go test -race ./...
|
||||
PASS: all tested packages; exit=0. Run completed before runtime fault injection.
|
||||
@@ -0,0 +1,349 @@
|
||||
{
|
||||
"status": "success",
|
||||
"data": {
|
||||
"resultType": "streams",
|
||||
"result": [
|
||||
{
|
||||
"stream": {
|
||||
"deployment_environment_name": "lab",
|
||||
"detected_level": "info",
|
||||
"flags": "1",
|
||||
"observed_timestamp": "1794380182289689386",
|
||||
"scope_name": "messenger",
|
||||
"service_instance_id": "e2edd33d8b58",
|
||||
"service_name": "messenger-worker",
|
||||
"service_version": "lab6",
|
||||
"severity_number": "9",
|
||||
"span_id": "48b1a00146d15161",
|
||||
"trace_id": "3c112fa1787d40898e457423046b2e97"
|
||||
},
|
||||
"values": [
|
||||
[
|
||||
"1794380182289687670",
|
||||
"{\"attempt\":4,\"event\":\"job.completed\",\"job_type\":\"attachment.process.v1\",\"outcome\":\"ready\",\"service.name\":\"messenger-worker\",\"severity\":\"INFO\",\"span_id\":\"48b1a00146d15161\",\"timestamp\":\"2026-11-11T06:56:22.289660585Z\",\"trace_id\":\"3c112fa1787d40898e457423046b2e97\"}"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"stream": {
|
||||
"deployment_environment_name": "lab",
|
||||
"detected_level": "info",
|
||||
"flags": "1",
|
||||
"observed_timestamp": "1794380182158663493",
|
||||
"scope_name": "messenger",
|
||||
"service_instance_id": "e6be289d2413",
|
||||
"service_name": "messenger-api",
|
||||
"service_version": "lab6",
|
||||
"severity_number": "9",
|
||||
"span_id": "3899f41081f472da",
|
||||
"trace_id": "3c112fa1787d40898e457423046b2e97"
|
||||
},
|
||||
"values": [
|
||||
[
|
||||
"1794380182158661106",
|
||||
"{\"attempt\":4,\"event\":\"job.published\",\"job_type\":\"attachment.process.v1\",\"service.name\":\"messenger-api\",\"severity\":\"INFO\",\"span_id\":\"3899f41081f472da\",\"timestamp\":\"2026-11-11T06:56:22.158638627Z\",\"trace_id\":\"3c112fa1787d40898e457423046b2e97\"}"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"stream": {
|
||||
"deployment_environment_name": "lab",
|
||||
"detected_level": "info",
|
||||
"flags": "1",
|
||||
"observed_timestamp": "1794380173660299027",
|
||||
"scope_name": "messenger",
|
||||
"service_instance_id": "e2edd33d8b58",
|
||||
"service_name": "messenger-worker",
|
||||
"service_version": "lab6",
|
||||
"severity_number": "9",
|
||||
"span_id": "4fdca42f0ece4b9b",
|
||||
"trace_id": "3c112fa1787d40898e457423046b2e97"
|
||||
},
|
||||
"values": [
|
||||
[
|
||||
"1794380173660289945",
|
||||
"{\"attempt\":3,\"event\":\"job.completed\",\"job_type\":\"attachment.process.v1\",\"outcome\":\"storage_unavailable\",\"service.name\":\"messenger-worker\",\"severity\":\"INFO\",\"span_id\":\"4fdca42f0ece4b9b\",\"timestamp\":\"2026-11-11T06:56:13.660190955Z\",\"trace_id\":\"3c112fa1787d40898e457423046b2e97\"}"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"stream": {
|
||||
"deployment_environment_name": "lab",
|
||||
"detected_level": "info",
|
||||
"flags": "1",
|
||||
"observed_timestamp": "1794380173552991633",
|
||||
"scope_name": "messenger",
|
||||
"service_instance_id": "c7b5ac648af7",
|
||||
"service_name": "messenger-api",
|
||||
"service_version": "lab6",
|
||||
"severity_number": "9",
|
||||
"span_id": "315d1330b194b738",
|
||||
"trace_id": "3c112fa1787d40898e457423046b2e97"
|
||||
},
|
||||
"values": [
|
||||
[
|
||||
"1794380173552988008",
|
||||
"{\"attempt\":3,\"event\":\"job.published\",\"job_type\":\"attachment.process.v1\",\"service.name\":\"messenger-api\",\"severity\":\"INFO\",\"span_id\":\"315d1330b194b738\",\"timestamp\":\"2026-11-11T06:56:13.552942013Z\",\"trace_id\":\"3c112fa1787d40898e457423046b2e97\"}"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"stream": {
|
||||
"deployment_environment_name": "lab",
|
||||
"detected_level": "info",
|
||||
"flags": "1",
|
||||
"observed_timestamp": "1794380169154868452",
|
||||
"scope_name": "messenger",
|
||||
"service_instance_id": "e2edd33d8b58",
|
||||
"service_name": "messenger-worker",
|
||||
"service_version": "lab6",
|
||||
"severity_number": "9",
|
||||
"span_id": "625b78e11c90b490",
|
||||
"trace_id": "3c112fa1787d40898e457423046b2e97"
|
||||
},
|
||||
"values": [
|
||||
[
|
||||
"1794380169154854245",
|
||||
"{\"attempt\":2,\"event\":\"job.completed\",\"job_type\":\"attachment.process.v1\",\"outcome\":\"storage_unavailable\",\"service.name\":\"messenger-worker\",\"severity\":\"INFO\",\"span_id\":\"625b78e11c90b490\",\"timestamp\":\"2026-11-11T06:56:09.154780337Z\",\"trace_id\":\"3c112fa1787d40898e457423046b2e97\"}"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"stream": {
|
||||
"deployment_environment_name": "lab",
|
||||
"detected_level": "info",
|
||||
"flags": "1",
|
||||
"observed_timestamp": "1794380169082259575",
|
||||
"scope_name": "messenger",
|
||||
"service_instance_id": "e6be289d2413",
|
||||
"service_name": "messenger-api",
|
||||
"service_version": "lab6",
|
||||
"severity_number": "9",
|
||||
"span_id": "07283b45d91f7178",
|
||||
"trace_id": "3c112fa1787d40898e457423046b2e97"
|
||||
},
|
||||
"values": [
|
||||
[
|
||||
"1794380169082247785",
|
||||
"{\"attempt\":2,\"event\":\"job.published\",\"job_type\":\"attachment.process.v1\",\"service.name\":\"messenger-api\",\"severity\":\"INFO\",\"span_id\":\"07283b45d91f7178\",\"timestamp\":\"2026-11-11T06:56:09.082187541Z\",\"trace_id\":\"3c112fa1787d40898e457423046b2e97\"}"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"stream": {
|
||||
"deployment_environment_name": "lab",
|
||||
"detected_level": "info",
|
||||
"flags": "1",
|
||||
"observed_timestamp": "1794380166805494596",
|
||||
"scope_name": "messenger",
|
||||
"service_instance_id": "e2edd33d8b58",
|
||||
"service_name": "messenger-worker",
|
||||
"service_version": "lab6",
|
||||
"severity_number": "9",
|
||||
"span_id": "59ca1b39745a3bd0",
|
||||
"trace_id": "3c112fa1787d40898e457423046b2e97"
|
||||
},
|
||||
"values": [
|
||||
[
|
||||
"1794380166805492471",
|
||||
"{\"attempt\":1,\"event\":\"job.completed\",\"job_type\":\"attachment.process.v1\",\"outcome\":\"storage_unavailable\",\"service.name\":\"messenger-worker\",\"severity\":\"INFO\",\"span_id\":\"59ca1b39745a3bd0\",\"timestamp\":\"2026-11-11T06:56:06.80541598Z\",\"trace_id\":\"3c112fa1787d40898e457423046b2e97\"}"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"stream": {
|
||||
"deployment_environment_name": "lab",
|
||||
"detected_level": "info",
|
||||
"flags": "1",
|
||||
"observed_timestamp": "1794380135473315188",
|
||||
"scope_name": "messenger",
|
||||
"service_instance_id": "e6be289d2413",
|
||||
"service_name": "messenger-api",
|
||||
"service_version": "lab6",
|
||||
"severity_number": "9",
|
||||
"span_id": "fe33cab1b1482745",
|
||||
"trace_id": "3c112fa1787d40898e457423046b2e97"
|
||||
},
|
||||
"values": [
|
||||
[
|
||||
"1794380135473314104",
|
||||
"{\"attempt\":1,\"event\":\"job.published\",\"job_type\":\"attachment.process.v1\",\"service.name\":\"messenger-api\",\"severity\":\"INFO\",\"span_id\":\"fe33cab1b1482745\",\"timestamp\":\"2026-11-11T06:55:35.473299437Z\",\"trace_id\":\"3c112fa1787d40898e457423046b2e97\"}"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"stream": {
|
||||
"deployment_environment_name": "lab",
|
||||
"detected_level": "info",
|
||||
"flags": "1",
|
||||
"observed_timestamp": "1794380135368996615",
|
||||
"scope_name": "messenger",
|
||||
"service_instance_id": "c7b5ac648af7",
|
||||
"service_name": "messenger-api",
|
||||
"service_version": "lab6",
|
||||
"severity_number": "9",
|
||||
"span_id": "26a9ac28885c10eb",
|
||||
"trace_id": "3c112fa1787d40898e457423046b2e97"
|
||||
},
|
||||
"values": [
|
||||
[
|
||||
"1794380135368994073",
|
||||
"{\"duration_seconds\":0.01217951,\"event\":\"http.request\",\"method\":\"POST\",\"request_id\":\"abd64a3a-9e50-4f65-8eba-5359554edcb6\",\"route\":\"/api/v1/chats/{chat_id}/attachments\",\"service.name\":\"messenger-api\",\"severity\":\"INFO\",\"span_id\":\"26a9ac28885c10eb\",\"status\":202,\"timestamp\":\"2026-11-11T06:55:35.368902734Z\",\"trace_id\":\"3c112fa1787d40898e457423046b2e97\"}"
|
||||
]
|
||||
]
|
||||
}
|
||||
],
|
||||
"stats": {
|
||||
"summary": {
|
||||
"bytesProcessedPerSecond": 27486554,
|
||||
"linesProcessedPerSecond": 56638,
|
||||
"totalBytesProcessed": 1721836,
|
||||
"totalLinesProcessed": 3548,
|
||||
"execTime": 0.062643,
|
||||
"queueTime": 0.000637,
|
||||
"subqueries": 0,
|
||||
"totalEntriesReturned": 9,
|
||||
"splits": 2,
|
||||
"shards": 2,
|
||||
"totalPostFilterLines": 9,
|
||||
"totalStructuredMetadataBytesProcessed": 511258
|
||||
},
|
||||
"querier": {
|
||||
"store": {
|
||||
"totalChunksRef": 0,
|
||||
"totalChunksDownloaded": 0,
|
||||
"chunksDownloadTime": 0,
|
||||
"queryReferencedStructuredMetadata": false,
|
||||
"chunk": {
|
||||
"headChunkBytes": 0,
|
||||
"headChunkLines": 0,
|
||||
"decompressedBytes": 0,
|
||||
"decompressedLines": 0,
|
||||
"compressedBytes": 0,
|
||||
"totalDuplicates": 0,
|
||||
"postFilterLines": 0,
|
||||
"headChunkStructuredMetadataBytes": 0,
|
||||
"decompressedStructuredMetadataBytes": 0
|
||||
},
|
||||
"chunkRefsFetchTime": 0,
|
||||
"congestionControlLatency": 0,
|
||||
"pipelineWrapperFilteredLines": 0
|
||||
}
|
||||
},
|
||||
"ingester": {
|
||||
"totalReached": 2,
|
||||
"totalChunksMatched": 3,
|
||||
"totalBatches": 3,
|
||||
"totalLinesSent": 9,
|
||||
"store": {
|
||||
"totalChunksRef": 0,
|
||||
"totalChunksDownloaded": 0,
|
||||
"chunksDownloadTime": 0,
|
||||
"queryReferencedStructuredMetadata": true,
|
||||
"chunk": {
|
||||
"headChunkBytes": 334028,
|
||||
"headChunkLines": 867,
|
||||
"decompressedBytes": 1387808,
|
||||
"decompressedLines": 2681,
|
||||
"compressedBytes": 243276,
|
||||
"totalDuplicates": 0,
|
||||
"postFilterLines": 9,
|
||||
"headChunkStructuredMetadataBytes": 55488,
|
||||
"decompressedStructuredMetadataBytes": 455770
|
||||
},
|
||||
"chunkRefsFetchTime": 497540,
|
||||
"congestionControlLatency": 0,
|
||||
"pipelineWrapperFilteredLines": 0
|
||||
}
|
||||
},
|
||||
"cache": {
|
||||
"chunk": {
|
||||
"entriesFound": 0,
|
||||
"entriesRequested": 0,
|
||||
"entriesStored": 0,
|
||||
"bytesReceived": 0,
|
||||
"bytesSent": 0,
|
||||
"requests": 0,
|
||||
"downloadTime": 0,
|
||||
"queryLengthServed": 0
|
||||
},
|
||||
"index": {
|
||||
"entriesFound": 0,
|
||||
"entriesRequested": 0,
|
||||
"entriesStored": 0,
|
||||
"bytesReceived": 0,
|
||||
"bytesSent": 0,
|
||||
"requests": 0,
|
||||
"downloadTime": 0,
|
||||
"queryLengthServed": 0
|
||||
},
|
||||
"result": {
|
||||
"entriesFound": 0,
|
||||
"entriesRequested": 0,
|
||||
"entriesStored": 0,
|
||||
"bytesReceived": 0,
|
||||
"bytesSent": 0,
|
||||
"requests": 0,
|
||||
"downloadTime": 0,
|
||||
"queryLengthServed": 0
|
||||
},
|
||||
"statsResult": {
|
||||
"entriesFound": 0,
|
||||
"entriesRequested": 1,
|
||||
"entriesStored": 1,
|
||||
"bytesReceived": 0,
|
||||
"bytesSent": 0,
|
||||
"requests": 2,
|
||||
"downloadTime": 2583823,
|
||||
"queryLengthServed": 0
|
||||
},
|
||||
"volumeResult": {
|
||||
"entriesFound": 0,
|
||||
"entriesRequested": 0,
|
||||
"entriesStored": 0,
|
||||
"bytesReceived": 0,
|
||||
"bytesSent": 0,
|
||||
"requests": 0,
|
||||
"downloadTime": 0,
|
||||
"queryLengthServed": 0
|
||||
},
|
||||
"seriesResult": {
|
||||
"entriesFound": 0,
|
||||
"entriesRequested": 0,
|
||||
"entriesStored": 0,
|
||||
"bytesReceived": 0,
|
||||
"bytesSent": 0,
|
||||
"requests": 0,
|
||||
"downloadTime": 0,
|
||||
"queryLengthServed": 0
|
||||
},
|
||||
"labelResult": {
|
||||
"entriesFound": 0,
|
||||
"entriesRequested": 0,
|
||||
"entriesStored": 0,
|
||||
"bytesReceived": 0,
|
||||
"bytesSent": 0,
|
||||
"requests": 0,
|
||||
"downloadTime": 0,
|
||||
"queryLengthServed": 0
|
||||
},
|
||||
"instantMetricResult": {
|
||||
"entriesFound": 0,
|
||||
"entriesRequested": 0,
|
||||
"entriesStored": 0,
|
||||
"bytesReceived": 0,
|
||||
"bytesSent": 0,
|
||||
"requests": 0,
|
||||
"downloadTime": 0,
|
||||
"queryLengthServed": 0
|
||||
}
|
||||
},
|
||||
"index": {
|
||||
"totalChunks": 0,
|
||||
"postFilterChunks": 0,
|
||||
"shardsDuration": 0,
|
||||
"usedBloomFilters": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
{
|
||||
"status": "success",
|
||||
"data": {
|
||||
"resultType": "streams",
|
||||
"result": [
|
||||
{
|
||||
"stream": {
|
||||
"deployment_environment_name": "lab",
|
||||
"detected_level": "info",
|
||||
"flags": "1",
|
||||
"observed_timestamp": "1794380221967106280",
|
||||
"scope_name": "messenger",
|
||||
"service_instance_id": "c7b5ac648af7",
|
||||
"service_name": "messenger-api",
|
||||
"service_version": "lab6",
|
||||
"severity_number": "9",
|
||||
"span_id": "0180e630b41605b3",
|
||||
"trace_id": "dbc9b2dc91404a1fa7fae889b013bb34"
|
||||
},
|
||||
"values": [
|
||||
[
|
||||
"1794380221967096071",
|
||||
"{\"duration_seconds\":2.008002544,\"event\":\"http.request\",\"method\":\"POST\",\"request_id\":\"403a5ef3-252f-496f-958c-272b032071e8\",\"route\":\"/api/v1/chats/{chat_id}/messages\",\"service.name\":\"messenger-api\",\"severity\":\"INFO\",\"span_id\":\"0180e630b41605b3\",\"status\":503,\"timestamp\":\"2026-11-11T06:57:01.966887521Z\",\"trace_id\":\"dbc9b2dc91404a1fa7fae889b013bb34\"}"
|
||||
]
|
||||
]
|
||||
}
|
||||
],
|
||||
"stats": {
|
||||
"summary": {
|
||||
"bytesProcessedPerSecond": 86774690,
|
||||
"linesProcessedPerSecond": 178807,
|
||||
"totalBytesProcessed": 1721836,
|
||||
"totalLinesProcessed": 3548,
|
||||
"execTime": 0.019843,
|
||||
"queueTime": 0.000248,
|
||||
"subqueries": 0,
|
||||
"totalEntriesReturned": 1,
|
||||
"splits": 2,
|
||||
"shards": 2,
|
||||
"totalPostFilterLines": 1,
|
||||
"totalStructuredMetadataBytesProcessed": 511258
|
||||
},
|
||||
"querier": {
|
||||
"store": {
|
||||
"totalChunksRef": 0,
|
||||
"totalChunksDownloaded": 0,
|
||||
"chunksDownloadTime": 0,
|
||||
"queryReferencedStructuredMetadata": false,
|
||||
"chunk": {
|
||||
"headChunkBytes": 0,
|
||||
"headChunkLines": 0,
|
||||
"decompressedBytes": 0,
|
||||
"decompressedLines": 0,
|
||||
"compressedBytes": 0,
|
||||
"totalDuplicates": 0,
|
||||
"postFilterLines": 0,
|
||||
"headChunkStructuredMetadataBytes": 0,
|
||||
"decompressedStructuredMetadataBytes": 0
|
||||
},
|
||||
"chunkRefsFetchTime": 0,
|
||||
"congestionControlLatency": 0,
|
||||
"pipelineWrapperFilteredLines": 0
|
||||
}
|
||||
},
|
||||
"ingester": {
|
||||
"totalReached": 2,
|
||||
"totalChunksMatched": 3,
|
||||
"totalBatches": 3,
|
||||
"totalLinesSent": 1,
|
||||
"store": {
|
||||
"totalChunksRef": 0,
|
||||
"totalChunksDownloaded": 0,
|
||||
"chunksDownloadTime": 0,
|
||||
"queryReferencedStructuredMetadata": true,
|
||||
"chunk": {
|
||||
"headChunkBytes": 334028,
|
||||
"headChunkLines": 867,
|
||||
"decompressedBytes": 1387808,
|
||||
"decompressedLines": 2681,
|
||||
"compressedBytes": 243276,
|
||||
"totalDuplicates": 0,
|
||||
"postFilterLines": 1,
|
||||
"headChunkStructuredMetadataBytes": 55488,
|
||||
"decompressedStructuredMetadataBytes": 455770
|
||||
},
|
||||
"chunkRefsFetchTime": 231355,
|
||||
"congestionControlLatency": 0,
|
||||
"pipelineWrapperFilteredLines": 0
|
||||
}
|
||||
},
|
||||
"cache": {
|
||||
"chunk": {
|
||||
"entriesFound": 0,
|
||||
"entriesRequested": 0,
|
||||
"entriesStored": 0,
|
||||
"bytesReceived": 0,
|
||||
"bytesSent": 0,
|
||||
"requests": 0,
|
||||
"downloadTime": 0,
|
||||
"queryLengthServed": 0
|
||||
},
|
||||
"index": {
|
||||
"entriesFound": 0,
|
||||
"entriesRequested": 0,
|
||||
"entriesStored": 0,
|
||||
"bytesReceived": 0,
|
||||
"bytesSent": 0,
|
||||
"requests": 0,
|
||||
"downloadTime": 0,
|
||||
"queryLengthServed": 0
|
||||
},
|
||||
"result": {
|
||||
"entriesFound": 0,
|
||||
"entriesRequested": 0,
|
||||
"entriesStored": 0,
|
||||
"bytesReceived": 0,
|
||||
"bytesSent": 0,
|
||||
"requests": 0,
|
||||
"downloadTime": 0,
|
||||
"queryLengthServed": 0
|
||||
},
|
||||
"statsResult": {
|
||||
"entriesFound": 1,
|
||||
"entriesRequested": 1,
|
||||
"entriesStored": 0,
|
||||
"bytesReceived": 261,
|
||||
"bytesSent": 0,
|
||||
"requests": 1,
|
||||
"downloadTime": 44288,
|
||||
"queryLengthServed": 116000000000
|
||||
},
|
||||
"volumeResult": {
|
||||
"entriesFound": 0,
|
||||
"entriesRequested": 0,
|
||||
"entriesStored": 0,
|
||||
"bytesReceived": 0,
|
||||
"bytesSent": 0,
|
||||
"requests": 0,
|
||||
"downloadTime": 0,
|
||||
"queryLengthServed": 0
|
||||
},
|
||||
"seriesResult": {
|
||||
"entriesFound": 0,
|
||||
"entriesRequested": 0,
|
||||
"entriesStored": 0,
|
||||
"bytesReceived": 0,
|
||||
"bytesSent": 0,
|
||||
"requests": 0,
|
||||
"downloadTime": 0,
|
||||
"queryLengthServed": 0
|
||||
},
|
||||
"labelResult": {
|
||||
"entriesFound": 0,
|
||||
"entriesRequested": 0,
|
||||
"entriesStored": 0,
|
||||
"bytesReceived": 0,
|
||||
"bytesSent": 0,
|
||||
"requests": 0,
|
||||
"downloadTime": 0,
|
||||
"queryLengthServed": 0
|
||||
},
|
||||
"instantMetricResult": {
|
||||
"entriesFound": 0,
|
||||
"entriesRequested": 0,
|
||||
"entriesStored": 0,
|
||||
"bytesReceived": 0,
|
||||
"bytesSent": 0,
|
||||
"requests": 0,
|
||||
"downloadTime": 0,
|
||||
"queryLengthServed": 0
|
||||
}
|
||||
},
|
||||
"index": {
|
||||
"totalChunks": 0,
|
||||
"postFilterChunks": 0,
|
||||
"shardsDuration": 0,
|
||||
"usedBloomFilters": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,239 @@
|
||||
{
|
||||
"batches": [
|
||||
{
|
||||
"resource": {
|
||||
"attributes": [
|
||||
{
|
||||
"key": "deployment.environment.name",
|
||||
"value": {
|
||||
"stringValue": "lab"
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "service.instance.id",
|
||||
"value": {
|
||||
"stringValue": "c7b5ac648af7"
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "service.version",
|
||||
"value": {
|
||||
"stringValue": "lab6"
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "service.name",
|
||||
"value": {
|
||||
"stringValue": "messenger-api"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"scopeSpans": [
|
||||
{
|
||||
"scope": {
|
||||
"name": "messenger"
|
||||
},
|
||||
"spans": [
|
||||
{
|
||||
"traceId": "28my3JFASh+n+uiJsBO7NA==",
|
||||
"spanId": "EcXZvs2zSiA=",
|
||||
"parentSpanId": "AYDmMLQWBbM=",
|
||||
"name": "postgresql SELECT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"startTimeUnixNano": "1794380219960223589",
|
||||
"endTimeUnixNano": "1794380219960724417",
|
||||
"attributes": [
|
||||
{
|
||||
"key": "db.system.name",
|
||||
"value": {
|
||||
"stringValue": "postgresql"
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "db.operation.name",
|
||||
"value": {
|
||||
"stringValue": "SELECT"
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": {
|
||||
"code": "STATUS_CODE_OK"
|
||||
}
|
||||
},
|
||||
{
|
||||
"traceId": "28my3JFASh+n+uiJsBO7NA==",
|
||||
"spanId": "gkE63CJbPbQ=",
|
||||
"parentSpanId": "AYDmMLQWBbM=",
|
||||
"name": "postgresql SELECT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"startTimeUnixNano": "1794380219960746208",
|
||||
"endTimeUnixNano": "1794380219961817030",
|
||||
"attributes": [
|
||||
{
|
||||
"key": "db.system.name",
|
||||
"value": {
|
||||
"stringValue": "postgresql"
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "db.operation.name",
|
||||
"value": {
|
||||
"stringValue": "SELECT"
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": {
|
||||
"code": "STATUS_CODE_OK"
|
||||
}
|
||||
},
|
||||
{
|
||||
"traceId": "28my3JFASh+n+uiJsBO7NA==",
|
||||
"spanId": "ep+Ye6udB30=",
|
||||
"parentSpanId": "AYDmMLQWBbM=",
|
||||
"name": "postgresql SELECT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"startTimeUnixNano": "1794380219961950029",
|
||||
"endTimeUnixNano": "1794380219962743021",
|
||||
"attributes": [
|
||||
{
|
||||
"key": "db.system.name",
|
||||
"value": {
|
||||
"stringValue": "postgresql"
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "db.operation.name",
|
||||
"value": {
|
||||
"stringValue": "SELECT"
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": {
|
||||
"code": "STATUS_CODE_OK"
|
||||
}
|
||||
},
|
||||
{
|
||||
"traceId": "28my3JFASh+n+uiJsBO7NA==",
|
||||
"spanId": "TxWSichX9ZA=",
|
||||
"parentSpanId": "AYDmMLQWBbM=",
|
||||
"name": "postgresql BEGIN",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"startTimeUnixNano": "1794380219962766813",
|
||||
"endTimeUnixNano": "1794380219962922353",
|
||||
"attributes": [
|
||||
{
|
||||
"key": "db.system.name",
|
||||
"value": {
|
||||
"stringValue": "postgresql"
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "db.operation.name",
|
||||
"value": {
|
||||
"stringValue": "BEGIN"
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": {
|
||||
"code": "STATUS_CODE_OK"
|
||||
}
|
||||
},
|
||||
{
|
||||
"traceId": "28my3JFASh+n+uiJsBO7NA==",
|
||||
"spanId": "m/ApFyKYZ0k=",
|
||||
"parentSpanId": "AYDmMLQWBbM=",
|
||||
"name": "postgresql SELECT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"startTimeUnixNano": "1794380219962928019",
|
||||
"endTimeUnixNano": "1794380219963135225",
|
||||
"attributes": [
|
||||
{
|
||||
"key": "db.system.name",
|
||||
"value": {
|
||||
"stringValue": "postgresql"
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "db.operation.name",
|
||||
"value": {
|
||||
"stringValue": "SELECT"
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": {
|
||||
"code": "STATUS_CODE_OK"
|
||||
}
|
||||
},
|
||||
{
|
||||
"traceId": "28my3JFASh+n+uiJsBO7NA==",
|
||||
"spanId": "5sQcL8g048w=",
|
||||
"parentSpanId": "AYDmMLQWBbM=",
|
||||
"name": "postgresql SELECT",
|
||||
"kind": "SPAN_KIND_CLIENT",
|
||||
"startTimeUnixNano": "1794380219963139559",
|
||||
"endTimeUnixNano": "1794380221964078996",
|
||||
"attributes": [
|
||||
{
|
||||
"key": "db.system.name",
|
||||
"value": {
|
||||
"stringValue": "postgresql"
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "db.operation.name",
|
||||
"value": {
|
||||
"stringValue": "SELECT"
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": {
|
||||
"message": "dependency unavailable",
|
||||
"code": "STATUS_CODE_ERROR"
|
||||
}
|
||||
},
|
||||
{
|
||||
"traceId": "28my3JFASh+n+uiJsBO7NA==",
|
||||
"spanId": "AYDmMLQWBbM=",
|
||||
"parentSpanId": "EjRWeJASNFY=",
|
||||
"name": "POST /api/v1/chats/{chat_id}/messages",
|
||||
"kind": "SPAN_KIND_SERVER",
|
||||
"startTimeUnixNano": "1794380219958881186",
|
||||
"endTimeUnixNano": "1794380221967108989",
|
||||
"attributes": [
|
||||
{
|
||||
"key": "method",
|
||||
"value": {
|
||||
"stringValue": "POST"
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "route",
|
||||
"value": {
|
||||
"stringValue": "/api/v1/chats/{chat_id}/messages"
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "status_class",
|
||||
"value": {
|
||||
"stringValue": "5xx"
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "http.response.status_code",
|
||||
"value": {
|
||||
"intValue": "503"
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": {
|
||||
"message": "server error",
|
||||
"code": "STATUS_CODE_ERROR"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
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
|
||||
go.opentelemetry.io/otel v1.38.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.14.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.38.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.38.0
|
||||
go.opentelemetry.io/otel/log v0.14.0
|
||||
go.opentelemetry.io/otel/metric v1.38.0
|
||||
go.opentelemetry.io/otel/sdk v1.38.0
|
||||
go.opentelemetry.io/otel/sdk/log v0.14.0
|
||||
go.opentelemetry.io/otel/sdk/metric v1.38.0
|
||||
go.opentelemetry.io/otel/trace v1.38.0
|
||||
golang.org/x/crypto v0.41.0
|
||||
golang.org/x/sync v0.16.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
|
||||
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/go-logr/logr v1.4.3 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/goccy/go-json v0.10.5 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // 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
|
||||
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.7.1 // indirect
|
||||
golang.org/x/net v0.43.0 // indirect
|
||||
golang.org/x/sys v0.35.0 // indirect
|
||||
golang.org/x/text v0.28.0 // indirect
|
||||
golang.org/x/time v0.11.0 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250825161204-c5933d9347a5 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250825161204-c5933d9347a5 // indirect
|
||||
google.golang.org/grpc v1.75.0 // indirect
|
||||
google.golang.org/protobuf v1.36.8 // indirect
|
||||
)
|
||||
@@ -0,0 +1,143 @@
|
||||
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/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
|
||||
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
|
||||
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/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
|
||||
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
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/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
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/grpc-ecosystem/grpc-gateway/v2 v2.27.2 h1:8Tjv8EJ+pM1xP8mK6egEbD1OgnVTyacbefKhmbLhIhU=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2/go.mod h1:pkJQ2tZHJ0aFOVEEot6oZmaVEZcRme73eIFmhiVuRWs=
|
||||
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.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
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=
|
||||
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
||||
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
|
||||
go.opentelemetry.io/otel v1.38.0 h1:RkfdswUDRimDg0m2Az18RKOsnI8UDzppJAtj01/Ymk8=
|
||||
go.opentelemetry.io/otel v1.38.0/go.mod h1:zcmtmQ1+YmQM9wrNsTGV/q/uyusom3P8RxwExxkZhjM=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.14.0 h1:QQqYw3lkrzwVsoEX0w//EhH/TCnpRdEenKBOOEIMjWc=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.14.0/go.mod h1:gSVQcr17jk2ig4jqJ2DX30IdWH251JcNAecvrqTxH1s=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.38.0 h1:Oe2z/BCg5q7k4iXC3cqJxKYg0ieRiOqF0cecFYdPTwk=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.38.0/go.mod h1:ZQM5lAJpOsKnYagGg/zV2krVqTtaVdYdDkhMoX6Oalg=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0 h1:GqRJVj7UmLjCVyVJ3ZFLdPRmhDUp2zFmQe3RHIOsw24=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0/go.mod h1:ri3aaHSmCTVYu2AWv44YMauwAQc0aqI9gHKIcSbI1pU=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.38.0 h1:aTL7F04bJHUlztTsNGJ2l+6he8c+y/b//eR0jjjemT4=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.38.0/go.mod h1:kldtb7jDTeol0l3ewcmd8SDvx3EmIE7lyvqbasU3QC4=
|
||||
go.opentelemetry.io/otel/log v0.14.0 h1:2rzJ+pOAZ8qmZ3DDHg73NEKzSZkhkGIua9gXtxNGgrM=
|
||||
go.opentelemetry.io/otel/log v0.14.0/go.mod h1:5jRG92fEAgx0SU/vFPxmJvhIuDU9E1SUnEQrMlJpOno=
|
||||
go.opentelemetry.io/otel/metric v1.38.0 h1:Kl6lzIYGAh5M159u9NgiRkmoMKjvbsKtYRwgfrA6WpA=
|
||||
go.opentelemetry.io/otel/metric v1.38.0/go.mod h1:kB5n/QoRM8YwmUahxvI3bO34eVtQf2i4utNVLr9gEmI=
|
||||
go.opentelemetry.io/otel/sdk v1.38.0 h1:l48sr5YbNf2hpCUj/FoGhW9yDkl+Ma+LrVl8qaM5b+E=
|
||||
go.opentelemetry.io/otel/sdk v1.38.0/go.mod h1:ghmNdGlVemJI3+ZB5iDEuk4bWA3GkTpW+DOoZMYBVVg=
|
||||
go.opentelemetry.io/otel/sdk/log v0.14.0 h1:JU/U3O7N6fsAXj0+CXz21Czg532dW2V4gG1HE/e8Zrg=
|
||||
go.opentelemetry.io/otel/sdk/log v0.14.0/go.mod h1:imQvII+0ZylXfKU7/wtOND8Hn4OpT3YUoIgqJVksUkM=
|
||||
go.opentelemetry.io/otel/sdk/log/logtest v0.14.0 h1:Ijbtz+JKXl8T2MngiwqBlPaHqc4YCaP/i13Qrow6gAM=
|
||||
go.opentelemetry.io/otel/sdk/log/logtest v0.14.0/go.mod h1:dCU8aEL6q+L9cYTqcVOk8rM9Tp8WdnHOPLiBgp0SGOA=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.38.0 h1:aSH66iL0aZqo//xXzQLYozmWrXxyFkBJ6qT5wthqPoM=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.38.0/go.mod h1:dg9PBnW9XdQ1Hd6ZnRz689CbtrUp0wMMs9iPcgT9EZA=
|
||||
go.opentelemetry.io/otel/trace v1.38.0 h1:Fxk5bKrDZJUH+AMyyIXGcFAPah0oRcT+LuNtJrmcNLE=
|
||||
go.opentelemetry.io/otel/trace v1.38.0/go.mod h1:j1P9ivuFsTceSWe1oY+EeW3sc+Pp42sO++GHkg4wwhs=
|
||||
go.opentelemetry.io/proto/otlp v1.7.1 h1:gTOMpGDb0WTBOP8JaO72iL3auEZhVmAQg4ipjOVAtj4=
|
||||
go.opentelemetry.io/proto/otlp v1.7.1/go.mod h1:b2rVh6rfI/s2pHWNlB7ILJcRALpcNDzKhACevjI+ZnE=
|
||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||
golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4=
|
||||
golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc=
|
||||
golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
|
||||
golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
|
||||
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
|
||||
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
|
||||
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
|
||||
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
|
||||
golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0=
|
||||
golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
|
||||
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
|
||||
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250825161204-c5933d9347a5 h1:BIRfGDEjiHRrk0QKZe3Xv2ieMhtgRGeLcZQ0mIVn4EY=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250825161204-c5933d9347a5/go.mod h1:j3QtIyytwqGr1JUDtYXwtMXWPKsEa5LtzIFN1Wn5WvE=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250825161204-c5933d9347a5 h1:eaY8u2EuxbRv7c3NiGK0/NedzVsCcV6hDuU5qPX5EGE=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250825161204-c5933d9347a5/go.mod h1:M4/wBTSeyLxupu3W3tJtOgB14jILAS/XWPSSa3TAlJc=
|
||||
google.golang.org/grpc v1.75.0 h1:+TW+dqTd2Biwe6KKfhE5JpiYIBWq865PhKGSXiivqt4=
|
||||
google.golang.org/grpc v1.75.0/go.mod h1:JtPAzKiq4v1xcAB2hydNlWI2RnF85XXcV0mhKXr2ecQ=
|
||||
google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc=
|
||||
google.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
|
||||
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=
|
||||
+20
-4
@@ -1,7 +1,23 @@
|
||||
# Инфраструктура студента
|
||||
# Инфраструктура lab6
|
||||
|
||||
Здесь разместите конфигурации выбранных сервисов; основную топологию — в корневом compose.yaml/stack.yaml. `compose.example.yaml` — только worksheet ролей и намеренно не запускается. `contracts/infrastructure.json` задаёт минимальные роли, не готовые образы/пароли.
|
||||
Полная топология находится в [compose.yaml](../compose.yaml). Запуск: `make up` из корня.
|
||||
Файл compose.example.yaml сохранён как исходный worksheet задания и не используется при запуске.
|
||||
|
||||
В REPORT.md сопоставьте роль → service name → версия/digest → health/readiness → volume → сеть/порт → способ передачи credentials. Приведите bootstrap (schema, bucket, broker topology, а с lab6 provisioning) и безопасное повторение этих команд.
|
||||
| Конфигурация | Назначение |
|
||||
| --- | --- |
|
||||
| haproxy.cfg | Балансировка двух API-реплик, DNS Docker, readiness каждой реплики |
|
||||
| redis.conf | Сессии, Redis Streams и AOF |
|
||||
| migrate.sh | Goose migrations с credentials из файла секрета |
|
||||
| minio-entrypoint.sh | Запуск MinIO с root credentials из файлов |
|
||||
| s3-bootstrap.sh, s3-policy.json | Приватный bucket и пользователь приложения с ограниченной policy |
|
||||
| otel/collector.yaml | Приём OTLP, memory limiter, batch, экспорт трёх сигналов |
|
||||
| prometheus/ | Scrape приложения/Collector/backend и локальные alert rules |
|
||||
| loki.yaml | OTLP logs, filesystem storage, retention |
|
||||
| tempo.yaml | OTLP traces, WAL/blocks, retention |
|
||||
| grafana/provisioning/ | Автоматическая регистрация трёх datasources и dashboard provider |
|
||||
| grafana/dashboards/messenger.json | Импортируемый dashboard с 15 панелями |
|
||||
|
||||
Приложение строится из исходников. Не используйте заранее существующий образ преподавательского сервера вместо своей реализации. Restart hook перезапускает все соответствующие stores с volumes; failover hook останавливает только заданную API-реплику.
|
||||
Named volumes сохраняют PostgreSQL, Redis, S3 и историю всех telemetry backend/Grafana.
|
||||
Bootstrap идемпотентен. Credentials создаёт scripts/bootstrap.sh; они не хранятся в Git.
|
||||
Сопоставление версий, readiness, volumes, портов и лимитов: [REPORT.md](../REPORT.md).
|
||||
Диагностика по сохранённым сигналам: [RUNBOOK.md](../RUNBOOK.md).
|
||||
|
||||
@@ -0,0 +1,519 @@
|
||||
{
|
||||
"uid": "messenger",
|
||||
"title": "Messenger observability",
|
||||
"schemaVersion": 41,
|
||||
"version": 1,
|
||||
"refresh": "5s",
|
||||
"time": {
|
||||
"from": "now-15m",
|
||||
"to": "now"
|
||||
},
|
||||
"panels": [
|
||||
{
|
||||
"id": 1,
|
||||
"title": "API RPS (business routes)",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"expr": "sum(rate(messenger_http_requests_total[$__rate_interval])) by (route)",
|
||||
"legendFormat": "{{service_name}} {{outcome}} {{route}}",
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "reqps"
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"title": "API 5xx / all business requests",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 0,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"expr": "(sum(rate(messenger_http_requests_total{status_class=\"5xx\"}[$__rate_interval])) or vector(0)) / clamp_min(sum(rate(messenger_http_requests_total[$__rate_interval])),0.001)",
|
||||
"legendFormat": "{{service_name}} {{outcome}} {{route}}",
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "percentunit"
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"title": "API p50 / p95 / p99 (all replicas, histogram)",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 8,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"expr": "histogram_quantile(0.5,sum(rate(messenger_http_duration_seconds_bucket[$__rate_interval])) by(le))",
|
||||
"legendFormat": "p50",
|
||||
"refId": "A"
|
||||
},
|
||||
{
|
||||
"expr": "histogram_quantile(0.95,sum(rate(messenger_http_duration_seconds_bucket[$__rate_interval])) by(le))",
|
||||
"legendFormat": "p95",
|
||||
"refId": "B"
|
||||
},
|
||||
{
|
||||
"expr": "histogram_quantile(0.99,sum(rate(messenger_http_duration_seconds_bucket[$__rate_interval])) by(le))",
|
||||
"legendFormat": "p99",
|
||||
"refId": "C"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "s"
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"title": "Worker job outcomes per second",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 8,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"expr": "sum(rate(messenger_jobs_total[$__rate_interval])) by(outcome)",
|
||||
"legendFormat": "{{service_name}} {{outcome}} {{route}}",
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "ops"
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"title": "Worker job p95 duration",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 16,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"expr": "histogram_quantile(0.95,sum(rate(messenger_job_duration_seconds_bucket[$__rate_interval])) by(le,outcome))",
|
||||
"legendFormat": "{{service_name}} {{outcome}} {{route}}",
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "s"
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"title": "Time from durable acceptance to ready p95",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 16,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"expr": "histogram_quantile(0.95,sum(rate(messenger_attachment_ready_seconds_bucket[$__rate_interval])) by(le))",
|
||||
"legendFormat": "{{service_name}} {{outcome}} {{route}}",
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "s"
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"title": "Authoritative queue depth (max across observers)",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 24,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"expr": "max(messenger_queue_depth)",
|
||||
"legendFormat": "{{service_name}} {{outcome}} {{route}}",
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short"
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"title": "Oldest unfinished job age",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 24,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"expr": "max(messenger_queue_oldest_age_seconds)",
|
||||
"legendFormat": "{{service_name}} {{outcome}} {{route}}",
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "s"
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"title": "DB pool acquired / acquiring / max",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 32,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"expr": "messenger_db_pool_used",
|
||||
"legendFormat": "used {{service_name}} {{service_instance_id}}",
|
||||
"refId": "A"
|
||||
},
|
||||
{
|
||||
"expr": "messenger_db_pool_waiting",
|
||||
"legendFormat": "waiting {{service_name}} {{service_instance_id}}",
|
||||
"refId": "B"
|
||||
},
|
||||
{
|
||||
"expr": "messenger_db_pool_max",
|
||||
"legendFormat": "max {{service_name}} {{service_instance_id}}",
|
||||
"refId": "C"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short"
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"title": "Worker saturation busy / capacity",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 32,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"expr": "sum(messenger_worker_busy{service_name=\"messenger-worker\"}) / clamp_min(sum(messenger_worker_capacity{service_name=\"messenger-worker\"}),1)",
|
||||
"legendFormat": "{{service_name}} {{outcome}} {{route}}",
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "percentunit"
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 11,
|
||||
"title": "Go runtime reserved memory (MemStats.Sys)",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 40,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"expr": "messenger_process_memory_bytes",
|
||||
"legendFormat": "{{service_name}} {{outcome}} {{route}}",
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "bytes"
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 12,
|
||||
"title": "Process CPU seconds / second",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 40,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"expr": "rate(messenger_process_cpu_seconds_total[$__rate_interval])",
|
||||
"legendFormat": "{{service_name}} {{outcome}} {{route}}",
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "percentunit"
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 13,
|
||||
"title": "SDK failed telemetry export operations",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 48,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"expr": "messenger_telemetry_export_errors",
|
||||
"legendFormat": "{{service_name}} {{outcome}} {{route}}",
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short"
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 14,
|
||||
"title": "Exporter failed spans (attempts, not unique loss)",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 48,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"expr": "sum(otelcol_exporter_send_failed_spans_total) by (exporter)",
|
||||
"legendFormat": "{{service_name}} {{outcome}} {{route}}",
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short"
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 99,
|
||||
"title": "API and worker structured logs; trace ID opens Tempo",
|
||||
"type": "logs",
|
||||
"datasource": {
|
||||
"type": "loki",
|
||||
"uid": "loki"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 56,
|
||||
"w": 24,
|
||||
"h": 10
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"expr": "{service_name=~\"messenger-api|messenger-worker\"} | json",
|
||||
"refId": "A"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"annotations": {
|
||||
"list": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
apiVersion: 1
|
||||
providers:
|
||||
- name: Messenger
|
||||
type: file
|
||||
options: {path: /var/lib/grafana/dashboards}
|
||||
updateIntervalSeconds: 10
|
||||
@@ -0,0 +1,29 @@
|
||||
apiVersion: 1
|
||||
datasources:
|
||||
- name: Prometheus
|
||||
uid: prometheus
|
||||
type: prometheus
|
||||
access: proxy
|
||||
url: http://prometheus:9090
|
||||
isDefault: true
|
||||
- name: Loki
|
||||
uid: loki
|
||||
type: loki
|
||||
access: proxy
|
||||
url: http://loki:3100
|
||||
jsonData:
|
||||
derivedFields:
|
||||
- name: TraceID
|
||||
matcherRegex: '"trace_id":"([a-f0-9]{32})"'
|
||||
datasourceUid: tempo
|
||||
url: '$${__value.raw}'
|
||||
- name: Tempo
|
||||
uid: tempo
|
||||
type: tempo
|
||||
access: proxy
|
||||
url: http://tempo:3200
|
||||
jsonData:
|
||||
tracesToLogsV2:
|
||||
datasourceUid: loki
|
||||
filterByTraceID: true
|
||||
serviceMap: {datasourceUid: prometheus}
|
||||
@@ -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 api:8080 check resolvers docker init-addr none
|
||||
@@ -0,0 +1,27 @@
|
||||
auth_enabled: false
|
||||
server: {http_listen_port: 3100, grpc_listen_port: 9096}
|
||||
common:
|
||||
instance_addr: 127.0.0.1
|
||||
path_prefix: /loki
|
||||
storage:
|
||||
filesystem: {chunks_directory: /loki/chunks, rules_directory: /loki/rules}
|
||||
replication_factor: 1
|
||||
ring:
|
||||
kvstore: {store: inmemory}
|
||||
schema_config:
|
||||
configs:
|
||||
- from: '2024-04-01'
|
||||
store: tsdb
|
||||
object_store: filesystem
|
||||
schema: v13
|
||||
index: {prefix: index_, period: 24h}
|
||||
limits_config:
|
||||
allow_structured_metadata: true
|
||||
retention_period: 168h
|
||||
ingestion_rate_mb: 4
|
||||
ingestion_burst_size_mb: 8
|
||||
compactor:
|
||||
working_directory: /loki/compactor
|
||||
retention_enabled: true
|
||||
delete_request_store: filesystem
|
||||
analytics: {reporting_enabled: false}
|
||||
Executable
+8
@@ -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 "$@"
|
||||
Executable
+5
@@ -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
|
||||
+20
-4
@@ -1,7 +1,23 @@
|
||||
# Конфигурация наблюдаемости — реализовать
|
||||
# OpenTelemetry Collector
|
||||
|
||||
Добавьте `collector.yaml` с OTLP receivers, processors и exporters выбранной версии Collector. Укажите явные bind endpoints, внутренние сети, memory limits/batch и поведение при backpressure по уровню. Сопоставьте все три pipeline с реально развёрнутыми backend.
|
||||
Конфигурация: [collector.yaml](collector.yaml), образ contrib 0.137.0 закреплён в Compose.
|
||||
API и worker используют SDK Go и передают три сигнала по OTLP HTTP/protobuf на collector:4318.
|
||||
GRPC receiver слушает :4317. Оба порта доступны только внутри сети Compose.
|
||||
|
||||
Добавьте конфигурации storage, Grafana provisioning/datasources, provisioning/dashboards и импортируемые dashboard JSON. На 4 — alert rules и runbooks. Пустой dashboard или debug exporter, который только печатает данные в stdout, не заменяют хранилища/доказательства из `contracts/observability.md`.
|
||||
| Pipeline | Processors | Exporter / backend |
|
||||
| --- | --- | --- |
|
||||
| metrics | memory_limiter, batch | Prometheus exporter :8889; Prometheus scrape каждые 5s |
|
||||
| logs | memory_limiter, batch | OTLP HTTP → Loki /otlp |
|
||||
| traces | memory_limiter, batch | OTLP HTTP → Tempo :4318 |
|
||||
|
||||
Не публикуйте OTLP/metrics/административные ports в общую сеть без необходимости. В lab7 реализуйте TLS/mTLS по trust matrix; экспорт Authorization и message bodies запрещён.
|
||||
Memory limiter:128MiB, spike32MiB, check1s. Batch:256, max512, timeout1s.
|
||||
Каждый OTLP exporter имеет queue256,2 consumers, timeout2s и retry максимум 20s.
|
||||
Collector ограничен cgroup192MiB. После исчерпания очереди/таймаутов сигналы могут потеряться.
|
||||
Очереди находятся в RAM и не переживают аварийный restart. Работа приложения не зависит от успешной записи telemetry.
|
||||
Метрики самого Collector доступны внутри сети на :8888 и собираются Prometheus.
|
||||
|
||||
Данные хранят отдельные Prometheus/Loki/Tempo; Collector не заменяет хранилище.
|
||||
Grafana provisioning: ../grafana/provisioning, dashboard: ../grafana/dashboards/messenger.json.
|
||||
Alert rules: ../prometheus/alerts.yaml. Процедуры расследования: ../../RUNBOOK.md.
|
||||
|
||||
Доказательства и ограничения: ../../REPORT.md, ../../INCIDENTS.md, ../../RESEARCH.md.
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
grpc: {endpoint: '0.0.0.0:4317'}
|
||||
http: {endpoint: '0.0.0.0:4318'}
|
||||
processors:
|
||||
memory_limiter:
|
||||
check_interval: 1s
|
||||
limit_mib: 128
|
||||
spike_limit_mib: 32
|
||||
batch:
|
||||
timeout: 1s
|
||||
send_batch_size: 256
|
||||
send_batch_max_size: 512
|
||||
exporters:
|
||||
prometheus:
|
||||
endpoint: 0.0.0.0:8889
|
||||
metric_expiration: 15s
|
||||
resource_to_telemetry_conversion: {enabled: true}
|
||||
otlphttp/tempo:
|
||||
endpoint: http://tempo:4318
|
||||
timeout: 2s
|
||||
sending_queue: {enabled: true, queue_size: 256, num_consumers: 2}
|
||||
retry_on_failure: {enabled: true, initial_interval: 1s, max_interval: 5s, max_elapsed_time: 20s}
|
||||
otlphttp/loki:
|
||||
endpoint: http://loki:3100/otlp
|
||||
timeout: 2s
|
||||
sending_queue: {enabled: true, queue_size: 256, num_consumers: 2}
|
||||
retry_on_failure: {enabled: true, initial_interval: 1s, max_interval: 5s, max_elapsed_time: 20s}
|
||||
service:
|
||||
telemetry:
|
||||
metrics:
|
||||
level: detailed
|
||||
readers:
|
||||
- pull:
|
||||
exporter:
|
||||
prometheus: {host: 0.0.0.0, port: 8888}
|
||||
pipelines:
|
||||
traces: {receivers: [otlp], processors: [memory_limiter, batch], exporters: [otlphttp/tempo]}
|
||||
metrics: {receivers: [otlp], processors: [memory_limiter, batch], exporters: [prometheus]}
|
||||
logs: {receivers: [otlp], processors: [memory_limiter, batch], exporters: [otlphttp/loki]}
|
||||
@@ -0,0 +1,19 @@
|
||||
groups:
|
||||
- name: messenger-slo
|
||||
rules:
|
||||
- alert: APIHighErrorRate
|
||||
expr: sum(rate(messenger_http_requests_total{status_class="5xx"}[1m])) / clamp_min(sum(rate(messenger_http_requests_total[1m])), 0.01) > 0.05
|
||||
for: 5s
|
||||
labels: {severity: warning}
|
||||
annotations:
|
||||
summary: More than 5 percent API server failures over 1 minute
|
||||
runbook_url: http://localhost:13000/d/messenger/messenger-observability
|
||||
description: Excludes health and client 4xx. Inspect PostgreSQL spans and pool; see RUNBOOK.md.
|
||||
- alert: QueueLagGrowing
|
||||
expr: max(messenger_queue_oldest_age_seconds) > 10 and max(messenger_queue_depth) > 0
|
||||
for: 5s
|
||||
labels: {severity: warning}
|
||||
annotations:
|
||||
summary: Oldest unfinished attachment exceeds 10 seconds
|
||||
runbook_url: http://localhost:13000/d/messenger/messenger-observability
|
||||
description: Inspect worker capacity, busy, outcomes and dependency spans; see RUNBOOK.md.
|
||||
@@ -0,0 +1,15 @@
|
||||
global:
|
||||
scrape_interval: 5s
|
||||
evaluation_interval: 5s
|
||||
rule_files: [/etc/prometheus/alerts.yaml]
|
||||
scrape_configs:
|
||||
- job_name: messenger
|
||||
static_configs: [{targets: ['collector:8889']}]
|
||||
- job_name: collector
|
||||
static_configs: [{targets: ['collector:8888']}]
|
||||
- job_name: tempo
|
||||
static_configs: [{targets: ['tempo:3200']}]
|
||||
- job_name: loki
|
||||
static_configs: [{targets: ['loki:3100']}]
|
||||
- job_name: prometheus
|
||||
static_configs: [{targets: ['localhost:9090']}]
|
||||
@@ -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
|
||||
Executable
+11
@@ -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.'
|
||||
@@ -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/*"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
server: {http_listen_port: 3200}
|
||||
distributor:
|
||||
receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
grpc: {endpoint: '0.0.0.0:4317'}
|
||||
http: {endpoint: '0.0.0.0:4318'}
|
||||
ingester:
|
||||
max_block_duration: 1m
|
||||
compactor:
|
||||
compaction: {block_retention: 168h}
|
||||
storage:
|
||||
trace:
|
||||
backend: local
|
||||
wal: {path: /var/tempo/wal}
|
||||
local: {path: /var/tempo/blocks}
|
||||
usage_report: {reporting_enabled: false}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
@@ -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}
|
||||
}
|
||||
@@ -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}
|
||||
}
|
||||
@@ -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"})
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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"})
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package chat
|
||||
|
||||
import (
|
||||
"gitflic.ru/akselbant/mtusi2026lab1-fork/internal/attachment"
|
||||
"gitflic.ru/akselbant/mtusi2026lab1-fork/internal/observability"
|
||||
"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, _ = os.Hostname()
|
||||
}
|
||||
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(observability.Middleware)
|
||||
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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
package attachment
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gitflic.ru/akselbant/mtusi2026lab1-fork/internal/observability"
|
||||
"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()
|
||||
traceparent, tracestate := observability.Inject(ctx)
|
||||
if _, err = tx.Exec(ctx, `INSERT INTO attachment_jobs(id,attachment_id,state,max_attempts,traceparent,tracestate) VALUES($1,$2,'queued',$3,$4,$5)`, job, a.ID, s.Options.MaxAttempts, traceparent, tracestate); 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, "Вариант не найден")
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user