'paid proxy DOWN: YouTube-URL jobs will keep failing' fired on a single ReadTimeout while the three static proxies were fine, and read as an outage. Severity now follows the actual impact: fallback down with the statics up is informational (no impact), statics down is a cost warning (jobs run on the per-GB proxy), both down is the red one. A route has to miss two probes 30 min apart before anyone is paged.
56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
"""The proxy watcher must say what is actually affected, and not page on one miss."""
|
||
import asyncio
|
||
import pytest
|
||
|
||
alerts = pytest.importorskip("cloud.alerts")
|
||
|
||
|
||
@pytest.fixture()
|
||
def sent(monkeypatch):
|
||
out = []
|
||
async def fake_send(title, body):
|
||
out.append((title, body))
|
||
monkeypatch.setattr(alerts, "send_admin_alert", fake_send)
|
||
monkeypatch.setenv("STATIC_PROXY_URLS", "http://s1,http://s2")
|
||
monkeypatch.setenv("PROXY_URL", "http://paid")
|
||
alerts._watch_down.clear(); alerts._watch_nag.clear(); alerts._watch_strikes.clear()
|
||
return out
|
||
|
||
|
||
def _fail(name, n=1):
|
||
for _ in range(n):
|
||
asyncio.run(alerts._watch_update(name, False, "ReadTimeout: x"))
|
||
|
||
|
||
def test_one_miss_is_silent(sent):
|
||
_fail(alerts._PAID_TARGET)
|
||
assert sent == []
|
||
|
||
|
||
def test_paid_down_with_statics_up_is_informational(sent):
|
||
_fail(alerts._PAID_TARGET, 2)
|
||
title, body = sent[-1]
|
||
assert title.startswith("ℹ️") and "fallback" in title
|
||
assert "No impact" in body and "static pool is UP" in body
|
||
assert "failing" not in body.split("Probe error")[0]
|
||
|
||
|
||
def test_statics_down_is_a_cost_warning(sent):
|
||
_fail(alerts._STATIC_TARGET, 2)
|
||
title, body = sent[-1]
|
||
assert title.startswith("🟠") and "costs money" in body
|
||
|
||
|
||
def test_both_down_is_red(sent):
|
||
_fail(alerts._STATIC_TARGET, 2)
|
||
_fail(alerts._PAID_TARGET, 2)
|
||
title, body = sent[-1]
|
||
assert title.startswith("🔴") and "ALL YouTube proxies" in title
|
||
|
||
|
||
def test_recovery_resets_strikes(sent):
|
||
_fail(alerts._PAID_TARGET, 2)
|
||
asyncio.run(alerts._watch_update(alerts._PAID_TARGET, True, ""))
|
||
assert sent[-1][0].startswith("✅")
|
||
_fail(alerts._PAID_TARGET, 1)
|
||
assert len(sent) == 2 # a single new miss after recovery stays quiet
|