From 33dcad674d41b7dc872cafa0e2f9d8e3e018a2aa Mon Sep 17 00:00:00 2001 From: Pauline Ribeyre Date: Thu, 11 Jul 2019 15:06:05 -0500 Subject: [PATCH 1/3] fix(status): unhealthy if no peregrine --- README.md | 2 +- pidgin/app.py | 13 +++++++++++-- requirements.txt | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) 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/pidgin/app.py b/pidgin/app.py index 2729267..11771a9 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,12 @@ def health_check(): responses: 200: description: Healthy - default: - description: Unhealthy + 500: + description: Unhealthy (Peregrine not available) """ + try: + send_query("{ program { name } }") + 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 From 46054765abeca26da386b9305abb60217c532de0 Mon Sep 17 00:00:00 2001 From: Pauline Ribeyre Date: Thu, 11 Jul 2019 15:53:19 -0500 Subject: [PATCH 2/3] fix(status): remove status test --- pidgin/app.py | 2 +- tests/system_test.py | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) delete mode 100644 tests/system_test.py diff --git a/pidgin/app.py b/pidgin/app.py index 11771a9..5a34a9b 100644 --- a/pidgin/app.py +++ b/pidgin/app.py @@ -24,7 +24,7 @@ }, } -logger = get_logger(__name__, log_level='info') +logger = get_logger(__name__, log_level="info") @app.route("/") 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 From 8f3b7c1b23a407f8df20bab68feec263a7e45aee Mon Sep 17 00:00:00 2001 From: Pauline Ribeyre Date: Thu, 11 Jul 2019 17:19:33 -0500 Subject: [PATCH 3/3] fix(status): check peregrine status --- deployment/uwsgi/wsgi.py | 1 + pidgin/app.py | 5 ++++- run.py | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) 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 5a34a9b..f939cf9 100644 --- a/pidgin/app.py +++ b/pidgin/app.py @@ -293,8 +293,11 @@ def health_check(): 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: - send_query("{ program { name } }") + requests.get(api_health_url) except requests.exceptions.ConnectionError: logger.error("Peregrine not available; returning unhealthy") return "Unhealthy", 500 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)