diff --git a/README.md b/README.md index 2fac753..d2d057d 100644 --- a/README.md +++ b/README.md @@ -22,4 +22,4 @@ Accept: application/vnd.schemaorg.ld+json # for JSON-LD format [OpenAPI documentation available here.](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/uc-cdis/pidgin/master/openapi/swagger.yml) -The YAML file comtaining the OpenAPI documentation can be found in the `openapi` folder; see the README in that folder for more details. +The YAML file containing the OpenAPI documentation can be found in the `openapi` folder; see the README in that folder for more details. diff --git a/deployment/uwsgi/wsgi.py b/deployment/uwsgi/wsgi.py index f63d0f1..f36c877 100644 --- a/deployment/uwsgi/wsgi.py +++ b/deployment/uwsgi/wsgi.py @@ -5,4 +5,5 @@ config = app.config config["API_URL"] = "http://peregrine-service/v0/submission/graphql/" +config["API_HEALTH_URL"] = "http://peregrine-service/_status" application = app diff --git a/pidgin/app.py b/pidgin/app.py index 2729267..f939cf9 100644 --- a/pidgin/app.py +++ b/pidgin/app.py @@ -1,3 +1,4 @@ +from cdislogging import get_logger import flask import json import requests @@ -23,6 +24,8 @@ }, } +logger = get_logger(__name__, log_level="info") + @app.route("/") def get_core_metadata(object_id): @@ -59,6 +62,7 @@ def get_core_metadata(object_id): 404: description: No core metadata was found for this object_id """ + logger.info("Getting metadata for object_id: {}".format(object_id)) accept = flask.request.headers.get("Accept") if accept == "x-bibtex": return get_bibtex_metadata(object_id) @@ -286,7 +290,15 @@ def health_check(): responses: 200: description: Healthy - default: - description: Unhealthy + 500: + description: Unhealthy (Peregrine not available) """ + api_health_url = app.config.get("API_HEALTH_URL") + if not api_health_url: + raise PidginException("Pidgin is not configured with API_HEALTH_URL") + try: + requests.get(api_health_url) + except requests.exceptions.ConnectionError: + logger.error("Peregrine not available; returning unhealthy") + return "Unhealthy", 500 return "Healthy", 200 diff --git a/requirements.txt b/requirements.txt index 646cef2..ccfc5a5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ +cdislogging==1.0.0 Flask==1.0.2 requests==2.20.0 diff --git a/run.py b/run.py index 33f40f0..0642935 100644 --- a/run.py +++ b/run.py @@ -1,4 +1,5 @@ from pidgin.app import app app.config["API_URL"] = "http://localhost/v0/submission/graphql/" # peregrine endpoint +app.config["API_HEALTH_URL"] = "http://localhost/_status" app.run("127.0.0.1", 5000, debug=True) diff --git a/tests/system_test.py b/tests/system_test.py deleted file mode 100644 index 8d46415..0000000 --- a/tests/system_test.py +++ /dev/null @@ -1,3 +0,0 @@ -def test_status_endpoint(client): - res = client.get("/_status") - assert res.status_code == 200