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
16 changes: 16 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ docstring gives: it is a record, not a claim about now.

## 2026-11-19

- **`PatchStateStopped` and `GuestStateStopped` now also fire for a
collector that stops and leaves its file.** The entry below left this open:
a stopped timer leaves its `.prom` file in the textfile directory,
node_exporter re-serves its last values on every scrape, and the series
never goes absent, so the rules saw nothing. Raised by Copilot in review of
#1585. Each rule now has a second branch, `or`'d to the first, on
`node_textfile_mtime_seconds` for its own file, as the lab's
`PatchStateStopped` has had since #1544: `apt-patch-state.prom` older than
two days against its daily timer, `guest-state.prom` older than an hour
against its ten-minute one. The mtime series carries `instance`, which
Alloy sets to the same hostname the collectors write into `host`, so
`label_replace` copies one into the other and both branches alert under
one label set. New promtool cases fire with the series present and the
file frozen, and stay quiet with the file rewritten and an old file of
another collector beside it. With the second branch removed the firing
cases fail; with the regex loosened to `.*state\.prom` the quiet ones do.
- **`PatchStateStopped` and `GuestStateStopped` no longer clear themselves a
day after a host's series disappears.** Both asked "did this host report in the day
before the last six hours", so about 30 h after the last sample the left
Expand Down
78 changes: 58 additions & 20 deletions stacks/observability/prometheus/rules/host.rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -314,15 +314,33 @@ groups:
# it when it goes. The cost is a 14d range per host each evaluation,
# one series per host, which this estate's handful of hosts can carry.
#
# WHAT THIS DOES NOT SEE: a timer that stops but leaves its file. The
# file stays in the textfile directory and is re-served on every
# scrape, so the series never goes absent. The lab's copy of this rule
# has a second branch on node_textfile_mtime_seconds for that; this
# one does not yet.
# TWO WAYS TO STOP, SO TWO BRANCHES. Everything above is the first:
# the series vanished, because Alloy or the textfile directory went.
# The second is a timer that stops and leaves its file. The file stays
# in the textfile directory and node_exporter re-serves its last
# values on every scrape, so the series never goes absent and the
# first branch cannot see it; only the file's mtime stops moving. Two
# days against the daily 08:00 timer, the window the lab's copy of
# this rule settled on (#1544), covers one missed run and its fifteen
# minutes of jitter and not two. The mtime series carries `instance`,
# which Alloy sets to the same hostname the collector writes into
# `host`, so label_replace copies one into the other and both branches
# alert under one label set. A host that is down loses its mtime
# series with everything else, so this branch stays quiet and
# InstanceDown speaks.
expr: >-
count by (host) (present_over_time(homelab_apt_upgrades_pending[14d] offset 6h))
unless
count by (host) (present_over_time(homelab_apt_upgrades_pending[6h]))
(
count by (host) (present_over_time(homelab_apt_upgrades_pending[14d] offset 6h))
unless
count by (host) (present_over_time(homelab_apt_upgrades_pending[6h]))
)
or
count by (host) (
label_replace(
time() - node_textfile_mtime_seconds{file=~".*apt-patch-state\\.prom"} > 2 * 86400,
"host", "$1", "instance", "(.*)"
)
)
for: 30m
labels:
component: host
Expand All @@ -331,9 +349,11 @@ groups:
annotations:
summary: "{{ $labels.host }} has stopped reporting patch state"
description: >-
It reported within the last two weeks and has not in six hours, so
SecurityUpdatesPending and RebootRequired are both blind to this host
until it comes back. Check homelab-patch-state.timer on the host —
Either its patch state reported within the last two weeks and has
not in six hours, or apt-patch-state.prom has not been rewritten in
two days, so SecurityUpdatesPending and RebootRequired are reading
no data or stale data for this host until the collector runs again.
Check homelab-patch-state.timer on the host —
`systemctl status homelab-patch-state.timer` — and that
/var/lib/node_exporter/textfile_collector/apt-patch-state.prom is
being written and is world-readable. A 0600 file is invisible to the
Expand Down Expand Up @@ -1019,13 +1039,28 @@ groups:
# Stopped, not missing: a hypervisor that never had the collector
# installed must stay quiet, or every host without it alerts forever.
# Fourteen days of memory, for PatchStateStopped's reason: with [1d]
# the alert cleared itself about 30h after the series went. Like
# PatchStateStopped it sees the series vanish, not a timer that stops
# and leaves guest-state.prom in place.
# the alert cleared itself about 30h after the series went.
#
# And PatchStateStopped's second branch, for a timer that stops and
# leaves guest-state.prom in place to be re-served. An hour, not two
# days: this timer runs every ten minutes, so an hour is six missed
# runs, which a reboot does not reach — ThinPoolStateStale's and
# GuestDiskStateStale's window for their ten-minute timers. It is also
# HypervisorGuestStopped's own hour, so a frozen file is caught no
# later than the guest it hides would have been.
expr: >-
count by (host) (present_over_time(homelab_guests_total[14d] offset 6h))
unless
count by (host) (present_over_time(homelab_guests_total[6h]))
(
count by (host) (present_over_time(homelab_guests_total[14d] offset 6h))
unless
count by (host) (present_over_time(homelab_guests_total[6h]))
)
or
count by (host) (
label_replace(
time() - node_textfile_mtime_seconds{file=~".*guest-state\\.prom"} > 3600,
"host", "$1", "instance", "(.*)"
)
)
for: 30m
labels:
component: host
Expand All @@ -1034,9 +1069,12 @@ groups:
annotations:
summary: "{{ $labels.host }} has stopped reporting its guests"
description: >-
It reported within the last two weeks and has not in six hours, so
HypervisorGuestStopped is blind to this hypervisor until it comes
back. Check homelab-guest-state.timer on the host and that
Either its guests reported within the last two weeks and have not
in six hours, or guest-state.prom has not been rewritten in an
hour, so HypervisorGuestStopped is reading no data or stale data
for this hypervisor until the collector runs again. Check
homelab-guest-state.timer on the host, its last run in the journal
(`journalctl -u homelab-guest-state`), and that
/var/lib/node_exporter/textfile_collector/guest-state.prom is being
written and is world-readable.

