Проверять содержимое изображений: байты фильтра PNG и настоящее декодирование JPEG

This commit is contained in:
2026-10-31 04:06:58 +03:00
parent d812d8f8d8
commit d34d0bec79
26 changed files with 1024 additions and 427 deletions
+11 -11
View File
@@ -1,5 +1,5 @@
# Запуск из чистого clone на пустых volumes, публичный smoke
# дата: 2026-10-30T19:58Z, чистый clone
# дата: 2026-10-31T00:55Z, чистый clone
# стенд: Apple M3 Pro, 11 CPU, 18 GB RAM, macOS 26.1, Docker 29.3.0, Compose 5.1.0
$ make env
@@ -9,14 +9,14 @@ $ make env
$ docker compose --env-file .env config --quiet
$ docker compose --env-file .env up -d --build
Image mtusi-messenger:lab4 Built
Image mtusi-messenger-lb:lab4 Built
Image mtusi-messenger-s3:lab4 Built
Image mtusi-messenger:lab4 Built
Image mtusi-messenger:lab4 Built
Image mtusi-messenger:lab4 Built
Image mtusi-messenger-lb:lab4 Built
Network mtusi-messenger-lab4_storage Created
Image mtusi-messenger:lab4 Built
Network mtusi-messenger-lab4_data Created
Network mtusi-messenger-lab4_storage Created
Network mtusi-messenger-lab4_edge Created
Volume mtusi-messenger-lab4_redisdata Created
Volume mtusi-messenger-lab4_s3data Created
@@ -30,13 +30,13 @@ $ docker compose --env-file .env up -d --build
Container mtusi-messenger-lab4-janitor-1 Created
Container mtusi-messenger-lab4-api-2 Created
Container mtusi-messenger-lab4-lb-1 Created
Container mtusi-messenger-lab4-postgres-1 Started
Container mtusi-messenger-lab4-redis-1 Started
Container mtusi-messenger-lab4-s3-1 Started
Container mtusi-messenger-lab4-postgres-1 Healthy
Container mtusi-messenger-lab4-postgres-1 Started
Container mtusi-messenger-lab4-s3-1 Healthy
Container mtusi-messenger-lab4-migrate-1 Started
Container mtusi-messenger-lab4-postgres-1 Healthy
Container mtusi-messenger-lab4-s3-init-1 Started
Container mtusi-messenger-lab4-migrate-1 Started
Container mtusi-messenger-lab4-redis-1 Healthy
Container mtusi-messenger-lab4-migrate-1 Exited
Container mtusi-messenger-lab4-migrate-1 Exited
@@ -60,16 +60,16 @@ migrate mtusi-messenger:lab4 exited Exited (0) 16 seconds ago
postgres postgres:17.11-alpine running Up 22 seconds (healthy) 5432/tcp
redis redis:7.4.11-alpine running Up 22 seconds (healthy) 6379/tcp
s3 mtusi-messenger-s3:lab4 running Up 22 seconds (healthy) 7333/tcp, 8080/tcp, 8333/tcp, 8888/tcp, 9333/tcp, 18080/tcp, 18888/tcp, 19333/tcp
s3-init mtusi-messenger:lab4 exited Exited (0) 5 seconds ago
s3-init mtusi-messenger:lab4 exited Exited (0) 4 seconds ago
$ docker compose --env-file .env logs migrate s3-init
migrate-1 | применена: 0001_init.sql
migrate-1 | применена: 0002_idempotency.sql
migrate-1 | применена: 0003_attachments.sql
s3-init-1 | bucket создан: messenger-attachments
s3-init-1 | S3 ещё не готов: ReadTimeoutError
s3-init-1 | bucket уже есть: messenger-attachments
s3-init-1 | пробная запись прошла
migrate-1 | применена: 0001_init.sql
migrate-1 | применена: 0002_idempotency.sql
migrate-1 | применена: 0003_attachments.sql
$ make check
python3 scripts/check_contract.py
+3 -2
View File
@@ -1,8 +1,9 @@
# Сценарий защиты: файл, сообщение, второй участник, посторонний, прямой доступ к S3
# дата: 2026-10-30T19:58Z, чистый clone
# дата: 2026-10-31T00:55Z, чистый clone
# стенд: Apple M3 Pro, 11 CPU, 18 GB RAM, macOS 26.1, Docker 29.3.0, Compose 5.1.0
$ python3 scripts/attachment_demo.py
$ make attachment-demo
python3 scripts/attachment_demo.py
загрузка: ready 111817 байт, sha256 99ea7533c441f79c
сообщение: 201 attachment_ids = 1
второй участник скачал: 200 image/png sha256 совпал: True
+67
View File
@@ -0,0 +1,67 @@
# Разбор изображений и сверка с Pillow внутри образа API
# дата: 2026-10-31T00:56Z, чистый clone
# стенд: Apple M3 Pro, 11 CPU, 18 GB RAM, macOS 26.1, Docker 29.3.0, Compose 5.1.0
$ make test-images
COPYFILE_DISABLE=1 tar -cf - src/images.py student-tests/samples.py student-tests/image tests/fixtures/sample.png | \
docker run --rm -i --entrypoint sh mtusi-messenger:lab4 -c 'cd /tmp && tar -xf - && python -m unittest discover -s student-tests/image -v'
tar: Ignoring unknown extended header keyword 'LIBARCHIVE.xattr.com.apple.provenance'
tar: Ignoring unknown extended header keyword 'LIBARCHIVE.xattr.com.apple.provenance'
tar: Ignoring unknown extended header keyword 'LIBARCHIVE.xattr.com.apple.provenance'
tar: Ignoring unknown extended header keyword 'LIBARCHIVE.xattr.com.apple.provenance'
tar: Ignoring unknown extended header keyword 'LIBARCHIVE.xattr.com.apple.provenance'
tar: Ignoring unknown extended header keyword 'LIBARCHIVE.xattr.com.apple.provenance'
test_cut_files (test_against_pillow.AgreementTest.test_cut_files) ... /usr/local/lib/python3.13/site-packages/PIL/TiffImagePlugin.py:982: UserWarning: Corrupt EXIF data. Expecting to read 4 bytes but only got 0.
warnings.warn(str(msg))
обрезка: принято 370, отвергнуто 2110, принято вопреки Pillow 0
ok
test_jpeg_with_headers_rebuilt (test_against_pillow.AgreementTest.test_jpeg_with_headers_rebuilt) ... JPEG с настоящими заголовками: принято 792, отвергнуто 8, принято вопреки Pillow 0
ok
test_png_chunks_shuffled (test_against_pillow.AgreementTest.test_png_chunks_shuffled) ... порядок блоков PNG: принято 0, отвергнуто 600, принято вопреки Pillow 0
ok
test_png_with_recomputed_crc (test_against_pillow.AgreementTest.test_png_with_recomputed_crc)
Самый важный случай: заголовок и CRC верны, испорчено только содержимое. Именно такой файл и был в замечании. ... ok
test_random_bytes_changed (test_against_pillow.AgreementTest.test_random_bytes_changed) ... PNG с верными CRC: принято 1354, отвергнуто 146, принято вопреки Pillow 0
ok
test_every_valid_file_is_accepted (test_against_pillow.ValidFilesTest.test_every_valid_file_is_accepted) ... замена байтов: принято 2218, отвергнуто 3982, принято вопреки Pillow 0
ok
test_jpeg_without_frame_or_scan (test_images.BrokenImagesTest.test_jpeg_without_frame_or_scan) ... ok
test_not_images (test_images.BrokenImagesTest.test_not_images) ... ok
test_png_bad_crc (test_images.BrokenImagesTest.test_png_bad_crc) ... ok
test_png_data_after_compressed_stream_in_zero_size (test_images.BrokenImagesTest.test_png_data_after_compressed_stream_in_zero_size) ... ok
test_png_data_after_end (test_images.BrokenImagesTest.test_png_data_after_end) ... ok
test_png_data_is_not_zlib (test_images.BrokenImagesTest.test_png_data_is_not_zlib) ... ok
test_png_with_wrong_amount_of_pixels (test_images.BrokenImagesTest.test_png_with_wrong_amount_of_pixels) ... ok
test_png_zero_size (test_images.BrokenImagesTest.test_png_zero_size) ... ok
test_random_corruption_never_crashes (test_images.BrokenImagesTest.test_random_corruption_never_crashes) ... ok
test_truncated (test_images.BrokenImagesTest.test_truncated) ... ok
test_big_frame_with_tiny_scan (test_images.JpegContentTest.test_big_frame_with_tiny_scan) ... ok
test_broken_frame_header (test_images.JpegContentTest.test_broken_frame_header) ... ok
test_scan_replaced_by_almost_nothing (test_images.JpegContentTest.test_scan_replaced_by_almost_nothing) ... ok
test_too_many_scans (test_images.JpegContentTest.test_too_many_scans) ... ok
test_truncated_with_end_marker_added (test_images.JpegContentTest.test_truncated_with_end_marker_added) ... ok
test_without_huffman_tables_like_mjpeg (test_images.JpegContentTest.test_without_huffman_tables_like_mjpeg) ... ok
test_without_quantization_tables (test_images.JpegContentTest.test_without_quantization_tables) ... ok
test_jpeg_over_limit (test_images.PixelLimitTest.test_jpeg_over_limit) ... ok
test_limit_is_exact (test_images.PixelLimitTest.test_limit_is_exact) ... ok
test_png_bomb_is_rejected_before_unpacking (test_images.PixelLimitTest.test_png_bomb_is_rejected_before_unpacking) ... ok
test_all_valid_filters (test_images.PngContentTest.test_all_valid_filters) ... ok
test_bad_filter_in_any_row (test_images.PngContentTest.test_bad_filter_in_any_row) ... ok
test_chunk_order (test_images.PngContentTest.test_chunk_order) ... ok
test_filter_check_crosses_inflate_blocks (test_images.PngContentTest.test_filter_check_crosses_inflate_blocks) ... ok
test_garbage_after_compressed_data (test_images.PngContentTest.test_garbage_after_compressed_data) ... ok
test_interlaced (test_images.PngContentTest.test_interlaced) ... ok
test_many_short_rows_are_checked_quickly (test_images.PngContentTest.test_many_short_rows_are_checked_quickly) ... ok
test_palette_rules (test_images.PngContentTest.test_palette_rules) ... ok
test_course_fixture (test_images.RealImagesTest.test_course_fixture) ... ok
test_jpeg_with_data_after_end (test_images.RealImagesTest.test_jpeg_with_data_after_end) ... ok
test_marker_on_block_border (test_images.RealImagesTest.test_marker_on_block_border) ... ok
test_real_images_are_accepted (test_images.RealImagesTest.test_real_images_are_accepted) ... ok
test_jpeg_without_image_data (test_images.ReviewCasesTest.test_jpeg_without_image_data) ... ok
test_png_with_invalid_filter_byte (test_images.ReviewCasesTest.test_png_with_invalid_filter_byte) ... ok
----------------------------------------------------------------------
Ran 40 tests in 0.952s
OK
+4 -19
View File
@@ -1,5 +1,5 @@
# Собственные тесты API и разбора изображений
# дата: 2026-10-30T19:58Z, чистый clone
# Собственные тесты API и вложений
# дата: 2026-10-31T00:55Z, чистый clone
# стенд: Apple M3 Pro, 11 CPU, 18 GB RAM, macOS 26.1, Docker 29.3.0, Compose 5.1.0
$ make student-test
@@ -26,6 +26,7 @@ test_outsider_looks_the_same_as_missing (test_attachments.AccessTest.test_outsid
test_variants (test_attachments.AccessTest.test_variants) ... ok
test_broken_images (test_attachments.ContentCheckTest.test_broken_images) ... ok
test_extension_is_not_trusted (test_attachments.ContentCheckTest.test_extension_is_not_trusted) ... ok
test_files_from_review (test_attachments.ContentCheckTest.test_files_from_review) ... ok
test_mime_spoofing (test_attachments.ContentCheckTest.test_mime_spoofing) ... ok
test_unsupported_content_type (test_attachments.ContentCheckTest.test_unsupported_content_type) ... ok
test_bad_filenames (test_attachments.FilenameTest.test_bad_filenames) ... ok
@@ -94,22 +95,6 @@ test_parallel_repeat_through_different_replicas (test_idempotency.IdempotencyTes
test_repeat_checks_access_again (test_idempotency.IdempotencyTest.test_repeat_checks_access_again) ... ok
test_repeat_returns_same_message (test_idempotency.IdempotencyTest.test_repeat_returns_same_message) ... ok
test_same_key_for_other_user_and_other_chat (test_idempotency.IdempotencyTest.test_same_key_for_other_user_and_other_chat) ... ok
test_jpeg_without_frame_or_scan (test_images.BrokenImagesTest.test_jpeg_without_frame_or_scan) ... ok
test_not_images (test_images.BrokenImagesTest.test_not_images) ... ok
test_png_bad_crc (test_images.BrokenImagesTest.test_png_bad_crc) ... ok
test_png_data_after_end (test_images.BrokenImagesTest.test_png_data_after_end) ... ok
test_png_data_is_not_zlib (test_images.BrokenImagesTest.test_png_data_is_not_zlib) ... ok
test_png_with_wrong_amount_of_pixels (test_images.BrokenImagesTest.test_png_with_wrong_amount_of_pixels) ... ok
test_png_zero_size (test_images.BrokenImagesTest.test_png_zero_size) ... ok
test_random_corruption_never_crashes (test_images.BrokenImagesTest.test_random_corruption_never_crashes) ... ok
test_truncated (test_images.BrokenImagesTest.test_truncated) ... ok
test_jpeg_over_limit (test_images.PixelLimitTest.test_jpeg_over_limit) ... ok
test_limit_is_exact (test_images.PixelLimitTest.test_limit_is_exact) ... ok
test_png_bomb_is_rejected_before_unpacking (test_images.PixelLimitTest.test_png_bomb_is_rejected_before_unpacking) ... ok
test_course_fixture (test_images.RealImagesTest.test_course_fixture) ... ok
test_jpeg_with_data_after_end (test_images.RealImagesTest.test_jpeg_with_data_after_end) ... ok
test_marker_on_block_border (test_images.RealImagesTest.test_marker_on_block_border) ... ok
test_real_images_are_accepted (test_images.RealImagesTest.test_real_images_are_accepted) ... ok
test_chat_cursor_belongs_to_user (test_pagination.ChatPaginationTest.test_chat_cursor_belongs_to_user) ... ok
test_walk_chat_list (test_pagination.ChatPaginationTest.test_walk_chat_list) ... ok
test_bad_cursor (test_pagination.MessagePaginationTest.test_bad_cursor) ... ok
@@ -148,7 +133,7 @@ test_password_is_never_returned (test_validation.UserValidationTest.test_passwor
test_password_length_limits (test_validation.UserValidationTest.test_password_length_limits) ... ok
----------------------------------------------------------------------
Ran 142 tests in 7.240s
Ran 127 tests in 7.860s
OK
+19 -19
View File
@@ -1,15 +1,15 @@
# Сохранность: перезапуск всего стенда с сохранением volumes, включая оригинал файла
# дата: 2026-10-30T19:58Z, чистый clone
# дата: 2026-10-31T00:56Z, чистый clone
# стенд: Apple M3 Pro, 11 CPU, 18 GB RAM, macOS 26.1, Docker 29.3.0, Compose 5.1.0
# до перезапуска
/mtusi-messenger-lab4-api-1 StartedAt=2026-10-30T19:58:29.088370587Z
/mtusi-messenger-lab4-api-2 StartedAt=2026-10-30T19:58:29.209140045Z
/mtusi-messenger-lab4-janitor-1 StartedAt=2026-10-30T19:58:29.085001378Z
/mtusi-messenger-lab4-lb-1 StartedAt=2026-10-30T19:58:29.300703295Z
/mtusi-messenger-lab4-postgres-1 StartedAt=2026-10-30T19:58:11.349641968Z
/mtusi-messenger-lab4-redis-1 StartedAt=2026-10-30T19:58:11.345301093Z
/mtusi-messenger-lab4-s3-1 StartedAt=2026-10-30T19:58:11.372245384Z
/mtusi-messenger-lab4-api-1 StartedAt=2026-10-31T00:55:51.019629833Z
/mtusi-messenger-lab4-api-2 StartedAt=2026-10-31T00:55:51.155422333Z
/mtusi-messenger-lab4-janitor-1 StartedAt=2026-10-31T00:55:51.019948375Z
/mtusi-messenger-lab4-lb-1 StartedAt=2026-10-31T00:55:51.246447042Z
/mtusi-messenger-lab4-postgres-1 StartedAt=2026-10-31T00:55:33.238815464Z
/mtusi-messenger-lab4-redis-1 StartedAt=2026-10-31T00:55:33.238242006Z
/mtusi-messenger-lab4-s3-1 StartedAt=2026-10-31T00:55:33.268518673Z
$ cat scripts/restart.sh
#!/bin/sh
@@ -33,13 +33,13 @@ Executing explicit persistence hook; hook output suppressed to avoid leaking sec
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
# после перезапуска: новое время старта у всех контейнеров
/mtusi-messenger-lab4-api-1 StartedAt=2026-10-30T19:58:43.982991844Z
/mtusi-messenger-lab4-api-2 StartedAt=2026-10-30T19:58:44.040335636Z
/mtusi-messenger-lab4-janitor-1 StartedAt=2026-10-30T19:58:43.669196927Z
/mtusi-messenger-lab4-lb-1 StartedAt=2026-10-30T19:58:43.367738094Z
/mtusi-messenger-lab4-postgres-1 StartedAt=2026-10-30T19:58:43.452856427Z
/mtusi-messenger-lab4-redis-1 StartedAt=2026-10-30T19:58:43.413552302Z
/mtusi-messenger-lab4-s3-1 StartedAt=2026-10-30T19:58:44.201471136Z
/mtusi-messenger-lab4-api-1 StartedAt=2026-10-31T00:56:08.283900967Z
/mtusi-messenger-lab4-api-2 StartedAt=2026-10-31T00:56:08.204635217Z
/mtusi-messenger-lab4-janitor-1 StartedAt=2026-10-31T00:56:08.100580008Z
/mtusi-messenger-lab4-lb-1 StartedAt=2026-10-31T00:56:07.638958341Z
/mtusi-messenger-lab4-postgres-1 StartedAt=2026-10-31T00:56:07.709906466Z
/mtusi-messenger-lab4-redis-1 StartedAt=2026-10-31T00:56:07.679625675Z
/mtusi-messenger-lab4-s3-1 StartedAt=2026-10-31T00:56:08.466819675Z
$ docker volume ls --filter name=mtusi-messenger-lab4
DRIVER VOLUME NAME
@@ -49,15 +49,15 @@ local mtusi-messenger-lab4_s3data
# повторный запуск миграций и создания bucket
$ docker compose --env-file .env run --rm --no-deps migrate
Container mtusi-messenger-lab4-migrate-run-5b40a0f89a6a Creating
Container mtusi-messenger-lab4-migrate-run-5b40a0f89a6a Created
Container mtusi-messenger-lab4-migrate-run-cf6cc716b21e Creating
Container mtusi-messenger-lab4-migrate-run-cf6cc716b21e Created
уже применена: 0001_init.sql
уже применена: 0002_idempotency.sql
уже применена: 0003_attachments.sql
$ docker compose --env-file .env run --rm --no-deps s3-init
Container mtusi-messenger-lab4-s3-init-run-0ac64ba9510a Creating
Container mtusi-messenger-lab4-s3-init-run-0ac64ba9510a Created
Container mtusi-messenger-lab4-s3-init-run-1a7c3702d2be Creating
Container mtusi-messenger-lab4-s3-init-run-1a7c3702d2be Created
bucket уже есть: messenger-attachments
пробная запись прошла
+27 -27
View File
@@ -1,88 +1,88 @@
# Публичный failover: файл загружен, обслужившая реплика остановлена, скачивание через другую; два прогона
# дата: 2026-10-30T19:59Z, чистый clone
# дата: 2026-10-31T00:56Z, чистый clone
# стенд: Apple M3 Pro, 11 CPU, 18 GB RAM, macOS 26.1, Docker 29.3.0, Compose 5.1.0
## прогон 1
# реплики до отказа
NAME STATE STATUS
mtusi-messenger-lab4-api-1 running Up 36 seconds (healthy)
mtusi-messenger-lab4-api-2 running Up 36 seconds (healthy)
mtusi-messenger-lab4-api-1 running Up 38 seconds (healthy)
mtusi-messenger-lab4-api-2 running Up 38 seconds (healthy)
$ 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:8080"
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
{"observed_instances_before": 2, "successful_writes": 116, "failed_attempts": 0, "first_recovery_seconds": 1.97}
{"observed_instances_before": 2, "successful_writes": 120, "failed_attempts": 0, "first_recovery_seconds": 2.065}
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
# какой контейнер реально остановлен
NAME STATE STATUS
mtusi-messenger-lab4-api-1 exited Exited (0) 14 seconds ago
mtusi-messenger-lab4-api-2 running Up 52 seconds (healthy)
mtusi-messenger-lab4-api-1 running Up 53 seconds (healthy)
mtusi-messenger-lab4-api-2 exited Exited (0) 14 seconds ago
$ make restore
docker compose --env-file .env up -d --no-recreate --no-build api
Container mtusi-messenger-lab4-postgres-1 Running
Container mtusi-messenger-lab4-redis-1 Running
Container mtusi-messenger-lab4-s3-1 Running
Container mtusi-messenger-lab4-api-2 Running
Container mtusi-messenger-lab4-postgres-1 Running
Container mtusi-messenger-lab4-api-1 Running
Container mtusi-messenger-lab4-postgres-1 Waiting
Container mtusi-messenger-lab4-s3-1 Waiting
Container mtusi-messenger-lab4-s3-1 Healthy
Container mtusi-messenger-lab4-postgres-1 Healthy
Container mtusi-messenger-lab4-migrate-1 Starting
Container mtusi-messenger-lab4-s3-init-1 Starting
Container mtusi-messenger-lab4-migrate-1 Started
Container mtusi-messenger-lab4-s3-init-1 Started
Container mtusi-messenger-lab4-migrate-1 Waiting
Container mtusi-messenger-lab4-migrate-1 Started
Container mtusi-messenger-lab4-redis-1 Waiting
Container mtusi-messenger-lab4-s3-init-1 Waiting
Container mtusi-messenger-lab4-migrate-1 Waiting
Container mtusi-messenger-lab4-redis-1 Healthy
Container mtusi-messenger-lab4-s3-init-1 Exited
Container mtusi-messenger-lab4-migrate-1 Exited
Container mtusi-messenger-lab4-api-1 Starting
Container mtusi-messenger-lab4-api-1 Started
Container mtusi-messenger-lab4-s3-init-1 Exited
Container mtusi-messenger-lab4-api-2 Starting
Container mtusi-messenger-lab4-api-2 Started
BASE_URL="http://localhost:8080" ./scripts/wait-ready.sh
готов: http://localhost:8080
## прогон 2
# реплики до отказа
NAME STATE STATUS
mtusi-messenger-lab4-api-1 running Up 4 seconds (healthy)
mtusi-messenger-lab4-api-2 running Up 58 seconds (healthy)
mtusi-messenger-lab4-api-1 running Up 59 seconds (healthy)
mtusi-messenger-lab4-api-2 running Up 4 seconds (healthy)
$ 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:8080"
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
{"observed_instances_before": 2, "successful_writes": 116, "failed_attempts": 0, "first_recovery_seconds": 1.731}
{"observed_instances_before": 2, "successful_writes": 121, "failed_attempts": 0, "first_recovery_seconds": 1.691}
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
# какой контейнер реально остановлен
NAME STATE STATUS
mtusi-messenger-lab4-api-1 exited Exited (0) 14 seconds ago
mtusi-messenger-lab4-api-2 running Up About a minute (healthy)
mtusi-messenger-lab4-api-1 running Up About a minute (healthy)
mtusi-messenger-lab4-api-2 exited Exited (0) 14 seconds ago
$ make restore
docker compose --env-file .env up -d --no-recreate --no-build api
Container mtusi-messenger-lab4-s3-1 Running
Container mtusi-messenger-lab4-postgres-1 Running
Container mtusi-messenger-lab4-redis-1 Running
Container mtusi-messenger-lab4-api-2 Running
Container mtusi-messenger-lab4-postgres-1 Waiting
Container mtusi-messenger-lab4-postgres-1 Running
Container mtusi-messenger-lab4-api-1 Running
Container mtusi-messenger-lab4-s3-1 Waiting
Container mtusi-messenger-lab4-s3-1 Healthy
Container mtusi-messenger-lab4-postgres-1 Waiting
Container mtusi-messenger-lab4-postgres-1 Healthy
Container mtusi-messenger-lab4-s3-1 Healthy
Container mtusi-messenger-lab4-migrate-1 Starting
Container mtusi-messenger-lab4-s3-init-1 Starting
Container mtusi-messenger-lab4-s3-init-1 Started
Container mtusi-messenger-lab4-migrate-1 Started
Container mtusi-messenger-lab4-s3-init-1 Started
Container mtusi-messenger-lab4-migrate-1 Waiting
Container mtusi-messenger-lab4-redis-1 Waiting
Container mtusi-messenger-lab4-s3-init-1 Waiting
Container mtusi-messenger-lab4-migrate-1 Waiting
Container mtusi-messenger-lab4-redis-1 Healthy
Container mtusi-messenger-lab4-migrate-1 Exited
Container mtusi-messenger-lab4-s3-init-1 Exited
Container mtusi-messenger-lab4-api-1 Starting
Container mtusi-messenger-lab4-api-1 Started
Container mtusi-messenger-lab4-migrate-1 Exited
Container mtusi-messenger-lab4-api-2 Starting
Container mtusi-messenger-lab4-api-2 Started
BASE_URL="http://localhost:8080" ./scripts/wait-ready.sh
готов: http://localhost:8080
+3 -3
View File
@@ -1,10 +1,10 @@
# Остановка каждой реплики под нагрузкой (SIGTERM), полные данные в failover-each.json
# дата: 2026-10-30T20:00Z, чистый clone
# дата: 2026-10-31T00:57Z, чистый clone
# стенд: Apple M3 Pro, 11 CPU, 18 GB RAM, macOS 26.1, Docker 29.3.0, Compose 5.1.0
$ make failover-each
BASE_URL="http://localhost:8080" python3 scripts/chaos.py stop --output evidence/failover-each.json
{"seconds": 17.89, "successful_requests": 10761, "failed_attempts": 0, "failed_statuses": [], "successful_rps": 601.6, "longest_gap_between_successes_s": 1.027, "first_success_after_action_s": 0.003, "last_success_on_target_after_action_s": 12.886, "instances_seen": 2, "target": "b4e0f5de7608", "signal": "SIGTERM", "stop_command_s": 0.59, "excluded_by_lb_after_s": 0.9, "verify": {"confirmed": 10761, "in_history": 10761, "lost_confirmed": 0, "duplicate_ids": 0, "duplicate_texts": 0, "unconfirmed_but_saved": 0}}
{"seconds": 19.96, "successful_requests": 11872, "failed_attempts": 0, "failed_statuses": [], "successful_rps": 594.9, "longest_gap_between_successes_s": 1.015, "first_success_after_action_s": 0.0, "last_success_on_target_after_action_s": 14.955, "instances_seen": 2, "target": "6f14dc16ebf3", "signal": "SIGTERM", "stop_command_s": 0.61, "excluded_by_lb_after_s": 1.51, "verify": {"confirmed": 11872, "in_history": 11872, "lost_confirmed": 0, "duplicate_ids": 0, "duplicate_texts": 0, "unconfirmed_but_saved": 0}}
{"seconds": 18.19, "successful_requests": 8333, "failed_attempts": 0, "failed_statuses": [], "successful_rps": 458.1, "longest_gap_between_successes_s": 0.997, "first_success_after_action_s": 0.004, "last_success_on_target_after_action_s": 13.188, "instances_seen": 2, "target": "e0ce1c223b49", "signal": "SIGTERM", "stop_command_s": 0.59, "excluded_by_lb_after_s": 1.63, "verify": {"confirmed": 8333, "in_history": 8333, "lost_confirmed": 0, "duplicate_ids": 0, "duplicate_texts": 0, "unconfirmed_but_saved": 0}}
{"seconds": 19.85, "successful_requests": 9258, "failed_attempts": 1, "failed_statuses": [502], "successful_rps": 466.3, "longest_gap_between_successes_s": 1.016, "first_success_after_action_s": 0.005, "last_success_on_target_after_action_s": 14.853, "instances_seen": 2, "target": "6e7001b3af3a", "signal": "SIGTERM", "stop_command_s": 0.66, "excluded_by_lb_after_s": 0.78, "verify": {"confirmed": 9258, "in_history": 9258, "lost_confirmed": 0, "duplicate_ids": 0, "duplicate_texts": 0, "unconfirmed_but_saved": 0}}
PASS: подтверждённые сообщения на месте, дублей нет
+6 -6
View File
@@ -1,16 +1,16 @@
# Поочерёдная замена реплик под нагрузкой, полные данные в rolling-update.json
# дата: 2026-10-30T20:00Z, чистый clone
# дата: 2026-10-31T00:58Z, чистый clone
# стенд: Apple M3 Pro, 11 CPU, 18 GB RAM, macOS 26.1, Docker 29.3.0, Compose 5.1.0
# образы до замены
/mtusi-messenger-lab4-api-1 sha256:693fe62509aa4bc5ff409c715e21da0f894
/mtusi-messenger-lab4-api-2 sha256:693fe62509aa4bc5ff409c715e21da0f894
/mtusi-messenger-lab4-api-1 sha256:53d2e279c4c191e566b6dd52082c532a7a4
/mtusi-messenger-lab4-api-2 sha256:53d2e279c4c191e566b6dd52082c532a7a4
$ make rolling-update APP_VERSION=2
BASE_URL="http://localhost:8080" python3 scripts/chaos.py rolling --output evidence/rolling-update.json
{"seconds": 25.51, "successful_requests": 17974, "failed_attempts": 0, "failed_statuses": [], "successful_rps": 704.5, "longest_gap_between_successes_s": 1.001, "first_success_after_action_s": 0.003, "last_success_on_target_after_action_s": null, "instances_seen": 4, "update_seconds": 15.51, "containers_before": {"b4e0f5de7608": "sha256:693fe62509aa", "6f14dc16ebf3": "sha256:693fe62509aa"}, "containers_after": {"abc646dd09cf": "sha256:bdbd0270135d", "d7f52b7d6c23": "sha256:bdbd0270135d"}, "app_version": "2", "verify": {"confirmed": 17974, "in_history": 17974, "lost_confirmed": 0, "duplicate_ids": 0, "duplicate_texts": 0, "unconfirmed_but_saved": 0}}
{"seconds": 24.77, "successful_requests": 13125, "failed_attempts": 0, "failed_statuses": [], "successful_rps": 529.8, "longest_gap_between_successes_s": 0.995, "first_success_after_action_s": 0.0, "last_success_on_target_after_action_s": null, "instances_seen": 4, "update_seconds": 14.77, "containers_before": {"e0ce1c223b49": "sha256:53d2e279c4c1", "6e7001b3af3a": "sha256:53d2e279c4c1"}, "containers_after": {"504924bd9076": "sha256:e71bfdb1c725", "ec77c0e85d5c": "sha256:e71bfdb1c725"}, "app_version": "2", "verify": {"confirmed": 13125, "in_history": 13125, "lost_confirmed": 0, "duplicate_ids": 0, "duplicate_texts": 0, "unconfirmed_but_saved": 0}}
PASS: подтверждённые сообщения на месте, дублей нет
# образы и версия после замены
/mtusi-messenger-lab4-api-3 sha256:bdbd0270135d576aecc5d4df3c91c41eb31 APP_VERSION=2
/mtusi-messenger-lab4-api-4 sha256:bdbd0270135d576aecc5d4df3c91c41eb31 APP_VERSION=2
/mtusi-messenger-lab4-api-3 sha256:e71bfdb1c7251e1ff3cba0fe406a31058f3 APP_VERSION=2
/mtusi-messenger-lab4-api-4 sha256:e71bfdb1c7251e1ff3cba0fe406a31058f3 APP_VERSION=2
+3 -3
View File
@@ -1,5 +1,5 @@
# Тесты отказов: сбой между S3 и БД, отказ S3, приватность bucket, истечение, отказ Redis и PostgreSQL, транзакции
# дата: 2026-10-30T20:01Z, чистый clone
# дата: 2026-10-31T00:58Z, чистый clone
# стенд: Apple M3 Pro, 11 CPU, 18 GB RAM, macOS 26.1, Docker 29.3.0, Compose 5.1.0
$ make test-failures
@@ -35,9 +35,9 @@ test_username_race_creates_one_row (test_transactions.TransactionTest.test_usern
test_valid_chat_is_committed_whole (test_transactions.TransactionTest.test_valid_chat_is_committed_whole) ... ok
----------------------------------------------------------------------
Ran 27 tests in 301.600s
Ran 27 tests in 310.107s
OK
подтверждено 6, в S3 без подтверждения 8, после очистки расхождений нет
подтверждено 3, в S3 без подтверждения 8, после очистки расхождений нет
+27 -17
View File
@@ -1,41 +1,46 @@
# Память при одновременных загрузках, полные данные в upload-peak.json
# дата: 2026-10-30T20:06Z, чистый clone
# Память при одновременных загрузках, полные данные последнего прогона в upload-peak.json
# дата: 2026-10-31T01:03Z, чистый clone
# стенд: Apple M3 Pro, 11 CPU, 18 GB RAM, macOS 26.1, Docker 29.3.0, Compose 5.1.0
# пять прогонов подряд: один удачный ничего не доказывает
$ make upload-peak
BASE_URL="http://localhost:8080" python3 scripts/upload_peak.py --output evidence/upload-peak.json
{"parallel_uploads": 1, "file_bytes": 10481664, "seconds": 0.14, "slowest_upload_s": 0.14, "statuses": {"201": 1}, "memory": {"abc646dd09cf": {"process_peak_rss_mib": 116.9, "cgroup_peak_mib": 98.7}, "d7f52b7d6c23": {"process_peak_rss_mib": 117.4, "cgroup_peak_mib": 110.3}}}
{"parallel_uploads": 10, "file_bytes": 10481664, "seconds": 1.29, "slowest_upload_s": 1.29, "statuses": {"201": 10}, "memory": {"abc646dd09cf": {"process_peak_rss_mib": 123.8, "cgroup_peak_mib": 160.0}, "d7f52b7d6c23": {"process_peak_rss_mib": 123.9, "cgroup_peak_mib": 160.2}}}
{"parallel_uploads": 30, "file_bytes": 10481664, "seconds": 3.79, "slowest_upload_s": 3.78, "statuses": {"201": 30}, "memory": {"abc646dd09cf": {"process_peak_rss_mib": 125.9, "cgroup_peak_mib": 256.1}, "d7f52b7d6c23": {"process_peak_rss_mib": 125.9, "cgroup_peak_mib": 258.8}}}
{"file": "PNG 10 MiB", "parallel_uploads": 1, "file_bytes": 10481664, "seconds": 0.16, "slowest_upload_s": 0.16, "statuses": {"201": 1}, "memory": {"504924bd9076": {"process_peak_rss_mib": 117.0, "cgroup_peak_mib": 110.2}, "ec77c0e85d5c": {"process_peak_rss_mib": 117.0, "cgroup_peak_mib": 99.1}}}
{"file": "PNG 10 MiB", "parallel_uploads": 10, "file_bytes": 10481664, "seconds": 1.53, "slowest_upload_s": 1.53, "statuses": {"201": 10}, "memory": {"504924bd9076": {"process_peak_rss_mib": 125.7, "cgroup_peak_mib": 165.9}, "ec77c0e85d5c": {"process_peak_rss_mib": 126.8, "cgroup_peak_mib": 156.3}}}
{"file": "PNG 10 MiB", "parallel_uploads": 30, "file_bytes": 10481664, "seconds": 6.65, "slowest_upload_s": 6.64, "statuses": {"201": 30}, "memory": {"504924bd9076": {"process_peak_rss_mib": 128.6, "cgroup_peak_mib": 269.6}, "ec77c0e85d5c": {"process_peak_rss_mib": 130.5, "cgroup_peak_mib": 270.6}}}
{"file": "прогрессивный CMYK JPEG, 40 млн пикселей", "parallel_uploads": 10, "file_bytes": 2642657, "seconds": 1.47, "slowest_upload_s": 1.47, "statuses": {"201": 10}, "memory": {"504924bd9076": {"process_peak_rss_mib": 438.0, "cgroup_peak_mib": 429.3}, "ec77c0e85d5c": {"process_peak_rss_mib": 439.9, "cgroup_peak_mib": 431.0}}}
PASS: все загрузки успешны
$ make upload-peak
BASE_URL="http://localhost:8080" python3 scripts/upload_peak.py --output evidence/upload-peak.json
{"parallel_uploads": 1, "file_bytes": 10481664, "seconds": 1.76, "slowest_upload_s": 1.76, "statuses": {"201": 1}, "memory": {"abc646dd09cf": {"process_peak_rss_mib": 117.4, "cgroup_peak_mib": 110.7}, "d7f52b7d6c23": {"process_peak_rss_mib": 117.3, "cgroup_peak_mib": 110.6}}}
{"parallel_uploads": 10, "file_bytes": 10481664, "seconds": 1.32, "slowest_upload_s": 1.31, "statuses": {"201": 10}, "memory": {"abc646dd09cf": {"process_peak_rss_mib": 124.0, "cgroup_peak_mib": 161.9}, "d7f52b7d6c23": {"process_peak_rss_mib": 124.3, "cgroup_peak_mib": 158.7}}}
{"parallel_uploads": 30, "file_bytes": 10481664, "seconds": 3.88, "slowest_upload_s": 3.87, "statuses": {"201": 30}, "memory": {"abc646dd09cf": {"process_peak_rss_mib": 126.2, "cgroup_peak_mib": 256.4}, "d7f52b7d6c23": {"process_peak_rss_mib": 125.8, "cgroup_peak_mib": 256.5}}}
{"file": "PNG 10 MiB", "parallel_uploads": 1, "file_bytes": 10481664, "seconds": 0.16, "slowest_upload_s": 0.16, "statuses": {"201": 1}, "memory": {"504924bd9076": {"process_peak_rss_mib": 116.7, "cgroup_peak_mib": 98.5}, "ec77c0e85d5c": {"process_peak_rss_mib": 117.1, "cgroup_peak_mib": 109.0}}}
{"file": "PNG 10 MiB", "parallel_uploads": 10, "file_bytes": 10481664, "seconds": 1.49, "slowest_upload_s": 1.49, "statuses": {"201": 10}, "memory": {"504924bd9076": {"process_peak_rss_mib": 123.6, "cgroup_peak_mib": 168.7}, "ec77c0e85d5c": {"process_peak_rss_mib": 123.7, "cgroup_peak_mib": 168.8}}}
{"file": "PNG 10 MiB", "parallel_uploads": 30, "file_bytes": 10481664, "seconds": 4.89, "slowest_upload_s": 4.88, "statuses": {"201": 30}, "memory": {"504924bd9076": {"process_peak_rss_mib": 126.6, "cgroup_peak_mib": 269.3}, "ec77c0e85d5c": {"process_peak_rss_mib": 126.6, "cgroup_peak_mib": 269.6}}}
{"file": "прогрессивный CMYK JPEG, 40 млн пикселей", "parallel_uploads": 10, "file_bytes": 2642657, "seconds": 1.42, "slowest_upload_s": 1.42, "statuses": {"201": 10}, "memory": {"504924bd9076": {"process_peak_rss_mib": 435.1, "cgroup_peak_mib": 426.9}, "ec77c0e85d5c": {"process_peak_rss_mib": 435.3, "cgroup_peak_mib": 427.2}}}
PASS: все загрузки успешны
$ make upload-peak
BASE_URL="http://localhost:8080" python3 scripts/upload_peak.py --output evidence/upload-peak.json
{"parallel_uploads": 1, "file_bytes": 10481664, "seconds": 1.83, "slowest_upload_s": 1.83, "statuses": {"201": 1}, "memory": {"abc646dd09cf": {"process_peak_rss_mib": 117.4, "cgroup_peak_mib": 99.0}, "d7f52b7d6c23": {"process_peak_rss_mib": 117.8, "cgroup_peak_mib": 110.6}}}
{"parallel_uploads": 10, "file_bytes": 10481664, "seconds": 1.34, "slowest_upload_s": 1.34, "statuses": {"201": 10}, "memory": {"abc646dd09cf": {"process_peak_rss_mib": 124.2, "cgroup_peak_mib": 176.0}, "d7f52b7d6c23": {"process_peak_rss_mib": 124.3, "cgroup_peak_mib": 168.9}}}
{"parallel_uploads": 30, "file_bytes": 10481664, "seconds": 4.48, "slowest_upload_s": 4.48, "statuses": {"201": 30}, "memory": {"abc646dd09cf": {"process_peak_rss_mib": 126.0, "cgroup_peak_mib": 256.1}, "d7f52b7d6c23": {"process_peak_rss_mib": 126.5, "cgroup_peak_mib": 256.5}}}
{"file": "PNG 10 MiB", "parallel_uploads": 1, "file_bytes": 10481664, "seconds": 0.17, "slowest_upload_s": 0.17, "statuses": {"201": 1}, "memory": {"504924bd9076": {"process_peak_rss_mib": 117.1, "cgroup_peak_mib": 110.4}, "ec77c0e85d5c": {"process_peak_rss_mib": 117.0, "cgroup_peak_mib": 99.1}}}
{"file": "PNG 10 MiB", "parallel_uploads": 10, "file_bytes": 10481664, "seconds": 1.6, "slowest_upload_s": 1.6, "statuses": {"201": 10}, "memory": {"504924bd9076": {"process_peak_rss_mib": 123.6, "cgroup_peak_mib": 161.2}, "ec77c0e85d5c": {"process_peak_rss_mib": 123.9, "cgroup_peak_mib": 163.2}}}
{"file": "PNG 10 MiB", "parallel_uploads": 30, "file_bytes": 10481664, "seconds": 7.01, "slowest_upload_s": 7.0, "statuses": {"201": 30}, "memory": {"504924bd9076": {"process_peak_rss_mib": 129.6, "cgroup_peak_mib": 272.5}, "ec77c0e85d5c": {"process_peak_rss_mib": 130.0, "cgroup_peak_mib": 273.6}}}
{"file": "прогрессивный CMYK JPEG, 40 млн пикселей", "parallel_uploads": 10, "file_bytes": 2642657, "seconds": 1.35, "slowest_upload_s": 1.35, "statuses": {"201": 10}, "memory": {"504924bd9076": {"process_peak_rss_mib": 438.4, "cgroup_peak_mib": 429.9}, "ec77c0e85d5c": {"process_peak_rss_mib": 438.9, "cgroup_peak_mib": 430.5}}}
PASS: все загрузки успешны
$ make upload-peak
BASE_URL="http://localhost:8080" python3 scripts/upload_peak.py --output evidence/upload-peak.json
{"parallel_uploads": 1, "file_bytes": 10481664, "seconds": 0.14, "slowest_upload_s": 0.14, "statuses": {"201": 1}, "memory": {"abc646dd09cf": {"process_peak_rss_mib": 117.8, "cgroup_peak_mib": 110.8}, "d7f52b7d6c23": {"process_peak_rss_mib": 117.1, "cgroup_peak_mib": 98.4}}}
{"parallel_uploads": 10, "file_bytes": 10481664, "seconds": 2.92, "slowest_upload_s": 2.92, "statuses": {"201": 10}, "memory": {"abc646dd09cf": {"process_peak_rss_mib": 125.6, "cgroup_peak_mib": 175.5}, "d7f52b7d6c23": {"process_peak_rss_mib": 126.4, "cgroup_peak_mib": 163.7}}}
{"parallel_uploads": 30, "file_bytes": 10481664, "seconds": 6.3, "slowest_upload_s": 6.29, "statuses": {"201": 30}, "memory": {"abc646dd09cf": {"process_peak_rss_mib": 129.2, "cgroup_peak_mib": 256.1}, "d7f52b7d6c23": {"process_peak_rss_mib": 128.8, "cgroup_peak_mib": 256.1}}}
{"file": "PNG 10 MiB", "parallel_uploads": 1, "file_bytes": 10481664, "seconds": 0.15, "slowest_upload_s": 0.15, "statuses": {"201": 1}, "memory": {"504924bd9076": {"process_peak_rss_mib": 116.7, "cgroup_peak_mib": 110.2}, "ec77c0e85d5c": {"process_peak_rss_mib": 119.4, "cgroup_peak_mib": 112.6}}}
{"file": "PNG 10 MiB", "parallel_uploads": 10, "file_bytes": 10481664, "seconds": 1.34, "slowest_upload_s": 1.33, "statuses": {"201": 10}, "memory": {"504924bd9076": {"process_peak_rss_mib": 123.6, "cgroup_peak_mib": 160.7}, "ec77c0e85d5c": {"process_peak_rss_mib": 123.9, "cgroup_peak_mib": 161.4}}}
{"file": "PNG 10 MiB", "parallel_uploads": 30, "file_bytes": 10481664, "seconds": 7.19, "slowest_upload_s": 7.18, "statuses": {"201": 30}, "memory": {"504924bd9076": {"process_peak_rss_mib": 126.5, "cgroup_peak_mib": 266.8}, "ec77c0e85d5c": {"process_peak_rss_mib": 126.7, "cgroup_peak_mib": 267.5}}}
{"file": "прогрессивный CMYK JPEG, 40 млн пикселей", "parallel_uploads": 10, "file_bytes": 2642657, "seconds": 1.31, "slowest_upload_s": 1.31, "statuses": {"201": 10}, "memory": {"504924bd9076": {"process_peak_rss_mib": 437.9, "cgroup_peak_mib": 429.2}, "ec77c0e85d5c": {"process_peak_rss_mib": 438.0, "cgroup_peak_mib": 429.1}}}
PASS: все загрузки успешны
$ make upload-peak
BASE_URL="http://localhost:8080" python3 scripts/upload_peak.py --output evidence/upload-peak.json
{"parallel_uploads": 1, "file_bytes": 10481664, "seconds": 0.48, "slowest_upload_s": 0.48, "statuses": {"201": 1}, "memory": {"abc646dd09cf": {"process_peak_rss_mib": 117.2, "cgroup_peak_mib": 110.5}, "d7f52b7d6c23": {"process_peak_rss_mib": 117.5, "cgroup_peak_mib": 110.2}}}
{"parallel_uploads": 10, "file_bytes": 10481664, "seconds": 3.87, "slowest_upload_s": 3.87, "statuses": {"201": 10}, "memory": {"abc646dd09cf": {"process_peak_rss_mib": 124.3, "cgroup_peak_mib": 163.7}, "d7f52b7d6c23": {"process_peak_rss_mib": 124.1, "cgroup_peak_mib": 164.1}}}
{"parallel_uploads": 30, "file_bytes": 10481664, "seconds": 6.43, "slowest_upload_s": 6.42, "statuses": {"201": 30}, "memory": {"abc646dd09cf": {"process_peak_rss_mib": 127.3, "cgroup_peak_mib": 256.0}, "d7f52b7d6c23": {"process_peak_rss_mib": 126.9, "cgroup_peak_mib": 256.0}}}
{"file": "PNG 10 MiB", "parallel_uploads": 1, "file_bytes": 10481664, "seconds": 0.14, "slowest_upload_s": 0.14, "statuses": {"201": 1}, "memory": {"504924bd9076": {"process_peak_rss_mib": 117.2, "cgroup_peak_mib": 110.5}, "ec77c0e85d5c": {"process_peak_rss_mib": 116.6, "cgroup_peak_mib": 110.2}}}
{"file": "PNG 10 MiB", "parallel_uploads": 10, "file_bytes": 10481664, "seconds": 2.1, "slowest_upload_s": 2.09, "statuses": {"201": 10}, "memory": {"504924bd9076": {"process_peak_rss_mib": 123.7, "cgroup_peak_mib": 166.6}, "ec77c0e85d5c": {"process_peak_rss_mib": 123.5, "cgroup_peak_mib": 160.5}}}
{"file": "PNG 10 MiB", "parallel_uploads": 30, "file_bytes": 10481664, "seconds": 5.88, "slowest_upload_s": 5.88, "statuses": {"201": 30}, "memory": {"504924bd9076": {"process_peak_rss_mib": 128.8, "cgroup_peak_mib": 274.4}, "ec77c0e85d5c": {"process_peak_rss_mib": 128.3, "cgroup_peak_mib": 273.9}}}
{"file": "прогрессивный CMYK JPEG, 40 млн пикселей", "parallel_uploads": 10, "file_bytes": 2642657, "seconds": 1.45, "slowest_upload_s": 1.44, "statuses": {"201": 10}, "memory": {"504924bd9076": {"process_peak_rss_mib": 437.6, "cgroup_peak_mib": 433.8}, "ec77c0e85d5c": {"process_peak_rss_mib": 437.3, "cgroup_peak_mib": 433.0}}}
PASS: все загрузки успешны
# S3 за все прогоны: перезапуски и OOM
@@ -43,3 +48,8 @@ restarts=0 oom=false
oom 0
oom_kill 0
oom_group_kill 0
# реплики API за все прогоны: OOM
restarts=0 oom=false
oom_kill 0
restarts=0 oom=false
oom_kill 0
+13 -12
View File
@@ -1,5 +1,5 @@
# Контейнеры: лимиты, порты, сети, секреты, права ключа S3
# дата: 2026-10-30T20:07Z, чистый clone
# дата: 2026-10-31T01:05Z, чистый clone
# стенд: Apple M3 Pro, 11 CPU, 18 GB RAM, macOS 26.1, Docker 29.3.0, Compose 5.1.0
$ docker compose ps # опубликован только lb, консоль S3 наружу не открыта
@@ -16,8 +16,8 @@ $ grep -c container_name compose.yaml
0
# лимиты CPU (в наносекундах на секунду) и памяти (байт)
/mtusi-messenger-lab4-api-3 cpus=1000000000 memory=268435456
/mtusi-messenger-lab4-api-4 cpus=1000000000 memory=268435456
/mtusi-messenger-lab4-api-3 cpus=1000000000 memory=536870912
/mtusi-messenger-lab4-api-4 cpus=1000000000 memory=536870912
/mtusi-messenger-lab4-janitor-1 cpus=250000000 memory=134217728
/mtusi-messenger-lab4-lb-1 cpus=500000000 memory=134217728
/mtusi-messenger-lab4-postgres-1 cpus=1000000000 memory=536870912
@@ -32,7 +32,7 @@ s3 mtusi-messenger-lab4_storage
postgres mtusi-messenger-lab4_data
redis mtusi-messenger-lab4_data
$ docker exec abc646dd09cf id
$ docker exec 504924bd9076 id
uid=10001(app) gid=10001(app) groups=10001(app)
$ docker exec <api> ls /run/secrets # ключа администратора S3 у API нет
@@ -41,20 +41,20 @@ database_url
s3_access_key_id
s3_secret_access_key
$ docker exec <api> env | grep -ci "password\|postgresql://\|redis://\|secret_access_key="
$ docker exec <api> env | grep -ci "password\|postgresql://\|redis://"
0
$ docker compose --env-file .env images
CONTAINER REPOSITORY TAG PLATFORM IMAGE ID SIZE CREATED
mtusi-messenger-lab4-api-3 mtusi-messenger lab4 linux/arm64 bdbd0270135d 230MB 9 minutes ago
mtusi-messenger-lab4-api-4 mtusi-messenger lab4 linux/arm64 bdbd0270135d 230MB 9 minutes ago
mtusi-messenger-lab4-janitor-1 sha256 693fe62509aa4bc5ff409c715e21da0f894a2223d5b0ba57cdaab4303cc12145 linux/arm64 693fe62509aa 230MB 9 minutes ago
mtusi-messenger-lab4-lb-1 mtusi-messenger-lb lab4 linux/arm64 874b8c49635f 38.8MB 30 minutes ago
mtusi-messenger-lab4-migrate-1 sha256 693fe62509aa4bc5ff409c715e21da0f894a2223d5b0ba57cdaab4303cc12145 linux/arm64 693fe62509aa 230MB 9 minutes ago
mtusi-messenger-lab4-api-3 mtusi-messenger lab4 linux/arm64 e71bfdb1c725 252MB 22 minutes ago
mtusi-messenger-lab4-api-4 mtusi-messenger lab4 linux/arm64 e71bfdb1c725 252MB 22 minutes ago
mtusi-messenger-lab4-janitor-1 sha256 53d2e279c4c191e566b6dd52082c532a7a4c5bb9f9ee75cd2c8327a3bc8f5944 linux/arm64 53d2e279c4c1 252MB 22 minutes ago
mtusi-messenger-lab4-lb-1 mtusi-messenger-lb lab4 linux/arm64 874b8c49635f 38.8MB 5 hours ago
mtusi-messenger-lab4-migrate-1 sha256 53d2e279c4c191e566b6dd52082c532a7a4c5bb9f9ee75cd2c8327a3bc8f5944 linux/arm64 53d2e279c4c1 252MB 22 minutes ago
mtusi-messenger-lab4-postgres-1 postgres 17.11-alpine linux/arm64/v8 25a89970a832 291MB 6 weeks ago
mtusi-messenger-lab4-redis-1 redis 7.4.11-alpine linux/arm64/v8 ec4f171e9ff0 39.5MB 6 weeks ago
mtusi-messenger-lab4-s3-1 mtusi-messenger-s3 lab4 linux/arm64 bb740ce2c254 509MB 31 minutes ago
mtusi-messenger-lab4-s3-init-1 sha256 693fe62509aa4bc5ff409c715e21da0f894a2223d5b0ba57cdaab4303cc12145 linux/arm64 693fe62509aa 230MB 9 minutes ago
mtusi-messenger-lab4-s3-1 mtusi-messenger-s3 lab4 linux/arm64 bb740ce2c254 509MB 5 hours ago
mtusi-messenger-lab4-s3-init-1 sha256 53d2e279c4c191e566b6dd52082c532a7a4c5bb9f9ee75cd2c8327a3bc8f5944 linux/arm64 53d2e279c4c1 252MB 22 minutes ago
$ docker exec <api> pip freeze
annotated-doc==0.0.5
@@ -71,6 +71,7 @@ h11==0.16.0
idna==3.20
jmespath==1.1.0
opentelemetry-api==1.45.1
pillow==13.0.0
psycopg==3.3.6
psycopg-binary==3.3.6
psycopg-pool==3.3.3
+3 -3
View File
@@ -1,12 +1,12 @@
# SIGTERM через балансировщик
# дата: 2026-10-30T20:07Z, чистый clone
# дата: 2026-10-31T01:05Z, чистый clone
# стенд: Apple M3 Pro, 11 CPU, 18 GB RAM, macOS 26.1, Docker 29.3.0, Compose 5.1.0
$ python3 scripts/sigterm_check.py
$ docker kill --signal=SIGTERM abc646dd09cf
$ docker kill --signal=SIGTERM 504924bd9076
новых запросов после SIGTERM: 20, попало на останавливаемую реплику: 0
начатые до SIGTERM запросы: ['HTTP/1.1 201 Created']
из них завершила останавливаемая реплика: 3
процесс завершился за 1.73 с, код выхода 0
процесс завершился за 1.57 с, код выхода 0
PASS: остановка корректная и укладывается в 10 секунд
+35 -35
View File
@@ -1,5 +1,5 @@
# Индекс истории: EXPLAIN (ANALYZE, BUFFERS), объём данных в первой таблице вывода
# дата: 2026-10-30T20:07Z, чистый clone
# дата: 2026-10-31T01:05Z, чистый clone
# стенд: Apple M3 Pro, 11 CPU, 18 GB RAM, macOS 26.1, Docker 29.3.0, Compose 5.1.0
$ make explain
@@ -7,22 +7,22 @@ $ make explain
== Объём данных
messages_total | messages_in_chat | table_size | index_size
----------------+------------------+------------+------------
101045 | 10000 | 11 MB | 9544 kB
91163 | 10000 | 10120 kB | 8968 kB
(1 row)
== 1. Первая страница (limit 50, запрос берёт 51 строку)
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.42..729.05 rows=51 width=112) (actual time=0.028..0.228 rows=51 loops=1)
Buffers: shared hit=63
-> Index Scan using messages_chat_history_idx on messages (cost=0.42..142912.03 rows=10003 width=112) (actual time=0.023..0.219 rows=51 loops=1)
Limit (cost=0.42..726.39 rows=51 width=112) (actual time=0.031..0.253 rows=51 loops=1)
Buffers: shared hit=64
-> Index Scan using messages_chat_history_idx on messages (cost=0.42..145123.89 rows=10195 width=112) (actual time=0.031..0.249 rows=51 loops=1)
Index Cond: (chat_id = '00000000-0000-4000-8000-000000000100'::uuid)
Buffers: shared hit=63
Buffers: shared hit=64
SubPlan 1
-> Aggregate (cost=13.78..13.79 rows=1 width=32) (actual time=0.004..0.004 rows=1 loops=51)
Buffers: shared hit=54
-> Sort (cost=13.74..13.76 rows=6 width=20) (actual time=0.002..0.002 rows=0 loops=51)
-> Sort (cost=13.74..13.76 rows=6 width=20) (actual time=0.003..0.003 rows=0 loops=51)
Sort Key: a."position"
Sort Method: quicksort Memory: 25kB
Buffers: shared hit=54
@@ -33,24 +33,24 @@ $ make explain
Index Cond: (message_id = messages.id)
Buffers: shared hit=51
Planning:
Buffers: shared hit=76
Planning Time: 0.174 ms
Execution Time: 0.255 ms
Buffers: shared hit=78
Planning Time: 0.235 ms
Execution Time: 0.286 ms
(22 rows)
== 2. Страница из середины истории: keyset после 5000-го сообщения
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.42..738.40 rows=51 width=112) (actual time=0.013..0.198 rows=51 loops=1)
Limit (cost=0.42..735.98 rows=51 width=112) (actual time=0.017..0.251 rows=51 loops=1)
Buffers: shared hit=59
-> Index Scan using messages_chat_history_idx on messages (cost=0.42..101986.67 rows=7048 width=112) (actual time=0.013..0.196 rows=51 loops=1)
Index Cond: ((chat_id = '00000000-0000-4000-8000-000000000100'::uuid) AND (ROW(created_at, id) > ROW('2026-10-30 11:47:36.896462+00'::timestamp with time zone, '0c56411c-acb3-420b-bd20-5ac5ed7ab8a2'::uuid)))
-> Index Scan using messages_chat_history_idx on messages (cost=0.42..98594.86 rows=6836 width=112) (actual time=0.017..0.248 rows=51 loops=1)
Index Cond: ((chat_id = '00000000-0000-4000-8000-000000000100'::uuid) AND (ROW(created_at, id) > ROW('2026-10-30 16:45:29.612108+00'::timestamp with time zone, '6dacd396-f0bd-431e-8871-9e3bb7792539'::uuid)))
Buffers: shared hit=59
SubPlan 1
-> Aggregate (cost=13.78..13.79 rows=1 width=32) (actual time=0.003..0.003 rows=1 loops=51)
-> Aggregate (cost=13.78..13.79 rows=1 width=32) (actual time=0.004..0.004 rows=1 loops=51)
Buffers: shared hit=51
-> Sort (cost=13.74..13.76 rows=6 width=20) (actual time=0.002..0.002 rows=0 loops=51)
-> Sort (cost=13.74..13.76 rows=6 width=20) (actual time=0.003..0.003 rows=0 loops=51)
Sort Key: a."position"
Sort Method: quicksort Memory: 25kB
Buffers: shared hit=51
@@ -60,19 +60,19 @@ $ make explain
-> Bitmap Index Scan on message_attachments_pkey (cost=0.00..4.20 rows=6 width=0) (actual time=0.000..0.000 rows=0 loops=51)
Index Cond: (message_id = messages.id)
Buffers: shared hit=51
Planning Time: 0.045 ms
Execution Time: 0.232 ms
Planning Time: 0.052 ms
Execution Time: 0.291 ms
(20 rows)
== 3. Та же страница через OFFSET (так делать не стали)
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=71434.79..72163.43 rows=51 width=112) (actual time=5.082..5.132 rows=51 loops=1)
Buffers: shared hit=5552
-> Index Scan using messages_chat_history_idx on messages (cost=0.42..142912.03 rows=10003 width=112) (actual time=0.012..5.035 rows=5051 loops=1)
Limit (cost=71174.26..71900.24 rows=51 width=112) (actual time=6.185..6.246 rows=51 loops=1)
Buffers: shared hit=5551
-> Index Scan using messages_chat_history_idx on messages (cost=0.42..145123.89 rows=10195 width=112) (actual time=0.012..6.130 rows=5051 loops=1)
Index Cond: (chat_id = '00000000-0000-4000-8000-000000000100'::uuid)
Buffers: shared hit=5552
Buffers: shared hit=5551
SubPlan 1
-> Aggregate (cost=13.78..13.79 rows=1 width=32) (actual time=0.001..0.001 rows=1 loops=5051)
Buffers: shared hit=5051
@@ -86,26 +86,26 @@ $ make explain
-> Bitmap Index Scan on message_attachments_pkey (cost=0.00..4.20 rows=6 width=0) (actual time=0.000..0.000 rows=0 loops=5051)
Index Cond: (message_id = messages.id)
Buffers: shared hit=5051
Planning Time: 0.032 ms
Execution Time: 5.152 ms
Planning Time: 0.038 ms
Execution Time: 6.266 ms
(20 rows)
== 4. Запрос из пункта 2 без индекса messages_chat_history_idx (DROP INDEX внутри транзакции с ROLLBACK)
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=3400.42..4104.22 rows=51 width=112) (actual time=3.126..3.183 rows=51 loops=1)
Buffers: shared hit=1454
-> Result (cost=3400.42..100662.45 rows=7048 width=112) (actual time=3.125..3.180 rows=51 loops=1)
Buffers: shared hit=1454
-> Sort (cost=3400.42..3418.04 rows=7048 width=80) (actual time=3.098..3.100 rows=51 loops=1)
Limit (cost=3088.42..3792.21 rows=51 width=112) (actual time=3.362..3.425 rows=51 loops=1)
Buffers: shared hit=1322
-> Result (cost=3088.42..97424.85 rows=6836 width=112) (actual time=3.362..3.422 rows=51 loops=1)
Buffers: shared hit=1322
-> Sort (cost=3088.42..3105.51 rows=6836 width=80) (actual time=3.343..3.345 rows=51 loops=1)
Sort Key: messages.created_at, messages.id
Sort Method: top-N heapsort Memory: 31kB
Buffers: shared hit=1403
-> Seq Scan on messages (cost=0.00..3165.29 rows=7048 width=80) (actual time=1.800..2.874 rows=5000 loops=1)
Filter: ((chat_id = '00000000-0000-4000-8000-000000000100'::uuid) AND (ROW(created_at, id) > ROW('2026-10-30 11:47:36.896462+00'::timestamp with time zone, '0c56411c-acb3-420b-bd20-5ac5ed7ab8a2'::uuid)))
Rows Removed by Filter: 96045
Buffers: shared hit=1397
Buffers: shared hit=1271
-> Seq Scan on messages (cost=0.00..2860.35 rows=6836 width=80) (actual time=1.866..3.076 rows=5000 loops=1)
Filter: ((chat_id = '00000000-0000-4000-8000-000000000100'::uuid) AND (ROW(created_at, id) > ROW('2026-10-30 16:45:29.612108+00'::timestamp with time zone, '6dacd396-f0bd-431e-8871-9e3bb7792539'::uuid)))
Rows Removed by Filter: 86163
Buffers: shared hit=1265
SubPlan 1
-> Aggregate (cost=13.78..13.79 rows=1 width=32) (actual time=0.001..0.001 rows=1 loops=51)
Buffers: shared hit=51
@@ -121,8 +121,8 @@ $ make explain
Buffers: shared hit=51
Planning:
Buffers: shared hit=4
Planning Time: 0.050 ms
Execution Time: 3.202 ms
Planning Time: 0.057 ms
Execution Time: 3.455 ms
(29 rows)
+25 -23
View File
@@ -3,22 +3,22 @@
"mode": "stop",
"rounds": [
{
"seconds": 17.89,
"successful_requests": 10761,
"seconds": 18.19,
"successful_requests": 8333,
"failed_attempts": 0,
"failed_statuses": [],
"successful_rps": 601.6,
"longest_gap_between_successes_s": 1.027,
"first_success_after_action_s": 0.003,
"last_success_on_target_after_action_s": 12.886,
"successful_rps": 458.1,
"longest_gap_between_successes_s": 0.997,
"first_success_after_action_s": 0.004,
"last_success_on_target_after_action_s": 13.188,
"instances_seen": 2,
"target": "b4e0f5de7608",
"target": "e0ce1c223b49",
"signal": "SIGTERM",
"stop_command_s": 0.59,
"excluded_by_lb_after_s": 0.9,
"excluded_by_lb_after_s": 1.63,
"verify": {
"confirmed": 10761,
"in_history": 10761,
"confirmed": 8333,
"in_history": 8333,
"lost_confirmed": 0,
"duplicate_ids": 0,
"duplicate_texts": 0,
@@ -26,22 +26,24 @@
}
},
{
"seconds": 19.96,
"successful_requests": 11872,
"failed_attempts": 0,
"failed_statuses": [],
"successful_rps": 594.9,
"longest_gap_between_successes_s": 1.015,
"first_success_after_action_s": 0.0,
"last_success_on_target_after_action_s": 14.955,
"seconds": 19.85,
"successful_requests": 9258,
"failed_attempts": 1,
"failed_statuses": [
502
],
"successful_rps": 466.3,
"longest_gap_between_successes_s": 1.016,
"first_success_after_action_s": 0.005,
"last_success_on_target_after_action_s": 14.853,
"instances_seen": 2,
"target": "6f14dc16ebf3",
"target": "6e7001b3af3a",
"signal": "SIGTERM",
"stop_command_s": 0.61,
"excluded_by_lb_after_s": 1.51,
"stop_command_s": 0.66,
"excluded_by_lb_after_s": 0.78,
"verify": {
"confirmed": 11872,
"in_history": 11872,
"confirmed": 9258,
"in_history": 9258,
"lost_confirmed": 0,
"duplicate_ids": 0,
"duplicate_texts": 0,
+12 -12
View File
@@ -3,28 +3,28 @@
"mode": "rolling",
"rounds": [
{
"seconds": 25.51,
"successful_requests": 17974,
"seconds": 24.77,
"successful_requests": 13125,
"failed_attempts": 0,
"failed_statuses": [],
"successful_rps": 704.5,
"longest_gap_between_successes_s": 1.001,
"first_success_after_action_s": 0.003,
"successful_rps": 529.8,
"longest_gap_between_successes_s": 0.995,
"first_success_after_action_s": 0.0,
"last_success_on_target_after_action_s": null,
"instances_seen": 4,
"update_seconds": 15.51,
"update_seconds": 14.77,
"containers_before": {
"b4e0f5de7608": "sha256:693fe62509aa",
"6f14dc16ebf3": "sha256:693fe62509aa"
"e0ce1c223b49": "sha256:53d2e279c4c1",
"6e7001b3af3a": "sha256:53d2e279c4c1"
},
"containers_after": {
"abc646dd09cf": "sha256:bdbd0270135d",
"d7f52b7d6c23": "sha256:bdbd0270135d"
"504924bd9076": "sha256:e71bfdb1c725",
"ec77c0e85d5c": "sha256:e71bfdb1c725"
},
"app_version": "2",
"verify": {
"confirmed": 17974,
"in_history": 17974,
"confirmed": 13125,
"in_history": 13125,
"lost_confirmed": 0,
"duplicate_ids": 0,
"duplicate_texts": 0,
+49 -26
View File
@@ -1,74 +1,97 @@
{
"limit_per_replica_mib": 256,
"limit_per_replica_mib": 512,
"replicas": 2,
"levels": [
{
"parallel_uploads": 0,
"memory": {
"abc646dd09cf": {
"process_peak_rss_mib": 117.2,
"504924bd9076": {
"process_peak_rss_mib": 116.8,
"cgroup_peak_mib": 110.5
},
"d7f52b7d6c23": {
"process_peak_rss_mib": 117.1,
"ec77c0e85d5c": {
"process_peak_rss_mib": 116.6,
"cgroup_peak_mib": 110.2
}
}
},
{
"file": "PNG 10 MiB",
"parallel_uploads": 1,
"file_bytes": 10481664,
"seconds": 0.48,
"slowest_upload_s": 0.48,
"seconds": 0.14,
"slowest_upload_s": 0.14,
"statuses": {
"201": 1
},
"memory": {
"abc646dd09cf": {
"504924bd9076": {
"process_peak_rss_mib": 117.2,
"cgroup_peak_mib": 110.5
},
"d7f52b7d6c23": {
"process_peak_rss_mib": 117.5,
"ec77c0e85d5c": {
"process_peak_rss_mib": 116.6,
"cgroup_peak_mib": 110.2
}
}
},
{
"file": "PNG 10 MiB",
"parallel_uploads": 10,
"file_bytes": 10481664,
"seconds": 3.87,
"slowest_upload_s": 3.87,
"seconds": 2.1,
"slowest_upload_s": 2.09,
"statuses": {
"201": 10
},
"memory": {
"abc646dd09cf": {
"process_peak_rss_mib": 124.3,
"cgroup_peak_mib": 163.7
"504924bd9076": {
"process_peak_rss_mib": 123.7,
"cgroup_peak_mib": 166.6
},
"d7f52b7d6c23": {
"process_peak_rss_mib": 124.1,
"cgroup_peak_mib": 164.1
"ec77c0e85d5c": {
"process_peak_rss_mib": 123.5,
"cgroup_peak_mib": 160.5
}
}
},
{
"file": "PNG 10 MiB",
"parallel_uploads": 30,
"file_bytes": 10481664,
"seconds": 6.43,
"slowest_upload_s": 6.42,
"seconds": 5.88,
"slowest_upload_s": 5.88,
"statuses": {
"201": 30
},
"memory": {
"abc646dd09cf": {
"process_peak_rss_mib": 127.3,
"cgroup_peak_mib": 256.0
"504924bd9076": {
"process_peak_rss_mib": 128.8,
"cgroup_peak_mib": 274.4
},
"d7f52b7d6c23": {
"process_peak_rss_mib": 126.9,
"cgroup_peak_mib": 256.0
"ec77c0e85d5c": {
"process_peak_rss_mib": 128.3,
"cgroup_peak_mib": 273.9
}
}
},
{
"file": "прогрессивный CMYK JPEG, 40 млн пикселей",
"parallel_uploads": 10,
"file_bytes": 2642657,
"seconds": 1.45,
"slowest_upload_s": 1.44,
"statuses": {
"201": 10
},
"memory": {
"504924bd9076": {
"process_peak_rss_mib": 437.6,
"cgroup_peak_mib": 433.8
},
"ec77c0e85d5c": {
"process_peak_rss_mib": 437.3,
"cgroup_peak_mib": 433.0
}
}
}