Watch
0
0
Fork
You've already forked hyperhive
0

report per agent whether a hive can pull its latest closure from the cache

for each agent the hive looks up its record in agent-closures, fetches the closure's narinfo from the cache with the pull token and checks that a signature by the cache's public key covers it. the result is a log line and the gauge hyperhive.agent.closure_pullable, with a reason label when it is 0. nothing is downloaded and deploys still build locally. part 3 of 3: the probe needs the cache facts and the closure read grant from parts 1 and 2.
This commit is contained in:
atlas 2026-10-27 17:33:57 +01:00 • committed by mara
commit 5486fc0333

View file

@ -6,7 +6,6 @@
//! substituter URL and the public key, where nix and the root helper read them.
use std::path::Path;
use std::time::Duration;
use anyhow::{Context as _, Result, bail};
use swarm_secret_client::attic::{Fact, Leaf, hive_path};
@ -64,6 +63,31 @@ impl Facts {
format!("{}/{}", self.url, self.cache)
}
pub fn public_key(&self) -> &str {
&self.public_key
}
pub fn token(&self) -> &str {
&self.token
}
/// Facts for a test that reaches a server on loopback: no scheme check,
/// so the one place an `http` URL gets past [`Facts::parse`] is a test.
#[cfg(test)]
pub(crate) fn unchecked_for_test(
token: &str,
url: &str,
cache: &str,
public_key: &str,
) -> Self {
Self {
token: token.to_owned(),
url: url.to_owned(),
cache: cache.to_owned(),
public_key: public_key.to_owned(),
}
}
/// The netrc line the server's host authenticates with. The token is the
/// password; the server ignores the login.
fn netrc(&self) -> String {
@ -96,9 +120,6 @@ impl Facts {
}
}
/// How often [`follow`] reads the facts.
pub const READ_INTERVAL: Duration = Duration::from_mins(5);
/// Read the facts and put them in [`crate::paths::ATTIC_DIR`]. The facts, or
/// `None` when the swarm has none for this hive.
///
@ -114,20 +135,6 @@ pub async fn sync() -> Result<Option<Facts>> {
Ok(facts)
}
/// [`sync`] now and every [`READ_INTERVAL`] until shutdown. A failed pass is
/// logged and leaves the files as they are.
pub async fn follow(mut shutdown: tokio::sync::watch::Receiver<bool>) {
loop {
if let Err(e) = sync().await {
tracing::warn!(error = %format!("{e:#}"), "attic: reading the cache facts failed");
}
tokio::select! {
() = tokio::time::sleep(READ_INTERVAL) => {}
_ = shutdown.changed() => return,
}
}
}
/// This hive's facts from the store.
///
/// `Ok(None)` when the swarm has none for it: no cache configured, the