feat(ui): shared |bytes |rate |duration |ago filters and status_class from Settings → Thresholds (#5093)
#5093 "Shared format filters and status_class driven by Settings → Thresholds". - steward/core/formatting.py: human_bytes (binary units), human_rate, human_duration (two largest units), ago (a <time> titled with the absolute UTC time) and status_class(value, kind, thresholds) -> ok/warn/crit/unknown, which raises on a kind the thresholds don't name. - app.py registers them as the bytes, rate, duration and ago filters and the status_class global; threshold_style is now graded by status_class (and caps its weight at 500). - Replaces the copies: docker's _human_bytes/_human_uptime, core alerts' _duration, the host-agent fmt_bps/fmt_bytes macros, the Traefik and UniFi byte-rate arithmetic, the swarm-failures ago macro and two uptime spans. - Tests: a table per helper, and every template compiled against the app's filters, so an unknown filter fails CI rather than a page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -41,21 +41,9 @@ def test_container_log_views_defined():
|
||||
assert callable(r.container_logs_lines)
|
||||
|
||||
|
||||
def test_human_bytes_formats_binary_units():
|
||||
assert r._human_bytes(None) == "—"
|
||||
assert r._human_bytes(0) == "0 B"
|
||||
assert r._human_bytes(512) == "512 B"
|
||||
assert r._human_bytes(1024) == "1.0 KiB"
|
||||
assert r._human_bytes(1536) == "1.5 KiB"
|
||||
assert r._human_bytes(1024 ** 2) == "1.0 MiB"
|
||||
assert r._human_bytes(int(1.5 * 1024 ** 3)) == "1.5 GiB"
|
||||
assert r._human_bytes(1024 ** 4) == "1.0 TiB"
|
||||
|
||||
|
||||
def test_human_uptime_compact():
|
||||
def test_uptime_is_the_shared_duration_or_none():
|
||||
from datetime import datetime, timedelta, timezone
|
||||
now = datetime.now(timezone.utc)
|
||||
assert r._human_uptime(None) is None
|
||||
assert r._human_uptime(now - timedelta(minutes=8)).endswith("m")
|
||||
assert "h" in r._human_uptime(now - timedelta(hours=5, minutes=12))
|
||||
assert "d" in r._human_uptime(now - timedelta(days=3, hours=4))
|
||||
assert r._uptime(None) is None
|
||||
assert r._uptime(now + timedelta(minutes=5)) is None # clock skew: not "-5m"
|
||||
assert r._uptime(now - timedelta(days=3, hours=4, seconds=30)) == "3d 4h"
|
||||
|
||||
Reference in New Issue
Block a user