Skip to content

Commit

Permalink
Healthz endpoints for Driver and Solvers (#2060)
Browse files Browse the repository at this point in the history
# 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
cowprotocol/infrastructure#858 deployment

## Related Issues

Fixes #1382
  • Loading branch information
squadgazzz authored Nov 17, 2023
1 parent b5a258a commit e3b558b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion crates/driver/src/infra/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions crates/driver/src/infra/api/routes/healthz.rs
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions crates/driver/src/infra/api/routes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod healthz;
mod info;
mod metrics;
mod quote;
Expand All @@ -6,6 +7,7 @@ mod settle;
mod solve;

pub(super) use {
healthz::healthz,
info::info,
metrics::metrics,
quote::{quote, OrderError},
Expand Down
1 change: 1 addition & 0 deletions crates/solvers/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ impl Api {
shutdown: impl Future<Output = ()> + 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(
Expand Down
5 changes: 5 additions & 0 deletions crates/solvers/src/api/routes/healthz.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use axum::{http::StatusCode, response::IntoResponse};

pub async fn healthz() -> impl IntoResponse {
StatusCode::OK
}
3 changes: 2 additions & 1 deletion crates/solvers/src/api/routes/mod.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down

0 comments on commit e3b558b

Please sign in to comment.