Spaces:
Sleeping
Sleeping
merge: unify Milestone-5-fix and Milestone-6 histories for PR
Browse files- monitoring/locust/README.md +101 -0
- monitoring/locust/locustfile.py +99 -0
- requirements.txt +2 -0
monitoring/locust/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Locust Load Testing - Skill Classification API
|
| 2 |
+
|
| 3 |
+
Questa directory contiene gli script per il load testing della Skill Classification API utilizzando [Locust](https://locust.io/).
|
| 4 |
+
|
| 5 |
+
## Prerequisiti
|
| 6 |
+
|
| 7 |
+
Assicurati di avere Python installato e installa Locust:
|
| 8 |
+
|
| 9 |
+
```bash
|
| 10 |
+
pip install locust
|
| 11 |
+
```
|
| 12 |
+
|
| 13 |
+
## Avvio del Test
|
| 14 |
+
|
| 15 |
+
### 1. Avvia Locust
|
| 16 |
+
|
| 17 |
+
Dalla directory `monitoring/locust/`, esegui:
|
| 18 |
+
|
| 19 |
+
```bash
|
| 20 |
+
locust -f locustfile.py
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
### 2. Accedi alla Web UI
|
| 24 |
+
|
| 25 |
+
Apri il browser e vai a: **http://localhost:8089**
|
| 26 |
+
|
| 27 |
+
### 3. Configura il Test
|
| 28 |
+
|
| 29 |
+
Nella Web UI, configura i seguenti parametri:
|
| 30 |
+
|
| 31 |
+
| Parametro | Descrizione | Valore Consigliato |
|
| 32 |
+
|-----------|-------------|-------------------|
|
| 33 |
+
| **Host** | URL dell'API da testare | `http://localhost:8080` (Docker) o `http://localhost:8000` (locale) |
|
| 34 |
+
| **Number of users** | Numero totale di utenti simulati | 10-100 |
|
| 35 |
+
| **Spawn rate** | Utenti da creare al secondo | 1-10 |
|
| 36 |
+
|
| 37 |
+
### 4. Avvia il Test
|
| 38 |
+
|
| 39 |
+
Clicca su **"Start swarming"** per avviare il test di carico.
|
| 40 |
+
|
| 41 |
+
## Task Implementati
|
| 42 |
+
|
| 43 |
+
Lo script simula il comportamento di utenti reali con i seguenti task:
|
| 44 |
+
|
| 45 |
+
| Task | Endpoint | Metodo | Peso | Descrizione |
|
| 46 |
+
|------|----------|--------|------|-------------|
|
| 47 |
+
| **Predizione Singola** | `/predict` | POST | 3 | Classifica un singolo issue text. Task principale, eseguito più frequentemente. |
|
| 48 |
+
| **Predizione Batch** | `/predict/batch` | POST | 1 | Classifica multipli issue text in una singola richiesta. |
|
| 49 |
+
| **Monitoraggio e Storia** | `/predictions`, `/health` | GET | 1 | Visualizza la cronologia delle predizioni e verifica lo stato del sistema. |
|
| 50 |
+
|
| 51 |
+
### Distribuzione dei Pesi
|
| 52 |
+
|
| 53 |
+
Con i pesi configurati (3:1:1), la distribuzione approssimativa delle richieste è:
|
| 54 |
+
- **60%** - Predizione Singola
|
| 55 |
+
- **20%** - Predizione Batch
|
| 56 |
+
- **20%** - Monitoraggio e Storia
|
| 57 |
+
|
| 58 |
+
### Tempo di Attesa
|
| 59 |
+
|
| 60 |
+
Ogni utente attende tra **1 e 5 secondi** tra un task e l'altro per simulare un comportamento realistico.
|
| 61 |
+
|
| 62 |
+
## Metriche Monitorate
|
| 63 |
+
|
| 64 |
+
Durante il test, Locust fornisce le seguenti metriche in tempo reale:
|
| 65 |
+
|
| 66 |
+
- **RPS (Requests Per Second)**: Numero di richieste al secondo
|
| 67 |
+
- **Response Time**: Tempo medio/mediano/percentili di risposta
|
| 68 |
+
- **Failure Rate**: Percentuale di richieste fallite
|
| 69 |
+
- **Active Users**: Numero di utenti attualmente attivi
|
| 70 |
+
|
| 71 |
+
## Opzioni Avanzate
|
| 72 |
+
|
| 73 |
+
### Esecuzione Headless (senza UI)
|
| 74 |
+
|
| 75 |
+
```bash
|
| 76 |
+
locust -f locustfile.py --headless -u 50 -r 5 -t 5m --host http://localhost:8000
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
| Opzione | Descrizione |
|
| 80 |
+
|---------|-------------|
|
| 81 |
+
| `--headless` | Esegui senza Web UI |
|
| 82 |
+
| `-u 50` | 50 utenti simulati |
|
| 83 |
+
| `-r 5` | 5 utenti creati al secondo |
|
| 84 |
+
| `-t 5m` | Durata del test: 5 minuti |
|
| 85 |
+
| `--host` | URL dell'API |
|
| 86 |
+
|
| 87 |
+
### Esportazione Risultati
|
| 88 |
+
|
| 89 |
+
```bash
|
| 90 |
+
locust -f locustfile.py --headless -u 50 -r 5 -t 5m --host http://localhost:8000 --csv=results
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
Questo creerà file CSV con i risultati del test.
|
| 94 |
+
|
| 95 |
+
## Struttura File
|
| 96 |
+
|
| 97 |
+
```
|
| 98 |
+
monitoring/locust/
|
| 99 |
+
├── locustfile.py # Script principale di load testing
|
| 100 |
+
└── README.md # Questa documentazione
|
| 101 |
+
```
|
monitoring/locust/locustfile.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Locust Load Testing Script for Skill Classification API
|
| 3 |
+
|
| 4 |
+
This script defines user behavior for load testing the prediction and monitoring
|
| 5 |
+
endpoints of the Skill Classification API.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from locust import HttpUser, task, between
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class SkillClassificationUser(HttpUser):
|
| 12 |
+
"""
|
| 13 |
+
Simulated user for load testing the Skill Classification API.
|
| 14 |
+
|
| 15 |
+
This user performs the following actions:
|
| 16 |
+
- Single predictions (most frequent)
|
| 17 |
+
- Batch predictions
|
| 18 |
+
- Monitoring and health checks
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
# Default host for the API (can be overridden via --host flag or Web UI)
|
| 22 |
+
# Use http://localhost:8080 for Docker or http://localhost:8000 for local dev
|
| 23 |
+
host = "http://localhost:8080"
|
| 24 |
+
|
| 25 |
+
# Wait between 1 and 5 seconds between tasks to simulate real user behavior
|
| 26 |
+
wait_time = between(1, 5)
|
| 27 |
+
|
| 28 |
+
@task(3)
|
| 29 |
+
def predict_single(self):
|
| 30 |
+
"""
|
| 31 |
+
Task 1: Single Prediction (Weight: 3)
|
| 32 |
+
|
| 33 |
+
Performs a POST request to /predict with a single issue text.
|
| 34 |
+
This is the main task and executes more frequently due to higher weight.
|
| 35 |
+
"""
|
| 36 |
+
payload = {
|
| 37 |
+
"issue_text": "Fix authentication bug in login module"
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
with self.client.post(
|
| 41 |
+
"/predict",
|
| 42 |
+
json=payload,
|
| 43 |
+
catch_response=True
|
| 44 |
+
) as response:
|
| 45 |
+
if response.status_code == 201:
|
| 46 |
+
response.success()
|
| 47 |
+
else:
|
| 48 |
+
response.failure(f"Prediction failed with status {response.status_code}")
|
| 49 |
+
|
| 50 |
+
@task(1)
|
| 51 |
+
def predict_batch(self):
|
| 52 |
+
"""
|
| 53 |
+
Task 2: Batch Prediction (Weight: 1)
|
| 54 |
+
|
| 55 |
+
Performs a POST request to /predict/batch with multiple issue texts.
|
| 56 |
+
"""
|
| 57 |
+
payload = {
|
| 58 |
+
"issues": [
|
| 59 |
+
{"issue_text": "Test 1"},
|
| 60 |
+
{"issue_text": "Test 2"}
|
| 61 |
+
]
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
with self.client.post(
|
| 65 |
+
"/predict/batch",
|
| 66 |
+
json=payload,
|
| 67 |
+
catch_response=True
|
| 68 |
+
) as response:
|
| 69 |
+
if response.status_code == 200:
|
| 70 |
+
response.success()
|
| 71 |
+
else:
|
| 72 |
+
response.failure(f"Batch prediction failed with status {response.status_code}")
|
| 73 |
+
|
| 74 |
+
@task(1)
|
| 75 |
+
def monitoring_and_history(self):
|
| 76 |
+
"""
|
| 77 |
+
Task 3: Monitoring and History (Weight: 1)
|
| 78 |
+
|
| 79 |
+
Performs GET requests to check prediction history and system health.
|
| 80 |
+
"""
|
| 81 |
+
# Check prediction history
|
| 82 |
+
with self.client.get(
|
| 83 |
+
"/predictions",
|
| 84 |
+
catch_response=True
|
| 85 |
+
) as response:
|
| 86 |
+
if 200 <= response.status_code < 300:
|
| 87 |
+
response.success()
|
| 88 |
+
else:
|
| 89 |
+
response.failure(f"Predictions history failed with status {response.status_code}")
|
| 90 |
+
|
| 91 |
+
# Check system health
|
| 92 |
+
with self.client.get(
|
| 93 |
+
"/health",
|
| 94 |
+
catch_response=True
|
| 95 |
+
) as response:
|
| 96 |
+
if 200 <= response.status_code < 300:
|
| 97 |
+
response.success()
|
| 98 |
+
else:
|
| 99 |
+
response.failure(f"Health check failed with status {response.status_code}")
|
requirements.txt
CHANGED
|
@@ -47,6 +47,8 @@ pytest-json-report>=1.5.0
|
|
| 47 |
pytest-cov>=4.0.0
|
| 48 |
pytest-xdist>=3.0.0
|
| 49 |
|
|
|
|
|
|
|
| 50 |
# Data validation and quality
|
| 51 |
great_expectations>=0.18.0
|
| 52 |
deepchecks>=0.18.0
|
|
|
|
| 47 |
pytest-cov>=4.0.0
|
| 48 |
pytest-xdist>=3.0.0
|
| 49 |
|
| 50 |
+
# Load testing
|
| 51 |
+
locust>=2.20.0
|
| 52 |
# Data validation and quality
|
| 53 |
great_expectations>=0.18.0
|
| 54 |
deepchecks>=0.18.0
|