test(observability): await measured recovery and verify store persistence
This commit is contained in:
@@ -0,0 +1,249 @@
|
||||
"""Derive tables and a figure from completed observations, never simulated data."""
|
||||
|
||||
import argparse
|
||||
import csv
|
||||
import json
|
||||
import math
|
||||
from collections import Counter
|
||||
from pathlib import Path
|
||||
|
||||
import matplotlib
|
||||
|
||||
matplotlib.use("Agg")
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
def quantile(values, fraction):
|
||||
ordered = sorted(values)
|
||||
return (
|
||||
ordered[max(0, math.ceil(len(ordered) * fraction) - 1)]
|
||||
if ordered
|
||||
else None
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("input", type=Path)
|
||||
parser.add_argument("--output", type=Path, required=True)
|
||||
args = parser.parse_args()
|
||||
report = json.loads(args.input.read_text())
|
||||
assert report["complete"] and report["scope"] == "full30m"
|
||||
assert report["elapsed_seconds"] >= 1800
|
||||
with (args.input.parent / report["requests_csv"]).open() as stream:
|
||||
requests = list(csv.DictReader(stream))
|
||||
samples = report["samples"]
|
||||
origin = samples[0]["at"]
|
||||
summaries = []
|
||||
for phase in report["phases"]:
|
||||
rows = [r for r in requests if r["phase"] == phase["name"]]
|
||||
successful = [
|
||||
float(r["seconds"]) for r in rows if r["status"] == "201"
|
||||
]
|
||||
elapsed = phase["end"] - phase["start"]
|
||||
summaries.append(
|
||||
{
|
||||
"phase": phase["name"],
|
||||
"seconds": round(elapsed, 3),
|
||||
"started_requests": len(rows),
|
||||
"statuses": dict(Counter(r["status"] for r in rows)),
|
||||
"successful_rps": round(len(successful) / elapsed, 3),
|
||||
"success_p50_ms": round(quantile(successful, 0.5) * 1000, 3)
|
||||
if successful
|
||||
else None,
|
||||
"success_p95_ms": round(quantile(successful, 0.95) * 1000, 3)
|
||||
if successful
|
||||
else None,
|
||||
"success_p99_ms": round(quantile(successful, 0.99) * 1000, 3)
|
||||
if successful
|
||||
else None,
|
||||
"critical_firing_names": sorted(
|
||||
n
|
||||
for n in phase["firing"]
|
||||
if n
|
||||
in {
|
||||
"ApiFastBurn",
|
||||
"ApiSlowBurn",
|
||||
"ReadyFastBurn",
|
||||
"ReadySlowBurn",
|
||||
}
|
||||
),
|
||||
"warning_firing_names": sorted(
|
||||
n
|
||||
for n in phase["firing"]
|
||||
if n
|
||||
not in {
|
||||
"ApiFastBurn",
|
||||
"ApiSlowBurn",
|
||||
"ReadyFastBurn",
|
||||
"ReadySlowBurn",
|
||||
}
|
||||
),
|
||||
}
|
||||
)
|
||||
intervals = {}
|
||||
for name in sorted({a["name"] for s in samples for a in s["alerts"]}):
|
||||
segments, start = [], None
|
||||
for sample in samples:
|
||||
active = any(
|
||||
a["name"] == name and a["state"] == "firing"
|
||||
for a in sample["alerts"]
|
||||
)
|
||||
if active and start is None:
|
||||
start = sample["at"]
|
||||
elif not active and start is not None:
|
||||
segments.append([start, sample["at"]])
|
||||
start = None
|
||||
if start is not None:
|
||||
segments.append([start, samples[-1]["at"]])
|
||||
intervals[name] = segments
|
||||
gap = [
|
||||
b["at"] - a["at"] for a, b in zip(samples, samples[1:], strict=False)
|
||||
]
|
||||
memory = [
|
||||
s["signals"]["collector_memory"] / 1024**2
|
||||
for s in samples
|
||||
if s["signals"]["collector_memory"] is not None
|
||||
]
|
||||
summary = {
|
||||
"source_commit": report["source_commit"],
|
||||
"runtime_versions": report["runtime_versions"],
|
||||
"elapsed_seconds": report["elapsed_seconds"],
|
||||
"sample_count": len(samples),
|
||||
"sample_gap_seconds": {
|
||||
"min": min(gap),
|
||||
"median": quantile(gap, 0.5),
|
||||
"max": max(gap),
|
||||
},
|
||||
"client_quantile_method": "nearest rank of successful end-to-end writes; not histogram interpolation",
|
||||
"phases": summaries,
|
||||
"incidents": report["incidents"],
|
||||
"firing_intervals_unix_seconds": intervals,
|
||||
"short_spikes": report["short_spikes"],
|
||||
"collector_rss_mib": {"min": min(memory), "max": max(memory)},
|
||||
"collector_max_queued_packets_sum": max(
|
||||
s["signals"]["collector_queue"] or 0 for s in samples
|
||||
),
|
||||
"collector_queue_capacity_sum": max(
|
||||
s["signals"]["collector_queue_capacity"] or 0 for s in samples
|
||||
),
|
||||
"backend_outage": report["backend_outage"],
|
||||
"preservation": report["preservation"],
|
||||
"final_30m_sli": report["final_30m_sli"],
|
||||
}
|
||||
args.output.mkdir(parents=True, exist_ok=True)
|
||||
(args.output / "summary.json").write_text(
|
||||
json.dumps(summary, ensure_ascii=False, indent=2) + "\n"
|
||||
)
|
||||
with (args.output / "phases.csv").open("w") as stream:
|
||||
writer = csv.DictWriter(stream, fieldnames=list(summaries[0]))
|
||||
writer.writeheader()
|
||||
writer.writerows(summaries)
|
||||
x = [(s["at"] - origin) / 60 for s in samples]
|
||||
fig, axes = plt.subplots(
|
||||
4, 1, figsize=(12, 12), sharex=True, layout="constrained"
|
||||
)
|
||||
for axis in axes:
|
||||
axis.grid(alpha=0.2)
|
||||
for phase in report["phases"]:
|
||||
if (
|
||||
phase["name"].endswith("_sustained")
|
||||
or phase["name"] == "backend_unavailable"
|
||||
):
|
||||
color = (
|
||||
"#cf704e"
|
||||
if phase["name"].startswith("api")
|
||||
else "#8b79b5"
|
||||
if phase["name"].startswith("ready")
|
||||
else "#85919d"
|
||||
)
|
||||
axis.axvspan(
|
||||
(phase["start"] - origin) / 60,
|
||||
(phase["end"] - origin) / 60,
|
||||
color=color,
|
||||
alpha=0.15,
|
||||
)
|
||||
axes[0].plot(
|
||||
x,
|
||||
[(s["signals"]["api_error_ratio_1m"] or 0) * 100 for s in samples],
|
||||
color="#b04a32",
|
||||
label="API 5xx ratio, rolling 1 min",
|
||||
)
|
||||
axes[0].axhline(1, color="black", ls=":", label="1% error budget")
|
||||
axes[0].set_ylabel("5xx, %")
|
||||
axes[0].legend(loc="upper right")
|
||||
axes[0].set_title(
|
||||
"Actual 30-minute SLO experiment: DB delay, stopped worker, unavailable telemetry stores"
|
||||
)
|
||||
axes[1].plot(
|
||||
x,
|
||||
[s["signals"]["queue_depth"] for s in samples],
|
||||
color="#386a9b",
|
||||
label="Queued jobs",
|
||||
)
|
||||
axes[1].set_ylabel("Jobs")
|
||||
other = axes[1].twinx()
|
||||
other.plot(
|
||||
x,
|
||||
[s["signals"]["oldest_job_age"] for s in samples],
|
||||
color="#8b579d",
|
||||
label="Oldest unfinished job",
|
||||
)
|
||||
other.axhline(20, ls=":", color="#8b579d")
|
||||
other.set_ylabel("Age, seconds")
|
||||
axes[1].legend(loc="upper left")
|
||||
other.legend(loc="upper right")
|
||||
alert_names = [
|
||||
"ApiFastBurn",
|
||||
"ApiSlowBurn",
|
||||
"ReadyFastBurn",
|
||||
"ReadySlowBurn",
|
||||
]
|
||||
for index, name in enumerate(alert_names):
|
||||
axes[2].broken_barh(
|
||||
[
|
||||
((start - origin) / 60, (end - start) / 60)
|
||||
for start, end in intervals.get(name, [])
|
||||
],
|
||||
(index - 0.3, 0.6),
|
||||
facecolors="#bd523c",
|
||||
)
|
||||
axes[2].set_yticks(range(4), alert_names)
|
||||
axes[2].set_ylim(-0.6, 3.6)
|
||||
axes[2].set_ylabel("Critical alert firing")
|
||||
axes[3].plot(
|
||||
x,
|
||||
[
|
||||
s["signals"]["collector_memory"] / 1024**2
|
||||
if s["signals"]["collector_memory"] is not None
|
||||
else None
|
||||
for s in samples
|
||||
],
|
||||
color="#347465",
|
||||
label="Collector RSS",
|
||||
)
|
||||
axes[3].axhline(
|
||||
report["container_limits"]["otel"]["mem_limit"] / 1024**2,
|
||||
ls=":",
|
||||
color="black",
|
||||
label="Container memory limit",
|
||||
)
|
||||
axes[3].set_ylabel("MiB")
|
||||
axes[3].set_xlabel("Minutes from first observation")
|
||||
other = axes[3].twinx()
|
||||
other.plot(
|
||||
x,
|
||||
[s["signals"]["collector_queue"] for s in samples],
|
||||
color="#9c6e2e",
|
||||
label="Queued telemetry packets, sum",
|
||||
)
|
||||
other.set_ylabel("Packets")
|
||||
axes[3].legend(loc="upper left")
|
||||
other.legend(loc="upper right")
|
||||
fig.savefig(args.output / "slo-timeline.png", dpi=150)
|
||||
plt.close(fig)
|
||||
print("PASS: measured phase statistics, alert intervals and timeline")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user