Expand Down
169 changes: 151 additions & 18 deletions stacks/observability/prometheus/tests/host.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -716,10 +716,13 @@ tests:
exp_annotations:
summary: "oracle has stopped reporting patch state"
description: >-
It reported within the last two weeks and has not in six hours, so
SecurityUpdatesPending and RebootRequired are both blind to this
host until it comes back. Check homelab-patch-state.timer on the
host — `systemctl status homelab-patch-state.timer` — and that
Either its patch state reported within the last two weeks and
has not in six hours, or apt-patch-state.prom has not been
rewritten in two days, so SecurityUpdatesPending and
RebootRequired are reading no data or stale data for this host
until the collector runs again. Check homelab-patch-state.timer
on the host — `systemctl status homelab-patch-state.timer` —
and that
/var/lib/node_exporter/textfile_collector/apt-patch-state.prom is
being written and is world-readable. A 0600 file is invisible to
the collector and produces exactly this silence.
Expand All @@ -746,10 +749,13 @@ tests:
exp_annotations:
summary: "oracle has stopped reporting patch state"
description: >-
It reported within the last two weeks and has not in six hours, so
SecurityUpdatesPending and RebootRequired are both blind to this
host until it comes back. Check homelab-patch-state.timer on the
host — `systemctl status homelab-patch-state.timer` — and that
Either its patch state reported within the last two weeks and
has not in six hours, or apt-patch-state.prom has not been
rewritten in two days, so SecurityUpdatesPending and
RebootRequired are reading no data or stale data for this host
until the collector runs again. Check homelab-patch-state.timer
on the host — `systemctl status homelab-patch-state.timer` —
and that
/var/lib/node_exporter/textfile_collector/apt-patch-state.prom is
being written and is world-readable. A 0600 file is invisible to
the collector and produces exactly this silence.
Expand All @@ -764,10 +770,13 @@ tests:
exp_annotations:
summary: "oracle has stopped reporting patch state"
description: >-
It reported within the last two weeks and has not in six hours, so
SecurityUpdatesPending and RebootRequired are both blind to this
host until it comes back. Check homelab-patch-state.timer on the
host — `systemctl status homelab-patch-state.timer` — and that
Either its patch state reported within the last two weeks and
has not in six hours, or apt-patch-state.prom has not been
rewritten in two days, so SecurityUpdatesPending and
RebootRequired are reading no data or stale data for this host
until the collector runs again. Check homelab-patch-state.timer
on the host — `systemctl status homelab-patch-state.timer` —
and that
/var/lib/node_exporter/textfile_collector/apt-patch-state.prom is
being written and is world-readable. A 0600 file is invisible to
the collector and produces exactly this silence.
Expand All @@ -789,6 +798,69 @@ tests:
alertname: PatchStateStopped
exp_alerts: []

