From e3b558b64239b5b153071c8ece5dedef0f1f1a19 Mon Sep 17 00:00:00 2001 From: ilya Date: Fri, 17 Nov 2023 10:22:44 +0000 Subject: [PATCH] Healthz endpoints for Driver and Solvers (#2060) # Description Adds liveness endpoints for `driver` and `solvers` crates. # Changes 2 new GET endpoints always returning `200OK` ## How to test Will be tested in scope of the https://github.com/cowprotocol/infrastructure/pull/858 deployment ## Related Issues Fixes #1382 --- crates/driver/src/infra/api/mod.rs | 3 ++- crates/driver/src/infra/api/routes/healthz.rs | 9 +++++++++ crates/driver/src/infra/api/routes/mod.rs | 2 ++ crates/solvers/src/api/mod.rs | 1 + crates/solvers/src/api/routes/healthz.rs | 5 +++++ crates/solvers/src/api/routes/mod.rs | 3 ++- 6 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 crates/driver/src/infra/api/routes/healthz.rs create mode 100644 crates/solvers/src/api/routes/healthz.rs diff --git a/crates/driver/src/infra/api/mod.rs b/crates/driver/src/infra/api/mod.rs index 7dc4794ca1..5f078c6490 100644 --- a/crates/driver/src/infra/api/mod.rs +++ b/crates/driver/src/infra/api/mod.rs @@ -43,8 +43,9 @@ impl Api { let tokens = tokens::Fetcher::new(self.eth.clone()); let pre_processor = domain::competition::AuctionProcessor::new(Arc::new(self.eth.clone())); - // Add the metrics endpoint. + // Add the metrics and healthz endpoints. app = routes::metrics(app); + app = routes::healthz(app); // Multiplex each solver as part of the API. Multiple solvers are multiplexed // on the same driver so only one liquidity collector collects the liquidity diff --git a/crates/driver/src/infra/api/routes/healthz.rs b/crates/driver/src/infra/api/routes/healthz.rs new file mode 100644 index 0000000000..157f557a93 --- /dev/null +++ b/crates/driver/src/infra/api/routes/healthz.rs @@ -0,0 +1,9 @@ +use axum::{http::StatusCode, response::IntoResponse, routing::get}; + +pub(in crate::infra::api) fn healthz(app: axum::Router<()>) -> axum::Router<()> { + app.route("/healthz", get(route)) +} + +async fn route() -> impl IntoResponse { + StatusCode::OK +} diff --git a/crates/driver/src/infra/api/routes/mod.rs b/crates/driver/src/infra/api/routes/mod.rs index d1661dab2e..ee1027b0e9 100644 --- a/crates/driver/src/infra/api/routes/mod.rs +++ b/crates/driver/src/infra/api/routes/mod.rs @@ -1,3 +1,4 @@ +mod healthz; mod info; mod metrics; mod quote; @@ -6,6 +7,7 @@ mod settle; mod solve; pub(super) use { + healthz::healthz, info::info, metrics::metrics, quote::{quote, OrderError}, diff --git a/crates/solvers/src/api/mod.rs b/crates/solvers/src/api/mod.rs index b5c4bbf1a8..12e8619592 100644 --- a/crates/solvers/src/api/mod.rs +++ b/crates/solvers/src/api/mod.rs @@ -20,6 +20,7 @@ impl Api { shutdown: impl Future + Send + 'static, ) -> Result<(), hyper::Error> { let app = axum::Router::new() + .route("/healthz", axum::routing::get(routes::healthz)) .route("/solve", axum::routing::post(routes::solve)) .route("/notify", axum::routing::post(routes::notify)) .layer( diff --git a/crates/solvers/src/api/routes/healthz.rs b/crates/solvers/src/api/routes/healthz.rs new file mode 100644 index 0000000000..7e39e585dc --- /dev/null +++ b/crates/solvers/src/api/routes/healthz.rs @@ -0,0 +1,5 @@ +use axum::{http::StatusCode, response::IntoResponse}; + +pub async fn healthz() -> impl IntoResponse { + StatusCode::OK +} diff --git a/crates/solvers/src/api/routes/mod.rs b/crates/solvers/src/api/routes/mod.rs index 6c051cfc9f..0628449625 100644 --- a/crates/solvers/src/api/routes/mod.rs +++ b/crates/solvers/src/api/routes/mod.rs @@ -1,9 +1,10 @@ use serde::Serialize; +mod healthz; mod notify; mod solve; -pub(super) use {notify::notify, solve::solve}; +pub(super) use {healthz::healthz, notify::notify, solve::solve}; #[derive(Debug, Serialize)] #[serde(untagged)]