From 4dd77fc3624367a4dc348e73ca2e85f2c01838b7 Mon Sep 17 00:00:00 2001 From: jeremyhi Date: Tue, 13 Oct 2026 08:56:21 +0800 Subject: [PATCH] ci: record failed pinned samples as missing A periodic scrape that fails or lacks the indexed object count is written as a missing sample instead of zero objects, the summary counts missing samples, and a sampler that already exited no longer aborts the crash cycle. Signed-off-by: jeremyhi --- .github/scripts/oswal-s3-bench-run.sh | 16 +++++++++++---- .github/scripts/oswal-s3-bench-summary.py | 15 ++++++++------ tests/perf/test_oswal_s3_bench_scripts.py | 24 ++++++++++++++++++----- 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/.github/scripts/oswal-s3-bench-run.sh b/.github/scripts/oswal-s3-bench-run.sh index 5c12c2be27e..1415a2fef91 100644 --- a/.github/scripts/oswal-s3-bench-run.sh +++ b/.github/scripts/oswal-s3-bench-run.sh @@ -139,12 +139,20 @@ restart() { # Pins the WAL with one row in a second table before the writers start, if asked, # and samples the object counts every 30 s while they run. sample_objects() { - while sleep 30; do - curl --noproxy '*' -fsS --max-time 10 http://127.0.0.1:4000/metrics 2>/dev/null | awk -v t="$(date +%s)" ' + set +e + local body + while sleep "${OSWAL_SAMPLE_SECONDS:-30}"; do + # A failed scrape is a missing sample, never zero objects. + if ! body=$(curl --noproxy '*' -fsS --max-time 10 http://127.0.0.1:4000/metrics 2>/dev/null) \ + || ! grep -q '^greptime_logstore_object_store_wal_indexed_objects ' <<< "$body"; then + echo "$(date +%s) missing" >> "$dir/objects.tsv" + continue + fi + awk -v t="$(date +%s)" ' /^greptime_logstore_object_store_wal_indexed_objects / {i = $2} /^greptime_logstore_object_store_wal_deleted_objects_total / {d = $2} /^greptime_logstore_object_store_wal_created_objects_total / {c = $2} - END {print t, i + 0, d + 0, c + 0}' >> "$dir/objects.tsv" + END {print t, i + 0, d + 0, c + 0}' <<< "$body" >> "$dir/objects.tsv" done } @@ -175,7 +183,7 @@ crash_cycles() { 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=; } + if [[ -n "$spid" ]]; then kill "$spid" 2>/dev/null || true; wait "$spid" 2>/dev/null || true; spid=; fi stop_server killed phase=-restart-$cycle started=$(now) start_server diff --git a/.github/scripts/oswal-s3-bench-summary.py b/.github/scripts/oswal-s3-bench-summary.py index 66114f868f8..84f92873fff 100644 --- a/.github/scripts/oswal-s3-bench-summary.py +++ b/.github/scripts/oswal-s3-bench-summary.py @@ -172,8 +172,10 @@ def load_cell(path: Path, spec: dict | None = None) -> dict: if row["mode"] == "crash": 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()] + # A sample is time, indexed, deleted, created; a failed scrape is time and "missing". + row["objects_samples"] = [[int(float(line.split()[0]))] + ( + [None] * 3 if line.split()[1:] == ["missing"] else [int(float(v)) for v in line.split()[1:]]) + for line in (path / "objects.tsv").read_text().splitlines() if line.strip()] return row @@ -285,12 +287,13 @@ def render(run: dict, rows: list, pairs: list) -> str: 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 |", - "| --- | --- | ---: | ---: |"] + lines += ["", "| Cell | Indexed objects every 30 s | Missing samples | Deleted objects at the end " + "| Created objects at the end |", "| --- | --- | ---: | ---: | ---: |"] for r in pinned: samples = r["objects_samples"] - lines.append(f"| {r['id']} | {', '.join(str(s[1]) for s in samples)} | {samples[-1][2]:,} " - f"| {samples[-1][3]:,} |") + last = next((s for s in reversed(samples) if s[1] is not None), [None] * 4) + lines.append(f"| {r['id']} | {', '.join('missing' if s[1] is None else str(s[1]) for s in samples)} " + f"| {sum(s[1] is None for s in samples)} | {fmt(last[2])} | {fmt(last[3])} |") restarts = [r for r in rows if "restart" in r] if restarts: lines += ["", "| Cell | Overrides | Objects created | Restart to /health s | Restart to count s " diff --git a/tests/perf/test_oswal_s3_bench_scripts.py b/tests/perf/test_oswal_s3_bench_scripts.py index ad3d2796732..e36c97dfcc7 100644 --- a/tests/perf/test_oswal_s3_bench_scripts.py +++ b/tests/perf/test_oswal_s3_bench_scripts.py @@ -434,14 +434,14 @@ class SummaryTest(unittest.TestCase): "greptime_logstore_object_store_wal_recovery_seconds_sum 2.5\n" "greptime_logstore_object_store_wal_recovery_seconds_count 1\n" "greptime_logstore_object_store_wal_recovered_objects_total 5399\n") - (path / "objects.tsv").write_text("100 300 0 301\n130 600 0 601\n") + (path / "objects.tsv").write_text("100 300 0 301\n130 600 0 601\n160 missing\n") rows = [summary.load_cell(p) for p in sorted((root / "cells").iterdir())] output = summary.render({}, rows, summary.ratios(rows)) self.assertIn("| 1-32-E | 50.0 | 10.0 | 4.77 | no | read 40, write 648 | — | 180 | 2 | write 4 |", output) self.assertIn("| pin-1-8-D | 1 | 540.0 | 4,000 | 4,003 | 0 | 0 | 3 | 8 | 4,003 | 4,000 | 0 | 5,400 " "| 4.50 | 2.500 | 5,399 | 1 | pass |", output) self.assertIn("| pin-1-8-D | 1 | 540.0 | 20.0 | 10.0 | 1.91 | no | write 9,000 | — |", output) - self.assertIn("| pin-1-8-D | 300, 600 | 0 | 601 |", output) + self.assertIn("| pin-1-8-D | 300, 600, missing | 1 | 0 | 601 |", output) def test_untouched_counters_are_zero_only_for_an_active_object_store_wal(self): with tempfile.TemporaryDirectory() as directory: @@ -505,6 +505,7 @@ esac """ FAKE_CURL = r"""#!/usr/bin/env bash printf '%s\n' "curl $*" >> "$FAKE_LOG" +[[ "$*" != *"--max-time 10"* || "${FAKE_SAMPLE_RC:-0}" == 0 ]] || exit "$FAKE_SAMPLE_RC" for arg in "$@"; do [[ "$arg" != *"GROUP BY seq"* ]] || { python3 -c 'import collections, json, sys counts = collections.Counter(int(l) for l in open(sys.argv[1]) if l.strip()) @@ -647,7 +648,7 @@ class CellLifecycleTest(unittest.TestCase): # the run script against fake docke self.assertEqual(log.count("/metrics"), 2) self.assertIn(f"type=bind,src={root}/corpus/corpus-6000,dst=/work/corpus,readonly", log) - def run_crash(self, root, metrics_rc=0): + def run_crash(self, root, metrics_rc=0, pin=False, sample_rc=0): """A crash cell against fake docker and a stub SQL endpoint that the fake kill takes down.""" import http.server import threading @@ -676,10 +677,12 @@ class CellLifecycleTest(unittest.TestCase): # the run script against fake docke server = Server(("127.0.0.1", 0), Handler) threading.Thread(target=server.serve_forever, daemon=True).start() - groups = json.dumps([{"name": "crash", "configs": "D", "mode": "crash", "cycles": 2, "kill_after": [1, 1]}]) + groups = json.dumps([{"name": "crash", "configs": "D", "mode": "crash", "cycles": 2, "kill_after": [1, 1], + "pin": pin}]) old = os.environ.copy() os.environ.update({"OSWAL_SQL_URL": f"http://127.0.0.1:{server.server_port}/v1/sql", - "FAKE_KILL_FLAG": str(flag), "FAKE_FOUND": str(found), "FAKE_BATCH_ROWS": "1000"}) + "FAKE_KILL_FLAG": str(flag), "FAKE_FOUND": str(found), "FAKE_BATCH_ROWS": "1000", + "OSWAL_SAMPLE_SECONDS": "0.2", "FAKE_SAMPLE_RC": str(sample_rc)}) try: return self.run_cells(root, load_rc=0, metrics_rc=metrics_rc, groups=groups) finally: @@ -706,6 +709,17 @@ class CellLifecycleTest(unittest.TestCase): # the run script against fake docke for name in ("metrics-start-1.prom", "metrics-cycle-2.prom", "metrics-restart-2.prom", "server-cycle-1.log"): self.assertTrue((cell / name).exists(), name) + def test_failed_pinned_samples_are_missing_not_zero(self): + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + cells, _, log, _ = self.run_crash(root, pin=True, sample_rc=28) + self.assertEqual(cells.returncode, 0, cells.stdout + cells.stderr) + cell = root / "results" / "cells" / "crash-1-8-D" + samples = (cell / "objects.tsv").read_text().splitlines() + self.assertTrue(samples and all(line.split()[1:] == ["missing"] for line in samples), samples) + self.assertIn("sql=INSERT INTO pin VALUES (1, 0)", log) + self.assertEqual(len((cell / "cycles.jsonl").read_text().splitlines()), 2) + def test_a_crash_cycle_without_its_scrapes_fails_the_cell(self): with tempfile.TemporaryDirectory() as directory: root = Path(directory)