From 2b3f2bfa1c924fba0ea894bb079196a6684c8c91 Mon Sep 17 00:00:00 2001 From: jedarden Date: Mon, 25 May 2026 04:40:50 -0400 Subject: [PATCH] fix(topology): populate shard_count, last_seen_ms, and error fields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Compute shard_count per node using rendezvous hash assignment - Compute last_seen_ms from node.last_seen (milliseconds since last health check) - Populate error field from node.last_error This completes the plan ยง10 topology endpoint JSON shape requirements. Closes: bf-3jy5 --- .../src/routes/admin_endpoints.rs | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/crates/miroir-proxy/src/routes/admin_endpoints.rs b/crates/miroir-proxy/src/routes/admin_endpoints.rs index 285f63c..d4ec7ed 100644 --- a/crates/miroir-proxy/src/routes/admin_endpoints.rs +++ b/crates/miroir-proxy/src/routes/admin_endpoints.rs @@ -1053,15 +1053,38 @@ where }; // Build node info list + // First compute shard counts per node using rendezvous assignment + use std::collections::HashMap; + let mut shard_counts: HashMap = HashMap::new(); + + for shard_id in 0..topo.shards { + for group in topo.groups() { + let assigned = router::assign_shard_in_group(shard_id, group.nodes(), topo.rf()); + for node_id in assigned { + *shard_counts + .entry(node_id.as_str().to_string()) + .or_insert(0) += 1; + } + } + } + let nodes: Vec = topo .nodes() - .map(|n| NodeInfo { - id: n.id.as_str().to_string(), - address: n.address.clone(), - status: format!("{:?}", n.status).to_lowercase(), - shard_count: 0, // TODO: compute from routing table - last_seen_ms: 0, // TODO: track last health check time - error: None, // TODO: populate from last health check error + .map(|n| { + // Compute last_seen_ms from node.last_seen + let last_seen_ms = n + .last_seen + .map(|i| i.elapsed().as_millis() as u64) + .unwrap_or(0); + + NodeInfo { + id: n.id.as_str().to_string(), + address: n.address.clone(), + status: format!("{:?}", n.status).to_lowercase(), + shard_count: shard_counts.get(n.id.as_str()).copied().unwrap_or(0), + last_seen_ms, + error: n.last_error.clone(), + } }) .collect();