From f60ddb0195951303dae90f83bcb5294d664ff4d8 Mon Sep 17 00:00:00 2001 From: Erik Reid <erik.reid@geant.org> Date: Sun, 6 Mar 2022 15:11:57 +0100 Subject: [PATCH] added /ping endpoint --- docs/source/protocol.rst | 9 +------- inventory_provider/routes/default.py | 32 ++++++++++++++++++++++++++++ test/test_general_routes.py | 12 +++++++++++ 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/docs/source/protocol.rst b/docs/source/protocol.rst index ccbb59d5..6a6366f7 100644 --- a/docs/source/protocol.rst +++ b/docs/source/protocol.rst @@ -17,14 +17,7 @@ and www.json.org for more details. .. contents:: :local: -/version -------------- - -.. autofunction:: inventory_provider.routes.default.version - - -API modules --------------- +.. automodule:: inventory_provider.routes.default .. automodule:: inventory_provider.routes.classifier diff --git a/inventory_provider/routes/default.py b/inventory_provider/routes/default.py index 13b8fb12..ea82dd88 100644 --- a/inventory_provider/routes/default.py +++ b/inventory_provider/routes/default.py @@ -1,3 +1,23 @@ +""" +Health-related Endpoints +========================= + +These endpoints are intended for checking the status of the service. + +.. contents:: :local: + +/version +--------------------- + +.. autofunction:: inventory_provider.routes.default.version + +/ping +----------------------------- + +.. autofunction:: inventory_provider.routes.default.ping + + +""" import pkg_resources from flask import Blueprint, jsonify, current_app @@ -72,3 +92,15 @@ def version(): if latch: version_params['latch'] = latch return jsonify(version_params) + + +@routes.route('/ping', methods=['GET', 'POST']) +def ping(): + """ + This method can be used to verify the web service is alive + and processing requests. This endpoint is used by haproxy + for backend http checks. + + There's no response payload, only 204 (empty content) will be returned. + """ + return '', 204 diff --git a/test/test_general_routes.py b/test/test_general_routes.py index 8bc82db7..40efb46d 100644 --- a/test/test_general_routes.py +++ b/test/test_general_routes.py @@ -63,3 +63,15 @@ def test_load_json_docs(data_config, mocked_redis): for ifc in common.load_json_docs( data_config, 'netconf-interfaces:*', num_threads=20): jsonschema.validate(ifc, INTERFACE_SCHEMA) + + +def test_ping_post(client): + rv = client.post('ping') + assert rv.status_code == 204 + assert len(rv.data) == 0 + + +def test_ping_get(client): + rv = client.get('ping') + assert rv.status_code == 204 + assert len(rv.data) == 0 -- GitLab