From 02bbaaf71425394082559c12f3c188f535bd5d7a Mon Sep 17 00:00:00 2001 From: nuwang <2070605+nuwang@users.noreply.github.com> Date: Fri, 21 Feb 2025 00:12:07 +0530 Subject: [PATCH] Add health check endpoint --- pulsar/web/routes.py | 6 ++++++ test/wsgi_app_test.py | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/pulsar/web/routes.py b/pulsar/web/routes.py index 4d6b0756..dd343a9a 100644 --- a/pulsar/web/routes.py +++ b/pulsar/web/routes.py @@ -4,6 +4,7 @@ from webob import exc +from pulsar import __version__ as pulsar_version from pulsar.client.action_mapper import path_type from pulsar.client.job_directory import verify_is_in_directory from pulsar.manager_endpoint_util import ( @@ -224,6 +225,11 @@ def object_store_get_store_usage_percent(object_store): return object_store.get_store_usage_percent() +@PulsarController(path="/healthz", method="GET", response_type='json') +def healthz(): + return {'version': pulsar_version} + + class PulsarDataset: """Intermediary between Pulsar and objectstore.""" diff --git a/test/wsgi_app_test.py b/test/wsgi_app_test.py index 21c3db18..3073c4c3 100644 --- a/test/wsgi_app_test.py +++ b/test/wsgi_app_test.py @@ -3,6 +3,8 @@ import time from urllib.parse import quote +from pulsar import __version__ as pulsar_version + def test_standard_requests(): """ Tests app controller methods. These tests should be @@ -68,3 +70,8 @@ def test_upload(upload_type): clean_response = app.delete("/jobs/%s" % job_id) assert clean_response.body.decode("utf-8") == 'OK' assert os.listdir(staging_directory) == [] + + # test healthz endpoint + healthz_response = app.get("/healthz") + healthz_data = json.loads(healthz_response.body.decode("utf-8")) + assert healthz_data["version"] == pulsar_version