Skip to content
Merged
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
17 changes: 17 additions & 0 deletions src/nodenorm/handlers/health.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import importlib.resources
import json
from functools import lru_cache
from urllib.parse import urlparse

from elasticsearch import AsyncElasticsearch

import nodenorm
from nodenorm.biolink import BIOLINK_MODEL_VERSION
from nodenorm.handlers.base import NodeNormalizationBaseHandler


@lru_cache(maxsize=None)
def get_openapi_version() -> str:
"""Read the API version from the openapi.json spec bundled with the webapp."""
openapi_path = importlib.resources.files(nodenorm) / "webapp" / "openapi.json"
openapi_spec = json.loads(openapi_path.read_text(encoding="utf-8"))
return openapi_spec["info"]["version"]


class NodeNormHealthHandler(NodeNormalizationBaseHandler):
"""
Important Endpoints
Expand All @@ -24,6 +36,7 @@ async def get(self):
parsed_compendia_url = urlparse(compendia_url)
babel_version = parsed_compendia_url.path.rstrip("/").rsplit("/", maxsplit=1)[-1]
babel_markdown = f"https://github.com/ncatstranslator/Babel/blob/master/releases/{babel_version}.md"
version = get_openapi_version()
try:
attributes = [
"name",
Expand All @@ -46,14 +59,18 @@ async def get(self):
except Exception:
status_response = {
"status": "error",
"version": version,
"babel_version": babel_version,
"babel_version_url": babel_markdown,
"backend": "elasticsearch",
}
else:
status_response = {
"status": "running",
"version": version,
"babel_version": babel_version,
"babel_version_url": babel_markdown,
"backend": "elasticsearch",
"biolink_model_toolkit_version": BIOLINK_MODEL_VERSION,
**nodes,
}
Expand Down
2 changes: 1 addition & 1 deletion src/nodenorm/webapp/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"openapi": "3.1.0",
"info": {
"title": "Node Normalization",
"version": "2.3.26",
"version": "1.0.0",
"x-translator": {
"component": "Utility",
"team": [
Expand Down