#5212 "Plain labels: no raw ids, scopes, metric keys or unexplained jargon", batch 3: - Disk page: each tile says what it holds. "Writable layers" becomes "Container files" and Build cache says it is safe to clear. Shared is "Shared with other images" with a tooltip, and "dangling" is gone. Untagged images show by id instead of "<none>", a capped list says "The 50 largest of N images", and each host shows "as of" its report. - Traefik: an expired certificate reads "expired 12 days ago", not "-12 days" (cert_left). The Traffic empty state knows whether the access log is on: off points to Settings → Plugins → Traefik; on says to check the mounted log path. - Moments use |ago with an exact UTC tooltip: UniFi last seen, alarms, events, speed test and DPI; AI token last used. - Settings: the Auth tab is "Authentication" like its breadcrumb, plugin fields read "Metrics URL" not metrics_url (field_label), a source's pull interval is "every 1h", and the last report time drops the ISO "T". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
113 lines
5.5 KiB
Python
113 lines
5.5 KiB
Python
"""The Traefik page puts failing and slow routers first and folds the healthy
|
|
ones into one table; certificates are graded by Settings → Thresholds (#5126)."""
|
|
from datetime import datetime, timedelta, timezone
|
|
from types import SimpleNamespace as NS
|
|
|
|
import pytest
|
|
|
|
from plugins.traefik.routes import gone_routers, router_state, split_routers
|
|
from steward.core.settings import to_thresholds_cfg
|
|
from tests._templates import render_plugin_template
|
|
from tests.test_style_tokens import hex_colours
|
|
|
|
TH = to_thresholds_cfg({}) # latency crit 200 ms
|
|
|
|
|
|
def _latest(req=1.0, p95=20.0, e4=0.0, e5=0.0):
|
|
return NS(request_rate=req, response_bytes_rate=1000.0, latency_p95_ms=p95, latency_p99_ms=p95 * 1.5,
|
|
error_rate_4xx_pct=e4, error_rate_5xx_pct=e5,
|
|
scraped_at=datetime.now(timezone.utc) - timedelta(seconds=30))
|
|
|
|
|
|
@pytest.mark.parametrize("latest, grade", [
|
|
(_latest(), "ok"),
|
|
(_latest(e5=2.5), "crit"),
|
|
(_latest(p95=450.0), "warn"),
|
|
(_latest(e4=5.0), "warn"),
|
|
(_latest(p95=120.0, e4=0.5), "ok"), # slow-ish but under the critical cutoff
|
|
])
|
|
def test_router_state(latest, grade):
|
|
assert router_state(latest, TH)[0] == grade
|
|
|
|
|
|
def _router(name, latest):
|
|
state, why = router_state(latest, TH)
|
|
return {"name": name, "latest": latest, "state": state, "why": why,
|
|
"sparkline_req": "", "sparkline_p95": "", "sparkline_5xx": ""}
|
|
|
|
|
|
def test_failing_routers_come_before_slow_ones_and_healthy_ones_split_off():
|
|
problems, healthy = split_routers([
|
|
_router("b-ok", _latest()), _router("slow", _latest(p95=450.0)),
|
|
_router("broken", _latest(e5=3.0)), _router("a-ok", _latest())])
|
|
assert [r["name"] for r in problems] == ["broken", "slow"]
|
|
assert [r["name"] for r in healthy] == ["a-ok", "b-ok"]
|
|
|
|
|
|
async def test_the_page_leads_with_problems_and_folds_the_healthy(app):
|
|
problems, healthy = split_routers([
|
|
_router("api", _latest(e5=3.0)), _router("web", _latest()), _router("docs", _latest())])
|
|
now = datetime.now(timezone.utc)
|
|
certs = [{"serial": "1", "cn": "soon.example", "sans": [], "not_after": now + timedelta(days=2),
|
|
"days_remaining": 2.0},
|
|
{"serial": "2", "cn": "fine.example", "sans": [], "not_after": now + timedelta(days=60),
|
|
"days_remaining": 60.0}]
|
|
async with app.test_request_context("/plugins/traefik/rows"):
|
|
page = await render_plugin_template(app, "traefik", "traefik/rows.html", problems=problems,
|
|
healthy=healthy, global_stat=None, certs=certs, range_key="24h",
|
|
error_4xx=1.0, error_5xx=0.1)
|
|
|
|
assert page.index(">api</h3>") < page.index('id="traefik-healthy"')
|
|
assert "3.0% of responses are 5xx" in page
|
|
assert ">2 healthy routers</summary>" in page
|
|
assert page.index(">docs</td>") < page.index(">web</td>")
|
|
assert 'class="tone-crit">2 days</td>' in page and 'class="tone-ok">60 days</td>' in page
|
|
assert "font-weight:600" not in page and not hex_colours(page), hex_colours(page)
|
|
|
|
|
|
def test_a_router_traefik_stopped_reporting_is_set_apart_not_failing():
|
|
live = _router("api", _latest())
|
|
removed = _router("old", _latest(e5=9.0))
|
|
removed["latest"].scraped_at = live["latest"].scraped_at - timedelta(minutes=10)
|
|
recent = _router("blip", _latest())
|
|
recent["latest"].scraped_at = live["latest"].scraped_at - timedelta(seconds=60)
|
|
current, gone = gone_routers([live, removed, recent], 30) # 3 scrapes = 90 s
|
|
assert [r["name"] for r in current] == ["api", "blip"]
|
|
assert [r["name"] for r in gone] == ["old"]
|
|
assert gone_routers([], 30) == ([], [])
|
|
|
|
|
|
async def test_gone_routers_are_listed_by_when_they_were_last_seen(app):
|
|
removed = _router("old", _latest(e5=9.0))
|
|
removed["latest"].scraped_at = datetime.now(timezone.utc) - timedelta(hours=2)
|
|
async with app.test_request_context("/plugins/traefik/rows"):
|
|
page = await render_plugin_template(app, "traefik", "traefik/rows.html", problems=[], healthy=[],
|
|
gone=[removed], global_stat=None, certs=[], range_key="24h",
|
|
error_4xx=1.0, error_5xx=0.1)
|
|
page = " ".join(page.split())
|
|
assert "1 router no longer reported</summary>" in page
|
|
assert "old</span> <span class=\"problem-detail\">last seen <time" in page and ">2h ago</time>" in page
|
|
assert "Failing" not in page
|
|
|
|
|
|
@pytest.mark.parametrize("days, says", [
|
|
(12.7, "12 days"), (1.2, "1 day"), (0.4, "expires today"),
|
|
(-0.3, "expired today"), (-1.5, "expired 1 day ago"), (-12.0, "expired 12 days ago"), (None, "—"),
|
|
])
|
|
def test_a_certificate_past_its_date_says_expired(days, says):
|
|
"""#5212: "expired 12 days ago", never "-12 days"."""
|
|
from steward.core.formatting import cert_left
|
|
assert cert_left(days) == says
|
|
|
|
|
|
@pytest.mark.parametrize("enabled, says, not_says", [
|
|
(False, "The access log is off", "No requests in the last"),
|
|
(True, "No requests in the last 24h", "The access log is off"),
|
|
])
|
|
async def test_the_traffic_empty_state_knows_whether_the_log_is_on(app, enabled, says, not_says):
|
|
async with app.test_request_context("/plugins/traefik/traffic"):
|
|
page = await render_plugin_template(app, "traefik", "traefik/traffic.html", summary=None, history=[],
|
|
range_key="24h", access_log_enabled=enabled,
|
|
access_log_path="/var/log/traefik/access.log")
|
|
assert says in page and not_says not in page
|