feat(ui): audit, alert rules and the rule form say things in words (#5212)
#5212 "Plain labels: no raw ids, scopes, metric keys or unexplained jargon", batch 1: - Audit log: each action reads as a sentence ("paused monitor"), with the code as its tooltip. Detail shows flags as yes/no, lists joined, a run's scope by name, spans as spans, and no ids the entity column already gives. The filter is now a picker of areas. - Alert rules, history and Status say the condition in words: "is down", "Fullest disk >= 85%". Readings use metric_value, and history times use |ago. - Rule form: sources and metrics by name, the threshold's unit, "fires when it is down/up" for an up/down metric instead of 0.5, and a metric reference built from the catalog. - Schedules and Maintenance: viewers no longer see Run now, Pause, Edit, Delete or New. Intervals and next runs read as "every 2h" and "in 3h"; a scope reads "Every alert on Host agent". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,16 @@ alerts_bp = Blueprint("alerts", __name__, url_prefix="/alerts")
|
||||
|
||||
_OPERATORS = [(op.value, op.value) for op in AlertOperator]
|
||||
|
||||
def _form_condition(form) -> dict:
|
||||
"""The operator and threshold the form asks for. An up/down metric's form
|
||||
sends the word it fires on (binary_when) instead: down is < 0.5, up is
|
||||
>= 0.5, the midpoint of the 1.0 / 0.0 such a metric records."""
|
||||
when = form.get("binary_when")
|
||||
if when in ("down", "up") and form.get("metric_name") in ("is_up", "is_healthy"):
|
||||
return {"operator": "<" if when == "down" else ">=", "threshold": "0.5"}
|
||||
return {"operator": form.get("operator", ""), "threshold": form.get("threshold")}
|
||||
|
||||
|
||||
def _rule_form(form) -> dict:
|
||||
"""The rule form's fields, as alert_svc.rule_fields takes them."""
|
||||
return {
|
||||
@@ -22,8 +32,7 @@ def _rule_form(form) -> dict:
|
||||
"source_module": form.get("source_module", ""),
|
||||
"resource_name": form.get("resource_name", ""),
|
||||
"metric_name": form.get("metric_name", ""),
|
||||
"operator": form.get("operator", ""),
|
||||
"threshold": form.get("threshold"),
|
||||
**_form_condition(form),
|
||||
"consecutive_failures_required": form.get("consecutive_failures_required"),
|
||||
"consecutive_ok_required": form.get("consecutive_ok_required"),
|
||||
"notify_no_data": "notify_no_data" in form,
|
||||
@@ -121,6 +130,7 @@ async def active_fragment():
|
||||
def _history_row(event, rule) -> dict:
|
||||
"""One transition as the history page shows it."""
|
||||
from steward.core.alerts import MUTED, RELEASED
|
||||
from steward.core.formatting import metric_label, metric_value
|
||||
notes, muted_by, released = [], None, False
|
||||
for part in (event.note or "").split("; "):
|
||||
if part.startswith(MUTED):
|
||||
@@ -129,11 +139,17 @@ def _history_row(event, rule) -> dict:
|
||||
released = True
|
||||
elif part:
|
||||
notes.append(part)
|
||||
value = "no data" if event.metric_value is None else f"{event.metric_value:g}"
|
||||
metric = rule.metric_name
|
||||
if event.metric_value is None:
|
||||
value = f"No {metric_label(metric)} reading"
|
||||
elif metric in ("is_up", "is_healthy"):
|
||||
value = metric_value(metric, event.metric_value).capitalize()
|
||||
else:
|
||||
value = f"{metric_label(metric)} {metric_value(metric, event.metric_value)}"
|
||||
return {
|
||||
"at": event.transitioned_at, "rule": rule,
|
||||
"from_state": event.from_state, "to_state": event.to_state,
|
||||
"value": value, "condition": f"{rule.operator.value} {rule.threshold:g}",
|
||||
"value": value, "condition": alert_svc.rule_condition(rule),
|
||||
"notes": notes, "muted_by": muted_by, "released": released,
|
||||
"deliveries": [(label, sent, error) for label, sent, error in (
|
||||
("email", event.email_sent, event.email_error),
|
||||
@@ -197,6 +213,7 @@ async def new_rule():
|
||||
initial_source=first_source,
|
||||
resources=resources,
|
||||
metrics=alert_svc.metric_catalog().get(first_source, []),
|
||||
catalog=alert_svc.metric_catalog(),
|
||||
ansible_sources=_ansible_source_names(),
|
||||
)
|
||||
|
||||
@@ -218,6 +235,7 @@ async def edit_rule(rule_id: str):
|
||||
initial_source=rule.source_module,
|
||||
resources=resources,
|
||||
metrics=alert_svc.metric_catalog().get(rule.source_module, []),
|
||||
catalog=alert_svc.metric_catalog(),
|
||||
ansible_sources=_ansible_source_names(),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user