Skip to content

Commit 99e921f

Browse files
committed
Add debug endpoint for haproxy
1 parent e7be9fb commit 99e921f

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/aleph/vm/orchestrator/supervisor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
about_execution_records,
3333
about_executions,
3434
about_login,
35+
debug_haproxy,
3536
list_executions,
3637
list_executions_v2,
3738
notify_allocation,
@@ -146,6 +147,7 @@ def setup_webapp(pool: VmPool | None):
146147
web.post("/control/machine/{ref}/confidential/initialize", operate_confidential_initialize),
147148
web.get("/control/machine/{ref}/confidential/measurement", operate_confidential_measurement),
148149
web.post("/control/machine/{ref}/confidential/inject_secret", operate_confidential_inject_secret),
150+
web.get("/debug/haproxy", debug_haproxy),
149151
# /status APIs are used to check that the VM Orchestrator is running properly
150152
web.get("/status/check/fastapi", status_check_fastapi),
151153
web.get("/status/check/fastapi/legacy", status_check_fastapi_legacy),

src/aleph/vm/orchestrator/views/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from aleph_message.models import InstanceContent, ItemHash, MessageType, PaymentType
1919
from pydantic import ValidationError
2020

21+
from aleph.vm import haproxy
2122
from aleph.vm.conf import settings
2223
from aleph.vm.controllers.firecracker.executable import (
2324
ResourceDownloadError,
@@ -148,6 +149,26 @@ async def about_login(request: web.Request) -> web.Response:
148149
return web.json_response({"success": False}, status=401)
149150

150151

152+
async def debug_haproxy(request: web.Request) -> web.Response:
153+
""" "Debug endpoint to check the status of HAProxy and the domains mapped to it.
154+
155+
This is a debug endpoint and should not be used in production. The interface is subject to change.
156+
"""
157+
socket = settings.HAPROXY_SOCKET
158+
import pathlib
159+
160+
if not pathlib.Path(socket).exists():
161+
logger.info("HAProxy not running? socket not found, skip domain mapping update")
162+
return web.json_response({"status": "no socket"}, status=http.HTTPStatus)
163+
r: dict = {"status": "ok", "backends": {}}
164+
for backend in haproxy.HAPROXY_BACKENDS:
165+
r["backends"][str(backend["name"])] = haproxy.get_current_backends(socket, backend["name"])
166+
return web.json_response(
167+
r,
168+
dumps=dumps_for_json,
169+
)
170+
171+
151172
@cors_allow_all
152173
async def about_executions(request: web.Request) -> web.Response:
153174
"/about/executions/details Debugging endpoint with full execution details."

0 commit comments

Comments
 (0)