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:
@@ -295,10 +295,12 @@ async def cover_groups_api():
|
||||
|
||||
|
||||
async def _target(db, source: str, *, host: str = "", resource: str = "", metric: str = "",
|
||||
covers: str = "resource") -> dict:
|
||||
"""The rule form's target pickers and the chosen metric's preview (#5475)."""
|
||||
covers: str = "resource", keep: bool = False) -> dict:
|
||||
"""The rule form's target pickers and the chosen metric's preview (#5475);
|
||||
`keep` on a rule's own page, so its resource and metric stay on offer."""
|
||||
from steward.core.status import sparkline_svg
|
||||
target = await alert_svc.rule_target(db, source, host=host, resource=resource, metric=metric)
|
||||
target = await alert_svc.rule_target(db, source, host=host, resource=resource, metric=metric,
|
||||
keep=keep)
|
||||
preview = None
|
||||
if target["resource"] and target["metric"]:
|
||||
preview = await alert_svc.metric_preview(db, source, target["resource"], target["metric"])
|
||||
@@ -360,7 +362,7 @@ async def edit_rule(rule_id: str):
|
||||
return redirect(f"/alerts/rules/{rule.parent_id}/edit")
|
||||
ctx = {**await _cover_choices(db, rule.source_module, rule),
|
||||
**await _target(db, rule.source_module, resource=rule.resource_name,
|
||||
metric=rule.metric_name, covers=rule.covers)}
|
||||
metric=rule.metric_name, covers=rule.covers, keep=True)}
|
||||
hosts = sorted((c.resource_name for c in (await db.execute(
|
||||
select(AlertRule).where(AlertRule.parent_id == rule.id))).scalars()), key=str.lower)
|
||||
history_count = (await db.execute(
|
||||
|
||||
Reference in New Issue
Block a user