feat: compensate failed uploads and clean stale pending attachments
- upload: delete the stored object when ready fails before COMMIT or the pending row is gone (503 instead of 500); unknown COMMIT outcome keeps it - cleaner service (python -m src.cleaner): stale pending rows older than grace (900 s, must exceed 17 s live-upload bound) under FOR UPDATE SKIP LOCKED, object before row, own S3 user with read/delete only - shared session_scope for API and cleaner; early_stop process name - partial index on pending attachments, CREATE INDEX CONCURRENTLY - s3-bootstrap: cleaner user, policy and checks; make env_setup appends missing template variables to an existing .env - failure checks: cleaner on the failure stand, id-list hook actions, five new and three updated tests; driver upload-consistency - sync upload-consistency deltas into main specs (storage-consistency) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -104,8 +104,8 @@ paths:
|
||||
`get_logger()` — как раз во время импорта настроек, и обработчик застал
|
||||
бы модули полуинициализированными. Запись — одна строка JSON через
|
||||
`os.write` в stdout, затем `os._exit(0)`; ошибка записи выходу не мешает.
|
||||
Поля — как у записей structlog: `event` «Stopped API before startup» и
|
||||
`instance_id` первыми, `module` `startup`, `signal` (`SIGTERM` /
|
||||
Поля — как у записей structlog: `event` «Stopped API before startup»
|
||||
(у уборщика — «Stopped cleaner before startup») и `instance_id` первыми, `module` `startup`, `signal` (`SIGTERM` /
|
||||
`SIGINT`), `level` `info`, `timestamp` ISO 8601 UTC с микросекундами и
|
||||
`Z`. `instance_id` — `APP__INSTANCE_ID` или hostname, то же значение по
|
||||
умолчанию, что `[app] instance_id`. Уровень `info`: остановку запросил
|
||||
@@ -141,12 +141,44 @@ paths:
|
||||
attachment» с `reason` (`type`, `declared_size`, `size`, `content`,
|
||||
`content_mismatch`, `damaged`, `pixels`, `interrupted`), `chat_id` и
|
||||
`filename_length`, `error` «Attachment content is missing» / «…size
|
||||
differs» с `attachment_id` и `object_key`. `MessageService` пишет
|
||||
differs» с `attachment_id` и `object_key`. С change
|
||||
`upload-consistency`: `warning` «Attachment upload left pending» с
|
||||
`attachment_id` и `step` (`put`, `ready`, `commit`), `info` «Deleted
|
||||
attachment object» или `warning` «Attachment object kept for cleaner»
|
||||
(`object_key`, `error_type`) о компенсации, `error` «Pending
|
||||
attachment was removed before ready». `MessageService` пишет
|
||||
`attachments_count` в «Created message» и «Rejected message
|
||||
attachments». Поле `filename` у записей — место вызова в коде
|
||||
(`CallsiteParameterAdder`), а не имя файла вложения.
|
||||
- Stack trace — только в лог, никогда в ответ.
|
||||
|
||||
## Журнал уборщика (с лабы 4)
|
||||
|
||||
Спек `service-logging`, «Журнал уборщика»; design change
|
||||
`upload-consistency`. Тот же `get_logger()`, `instance_id` — hostname
|
||||
контейнера уборщика.
|
||||
|
||||
- `cleaner` (`src/cleaner/main.py`): `info` «Started cleaner»
|
||||
(`interval_seconds`, `pending_grace_seconds`, `batch_size`,
|
||||
`live_upload_bound_seconds`, `once`, адрес и имя базы, размер пула,
|
||||
`s3_host`, `s3_port`, `s3_bucket`), `info` «Stopped cleaner»
|
||||
(`exit_code`), `error` «Cleaner grace period is not longer than live
|
||||
upload bound» (grace, оба срока, граница), `error` «Cleanup pass
|
||||
failed» с traceback. Неверные настройки — запись «Invalid cleaner
|
||||
settings» мимо structlog (`early_stop.write_record`: `loc` и `msg`
|
||||
ошибок, без значений полей), «Stopped cleaner before startup» — как у
|
||||
API.
|
||||
- `attachment_cleanup_service`: `info` «Removed stale attachment»
|
||||
(`attachment_id`, `object_key`, `age_seconds`); итог прохода
|
||||
«Finished cleanup pass» / «Interrupted cleanup pass» (`removed`,
|
||||
`skipped`, `interrupted_by`, `duration_ms`): `warning` при отказе S3
|
||||
или БД, `info`, если что-то убрано или проход остановлен сигналом,
|
||||
иначе `debug` — пустой проход раз в минуту журнал не засоряет.
|
||||
- Причину отказа пишет нижний слой: клиент S3 (`object_storage`) и
|
||||
`session_scope` (`database`, `warning` «Database is unavailable»);
|
||||
сервис только называет `interrupted_by`.
|
||||
- `filename`, ключей и секретов S3, подписей в записях уборщика нет.
|
||||
|
||||
## Где логировать
|
||||
|
||||
| Слой | Логи | Логгер модуля |
|
||||
|
||||
Reference in New Issue
Block a user