Skip to content

Add load test #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions alerting/rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Binary file added locust/__pycache__/locustfile.cpython-311.pyc
Binary file not shown.
11 changes: 11 additions & 0 deletions locust/docker-compose.locust.yml
Original file line number Diff line number Diff line change
@@ -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"
22 changes: 22 additions & 0 deletions locust/locustfile.py
Original file line number Diff line number Diff line change
@@ -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)