Files
mtusi2026lab7/Makefile
T

143 lines
4.8 KiB
Makefile

PYTHON ?= python3
BASE_URL ?= https://localhost:8443
CA_FILE ?=
ACTION_SCRIPT ?=
TLS_ARGS = $(if $(CA_FILE),--ca-file "$(CA_FILE)",)
.PHONY: help check validate test load test-persistence test-failover test-security
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)
test-security:
$(PYTHON) tests/security.py --base-url "$(BASE_URL)" $(TLS_ARGS)
# ---------------------------------------------------------------------------
# Student solution (lab 5, Python). On Windows: PowerShell/Git Bash with GNU make, public
# tests need PYTHONUTF8=1, and the hooks are started through scripts/*.cmd (Git Bash).
.PHONY: grafana alerts trace-demo dashboard dashboard-check incidents track1 obs-test secrets up down logs ps migrate student-test unit-test explain lb-status restore rolling-update failover-series bench-memory worker-stop worker-start jobs failed audit track2
secrets:
$(PYTHON) scripts/init_secrets.py
# Build, apply migrations ONCE (service migrate), start broker, API replicas, LB, relay and worker.
up: secrets
docker compose up -d --build --wait
# Safe stop: containers stop, named volumes (data, queue) stay.
down:
docker compose down
logs:
docker compose logs --tail 50 api lb relay worker
ps:
docker compose ps -a
migrate:
docker compose run --rm migrate
# HAProxy view of the replicas (UP/DOWN) mapped to containers and X-Instance-Id.
lb-status:
$(PYTHON) scripts/lbctl.py status
$(PYTHON) scripts/lbctl.py replicas
# Start replicas stopped by scripts/stop-one.sh again and wait until the LB has them all UP.
restore:
sh scripts/restore-api.sh
$(PYTHON) scripts/lbctl.py wait-up $${API_REPLICAS:-2}
# Replace every API replica one by one with a freshly built image (no downtime).
rolling-update:
sh scripts/rolling-update.sh
# Lab 3: stop each replica in turn under load, measure RPS/errors/recovery (evidence/failover/).
failover-series:
$(PYTHON) bench/failover_series.py --output evidence/failover
# Lab 5 demo: stop the worker (uploads still get 202, content answers 409), start it again.
worker-stop:
docker compose stop worker
worker-start:
docker compose start worker
# Lab 5 operator view: jobs by state + outbox backlog; failed registry (replay: see REPORT.md).
jobs:
docker compose run --rm --no-deps jobctl stats
failed:
docker compose run --rm --no-deps jobctl list-failed
# Track 2: read-only check of the pipeline invariants over PostgreSQL and both buckets.
audit:
docker compose run --rm --no-deps auditor
# Track 2: automatic fault-injection matrix (duplicate, reorder, crashes, stale versions).
track2:
$(PYTHON) bench/pipeline_faults.py --output evidence/track2
# Own tests: unit + black-box against the running stand (needs requirements*.txt in a venv).
student-test:
$(PYTHON) -m pytest student-tests -v
unit-test:
$(PYTHON) -m pytest student-tests -m "not stack" -q
explain:
$(PYTHON) scripts/explain_history.py --output evidence/explain-history.txt
# Lab 4: peak RAM of the replicas under 16 simultaneous uploads (evidence/memory/).
bench-memory:
$(PYTHON) bench/upload_memory.py --output evidence/memory
# ---------------------------------------------------------------------------
# Lab 6: observability (docs/OBSERVABILITY.md, docs/SLO.md, docs/RUNBOOK.md, docs/TRACK1.md)
grafana:
@echo "Grafana: http://127.0.0.1:3000 user admin, password in secrets/grafana_admin_password"
alerts:
$(PYTHON) scripts/obs.py alerts
# Controlled request with our own traceparent -> its trace in Tempo + its logs in Loki.
trace-demo:
$(PYTHON) scripts/trace_demo.py --output evidence/trace-demo.txt
# Regenerate the dashboard JSON / run every dashboard query through Grafana.
dashboard:
$(PYTHON) scripts/build_dashboard.py
dashboard-check:
$(PYTHON) scripts/check_dashboard.py --output evidence/dashboard-check.txt
# Level 4 incidents under load (worker stop, DB lock, slow handler, backend/collector down).
incidents:
$(PYTHON) bench/incidents.py all
# Track 1: price of observability (off / full / head10 / tail), 3 runs each.
track1:
$(PYTHON) bench/track1.py --runs 3 --output evidence/track1
obs-test:
$(PYTHON) -m pytest student-tests/test_observability.py -v