Host down: tell a planned reboot from a crash using the journal in Loki #65

Merged
jared merged 1 commits from planned-reboots into main 2026-11-25 14:35:11 -05:00
Owner

Refs #47. This PR covers Gandalf's part. The "unexpected reboot" alert, for crashes that recover inside the window, is host health, so it goes to thor (see the comment on #47).

What changes

When a configured host stops reporting to Prometheus, Gandalf asks Loki whether the host's systemd-logind logged a shutdown request just before it went quiet. The request looks like The system will reboot now! or power off now!.

Shutdown requested:

  • Dashboard: the host shows as "rebooting (planned)" in Needs attention, as an info-level host_rebooting event rather than an outage.
  • Cluster check: the host doesn't count toward it. Last night's two requested power-offs would no longer add up toward a cluster alert.
  • Ticket: only if the host hasn't come back within planned_reboot_grace of the shutdown line. The default is 20 minutes, and planned_reboot_grace_hosts sets per-host overrides. The ticket is P2 and titled "Planned reboot did not come back", with checks aimed at a host stuck in POST or boot, or left powered off.

No shutdown line: alerted exactly as before, on host_failure_threshold.

Loki not configured, unreachable, or erroring: alerted exactly as before. A failed log query never delays or silences an alert.

How it's built

  • reboots.py: a Loki client plus find_shutdown and grace_for. It doesn't touch Gandalf's database or tickets, so thor can take it over unchanged.
  • Loki queries: one per check per missing host, and only while the host could still be in an ordinary reboot (host_failure_threshold checks). The answer is cached until the host returns.
  • Restarts: a monitor restart in the middle of a reboot still finds the shutdown line, because the lookback covers the whole window.

Verification

  • Real data: ran find_shutdown from prod against Loki for last month's reboots. All six came out right:
Reboot Result
micro1 planned, 11-06 planned (23:17:49)
monitor-02 planned, 11-06 planned (23:25:26)
compute-storage-02 planned, 11-18 planned (20:02:19)
compute-storage-02 crash, 11-21 not planned, alerted as usual
compute-storage-01 power off, 11-25 planned (03:21:38)
storage-01 unclean stop, 11-25 not planned, alerted as usual
  • Tests: 678 pass, 23 of them new. They cover planned with no ticket, cluster exclusion, caching, grace expiry, per-host grace, a crash, Loki down, no Loki configured, a monitor restart mid-reboot, and the query window cutoff. The Needs attention entry is tested too.
  • flake8 and bandit are clean. No em or en dashes.

Rollout

Prod's config.json needs "loki": {"url": "http://10.10.10.69:3100"}. Until it has that, nothing changes. I checked that the Gandalf LXC can query Loki at that address. After the merge I'll back up the config, add the key, and restart gandalf-monitor.

🤖 Generated with Claude Code

Refs #47. This PR covers Gandalf's part. The "unexpected reboot" alert, for crashes that recover inside the window, is host health, so it goes to thor (see the comment on #47). ## What changes When a configured host stops reporting to Prometheus, Gandalf asks Loki whether the host's `systemd-logind` logged a shutdown request just before it went quiet. The request looks like `The system will reboot now!` or `power off now!`. **Shutdown requested:** - Dashboard: the host shows as **"rebooting (planned)"** in Needs attention, as an info-level `host_rebooting` event rather than an outage. - Cluster check: the host doesn't count toward it. Last night's two requested power-offs would no longer add up toward a cluster alert. - Ticket: only if the host hasn't come back within `planned_reboot_grace` of the shutdown line. The default is 20 minutes, and `planned_reboot_grace_hosts` sets per-host overrides. The ticket is P2 and titled "Planned reboot did not come back", with checks aimed at a host stuck in POST or boot, or left powered off. **No shutdown line:** alerted exactly as before, on `host_failure_threshold`. **Loki not configured, unreachable, or erroring:** alerted exactly as before. A failed log query never delays or silences an alert. ## How it's built - **`reboots.py`:** a Loki client plus `find_shutdown` and `grace_for`. It doesn't touch Gandalf's database or tickets, so thor can take it over unchanged. - **Loki queries:** one per check per missing host, and only while the host could still be in an ordinary reboot (`host_failure_threshold` checks). The answer is cached until the host returns. - **Restarts:** a monitor restart in the middle of a reboot still finds the shutdown line, because the lookback covers the whole window. ## Verification - **Real data:** ran `find_shutdown` from prod against Loki for last month's reboots. All six came out right: | Reboot | Result | |---|---| | micro1 planned, 11-06 | planned (23:17:49) | | monitor-02 planned, 11-06 | planned (23:25:26) | | compute-storage-02 planned, 11-18 | planned (20:02:19) | | compute-storage-02 crash, 11-21 | not planned, alerted as usual | | compute-storage-01 power off, 11-25 | planned (03:21:38) | | storage-01 unclean stop, 11-25 | not planned, alerted as usual | - **Tests:** 678 pass, 23 of them new. They cover planned with no ticket, cluster exclusion, caching, grace expiry, per-host grace, a crash, Loki down, no Loki configured, a monitor restart mid-reboot, and the query window cutoff. The Needs attention entry is tested too. - flake8 and bandit are clean. No em or en dashes. ## Rollout Prod's `config.json` needs `"loki": {"url": "http://10.10.10.69:3100"}`. Until it has that, nothing changes. I checked that the Gandalf LXC can query Loki at that address. After the merge I'll back up the config, add the key, and restart gandalf-monitor. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jared added 1 commit 2026-11-25 14:28:30 -05:00
Host down: tell a planned reboot from a crash using the journal in Loki
Lint / JS (eslint) (push) Successful in 12s
Lint / Python (flake8) (push) Successful in 1m34s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 1m54s
Lint / JS (eslint) (pull_request) Successful in 37s
Security / Python Security (bandit) (pull_request) Successful in 2m36s
Test / Python Tests (pytest) (push) Successful in 2m17s
Lint / Python (flake8) (pull_request) Successful in 57s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Test / Python Tests (pytest) (pull_request) Successful in 1m16s
1db932f10e
When a host stops reporting, ask Loki whether its systemd-logind logged a
shutdown request just before. If so, show it as "rebooting (planned)"
instead of an outage, keep it out of the cluster check, and ticket only if
it has not come back within planned_reboot_grace (default 20 min, per host
overrides) as "Planned reboot did not come back". No line, no Loki config,
or a Loki error: alert exactly as before.

Refs #47 (the "unexpected reboot" alert for crashes that recover goes to thor)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jared scheduled this pull request to auto merge when all checks succeed 2026-11-25 14:35:08 -05:00
jared merged commit bf5d36ed1e into main 2026-11-25 14:35:11 -05:00
jared deleted branch planned-reboots 2026-11-25 14:35:13 -05:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: LotusGuild/gandalf#65