# --- PatchStateStopped: fires when the file stops being rewritten ---------
# The case the first branch cannot see, raised in review on #1585: the timer
# stops and leaves apt-patch-state.prom in place, node_exporter re-serves it,
# and homelab_apt_upgrades_pending stays present throughout. Only the mtime
# stops moving. Written at t=0 and never again, it is two days old at 48h,
# and `for: 30m` makes it firing by 49h. Quiet at 47h, inside the window.
#
# The alert carries `host`, copied from the mtime series' `instance`, so it
# is the same label set the absence branch produces for the same host.
- interval: 5m
input_series:
- series: 'homelab_apt_upgrades_pending{host="oracle"}'
values: "3x600"
- series: 'node_textfile_mtime_seconds{instance="oracle",job="oracle-metrics",file="apt-patch-state.prom"}'
values: "0x600"
alert_rule_test:
- eval_time: 47h
alertname: PatchStateStopped
exp_alerts: []
- eval_time: 49h
alertname: PatchStateStopped
exp_alerts:
- exp_labels:
host: oracle
component: host
severity: warning
category: security
exp_annotations:
summary: "oracle has stopped reporting patch state"
description: >-
Either its patch state reported within the last two weeks and
has not in six hours, or apt-patch-state.prom has not been
rewritten in two days, so SecurityUpdatesPending and
RebootRequired are reading no data or stale data for this host
until the collector runs again. Check homelab-patch-state.timer
on the host — `systemctl status homelab-patch-state.timer` —
and that
/var/lib/node_exporter/textfile_collector/apt-patch-state.prom is
being written and is world-readable. A 0600 file is invisible to
the collector and produces exactly this silence.

# --- PatchStateStopped: quiet while the daily timer keeps rewriting it ----
# Rewritten once a day, as the 08:00 timer does, so the file is never more
# than a day old. guest-state.prom beside it on the same host is old and must
# not match: the regex is the whole scope of the branch, and a loosened
# `.*state\.prom` fails this case.
#
# Sampled every 5m although the file changes daily. At 1h each series is
# absent for most of every step (the lookback is 5m), `for` restarts each
# time, and the loosened regex survived this case still pending.
- interval: 5m
input_series:
- series: 'homelab_apt_upgrades_pending{host="oracle"}'
values: "3x1000"
- series: 'node_textfile_mtime_seconds{instance="oracle",job="oracle-metrics",file="apt-patch-state.prom"}'
values: "0x287 86400x287 172800x287 259200x135"
- series: 'node_textfile_mtime_seconds{instance="oracle",job="oracle-metrics",file="guest-state.prom"}'
values: "0x1000"
alert_rule_test:
- eval_time: 79h
alertname: PatchStateStopped
exp_alerts: []

