ci: fix the groups variable and report crash traffic per cycle

GROUPS is a Bash array of the user's group ids, so the workflow passes the input as OSWAL_GROUPS. An idle window no longer counts toward the load's traffic, crash cycles report their own WAL traffic from a baseline scrape when their writers start, losses are reported per cycle beside the cumulative check, and a crash cycle that loses a metrics scrape after three attempts fails its cell.

Signed-off-by: jeremyhi <fengjiachun@gmail.com>
This commit is contained in:
jeremyhi
2026-10-13 08:50:38 +08:00
parent be4514ad7e
commit 55eac3a4a1
5 changed files with 223 additions and 65 deletions
+16 -8
View File
@@ -109,14 +109,20 @@ def check_kill(directory: Path, writers: int, before_ns: int, after_ns: int, win
"kill_errors": errors}
def verify(run_dir: Path, found: dict, rows: int, enqueued: bool) -> dict:
"""Checks the table, read as batch -> row count, against every cycle's writers so far."""
acked, stripes = [], collections.OrderedDict()
def verify(run_dir: Path, found: dict, rows: int, enqueued: bool, cycle: int) -> dict:
"""Checks the table, read as batch -> row count, against every cycle's writers so far, and
counts what the given cycle's writers acknowledged, left and lost on their own."""
acked, stripes, cycle_attempted, cycle_acked = [], collections.OrderedDict(), set(), set()
for cycle_dir in sorted(run_dir.glob("cycle-*"), key=lambda p: int(p.name.split("-")[1])):
current = cycle_dir.name == f"cycle-{cycle}"
for path in sorted(cycle_dir.glob("attempted-*.log")):
stripes[(cycle_dir.name, path.name)] = [int(seq) for (seq,) in lines(path)]
if current:
cycle_attempted.update(stripes[(cycle_dir.name, path.name)])
for path in sorted(cycle_dir.glob("acked-*.log")):
acked += [int(seq) for (seq,) in lines(path)]
if current:
cycle_acked.update(int(seq) for (seq,) in lines(path))
acked_set = set(acked)
attempted = {seq for stripe in stripes.values() for seq in stripe}
errors = []
@@ -147,8 +153,12 @@ def verify(run_dir: Path, found: dict, rows: int, enqueued: bool) -> dict:
errors.append(f"present, unacknowledged and not in flight at a kill: {stray[:20]}")
if len(acked) != len(acked_set):
errors.append("a batch was acknowledged twice")
return {"found_batches": len(found), "acked_batches": len(acked_set), "lost_batches": len(missing),
"lost_rows": len(missing) * rows, "extra_batches": len(extra), "verify_errors": errors}
present = set(found) & cycle_attempted
return {"cycle_acked_batches": len(cycle_acked), "cycle_present_batches": len(present),
"cycle_lost_batches": len(cycle_acked - present), "cycle_lost_rows": len(cycle_acked - present) * rows,
"cycle_extra_batches": len(present - cycle_acked),
"total_found_batches": len(found), "total_acked_batches": len(acked_set),
"total_lost_batches": len(missing), "total_extra_batches": len(extra), "verify_errors": errors}
def main() -> int:
@@ -175,9 +185,7 @@ def main() -> int:
result |= check_kill(args.run_dir / f"cycle-{args.cycle}", args.writers, args.before_ns, args.after_ns,
args.window_max_ms)
result |= verify(args.run_dir, {int(seq): int(count) for seq, count in rows}, args.rows,
args.mode == "enqueued")
result["cycle_acked_batches"] = sum(
len(lines(p)) for p in (args.run_dir / f"cycle-{args.cycle}").glob("acked-*.log"))
args.mode == "enqueued", args.cycle)
result["passed"] = not result["kill_errors"] and not result["verify_errors"]
print(json.dumps(result))
return 0 if result["passed"] else 1
+22 -6
View File
@@ -73,6 +73,13 @@ scrape_metrics() {
case "$phase" in "") metrics_scraped=true ;; -restart) restart_scraped=true ;; esac
}
# A crash cycle cannot repeat a scrape once its server is killed, so it retries.
scrape_retry() {
local attempt
for attempt in 1 2 3; do scrape_metrics && return 0; sleep 1; done
return 1
}
sql() { curl --noproxy '*' -fsS --max-time 30 --data-urlencode "sql=$1" 'http://127.0.0.1:4000/v1/sql?db=public'; }
now_ns() { python3 -c 'import time; print(time.time_ns())'; }
@@ -146,6 +153,7 @@ sample_objects() {
# against what was acknowledged. Nothing is cleaned between cycles.
crash_cycles() {
local writers rows cycles kill_min kill_max cycle cdir wpid spid= delay before after started restart_s query_s next=0 pin_count
local load_start complete sql_url=${OSWAL_SQL_URL:-http://127.0.0.1:4000/v1/sql?db=public}
writers=$(jq -r .concurrency <<< "$spec") rows=$(jq -r .batch_rows "$PLAN") cycles=$(jq -r .cycles <<< "$spec")
kill_min=$(jq -r '.kill_after[0]' <<< "$spec") kill_max=$(jq -r '.kill_after[1]' <<< "$spec")
if jq -e .pin <<< "$spec" >/dev/null; then
@@ -154,14 +162,17 @@ crash_cycles() {
fi
sql "CREATE TABLE crash (seq BIGINT, ts TIMESTAMP TIME INDEX) WITH (append_mode = 'true')" >/dev/null
for ((cycle = 1; cycle <= cycles; cycle++)); do
cdir="$dir/cycle-$cycle"; mkdir -p "$cdir"
python3 "$here/oswal-s3-bench-crash.py" write --dir "$cdir" --url 'http://127.0.0.1:4000/v1/sql?db=public' \
cdir="$dir/cycle-$cycle" complete=true; mkdir -p "$cdir"
# The counters of this server process before its writers start are the cycle's baseline.
phase=-start-$cycle; scrape_retry || complete=false
load_start=$(now_ns)
python3 "$here/oswal-s3-bench-crash.py" write --dir "$cdir" --url "$sql_url" \
--writers "$writers" --first-seq "$next" --rows "$rows" &
wpid=$!
if jq -e .pin <<< "$spec" >/dev/null; then sample_objects & spid=$!; fi
delay=$(awk -v a="$kill_min" -v b="$kill_max" 'BEGIN {srand(); printf "%.3f", a + rand() * (b - a)}')
sleep "$delay"
phase=-cycle-$cycle; scrape_metrics || true
phase=-cycle-$cycle; scrape_retry || complete=false
before=$(now_ns); docker kill --signal KILL "$cid" >/dev/null; after=$(now_ns)
wait "$wpid"
[[ -z "$spid" ]] || { kill "$spid" 2>/dev/null; wait "$spid" 2>/dev/null || true; spid=; }
@@ -174,7 +185,7 @@ crash_cycles() {
sleep 0.2
done
query_s=$(elapsed "$started")
scrape_metrics || true
scrape_retry || complete=false
pin_count=null
if jq -e .pin <<< "$spec" >/dev/null; then
pin_count=$(sql "SELECT count(*) FROM pin" | jq -er '.output[0].records.rows[0][0]')
@@ -184,9 +195,14 @@ crash_cycles() {
--mode "$(jq -r .wal.ACK_MODE <<< "$spec")" --writers "$writers" --rows "$rows" \
--before-ns "$before" --after-ns "$after" --window-max-ms 2000 > "$cdir/check.json" || verdict=$?
jq -c --arg delay "$delay" --arg restart "$restart_s" --arg query "$query_s" --argjson pin "$pin_count" \
'. + {kill_after_seconds: ($delay | tonumber), restart_seconds: ($restart | tonumber),
restart_query_seconds: ($query | tonumber), pin_rows: $pin}' "$cdir/check.json" >> "$dir/cycles.jsonl"
--argjson load "$(awk -v a="$load_start" -v b="$before" 'BEGIN {printf "%.3f", (b - a) / 1e9}')" \
--argjson complete "$complete" \
'. + {kill_after_seconds: ($delay | tonumber), load_seconds: $load, restart_seconds: ($restart | tonumber),
restart_query_seconds: ($query | tonumber), pin_rows: $pin, metrics_complete: $complete}' \
"$cdir/check.json" >> "$dir/cycles.jsonl"
((verdict == 0)) || { echo "$id: cycle $cycle failed its check" >&2; exit 6; }
# A cycle without its scrapes is not a measurement, whatever the table held.
[[ "$complete" == true ]] || { echo "$id: cycle $cycle lost a metrics scrape" >&2; exit 4; }
next=$(cat "$cdir"/attempted-*.log | sort -n | tail -1); next=$((next + 1))
done
}
+54 -30
View File
@@ -82,14 +82,34 @@ def interval_seconds(wal: dict) -> float:
return float(value[:-2]) / 1000 if value.endswith("ms") else float(value.rstrip("s"))
def crash_cycles(path: Path) -> list:
def traffic(end: dict, start: dict, seconds, wal: dict) -> dict:
"""WAL traffic between two scrapes of one process over `seconds`; more objects than seal
ticks, or objects near the 8 MiB threshold, mean batches sealed on size rather than on the timer."""
def delta(name):
value = end["samples"].get(name)
return None if value is None else value - start["samples"].get(name, 0)
created, written, objects = delta("created_objects_total"), delta("object_bytes_sum"), delta("object_bytes_count")
per_second = created / seconds if created and seconds else None
mean = written / objects if written and objects else None
return {"wal_mb_per_second": written / seconds / 1e6 if written and seconds else None,
"objects_per_second": per_second, "mean_object_bytes": mean,
"sealed_on_size": None if per_second is None else
per_second > 1.05 / interval_seconds(wal) or (mean or 0) >= 0.9 * 8 * 2**20,
"requests": {op: n - start["requests"].get(op, 0) for op, n in end["requests"].items()
if n != start["requests"].get(op, 0)}}
def crash_cycles(path: Path, wal: dict) -> list:
"""Each cycle's check plus the loaded server's metrics before the kill and the restarted one's after."""
cycles = [json.loads(line) for line in (path / "cycles.jsonl").read_text().splitlines()
if line.strip()] if (path / "cycles.jsonl").exists() else []
for cycle in cycles:
before = read_metrics(path / f"metrics-cycle-{cycle['cycle']}.prom")["samples"]
start = read_metrics(path / f"metrics-start-{cycle['cycle']}.prom")
killed = read_metrics(path / f"metrics-cycle-{cycle['cycle']}.prom")
before = killed["samples"]
after = read_metrics(path / f"metrics-restart-{cycle['cycle']}.prom")
once = after["samples"].get("recovery_seconds_count") == 1
cycle |= traffic(killed, start, cycle.get("load_seconds"), wal)
cycle |= {"created_before_kill": before.get("created_objects_total"),
"indexed_before_kill": before.get("indexed_objects"),
"recovery_seconds": after["samples"].get("recovery_seconds_sum") if once else None,
@@ -104,7 +124,9 @@ def load_cell(path: Path, spec: dict | None = None) -> dict:
cell = json.loads(recorded.read_text()) if recorded.exists() else spec | {"exit_code": None, "missing": True}
result_path = path / "greptimedb-1" / "load-result.json"
result = json.loads(result_path.read_text()) if result_path.exists() else {}
metrics, restarted = read_metrics(path / "metrics.prom"), read_metrics(path / "metrics-restart.prom")
final, restarted = read_metrics(path / "metrics.prom"), read_metrics(path / "metrics-restart.prom")
# With an idle window the scrape taken when the load ended describes the load.
metrics = read_metrics(path / "metrics-idle.prom") if cell.get("idle_seconds") else final
load_seconds = result.get("load_seconds")
wall, cpu = cell.get("load_wall_seconds"), cell.get("server_cpu_seconds")
row = {
@@ -140,25 +162,15 @@ def load_cell(path: Path, spec: dict | None = None) -> dict:
row[counter] = metrics["samples"].get(counter, 0 if active else None)
created = row["created_objects_total"]
row["creates_per_minute"] = created * 60 / load_seconds if created is not None and load_seconds else None
# WAL traffic of the load; more objects than seal ticks, or objects near the
# 8 MiB threshold, mean batches sealed on size rather than on the timer.
written, objects = metrics["samples"].get("object_bytes_sum"), metrics["samples"].get("object_bytes_count")
per_second = created / load_seconds if created and load_seconds else None
mean = written / objects if written and objects else None
row |= {"wal_mb_per_second": written / load_seconds / 1e6 if written and load_seconds else None,
"objects_per_second": per_second, "mean_object_bytes": mean,
"sealed_on_size": None if per_second is None else
per_second > 1.05 / interval_seconds(cell.get("wal", {})) or (mean or 0) >= 0.9 * 8 * 2**20,
"requests": metrics["requests"], "restart_requests": restarted["requests"]}
row |= traffic(metrics, {"samples": {}, "requests": {}}, load_seconds, cell.get("wal", {}))
row["restart_requests"] = restarted["requests"]
if cell.get("idle_seconds"):
idle = read_metrics(path / "metrics-idle.prom")
start = idle["samples"].get("created_objects_total", 0)
row["idle"] = {"seconds": cell["idle_seconds"],
"creates": None if created is None else created - start,
"requests": {op: n - idle["requests"].get(op, 0) for op, n in metrics["requests"].items()
if n != idle["requests"].get(op, 0)}}
idle = traffic(final, metrics, cell["idle_seconds"], cell.get("wal", {}))
end = final["samples"].get("created_objects_total")
row["idle"] = {"seconds": cell["idle_seconds"], "requests": idle["requests"],
"creates": None if end is None else end - metrics["samples"].get("created_objects_total", 0)}
if row["mode"] == "crash":
row["cycles"] = crash_cycles(path)
row["cycles"] = crash_cycles(path, cell.get("wal", {}))
if (path / "objects.tsv").exists():
row["objects_samples"] = [[int(float(v)) for v in line.split()]
for line in (path / "objects.tsv").read_text().splitlines() if line.strip()]
@@ -244,21 +256,33 @@ def render(run: dict, rows: list, pairs: list) -> str:
fmt(idle.get("seconds")), fmt(idle.get("creates")), operations(idle["requests"]) if idle else "—"]) + " |")
crashes = [r for r in rows if r["mode"] == "crash"]
if crashes:
lines += ["", "| Cell | Cycle | Kill after s | Acked batches | In flight | Found | Acked so far | Lost batches "
"| Lost rows | Extra | Indexed at kill | Restart to /health s | Recovery s | Recovered objects "
"| Pin rows | Verdict |",
lines += ["", "| Cell | Cycle | Kill after s | Acked | Present | Lost | Lost rows | Extra | In flight "
"| All found | All acked | All lost | Indexed at kill | Restart to /health s | Recovery s "
"| Recovered objects | Pin rows | Verdict |",
"| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: "
"| ---: | --- |"]
"| ---: | ---: | ---: | --- |"]
for r in crashes:
for c in r["cycles"] or [{}]:
verdict = "—" if not c else "FAIL: " + "; ".join(c.get("kill_errors", []) + c.get("verify_errors", [])) \
if not c.get("passed") else "pass" if c.get("metrics_complete", True) else "pass, scrape missing"
lines.append(" | ".join([
f"| {label(r)}", fmt(c.get("cycle")), fmt(c.get("kill_after_seconds"), 1),
fmt(c.get("cycle_acked_batches")), fmt(c.get("in_flight")), fmt(c.get("found_batches")),
fmt(c.get("acked_batches")), fmt(c.get("lost_batches")), fmt(c.get("lost_rows")),
fmt(c.get("extra_batches")), fmt(c.get("indexed_before_kill")), fmt(c.get("restart_seconds"), 2),
fmt(c.get("recovery_seconds"), 3), fmt(c.get("recovered_objects")), fmt(c.get("pin_rows")),
"—" if not c else "pass" if c.get("passed") else "FAIL: " + "; ".join(
c.get("kill_errors", []) + c.get("verify_errors", []))]) + " |")
fmt(c.get("cycle_acked_batches")), fmt(c.get("cycle_present_batches")),
fmt(c.get("cycle_lost_batches")), fmt(c.get("cycle_lost_rows")), fmt(c.get("cycle_extra_batches")),
fmt(c.get("in_flight")), fmt(c.get("total_found_batches")), fmt(c.get("total_acked_batches")),
fmt(c.get("total_lost_batches")), fmt(c.get("indexed_before_kill")),
fmt(c.get("restart_seconds"), 2), fmt(c.get("recovery_seconds"), 3),
fmt(c.get("recovered_objects")), fmt(c.get("pin_rows")), verdict]) + " |")
lines += ["", "| Cell | Cycle | Load s | WAL MB/s | Objects/s | Mean object MiB | Sealed on size "
"| Requests until the kill | Requests of the restart |",
"| --- | ---: | ---: | ---: | ---: | ---: | --- | --- | --- |"]
for r in crashes:
for c in r["cycles"]:
lines.append(" | ".join([
f"| {r['id']}", fmt(c["cycle"]), fmt(c.get("load_seconds"), 1), fmt(c["wal_mb_per_second"], 1),
fmt(c["objects_per_second"], 1), fmt(c["mean_object_bytes"], 2, 1 / 2**20),
"—" if c["sealed_on_size"] is None else ("yes" if c["sealed_on_size"] else "no"),
operations(c["requests"]), operations(c["restart_requests"])]) + " |")
pinned = [r for r in crashes if r.get("objects_samples")]
if pinned:
lines += ["", "| Cell | Indexed objects every 30 s | Deleted objects at the end | Created objects at the end |",