From e7fea6870845b9be9b863016aee1416b179165da Mon Sep 17 00:00:00 2001 From: Matt Jia Date: Aug 14 2017 05:09:39 +0000 Subject: add health checks for the web application --- diff --git a/functional-tests/test_healthcheck.py b/functional-tests/test_healthcheck.py new file mode 100644 index 0000000..e27ff90 --- /dev/null +++ b/functional-tests/test_healthcheck.py @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0+ + + +def test_healthcheck(requests_session, greenwave_server): + r = requests_session.get(greenwave_server.url + 'healthcheck') + assert r.status_code == 200 + assert r.text == 'Health check OK' diff --git a/greenwave/app_factory.py b/greenwave/app_factory.py index f19c637..5519e7c 100644 --- a/greenwave/app_factory.py +++ b/greenwave/app_factory.py @@ -54,4 +54,16 @@ def create_app(config_obj=None): init_logging(app) # register blueprints app.register_blueprint(api, url_prefix="/api/v1.0") + app.add_url_rule('/healthcheck', view_func=healthcheck) return app + + +def healthcheck(): + """ + Request handler for performing an application-level health check. This is + not part of the published API, it is intended for use by OpenShift or other + monitoring tools. + + Returns a 200 response if the application is alive and able to serve requests. + """ + return ('Health check OK', 200, [('Content-Type', 'text/plain')])