-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
567 lines (499 loc) · 23.6 KB
/
Copy pathMakefile
File metadata and controls
567 lines (499 loc) · 23.6 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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
.PHONY: build help compose-dev compose-dev-build compose-dev-down compose-prod compose-prod-build compose-prod-down compose-scale compose-logs compose-ps clean test-infra db-migrate db-shell test test-coverage test-unit test-integration fmt fmt-check vet lint build-binary build-image \
k8s-cluster-up k8s-cluster-down k8s-image k8s-up k8s-down k8s-status k8s-hpa \n loadtest-help loadtest-setup loadtest-start loadtest-stop loadtest-full loadtest-capacity loadtest-login loadtest-register loadtest-logout loadtest-checkauth loadtest-websocket loadtest-push loadtest-pushroom loadtest-count loadtest-roominfo loadtest-smoke loadtest-custom loadtest-report loadtest-grafana loadtest-clean
# Default HOST_IP for development
HOST_IP ?= 127.0.0.1
# Host port for connect-ws. The container always listens on 7000; only the
# published host port moves. macOS AirPlay Receiver (ControlCenter) holds 7000,
# so a local .env can set WS_HOST_PORT to something free without changing any
# in-container address, the compiled client, or the Kubernetes manifests.
# Read from .env so make and docker compose never disagree: compose reads .env
# itself, and an exported default here would override it.
WS_HOST_PORT := $(strip $(shell sed -n 's/^WS_HOST_PORT=//p' .env 2>/dev/null))
ifeq ($(WS_HOST_PORT),)
WS_HOST_PORT := 7000
endif
# Replica count for load-test scale-out runs: make loadtest-capacity LOGIC_REPLICAS=3
LOGIC_REPLICAS ?= 1
# Image tag. The Kubernetes manifests name gochat:dev, so k8s-image overrides
# this; nothing else should need to.
IMAGE_TAG ?= latest
# Kubernetes
KIND_CLUSTER ?= gochat
K8S_DIR := deployments/k8s
# Rendering rather than `kubectl apply -k`: the base kustomization generates the
# postgres migrations ConfigMap from db/migrations, which is outside its root, and
# only `kubectl kustomize` takes --load-restrictor.
KUSTOMIZE = kubectl kustomize --load-restrictor LoadRestrictionsNone
METRICS_SERVER_URL := https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.9.0/components.yaml
# Legacy build command (for backward compatibility)
build: # make build TAG=1.23;make build TAG=latest,自定义版本号,构建自己机器可以运行的镜像(因为M1机器拉取提供的镜像架构不同,只能自己构建)
cd ./docker && docker build -t lockgit/gochat:${TAG} .
help:
@echo "GoChat Multi-Container Deployment"
@echo ""
@echo "Available targets:"
@echo " build - Legacy: Build single-container image (use TAG=version)"
@echo " compose-dev - Start development environment"
@echo " compose-dev-build - Build and start development environment"
@echo " compose-dev-down - Stop development environment"
@echo " compose-prod - Start production environment (detached)"
@echo " compose-prod-build - Build and start production environment"
@echo " compose-prod-down - Stop production environment"
@echo " compose-scale - Start with scaled services (logic=3, connect-ws=2, task=2)"
@echo " compose-logs - View logs from all services"
@echo " compose-ps - Show running services"
@echo " test-infra - Test infrastructure only (etcd + redis)"
@echo " clean - Remove all containers, volumes, and images"
@echo ""
@echo "Testing & Quality:"
@echo " test - Run all tests"
@echo " test-coverage - Run tests with coverage report"
@echo " test-unit - Run unit tests only"
@echo " test-integration - Run integration tests with Docker (starts services)"
@echo " test-integration-quick - Run integration tests (services must be running)"
@echo " fmt - Format code with go fmt"
@echo " fmt-check - Check if code is formatted"
@echo " vet - Run go vet"
@echo " lint - Run golangci-lint"
@echo ""
@echo "Building:"
@echo " build-binary - Build gochat binary"
@echo " build-image - Build Docker image"
@echo ""
@echo "Load Testing:"
@echo " loadtest-help - Show load testing help"
@echo " loadtest-full - Run full system load test"
@echo " loadtest-capacity - Run step-based capacity test"
@echo " loadtest-smoke - Quick smoke test"
@echo ""
@echo "Environment variables:"
@echo " HOST_IP=<ip> - Set host IP address (default: 127.0.0.1)"
# Development commands
compose-dev:
@echo "Starting GoChat in development mode..."
HOST_IP=$(HOST_IP) docker compose -f docker-compose.yml -f deployments/docker-compose.dev.yml up
compose-dev-build:
@echo "Building and starting GoChat in development mode..."
HOST_IP=$(HOST_IP) docker compose -f docker-compose.yml -f deployments/docker-compose.dev.yml up --build
compose-dev-down:
@echo "Stopping development environment..."
docker compose -f docker-compose.yml -f deployments/docker-compose.dev.yml down
# Production commands
compose-prod:
@echo "Starting GoChat in production mode..."
@if [ -z "$(HOST_IP)" ] || [ "$(HOST_IP)" = "127.0.0.1" ]; then \
echo "WARNING: HOST_IP is set to localhost. For production, use: make compose-prod HOST_IP=<your-server-ip>"; \
echo "Continuing in 3 seconds..."; \
sleep 3; \
fi
HOST_IP=$(HOST_IP) docker compose -f docker-compose.yml -f deployments/docker-compose.prod.yml up -d
compose-prod-build:
@echo "Building and starting GoChat in production mode..."
@if [ -z "$(HOST_IP)" ] || [ "$(HOST_IP)" = "127.0.0.1" ]; then \
echo "WARNING: HOST_IP is set to localhost. For production, use: make compose-prod-build HOST_IP=<your-server-ip>"; \
echo "Continuing in 3 seconds..."; \
sleep 3; \
fi
HOST_IP=$(HOST_IP) docker compose -f docker-compose.yml -f deployments/docker-compose.prod.yml up -d --build
compose-prod-down:
@echo "Stopping production environment..."
docker compose -f docker-compose.yml -f deployments/docker-compose.prod.yml down
# Scaling example
compose-scale:
@echo "Starting GoChat with scaled services..."
HOST_IP=$(HOST_IP) docker compose -f docker-compose.yml up \
--scale logic=3 \
--scale connect-ws=2 \
--scale connect-tcp=2 \
--scale task=2 \
--scale api=2
# Utility commands
compose-logs:
docker compose -f docker-compose.yml logs -f
compose-ps:
docker compose -f docker-compose.yml ps
# Test infrastructure only (etcd + redis)
test-infra:
@echo "Starting infrastructure services only..."
docker compose -f docker-compose.yml up etcd redis postgres
# Database
db-migrate:
@echo "Applying migrations to the running postgres container..."
@for f in db/migrations/*.sql; do echo " $$f"; docker exec -i gochat-postgres psql -U gochat -d gochat -v ON_ERROR_STOP=1 < $$f; done
@echo "Migrations applied."
db-shell:
docker exec -it gochat-postgres psql -U gochat -d gochat
# Clean up everything
clean:
@echo "WARNING: This will remove all GoChat containers, volumes, and images."
@echo "Press Ctrl+C to cancel, or wait 5 seconds to continue..."
@sleep 5
docker compose -f docker-compose.yml -f deployments/docker-compose.dev.yml down -v --rmi all || true
docker compose -f docker-compose.yml -f deployments/docker-compose.prod.yml down -v --rmi all || true
@echo "Clean complete!"
# Testing targets
test:
@echo "Running all tests..."
go test -v -race ./...
test-coverage:
@echo "Running tests with coverage..."
go test -v -race -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
test-unit:
@echo "Running unit tests..."
go test -v -short ./...
# TRACING_SAMPLING_RATE=1.0: dev samples at 1%, which makes "traces exist" a
# test that fails at random. The shutdown tests restart services through
# docker compose, so they need the same -f arguments the stack was started with.
test-integration:
@echo "Running integration tests with Docker..."
@echo "Starting services..."
TRACING_SAMPLING_RATE=1.0 docker compose -f docker-compose.yml -f deployments/docker-compose.test.yml up -d --build
@echo "Waiting for services to be healthy..."
@sleep 30
@echo "Running integration tests from host..."
TEST_API_URL=http://localhost:7070 \
TEST_WS_URL=ws://localhost:$(WS_HOST_PORT)/ws \
TEST_REDIS_ADDR=localhost:6379 \
TEST_COMPOSE_FILES=docker-compose.yml,deployments/docker-compose.test.yml \
go test -v -race -timeout 15m ./tests/integration/... || (docker compose -f docker-compose.yml -f deployments/docker-compose.test.yml down && exit 1)
@echo "Stopping services..."
docker compose -f docker-compose.yml -f deployments/docker-compose.test.yml down
test-integration-quick:
@echo "Running integration tests (assumes services are already running)..."
TEST_API_URL=http://localhost:7070 \
TEST_WS_URL=ws://localhost:$(WS_HOST_PORT)/ws \
TEST_REDIS_ADDR=localhost:6379 \
TEST_COMPOSE_FILES=docker-compose.yml,deployments/docker-compose.test.yml \
go test -v -race -timeout 15m ./tests/integration/...
# Code quality targets
fmt:
@echo "Formatting code..."
go fmt ./...
fmt-check:
@echo "Checking code formatting..."
@test -z "$$(go fmt ./...)" || (echo "Code not formatted, run 'make fmt'" && exit 1)
vet:
@echo "Running go vet..."
go vet ./...
lint:
@echo "Running golangci-lint..."
golangci-lint run
# Build targets
build-binary:
@echo "Building gochat binary..."
CGO_ENABLED=0 GOOS=linux go build -tags=etcd -ldflags="-w -s" -o bin/gochat main.go
@echo "Binary built: bin/gochat"
build-image:
@echo "Building Docker image..."
docker build -t gochat:$(IMAGE_TAG) -f docker/Dockerfile .
@echo "Image built: gochat:$(IMAGE_TAG)"
# ============================================
# Kubernetes (local kind cluster)
# ============================================
# The second deployment target. Compose stays the one the development loop, the
# CI integration tests and the load tests use; this is where readiness and
# autoscaling are actually exercised. See docs/kubernetes.md.
#
# Both bind the same host ports, so only one can run at a time.
k8s-cluster-up:
@echo "Creating kind cluster '$(KIND_CLUSTER)'..."
kind create cluster --name $(KIND_CLUSTER) --config $(K8S_DIR)/kind-cluster.yaml
@echo "Cluster ready."
k8s-cluster-down:
kind delete cluster --name $(KIND_CLUSTER)
k8s-image:
@$(MAKE) build-image IMAGE_TAG=dev
@echo "Loading gochat:dev into the cluster (no registry involved)..."
kind load docker-image gochat:dev --name $(KIND_CLUSTER)
k8s-up: k8s-image
@echo "Installing metrics-server (CPU metrics, for comparison with the custom ones)..."
kubectl apply -f $(METRICS_SERVER_URL)
@# kubelet on kind serves a self-signed certificate with no IP SAN, so
@# scraping it by node IP fails validation. The clean fix is serverTLSBootstrap
@# plus manual CSR approval, which would stop this being one command.
kubectl -n kube-system patch deployment metrics-server --type=json -p='[{"op":"add","path":"/spec/template/spec/containers/0/args/-","value":"--kubelet-insecure-tls"}]'
@echo "Applying the observability stack..."
$(KUSTOMIZE) $(K8S_DIR)/monitoring | kubectl apply -f -
@echo "Applying the application..."
$(KUSTOMIZE) $(K8S_DIR)/overlays/dev | kubectl apply -f -
@echo "Waiting for dependencies..."
kubectl -n gochat rollout status statefulset/etcd --timeout=180s
kubectl -n gochat rollout status statefulset/redis --timeout=180s
kubectl -n gochat rollout status statefulset/postgres --timeout=180s
kubectl -n gochat rollout status statefulset/rabbitmq --timeout=300s
@echo "Waiting for the application..."
kubectl -n gochat rollout status deployment/logic --timeout=180s
kubectl -n gochat rollout status deployment/connect-ws --timeout=180s
kubectl -n gochat rollout status deployment/connect-tcp --timeout=180s
kubectl -n gochat rollout status deployment/api --timeout=180s
kubectl -n gochat rollout status deployment/task --timeout=180s
kubectl -n gochat rollout status deployment/site --timeout=180s
@echo "Waiting for the metrics pipeline..."
kubectl -n monitoring rollout status deployment/prometheus --timeout=180s
kubectl -n monitoring rollout status deployment/prometheus-adapter --timeout=180s
kubectl -n monitoring rollout status deployment/grafana --timeout=180s
kubectl -n monitoring rollout status deployment/jaeger --timeout=180s
@# Applied last: an HPA whose metric nothing serves yet reads <unknown>.
@echo "Applying the autoscalers..."
kubectl apply -k $(K8S_DIR)/autoscaling
@echo ""
@echo "GoChat is up. UI http://localhost:8080 Grafana http://localhost:3000 (admin/admin)"
@echo "Prometheus http://localhost:19090 Jaeger http://localhost:16686"
@echo "Watch the autoscaler with: make k8s-hpa"
k8s-down:
-kubectl delete -k $(K8S_DIR)/autoscaling --ignore-not-found
-$(KUSTOMIZE) $(K8S_DIR)/overlays/dev | kubectl delete --ignore-not-found -f -
-$(KUSTOMIZE) $(K8S_DIR)/monitoring | kubectl delete --ignore-not-found -f -
@echo "Workloads removed. The cluster is still up; 'make k8s-cluster-down' removes it."
k8s-status:
@echo "== pods =="
@kubectl get pods -n gochat -o wide
@kubectl get pods -n monitoring
@echo ""
@echo "== services =="
@kubectl get svc -n gochat
@echo ""
@echo "== autoscalers =="
@kubectl get hpa -n gochat
k8s-hpa:
kubectl get hpa -n gochat -w
# ============================================
# Load Testing Targets
# ============================================
# Load test configuration (all runtime-configurable)
K6_VUS ?=
K6_DURATION ?=
K6_START_VUS ?= 10
K6_END_VUS ?= 100
K6_STEP_VUS ?= 10
K6_STEP_DURATION ?= 1m
K6_RAMP_DURATION ?= 30s
K6_WARMUP_DURATION ?= 20s
LOADTEST_SCRIPT ?= full-system.js
# Compose files for load testing
LOADTEST_COMPOSE = docker compose -f docker-compose.yml -f loadtest/docker-compose.loadtest.yml
# Only pass K6_VUS when explicitly set to avoid forcing fixed-VU mode.
K6_ENV_VARS = \
-e K6_DURATION=$(K6_DURATION) \
-e K6_START_VUS=$(K6_START_VUS) \
-e K6_END_VUS=$(K6_END_VUS) \
-e K6_STEP_VUS=$(K6_STEP_VUS) \
-e K6_STEP_DURATION=$(K6_STEP_DURATION) \
-e K6_RAMP_DURATION=$(K6_RAMP_DURATION) \
-e K6_WARMUP_DURATION=$(K6_WARMUP_DURATION)
ifneq ($(strip $(K6_VUS)),)
K6_ENV_VARS += -e K6_VUS=$(K6_VUS)
endif
# Show load test help
loadtest-help:
@echo "GoChat Load Testing Commands"
@echo ""
@echo "Setup & Infrastructure:"
@echo " loadtest-setup - Pull required Docker images"
@echo " loadtest-start - Start services (with rebuild)"
@echo " loadtest-start-quick - Start services (no rebuild, faster)"
@echo " loadtest-stop - Stop all load test services"
@echo " loadtest-clean - Remove reports and volumes"
@echo ""
@echo " Tip: Use NOBUILD=1 to skip rebuild: make loadtest-start NOBUILD=1"
@echo ""
@echo "Test Scenarios:"
@echo " loadtest-full - Run complete system load test"
@echo " loadtest-capacity - Run step-based capacity baseline test"
@echo " loadtest-login - Test /user/login endpoint only"
@echo " loadtest-register - Test /user/register endpoint only"
@echo " loadtest-logout - Test /user/logout endpoint only"
@echo " loadtest-checkauth - Test /user/checkAuth endpoint only"
@echo " loadtest-websocket - Test WebSocket connections only"
@echo " loadtest-push - Test /push/push endpoint only"
@echo " loadtest-pushroom - Test /push/pushRoom endpoint only"
@echo " loadtest-count - Test /push/count endpoint only"
@echo " loadtest-roominfo - Test /push/getRoomInfo endpoint only"
@echo " loadtest-smoke - Quick 30s smoke test (5 VUs)"
@echo " loadtest-custom - Run custom script (LOADTEST_SCRIPT=file.js)"
@echo ""
@echo "Reporting:"
@echo " loadtest-report - Generate HTML report from results"
@echo " loadtest-grafana - Start Grafana for real-time monitoring"
@echo ""
@echo "Configuration (all runtime-configurable):"
@echo " K6_VUS - Fixed number of virtual users"
@echo " K6_DURATION - Test duration (e.g., 5m, 10m)"
@echo " K6_START_VUS - Starting VUs for capacity test (default: 10)"
@echo " K6_END_VUS - Maximum VUs for capacity test (default: 100)"
@echo " K6_STEP_VUS - VU increment per step (default: 10)"
@echo " K6_STEP_DURATION - Duration at each step (default: 1m)"
@echo " K6_RAMP_DURATION - Ramp duration between steps (default: 30s)"
@echo " K6_WARMUP_DURATION - Warm-up per step (excluded from stats, default: 20s)"
@echo ""
@echo "Examples:"
@echo " make loadtest-full K6_VUS=200 K6_DURATION=10m"
@echo " make loadtest-capacity K6_START_VUS=10 K6_END_VUS=500 K6_STEP_VUS=50"
@echo " make loadtest-login K6_VUS=50 K6_DURATION=2m"
# Setup load testing environment
loadtest-setup:
@echo "Setting up load testing environment..."
@mkdir -p loadtest/reports
@mkdir -p loadtest/scripts/lib/vendor
@if [ ! -f loadtest/scripts/lib/vendor/k6-reporter.js ]; then \
echo "Downloading k6-reporter..."; \
curl -sL "https://raw.githubusercontent.com/benc-uk/k6-reporter/2.4.0/dist/bundle.js" \
-o loadtest/scripts/lib/vendor/k6-reporter.js; \
fi
$(LOADTEST_COMPOSE) pull k6 || true
@echo "Setup complete"
# Ensure k6-reporter dependency exists
loadtest-deps:
@mkdir -p loadtest/scripts/lib/vendor
@if [ ! -f loadtest/scripts/lib/vendor/k6-reporter.js ]; then \
echo "Downloading k6-reporter..."; \
curl -sL "https://raw.githubusercontent.com/benc-uk/k6-reporter/2.4.0/dist/bundle.js" \
-o loadtest/scripts/lib/vendor/k6-reporter.js; \
fi
# Start services for load testing (with resource limits)
# Use NOBUILD=1 to skip rebuilding images (e.g., make loadtest-start NOBUILD=1)
loadtest-start: loadtest-deps
@echo "Starting GoChat services for load testing..."
ifeq ($(NOBUILD),1)
$(LOADTEST_COMPOSE) up -d --scale logic=$(LOGIC_REPLICAS) etcd redis rabbitmq postgres jaeger prometheus grafana logic connect-ws connect-tcp task api
else
$(LOADTEST_COMPOSE) up -d --build --scale logic=$(LOGIC_REPLICAS) etcd redis rabbitmq postgres jaeger prometheus grafana logic connect-ws connect-tcp task api
endif
@echo "Waiting for Redis to be ready..."
@sleep 5
@echo "Flushing Redis data for clean test environment..."
@docker exec gochat-redis redis-cli FLUSHALL || true
@echo "Truncating users so repeated runs start from the same state..."
@docker exec gochat-postgres psql -U gochat -d gochat -c "TRUNCATE users RESTART IDENTITY" || true
@echo "Waiting for services to be healthy (55s)..."
@sleep 55
@echo "Services ready for load testing"
# Start services without rebuilding (quick start for load testing)
loadtest-start-quick: loadtest-deps
@echo "Starting GoChat services for load testing (no rebuild)..."
$(LOADTEST_COMPOSE) up -d --scale logic=$(LOGIC_REPLICAS) etcd redis rabbitmq postgres jaeger prometheus grafana logic connect-ws connect-tcp task api
@echo "Waiting for Redis to be ready..."
@sleep 5
@echo "Flushing Redis data for clean test environment..."
@docker exec gochat-redis redis-cli FLUSHALL || true
@echo "Truncating users so repeated runs start from the same state..."
@docker exec gochat-postgres psql -U gochat -d gochat -c "TRUNCATE users RESTART IDENTITY" || true
@echo "Waiting for services to be healthy (55s)..."
@sleep 55
@echo "Services ready for load testing"
# Stop load testing environment
loadtest-stop:
@echo "Stopping load testing environment..."
$(LOADTEST_COMPOSE) down
# Run full system load test
loadtest-full: loadtest-start
@echo "Running full system load test..."
@echo "Metrics streaming to Prometheus - view in Grafana at http://localhost:3000"
$(LOADTEST_COMPOSE) run --rm \
$(K6_ENV_VARS) \
k6 run --out experimental-prometheus-rw /scripts/full-system.js
@echo "Test complete. Report: loadtest/reports/full-system.html"
# Run capacity baseline test (step-based)
loadtest-capacity: loadtest-start
@echo "Running capacity baseline test..."
@echo "Configuration: Start=$(K6_START_VUS) End=$(K6_END_VUS) Step=$(K6_STEP_VUS)"
@echo "Metrics streaming to Prometheus - view in Grafana at http://localhost:3000"
$(LOADTEST_COMPOSE) run --rm \
$(K6_ENV_VARS) \
k6 run --out experimental-prometheus-rw /scripts/capacity-baseline.js
@echo "Test complete. Report: loadtest/reports/capacity-baseline.html"
# Run login endpoint test only
loadtest-login: loadtest-start
@echo "Running login endpoint load test..."
$(LOADTEST_COMPOSE) run --rm \
$(K6_ENV_VARS) \
k6 run --out experimental-prometheus-rw /scripts/scenarios/user-login.js
@echo "Test complete. Report: loadtest/reports/user-login.html"
# Run register endpoint test only
loadtest-register: loadtest-start
@echo "Running register endpoint load test..."
$(LOADTEST_COMPOSE) run --rm \
$(K6_ENV_VARS) \
k6 run --out experimental-prometheus-rw /scripts/scenarios/user-register.js
@echo "Test complete. Report: loadtest/reports/user-register.html"
# Run WebSocket endpoint test only
loadtest-websocket: loadtest-start
@echo "Running WebSocket load test..."
$(LOADTEST_COMPOSE) run --rm \
$(K6_ENV_VARS) \
k6 run --out experimental-prometheus-rw /scripts/scenarios/websocket.js
@echo "Test complete. Report: loadtest/reports/websocket.html"
# Run push endpoint test only
loadtest-push: loadtest-start
@echo "Running push endpoint load test..."
$(LOADTEST_COMPOSE) run --rm \
$(K6_ENV_VARS) \
k6 run --out experimental-prometheus-rw /scripts/scenarios/push-push.js
@echo "Test complete. Report: loadtest/reports/push-push.html"
# Run push room endpoint test only
loadtest-pushroom: loadtest-start
@echo "Running push room endpoint load test..."
$(LOADTEST_COMPOSE) run --rm \
$(K6_ENV_VARS) \
k6 run --out experimental-prometheus-rw /scripts/scenarios/push-room.js
@echo "Test complete. Report: loadtest/reports/push-room.html"
# Run logout endpoint test only
loadtest-logout: loadtest-start
@echo "Running logout endpoint load test..."
$(LOADTEST_COMPOSE) run --rm \
$(K6_ENV_VARS) \
k6 run --out experimental-prometheus-rw /scripts/scenarios/user-logout.js
@echo "Test complete. Report: loadtest/reports/user-logout.html"
# Run checkAuth endpoint test only
loadtest-checkauth: loadtest-start
@echo "Running checkAuth endpoint load test..."
$(LOADTEST_COMPOSE) run --rm \
$(K6_ENV_VARS) \
k6 run --out experimental-prometheus-rw /scripts/scenarios/user-checkauth.js
@echo "Test complete. Report: loadtest/reports/user-checkauth.html"
# Run push count endpoint test only
loadtest-count: loadtest-start
@echo "Running push count endpoint load test..."
$(LOADTEST_COMPOSE) run --rm \
$(K6_ENV_VARS) \
k6 run --out experimental-prometheus-rw /scripts/scenarios/push-count.js
@echo "Test complete. Report: loadtest/reports/push-count.html"
# Run room info endpoint test only
loadtest-roominfo: loadtest-start
@echo "Running room info endpoint load test..."
$(LOADTEST_COMPOSE) run --rm \
$(K6_ENV_VARS) \
k6 run --out experimental-prometheus-rw /scripts/scenarios/push-roominfo.js
@echo "Test complete. Report: loadtest/reports/push-roominfo.html"
# Run quick smoke test
loadtest-smoke: loadtest-start
@echo "Running smoke test (5 VUs, 30s)..."
$(LOADTEST_COMPOSE) run --rm \
-e K6_VUS=5 \
-e K6_DURATION=30s \
k6 run --out experimental-prometheus-rw /scripts/full-system.js
@echo "Smoke test complete"
# Run custom script
loadtest-custom: loadtest-start
@echo "Running custom load test: $(LOADTEST_SCRIPT)..."
$(LOADTEST_COMPOSE) run --rm \
$(K6_ENV_VARS) \
k6 run --out experimental-prometheus-rw /scripts/$(LOADTEST_SCRIPT)
# Start Grafana for load test visualization
loadtest-grafana:
@echo "Starting Grafana for load test visualization..."
$(LOADTEST_COMPOSE) --profile monitoring up -d grafana
@echo "Grafana available at http://localhost:3000 (admin/admin)"
# Clean load test artifacts
loadtest-clean:
@echo "Cleaning load test artifacts..."
rm -rf loadtest/reports/*.json loadtest/reports/*.html loadtest/reports/*.txt 2>/dev/null || true
$(LOADTEST_COMPOSE) down -v 2>/dev/null || true
@echo "Load test cleanup complete"
# Measure what a connect instance's departure costs its clients, with graceful
# shutdown on and then off. One image, one procedure, one variable changed.
drain-demo:
@echo "Running the shutdown A/B..."
bash scripts/drain-demo.sh