Repository navigation
Expand file tree
/
Copy pathjustfile
More file actions
261 lines (219 loc) · 10.8 KB
/
Copy pathjustfile
File metadata and controls
261 lines (219 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# Evaluating Node.js Performance - Command Runner
# Load .env (if present) so admin recipes use the same KAFKA_TOPIC, GROUP_ID,
# and PostgreSQL credentials as the running containers. Missing .env is fine.
set dotenv-load := true
# List all available commands grouped by category
default:
@awk ' \
/^# ---/ { print "\n\033[1;33m" $0 "\033[0m" } \
/^# [^-]/ { desc = substr($0, 3) } \
/^[a-zA-Z0-9_-]+( .*)?:([^=]|$)/ { \
name = $1; \
sub(/:$/, "", name); \
if (name != "default" && desc != "") { \
printf " \033[36m%-25s\033[0m %s\n", name, desc; \
} \
desc = "" \
} \
END { print "" } \
' "{{justfile()}}"
# --- Setup ---
# Install all npm dependencies (runs in container, writes to host via mount)
install:
docker compose --profile tools run --rm --user "$(id -u):$(id -g)" -e npm_config_cache=/tmp/.npm node-tools "npm install --ignore-scripts"
# Install Python deps into a local .venv, for the EDITOR ONLY (optional).
# Re-run after `just lock-python` changes the pins in `requirements.lock.txt`.
install-python:
uv venv --clear --python 3.12.13 .venv
uv pip install --python .venv -r requirements.lock.txt
# Build all images including tools (consumer + k6 + python)
build-all:
docker compose --profile load --profile tools build
# Regenerate the fully-pinned + hashed Python lock from requirements.txt
lock-python:
docker run --rm -v "$(pwd):/w" -w /w -e CUSTOM_COMPILE_COMMAND="just lock-python" python:3.12.13-slim sh -c "pip install --no-cache-dir pip-tools==7.4.1 && pip-compile --strip-extras --generate-hashes --output-file=requirements.lock.txt requirements.txt"
# --- Infrastructure ---
# Start infrastructure with cAdvisor (auto-detects macOS vs Linux)
infra:
#!/usr/bin/env bash
set -euo pipefail
if [[ "$(uname)" == "Linux" ]]; then
docker compose --profile monitoring-linux up -d kafka postgres prometheus grafana cadvisor-linux
else
docker compose --profile monitoring up -d kafka postgres prometheus grafana cadvisor
fi
echo "Waiting for Kafka to be healthy..."
docker compose up kafka-init 2>&1 | tail -3
echo ""
echo "Infrastructure ready."
echo " Grafana: http://localhost:3000 (admin/admin)"
echo " Prometheus: http://localhost:9091"
echo " cAdvisor: http://localhost:8080"
echo " Kafka: localhost:9094 (external)"
echo " PostgreSQL: localhost:5432"
# --- Consumer ---
# Start with I/O workload (default)
up-io replicas="1":
docker compose -f docker-compose.yml -f docker-compose.io.yml up -d --scale consumer={{replicas}}
# Start with CPU workload
up-cpu replicas="1":
docker compose -f docker-compose.yml -f docker-compose.cpu.yml up -d --scale consumer={{replicas}}
# Start with Mixed workload
up-mix replicas="1":
docker compose -f docker-compose.yml -f docker-compose.mix.yml up -d --scale consumer={{replicas}}
# Scale running consumers (e.g., just scale 4)
scale replicas:
docker compose up -d --scale consumer={{replicas}} --no-recreate
# --- Load Testing (k6) ---
# Run a quick smoke test (10 msg/s for 30s)
k6-smoke:
docker compose --profile load run --rm k6 run --env RATE=10 --env DURATION=30s /scripts/scenarios/baseline.js
# Run stress test at a specific rate (e.g., just k6-stress 20000)
k6-stress rate="10000":
docker compose --profile load run --rm k6 run --env TARGET_RATE={{rate}} /scripts/scenarios/stress-test.js
# --- Test Automation ---
# Run a full scenario (e.g., just run-scenario S2 4 1)
run-scenario scenario replicas repetition:
./scripts/run-scenario.sh {{scenario}} {{replicas}} {{repetition}}
# Run all tests for a scenario filter (e.g., just run-all S2, just run-all burst)
run-all filter="all":
./scripts/run-all.sh {{filter}}
# Audit data completeness (checks all 90 runs)
audit-data reps="5":
./scripts/audit-data.sh {{reps}}
# --- Data Analysis ---
# Run statistical analysis on collected results
analyze *args:
docker compose --profile tools run --rm python scripts/analyze.py {{args}}
# Export statistical analysis as CSV
analyze-csv *args:
docker compose --profile tools run --rm python scripts/analyze.py --csv {{args}}
# Export statistical analysis as JSON
analyze-json *args:
docker compose --profile tools run --rm python scripts/analyze.py --json {{args}}
# Generate all graphs from results
generate-graphs *args:
docker compose --profile tools run --rm python scripts/generate_graphs.py {{args}}
# List available graph types
list-graphs:
docker compose --profile tools run --rm python scripts/generate_graphs.py --list
# --- Monitoring ---
# View consumer logs (follow mode)
logs:
docker compose logs -f consumer
# Show running services and their status
status:
docker compose ps
# Show consumer group lag and partition assignment
kafka-lag:
docker compose exec kafka /opt/kafka/bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group "${GROUP_ID:-benchmark-group}" --describe
# Open Grafana dashboard in browser
grafana:
#!/usr/bin/env bash
if command -v xdg-open &>/dev/null; then
xdg-open http://localhost:3000
elif command -v open &>/dev/null; then
open http://localhost:3000
else
echo "Open manually: http://localhost:3000"
fi
# --- Development ---
# TypeScript type check
typecheck:
docker compose --profile tools run --rm node-tools "npm run typecheck"
# Format all supported files (Prettier: JS/TS/JSON/YAML/MD - Ruff: Python - shfmt: Shell)
format:
docker compose --profile tools run --rm node-tools "npm run format"
docker compose --profile tools run --rm --entrypoint ruff python format scripts/
docker run --rm -v "$(pwd):/workspace" -w /workspace mvdan/shfmt:v3.13.1 -w -i 2 -ci scripts/*.sh
# Check formatting without writing changes
format-check:
docker compose --profile tools run --rm node-tools "npm run format:check"
docker compose --profile tools run --rm --entrypoint ruff python format --check scripts/
docker run --rm -v "$(pwd):/workspace" -w /workspace mvdan/shfmt:v3.13.1 -d -i 2 -ci scripts/*.sh
# Lint Dockerfiles for best practices
lint-dockerfiles:
docker run --rm -i -v "$(pwd):/workspace" -w /workspace hadolint/hadolint:v2.14.0 hadolint consumer/Dockerfile k6/Dockerfile scripts/Dockerfile
# --- Cleanup & Verify ---
# Wipe collected stats for a fresh start: all, or one scenario (e.g. just clean-stats S2)
[confirm("This permanently deletes collected run exports, run-log rows, and graphs. Continue?")]
clean-stats filter="all":
#!/usr/bin/env bash
set -euo pipefail
FILTER="{{filter}}"
if [ "${FILTER}" = "all" ]; then
# Remove every per-run export folder, the audit log, and all graphs.
# Matches run folders (e.g. S2-R4-1) only - never the S1..S6 dirs or .gitkeep.
find results -type d -name 'S*-R*-*' -exec rm -rf {} +
rm -f results/run-log.csv
rm -f results/graphs/*.png
echo "All stats cleared. Scenario dirs and .gitkeep preserved."
else
# Single scenario: validate it exists, drop its run folders, prune its
# rows from run-log.csv. Graphs are aggregate, so leave them untouched
# (regenerate with just generate-graphs once data is re-collected).
if [ ! -d "results/${FILTER}" ]; then
echo "Unknown scenario '${FILTER}' (expected S1..S6, or 'all')." >&2
exit 1
fi
find "results/${FILTER}" -type d -name "${FILTER}-R*-*" -exec rm -rf {} +
if [ -f results/run-log.csv ]; then
# Keep the header and every row that is NOT this scenario.
grep -v "^${FILTER}-R" results/run-log.csv >results/run-log.csv.tmp || true
mv results/run-log.csv.tmp results/run-log.csv
fi
echo "Stats for ${FILTER} cleared (run folders + run-log rows; graphs left intact)."
fi
# Stop all services
down:
docker compose --profile load --profile monitoring --profile monitoring-linux --profile tools down
# Stop all services and remove volumes (full reset)
down-clean:
docker compose --profile load --profile monitoring --profile monitoring-linux --profile tools down -v
# Verify the full end-to-end setup works (build, start, smoke test, cleanup)
verify:
#!/usr/bin/env bash
set -euo pipefail
echo "╔══════════════════════════════════════════════════╗"
echo "║ End-to-End Verification ║"
echo "╚══════════════════════════════════════════════════╝"
echo ""
echo "[1/5] Building Docker images..."
just build-all
echo ""
echo "[2/5] Starting infrastructure..."
just infra
echo ""
echo "[3/5] Starting consumer (I/O workload)..."
docker compose -f docker-compose.yml -f docker-compose.io.yml up -d --scale consumer=1 --wait consumer
echo ""
echo "[4/5] Running smoke test (10 msg/s, 30s)..."
just k6-smoke
echo "Waiting 15s for metrics to propagate..."
sleep 15
MSG_COUNT=$(docker compose exec -T postgres psql -U "${POSTGRES_USER:-benchmark}" -d "${POSTGRES_DB:-benchmark}" -tA -c "SELECT COUNT(*) FROM messages;")
PROM_STATUS=$(curl -gsf 'http://localhost:9091/api/v1/query?query=consumer_messages_processed_total' | docker compose --profile tools run --rm -T python -c "import sys,json; d=json.load(sys.stdin); r=d.get('data',{}).get('result',[]); print('1' if r and float(r[0]['value'][1])>0 else '0')" 2>/dev/null || echo "0")
echo ""
echo "╔══════════════════════════════════════════════════╗"
echo "║ Verification Results ║"
echo "╠══════════════════════════════════════════════════╣"
echo "║ PostgreSQL messages: ${MSG_COUNT:-0}"
echo "║ Prometheus metrics: ${PROM_STATUS} (1 = collecting)"
echo "╚══════════════════════════════════════════════════╝"
if [ "${MSG_COUNT:-0}" -gt 0 ] && [ "${PROM_STATUS}" = "1" ]; then
VERIFY_OK=true
echo ""
echo "✓ All checks passed. Pipeline is working correctly."
else
VERIFY_OK=false
echo ""
echo "✗ Some checks failed. Review the output above."
fi
echo ""
echo "[5/5] Cleaning up..."
just down-clean
echo ""
echo "Verification complete."
# Exit non-zero on failure (after cleanup) so scripts and the pre-flight
# checklist can rely on the exit code, not just the printed ✓/✗.
[ "${VERIFY_OK}" = true ] || exit 1