Files
thor/tests/test_replay_t1.py
T
jaredandClaude Opus 5.5 983ba27386
CI / Lint (flake8, house style) (pull_request) Successful in 50s
CI / Test (pytest) (pull_request) Successful in 52s
CI / Security (bandit, pip-audit) (pull_request) Successful in 1m1s
CI / Integration (MariaDB) (pull_request) Successful in 1m40s
CI / Scan (secrets, workflows, shell, patterns) (pull_request) Successful in 1m15s
CI / Deploy (pull_request) Skipped
Engine, memory check, symptom checks, outbox, T1 replay
- thor/engine.py: one incident per root cause. New causes held one cycle, symptoms attached
  to the highest cause they relate to (same host, or cluster-wide effects for causes that
  can stall the cluster), priority only rises, rate-limited refresh, cleared after 15 min.
- thor/checks/memory.py: node_vmstat_oom_kill + kernel oom-kill lines; global vs cgroup,
  victim and CT, trigger cpuset; P3 / P2 (loop) / P1 (Ceph or other hosts stalling).
- thor/checks/symptoms.py: scrape timeouts, pvestatd timeouts, Ceph alerts switching on.
- thor/outbox.py: live actions to Tinker with backoff; shadow actions are only recorded.
- Migration 2: incidents, actions, observations.
- PromQL/LogQL regex escaping fixed (found by recording against the real Prometheus).
- tests/replay.py + tests/fixtures/t1.json: 2026-11-23 replayed through the real monitor:
  exactly one ticket (P1 from the start: pvestatd timed out on three other hosts with the
  first kill), 15 symptoms as Also seen, cleared 06:18, Loki's 06:00 outage delays only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 23:02:10 -05:00

83 lines
3.3 KiB
Python

"""T1, the reference incident (thor#1): 2026-11-23 OOM loop on compute-storage-01 (CT 154).
Right outcome: exactly one ticket, for the out-of-memory host, naming CT 154; the Ceph alerts,
pvestatd timeouts and scrape timeouts on other hosts are "Also seen" on it, not tickets of
their own (Gandalf's false P1 network ticket, Tinker 615797777, is what this replaces).
"""
from datetime import datetime, timezone
import pytest
from .replay import Replay
KEY = 'host:compute-storage-01:oom'
def hm(ts: float) -> str:
return datetime.fromtimestamp(ts, tz=timezone.utc).strftime('%H:%M')
@pytest.fixture(scope='module')
def t1():
return Replay('t1').run()
def test_exactly_one_ticket_for_the_oom_host(t1):
opened = t1.opened()
assert len(opened) == 1, [a['payload']['title'] for a in opened]
a = opened[0]
assert a['incident_key'] == KEY
assert a['mode'] == 'shadow' and a['status'] == 'shadow' # nothing is sent in phase 1
p = a['payload']
assert p['dedup_key'] == KEY
assert p['title'].startswith('[compute-storage-01][auto][thor][software] Out of memory: CT 154 pelican-wings-02')
assert p['title'].endswith('[single-node][production][issue]')
# Opened soon after the first kill (05:11:30 by the counter), after one cycle's hold.
assert '05:12' <= hm(a['created']) <= '05:17'
def test_no_other_incident_becomes_a_ticket(t1):
assert set(t1.store.incidents) == {KEY}
assert {a['incident_key'] for a in t1.actions()} == {KEY}
def test_counts_all_eleven_kills_of_ct_154(t1):
inc = t1.store.incidents[KEY]
assert len(inc['events']) == 11
assert all(e['guest'] == '154' for e in inc['events'])
assert inc['summary'] == 'Out of memory: CT 154 pelican-wings-02 java OOM-killed 11 times'
def test_opens_at_p1_because_the_cluster_stalled_with_the_first_kill(t1):
"""pvestatd timed out on three other hosts at 05:11:03 (never on normal days) as the first
kill landed at 05:11:08: other hosts stalling means P1 from the start (operator decision,
2026-11-25; the thor#1 table had guessed P3 rising to P1 at 06:01)."""
opened = t1.opened()[0]
assert opened['payload']['priority'] == 1
assert 'pvestatd' in opened['payload']['description']
assert not t1.actions('escalate') # nothing higher to go to
def test_symptoms_on_other_hosts_are_also_seen_not_tickets(t1):
symptoms = t1.store.incidents[KEY]['symptoms']
kinds = {(s['kind'], s['subject']) for s in symptoms.values()}
assert ('scrape', 'compute-storage-02') in kinds
assert ('scrape', 'storage-01') in kinds
assert ('pvestatd', 'monitor-01') in kinds
assert any(k == 'ceph_alert' for k, _ in kinds)
assert t1.actions('also_seen'), 'symptoms after the ticket opened are added as comments'
def test_clears_fifteen_minutes_after_the_last_kill(t1):
cleared = t1.actions('cleared')
assert len(cleared) == 1
# Last kill 06:01:27 (counter 06:02:00): cleared 15 minutes later, within a cycle or two.
assert '06:16' <= hm(cleared[0]['created']) <= '06:21'
assert t1.store.incidents[KEY]['state'] == 'cleared'
def test_loki_outage_at_06_00_delays_but_loses_nothing(t1):
held = [r for r in t1.results if not r.ok]
assert held, 'the recorded Loki 500s should hold at least one window'
assert all('loki' in r.error for r in held)