166 lines
6.9 KiB
Makefile
166 lines
6.9 KiB
Makefile
PYTHON ?= python3
|
||
BASE_URL ?= http://localhost:8080
|
||
CA_FILE ?=
|
||
ACTION_SCRIPT ?=
|
||
TLS_ARGS = $(if $(CA_FILE),--ca-file "$(CA_FILE)",)
|
||
|
||
.PHONY: help check validate test load test-persistence test-failover
|
||
|
||
help:
|
||
@echo "check: offline structure; validate: full OpenAPI (requirements-dev.txt); test: running API; load: synthetic writes"
|
||
|
||
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)
|
||
|
||
# ---------------------------------------------------------------------------------------------
|
||
# Цели решения (lab6, включая цели lab2–lab5). Публичные цели выше не изменены.
|
||
# ---------------------------------------------------------------------------------------------
|
||
COMPOSE ?= docker compose --env-file .env
|
||
IN_WORKER = $(COMPOSE) run --rm --no-deps -T -v "$(CURDIR)/student-tests:/app/student-tests:ro" --entrypoint python worker
|
||
IN_API = $(COMPOSE) run --rm --no-deps -T -v "$(CURDIR)/student-tests:/app/student-tests:ro" --entrypoint python api
|
||
|
||
.PHONY: secrets up down ps logs destroy-data restore stop-worker start-worker restart-api-broker s3-check \
|
||
jobs-failed jobs-invariants test-student test-pipeline test-imgproc test-jobs-failures test-track2 \
|
||
chaos test-attachments test-storage-failures test-api test-idempotency test-expiry test-cache-race \
|
||
test-failures upload-memory evidence test-observability test-telemetry-persistence incidents \
|
||
incident-worker-stop incident-db-slow incident-handler-slow incident-db-down incident-telemetry-down \
|
||
incident-collector-down telemetry-cost grafana
|
||
|
||
secrets:
|
||
./scripts/init-secrets.sh
|
||
|
||
# Единая команда запуска: LB + 2 API + 2 worker + migrate/s3-init/broker-init (one-shot) + PostgreSQL + Redis + S3 + NATS
|
||
# + OTel Collector + Prometheus + Loki + Tempo + Grafana (provisioning из infra/grafana).
|
||
up: secrets
|
||
$(COMPOSE) --profile ttl up -d --build --wait
|
||
|
||
ps:
|
||
$(COMPOSE) --profile ttl --profile fault ps -a
|
||
|
||
logs:
|
||
$(COMPOSE) logs --tail=100 lb api worker nats otel-collector
|
||
|
||
# Безопасная остановка: контейнеры удаляются, volumes (данные и история telemetry) сохраняются.
|
||
down:
|
||
$(COMPOSE) --profile ttl --profile fault down
|
||
|
||
# НАМЕРЕННОЕ удаление учебных данных (pgdata, s3data, natsdata и история promdata/lokidata/tempodata/grafanadata).
|
||
destroy-data:
|
||
@echo "This deletes ALL lab6 volumes (PostgreSQL, S3, NATS, Prometheus, Loki, Tempo, Grafana). Type 'yes' to continue:"; read ans; [ "$$ans" = yes ]
|
||
$(COMPOSE) --profile ttl --profile fault down -v
|
||
|
||
# Вернуть реплики API после make test-failover ACTION_SCRIPT=scripts/stop-one.sh
|
||
restore:
|
||
./scripts/start-replicas.sh
|
||
|
||
# Сценарий защиты: остановить/запустить worker; перезапустить API и брокер (volumes сохраняются).
|
||
stop-worker:
|
||
./scripts/stop-worker.sh
|
||
|
||
start-worker:
|
||
./scripts/start-worker.sh
|
||
|
||
restart-api-broker:
|
||
./scripts/restart-api-broker.sh
|
||
|
||
s3-check:
|
||
$(COMPOSE) exec -T api python -m messenger s3-check
|
||
|
||
# Реестр failed (DLQ) и проверка инвариантов pipeline.
|
||
jobs-failed:
|
||
$(COMPOSE) exec -T api python -m messenger jobs failed
|
||
|
||
jobs-invariants:
|
||
$(COMPOSE) exec -T api python -m messenger jobs invariants --settled --verify-bytes
|
||
|
||
test-pipeline:
|
||
$(PYTHON) student-tests/test_pipeline.py
|
||
|
||
# Правила вариантов и лимиты worker — внутри образа (нужен Pillow).
|
||
test-imgproc:
|
||
$(IN_WORKER) student-tests/test_imgproc.py
|
||
|
||
# Останавливает/запускает worker, брокер и реплики API, профиль fault. Volumes не трогает. ≈ 6 мин.
|
||
test-jobs-failures:
|
||
$(PYTHON) student-tests/test_jobs_failures.py
|
||
|
||
# Трек 2: автоматическая инъекция отказов (дубли, reorder, crash, версии) + инварианты. ≈ 3 мин.
|
||
test-track2:
|
||
$(PYTHON) student-tests/test_pipeline_idempotency.py
|
||
|
||
# Трек 2: рандомизированный хаос-прогон (три seed).
|
||
chaos:
|
||
mkdir -p evidence/track2
|
||
for s in 1 2 3; do $(PYTHON) research/track2_chaos.py --seed $$s --uploads 60 --output evidence/track2/chaos-seed$$s.json || exit 1; done
|
||
|
||
test-attachments:
|
||
$(PYTHON) student-tests/test_attachments.py
|
||
|
||
test-storage-failures:
|
||
$(PYTHON) student-tests/test_storage_failures.py
|
||
|
||
test-api:
|
||
$(PYTHON) student-tests/test_api.py
|
||
|
||
test-idempotency:
|
||
$(PYTHON) student-tests/test_idempotency.py
|
||
|
||
test-expiry:
|
||
$(PYTHON) student-tests/test_expiry.py
|
||
|
||
test-cache-race:
|
||
$(IN_API) student-tests/test_cache_race.py
|
||
|
||
test-failures:
|
||
$(PYTHON) student-tests/test_failures.py
|
||
|
||
test-student: test-pipeline test-imgproc test-attachments test-api test-idempotency test-expiry test-cache-race \
|
||
test-jobs-failures test-storage-failures test-failures test-track2
|
||
|
||
upload-memory:
|
||
$(PYTHON) research/upload_memory.py --output evidence/upload-memory.json
|
||
|
||
evidence:
|
||
./scripts/collect-evidence.sh
|
||
|
||
# ----------------------------------------------------------------------------------------- lab6: наблюдаемость
|
||
grafana:
|
||
@echo "Grafana: http://127.0.0.1:3000 (admin / пароль в secrets/grafana_admin_password)"
|
||
|
||
# Уровни 3–4: provisioning, сигналы, корреляция запрос→лог→trace, upload→worker, retry, отсутствие секретов.
|
||
test-observability:
|
||
$(PYTHON) student-tests/test_observability.py
|
||
|
||
# История telemetry переживает перезапуск всех хранилищ (scripts/restart.sh).
|
||
test-telemetry-persistence:
|
||
$(PYTHON) student-tests/test_telemetry_persistence.py
|
||
|
||
# Контролируемые инциденты под нагрузкой: firing → resolved (≈ 20 мин все). Вывод — evidence/incidents.
|
||
incidents:
|
||
$(PYTHON) research/incidents.py all --out evidence/incidents
|
||
|
||
incident-worker-stop incident-db-slow incident-handler-slow incident-db-down incident-telemetry-down incident-collector-down:
|
||
$(PYTHON) research/incidents.py $(@:incident-%=%) --out evidence/incidents
|
||
|
||
# Трек 1: цена наблюдаемости (off / full / head10 / tail), 3 повтора × 4 конфигурации ≈ 35 мин.
|
||
telemetry-cost:
|
||
$(PYTHON) research/telemetry_cost.py --reps 3 --rate 60 --window 60 --out evidence/track1
|
||
|