From 728ab99fa7d506566c054240e18017da064f177f Mon Sep 17 00:00:00 2001 From: Harsh pratap Singh Date: Wed, 12 Feb 2025 01:12:14 +0530 Subject: [PATCH] Add load test --- alerting/rules.yml | 4 ++-- locust/__pycache__/locustfile.cpython-311.pyc | Bin 0 -> 1698 bytes locust/docker-compose.locust.yml | 11 +++++++++ locust/locustfile.py | 22 ++++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 locust/__pycache__/locustfile.cpython-311.pyc create mode 100644 locust/docker-compose.locust.yml create mode 100644 locust/locustfile.py diff --git a/alerting/rules.yml b/alerting/rules.yml index 1a507d1..cb8ca35 100644 --- a/alerting/rules.yml +++ b/alerting/rules.yml @@ -2,7 +2,7 @@ groups: - name: WebServerAlerts rules: - alert: HighResponseTime - expr: rate(http_request_duration_seconds_sum[5m]) / rate(http_request_duration_seconds_count[5m]) > 0.5 + expr: rate(flask_http_request_duration_seconds_sum[5m]) / rate(flask_http_request_duration_seconds_count[5m]) > 0.5 for: 5m labels: severity: warning @@ -11,7 +11,7 @@ groups: description: Average response time is above 500ms for 5 minutes - alert: HighErrorRate - expr: rate(http_requests_total{status_code=~"5.."}[5m]) / rate(http_requests_total[5m]) > 0.05 + expr: rate(flask_http_requests_total{status_code=~"5.."}[5m]) / rate(flask_http_requests_total[5m]) > 0.05 for: 5m labels: severity: critical diff --git a/locust/__pycache__/locustfile.cpython-311.pyc b/locust/__pycache__/locustfile.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2e2f19f12f75b4658ec4b4d75cf5d2d26bb7b561 GIT binary patch literal 1698 zcmcIk&uiR96rPc^E3LEJZHS#Xm!kflu!ZaU)x9)^-BDbawRg^xh}E`M!Cx ze^e?H1jd8kHy0*#LjJ*rd=&PaozKBpB`$GkKtkH4q1M(yy{%KCk*|oWEfZJgbRFK` zgex0u!!_net+0)cH9fJeC>39mTqK5K@=jvj;%bTWZf6gl-i*D6o!`J&C7iUWOWK-7 zxb9L{Ti2ihT-ksMdbXvq=W^#$)J+1k*O zVkhutp%;)Sfc+1K|=Bksp8=kWrD8Dvypmu0E`;=})h%R9{%sHbdZE5ZB#M6hMRq*vcH8(#XxtSG}0 zTjCwC;y9R0LvaG!q?}=#^sD{JT#fN4zV`+(O3yz-F)nUd7l-*2Q-IyZ-anuS9?`Us zX2AKcjpXV+b&Y3*g9jGcsR%7?_U$=8>;+75TY?ryo7vxfGk4V%S)0|xDJYhhA(s+2 zx~#DGVs;NVdbXw|#-fb6q5_~+O%qiF8!?=NBN83Q0uH92J<}HMpU!nUl0s4C88G{u z^OrUKr!~EH`f2U?55wBb@cZjSYx;$CW6QcR%x9`wt2U8Xj?-l!cbsIxal**$1?ZO@ z=WdS$Sw^6mNok4s%29sE69Z4Lz{4sg(M+Rx56lKhzngBfFfob-H$wgjX0ZQz`R=Ko z%r&}p?&r!cmBH80^5qW)Gk+IKgR3j=|2V%qKhm_qry~O9l}?J4JYbRH#5kmhkmeYq zIXVovNfC3Cj)C$}mdKWj3vJa3NijRa0vDZ8MD`h(kI=)0O9}2;UuJq;5+6eh|0W~@ gGtw!gFUcpvx6hGrg5o0HY*)NjY3B7?^63)(1=1CZ{r~^~ literal 0 HcmV?d00001 diff --git a/locust/docker-compose.locust.yml b/locust/docker-compose.locust.yml new file mode 100644 index 0000000..39a3444 --- /dev/null +++ b/locust/docker-compose.locust.yml @@ -0,0 +1,11 @@ +version: '3.8' + +services: + locust: + image: locustio/locust + volumes: + - .:/mnt/locust # Mount the current folder, NOT ./locust + working_dir: /mnt/locust + command: locust -f /mnt/locust/locustfile.py + ports: + - "8089:8089" diff --git a/locust/locustfile.py b/locust/locustfile.py new file mode 100644 index 0000000..fff5150 --- /dev/null +++ b/locust/locustfile.py @@ -0,0 +1,22 @@ +from locust import HttpUser, task, between + +class WebUser(HttpUser): + wait_time = between(1, 3) + + + host = "http://localhost:7100" + + @task(3) + def load_homepage(self): + """Request the home page.""" + self.client.get("/", allow_redirects=False) + + @task(1) + def health_check(self): + """Call the health check endpoint without a trailing slash.""" + self.client.get("/health", allow_redirects=False) + + @task(2) + def send_post_request(self): + """Simulate sending a POST request.""" + self.client.post("/health", json={"message": "test payload"}, allow_redirects=False)