From 6557831f8cfa15661bb2d985ed1661a78251b9b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 10 Sep 2026 15:43:49 +0300 Subject: [PATCH] the family flyout carries the same health dots the admin table does. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each sibling mark probes /healthz concurrently; green while it answers ok, muted otherwise. The probe lives in one module. No new landing tab, no copy, no JS — hover/focus still opens the flyout. --- crates/im-web/assets/main.css | 2 +- crates/im-web/src/admin.rs | 105 +++++++++++++++++++++++----------- crates/im-web/src/health.rs | 39 +++++++++++++ crates/im-web/src/layout.rs | 40 +++++++++---- crates/im-web/src/main.rs | 1 + style/main.scss | 2 +- 6 files changed, 143 insertions(+), 46 deletions(-) create mode 100644 crates/im-web/src/health.rs diff --git a/crates/im-web/assets/main.css b/crates/im-web/assets/main.css index b2a0c81..da0ba15 100644 --- a/crates/im-web/assets/main.css +++ b/crates/im-web/assets/main.css @@ -340,7 +340,7 @@ body:has(.auth-stage) > .auth-stage::-webkit-scrollbar { left: 50%; z-index: 2; display: flex; - align-items: baseline; + align-items: center; gap: 10px; padding: 6px 12px; background: var(--surface); diff --git a/crates/im-web/src/admin.rs b/crates/im-web/src/admin.rs index 525ba30..038a57e 100644 --- a/crates/im-web/src/admin.rs +++ b/crates/im-web/src/admin.rs @@ -15,6 +15,7 @@ use topcoat::router::response::{IntoResponse, Response}; use topcoat::router::{HeaderValue, StatusCode, header, route}; use topcoat::view::{Child, ViewExt, view}; +use crate::health::{Probe, probe_healthz}; use crate::i18n::{self, Key, lang_of, t}; use crate::layout::shell; use crate::mailer; @@ -1489,39 +1490,6 @@ async fn health_section(cx: &Cx, lang: i18n::Lang) -> Result` — and the answer's latency; everything else, refused -/// or wrong status or a body that does not begin ok or the two-second -/// ceiling, is `Down`. -enum Probe { - Up { body: String, ms: u128 }, - Down, -} - -async fn probe_healthz(http: &reqwest::Client, url: &str) -> Probe { - let started = std::time::Instant::now(); - let Ok(answer) = http - .get(url) - .timeout(std::time::Duration::from_secs(2)) - .send() - .await - else { - return Probe::Down; - }; - if !answer.status().is_success() { - return Probe::Down; - } - let body = answer.text().await.unwrap_or_default(); - let body = body.trim(); - if body.starts_with("ok") { - Probe::Up { - body: body.chars().take(64).collect(), - ms: started.elapsed().as_millis(), - } - } else { - Probe::Down - } -} /// Fits the log's page size to the browser's own viewport: measured against /// the first rendered row, never against a guess at the row height. A fit /// that would change the page size reloads once through a fresh @@ -2622,7 +2590,7 @@ mod tests { let http = reqwest::Client::new(); // A stand-in service answering the deploy body. - use super::{Probe, probe_healthz}; + use crate::health::{Probe, probe_healthz}; let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap(); let addr = listener.local_addr().unwrap(); @@ -2689,4 +2657,73 @@ mod tests { assert!(body.contains("Unreachable"), "the dark row reads Down: {body}"); } } + + /// The signed-in flyout marks each sibling with the same health the + /// admin table reads: a sibling answering `ok` renders `health-on`, + /// a dark port `health-off`, dots only — no body, no latency — and + /// im's own row stays out of the flyout. + #[tokio::test] + async fn family_flyout_marks_siblings_with_health_dots() { + use tokio::io::{AsyncReadExt as _, AsyncWriteExt as _}; + + let setup = setup().await; + + // A live sibling answering the deploy body, and a dark one. + let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap(); + let live_url = format!("http://{}", listener.local_addr().unwrap()); + let talker = tokio::spawn(async move { + let (mut sock, _) = listener.accept().await.unwrap(); + let mut buf = [0u8; 1024]; + let _ = sock.read(&mut buf).await; + sock.write_all(b"HTTP/1.1 200 OK\r\ncontent-length: 6\r\n\r\nok dev") + .await + .unwrap(); + }); + let dark = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap(); + let dark_url = format!("http://{}", dark.local_addr().unwrap()); + drop(dark); + // `im` gets a row too — one the flyout must leave out. + for (key, url) in [("iz", live_url), ("in", dark_url.clone()), ("im", dark_url)] { + im_core::services::add( + &setup.store, + &im_core::services::Service { + key: key.into(), + name: "Fixture".into(), + url, + owner: None, + client_id: None, + storage_limit_bytes: None, + }, + ) + .await + .unwrap(); + } + + let (_, _, body) = get_full(&setup.router, "/", Some(&setup.plain_cookie)).await; + talker.await.unwrap(); + assert!(body.contains("service-trio"), "{body}"); + assert!( + body.contains(r#"iz"), "the live sibling renders: {body}"); + assert!(body.contains("health-dot health-off"), "the dark sibling reads off: {body}"); + assert!(body.contains(">in"), "the dark sibling renders: {body}"); + assert!(!body.contains(">im"), "im's own row stays out: {body}"); + assert!(!body.contains("ok dev"), "the flyout carries dots only: {body}"); + assert!(!body.contains(" ms"), "the flyout carries no latency: {body}"); + } + + /// A family with no siblings is the bare mark: no flyout in the DOM + /// at all, so there is nothing to reveal and nothing to probe. + #[tokio::test] + async fn family_flyout_without_siblings_is_the_bare_mark() { + let setup = setup().await; + let (_, _, body) = get_full(&setup.router, "/", Some(&setup.plain_cookie)).await; + assert!(!body.contains("service-trio"), "{body}"); + assert!(!body.contains("wordmark-family"), "{body}"); + assert!(!body.contains("health-dot"), "{body}"); + assert!(body.contains("wordmark-text"), "the bare mark stays: {body}"); + } } diff --git a/crates/im-web/src/health.rs b/crates/im-web/src/health.rs new file mode 100644 index 0000000..41885e1 --- /dev/null +++ b/crates/im-web/src/health.rs @@ -0,0 +1,39 @@ +//! The one family-health probe, shared by the admin panel's health table +//! and the signed-in wordmark's flyout: a service is asked +//! `GET {url}/healthz` where it stands — no credentials, two seconds to +//! answer — and the callers fan the probes out concurrently, so a family +//! member that is down costs its two seconds, not two seconds each. + +/// One `/healthz` reading. `Up` carries the body — the deploy contract's +/// `ok ` — and the answer's latency; everything else, refused +/// or wrong status or a body that does not begin ok or the two-second +/// ceiling, is `Down`. +pub(crate) enum Probe { + Up { body: String, ms: u128 }, + Down, +} + +pub(crate) async fn probe_healthz(http: &reqwest::Client, url: &str) -> Probe { + let started = std::time::Instant::now(); + let Ok(answer) = http + .get(url) + .timeout(std::time::Duration::from_secs(2)) + .send() + .await + else { + return Probe::Down; + }; + if !answer.status().is_success() { + return Probe::Down; + } + let body = answer.text().await.unwrap_or_default(); + let body = body.trim(); + if body.starts_with("ok") { + Probe::Up { + body: body.chars().take(64).collect(), + ms: started.elapsed().as_millis(), + } + } else { + Probe::Down + } +} diff --git a/crates/im-web/src/layout.rs b/crates/im-web/src/layout.rs index 0343100..b28ceea 100644 --- a/crates/im-web/src/layout.rs +++ b/crates/im-web/src/layout.rs @@ -7,6 +7,7 @@ use topcoat::asset::{Asset, asset}; use topcoat::context::Cx; use topcoat::view::{BoxView, Child, View, ViewExt, view}; +use crate::health::{Probe, probe_healthz}; use crate::i18n::{Key, Lang, lang_of, t}; use crate::server; @@ -27,25 +28,44 @@ pub async fn wordmark(cx: &Cx) -> Result { /// The signed-in chrome's wordmark with the family behind it: the `im` /// mark as above, and the sibling services' wordmarks in a flyout that /// opens under it on hover and on keyboard focus (the mark is focusable -/// for that), middots between, each a plain link. No script: the flyout -/// is CSS on `:hover` / `:focus-within`. A family with no siblings renders -/// the bare mark — nothing to reveal. The list is the stored one, the same -/// rows `/family` serves, minus im's own row. +/// for that), middots between, each a plain link carrying a health dot — +/// the same `/healthz` reading the admin panel's table takes its rows +/// from, green while the sibling answers `ok`, muted while it does not. +/// No script: the flyout is CSS on `:hover` / `:focus-within`. A family +/// with no siblings renders the bare mark — nothing to reveal, nothing +/// to probe. The list is the stored one, the same rows `/family` serves, +/// minus im's own row. pub async fn family_wordmark(cx: &Cx) -> Result> { let services = im_core::services::list(&server::app(cx).store).await?; let siblings = services .iter() .filter(|service| service.key != "im") - .map(|service| { - let key = crate::pages::escape(&service.key); - let url = crate::pages::escape(&service.url); - format!(r#"{key}"#) - }) .collect::>(); if siblings.is_empty() { return wordmark(cx).await.map(ViewExt::boxed); } - let marks = siblings.join(r#"·"#); + // Every probe at once: a family member that is down costs its two + // seconds, not two seconds each. + let http = reqwest::Client::new(); + let mut probes = Vec::new(); + for service in &siblings { + let http = http.clone(); + let url = format!("{}/healthz", service.url.trim_end_matches('/')); + probes.push(tokio::spawn(async move { probe_healthz(&http, &url).await })); + } + let mut marks = Vec::new(); + for (service, probe) in siblings.iter().zip(probes) { + let key = crate::pages::escape(&service.key); + let url = crate::pages::escape(&service.url); + let dot = match probe.await.unwrap_or(Probe::Down) { + Probe::Up { .. } => "health-on", + Probe::Down => "health-off", + }; + marks.push(format!( + r#"{key}"# + )); + } + let marks = marks.join(r#"·"#); Ok(view! { cx =>
diff --git a/crates/im-web/src/main.rs b/crates/im-web/src/main.rs index 84d4989..45c1fc6 100644 --- a/crates/im-web/src/main.rs +++ b/crates/im-web/src/main.rs @@ -15,6 +15,7 @@ mod auth; mod config; mod directory; mod dropdown; +mod health; mod i18n; mod layout; mod live; diff --git a/style/main.scss b/style/main.scss index 46483be..f08af5a 100644 --- a/style/main.scss +++ b/style/main.scss @@ -307,7 +307,7 @@ body:has(.auth-stage) { left: 50%; z-index: 2; display: flex; - align-items: baseline; + align-items: center; gap: 10px; padding: 6px 12px; background: var(--surface);