feat(security): add scoped identities, TLS boundaries and OpenBao bootstrap
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
"""Summarize measured fault invariants and child resource samples."""
|
||||
|
||||
import argparse
|
||||
import csv
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import matplotlib
|
||||
|
||||
matplotlib.use("Agg")
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
def effects(case):
|
||||
for key in ["effect", "v1", "v2"]:
|
||||
if key in case:
|
||||
yield key, case[key]
|
||||
for i, item in enumerate(case.get("effects", [])):
|
||||
yield str(i + 1), item
|
||||
|
||||
|
||||
def main():
|
||||
p = argparse.ArgumentParser()
|
||||
p.add_argument("input", type=Path)
|
||||
p.add_argument("--output", required=True, type=Path)
|
||||
a = p.parse_args()
|
||||
d = json.loads(a.input.read_text())
|
||||
assert d["complete"] and d.get("scope", "all") == "all"
|
||||
rows = []
|
||||
for case in d["cases"]:
|
||||
for role, e in effects(case):
|
||||
j = e["job"]
|
||||
rows.append(
|
||||
dict(
|
||||
case=case["case"],
|
||||
role=role,
|
||||
job_id=j["id"],
|
||||
version=j["pipeline_version"],
|
||||
attempt=j["attempt"],
|
||||
cycle=j["cycle"],
|
||||
fence=j["fence"],
|
||||
state=j["state"],
|
||||
publications=e["publications"],
|
||||
variant_rows=len(e["variants"]),
|
||||
physical_keys=len(e["physical_keys"]),
|
||||
)
|
||||
)
|
||||
a.output.mkdir(parents=True, exist_ok=True)
|
||||
with (a.output / "effects.csv").open("w") as f:
|
||||
writer = csv.DictWriter(f, fieldnames=list(rows[0]))
|
||||
writer.writeheader()
|
||||
writer.writerows(rows)
|
||||
ready = [r for r in rows if r["state"] == "ready"]
|
||||
assert all(
|
||||
r["publications"] == 1
|
||||
and r["variant_rows"] == 4
|
||||
and r["physical_keys"] == 4
|
||||
for r in ready
|
||||
)
|
||||
stale = [r for r in rows if r["state"] == "obsolete"]
|
||||
assert all(r["publications"] == 0 for r in stale)
|
||||
job_ids = {r["job_id"] for r in rows}
|
||||
samples = [
|
||||
x["detail"]
|
||||
for x in d["worker_metrics"]
|
||||
if str(x["job_id"]) in job_ids
|
||||
and x["detail"].get("result") == "ready"
|
||||
and "rss_peak_mib" in x["detail"]
|
||||
]
|
||||
stats = {
|
||||
"source_commit": d["source_commit"],
|
||||
"cases": len(d["cases"]),
|
||||
"observed_ready_effects": len(ready),
|
||||
"observed_obsolete_effects": len(stale),
|
||||
"all_ready_have_one_publication_and_four_variants": True,
|
||||
"all_obsolete_have_zero_publications": True,
|
||||
"successful_child_samples": len(samples),
|
||||
"child_elapsed_range_seconds": [
|
||||
min(x["seconds"] for x in samples),
|
||||
max(x["seconds"] for x in samples),
|
||||
],
|
||||
"child_cpu_range_seconds": [
|
||||
min(x["cpu_seconds"] for x in samples),
|
||||
max(x["cpu_seconds"] for x in samples),
|
||||
],
|
||||
"child_peak_rss_range_mib": [
|
||||
min(x["rss_peak_mib"] for x in samples),
|
||||
max(x["rss_peak_mib"] for x in samples),
|
||||
],
|
||||
"scope": "process self metrics, no queue lag or throughput claim; fault-free and retry children only where a result was returned",
|
||||
}
|
||||
(a.output / "summary.json").write_text(json.dumps(stats, indent=2) + "\n")
|
||||
fig, axes = plt.subplots(1, 2, figsize=(13, 5), layout="constrained")
|
||||
axes[0].bar(
|
||||
range(1, len(rows) + 1),
|
||||
[r["publications"] for r in rows],
|
||||
color=[
|
||||
"#246b8e" if r["state"] == "ready" else "#d17d20" for r in rows
|
||||
],
|
||||
)
|
||||
axes[0].axhline(1, color="#5b6870", linestyle="--", linewidth=1)
|
||||
axes[0].set(
|
||||
xlabel="Effect observation (CSV row)",
|
||||
ylabel="Committed publications",
|
||||
title="One publication per ready version; stale v1 = 0",
|
||||
yticks=[0, 1],
|
||||
)
|
||||
axes[1].scatter(
|
||||
[x["seconds"] for x in samples],
|
||||
[x["rss_peak_mib"] for x in samples],
|
||||
color="#246b8e",
|
||||
s=35,
|
||||
alpha=0.8,
|
||||
)
|
||||
axes[1].set(
|
||||
xlabel="Child elapsed, seconds",
|
||||
ylabel="Child peak RSS, MiB",
|
||||
title=f"{len(samples)} completed child samples (synthetic320×200)",
|
||||
)
|
||||
for ax in axes:
|
||||
ax.grid(axis="y", alpha=0.2)
|
||||
fig.savefig(a.output / "pipeline-results.png", dpi=150)
|
||||
plt.close(fig)
|
||||
print(json.dumps(stats, indent=2))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -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