forked from mtusi2026/mtusi2026lab4
reconcile-inject.sh wrote an orphan under a key whose uuid differed from the id it printed, so the demo could only compare counts; it now uses one uuid for both, and the dry-run check compares the found and the injected sets per class. The heal step returns the original bytes under one quarantined key and random bytes of the same length under another, and checks that only the first leaves the quarantine. The load phase sums rechecked over its passes, and a new step stops a pass hanging on a paused S3 with docker stop and checks exit code 143 within seconds and a free lock afterwards. reconcile_track.py cost clears the run files of the previous series and measures 1k, 10k, 30k and 100k with --deep everywhere. The scenarios record date, commit and docker inspect of the replicas or of S3 at the moment they are down. make load-evidence and make clean-clone-evidence rerun the message load and the clean clone block with raw output, and make upload-memory passes ARGS to reproduce the run directories. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V1d3RLHNBBMA6UqBLLJv27
206 lines
7.9 KiB
Makefile
206 lines
7.9 KiB
Makefile
PYTHON ?= python3
|
||
BASE_URL ?= http://$(shell docker compose port lb 8080 2>/dev/null || echo localhost:8080)
|
||
CA_FILE ?=
|
||
ACTION_SCRIPT ?=
|
||
TLS_ARGS = $(if $(CA_FILE),--ca-file "$(CA_FILE)",)
|
||
|
||
VENV ?= .venv
|
||
UV ?= uv
|
||
COMPOSE ?= docker compose
|
||
RATE ?= 100
|
||
FROM_REV ?=
|
||
SHIFT ?= 0
|
||
SCRIPTS_PY = scripts/probe.py scripts/limits.py scripts/lab4_scenarios.py scripts/lab4_seed.py \
|
||
scripts/upload_memory.py scripts/reconcile_check.py scripts/reconcile_track.py
|
||
SCENARIO ?= failover-upload
|
||
PSQL = $(COMPOSE) exec -T postgres psql -U messenger -d messenger -X -q
|
||
PYTEST_ARGS ?=
|
||
|
||
.PHONY: help check validate test load test-persistence test-failover \
|
||
install lint format typecheck student-test \
|
||
secrets up down reset-data migrate ps logs restore lb-check failover-evidence stack-evidence \
|
||
persistence-evidence storage-evidence cache-evidence test-faults faults-evidence seed explain retry-check \
|
||
limits detection failover-each rolling-update level4 \
|
||
scenario s3-check attachments-evidence upload-faults upload-memory \
|
||
reconcile reconcile-demo reconcile-cost load-evidence clean-clone-evidence
|
||
|
||
help:
|
||
@echo "check: offline structure; validate: full OpenAPI (requirements-dev.txt); test: running API; load: synthetic writes"
|
||
@echo "install/lint/typecheck/student-test: студенческий тулчейн"
|
||
@echo "secrets/up/down/migrate/ps/logs: стенд Docker Compose; reset-data: намеренное удаление volumes"
|
||
@echo "restore: вернуть остановленные реплики; lb-check: реплики на одном токене и 20 гонок одного ключа"
|
||
@echo "retry-check: потерянный ответ на живой и на убитой реплике, повтор тем же ключом"
|
||
@echo "level4 = limits, lb-check, detection, failover-each, rolling-update [FROM_REV=<коммит>]; RATE=$(RATE) rps"
|
||
@echo "scenario SCENARIO=failover-upload|s3-outage → evidence/<сценарий>.json; s3-check; attachments-evidence"
|
||
@echo "upload-faults: негативный suite, компенсация, уборка, обрыв и зависание загрузки против стенда"
|
||
@echo "upload-memory ARGS='--out evidence/upload-memory/runN': пик памяти реплик при 10/20/40 загрузках 1 и 10 MiB"
|
||
@echo "load-evidence: tests/load.py ×3 клиентом-контейнером в сети edge стенда → evidence/load.txt, evidence/load/"
|
||
@echo "clean-clone-evidence: блок «Запуск из чистого clone» в свежем клоне рядом → evidence/clean-clone.txt"
|
||
@echo "reconcile ARGS='--apply --deep': сверка PostgreSQL ↔ S3 (без ARGS — dry-run); трек 2:"
|
||
@echo "reconcile-demo: внедрение ошибок, dry-run/apply/повтор, безопасность, нагрузка → evidence/reconcile/"
|
||
@echo "reconcile-cost: стоимость обхода 1k/10k/30k/100k объектов × 3 прогона на чистом стенде → evidence/reconcile/cost/"
|
||
@echo "BASE_URL=$(BASE_URL) (порт lb из docker compose); failover-evidence SHIFT=1 — сдвиг round robin на вторую реплику"
|
||
|
||
check:
|
||
$(PYTHON) scripts/check_contract.py
|
||
|
||
validate: PYTHON := $(if $(wildcard $(VENV)/bin/python),$(VENV)/bin/python,$(PYTHON))
|
||
validate:
|
||
$(PYTHON) scripts/validate_openapi.py
|
||
|
||
test:
|
||
$(PYTHON) tests/smoke.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||
|
||
load:
|
||
$(PYTHON) tests/load.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||
|
||
test-persistence:
|
||
@test -n "$(ACTION_SCRIPT)" || (echo "Set ACTION_SCRIPT to your implemented executable restart hook"; exit 2)
|
||
$(PYTHON) tests/resilience.py --mode persistence --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||
|
||
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)
|
||
|
||
install:
|
||
$(UV) sync --group dev
|
||
|
||
lint:
|
||
$(VENV)/bin/ruff check src student-tests $(SCRIPTS_PY)
|
||
$(VENV)/bin/ruff format --check src student-tests $(SCRIPTS_PY)
|
||
$(VENV)/bin/ty check src student-tests
|
||
|
||
format:
|
||
$(VENV)/bin/ruff check --fix src student-tests $(SCRIPTS_PY)
|
||
$(VENV)/bin/ruff format src student-tests $(SCRIPTS_PY)
|
||
|
||
typecheck:
|
||
$(VENV)/bin/ty check src student-tests
|
||
|
||
student-test:
|
||
$(VENV)/bin/pytest $(PYTEST_ARGS)
|
||
|
||
secrets:
|
||
sh scripts/secrets.sh
|
||
|
||
up: secrets
|
||
$(COMPOSE) up -d --build --wait
|
||
scripts/lb-wait.sh
|
||
|
||
down:
|
||
$(COMPOSE) --profile bench --profile tools --profile reconcile down
|
||
|
||
reset-data:
|
||
@echo "Удаляются volumes с учебными данными стенда"
|
||
$(COMPOSE) --profile bench --profile tools --profile reconcile down -v --remove-orphans
|
||
|
||
migrate:
|
||
$(COMPOSE) run --rm migrate
|
||
|
||
ps:
|
||
$(COMPOSE) ps
|
||
|
||
logs:
|
||
$(COMPOSE) logs --tail 200
|
||
|
||
restore:
|
||
scripts/restore.sh
|
||
|
||
lb-check:
|
||
$(PYTHON) scripts/probe.py check --rounds 20 --out evidence/lb-check.json
|
||
|
||
retry-check:
|
||
$(PYTHON) scripts/probe.py retry --out evidence/retry.json
|
||
|
||
limits:
|
||
$(PYTHON) scripts/limits.py --out evidence/limits.txt
|
||
|
||
detection:
|
||
rm -rf evidence/detection
|
||
for run in 1 2 3; do sh scripts/detection.sh evidence/detection/run$$run || exit 1; done
|
||
|
||
failover-each:
|
||
RATE=$(RATE) sh scripts/failover-each.sh evidence/failover-each
|
||
|
||
rolling-update:
|
||
ifneq ($(FROM_REV),)
|
||
git archive "$(FROM_REV)" | docker build -q -t "mtusi-messenger:$(FROM_REV)" -
|
||
API_IMAGE="mtusi-messenger:$(FROM_REV)" $(COMPOSE) up -d --no-deps --force-recreate --wait api
|
||
scripts/lb-wait.sh
|
||
endif
|
||
$(COMPOSE) build -q api
|
||
RATE=$(RATE) $(PYTHON) scripts/probe.py load --expect replace --duration 90 \
|
||
--out evidence/rolling$(if $(FROM_REV),-from-$(FROM_REV)) \
|
||
-- scripts/rolling-update.sh
|
||
|
||
level4: limits lb-check detection failover-each rolling-update
|
||
|
||
scenario:
|
||
$(PYTHON) scripts/lab4_scenarios.py $(SCENARIO) --base-url "$(BASE_URL)" --restore --output evidence/$(SCENARIO).json
|
||
scripts/lb-wait.sh
|
||
|
||
s3-check:
|
||
sh scripts/s3-check.sh > evidence/s3-security.txt; status=$$?; cat evidence/s3-security.txt; exit $$status
|
||
|
||
attachments-evidence:
|
||
sh scripts/evidence-attachments.sh
|
||
|
||
upload-faults:
|
||
{ echo "date: $$(date -u +%FT%TZ) commit: $$(git rev-parse --short HEAD) BASE_URL=$(BASE_URL)"; \
|
||
BASE_URL="$(BASE_URL)" $(VENV)/bin/pytest -m stack -v -s --no-header --tb=short \
|
||
-p no:cacheprovider student-tests/stack/test_attachment_faults.py; } > evidence/upload-faults.txt; \
|
||
status=$$?; cat evidence/upload-faults.txt; exit $$status
|
||
|
||
upload-memory:
|
||
$(PYTHON) scripts/upload_memory.py --base-url "$(BASE_URL)" $(ARGS)
|
||
|
||
load-evidence:
|
||
sh scripts/load-evidence.sh
|
||
|
||
clean-clone-evidence:
|
||
sh scripts/clean-clone.sh
|
||
|
||
reconcile:
|
||
$(COMPOSE) run --rm --no-deps reconciler $(ARGS)
|
||
|
||
reconcile-demo:
|
||
$(PYTHON) scripts/reconcile_track.py demo --base-url "$(BASE_URL)"
|
||
|
||
reconcile-cost:
|
||
$(PYTHON) scripts/reconcile_track.py cost $(ARGS)
|
||
|
||
failover-evidence:
|
||
sh scripts/failover-evidence.sh "$(BASE_URL)" "$(SHIFT)"
|
||
|
||
stack-evidence:
|
||
sh scripts/evidence-stack.sh
|
||
|
||
persistence-evidence:
|
||
sh scripts/persistence-evidence.sh "$(BASE_URL)" > evidence/persistence.txt
|
||
cat evidence/persistence.txt
|
||
|
||
storage-evidence:
|
||
sh scripts/evidence-storage.sh
|
||
|
||
cache-evidence:
|
||
sh scripts/evidence-cache.sh > evidence/cache.txt
|
||
cat evidence/cache.txt
|
||
|
||
test-faults:
|
||
BASE_URL="$(BASE_URL)" $(VENV)/bin/pytest -m stack -v -s student-tests/stack
|
||
|
||
faults-evidence:
|
||
{ echo "date: $$(date -u +%FT%TZ) commit: $$(git rev-parse --short HEAD)"; echo "\$$ make test-faults"; \
|
||
$(MAKE) --no-print-directory test-faults 2>&1; } | sed 's#$(CURDIR)#<repo>#g' > evidence/faults.txt
|
||
cat evidence/faults.txt
|
||
grep -qE '^=+ [0-9]+ passed in' evidence/faults.txt
|
||
|
||
seed:
|
||
$(PSQL) -f - < scripts/sql/seed-history.sql
|
||
|
||
explain: seed
|
||
{ echo "date: $$(date -u +%FT%TZ) commit: $$(git rev-parse --short HEAD)"; \
|
||
echo "\$$ make explain # scripts/sql/explain-history.sql"; \
|
||
$(PSQL) -f - < scripts/sql/explain-history.sql; } > evidence/explain-history.txt
|
||
cat evidence/explain-history.txt
|