Bring the stdlib suite and image generator of the lab 5 preparation: make suite-preflight checks services, readiness, schema columns, broker topology and the faults override, and make level3 runs the grade 3 scenarios (smoke through the pipeline, worker down with API, relay and broker restarts, duplicate delivery after ready, poison image, S3 outage with recovery, retries up to JOB_MAX_ATTEMPTS) and checks the invariants into evidence/level3.json. make pipeline-evidence shows the queued job on the broker while the worker is stopped, its properties and contract payload, the 409 before ready and SIGTERM of the relay and the worker; make topology dumps queues, consumers with prefetch, permissions and users. The lab 4 failover and S3 outage scenarios and the upload fault suite now expect 202 and wait for ready, the stack evidence lists the broker and its client packages, and the CI acceptance job runs the pipeline scenarios and the SIGTERM check of the new processes. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
214 lines
7.4 KiB
Makefile
214 lines
7.4 KiB
Makefile
PYTHON ?= python3
|
|
BASE_URL ?= http://localhost:8080
|
|
CA_FILE ?=
|
|
ACTION_SCRIPT ?=
|
|
TLS_ARGS = $(if $(CA_FILE),--ca-file "$(CA_FILE)",)
|
|
|
|
VENV ?= .venv
|
|
UV ?= uv
|
|
COMPOSE ?= docker compose
|
|
RATE ?= 100
|
|
API_IMAGE ?= mtusi-messenger:lab5
|
|
FROM_REV ?=
|
|
SCRIPTS_PY = scripts/probe.py scripts/limits.py scripts/lab4_scenarios.py scripts/lab4_seed.py \
|
|
scripts/upload_memory.py scripts/make_images.py scripts/pipeline_suite.py \
|
|
scripts/pipeline_evidence.py
|
|
SCENARIO ?= failover-upload
|
|
PSQL = $(COMPOSE) exec -T postgres psql -U messenger -d messenger -X -q
|
|
|
|
.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 seed explain \
|
|
limits detection failover-each rolling-update level4 \
|
|
scenario s3-check attachments-evidence upload-faults upload-memory \
|
|
images queues topology worker-stop worker-start broker-restart suite-preflight level3 \
|
|
pipeline-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 "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: пик памяти реплик при 10/20/40 одновременных загрузках 1 и 10 MiB → evidence/upload-memory/"
|
|
@echo "lab5: queues, topology, worker-stop/worker-start, broker-restart, images, suite-preflight, level3"
|
|
|
|
check:
|
|
$(PYTHON) scripts/check_contract.py
|
|
|
|
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
|
|
|
|
secrets:
|
|
sh scripts/secrets.sh
|
|
sh scripts/broker-secrets.sh
|
|
|
|
up: secrets
|
|
$(COMPOSE) up -d --build --wait
|
|
|
|
down:
|
|
$(COMPOSE) down
|
|
|
|
reset-data:
|
|
@echo "Удаляются volumes с учебными данными стенда"
|
|
$(COMPOSE) 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
|
|
|
|
limits:
|
|
$(PYTHON) scripts/limits.py --out evidence/limits.txt
|
|
|
|
detection:
|
|
sh scripts/detection.sh evidence/detection
|
|
|
|
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 "$(API_IMAGE)" -
|
|
$(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)"
|
|
|
|
failover-evidence:
|
|
sh scripts/failover-evidence.sh "$(BASE_URL)"
|
|
|
|
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
|
|
|
|
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
|
|
|
|
images:
|
|
$(PYTHON) scripts/make_images.py
|
|
|
|
queues:
|
|
sh scripts/broker.sh queues
|
|
|
|
topology:
|
|
{ echo "date: $$(date -u +%FT%TZ) commit: $$(git rev-parse --short HEAD)"; \
|
|
echo "$$ rabbitmqctl list_queues -p messenger name type durable policy messages"; \
|
|
$(COMPOSE) exec -T broker rabbitmqctl -q list_queues -p messenger name type durable policy messages; \
|
|
echo "$$ rabbitmqctl list_consumers -p messenger"; \
|
|
$(COMPOSE) exec -T broker rabbitmqctl -q list_consumers -p messenger queue_name ack_required prefetch_count; \
|
|
echo "$$ rabbitmqctl list_permissions -p messenger"; \
|
|
$(COMPOSE) exec -T broker rabbitmqctl -q list_permissions -p messenger; \
|
|
echo "$$ rabbitmqctl list_users"; \
|
|
$(COMPOSE) exec -T broker rabbitmqctl -q list_users; \
|
|
echo "$$ docker compose ps"; \
|
|
$(COMPOSE) ps --format '{{.Service}}\t{{.Status}}\t{{.Ports}}'; } > evidence/topology.txt
|
|
cat evidence/topology.txt
|
|
|
|
worker-stop:
|
|
sh scripts/worker.sh stop
|
|
|
|
worker-start:
|
|
sh scripts/worker.sh start
|
|
|
|
broker-restart:
|
|
sh scripts/broker.sh restart
|
|
|
|
suite-preflight:
|
|
BASE_URL="$(BASE_URL)" $(PYTHON) scripts/pipeline_suite.py --preflight
|
|
|
|
level3:
|
|
BASE_URL="$(BASE_URL)" $(PYTHON) scripts/pipeline_suite.py --level 3 --output evidence/level3.json
|
|
|
|
pipeline-evidence:
|
|
$(PYTHON) scripts/pipeline_evidence.py --base-url "$(BASE_URL)" > evidence/pipeline-stand.txt; \
|
|
status=$$?; cat evidence/pipeline-stand.txt; exit $$status
|