From 35c108b85d2b70ad28cd93bfd412607a89b9acf9 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 14 Jun 2023 13:53:19 +0200 Subject: admin api: switch GetClusterHealth to camelcase (fix #381 again) --- src/api/admin/cluster.rs | 28 ++++++++++++++++++++++++++++ src/api/admin/router.rs | 2 +- src/rpc/system.rs | 4 ++-- 3 files changed, 31 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/api/admin/cluster.rs b/src/api/admin/cluster.rs index 8a208a2c..90203043 100644 --- a/src/api/admin/cluster.rs +++ b/src/api/admin/cluster.rs @@ -40,7 +40,22 @@ pub async fn handle_get_cluster_status(garage: &Arc) -> Result) -> Result, Error> { + use garage_rpc::system::ClusterHealthStatus; let health = garage.system.health(); + let health = ClusterHealth { + status: match health.status { + ClusterHealthStatus::Healthy => "healthy", + ClusterHealthStatus::Degraded => "degraded", + ClusterHealthStatus::Unavailable => "unavailable", + }, + known_nodes: health.known_nodes, + connected_nodes: health.connected_nodes, + storage_nodes: health.storage_nodes, + storage_nodes_ok: health.storage_nodes_ok, + partitions: health.partitions, + partitions_quorum: health.partitions_quorum, + partitions_all_ok: health.partitions_all_ok, + }; Ok(json_ok_response(&health)?) } @@ -120,6 +135,19 @@ fn get_cluster_layout(garage: &Arc) -> GetClusterLayoutResponse { // ---- +#[derive(Debug, Clone, Copy, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct ClusterHealth { + pub status: &'static str, + pub known_nodes: usize, + pub connected_nodes: usize, + pub storage_nodes: usize, + pub storage_nodes_ok: usize, + pub partitions: usize, + pub partitions_quorum: usize, + pub partitions_all_ok: usize, +} + #[derive(Serialize)] #[serde(rename_all = "camelCase")] struct GetClusterStatusResponse { diff --git a/src/api/admin/router.rs b/src/api/admin/router.rs index 5af3ffb5..b98db284 100644 --- a/src/api/admin/router.rs +++ b/src/api/admin/router.rs @@ -96,7 +96,7 @@ impl Endpoint { GET "/health" => Health, GET "/metrics" => Metrics, GET "/v1/status" => GetClusterStatus, - GET "/v0/health" => GetClusterHealth, + GET "/v1/health" => GetClusterHealth, POST "/v0/connect" => ConnectClusterNodes, // Layout endpoints GET "/v1/layout" => GetClusterLayout, diff --git a/src/rpc/system.rs b/src/rpc/system.rs index c549d8fc..1675e70e 100644 --- a/src/rpc/system.rs +++ b/src/rpc/system.rs @@ -151,7 +151,7 @@ pub struct KnownNodeInfo { pub status: NodeStatus, } -#[derive(Debug, Clone, Copy, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy)] pub struct ClusterHealth { /// The current health status of the cluster (see below) pub status: ClusterHealthStatus, @@ -171,7 +171,7 @@ pub struct ClusterHealth { pub partitions_all_ok: usize, } -#[derive(Debug, Clone, Copy, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy)] pub enum ClusterHealthStatus { /// All nodes are available Healthy, -- cgit v1.2.3