From e183cd7c28c707f7458dadd71e560996ca67c95d Mon Sep 17 00:00:00 2001 From: Ben Pope Date: Thu, 3 Nov 2022 20:49:52 +0000 Subject: [PATCH 1/2] pp/rest: Add a health check Signed-off-by: Ben Pope (cherry picked from commit 2f979d1d39632b1040b64a7e6500c865cf134b63) --- src/v/pandaproxy/api/api-doc/rest.json | 14 ++++++++++++++ src/v/pandaproxy/rest/handlers.cc | 11 +++++++++++ src/v/pandaproxy/rest/handlers.h | 3 +++ src/v/pandaproxy/rest/proxy.cc | 4 ++++ 4 files changed, 32 insertions(+) diff --git a/src/v/pandaproxy/api/api-doc/rest.json b/src/v/pandaproxy/api/api-doc/rest.json index f34d9368272e..44ebecbe7aee 100644 --- a/src/v/pandaproxy/api/api-doc/rest.json +++ b/src/v/pandaproxy/api/api-doc/rest.json @@ -547,4 +547,18 @@ } } } + }, + "/status/ready": { + "get": { + "summary": "Health check", + "operationId": "http_rest_status_ready", + "responses": { + "200": { + "description": "Success" + }, + "503": { + "description": "Service Unavailable" + } + } + } } \ No newline at end of file diff --git a/src/v/pandaproxy/rest/handlers.cc b/src/v/pandaproxy/rest/handlers.cc index d3b5dc4be0e2..9c74cd832674 100644 --- a/src/v/pandaproxy/rest/handlers.cc +++ b/src/v/pandaproxy/rest/handlers.cc @@ -523,4 +523,15 @@ post_consumer_offsets(server::request_t rq, server::reply_t rp) { group_shard, rq.context().smp_sg, std::move(handler)); } +ss::future +status_ready(proxy::server::request_t rq, proxy::server::reply_t rp) { + auto make_metadata_req = []() { + return kafka::metadata_request{.list_all_topics = false}; + }; + + auto res = co_await rq.dispatch(make_metadata_req); + rp.rep->set_status(ss::httpd::reply::status_type::ok); + co_return rp; +} + } // namespace pandaproxy::rest diff --git a/src/v/pandaproxy/rest/handlers.h b/src/v/pandaproxy/rest/handlers.h index 4b6c18e8075a..8e8fa9ccef3b 100644 --- a/src/v/pandaproxy/rest/handlers.h +++ b/src/v/pandaproxy/rest/handlers.h @@ -49,4 +49,7 @@ ss::future::reply_t> get_consumer_offsets( ss::future::reply_t> post_consumer_offsets( ctx_server::request_t rq, ctx_server::reply_t rp); +ss::future +status_ready(proxy::server::request_t rq, proxy::server::reply_t rp); + } // namespace pandaproxy::rest diff --git a/src/v/pandaproxy/rest/proxy.cc b/src/v/pandaproxy/rest/proxy.cc index d277e91d506c..4c0f23c8f54f 100644 --- a/src/v/pandaproxy/rest/proxy.cc +++ b/src/v/pandaproxy/rest/proxy.cc @@ -56,6 +56,10 @@ server::routes_t get_proxy_routes() { routes.routes.emplace_back(server::route_t{ ss::httpd::rest_json::post_consumer_offsets, post_consumer_offsets}); + routes.routes.emplace_back(server::route_t{ + ss::httpd::rest_json::http_rest_status_ready, + wrap(gate, es, status_ready)}); + return routes; } From f7859ff4b515a2c266ecc4d143666d17beb0d3c0 Mon Sep 17 00:00:00 2001 From: Ben Pope Date: Thu, 3 Nov 2022 20:50:08 +0000 Subject: [PATCH 2/2] schema_registry: Add a health check Signed-off-by: Ben Pope (cherry picked from commit 35f1fd0396fbd3562efa053a4b51a1afa0485b92) --- src/v/pandaproxy/api/api-doc/schema_registry.json | 14 ++++++++++++++ src/v/pandaproxy/schema_registry/handlers.cc | 7 +++++++ src/v/pandaproxy/schema_registry/handlers.h | 3 +++ src/v/pandaproxy/schema_registry/service.cc | 4 ++++ 4 files changed, 28 insertions(+) diff --git a/src/v/pandaproxy/api/api-doc/schema_registry.json b/src/v/pandaproxy/api/api-doc/schema_registry.json index dd81567ec34e..b8cdee5cfded 100644 --- a/src/v/pandaproxy/api/api-doc/schema_registry.json +++ b/src/v/pandaproxy/api/api-doc/schema_registry.json @@ -848,4 +848,18 @@ } } } + }, + "/status/ready": { + "get": { + "summary": "Health check", + "operationId": "schema_registry_status_ready", + "responses": { + "200": { + "description": "Success" + }, + "503": { + "description": "Service Unavailable" + } + } + } } diff --git a/src/v/pandaproxy/schema_registry/handlers.cc b/src/v/pandaproxy/schema_registry/handlers.cc index 4df90c707568..97e754212650 100644 --- a/src/v/pandaproxy/schema_registry/handlers.cc +++ b/src/v/pandaproxy/schema_registry/handlers.cc @@ -516,4 +516,11 @@ compatibility_subject_version(server::request_t rq, server::reply_t rp) { co_return rp; } +ss::future +status_ready(server::request_t rq, server::reply_t rp) { + co_await rq.service().writer().read_sync(); + rp.rep->set_status(ss::httpd::reply::status_type::ok); + co_return rp; +} + } // namespace pandaproxy::schema_registry diff --git a/src/v/pandaproxy/schema_registry/handlers.h b/src/v/pandaproxy/schema_registry/handlers.h index 35b39441b1f6..20fec78eba63 100644 --- a/src/v/pandaproxy/schema_registry/handlers.h +++ b/src/v/pandaproxy/schema_registry/handlers.h @@ -74,4 +74,7 @@ ss::future::reply_t> delete_subject_version( ss::future::reply_t> compatibility_subject_version( ctx_server::request_t rq, ctx_server::reply_t rp); +ss::future::reply_t> status_ready( + ctx_server::request_t rq, ctx_server::reply_t rp); + } // namespace pandaproxy::schema_registry diff --git a/src/v/pandaproxy/schema_registry/service.cc b/src/v/pandaproxy/schema_registry/service.cc index a430a0032870..c76708710040 100644 --- a/src/v/pandaproxy/schema_registry/service.cc +++ b/src/v/pandaproxy/schema_registry/service.cc @@ -130,6 +130,10 @@ server::routes_t get_schema_registry_routes(ss::gate& gate, one_shot& es) { ss::httpd::schema_registry_json::compatibility_subject_version, wrap(gate, es, compatibility_subject_version)}); + routes.routes.emplace_back(server::route_t{ + ss::httpd::schema_registry_json::schema_registry_status_ready, + wrap(gate, es, status_ready)}); + return routes; }