Skip to content

Commit

Permalink
Feature: Load balancer could not distinguish outdated supervisors
Browse files Browse the repository at this point in the history
The load balancer could not check if a supervisor is running the latest release using the status of a GET response.

This is useful for the healthcheck of the Traefik Proxy to ensure that backend CRNs are running the latest version.
  • Loading branch information
hoh committed May 11, 2022
1 parent 471ab9b commit e8fd32b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packaging/aleph-vm/DEBIAN/control
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ Version: 0.1.8
Architecture: all
Maintainer: Aleph.im
Description: Aleph.im VM execution engine
Depends: python3,python3-pip,python3-aiohttp,python3-msgpack,python3-aiodns,python3-sqlalchemy,python3-setproctitle,redis,python3-aioredis,python3-psutil,sudo,acl,curl,systemd-container,squashfs-tools,debootstrap
Depends: python3,python3-pip,python3-aiohttp,python3-msgpack,python3-aiodns,python3-sqlalchemy,python3-setproctitle,redis,python3-aioredis,python3-psutil,sudo,acl,curl,systemd-container,squashfs-tools,debootstrap,python3-packaging
Section: aleph-im
Priority: Extra
3 changes: 2 additions & 1 deletion vm_supervisor/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
about_executions,
about_config,
status_check_fastapi,
about_execution_records,
about_execution_records, status_check_version,
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -51,6 +51,7 @@ async def server_version_middleware(
web.get("/about/executions/records", about_execution_records),
web.get("/about/config", about_config),
web.get("/status/check/fastapi", status_check_fastapi),
web.get("/status/check/version", status_check_version),
web.route("*", "/vm/{ref}{suffix:.*}", run_code_from_path),
web.route("*", "/{suffix:.*}", run_code_from_hostname),
]
Expand Down
26 changes: 25 additions & 1 deletion vm_supervisor/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import logging
import os.path
from string import Template
from typing import Awaitable
from typing import Awaitable, Optional
from packaging.version import Version, InvalidVersion

import aiodns
import aiohttp
Expand Down Expand Up @@ -141,3 +142,26 @@ async def status_check_fastapi(request: web.Request):
"persistent_storage": await status.check_persistent_storage(session),
}
return web.json_response(result, status=200 if all(result.values()) else 503)


async def status_check_version(request: web.Request):
"""Check if the software is running a version equal or newer than the given one"""
reference_str: Optional[str] = request.query.get("reference")
if not reference_str:
raise web.HTTPBadRequest(text="Query field '?reference=` must be specified")
try:
reference = Version(reference_str)
except InvalidVersion as error:
raise web.HTTPBadRequest(text=error.args[0])

try:
current = Version(get_version_from_git())
except InvalidVersion as error:
raise web.HTTPServiceUnavailable(text=error.args[0])

if current >= reference:
return web.Response(
status=200, text=f"Up-to-date: version {current} >= {reference}"
)
else:
return web.HTTPForbidden(text=f"Outdated: version {current} < {reference}")

0 comments on commit e8fd32b

Please sign in to comment.