# --- DriftCheckStopped: fires when the timestamp stops moving ---------------
# The collector writes the run's Unix time and node_exporter re-serves the
# file on every scrape, so the series is present throughout; only its value
Expand Down Expand Up @@ -1842,9 +1914,12 @@ tests:
exp_annotations:
summary: "Saruman has stopped reporting its guests"
description: >-
It reported within the last two weeks and has not in six hours, so
HypervisorGuestStopped is blind to this hypervisor until it
comes back. Check homelab-guest-state.timer on the host and that
Either its guests reported within the last two weeks and have
not in six hours, or guest-state.prom has not been rewritten in
an hour, so HypervisorGuestStopped is reading no data or stale
data for this hypervisor until the collector runs again. Check
homelab-guest-state.timer on the host, its last run in the
journal (`journalctl -u homelab-guest-state`), and that
/var/lib/node_exporter/textfile_collector/guest-state.prom is
being written and is world-readable.

Expand All @@ -1868,9 +1943,12 @@ tests:
exp_annotations:
summary: "Saruman has stopped reporting its guests"
description: >-
It reported within the last two weeks and has not in six hours, so
HypervisorGuestStopped is blind to this hypervisor until it
comes back. Check homelab-guest-state.timer on the host and that
Either its guests reported within the last two weeks and have
not in six hours, or guest-state.prom has not been rewritten in
an hour, so HypervisorGuestStopped is reading no data or stale
data for this hypervisor until the collector runs again. Check
homelab-guest-state.timer on the host, its last run in the
journal (`journalctl -u homelab-guest-state`), and that
/var/lib/node_exporter/textfile_collector/guest-state.prom is
being written and is world-readable.
- eval_time: 16d
Expand All @@ -1889,6 +1967,61 @@ tests:
alertname: GuestStateStopped
exp_alerts: []

# --- GuestStateStopped: fires when the file stops being rewritten ---------
# PatchStateStopped's second branch, at this timer's cadence. The collector
# stops, guest-state.prom stays, homelab_guests_total is re-served and never
# goes absent. Written at t=0 and never again, it is an hour old at 60m and
# firing by 95m; quiet at 55m.
- interval: 5m
input_series:
- series: 'homelab_guests_total{host="Saruman"}'
values: "1x40"
- series: 'node_textfile_mtime_seconds{instance="Saruman",job="Saruman-metrics",file="guest-state.prom"}'
values: "0x40"
alert_rule_test:
- eval_time: 55m
alertname: GuestStateStopped
exp_alerts: []
- eval_time: 95m
alertname: GuestStateStopped
exp_alerts:
- exp_labels:
host: Saruman
component: host
severity: warning
category: availability
exp_annotations:
summary: "Saruman has stopped reporting its guests"
description: >-
Either its guests reported within the last two weeks and have
not in six hours, or guest-state.prom has not been rewritten in
an hour, so HypervisorGuestStopped is reading no data or stale
data for this hypervisor until the collector runs again. Check
homelab-guest-state.timer on the host, its last run in the
journal (`journalctl -u homelab-guest-state`), and that
/var/lib/node_exporter/textfile_collector/guest-state.prom is
being written and is world-readable.

# --- GuestStateStopped: quiet while the timer keeps rewriting it ----------
# Rewritten on every sample. guest-disk-state.prom beside it is old and must
# not match: `.*guest-state\.prom` does not reach it, and a regex loosened
# to `.*state\.prom` fails this case. Sampled every 5m for
# ThinPoolStateStale's reason: at 10m each sample is absent for half of
# every step and `for` restarts, so a loosened regex would pass still
# pending.
- interval: 5m
input_series:
- series: 'homelab_guests_total{host="Saruman"}'
values: "1x40"
- series: 'node_textfile_mtime_seconds{instance="Saruman",job="Saruman-metrics",file="guest-state.prom"}'
values: "0+300x40"
- series: 'node_textfile_mtime_seconds{instance="Saruman",job="Saruman-metrics",file="guest-disk-state.prom"}'
values: "0x40"
alert_rule_test:
- eval_time: 3h
alertname: GuestStateStopped
exp_alerts: []

# --- ThinPoolNearlyFull: data and metadata, both at once ------------------
# The case label_replace exists for. Both spaces of one pool over their lines
# at the same time must be TWO alerts told apart by `space`; without it the
Expand Down