From 0ed89918de79e4fe41e3e974159c1c227634ae2c Mon Sep 17 00:00:00 2001 From: Diana Rita Nanyanzi <31903212+d-rita@users.noreply.github.com> Date: Tue, 30 Aug 2022 02:59:31 +0300 Subject: [PATCH] Add simple health check endpoint to determine API accessibility --- API/main.py | 2 ++ API/system.py | 42 ++++++++++++++++++++++++++++++++++++++++++ src/galaxy/app.py | 2 -- 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 API/system.py diff --git a/API/main.py b/API/main.py index baac0d5c..0df04ff2 100644 --- a/API/main.py +++ b/API/main.py @@ -36,6 +36,7 @@ from .download_export import router as download_router from .test_router import router as test_router from .status import router as status_router +from .system import router as health_router from fastapi import Request from fastapi.responses import JSONResponse from src.galaxy.db_session import database_instance @@ -71,6 +72,7 @@ app.include_router(tm_router) app.include_router(status_router) app.include_router(raw_data_router) +app.include_router(health_router) if use_s3_to_upload is False : # only mount the disk if config is set to disk app.include_router(download_router) diff --git a/API/system.py b/API/system.py new file mode 100644 index 00000000..a42e47cd --- /dev/null +++ b/API/system.py @@ -0,0 +1,42 @@ +# Copyright (C) 2021 Humanitarian OpenStreetmap Team + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +# Humanitarian OpenStreetmap Team +# 1100 13th Street NW Suite 800 Washington, D.C. 20005 +# + +""" + Router Responsible for Checking API Health +""" + +from fastapi import APIRouter +from fastapi_versioning import version + +router = APIRouter(prefix="/system") + +@router.get("/health/") +@version(1) +def check_system_health(): + """Simple health check for API accessibility + + Returns: + + { + "status": "healthy" + } + """ + return {"status": "healthy"} + + \ No newline at end of file diff --git a/src/galaxy/app.py b/src/galaxy/app.py index e646568c..e920860c 100644 --- a/src/galaxy/app.py +++ b/src/galaxy/app.py @@ -1273,5 +1273,3 @@ def __call__(self, bytes_amount): self._seen_so_far += bytes_amount percentage = (self._seen_so_far / self._size) * 100 logging.debug("\r%s %s / %s (%.2f%%)" ,self._filename, self._seen_so_far, self._size,percentage) - - \ No newline at end of file