Skip to content

Commit e26be48

Browse files
committed
Add /burn endpoint for CPU load simulation
1 parent aa4485e commit e26be48

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/common/core/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# Aptible health checks must be on /healthcheck and cannot redirect
1212
# see https://www.aptible.com/docs/core-concepts/apps/connecting-to-apps/app-endpoints/https-endpoints/health-checks
1313
re_path(r"^healthcheck", include("health_check.urls", namespace="health-aptible")),
14+
path("burn/", views.burn),
1415
]
1516

1617
if settings.PROMETHEUS_ENABLED:

src/common/core/views.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import time
23

34
import prometheus_client
45
from django.http import HttpResponse, JsonResponse
@@ -25,3 +26,17 @@ def metrics(request: Request) -> HttpResponse:
2526
metrics_page,
2627
content_type=prometheus_client.CONTENT_TYPE_LATEST,
2728
)
29+
30+
31+
def burn(request: Request) -> HttpResponse:
32+
"""
33+
Burn CPU for a specified duration to simulate load.
34+
35+
Usage: GET /burn?s=10 (burns CPU for 10 seconds)
36+
"""
37+
seconds = int(request.GET.get("s", 1))
38+
end_time = time.monotonic() + seconds
39+
while time.monotonic() < end_time:
40+
pass # Busy wait
41+
42+
return HttpResponse("waited")

0 commit comments

Comments
 (0)