# Load Tests - veza-backend-api ## Installation ### k6 (recommandé) ```bash # Linux sudo gpg -k sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D9 echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list sudo apt-get update sudo apt-get install k6 # macOS brew install k6 # Windows choco install k6 ``` ### Vegeta (alternative) ```bash # Linux/macOS go install github.com/tsenart/vegeta@latest # Ou télécharger depuis https://github.com/tsenart/vegeta/releases ``` ## Utilisation ### k6 Load Test **Test basique** (endpoints critiques): ```bash k6 run scripts/loadtest/k6_load_test.js ``` **Avec URL personnalisée**: ```bash BASE_URL=http://staging.example.com:8080 k6 run scripts/loadtest/k6_load_test.js ``` **Avec token d'authentification** (pour tester endpoints protégés): ```bash AUTH_TOKEN=your_jwt_token BASE_URL=http://localhost:8080 k6 run scripts/loadtest/k6_load_test.js ``` **Test plus intensif** (modifier les stages dans le script): ```javascript stages: [ { duration: '1m', target: 50 }, // 50 VUs { duration: '2m', target: 50 }, { duration: '1m', target: 0 }, ], ``` ### Vegeta Load Test (alternative) **Test simple**: ```bash echo "GET http://localhost:8080/health" | vegeta attack -duration=30s -rate=10/s | vegeta report ``` **Test multiple endpoints**: ```bash cat < 500ms**: Performance dégradée 2. **Error rate > 5%**: Problèmes de stabilité 3. **Health check > 100ms**: Problème de base de données ou dépendances 4. **Readyz check > 200ms**: Problème de readiness ### Actions si seuils dépassés 1. **Vérifier logs application**: `tail -f /var/log/veza-backend-api/*.log` 2. **Vérifier métriques Prometheus**: - `veza_db_pool_open_connections` - `veza_gin_http_request_duration_seconds` - `veza_gin_http_requests_total{status=~"5.."}` 3. **Vérifier ressources système**: `htop`, `iostat`, `netstat` 4. **Consulter runbooks**: `docs/runbooks/` ## Intégration CI/CD ### Exemple GitHub Actions ```yaml - name: Run load tests run: | k6 run scripts/loadtest/k6_load_test.js ``` ### Exemple GitLab CI ```yaml load_test: script: - k6 run scripts/loadtest/k6_load_test.js only: - main - staging ``` ## Notes - Les tests utilisent des **credentials invalides** pour `/api/v1/auth/login` (attendu: 401) - Les tests **ne modifient pas** de données (read-only sauf login qui échoue) - Ajuster les **seuils** selon votre infrastructure (ex: latence réseau, CPU, etc.)