Run the level 4 scenarios with one command
make level4 runs the level 3 and level 4 scenarios of the pipeline suite and the invariants into evidence/level4.json. New scenarios: worker_limits (a 40 Mpx render under a 0.5 s timeout and a 200 MiB address space fails with processing_failed while the worker keeps running, then succeeds with the default limits under the container limit), retry_backoff_jitter (delays from the job journal stay within [d/2, d] and differ) and failed_retention (failed staging is kept, removed after the retention, then replay answers expired). The stalled holder must be fenced and the republished copy must be a no-op. The faults override passes the stall, render limits and retention through; the admin CLI is python -m messenger.admin. make failed, make replay ID=... and make dlq are the operator entry points; the lab 4 target becomes lab4-level4. CI runs level4 instead of level3. The registry prints ISO timestamps. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
b568fcf9c9
commit
b9d28d190e
+8
-1
@@ -3,6 +3,12 @@ set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
COMPOSE=${COMPOSE:-docker compose}
|
||||
service=${BROKER_SERVICE:-broker}
|
||||
dlq() {
|
||||
$COMPOSE exec -T "$service" sh -c 'RABBITMQADMIN_USERNAME=messenger-ops \
|
||||
RABBITMQADMIN_PASSWORD="$(cat /run/secrets/rabbitmq_ops_password)" \
|
||||
exec rabbitmqadmin --non-interactive -V messenger get messages \
|
||||
-q attachments.process.dlq -c "$1" -a ack_requeue_true' sh "${1:-10}"
|
||||
}
|
||||
queues() {
|
||||
$COMPOSE exec -T "$service" rabbitmqctl -q list_queues -p messenger \
|
||||
name type messages_ready messages_unacknowledged consumers
|
||||
@@ -10,5 +16,6 @@ queues() {
|
||||
case "${1:-}" in
|
||||
restart) $COMPOSE restart -t 20 "$service" && $COMPOSE up -d --no-deps --no-recreate --wait --wait-timeout 90 "$service" ;;
|
||||
queues) queues ;;
|
||||
*) echo "usage: $0 restart|queues" >&2; exit 2 ;;
|
||||
dlq) dlq "${2:-10}" ;;
|
||||
*) echo "usage: $0 restart|queues|dlq [count]" >&2; exit 2 ;;
|
||||
esac
|
||||
|
||||
@@ -22,6 +22,7 @@ from client import Client, Failure, check
|
||||
from image_probe import jpeg_size
|
||||
|
||||
FIXTURE = ROOT / "tests/fixtures/sample.png"
|
||||
HEAVY = "png-at-pixel-limit-8000x5000.png"
|
||||
EXCHANGE, ROUTING_KEY = "attachments", "attachment.process.v1"
|
||||
QUEUE, DLQ = "attachments.process", "attachments.process.dlq"
|
||||
RABBITMQADMIN = (
|
||||
@@ -45,6 +46,9 @@ SCENARIOS = (
|
||||
("lease_expiry_fencing", 4, "stalled worker, lease expiry"),
|
||||
("replay_failed", 4, "operator replay"),
|
||||
("malformed_message_dead_lettered", 4, "message that is not a job goes to the DLQ"),
|
||||
("worker_limits", 4, "render time and memory limits, 40 Mpx in the worker limit"),
|
||||
("retry_backoff_jitter", 4, "backoff with equal jitter between attempts"),
|
||||
("failed_retention", 4, "failed staging kept until retention, then replay expires"),
|
||||
("crash_before_side_effect", 5, "after claim, before side effects"),
|
||||
("worker_kill_mid_task", 5, "SIGKILL during processing"),
|
||||
("duplicate_in_flight", 5, "two copies of one job in flight"),
|
||||
@@ -71,6 +75,10 @@ variants:
|
||||
events:
|
||||
SELECT kind, attempt FROM job_events WHERE attachment_id = :'id' ORDER BY id
|
||||
|
||||
backoff:
|
||||
SELECT attempt, (detail->>'delay_seconds')::float8 AS delay FROM job_events
|
||||
WHERE attachment_id = :'id' AND kind = 'retry_scheduled' ORDER BY id
|
||||
|
||||
nonterminal:
|
||||
SELECT id, status FROM attachments
|
||||
WHERE id = ANY(:'ids'::uuid[]) AND status NOT IN ('ready', 'failed')
|
||||
@@ -183,9 +191,12 @@ class Stack:
|
||||
wait.remove("--no-recreate")
|
||||
self.dc(*wait, *services, faults=faults, env=env)
|
||||
|
||||
def launch(self, service, point=""):
|
||||
def launch(self, service, point="", **overrides):
|
||||
variable = "WORKER_FAULT_POINT" if service == self.args.worker else "RELAY_FAULT_POINT"
|
||||
self.up(service, faults=True, env={variable: point})
|
||||
self.up(service, faults=True, env={variable: point, **overrides})
|
||||
|
||||
def cgroup(self, service, name):
|
||||
return self.dc("exec", "-T", service, "cat", "/sys/fs/cgroup/" + name).strip()
|
||||
|
||||
def restore(self):
|
||||
self.dc("up", "-d", "--no-deps", "--wait", self.args.relay, self.args.worker)
|
||||
@@ -526,6 +537,73 @@ class Suite:
|
||||
self.dead_letters += 1
|
||||
return {"dead_letters": self.stack.queues()[DLQ][0] - before}
|
||||
|
||||
def limited(self, data, **overrides):
|
||||
self.stack.launch(self.args.worker, **overrides)
|
||||
att = self.api.upload(data, name=HEAVY, final=("failed",))
|
||||
failed = self.api.wait(att["id"], ("failed",), self.args.recovery_timeout)
|
||||
check(failed["error_code"] == "processing_failed", f"limit gave {failed['error_code']}")
|
||||
jobs = self.stack.sql("jobs", id=att["id"])
|
||||
check([j["attempt"] for j in jobs] == [1], "a limit breach was retried")
|
||||
state, _ = self.stack.state(self.args.worker)
|
||||
check(state == "running", "worker died on a limit breach: " + state)
|
||||
return {"attachment_id": att["id"], "error_code": failed["error_code"], "worker": state}
|
||||
|
||||
def worker_limits(self):
|
||||
folder = Path(self.args.images) / "limits"
|
||||
make_images.build(folder, True, {HEAVY})
|
||||
data = (folder / HEAVY).read_bytes()
|
||||
self.drained()
|
||||
timed = self.limited(data, FAULT_RENDER_TIMEOUT_SECONDS=str(self.args.tight_timeout))
|
||||
memory = self.limited(data, FAULT_RENDER_MEMORY_MB=str(self.args.tight_memory_mb))
|
||||
self.stack.launch(self.args.worker)
|
||||
att = self.api.upload(data, name=HEAVY)
|
||||
ready = self.api.wait(att["id"], timeout=self.args.recovery_timeout)
|
||||
sizes = {"thumbnail": [256, 160], "crop": [128, 128], "optimized": [1280, 800]}
|
||||
names = self.verify(ready, sizes)
|
||||
peak = int(self.stack.cgroup(self.args.worker, "memory.peak"))
|
||||
limit = int(self.stack.cgroup(self.args.worker, "memory.max"))
|
||||
check(peak < limit, f"worker peak {peak} reached its limit {limit}")
|
||||
return {
|
||||
"image": {"file": HEAVY, "bytes": len(data), "pixels": 8000 * 5000},
|
||||
"render_timeout": {"seconds": self.args.tight_timeout, **timed},
|
||||
"render_memory": {"mib": self.args.tight_memory_mb, **memory},
|
||||
"default_limits": {
|
||||
"attachment_id": att["id"],
|
||||
"variants": names,
|
||||
"memory_peak_mib": round(peak / 2**20, 1),
|
||||
"memory_max_mib": round(limit / 2**20, 1),
|
||||
},
|
||||
}
|
||||
|
||||
def retry_backoff_jitter(self):
|
||||
ident, jobs = self.exhaust()
|
||||
self.api.final[ident] = {"failed"}
|
||||
rows = self.stack.sql("backoff", id=ident)
|
||||
check([r["attempt"] for r in rows] == [2, 3, 4, 5], f"unexpected retries {rows}")
|
||||
shares = []
|
||||
for row in rows:
|
||||
ceiling = min(60.0, self.args.backoff_base * 2 ** (row["attempt"] - 2))
|
||||
share = row["delay"] / ceiling
|
||||
check(0.5 <= share <= 1.0, f"delay {row['delay']} outside [{ceiling / 2}, {ceiling}]")
|
||||
shares.append(round(share, 3))
|
||||
check(len(set(shares)) > 1, f"no jitter: shares {shares}")
|
||||
return {"attachment_id": ident, "delays": rows, "share_of_ceiling": shares, "jobs": jobs}
|
||||
|
||||
def failed_retention(self):
|
||||
ident, _ = self.exhaust()
|
||||
self.api.final[ident] = {"failed"}
|
||||
kept = self.record(ident)["staging_key"]
|
||||
check(kept is not None, "failed staging was removed before the retention period")
|
||||
try:
|
||||
self.stack.launch(self.args.relay, FAULT_STAGING_RETENTION_SECONDS="1")
|
||||
poll(lambda: self.record(ident)["staging_key"] is None, 30, "failed staging cleanup")
|
||||
finally:
|
||||
self.stack.launch(self.args.relay)
|
||||
replay = self.stack.admin("replay", "--attachment-id", ident)
|
||||
check(replay["result"] == "expired", f"replay after retention gave {replay}")
|
||||
check(self.api.get(ident)["status"] == "failed", "expired replay changed the status")
|
||||
return {"attachment_id": ident, "staging_before": "kept", "replay": replay}
|
||||
|
||||
def image_matrix(self):
|
||||
folder = Path(self.args.images)
|
||||
results = []
|
||||
@@ -561,9 +639,13 @@ class Suite:
|
||||
def crash_publish_confirm(self):
|
||||
def observe(ident):
|
||||
outbox = [r["published"] for r in self.stack.sql("outbox", id=ident)]
|
||||
check(outbox == [False], "outbox row was marked before the crash point")
|
||||
return {"outbox_published": outbox, "queues": self.stack.queues()}
|
||||
|
||||
return self.crash(self.args.relay, "after_publish_before_confirm", observe)
|
||||
result = self.crash(self.args.relay, "after_publish_before_confirm", observe)
|
||||
kinds = [e["kind"] for e in self.stack.sql("events", id=result["attachment_id"])]
|
||||
check("duplicate_noop" in kinds, "the republished copy was not a no-op: " + str(kinds))
|
||||
return {**result, "events": kinds}
|
||||
|
||||
def crash_after_s3_before_commit(self):
|
||||
def observe(ident):
|
||||
@@ -604,6 +686,7 @@ class Suite:
|
||||
self.stack.launch(self.args.worker)
|
||||
check(before == after, "stalled worker overwrote the result after its lease expired")
|
||||
jobs, events = self.stack.sql("jobs", id=ident), self.stack.sql("events", id=ident)
|
||||
check(any(e["kind"] == "fenced" for e in events), "stalled holder was not fenced")
|
||||
return {"attachment_id": ident, "jobs": jobs, "events": events}
|
||||
|
||||
def worker_kill_mid_task(self):
|
||||
@@ -905,7 +988,7 @@ def arguments():
|
||||
parser.add_argument("--ca-file", default=env("CA_FILE"))
|
||||
parser.add_argument("--compose", default=env("COMPOSE", "docker compose"))
|
||||
parser.add_argument("--compose-faults", default=env("COMPOSE_FAULTS", faults))
|
||||
parser.add_argument("--admin", default=env("ADMIN_CLI", "python -m messenger.worker.admin"))
|
||||
parser.add_argument("--admin", default=env("ADMIN_CLI", "python -m messenger.admin"))
|
||||
parser.add_argument("--api", nargs="+", default=env("API_SERVICES", "").split())
|
||||
parser.add_argument("--worker", default="worker")
|
||||
parser.add_argument("--relay", default="relay")
|
||||
@@ -923,6 +1006,11 @@ def arguments():
|
||||
"--stall-seconds", type=float, default=float(env("FAULT_STALL_SECONDS", "15"))
|
||||
)
|
||||
parser.add_argument("--recovery-timeout", type=float, default=120)
|
||||
parser.add_argument(
|
||||
"--backoff-base", type=float, default=float(env("FAULT_BACKOFF_BASE_SECONDS", "1"))
|
||||
)
|
||||
parser.add_argument("--tight-timeout", type=float, default=0.5, help="render seconds")
|
||||
parser.add_argument("--tight-memory-mb", type=int, default=200, help="render address space")
|
||||
parser.add_argument("--images", default=str(ROOT / "build/lab5-images"))
|
||||
parser.add_argument("--heavy", action="store_true")
|
||||
parser.add_argument("--output", default="")
|
||||
|
||||
Reference in New Issue
Block a user