Watch
0
0
Fork
You've already forked hyperhive
0

logs and metrics permissions, tolerant record decode, hive capabilities

This commit is contained in:
atlas 2026-11-01 17:40:09 +01:00
commit 04598542b6

View file

@ -396,15 +396,29 @@ pub(crate) fn queue_first_deploy(
coord.job_queue.insert_first_deploy_once(agent)
}
/// Offer one snapshot: this hive's current readiness, under its own key.
/// The snapshot a hive offers: its readiness, and what it can do (`swarm_wire::hive_status`).
#[derive(serde::Serialize)]
struct Snapshot {
#[serde(flatten)]
readiness: crate::warnings::Readiness,
capabilities: &'static [&'static str],
}
fn snapshot() -> Snapshot {
Snapshot {
readiness: crate::warnings::readiness(),
capabilities: &[swarm_wire::hive_status::TOLERANT_PERMISSIONS],
}
}
/// Offer one snapshot under this hive's own key.
async fn publish(client: &async_nats::Client, hive: &str) -> Result<()> {
// An unconnected client does not fail a JetStream request, it hangs
// on it — which here would hang the loop, shutdown arm included.
swarm_queue_client::ensure_connected(client)?;
let store = swarm_queue_client::status::open_or_create(client).await?;
let payload =
serde_json::to_vec(&crate::warnings::readiness()).context("serialising the readiness")?;
let payload = serde_json::to_vec(&snapshot()).context("serialising the snapshot")?;
store
.put(hive, payload.into())
.await
@ -427,3 +441,20 @@ mod rev_marker_tests {
assert!(!marker_holds(&marker, "bbb"), "another rev still deploys");
}
}
#[cfg(test)]
mod snapshot_tests {
use super::snapshot;
/// The controller reads the capability out of the published bytes with
/// the wire type, and the readiness keeps its own top-level fields.
#[test]
fn the_snapshot_advertises_tolerant_permissions_beside_the_readiness() {
let value = serde_json::to_value(snapshot()).unwrap();
assert!(
swarm_wire::hive_status::Capabilities::of_snapshot(&value)
.has(swarm_wire::hive_status::TOLERANT_PERMISSIONS)
);
assert!(value.get("status").is_some() && value.get("warnings").is_some());
}
}