admin api: return full layout computation statistics as json (fix #1428)

This commit is contained in:
Alex Auvolat
2026-05-01 19:30:27 +02:00
committed by Alex
parent ada0c8ab70
commit 62349a6559
10 changed files with 284 additions and 129 deletions
+8
View File
@@ -618,6 +618,10 @@ pub enum PreviewClusterLayoutChangesResponse {
/// Plain-text information about the layout computation
/// (do not try to parse this)
message: Vec<String>,
/// Structured statistics about the layout computation
// FIXME for v3: remove default and skip_serializing_if
#[serde(default, skip_serializing_if = "Option::is_none")]
statistics: Option<Box<garage_rpc::layout::ComputationStat>>,
/// Details about the new cluster layout
new_layout: GetClusterLayoutResponse,
},
@@ -639,6 +643,10 @@ pub struct ApplyClusterLayoutResponse {
/// Plain-text information about the layout computation
/// (do not try to parse this)
pub message: Vec<String>,
/// Structured statistics about the layout computation
// FIXME for v3: remove default and skip_serializing_if
#[serde(default, skip_serializing_if = "Option::is_none")]
pub statistics: Option<garage_rpc::layout::ComputationStat>,
/// Details about the new cluster layout
pub layout: GetClusterLayoutResponse,
}
+12 -6
View File
@@ -255,10 +255,14 @@ impl RequestHandler for PreviewClusterLayoutChangesRequest {
Ok(PreviewClusterLayoutChangesResponse::Error { error })
}
Err(e) => Err(e.into()),
Ok((new_layout, msg)) => Ok(PreviewClusterLayoutChangesResponse::Success {
message: msg,
new_layout: format_cluster_layout(&new_layout),
}),
Ok((new_layout, stat)) => {
let message = stat.to_message();
Ok(PreviewClusterLayoutChangesResponse::Success {
message,
statistics: Some(Box::new(stat)),
new_layout: format_cluster_layout(&new_layout),
})
}
}
}
}
@@ -272,7 +276,8 @@ impl RequestHandler for ApplyClusterLayoutRequest {
_admin: &Admin,
) -> Result<ApplyClusterLayoutResponse, Error> {
let layout = garage.system.cluster_layout().inner().clone();
let (layout, msg) = layout.apply_staged_changes(self.version)?;
let (layout, stat) = layout.apply_staged_changes(self.version)?;
let message = stat.to_message();
garage
.system
@@ -281,7 +286,8 @@ impl RequestHandler for ApplyClusterLayoutRequest {
.await?;
Ok(ApplyClusterLayoutResponse {
message: msg,
message,
statistics: Some(stat),
layout: format_cluster_layout(&layout),
})
}