forge
Explore
Log in

Don't you dare go Hollow

the family flyout carries the same health dots the admin table does.

Browse files at this commit

6557831f8cfa15661bb2d985ed1661a78251b9b2Ahmet Kaan GümüşParent: 30917a3
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.cssmodified+1 -1
@@ -340,7 +340,7 @@ body:has(.auth-stage) > .auth-stage::-webkit-scrollbar {
340 left: 50%;340 left: 50%;
341 z-index: 2;341 z-index: 2;
342 display: flex;342 display: flex;
343- align-items: baseline;343+ align-items: center;
344 gap: 10px;344 gap: 10px;
345 padding: 6px 12px;345 padding: 6px 12px;
346 background: var(--surface);346 background: var(--surface);
crates/im-web/src/admin.rsmodified+71 -34
@@ -15,6 +15,7 @@ use topcoat::router::response::{IntoResponse, Response};
15 use topcoat::router::{HeaderValue, StatusCode, header, route};15 use topcoat::router::{HeaderValue, StatusCode, header, route};
16 use topcoat::view::{Child, ViewExt, view};16 use topcoat::view::{Child, ViewExt, view};
17 17
18+use crate::health::{Probe, probe_healthz};
18 use crate::i18n::{self, Key, lang_of, t};19 use crate::i18n::{self, Key, lang_of, t};
19 use crate::layout::shell;20 use crate::layout::shell;
20 use crate::mailer;21 use crate::mailer;
@@ -1489,39 +1490,6 @@ async fn health_section(cx: &Cx, lang: i18n::Lang) -> Result<String, topcoat::Er
1489 ))1490 ))
1490 }1491 }
1491 1492
1492-/// One `/healthz` reading. `Up` carries the body — the deploy contract's
1493-/// `ok <build sha>` — and the answer's latency; everything else, refused
1494-/// or wrong status or a body that does not begin ok or the two-second
1495-/// ceiling, is `Down`.
1496-enum Probe {
1497- Up { body: String, ms: u128 },
1498- Down,
1499-}
1500-
1501-async fn probe_healthz(http: &reqwest::Client, url: &str) -> Probe {
1502- let started = std::time::Instant::now();
1503- let Ok(answer) = http
1504- .get(url)
1505- .timeout(std::time::Duration::from_secs(2))
1506- .send()
1507- .await
1508- else {
1509- return Probe::Down;
1510- };
1511- if !answer.status().is_success() {
1512- return Probe::Down;
1513- }
1514- let body = answer.text().await.unwrap_or_default();
1515- let body = body.trim();
1516- if body.starts_with("ok") {
1517- Probe::Up {
1518- body: body.chars().take(64).collect(),
1519- ms: started.elapsed().as_millis(),
1520- }
1521- } else {
1522- Probe::Down
1523- }
1524-}
1525 /// Fits the log's page size to the browser's own viewport: measured against1493 /// Fits the log's page size to the browser's own viewport: measured against
1526 /// the first rendered row, never against a guess at the row height. A fit1494 /// the first rendered row, never against a guess at the row height. A fit
1527 /// that would change the page size reloads once through a fresh1495 /// that would change the page size reloads once through a fresh
@@ -2622,7 +2590,7 @@ mod tests {
2622 let http = reqwest::Client::new();2590 let http = reqwest::Client::new();
2623 2591
2624 // A stand-in service answering the deploy body.2592 // A stand-in service answering the deploy body.
2625- use super::{Probe, probe_healthz};2593+ use crate::health::{Probe, probe_healthz};
2626 let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();2594 let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
2627 2595
2628 let addr = listener.local_addr().unwrap();2596 let addr = listener.local_addr().unwrap();
@@ -2689,4 +2657,73 @@ mod tests {
2689 assert!(body.contains("Unreachable"), "the dark row reads Down: {body}");2657 assert!(body.contains("Unreachable"), "the dark row reads Down: {body}");
2690 }2658 }
2691 }2659 }
2660+
2661+ /// The signed-in flyout marks each sibling with the same health the
2662+ /// admin table reads: a sibling answering `ok` renders `health-on`,
2663+ /// a dark port `health-off`, dots only — no body, no latency — and
2664+ /// im's own row stays out of the flyout.
2665+ #[tokio::test]
2666+ async fn family_flyout_marks_siblings_with_health_dots() {
2667+ use tokio::io::{AsyncReadExt as _, AsyncWriteExt as _};
2668+
2669+ let setup = setup().await;
2670+
2671+ // A live sibling answering the deploy body, and a dark one.
2672+ let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
2673+ let live_url = format!("http://{}", listener.local_addr().unwrap());
2674+ let talker = tokio::spawn(async move {
2675+ let (mut sock, _) = listener.accept().await.unwrap();
2676+ let mut buf = [0u8; 1024];
2677+ let _ = sock.read(&mut buf).await;
2678+ sock.write_all(b"HTTP/1.1 200 OK\r\ncontent-length: 6\r\n\r\nok dev")
2679+ .await
2680+ .unwrap();
2681+ });
2682+ let dark = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
2683+ let dark_url = format!("http://{}", dark.local_addr().unwrap());
2684+ drop(dark);
2685+ // `im` gets a row too — one the flyout must leave out.
2686+ for (key, url) in [("iz", live_url), ("in", dark_url.clone()), ("im", dark_url)] {
2687+ im_core::services::add(
2688+ &setup.store,
2689+ &im_core::services::Service {
2690+ key: key.into(),
2691+ name: "Fixture".into(),
2692+ url,
2693+ owner: None,
2694+ client_id: None,
2695+ storage_limit_bytes: None,
2696+ },
2697+ )
2698+ .await
2699+ .unwrap();
2700+ }
2701+
2702+ let (_, _, body) = get_full(&setup.router, "/", Some(&setup.plain_cookie)).await;
2703+ talker.await.unwrap();
2704+ assert!(body.contains("service-trio"), "{body}");
2705+ assert!(
2706+ body.contains(r#"<a class="trio-mark" href="http://127.0.0.1:"#),
2707+ "the marks stay links: {body}"
2708+ );
2709+ assert!(body.contains("health-dot health-on"), "the ok sibling reads on: {body}");
2710+ assert!(body.contains(">iz</a>"), "the live sibling renders: {body}");
2711+ assert!(body.contains("health-dot health-off"), "the dark sibling reads off: {body}");
2712+ assert!(body.contains(">in</a>"), "the dark sibling renders: {body}");
2713+ assert!(!body.contains(">im</a>"), "im's own row stays out: {body}");
2714+ assert!(!body.contains("ok dev"), "the flyout carries dots only: {body}");
2715+ assert!(!body.contains(" ms</span>"), "the flyout carries no latency: {body}");
2716+ }
2717+
2718+ /// A family with no siblings is the bare mark: no flyout in the DOM
2719+ /// at all, so there is nothing to reveal and nothing to probe.
2720+ #[tokio::test]
2721+ async fn family_flyout_without_siblings_is_the_bare_mark() {
2722+ let setup = setup().await;
2723+ let (_, _, body) = get_full(&setup.router, "/", Some(&setup.plain_cookie)).await;
2724+ assert!(!body.contains("service-trio"), "{body}");
2725+ assert!(!body.contains("wordmark-family"), "{body}");
2726+ assert!(!body.contains("health-dot"), "{body}");
2727+ assert!(body.contains("wordmark-text"), "the bare mark stays: {body}");
2728+ }
2692 }2729 }
crates/im-web/src/health.rsadded+39 -0
@@ -0,0 +1,39 @@
1+//! The one family-health probe, shared by the admin panel's health table
2+//! and the signed-in wordmark's flyout: a service is asked
3+//! `GET {url}/healthz` where it stands — no credentials, two seconds to
4+//! answer — and the callers fan the probes out concurrently, so a family
5+//! member that is down costs its two seconds, not two seconds each.
6+
7+/// One `/healthz` reading. `Up` carries the body — the deploy contract's
8+/// `ok <build sha>` — and the answer's latency; everything else, refused
9+/// or wrong status or a body that does not begin ok or the two-second
10+/// ceiling, is `Down`.
11+pub(crate) enum Probe {
12+ Up { body: String, ms: u128 },
13+ Down,
14+}
15+
16+pub(crate) async fn probe_healthz(http: &reqwest::Client, url: &str) -> Probe {
17+ let started = std::time::Instant::now();
18+ let Ok(answer) = http
19+ .get(url)
20+ .timeout(std::time::Duration::from_secs(2))
21+ .send()
22+ .await
23+ else {
24+ return Probe::Down;
25+ };
26+ if !answer.status().is_success() {
27+ return Probe::Down;
28+ }
29+ let body = answer.text().await.unwrap_or_default();
30+ let body = body.trim();
31+ if body.starts_with("ok") {
32+ Probe::Up {
33+ body: body.chars().take(64).collect(),
34+ ms: started.elapsed().as_millis(),
35+ }
36+ } else {
37+ Probe::Down
38+ }
39+}
crates/im-web/src/layout.rsmodified+30 -10
@@ -7,6 +7,7 @@ use topcoat::asset::{Asset, asset};
7 use topcoat::context::Cx;7 use topcoat::context::Cx;
8 use topcoat::view::{BoxView, Child, View, ViewExt, view};8 use topcoat::view::{BoxView, Child, View, ViewExt, view};
9 9
10+use crate::health::{Probe, probe_healthz};
10 use crate::i18n::{Key, Lang, lang_of, t};11 use crate::i18n::{Key, Lang, lang_of, t};
11 use crate::server;12 use crate::server;
12 13
@@ -27,25 +28,44 @@ pub async fn wordmark(cx: &Cx) -> Result<impl View + '_> {
27 /// The signed-in chrome's wordmark with the family behind it: the `im`28 /// The signed-in chrome's wordmark with the family behind it: the `im`
28 /// mark as above, and the sibling services' wordmarks in a flyout that29 /// mark as above, and the sibling services' wordmarks in a flyout that
29 /// opens under it on hover and on keyboard focus (the mark is focusable30 /// opens under it on hover and on keyboard focus (the mark is focusable
30-/// for that), middots between, each a plain link. No script: the flyout31+/// for that), middots between, each a plain link carrying a health dot —
31-/// is CSS on `:hover` / `:focus-within`. A family with no siblings renders32+/// the same `/healthz` reading the admin panel's table takes its rows
32-/// the bare mark — nothing to reveal. The list is the stored one, the same33+/// from, green while the sibling answers `ok`, muted while it does not.
33-/// rows `/family` serves, minus im's own row.34+/// No script: the flyout is CSS on `:hover` / `:focus-within`. A family
35+/// with no siblings renders the bare mark — nothing to reveal, nothing
36+/// to probe. The list is the stored one, the same rows `/family` serves,
37+/// minus im's own row.
34 pub async fn family_wordmark(cx: &Cx) -> Result<BoxView<'_>> {38 pub async fn family_wordmark(cx: &Cx) -> Result<BoxView<'_>> {
35 let services = im_core::services::list(&server::app(cx).store).await?;39 let services = im_core::services::list(&server::app(cx).store).await?;
36 let siblings = services40 let siblings = services
37 .iter()41 .iter()
38 .filter(|service| service.key != "im")42 .filter(|service| service.key != "im")
39- .map(|service| {
40- let key = crate::pages::escape(&service.key);
41- let url = crate::pages::escape(&service.url);
42- format!(r#"<a class="trio-mark" href="{url}">{key}</a>"#)
43- })
44 .collect::<Vec<_>>();43 .collect::<Vec<_>>();
45 if siblings.is_empty() {44 if siblings.is_empty() {
46 return wordmark(cx).await.map(ViewExt::boxed);45 return wordmark(cx).await.map(ViewExt::boxed);
47 }46 }
48- let marks = siblings.join(r#"<span class="trio-sep">·</span>"#);47+ // Every probe at once: a family member that is down costs its two
48+ // seconds, not two seconds each.
49+ let http = reqwest::Client::new();
50+ let mut probes = Vec::new();
51+ for service in &siblings {
52+ let http = http.clone();
53+ let url = format!("{}/healthz", service.url.trim_end_matches('/'));
54+ probes.push(tokio::spawn(async move { probe_healthz(&http, &url).await }));
55+ }
56+ let mut marks = Vec::new();
57+ for (service, probe) in siblings.iter().zip(probes) {
58+ let key = crate::pages::escape(&service.key);
59+ let url = crate::pages::escape(&service.url);
60+ let dot = match probe.await.unwrap_or(Probe::Down) {
61+ Probe::Up { .. } => "health-on",
62+ Probe::Down => "health-off",
63+ };
64+ marks.push(format!(
65+ r#"<a class="trio-mark" href="{url}"><span class="health-dot {dot}"></span>{key}</a>"#
66+ ));
67+ }
68+ let marks = marks.join(r#"<span class="trio-sep">·</span>"#);
49 Ok(view! {69 Ok(view! {
50 cx =>70 cx =>
51 <div class="wordmark-family">71 <div class="wordmark-family">
crates/im-web/src/main.rsmodified+1 -0
@@ -15,6 +15,7 @@ mod auth;
15 mod config;15 mod config;
16 mod directory;16 mod directory;
17 mod dropdown;17 mod dropdown;
18+mod health;
18 mod i18n;19 mod i18n;
19 mod layout;20 mod layout;
20 mod live;21 mod live;
style/main.scssmodified+1 -1
@@ -307,7 +307,7 @@ body:has(.auth-stage) {
307 left: 50%;307 left: 50%;
308 z-index: 2;308 z-index: 2;
309 display: flex;309 display: flex;
310- align-items: baseline;310+ align-items: center;
311 gap: 10px;311 gap: 10px;
312 padding: 6px 12px;312 padding: 6px 12px;
313 background: var(--surface);313 background: var(--surface);