This project implements a distributed load testing solution using Playwright and Kubernetes. It measures page load times and provides real-time metrics through Prometheus and Grafana.
The solution consists of:
- Load testing workers running Playwright
- Prometheus for metrics collection
- Grafana for visualization
- Kubernetes for orchestration
- Node.js 16+
- Docker
- Minikube or a Kubernetes cluster
- kubectl
- Terraform (for infrastructure setup)
npm install
docker build -t playwright-load-tester .
- Start Minikube:
minikube start
- Deploy monitoring stack:
kubectl apply -f k8s/monitoring/local-monitoring.yaml
- Deploy load testers:
kubectl apply -f k8s/load-tester.yaml
- Prometheus UI:
kubectl port-forward -n monitoring svc/prometheus 9090:9090
Access at: http://localhost:9090
- Grafana UI:
kubectl port-forward -n monitoring svc/grafana 3000:3000
Access at: http://localhost:3000
- Default credentials: admin/admin
TARGET_URL
: URL to test (default: http://localhost:3000)CONCURRENT_SESSIONS
: Number of concurrent test sessions (default: 5)TEST_DURATION
: Test duration in milliseconds (default: 300000)THINK_TIME
: Time between requests in milliseconds (default: 2000)
The solution exposes the following metrics:
playwright_page_load_time_seconds
: Histogram of page load timesplaywright_page_load_errors_total
: Counter of page load errors
Example queries for Prometheus:
- Average page load time:
rate(playwright_page_load_time_seconds_sum[5m]) / rate(playwright_page_load_time_seconds_count[5m])
- Error rate:
rate(playwright_page_load_errors_total[5m])
Import the following dashboard to visualize the metrics:
- Go to Grafana UI
- Navigate to Dashboards > Import
- Use the dashboard ID: [TODO: Add dashboard ID]
- Pods not starting:
kubectl describe pod <pod-name> -n monitoring
kubectl logs <pod-name> -n monitoring
- Metrics not showing:
kubectl port-forward <pod-name> 3000:3000
curl localhost:3000/metrics
- Prometheus targets:
kubectl port-forward -n monitoring svc/prometheus 9090:9090
# Check targets in Prometheus UI
- Modify
src/worker.js
to add new test scenarios - Rebuild and redeploy:
docker build -t playwright-load-tester .
kubectl rollout restart deployment playwright-load-tester
- Start the worker locally:
node src/worker.js
- Access metrics:
curl localhost:3000/metrics
MIT