feat: notify when a container fails or turns unhealthy #26
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/19-notifications"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Desktop notifications when a container exits with an error, runs out of memory, or turns unhealthy. Clicking one (or its Show Logs button) opens Krane on that container's logs.
Closes #19
Stacked on #25 (start at login), which is stacked on #24, #23 and #22. Retarget to main once those merge.
What's in it
src/notify.rs: listens to container events and talks toorg.freedesktop.Notificationsover D-Bus. zbus is already in the build through ksni, so it's now a direct dependency with no new crates.docker stop/kill/rm -ffrom the CLI on Docker (a kill or stop within 10 s before thedie)oom+diebecome one "Ran out of memory" notification. A restart loop notifies at most once a minute per container, and the new notification replaces the old one.health_status: unhealthynotifies. Podman'shealth_statushas no status and repeats on every check, so Krane inspects the container and notifies only when it turns unhealthy.~/.config/krane/settings.json.(Xfce 4.20 here. The icon is blank only because Krane's icon isn't installed on this test box.)
Tested
docker stopstayed quiet#16 will need to move this listener onto the shared engine client and restart it when the engine changes.
f4730a01ae78bdd8e0d5Review from Nye (posted by Upper Wolfjaw):
PR #26 (#19 notifications) review at
f4730a0: CHANGES REQUESTEDC7 pass: fmt, clippy -D warnings (with/without mock), both builds, 26 tests. Live on Docker 26
(private D-Bus session, fake notification server fake_notifyd.py, pr26-live.sh): crash exit 3 ->
"stopped / Exited with code 3." with default+Show Logs actions; OOM -> one alert "Ran out of memory";
health-cmd false -> "is unhealthy"; clean exit and
docker stopquiet. Code reads well: Tracker logic,5 s D-Bus timeouts, escaping only with body-markup, replaces_id per container.
F9 (medium): Podman CLI stops alert.
podman stop(anddocker stop/compose against Podman's socket)send only
die 137(no kill/stop event; checked on the events stream), so Krane shows"nye-p-stop stopped / Exited with code 137". README promises CLI stops stay quiet.
Proof: notes/pr26-podman-stop-proof.sh (run in pr26 worktree; needs rootless podman socket).
Fix options: treat die with exitCode 137 or 143 and no preceding oom as a stop (quiet), at least when
the engine is Podman (version Components "Podman Engine"); or narrow the README claim. Former preferred.
F8 (low): login race. Notifier::connect caches GetCapabilities; if the notification server isn't on
the bus yet (KDE/GNOME: server is the shell, not D-Bus activatable; Krane via start at login), caps =
[] for the whole session -> no "default" action (click never opens logs) and no escaping.
Proof:
notes/pr26-live.sh late(bus config session-noactivation.conf, server starts 3 s after Krane).Fix: don't keep an empty/failed capability answer; re-ask GetCapabilities in show() until one succeeds
(or ask every time; it's one cheap call with the 5 s timeout).
Notes (not blocking):
docker run --rm img falseor Ctrl-C (130) indocker run -italerts.stopping" when a container is mid-stop (bollard enum). Worth an issue for #16 (engine picker).78bdd8e0d542dfed553aFixed both findings in
42dfed5(amended; #27 rebased onto it as73ece6f).notes/pr26-live.sh latepasses: the crash alert has the default/Show Logs actions.diewith 137 or 143 and nooomcounts as a stop and stays quiet. Crashes (any other code) and OOMs still alert, and nothing changes on Docker.notes/pr26-podman-stop-proof.shpasses on Podman 5.4.2. New unit test:podman_cli_stop_is_quiet_but_its_crashes_and_ooms_alert.Trade-off: on Podman, an outside
kill -9(with no OOM) is now quiet too, because the events stream can't tell it apart from a stop.Local CI is green: fmt, clippy (both feature sets), builds, and 31 tests.
42dfed553a5838fb897cF11 fixed in
5838fb8: adie137/143 with no kill, stop or oom event now inspects the container.State.OOMKilled=truealerts "Ran out of memory" (Podman's only signal, and Docker's oom-after-die race). Otherwise Podman treats it as a stop, and Docker alerts the exit code. A lateoomonly counts within 10 s of the die. Nye's OOM proof passes (2 of 3 containers marked OOMKilled, both alerted as out of memory; podman stop quiet), and the F9 stop proof still passes. 3 new unit tests.