"swarm services short on swarm is 6." becomes "6 swarm services are short of their replicas.", with a Which line naming each service and how many of its tasks run. The swarm figures get labels, and the counting figures (swarm, mounts, drives, updates) read as sentences in the email, its subject and the Alerts page. A plugin names what its count counts through core.alerts.names_behind; the Docker plugin does for the three swarm figures, from the stored swarm. Webhooks get alert.which too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
26 lines
1.0 KiB
Python
26 lines
1.0 KiB
Python
"""A figure that counts things names what it counts in the alert about it
|
|
(#6400): the plugin recording it registers how, and a lookup that fails
|
|
leaves the alert to go out without names."""
|
|
from steward.core import alerts
|
|
|
|
|
|
async def test_a_registered_count_is_named_and_others_are_not(monkeypatch):
|
|
monkeypatch.setattr(alerts, "_NAMED", {})
|
|
|
|
async def short(session, resource):
|
|
return [f"{resource}: api (0 of 1 running)"]
|
|
|
|
alerts.names_behind("docker", "swarm_services_short", short)
|
|
assert await alerts.which(None, "docker", "swarm_services_short", "swarm") == ["swarm: api (0 of 1 running)"]
|
|
assert await alerts.which(None, "host_agent", "cpu_pct", "web-1") == []
|
|
|
|
|
|
async def test_a_lookup_that_fails_names_nothing(monkeypatch):
|
|
monkeypatch.setattr(alerts, "_NAMED", {})
|
|
|
|
async def broken(session, resource):
|
|
raise RuntimeError("database away")
|
|
|
|
alerts.names_behind("docker", "swarm_nodes_down", broken)
|
|
assert await alerts.which(None, "docker", "swarm_nodes_down", "swarm") == []
|