#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>
71 lines
3.3 KiB
Python
71 lines
3.3 KiB
Python
"""The Status page says what is wrong, and since when, before anything else
|
|
(#5120)."""
|
|
from datetime import datetime, timedelta, timezone
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
from quart import render_template
|
|
|
|
from steward.core.status import StatusEntry, streak_start
|
|
from tests.test_style_tokens import hex_colours
|
|
|
|
T0 = datetime(2026, 10, 6, 18, 0, tzinfo=timezone.utc)
|
|
|
|
|
|
def _checks(*ups):
|
|
return [SimpleNamespace(is_up=up, checked_at=T0 + timedelta(minutes=i)) for i, up in enumerate(ups)]
|
|
|
|
|
|
@pytest.mark.parametrize("ups, since, at_least", [
|
|
((), None, False),
|
|
((True,), 0, True),
|
|
((False, False, False), 0, True), # down for every check we have
|
|
((True, True, False, False), 2, False), # went down at the third check
|
|
((False, True, True, False), 3, False),
|
|
])
|
|
def test_streak_start(ups, since, at_least):
|
|
checks = _checks(*ups)
|
|
assert streak_start(checks) == ((checks[since].checked_at if since is not None else None), at_least)
|
|
|
|
|
|
async def _rows(app, entries, alerts):
|
|
async with app.test_request_context("/status/rows"):
|
|
return await render_template(
|
|
"status/rows.html", entries=entries, alerts=alerts,
|
|
problems=[e for e in entries if e.status == "down"],
|
|
up=sum(e.status == "up" for e in entries), down=sum(e.status == "down" for e in entries), pending=0)
|
|
|
|
|
|
async def test_the_problems_come_first_and_say_since_when(app):
|
|
now = datetime.now(timezone.utc)
|
|
entries = [
|
|
StatusEntry(kind="http", key="1", name="shop-api", target="https://shop/x", status="down",
|
|
since=now - timedelta(minutes=12), uptime={"24h": 93.0}, tls_days=2.0),
|
|
StatusEntry(kind="icmp", key="2", name="nas", target="10.0.0.5", status="up",
|
|
since=now - timedelta(days=3), since_at_least=True, uptime={"24h": 100.0}),
|
|
]
|
|
state = SimpleNamespace(state=SimpleNamespace(value="firing"), no_data_since=None,
|
|
last_transition_at=now - timedelta(minutes=4))
|
|
rule = SimpleNamespace(id="r1", name="CPU high", resource_name="web01", metric_name="cpu_pct",
|
|
operator=SimpleNamespace(value=">"), threshold=90)
|
|
page = await _rows(app, entries, [(state, rule)])
|
|
|
|
attention = page.index("Needs attention")
|
|
assert attention < page.index("Recent checks") # before the full list
|
|
problem_card = page[attention:page.index("</section>")]
|
|
assert "shop-api" in problem_card and "nas" not in problem_card
|
|
assert "down since <time" in problem_card and ">12m ago</time>" in problem_card
|
|
assert "CPU high" in problem_card and "web01 CPU > 90%" in problem_card and ">4m ago</time>" in problem_card
|
|
assert '<span class="badge badge-crit">Firing</span>' in problem_card
|
|
# Uptime and TLS coloured by Settings → Thresholds, not by literals.
|
|
assert '<span class="tone-crit">93.00%</span>' in page and '<span class="tone-ok">100.00%</span>' in page
|
|
assert 'class="tone-crit" title="TLS certificate expires in 2 days">2d' in page
|
|
assert not hex_colours(page), hex_colours(page)
|
|
|
|
|
|
async def test_a_quiet_board_has_no_problem_card(app):
|
|
entries = [StatusEntry(kind="icmp", key="2", name="nas", target="10.0.0.5", status="up")]
|
|
page = await _rows(app, entries, [])
|
|
assert "Needs attention" not in page and "nas" in page
|
|
assert "No monitors yet" in await _rows(app, [], [])
|