"""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)