WAN: ticket sustained slowdowns; reboot drops no longer mean "unstable"
Lint / JS (eslint) (push) Successful in 11s
Lint / Python (flake8) (push) Successful in 1m28s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 1m38s
Lint / Python (flake8) (pull_request) Successful in 57s
Test / Python Tests (pytest) (push) Successful in 1m20s
Lint / JS (eslint) (pull_request) Successful in 17s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 2m54s
Test / Python Tests (pytest) (pull_request) Successful in 3m9s
Lint / JS (eslint) (push) Successful in 11s
Lint / Python (flake8) (push) Successful in 1m28s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 1m38s
Lint / Python (flake8) (pull_request) Successful in 57s
Test / Python Tests (pytest) (push) Successful in 1m20s
Lint / JS (eslint) (pull_request) Successful in 17s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 2m54s
Test / Python Tests (pytest) (pull_request) Successful in 3m9s
On 2026-11-23/24 the WAN was degraded for about 20 hours with no ticket, and the only ticket came from the owner's reboot fixing it. - wan_degraded (P2): half or more of the last 2 hours of UniFi WAN health periods slow, lossy or down. Closes with a recovery note once the last 2 hours are at most a quarter bad. Mentions a slow ping from the modem. - "WAN connection unstable" waits 10 minutes, then counts only drops that no modem restart explains (Smart Power, uptime reset, or the Restart modem button, folded into one restart when within 15 minutes). - Both list the last 7 days of restarts and how long each lasted, and suggest asking AT&T for a replacement after 2+ restarts in a week. Closes #58 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bba483bb05
commit
a31437f2e5
5 files changed
+346
-17
No files matched your search
@@ -558,3 +558,56 @@ class TestModemRestart:
|
||||
a.session.post = MagicMock(return_value=MagicMock(status_code=200, text=LOGIN_FORM))
|
||||
with pytest.raises(modem.ModemDataInvalid, match='not started'):
|
||||
a.restart()
|
||||
|
||||
|
||||
class TestRestartEpisodes:
|
||||
def test_reboot_then_smart_power_is_one_restart(self):
|
||||
h = {'restarts': [{'at': 1000, 'by': None}, {'at': 1200, 'by': 'RPDU'}, {'at': 1590, 'by': 'RPDU'}]}
|
||||
assert modem.restart_episodes(h, None, 0) == [{'at': 1000, 'by': 'smart power'}]
|
||||
|
||||
def test_gandalf_button_names_the_restart(self):
|
||||
h = {'restarts': [{'at': 1100, 'by': 'RPDU'}]}
|
||||
assert modem.restart_episodes(h, {'at': 1000}, 0) == [{'at': 1000, 'by': 'gandalf'}]
|
||||
|
||||
def test_separate_days_are_separate_restarts(self):
|
||||
h = {'restarts': [{'at': 1000, 'by': None}, {'at': 1000 + 86400, 'by': None}]}
|
||||
assert len(modem.restart_episodes(h, None, 0)) == 2
|
||||
|
||||
def test_older_than_since_is_left_out(self):
|
||||
assert modem.restart_episodes({'restarts': [{'at': 10, 'by': None}]}, None, 100) == []
|
||||
|
||||
def test_unexplained_drops(self):
|
||||
eps = [{'at': 1000, 'by': 'outside'}]
|
||||
outs = [{'failed_at': 800}, {'failed_at': 1800}, {'failed_at': 5000}, {'failed_at': 50}]
|
||||
assert modem.unexplained_drops(outs, eps, 100) == [{'failed_at': 5000}]
|
||||
|
||||
def test_lines_and_hint(self):
|
||||
eps = [{'at': 0, 'by': 'gandalf'}, {'at': 3 * 86400 + 4 * 3600, 'by': 'outside'}]
|
||||
lines = modem.restart_lines(eps, 3 * 86400 + 5 * 3600)
|
||||
assert lines[0].endswith("Gandalf's Restart modem button, next restart 3 d 4 h later")
|
||||
assert lines[1].endswith('restarted outside Gandalf (AT&T app, modem button or power), 1 h 0 min ago')
|
||||
assert 'replacement BGW320' in modem.replacement_hint(eps)
|
||||
assert modem.replacement_hint(eps[:1]) == ''
|
||||
|
||||
|
||||
class TestDegradation:
|
||||
def periods(self, states, end=10000.0):
|
||||
return [{'ts': end - (len(states) - 1 - i) * 300, 'state': s} for i, s in enumerate(states)]
|
||||
|
||||
def test_half_of_two_hours_is_degraded(self):
|
||||
d = modem.degradation(self.periods(['ok'] * 12 + ['loss'] * 12), 10000.0)
|
||||
assert d['bad'] == 12 and d['total'] == 24 and d['loss'] == 12
|
||||
|
||||
def test_under_half_is_not(self):
|
||||
assert modem.degradation(self.periods(['ok'] * 13 + ['loss'] * 11), 10000.0) is None
|
||||
|
||||
def test_needs_an_hour_of_data(self):
|
||||
assert modem.degradation(self.periods(['loss'] * 6), 10000.0) is None
|
||||
|
||||
def test_window_ignores_older_periods(self):
|
||||
assert modem.degradation(self.periods(['loss'] * 30 + ['ok'] * 24), 10000.0 + 0) is None
|
||||
|
||||
def test_recovered(self):
|
||||
assert modem.recovered(self.periods(['loss'] * 12 + ['ok'] * 18 + ['latency'] * 6), 10000.0)
|
||||
assert modem.recovered(self.periods(['loss'] * 6 + ['ok'] * 18), 10000.0) # exactly a quarter
|
||||
assert not modem.recovered(self.periods(['latency'] * 7 + ['ok'] * 17), 10000.0)
|
||||
+91
-1
@@ -475,13 +475,62 @@ class TestWanLog:
|
||||
mon._process_wan_log([])
|
||||
assert not mon.tickets.create.called
|
||||
|
||||
def test_unstable_wan_tickets_after_a_day(self, mon, db):
|
||||
def test_unstable_wan_waits_before_deciding(self, mon, db):
|
||||
now = time.time()
|
||||
self._state(db, unifi_log_cursor=str(int(now * 1000)))
|
||||
self._mon(mon, [{'key': modem_api.LOG_WAN_UNSTABLE, 'ts': now, 'device': 'UDM', 'wan': 'WAN1'}])
|
||||
mon._process_wan_log([])
|
||||
assert not mon.tickets.create.called
|
||||
saved = dict((c.args[0], c.args[1]) for c in db.set_state.call_args_list)
|
||||
assert saved['wan_history']['unstable_pending_at'] >= now
|
||||
|
||||
def _decide(self, mon, db, outages, restarts, button=None, pending_age=700):
|
||||
now = time.time()
|
||||
history = {'outages': outages, 'restarts': restarts, 'unstable_pending_at': now - pending_age}
|
||||
self._state(db, wan_history=json.dumps(history),
|
||||
modem_restart=json.dumps(button) if button else None)
|
||||
mon._decide_unstable([])
|
||||
return now
|
||||
|
||||
def test_drops_with_no_restart_ticket_after_the_wait(self, mon, db):
|
||||
now = time.time()
|
||||
self._decide(mon, db, [{'failed_at': now - 5000}, {'failed_at': now - 900}], [])
|
||||
assert 'unstable' in mon.tickets.create.call_args.args[0]
|
||||
|
||||
def test_not_decided_before_the_wait(self, mon, db):
|
||||
now = time.time()
|
||||
self._decide(mon, db, [{'failed_at': now - 5000}, {'failed_at': now - 900}], [], pending_age=60)
|
||||
assert not mon.tickets.create.called
|
||||
|
||||
def test_reboot_drops_alone_open_no_ticket(self, mon, db):
|
||||
# 2026-11-24: an AT&T-app reboot, Smart Power cycling it twice, two short drops
|
||||
now = time.time()
|
||||
boot = now - 1500
|
||||
self._decide(mon, db,
|
||||
[{'failed_at': boot + 180}, {'failed_at': boot + 600}],
|
||||
[{'at': boot, 'by': 'RPDU', 'confirmed': True},
|
||||
{'at': boot + 386, 'by': 'RPDU', 'confirmed': False}])
|
||||
assert not mon.tickets.create.called
|
||||
saved = dict((c.args[0], c.args[1]) for c in db.set_state.call_args_list)
|
||||
assert 'unstable_pending_at' not in saved['wan_history']
|
||||
|
||||
def test_restart_by_gandalf_button_explains_its_drop(self, mon, db):
|
||||
now = time.time()
|
||||
self._decide(mon, db, [{'failed_at': now - 1200}, {'failed_at': now - 50000}], [],
|
||||
button={'at': now - 1300})
|
||||
assert not mon.tickets.create.called
|
||||
|
||||
def test_ticket_lists_restarts_and_suggests_replacement(self, mon, db):
|
||||
now = time.time()
|
||||
self._decide(mon, db,
|
||||
[{'failed_at': now - 20000}, {'failed_at': now - 10000}, {'failed_at': now - 900}],
|
||||
[{'at': now - 3 * 86400, 'by': None, 'confirmed': True},
|
||||
{'at': now - 1200 - 2 * 86400, 'by': 'RPDU', 'confirmed': True}])
|
||||
desc = mon.tickets.create.call_args.args[1]
|
||||
assert 'Modem restarts in the last 7 days' in desc
|
||||
assert 'restarted outside Gandalf' in desc and 'Smart Power power-cycled it' in desc
|
||||
assert 'replacement BGW320' in desc
|
||||
|
||||
def test_suppression_blocks_one_shot_ticket(self, mon, db):
|
||||
now = time.time()
|
||||
db.check_suppressed.return_value = True
|
||||
@@ -1157,6 +1206,47 @@ class TestWanQualityCollection:
|
||||
assert c.get_wan_dashboard() is None
|
||||
|
||||
|
||||
def _timeline(states, end=100000.0):
|
||||
"""WAN quality periods ending at *end*, one per state, 5 minutes apart."""
|
||||
return {'periods': [{'ts': end - (len(states) - 1 - i) * 300, 'state': s} for i, s in enumerate(states)]}
|
||||
|
||||
|
||||
class TestWanDegraded:
|
||||
"""2026-11-23/24: about 20 hours of latency and loss with no ticket (gandalf#58)."""
|
||||
|
||||
def test_two_bad_hours_open_a_ticket(self, mon, db):
|
||||
mon._process_wan_degraded(_timeline(['latency'] * 14 + ['ok'] * 6 + ['loss'] * 4), [])
|
||||
assert ('wan_degraded', 'att-modem', '') in upserted(db)
|
||||
title, desc = mon.tickets.create.call_args.args[:2]
|
||||
assert 'Internet degraded' in title
|
||||
assert '18 of 24 five-minute periods had 14 latency, 4 loss' in desc
|
||||
assert 'Restart modem' in desc
|
||||
|
||||
def test_odd_slow_periods_do_nothing(self, mon, db):
|
||||
mon._process_wan_degraded(_timeline(['ok'] * 20 + ['latency'] * 4), [])
|
||||
assert not db.upsert_event.called
|
||||
assert not mon.tickets.create.called
|
||||
|
||||
def test_mostly_fine_hour_resolves(self, mon, db):
|
||||
mon._process_wan_degraded(_timeline(['latency'] * 12 + ['ok'] * 20 + ['latency'] * 4), [])
|
||||
db.resolve_event.assert_called_with('wan_degraded', 'att-modem', '')
|
||||
|
||||
def test_in_between_leaves_it_open(self, mon, db):
|
||||
# 9 of the last 24 bad: under half, but over a quarter, so no change either way
|
||||
mon._process_wan_degraded(_timeline(['ok'] * 15 + ['latency'] * 9), [])
|
||||
assert not db.upsert_event.called and not db.resolve_event.called
|
||||
|
||||
def test_no_timeline_leaves_it_alone(self, mon, db):
|
||||
mon._process_wan_degraded(None, [])
|
||||
assert not db.upsert_event.called and not db.resolve_event.called
|
||||
|
||||
def test_slow_ping_from_the_modem_is_mentioned(self, mon, db):
|
||||
checks = json.dumps({'ping': {'verdict': 'gateway', 'avg_ms': 1154}})
|
||||
db.get_state.side_effect = lambda k, d=None: checks if k == 'modem_checks' else None
|
||||
mon._process_wan_degraded(_timeline(['loss'] * 24), [])
|
||||
assert 'ping from the modem itself was slow too (avg 1154 ms)' in mon.tickets.create.call_args.args[1]
|
||||
|
||||
|
||||
class TestModemChecks:
|
||||
NOW = 1_000_000.0
|
||||
|
||||
|
||||
Reference in new issue
Block a user