mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-29 14:30:52 +00:00
Resolves 68 conflicted files. The governing rule was our structure with their
network semantics: the tor boolean becomes a network mode (clearnet | tor |
multi) throughout the variant layer, while this branch's architecture and mesh
axes, its extracted modules and its i18n content stay.
Where the two sides covered different ground, both are kept rather than one
picked:
- ca_injected answers a ca_client on the deployment's TLS mode OR on an SSO
issuer that resolves self-signed. 3a3e9ed2c9 records why: an issuer is not
an object store, so keeping only one side drops the other's coverage.
- get_merged_domains keeps the loud refusal when svc-net-tor is deployed
without a provisioned node, now gated on their tor_serves_host; their
node_onion_of returns an empty string there, which would have served every
onion-exclusive app on clearnet in silence.
- sso_cookie_domains stays the single source for oauth2-proxy's cookie scope.
Their per-network branch omitted the issuer domain on the onion arm, which
breaks the callback leg.
- The clearnet CSP batch carries --clearnet-timeout again; their batch dict
hardcoded zero while the role still passes the flag.
- The dashboard keeps its i18n content dir, image, version and design
resolution; their side reduced the logo sources to the bare service
provider values.
Their side wins where it is measurably better: the onion mirror rewrite is
gated per vhost rather than per app, the Playwright onion decision reads the
pass's own domain instead of the role's canonical one, and the matomo
reinjection and dashboard config render per network sibling.
Eight files were broken by the merge without ever carrying a conflict marker,
because git marks only the lines both sides touched:
- utils/cache/domains.py lost the onionize block that sat between two hunks
- roles/sys-front-inj-all/templates/body_filter.lua.j2 called it
- web-app-bluesky, keycloak sso_proxy: the get_entity_name filter was renamed
- trigger/__main__.py, playwright_coverage.py and its test: the deleted tor
module
- cli/administration/deploy/ci/timings.py read Label.tor
- plugins/filter/csp_filters.py called _aligned_url with four of six arguments
- tests/unit/python/utils/cache/test_domains.py referenced a renamed class
- tests/.../sys-ctl-hlth-csp/files/test_script.py mocked a function main no
longer calls
Verified: the variant layer (155 tests, 65 subtests), ca_injected (18),
the CI layer (175), the domains cache including the restored guard (32),
retrigger inputs (9), timings and the CSP health script (53). make
quality-high clears autoformat; its remaining findings are tracked separately.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
234 lines
7.5 KiB
Python
234 lines
7.5 KiB
Python
"""What each axis value costs in runner time, measured off finished runs.
|
|
|
|
Usage:
|
|
python -m cli.administration.deploy.ci.timings [--runs N] [--repo owner/repo]
|
|
[--branch B] [--minimum N]
|
|
|
|
A verification run wants the combination that reaches a verdict soonest, and
|
|
the axes differ by minutes: an onion row waits for circuits the clearnet row
|
|
never builds, and swarm brings a cluster up before the first service starts.
|
|
The combination that answers the question fastest is therefore not the one the
|
|
sweep rotation happens to draw.
|
|
|
|
Nothing recorded that cost, so the choice used to be made by assertion. Deploy
|
|
job titles carry the whole row (:func:`utils.github.variant.axes.parse_label`)
|
|
and the API gives every job a start and an end, so the cost per axis value is
|
|
read back off the runs that already happened.
|
|
|
|
Medians, not means: a job that hit a queue wait or a network stall is a long
|
|
tail on an otherwise cheap axis, and averaging lets one such job outvote a
|
|
hundred normal ones.
|
|
|
|
A filesystem row states the kind the matrix *assigned*. A deploy may fall back
|
|
from it when the host kernel cannot serve it
|
|
(``scripts/tests/deploy/utils/filesystem/resolve.sh``) and the title does not
|
|
record that, so read that axis as a preference ranking and prove the kind
|
|
separately before pinning it.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import statistics
|
|
import sys
|
|
from datetime import datetime
|
|
from typing import TYPE_CHECKING
|
|
|
|
from cli.administration.deploy.ci.gh import (
|
|
_gh,
|
|
current_branch,
|
|
fetch_jobs,
|
|
resolve_repo,
|
|
)
|
|
from cli.administration.deploy.ci.runs import _effective
|
|
from utils.github.variant import axes
|
|
|
|
if TYPE_CHECKING:
|
|
from collections.abc import Iterable, Mapping
|
|
|
|
AXES: tuple[str, ...] = ("mode", "network", "distro", "filesystem", "architecture")
|
|
|
|
|
|
def _seconds(job: Mapping[str, object]) -> float | None:
|
|
"""Wall-clock of one job, or None when it never reached both timestamps."""
|
|
started = job.get("startedAt") or job.get("started_at")
|
|
completed = job.get("completedAt") or job.get("completed_at")
|
|
if not started or not completed:
|
|
return None
|
|
try:
|
|
begin = datetime.fromisoformat(str(started))
|
|
end = datetime.fromisoformat(str(completed))
|
|
except ValueError:
|
|
return None
|
|
span = (end - begin).total_seconds()
|
|
return span if span > 0 else None
|
|
|
|
|
|
def _values(label: axes.Label) -> dict[str, str]:
|
|
"""The axis values one parsed job title carries."""
|
|
return {
|
|
"mode": label.mode,
|
|
"network": label.network,
|
|
"distro": label.distro,
|
|
"filesystem": label.filesystem,
|
|
"architecture": label.architecture,
|
|
}
|
|
|
|
|
|
def samples(jobs: Iterable[Mapping[str, object]]) -> dict[str, dict[str, list[float]]]:
|
|
"""Durations of the deploy jobs, grouped by axis and by value.
|
|
|
|
Only successful jobs count. A failed job stops early or runs into a
|
|
timeout, so its duration measures the failure rather than the axis, and
|
|
these axes are picked between to reach a verdict cheaply.
|
|
|
|
Args:
|
|
jobs: jobs of one or more runs, as the GitHub API returns them.
|
|
|
|
Returns:
|
|
``{axis: {value: [seconds, ...]}}``; values that never appeared are
|
|
left out entirely.
|
|
"""
|
|
out: dict[str, dict[str, list[float]]] = {axis: {} for axis in AXES}
|
|
for job in jobs:
|
|
if _effective(dict(job)) != "success":
|
|
continue
|
|
label = axes.parse_label(str(job.get("name", "")))
|
|
if label is None:
|
|
continue
|
|
span = _seconds(job)
|
|
if span is None:
|
|
continue
|
|
for axis, value in _values(label).items():
|
|
if value:
|
|
out[axis].setdefault(value, []).append(span)
|
|
return out
|
|
|
|
|
|
def ranking(
|
|
grouped: Mapping[str, Mapping[str, list[float]]], axis: str, *, minimum: int = 3
|
|
) -> list[tuple[str, float, int]]:
|
|
"""One axis' values from cheapest to dearest.
|
|
|
|
Args:
|
|
grouped: :func:`samples` output.
|
|
axis: one of :data:`AXES`.
|
|
minimum: how many jobs a value needs before it is ranked at all. A
|
|
value seen once is a single observation, and steering a whole run
|
|
by it is how one queue wait becomes a policy.
|
|
|
|
Returns:
|
|
``[(value, median_seconds, sample_count), ...]``, cheapest first.
|
|
"""
|
|
rows = [
|
|
(value, statistics.median(spans), len(spans))
|
|
for value, spans in grouped.get(axis, {}).items()
|
|
if len(spans) >= minimum
|
|
]
|
|
return sorted(rows, key=lambda row: row[1])
|
|
|
|
|
|
def fastest(
|
|
grouped: Mapping[str, Mapping[str, list[float]]],
|
|
axis: str,
|
|
*,
|
|
among: Iterable[str] = (),
|
|
minimum: int = 3,
|
|
) -> str | None:
|
|
"""The cheapest value of *axis*, or None when nothing is measured enough.
|
|
|
|
Args:
|
|
grouped: :func:`samples` output.
|
|
axis: one of :data:`AXES`.
|
|
among: restrict the choice to these values; empty allows all of them.
|
|
minimum: as in :func:`ranking`.
|
|
|
|
Returns:
|
|
The value name, or None when no allowed value cleared *minimum*. None
|
|
is a real answer: the measurement cannot carry a pin, and the caller
|
|
leaves that axis to the rotation instead of guessing it.
|
|
"""
|
|
allowed = set(among)
|
|
for value, _median, _count in ranking(grouped, axis, minimum=minimum):
|
|
if not allowed or value in allowed:
|
|
return value
|
|
return None
|
|
|
|
|
|
def collect(*, runs_back: int, repo: str, branch: str) -> list[dict]:
|
|
"""Jobs of the last *runs_back* finished runs of *branch*.
|
|
|
|
Args:
|
|
runs_back: how many finished runs to read.
|
|
repo: ``owner/repo`` the branch lives on.
|
|
branch: branch whose runs are read.
|
|
"""
|
|
listed = json.loads(
|
|
_gh(
|
|
[
|
|
"run",
|
|
"list",
|
|
"--branch",
|
|
branch,
|
|
"--status",
|
|
"completed",
|
|
"-L",
|
|
str(runs_back),
|
|
"--json",
|
|
"databaseId",
|
|
],
|
|
repo=repo,
|
|
)
|
|
or "[]"
|
|
)
|
|
jobs: list[dict] = []
|
|
for entry in listed:
|
|
jobs += fetch_jobs(str(entry["databaseId"]), repo=repo)
|
|
return jobs
|
|
|
|
|
|
def _format(seconds: float) -> str:
|
|
return f"{int(seconds) // 60}m {int(seconds) % 60:02d}s"
|
|
|
|
|
|
def main(argv: list[str] | None = None) -> int:
|
|
parser = argparse.ArgumentParser(
|
|
prog="infinito administration deploy ci timings",
|
|
description=(
|
|
"Median wall-clock per axis value, read off the deploy jobs of "
|
|
"recent finished runs."
|
|
),
|
|
)
|
|
parser.add_argument("--runs", type=int, default=5)
|
|
parser.add_argument("--repo", default=None)
|
|
parser.add_argument("--branch", default=None)
|
|
parser.add_argument("--minimum", type=int, default=3)
|
|
args = parser.parse_args(argv)
|
|
|
|
repo = args.repo or resolve_repo()
|
|
branch = args.branch or current_branch()
|
|
grouped = samples(collect(runs_back=args.runs, repo=repo, branch=branch))
|
|
|
|
if not any(grouped[axis] for axis in AXES):
|
|
print(
|
|
f"No finished deploy job of {branch} in the last {args.runs} run(s) "
|
|
"carries both timestamps; nothing to rank.",
|
|
file=sys.stderr,
|
|
)
|
|
return 1
|
|
|
|
for axis in AXES:
|
|
rows = ranking(grouped, axis, minimum=args.minimum)
|
|
print(f"\n{axis}:")
|
|
if not rows:
|
|
print(f" no value reached {args.minimum} job(s)")
|
|
continue
|
|
for value, median, count in rows:
|
|
print(f" {value:<12} {_format(median):>8} {count} job(s)")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|