huskies: merge 1154 story Extend gateway_health with a relay-working signal — is each sled actually delivering events?
This commit is contained in:
@@ -73,6 +73,16 @@ impl HealthLine {
|
||||
}
|
||||
}
|
||||
|
||||
/// Append `relay=X` information to this line's detail field.
|
||||
fn with_relay(mut self, relay: &str) -> Self {
|
||||
let relay_text = format!("relay={relay}");
|
||||
self.detail = Some(match self.detail {
|
||||
Some(d) => format!("{d} | {relay_text}"),
|
||||
None => relay_text,
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
/// Format as a single Markdown-friendly line.
|
||||
fn format(&self) -> String {
|
||||
let status = match self.status {
|
||||
@@ -216,7 +226,8 @@ async fn check_build_hash(project_root: &std::path::Path) -> HealthLine {
|
||||
/// Check each registered sled's `/health` endpoint with a 5-second timeout.
|
||||
///
|
||||
/// Returns one [`HealthLine`] per sled. PASS when the sled responds with HTTP
|
||||
/// 2xx; FAIL when the request times out or returns an error status.
|
||||
/// 2xx; FAIL when the request times out or returns an error status. Each line
|
||||
/// includes a `relay=X` indicator derived from the gateway CRDT event log.
|
||||
async fn check_sleds(
|
||||
store: &tokio::sync::RwLock<BTreeMap<String, crate::service::gateway::config::ProjectEntry>>,
|
||||
) -> Vec<HealthLine> {
|
||||
@@ -235,31 +246,53 @@ async fn check_sleds(
|
||||
)];
|
||||
}
|
||||
|
||||
let event_entries = crate::crdt_state::read_all_event_log_entries();
|
||||
let now_secs = chrono::Utc::now().timestamp() as f64;
|
||||
let client = reqwest::Client::new();
|
||||
let mut lines = Vec::new();
|
||||
|
||||
for (name, url_opt) in entries {
|
||||
let subsystem = format!("sled:{name}");
|
||||
let relay = {
|
||||
let latest = event_entries
|
||||
.iter()
|
||||
.filter(|e| e.sled_id == name)
|
||||
.map(|e| e.timestamp)
|
||||
.fold(f64::NEG_INFINITY, f64::max);
|
||||
if latest == f64::NEG_INFINITY {
|
||||
"never"
|
||||
} else if now_secs - latest <= crate::service::gateway::RELAY_MAX_AGE_SECS {
|
||||
"ok"
|
||||
} else {
|
||||
"silent"
|
||||
}
|
||||
};
|
||||
let line = match url_opt {
|
||||
None => HealthLine::warn(subsystem, "no URL configured", "set url in projects.toml"),
|
||||
None => HealthLine::warn(subsystem, "no URL configured", "set url in projects.toml")
|
||||
.with_relay(relay),
|
||||
Some(url) => {
|
||||
let health_url = format!("{}/health", url.trim_end_matches('/'));
|
||||
let result = timeout(Duration::from_secs(5), client.get(&health_url).send()).await;
|
||||
match result {
|
||||
Err(_) => {
|
||||
HealthLine::fail(subsystem, "timed out", "check container is running")
|
||||
.with_relay(relay)
|
||||
}
|
||||
Ok(Err(e)) => HealthLine::fail(
|
||||
subsystem,
|
||||
format!("unreachable: {}", short_error(&e.to_string())),
|
||||
"check container is running",
|
||||
),
|
||||
Ok(Ok(resp)) if resp.status().is_success() => HealthLine::pass(subsystem),
|
||||
)
|
||||
.with_relay(relay),
|
||||
Ok(Ok(resp)) if resp.status().is_success() => {
|
||||
HealthLine::pass(subsystem).with_relay(relay)
|
||||
}
|
||||
Ok(Ok(resp)) => HealthLine::fail(
|
||||
subsystem,
|
||||
format!("HTTP {}", resp.status().as_u16()),
|
||||
"check container logs",
|
||||
),
|
||||
)
|
||||
.with_relay(relay),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user