forked from mtusi2026/mtusi2026lab3
Lab3 baseline: HAProxy, replicated stateless API, shared PostgreSQL/Valkey, idempotent messages
This commit is contained in:
@@ -1,13 +1,29 @@
|
||||
PYTHON ?= python3
|
||||
BASE_URL ?= http://localhost:8080
|
||||
GO ?= go
|
||||
BASE_URL ?= http://127.0.0.1:8083
|
||||
CA_FILE ?=
|
||||
ACTION_SCRIPT ?=
|
||||
TLS_ARGS = $(if $(CA_FILE),--ca-file "$(CA_FILE)",)
|
||||
COMPOSE ?= ./scripts/compose.sh
|
||||
COMPOSE_ARGS = --env-file .env
|
||||
IMAGE ?= mtusi-messenger-lab3-melnikov:local
|
||||
GIT_REVISION ?= $(shell git rev-parse HEAD 2>/dev/null || echo unknown)
|
||||
export GIT_REVISION
|
||||
export API_IMAGE ?= $(IMAGE)
|
||||
|
||||
.PHONY: help check validate test load test-persistence test-failover
|
||||
.PHONY: help check validate env up wait build-image docker-config stop down purge logs ps \
|
||||
test load test-persistence test-failover test-student test-student-race \
|
||||
test-expiry test-failure test-container test-db track1 failover-each rolling
|
||||
|
||||
help:
|
||||
@echo "check: offline structure; validate: full OpenAPI (requirements-dev.txt); test: running API; load: synthetic writes"
|
||||
@echo "check: offline structure; validate: full OpenAPI (requirements-dev.txt); test: running API"
|
||||
@echo "env: create ignored .env with random local credentials; up: build+start stack; wait: wait for /health/ready"
|
||||
@echo "stop: stop containers (data kept); down: remove containers (volumes kept); purge: DELETE volumes and data"
|
||||
@echo "test-student: Go unit tests + black-box suite; test-student-race: Go race detector"
|
||||
@echo "test-persistence: ACTION_SCRIPT=scripts/restart.sh; test-failover: ACTION_SCRIPT=scripts/stop-one.sh"
|
||||
@echo "failover-each: stop every real API replica in turn and measure RPS/errors/recovery"
|
||||
@echo "track1: level-5 track 1 (scaling price, saturation, one improvement)"
|
||||
@echo "rolling: rolling replacement of API containers under load"
|
||||
|
||||
check:
|
||||
$(PYTHON) scripts/check_contract.py
|
||||
@@ -21,10 +37,69 @@ test:
|
||||
load:
|
||||
$(PYTHON) tests/load.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||||
|
||||
env:
|
||||
./scripts/init-env.sh
|
||||
|
||||
up:
|
||||
@test -f .env || (echo "Run make env first" >&2; exit 2)
|
||||
GIT_REVISION="$(GIT_REVISION)" API_IMAGE="$(IMAGE)" $(COMPOSE) $(COMPOSE_ARGS) up -d --build
|
||||
./scripts/wait-ready.sh
|
||||
|
||||
wait:
|
||||
./scripts/wait-ready.sh
|
||||
|
||||
build-image:
|
||||
@test -f .env || (echo "Run make env first" >&2; exit 2)
|
||||
GIT_REVISION="$(GIT_REVISION)" API_IMAGE="$(IMAGE)" $(COMPOSE) $(COMPOSE_ARGS) build api
|
||||
|
||||
docker-config:
|
||||
GIT_REVISION="$(GIT_REVISION)" API_IMAGE="$(IMAGE)" $(COMPOSE) $(COMPOSE_ARGS) config --quiet
|
||||
|
||||
stop:
|
||||
$(COMPOSE) $(COMPOSE_ARGS) stop
|
||||
|
||||
down:
|
||||
$(COMPOSE) $(COMPOSE_ARGS) down
|
||||
|
||||
purge:
|
||||
@echo "PURGE removes containers AND named volumes mtusi-lab3-melnikov-*: all synthetic data is lost."
|
||||
$(COMPOSE) $(COMPOSE_ARGS) down -v
|
||||
|
||||
logs:
|
||||
$(COMPOSE) $(COMPOSE_ARGS) logs --tail=100 api
|
||||
|
||||
ps:
|
||||
$(COMPOSE) $(COMPOSE_ARGS) ps
|
||||
|
||||
test-persistence:
|
||||
@test -n "$(ACTION_SCRIPT)" || (echo "Set ACTION_SCRIPT to your implemented executable restart hook"; exit 2)
|
||||
@test -n "$(ACTION_SCRIPT)" || (echo "Set ACTION_SCRIPT to your implemented executable restart hook" >&2; 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)
|
||||
@test -n "$(ACTION_SCRIPT)" || (echo "Set ACTION_SCRIPT to your implemented executable stop-one hook" >&2; exit 2)
|
||||
$(PYTHON) tests/resilience.py --mode failover --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||||
|
||||
test-student:
|
||||
$(GO) test -count=1 ./...
|
||||
$(PYTHON) student-tests/blackbox.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||||
|
||||
test-student-race:
|
||||
$(GO) test -race -count=1 ./...
|
||||
|
||||
failover-each:
|
||||
$(PYTHON) scripts/failover-matrix.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||||
|
||||
rolling:
|
||||
./scripts/rolling-update.sh
|
||||
|
||||
test-failure:
|
||||
$(PYTHON) scripts/failure-checks.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||||
|
||||
test-container:
|
||||
$(PYTHON) scripts/container-checks.py --base-url "$(BASE_URL)" $(TLS_ARGS) --image "$(IMAGE)"
|
||||
|
||||
test-db:
|
||||
$(PYTHON) scripts/db-checks.py
|
||||
|
||||
track1:
|
||||
$(PYTHON) scripts/track1.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||||
|
||||
Reference in New Issue
Block a user