Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
84 lines
3.1 KiB
Python
84 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Generate seed/logs/service.log (and hidden/evidence.json) by replaying a scripted incident through the seed code.
|
|
|
|
Run from anywhere: python3 gen_log.py
|
|
|
|
The log is the tail of a longer simulated run (about 4k jobs have already gone through when it
|
|
starts, so it begins in the middle of things): the id sequence wraps at j-fff, and four long-running
|
|
export jobs are still leased when their ids are handed out a second time. Two more incidents (a
|
|
stalled worker whose lease expires, and a job that fails three times) are unrelated red herrings.
|
|
"""
|
|
|
|
import json
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
sys.path.insert(0, os.path.join(HERE, "seed"))
|
|
|
|
from sched.sim import Sim, SimConfig # noqa: E402
|
|
|
|
LOG_FROM = 3796 # job number at which the excerpt starts (300 jobs before the id sequence wraps)
|
|
JOBS = LOG_FROM + 1500
|
|
|
|
|
|
def config():
|
|
return SimConfig(
|
|
jobs=JOBS,
|
|
seed=7,
|
|
workers=6,
|
|
slow_workers=3,
|
|
rate=1.8,
|
|
# exports that are already running when the excerpt starts: job number -> duration in seconds
|
|
planted={20: 2233.8, 163: 3300.0, 640: 2271.24},
|
|
stalls={4500: (0.5, 150.0)}, # a frozen worker: no heartbeat for 150 s
|
|
fail_plan={4350: 99}, # a job whose upstream keeps failing
|
|
keep_log=True,
|
|
log_from=LOG_FROM,
|
|
)
|
|
|
|
|
|
def main():
|
|
sim = Sim(config())
|
|
sim.run()
|
|
lines = sim.log.lines
|
|
out = os.path.join(HERE, "seed", "logs", "service.log")
|
|
os.makedirs(os.path.dirname(out), exist_ok=True)
|
|
with open(out, "w", newline="\n") as fh:
|
|
fh.write("\n".join(lines) + "\n")
|
|
|
|
def find(pattern, start=0):
|
|
rx = re.compile(pattern)
|
|
return [i for i, l in enumerate(lines, 1) if i > start and rx.search(l)]
|
|
|
|
key = {}
|
|
key["wrap_last"] = find(r"accepted job=j-fff ")[0]
|
|
key["wrap_first"] = find(r"accepted job=j-000 ")[0]
|
|
reused = {}
|
|
for jid in ("j-014", "j-0a3", "j-280", "j-3c7"):
|
|
accepted = find(r"accepted job=%s kind=(?!export)" % jid)
|
|
assert len(accepted) == 1, (jid, accepted)
|
|
symptom = find(r"job %s vanished|ack for unknown job %s|claim of unknown job %s" % (jid, jid, jid), accepted[0])
|
|
assert symptom, jid
|
|
reused[jid] = {"accepted": accepted[0], "symptom": symptom}
|
|
key["reused"] = reused
|
|
key["dedupe_swallow"] = [i for i in find(r"dedupe hit key=k-d3f091db") if i > reused["j-014"]["accepted"]]
|
|
key["ack_attempts0"] = find(r"ack job=j-014 worker=w4 attempts=0")
|
|
key["claim_dropped"] = find(r"claim of unknown job j-014")
|
|
key["ack_unknown"] = find(r"ack for unknown job j-280")
|
|
key["vanished"] = find(r"vanished: lease expired while running")
|
|
key["red_herrings"] = {
|
|
"lease_expired": find(r"lease expired job=j-194"),
|
|
"dead": find(r"dead after 3 attempts"),
|
|
}
|
|
with open(os.path.join(HERE, "hidden", "evidence.json"), "w", newline="\n") as fh:
|
|
json.dump(key, fh, indent=1, sort_keys=True)
|
|
size = os.path.getsize(out)
|
|
print("%d lines, %d bytes" % (len(lines), size))
|
|
print(json.dumps(key, sort_keys=True))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|