feat: show shared engine health and hourly errors in overview (#1086)

This commit is contained in:
2026-11-17 13:14:53 +01:00
parent f53335d59e
commit a1e267dcd4
4 changed files with 188 additions and 14 deletions

View File

@ -33,6 +33,7 @@ struct FixedEngine {
port: u16,
starts: AtomicUsize,
stops: AtomicUsize,
health_checks: AtomicUsize,
delay: Duration,
fail: bool,
}
@ -75,6 +76,7 @@ impl Engine for FixedEngine {
Ok(())
}
async fn health(&self, _i: &InstanceHandle) -> Health {
self.health_checks.fetch_add(1, Ordering::SeqCst);
Health::Ready
}
fn endpoint(&self, i: &InstanceHandle) -> Endpoint {
@ -238,6 +240,7 @@ async fn gateway_with(
port: backend_port,
starts: AtomicUsize::new(0),
stops: AtomicUsize::new(0),
health_checks: AtomicUsize::new(0),
delay: Duration::from_millis(delay_ms),
fail,
});
@ -2914,3 +2917,47 @@ async fn auswertung_zaehlt_anfragen_und_speichert_nur_einen_erfolgreichen_start(
assert!(body.contains("<td>bonsai</td><td>–</td><td class=\"num\">2</td><td class=\"num\">2</td><td class=\"num\">4</td><td class=\"num\">0</td><td class=\"num\">1</td>"), "{body}");
}
}
#[tokio::test]
async fn ueberwachung_zeigt_health_und_stundenfehler_ohne_inhalte() {
let gw = gateway(0, false).await;
let cookie = ui_cookie(&gw).await;
let (_, _, body) = ui_get(&gw, "/ui", Some(&cookie)).await;
assert!(body.contains("nicht geladen"));
assert!(body.contains("Serverfehler letzte Stunde: 0"));
let _ = gw
.chat(Some(&gw.key), None, &chat_body("bonsai", false))
.await
.text()
.await;
gw.state
.runtime
.metrics
.record_request("bonsai", 503, 1, None, None, false);
gw.state.runtime.metrics.record_start_failure("bonsai");
tokio::time::sleep(Duration::from_millis(5100)).await;
let (_, _, body) = ui_get(&gw, "/ui/teil/uebersicht", Some(&cookie)).await;
assert!(body.contains("erreichbar (1/1)"));
assert!(body.contains("Serverfehler letzte Stunde: 1"));
assert!(body.contains("Fehlstarts letzte Stunde: 1"));
assert!(body.contains("title=\"Anfragen, deren Antwort"));
assert!(!body.contains("/m/bonsai"));
}
#[tokio::test]
async fn parallele_statusabfragen_teilen_health_messung() {
let gw = gateway(0, false).await;
let _ = gw
.chat(Some(&gw.key), None, &chat_body("bonsai", false))
.await
.text()
.await;
let before = gw.engine.health_checks.load(Ordering::SeqCst);
let (a, b) = tokio::join!(
gw.state.runtime.engine_status(),
gw.state.runtime.engine_status()
);
assert_eq!(a[0].reachable, 1);
assert_eq!(b[0].reachable, 1);
assert_eq!(gw.engine.health_checks.load(Ordering::SeqCst), before + 1);
}