fix(alerts): a metric picked on one part doesn't follow you to another (#5475)
CI / lint (push) Successful in 2s
CI / integration (push) Successful in 1m8s
CI / unit (push) Successful in 1m26s
CI / publish (push) Successful in 1m17s

#5475 "Rule form: pick the host, then its part…". CI run 8909 caught it:
moving from the whole host to a mount kept "CPU" in the mount's Metric list,
because a chosen metric always stayed on offer. Only a rule's own page keeps
its resource and metric after they go quiet (keep=True from edit_rule); the
pickers' swaps drop a metric the new part doesn't report.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-09 09:58:29 -04:00
co-authored by Claude Opus 5.5
parent d19df51ffb
commit 731e7cd6e6
3 changed files with 19 additions and 9 deletions
+8 -1
View File
@@ -59,7 +59,14 @@ async def test_picking_another_host_starts_at_the_whole_host():
async def test_a_rule_s_own_resource_stays_on_offer_after_it_goes_quiet():
got = await alert_svc.rule_target(_db(), "host_agent", resource="h3:/data",
metric="disk_used_pct")
metric="disk_used_pct", keep=True)
assert "h3" in got["hosts"] and got["host"] == "h3"
assert got["parts"] == [("Mounts", [("h3:/data", "/data")])]
assert got["metric"] == "disk_used_pct"
# A reporting part whose metric went quiet keeps it on the rule's own page.
got = await alert_svc.rule_target(_db(), "host_agent", resource="h1:/var", metric="disk_free_pct",
keep=True)
assert got["metric"] == "" # not in the catalog: not offered
got = await alert_svc.rule_target(_db(), "host_agent", resource="h1:/var", metric="uptime_secs",
keep=True)
assert got["metrics"] == ["disk_used_pct", "uptime_secs"] and got["metric"] == "uptime_secs"