ЛР 4 — БПИ2303 — Щербаков — на 3

This commit is contained in:
2026-11-13 14:02:00 +03:00
parent ec540a1a72
commit 125a5e6409
39 changed files with 2112 additions and 50 deletions
+13
View File
@@ -3,3 +3,16 @@
Храните небольшие обезличенные результаты: команды и stdout проверок, JSON/CSV агрегатов нагрузки, EXPLAIN, dashboard JSON, текст разбора отказа. Укажите дату, commit, аппаратные лимиты и профиль нагрузки.
Не добавляйте .env, session tokens, cookies, приватные ключи, credentials, реальные сообщения, raw dumps и signed URLs. Для скриншотов скрывайте секреты. Большие логи/бинарные traces сохраняйте отдельно по правилам преподавателя; одного скриншота без методики недостаточно.
## ??????????? ???????? ??????? ?? 3
- [grade3-checks.txt](grade3-checks.txt) ? smoke, 21 ?????????????? ??????????? ????,
????????, inspect, persistence, ????????? ??????????? API, private S3,
?????/?????????????? S3 ? failover ????? API.
- [final-checks.txt](final-checks.txt) ? ????????? ??????, smoke, ??? 23 ???????????
????? (????????? ?????? ??????? 10 MiB ? 40 ??? ????????), runtime dependencies,
????????? ???????? ? ???????????? ?????????? ?????????/tests ???????????? Git.
??????? ??????????????? ??????? ??????: `python scripts/verify.py --base-url
http://127.0.0.1:18084 --output evidence/grade3-checks.txt`.
+58
View File
@@ -0,0 +1,58 @@
UTC 2026-11-13T10:54:55.166348+00:00
COMMAND C:\Python312\python.exe scripts/check_contract.py
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
COMMAND C:\Python312\python.exe tests/smoke.py --base-url http://127.0.0.1:18084
PASS: lab4 public API scenario; infrastructure and grading evidence remain separate.
COMMAND C:\Python312\python.exe -m unittest discover -s student-tests -v
test_access_before_payload_validation (test_api.API.test_access_before_payload_validation) ... ok
test_bad_credentials_and_schemes (test_api.API.test_bad_credentials_and_schemes) ... ok
test_chat_atomic_invalid_members (test_api.API.test_chat_atomic_invalid_members) ... ok
test_concurrent_messages_and_keyset (test_api.API.test_concurrent_messages_and_keyset) ... ok
test_cursor_scope_and_tampering (test_api.API.test_cursor_scope_and_tampering) ... ok
test_json_and_sender_validation (test_api.API.test_json_and_sender_validation) ... ok
test_logout_only_revokes_current_session (test_api.API.test_logout_only_revokes_current_session) ... ok
test_registration_validation (test_api.API.test_registration_validation) ... ok
test_unicode_password_with_colon_and_max_length (test_api.API.test_unicode_password_with_colon_and_max_length) ... ok
test_username_race (test_api.API.test_username_race) ... ok
test_acl_before_image_validation (test_attachments.Attachments.test_acl_before_image_validation) ... ok
test_attachment_scope_and_idempotency (test_attachments.Attachments.test_attachment_scope_and_idempotency) ... ok
test_byte_limit_before_reading_body (test_attachments.Attachments.test_byte_limit_before_reading_body) ... ok
test_exactly_40_million_pixels_accepted (test_attachments.Attachments.test_exactly_40_million_pixels_accepted) ... ok
test_filename (test_attachments.Attachments.test_filename) ... ok
test_image_validation (test_attachments.Attachments.test_image_validation) ... ok
test_jpeg_original_and_truncation (test_attachments.Attachments.test_jpeg_original_and_truncation) ... ok
test_maximum_byte_size_accepted (test_attachments.Attachments.test_maximum_byte_size_accepted) ... ok
test_original_and_message_shared_with_member (test_attachments.Attachments.test_original_and_message_shared_with_member) ... ok
test_conflicting_bodies_race (test_idempotency.Idempotency.test_conflicting_bodies_race) ... ok
test_invalid_keys_and_no_cached_error (test_idempotency.Idempotency.test_invalid_keys_and_no_cached_error) ... ok
test_key_scope_and_access (test_idempotency.Idempotency.test_key_scope_and_access) ... ok
test_same_key_concurrent_across_replicas (test_idempotency.Idempotency.test_same_key_concurrent_across_replicas) ... PASS: concurrent_retries=12 observed_replicas=2 committed_messages=1
ok
----------------------------------------------------------------------
Ran 23 tests in 32.470s
OK
COMMAND docker compose --env-file .env exec -T api1 python -m pip freeze
WARNING: The directory '/home/messenger/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you should use sudo's -H flag.
boto3==1.40.61
botocore==1.40.76
jmespath==1.1.0
pillow==12.0.0
psycopg==3.2.6
psycopg-binary==3.2.6
psycopg-pool==3.2.6
python-dateutil==2.9.0.post0
s3transfer==0.14.0
six==1.17.0
typing_extensions==4.16.0
urllib3==2.8.0
COMMAND docker compose --env-file .env ps
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
mtusi2026lab4-api1-1 mtusi2026lab4-api:local "python -m src.server" api1 About a minute ago Up About a minute (healthy) 8080/tcp
mtusi2026lab4-api2-1 mtusi2026lab4-api:local "python -m src.server" api2 About a minute ago Up About a minute (healthy) 8080/tcp
mtusi2026lab4-lb-1 haproxy:3.0.11-alpine "docker-entrypoint.s…" lb 7 minutes ago Up 5 minutes 127.0.0.1:18084->8080/tcp
mtusi2026lab4-postgres-1 postgres:16.10-bookworm "docker-entrypoint.s…" postgres 7 minutes ago Up 5 minutes (healthy) 5432/tcp
mtusi2026lab4-s3-1 chrislusf/seaweedfs:3.85 "/entrypoint.sh serv…" s3 7 minutes ago Up 4 minutes 7333/tcp, 8080/tcp, 8333/tcp, 8888/tcp, 9333/tcp, 18080/tcp, 18888/tcp, 19333/tcp
COMMAND git -c safe.directory=C:/Users/marks/Desktop/vp/mtusi2026lab4 diff --exit-code -- README.md COURSE.md contracts tests
PASS: final source, smoke, all 23 student tests, runtime dependencies and unchanged public contract/tests
+65
View File
@@ -0,0 +1,65 @@
UTC 2026-11-13T10:49:10.611207+00:00
COMMAND python scripts/verify.py --base-url http://127.0.0.1:18084
Client=29.5.3 Server=29.5.3
Docker CPUs=8 memory_bytes=2967707648 OS=Docker Desktop
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
PASS: lab4 public API scenario; infrastructure and grading evidence remain separate.
test_access_before_payload_validation (test_api.API.test_access_before_payload_validation) ... ok
test_bad_credentials_and_schemes (test_api.API.test_bad_credentials_and_schemes) ... ok
test_chat_atomic_invalid_members (test_api.API.test_chat_atomic_invalid_members) ... ok
test_concurrent_messages_and_keyset (test_api.API.test_concurrent_messages_and_keyset) ... ok
test_cursor_scope_and_tampering (test_api.API.test_cursor_scope_and_tampering) ... ok
test_json_and_sender_validation (test_api.API.test_json_and_sender_validation) ... ok
test_logout_only_revokes_current_session (test_api.API.test_logout_only_revokes_current_session) ... ok
test_registration_validation (test_api.API.test_registration_validation) ... ok
test_unicode_password_with_colon_and_max_length (test_api.API.test_unicode_password_with_colon_and_max_length) ... ok
test_username_race (test_api.API.test_username_race) ... ok
test_acl_before_image_validation (test_attachments.Attachments.test_acl_before_image_validation) ... ok
test_attachment_scope_and_idempotency (test_attachments.Attachments.test_attachment_scope_and_idempotency) ... ok
test_byte_limit_before_reading_body (test_attachments.Attachments.test_byte_limit_before_reading_body) ... ok
test_filename (test_attachments.Attachments.test_filename) ... ok
test_image_validation (test_attachments.Attachments.test_image_validation) ... ok
test_jpeg_original_and_truncation (test_attachments.Attachments.test_jpeg_original_and_truncation) ... ok
test_original_and_message_shared_with_member (test_attachments.Attachments.test_original_and_message_shared_with_member) ... ok
test_conflicting_bodies_race (test_idempotency.Idempotency.test_conflicting_bodies_race) ... ok
test_invalid_keys_and_no_cached_error (test_idempotency.Idempotency.test_invalid_keys_and_no_cached_error) ... ok
test_key_scope_and_access (test_idempotency.Idempotency.test_key_scope_and_access) ... ok
test_same_key_concurrent_across_replicas (test_idempotency.Idempotency.test_same_key_concurrent_across_replicas) ... PASS: concurrent_retries=12 observed_replicas=2 committed_messages=1
ok
----------------------------------------------------------------------
Ran 21 tests in 29.448s
OK
OBSERVED_INSTANCES ["api1-a65e7971cde3", "api2-ee7a40d9d441"]
Container mtusi2026lab4-migrate-run-3fcdaacd95b0 Creating
Container mtusi2026lab4-migrate-run-3fcdaacd95b0 Created
PASS: migrations applied
Container mtusi2026lab4-migrate-run-5309164ddf9e Creating
Container mtusi2026lab4-migrate-run-5309164ddf9e Created
PASS: migrations applied
PASS: repeated migrations preserve all table counts 71|26|49|57|68|57|3|5
BEFORE_RESTART {"api1": {"id": "82d506213800", "status": "running", "started_at": "2026-11-13T10:48:35.085906013Z", "volumes": [], "ports": {}, "memory_limit": 536870912, "nano_cpus": 1000000000}, "api2": {"id": "65158cbc104d", "status": "running", "started_at": "2026-11-13T10:48:35.090231302Z", "volumes": [], "ports": {}, "memory_limit": 536870912, "nano_cpus": 1000000000}, "postgres": {"id": "337a801d2d8d", "status": "running", "started_at": "2026-11-13T10:48:08.472177118Z", "volumes": ["mtusi2026lab4_postgres_data"], "ports": {}, "memory_limit": 268435456, "nano_cpus": 1000000000}, "s3": {"id": "dabae5d269ac", "status": "running", "started_at": "2026-11-13T10:48:08.462152899Z", "volumes": ["mtusi2026lab4_s3_data"], "ports": {}, "memory_limit": 536870912, "nano_cpus": 1000000000}, "lb": {"id": "3288ada2b3b9", "status": "running", "started_at": "2026-11-13T10:48:41.912294259Z", "volumes": [], "ports": {"8080/tcp": [{"HostIp": "127.0.0.1", "HostPort": "18084"}]}, "memory_limit": 134217728, "nano_cpus": 500000000}}
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
AFTER_RESTART {"api1": {"id": "82d506213800", "status": "running", "started_at": "2026-11-13T10:50:04.482195882Z", "volumes": [], "ports": {}, "memory_limit": 536870912, "nano_cpus": 1000000000}, "api2": {"id": "65158cbc104d", "status": "running", "started_at": "2026-11-13T10:50:04.40460967Z", "volumes": [], "ports": {}, "memory_limit": 536870912, "nano_cpus": 1000000000}, "postgres": {"id": "337a801d2d8d", "status": "running", "started_at": "2026-11-13T10:50:04.716428682Z", "volumes": ["mtusi2026lab4_postgres_data"], "ports": {}, "memory_limit": 268435456, "nano_cpus": 1000000000}, "s3": {"id": "dabae5d269ac", "status": "running", "started_at": "2026-11-13T10:50:04.907037089Z", "volumes": ["mtusi2026lab4_s3_data"], "ports": {}, "memory_limit": 536870912, "nano_cpus": 1000000000}, "lb": {"id": "3288ada2b3b9", "status": "running", "started_at": "2026-11-13T10:50:04.291720252Z", "volumes": [], "ports": {"8080/tcp": [{"HostIp": "127.0.0.1", "HostPort": "18084"}]}, "memory_limit": 134217728, "nano_cpus": 500000000}}
PASS: five containers restarted; volume, sessions, cursor and idempotency result preserved
UPLOAD_FAILOVER {"stopped": "api1-bf729723a3ad", "download_instance": "api2-c0d733cf173b", "sha256": "99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75", "message_id": "132a8a9f-aab2-4e08-ba11-6cc489acd306"}
UPLOAD_FAILOVER {"stopped": "api2-c0d733cf173b", "download_instance": "api1-a18496561062", "sha256": "99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75", "message_id": "293f8515-01cc-4360-b87d-d923f6e8d928"}
PASS: anonymous S3 GET of existing object denied (403)
PASS: S3 down: live=200 ready=503 metadata=200 download=503 upload=503
PASS: S3 recovered; original bytes preserved; failed upload created no metadata
FAILOVER_RUN 1
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
{"observed_instances_before": 2, "successful_writes": 97, "failed_attempts": 0, "first_recovery_seconds": 3.844}
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
AFTER_FAILOVER {"api1": {"id": "82d506213800", "status": "exited", "started_at": "2026-11-13T10:50:44.539901416Z", "volumes": [], "ports": {}, "memory_limit": 536870912, "nano_cpus": 1000000000}, "api2": {"id": "65158cbc104d", "status": "running", "started_at": "2026-11-13T10:51:02.755073452Z", "volumes": [], "ports": {}, "memory_limit": 536870912, "nano_cpus": 1000000000}, "postgres": {"id": "337a801d2d8d", "status": "running", "started_at": "2026-11-13T10:50:04.716428682Z", "volumes": ["mtusi2026lab4_postgres_data"], "ports": {}, "memory_limit": 268435456, "nano_cpus": 1000000000}, "s3": {"id": "dabae5d269ac", "status": "running", "started_at": "2026-11-13T10:51:31.425009302Z", "volumes": ["mtusi2026lab4_s3_data"], "ports": {}, "memory_limit": 536870912, "nano_cpus": 1000000000}, "lb": {"id": "3288ada2b3b9", "status": "running", "started_at": "2026-11-13T10:50:04.291720252Z", "volumes": [], "ports": {"8080/tcp": [{"HostIp": "127.0.0.1", "HostPort": "18084"}]}, "memory_limit": 134217728, "nano_cpus": 500000000}}
CONCURRENT_READS {"ok": 148, "errors": 1}
FAILOVER_RUN 2
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
{"observed_instances_before": 2, "successful_writes": 96, "failed_attempts": 0, "first_recovery_seconds": 4.75}
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
AFTER_FAILOVER {"api1": {"id": "82d506213800", "status": "running", "started_at": "2026-11-13T10:52:31.531295764Z", "volumes": [], "ports": {}, "memory_limit": 536870912, "nano_cpus": 1000000000}, "api2": {"id": "65158cbc104d", "status": "exited", "started_at": "2026-11-13T10:51:02.755073452Z", "volumes": [], "ports": {}, "memory_limit": 536870912, "nano_cpus": 1000000000}, "postgres": {"id": "337a801d2d8d", "status": "running", "started_at": "2026-11-13T10:50:04.716428682Z", "volumes": ["mtusi2026lab4_postgres_data"], "ports": {}, "memory_limit": 268435456, "nano_cpus": 1000000000}, "s3": {"id": "dabae5d269ac", "status": "running", "started_at": "2026-11-13T10:51:31.425009302Z", "volumes": ["mtusi2026lab4_s3_data"], "ports": {}, "memory_limit": 536870912, "nano_cpus": 1000000000}, "lb": {"id": "3288ada2b3b9", "status": "running", "started_at": "2026-11-13T10:50:04.291720252Z", "volumes": [], "ports": {"8080/tcp": [{"HostIp": "127.0.0.1", "HostPort": "18084"}]}, "memory_limit": 134217728, "nano_cpus": 500000000}}
CONCURRENT_READS {"ok": 145, "errors": 1}
PASS: each API stopped separately; reads/writes and original session survive; both replicas restored; S3 bytes checked
PASS: grade-3 verification complete