maurocarlu commited on
Commit
35ada21
·
1 Parent(s): 73d22a4

Introduce Locust load testing for the Skill Classification API, adding a test script, setup instructions, and required dependency.

Browse files
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,9 @@ 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
+
53
  # Data validation and quality
54
  great_expectations>=0.18.0
55
  deepchecks>=0.18.0