Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ and listed with their assets on the
entry under the pool's with the command that removes it, `devstack
doctor` warns, and a hook bound to the upstream applies for the agent
that has it set up itself.
- **The dashboard's mark says when something needs attention.** A dot on
the mark in the top bar and on the browser tab's icon turns red when
something failed in any stack (a service, a build, a start, a lane's
start on a node) or the hub cannot be reached, and yellow when something
waits for you (a build held for promote, a pool request, a skill set to
answer). The hub sends it on its event stream as an `attention` event;
`/hub/summary` gives each item a `level` and now lists failed lane
starts too. On hover the mark turns over to the nut of the nuts family
([ADR-0097](docs/adr/0097-the-dashboards-mark-says-what-needs-attention.md)).
- **`devstack init` sets `PYTHONUTF8 = "1"` for Python apps.** On Windows a
native Python process opens text files in the ANSI code page (cp1252)
unless the code passes `encoding=`, while the same code in a container
Expand Down
18 changes: 18 additions & 0 deletions crates/devstack-hub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,23 @@ fn hub_events(s: &AppState) -> impl tokio_stream::Stream<Item = serde_json::Valu
.map(|w| serde_json::json!({ "type": "worktrees", "worktrees": w }));
let skills = tokio_stream::wrappers::WatchStream::new(s.skills.subscribe())
.map(|skills| serde_json::json!({ "type": "skills", "skills": skills }));
// What needs attention (ADR-0097): again when a stream's glance or the
// stack list (a start failed, a stack stopped) changed, sent only when
// the items did.
let attention = {
let s = s.clone();
let mut last: Option<Vec<summary::Attention>> = None;
tokio_stream::wrappers::WatchStream::new(s.board.subscribe())
.map(|_| ())
.merge(tokio_stream::wrappers::WatchStream::new(s.stacks.clone()).map(|_| ()))
.filter_map(move |()| {
let now = summary::attention(&s);
(last.as_ref() != Some(&now)).then(|| {
last = Some(now.clone());
serde_json::json!({ "type": "attention", "items": now })
})
})
};
// A dashboard that fell behind misses a toast, nothing it shows.
let notices =
tokio_stream::wrappers::BroadcastStream::new(notice::subscribe()).filter_map(|n| n.ok());
Expand All @@ -1587,6 +1604,7 @@ fn hub_events(s: &AppState) -> impl tokio_stream::Stream<Item = serde_json::Valu
.merge(pools)
.merge(skills)
.merge(trees)
.merge(attention)
.merge(notices)
}

Expand Down
4 changes: 3 additions & 1 deletion crates/devstack-hub/src/notify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,9 @@ async fn follow_stack(s: AppState, id: String, name: String) {
}
_ => scope.apply(&ev),
};
s.board.set(&id, None, scope.glance());
let mut glance = scope.glance();
glance.attention.extend(lanes.attention());
s.board.set(&id, None, glance);
for n in notices {
s.notify.deliver(&id, &name, None, n);
}
Expand Down
86 changes: 77 additions & 9 deletions crates/devstack-hub/src/notify/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use serde_json::Value;
use std::collections::HashMap;

use crate::summary::Level;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum Kind {
BuildFailed,
Expand Down Expand Up @@ -179,7 +181,8 @@ impl Scope {
if !svc.reason.starts_with(STOPPED_PREFIX)
&& !svc.reason.starts_with(CASCADE_PREFIX) =>
{
g.attention.push(attention(name, "failed", &svc.reason));
g.attention
.push(attention(name, "failed", &svc.reason, Level::Error));
}
_ => {}
}
Expand All @@ -188,11 +191,14 @@ impl Scope {
name,
"build held for promote",
&svc.candidate_reason,
Level::Warn,
)),
Some("failed") => g.attention.push(attention(
name,
"build failed",
&svc.candidate_reason,
Level::Error,
)),
Some("failed") => {
g.attention
.push(attention(name, "build failed", &svc.candidate_reason));
}
_ => {}
}
}
Expand All @@ -201,12 +207,13 @@ impl Scope {
}

/// `<service>: <what>`, and the first line of why.
fn attention(service: &str, what: &str, reason: &str) -> crate::summary::Item {
fn attention(service: &str, what: &str, reason: &str, level: Level) -> crate::summary::Item {
crate::summary::Item {
lane: None,
service: Some(service.to_string()),
text: format!("{service}: {what}"),
detail: first_lines(reason, 1),
level,
}
}

Expand Down Expand Up @@ -325,6 +332,8 @@ pub struct Lanes {
struct LaneSeen {
owns_main: bool,
failed_at: Option<u64>,
/// `<start|move> on <node> failed`, and why, while it is so.
failure: Option<(String, String)>,
}

impl Lanes {
Expand All @@ -350,13 +359,11 @@ impl Lanes {
&& was.failed_at != Some(at)
{
let m = &l["moving"];
let what = if m["kind"] == "move" { "move" } else { "start" };
let to = m["to"].as_str().unwrap_or("a node");
out.push(Notice {
kind: Kind::LaneFailed,
service: None,
lane: Some(name.to_string()),
title: format!("Lane {name}: {what} on {to} failed"),
title: format!("Lane {name}: {}", failed_what(m)),
body: first_lines(m["error"].as_str().unwrap_or(""), 3),
});
}
Expand All @@ -377,6 +384,28 @@ impl Lanes {
out
}

/// The lanes whose start or move on a node failed and that are still
/// so, for the hub's summary (ADR-0097).
pub fn attention(&self) -> Vec<crate::summary::Item> {
let mut out: Vec<_> = self
.known
.iter()
.flatten()
.filter_map(|(name, l)| {
let (what, why) = l.failure.clone()?;
Some(crate::summary::Item {
lane: Some(name.clone()),
service: None,
text: format!("lane {name}: {what}"),
detail: why,
level: Level::Error,
})
})
.collect();
out.sort_by(|a, b| a.lane.cmp(&b.lane));
out
}

/// The lanes that have an API of their own now: started, on this
/// machine or on a node.
pub fn started(lanes: &Value) -> Vec<String> {
Expand All @@ -401,12 +430,27 @@ fn seen(lanes: &Value) -> HashMap<String, LaneSeen> {
LaneSeen {
owns_main: l["owns_main"].as_bool().unwrap_or(false),
failed_at: l["moving"]["failed_at"].as_u64(),
failure: failure(&l["moving"]),
},
))
})
.collect()
}

/// A lane's failed start or move: `<start|move> on <node> failed`, and the
/// first line of why; `None` while it has not failed.
fn failure(m: &Value) -> Option<(String, String)> {
let error = m["error"].as_str()?;
Some((failed_what(m), first_lines(error, 1)))
}

/// `<start|move> on <node> failed`.
fn failed_what(m: &Value) -> String {
let what = if m["kind"] == "move" { "move" } else { "start" };
let to = m["to"].as_str().unwrap_or("a node");
format!("{what} on {to} failed")
}

/// At most `n` non-empty lines, each at most 200 characters.
fn first_lines(text: &str, n: usize) -> String {
text.lines()
Expand Down Expand Up @@ -465,6 +509,7 @@ mod tests {
assert_eq!(g.attention.len(), 1);
assert_eq!(g.attention[0].text, "api: build held for promote");
assert_eq!(g.attention[0].detail, "schema");
assert_eq!(g.attention[0].level, Level::Warn);
s.apply(&service(
"worker",
json!({ "state": "failed", "reason": "port taken" }),
Expand All @@ -473,6 +518,7 @@ mod tests {
assert!(!g.starting);
assert_eq!(g.attention[1].text, "worker: failed");
assert_eq!(g.attention[1].service.as_deref(), Some("worker"));
assert_eq!(g.attention[1].level, Level::Error);
}

#[test]
Expand Down Expand Up @@ -634,6 +680,28 @@ mod tests {
);
}

#[test]
fn a_failed_lane_needs_attention_while_it_is_so() {
let mut l = Lanes::default();
let lane = |error: Option<&str>| {
json!([{ "name": "feat-x", "active": false,
"moving": error.map(|e| json!({ "kind": "move", "to": "big-box", "error": e, "failed_at": 1 })) }])
};
l.baseline(&lane(Some(
"no lease: node full
more",
)));
// Unlike a notification, what had failed before counts: it still is.
let a = l.attention();
assert_eq!(a.len(), 1);
assert_eq!(a[0].text, "lane feat-x: move on big-box failed");
assert_eq!(a[0].detail, "no lease: node full");
assert_eq!(a[0].lane.as_deref(), Some("feat-x"));
assert_eq!(a[0].level, Level::Error);
l.apply(&lane(None));
assert!(l.attention().is_empty());
}

#[test]
fn lanes_failing_and_taking_the_main_ports() {
let mut l = Lanes::default();
Expand Down
Loading