fix(alerts): a metric picked on one part doesn't follow you to another (#5475)
#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:
@@ -391,13 +391,14 @@ def alertable(source_module: str, reported: set[str]) -> list[str]:
|
||||
|
||||
|
||||
async def rule_target(db, source_module: str, *, host: str = "", resource: str = "",
|
||||
metric: str = "") -> dict:
|
||||
metric: str = "", keep: bool = False) -> dict:
|
||||
"""What the rule form's target pickers offer (#5475), from the latest-value
|
||||
table: the resources that report something a rule can watch, and for the
|
||||
chosen one the metrics it reports. For a host source the resources split
|
||||
into a Host picker and a Part picker ("the whole host", then the host's
|
||||
mounts, cores and so on). A resource or metric already chosen stays on
|
||||
offer even when it has gone quiet, so editing a rule never drops them.
|
||||
mounts, cores and so on). With `keep` (a rule's own page), its resource
|
||||
and metric stay on offer even after they go quiet, so opening a rule
|
||||
never drops them; a metric carried over from another part is dropped.
|
||||
|
||||
Returns host_source, hosts, host, parts [(heading, [(value, label)])],
|
||||
resources, resource, metrics, metric."""
|
||||
@@ -434,7 +435,7 @@ async def rule_target(db, source_module: str, *, host: str = "", resource: str =
|
||||
else:
|
||||
out["resources"] = sorted(pickable, key=str.lower)
|
||||
metrics = list(pickable.get(out["resource"]) or catalog)
|
||||
if metric and metric not in metrics and (metric in catalog or not catalog):
|
||||
if keep and metric and metric not in metrics and (metric in catalog or not catalog):
|
||||
metrics.append(metric)
|
||||
out.update(metrics=metrics, metric=metric if metric in metrics else "")
|
||||
return out
|
||||
|
||||
Reference in New Issue
Block a user