aboutsummaryrefslogtreecommitdiff
path: root/src/api/admin/cluster.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-12-05 15:38:32 +0100
committerAlex Auvolat <alex@adnab.me>2022-12-05 15:38:32 +0100
commitd7868c48a4d8d5831051a0be088fe7bbec259bca (patch)
tree27e5b5d5050a73e159f716884f69c2fec5a8fbb6 /src/api/admin/cluster.rs
parent280d1be7b1fde13d23e47f75aa8acd2f90efb81f (diff)
downloadgarage-d7868c48a4d8d5831051a0be088fe7bbec259bca.tar.gz
garage-d7868c48a4d8d5831051a0be088fe7bbec259bca.zip
Separate /health (simple text answer) and /v0/health (full json answer, authenticated)
Diffstat (limited to 'src/api/admin/cluster.rs')
-rw-r--r--src/api/admin/cluster.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/api/admin/cluster.rs b/src/api/admin/cluster.rs
index 706db727..a773e27a 100644
--- a/src/api/admin/cluster.rs
+++ b/src/api/admin/cluster.rs
@@ -9,6 +9,7 @@ use garage_util::crdt::*;
use garage_util::data::*;
use garage_rpc::layout::*;
+use garage_rpc::system::ClusterHealthStatus;
use garage_model::garage::Garage;
@@ -43,6 +44,22 @@ pub async fn handle_get_cluster_status(garage: &Arc<Garage>) -> Result<Response<
Ok(json_ok_response(&res)?)
}
+pub async fn handle_get_cluster_health(garage: &Arc<Garage>) -> Result<Response<Body>, Error> {
+ let health = garage.system.health();
+
+ let status = match health.status {
+ ClusterHealthStatus::Unavailable => StatusCode::SERVICE_UNAVAILABLE,
+ _ => StatusCode::OK,
+ };
+
+ let resp_json =
+ serde_json::to_string_pretty(&health).map_err(garage_util::error::Error::from)?;
+ Ok(Response::builder()
+ .status(status)
+ .header(http::header::CONTENT_TYPE, "application/json")
+ .body(Body::from(resp_json))?)
+}
+
pub async fn handle_connect_cluster_nodes(
garage: &Arc<Garage>,
req: Request<Body>,