livery.workshop._metrics¶
livery.workshop._metrics ¶
Timing rows on the CI state store, and the reader that renders them.
One row per job per run, one file per run on the metrics series
of the state store (livery.git), named by zero-padded
run id so that name order is time order. A row is end to end, not
gate-only: the queue wait, the job's wall, and every step's wall as
the forge times them, beside the per-task durations and lane waits
the leg's own trace recorded, and the test time per package summed
from the trace's pytest slices.
Three writers, all inside CI. Each check leg ends with put_leg: it
reads the trace the profiled gate wrote and puts the task half of
its row on the leg's per-run ref, in one write with every file the
leg's other entries left in its spool (LEG_SPOOL); a leg that ran
as one shard of several carries the record it left of what it
partitioned in the row, under shard; a write that fails is a red
leg. The run's gate job first folds each platform's shards into one
ref (livery.workshop._fold), then runs collect: it reads the
per-run refs, asks the forge for the run's jobs, joins the two
halves, folds in the sections the job's judges left (RUN_ROW),
puts the run's file on the series under its window, and writes each
check leg's seconds per item onto its platform leg's series of
the livery.workshop.DURATIONS family; it fails open loudly, a
printed reason and never a red job. The run's last green job runs
drop_halves: the per-run refs go once every job that writes a half
has completed green, so a re-run of a red gate job still finds what
its legs put, and a point with no gate job, where every job puts a
half and collects, keeps each job's half until the last one has
folded it in. Local runs read: render is what fm ci.timings
prints, the latest value, p50, and p90 per metric over the window, a
platform that ran as shards as one section with a line per shard, the
movers against a base window, and each section's trend.
Functions:
| Name | Description |
|---|---|
write_leg_bundle |
Write label's leg files into |
run_leg_dirs |
Every collected leg directory under |
read_leg_json |
Read filename from leg_dir as a JSON object; |
read_all_leg_files |
Read every |
drop_leg_dir |
Remove one collected leg directory under |
run_ref |
The per-run ref one leg of run writes. |
leave_leg_file |
Leave data in the leg's spool as name, for the leg's one write. |
leg_files |
The files the leg's entries left in its spool, by name; or why one cannot ride. |
leave_section |
Leave a section of the run's row, a number per package, for the gate job. |
sections |
The sections the gate job's entries left, by name; a malformed file is left out. |
leg_row |
The task half of job's row from its trace; |
put_leg |
Put job's task half and the leg's spool on its per-run ref, in one write. |
run_file |
The series file for run_id (and attempt): sorted by time and attempt. |
collect |
Join the legs' halves with the forge's times into the run's file; what happened. |
drop_halves |
Drop the run's per-run refs once every half is in and nothing is red. |
gate_steps |
The gate's steps of a leg's row by task key, in milliseconds. |
tests_ms |
The test time summed over packages, a row's |
first_shard_head |
The item seconds the first shard's unsplit steps stand for on row. |
render |
The timings, rendered: per job and metric the latest, p50, p90, and the movers. |
Attributes:
| Name | Type | Description |
|---|---|---|
SCHEMA |
|
|
SERIES |
|
|
RUNS |
Keyed
|
|
ROW_FILE |
|
|
LEG_SPOOL |
|
|
RUN_LEGS |
|
|
RUN_ROW |
|
|
SLOWEST |
|
|
GATE_STEPS |
|
|
TEST_PHASE |
|
RUNS
module-attribute
¶
write_leg_bundle ¶
Write label's leg files into .workshop/run-legs/<slug>/.
Replaces any prior files for label so reruns never mix stale
artifacts. Stamps when and schema on each JSON object when
absent so readers see the same metadata the store series stamped.
Source code in packages/workshop/src/livery/workshop/_metrics.py
run_leg_dirs ¶
Every collected leg directory under .workshop/run-legs/, sorted by slug.
Source code in packages/workshop/src/livery/workshop/_metrics.py
read_leg_json ¶
read_leg_json(leg_dir: Path, filename: str, *, expected_schema: int | None = SCHEMA) -> tuple[dict[str, Any] | None, str]
Read filename from leg_dir as a JSON object; (None, '') if absent.
Returns a non-empty error string naming the leg and file if the file exists but cannot be read, does not parse as JSON, is not a JSON object, or carries a schema other than expected_schema.
Source code in packages/workshop/src/livery/workshop/_metrics.py
read_all_leg_files ¶
Read every *.json file in leg_dir; returns (rows, skipped, error).
Any non-JSON file is reported in skipped; any malformed *.json
file returns an error string naming the leg and file.
Source code in packages/workshop/src/livery/workshop/_metrics.py
drop_leg_dir ¶
Remove one collected leg directory under .workshop/run-legs/.
run_ref ¶
run_ref(run: RunContext, leg: str) -> str
leave_leg_file ¶
Leave data in the leg's spool as name, for the leg's one write.
The leg's last entry, ci.leg, puts every file the spool holds
on the leg's per-run ref, a series of livery.workshop.RUNS,
beside its timing row and under its own name, where the gate job
reads it. That write refuses a file named row.json, the timing
row's own name. A file left twice under one name keeps the last
data.
Returns:
| Type | Description |
|---|---|
Path
|
The path of the file left under root. |
Source code in packages/workshop/src/livery/workshop/_metrics.py
leg_files ¶
The files the leg's entries left in its spool, by name; or why one cannot ride.
A file that is not a JSON object, or one named as the leg's own row, refuses by name: the write would carry what no reader takes.
Source code in packages/workshop/src/livery/workshop/_metrics.py
leave_section ¶
Leave a section of the run's row, a number per package, for the gate job.
The gate job's ci.metrics.collect entry, before its verdict,
folds every section left at root into the run's file on the
metrics series, and fm ci.timings renders each as a trend, the
numbers followed by unit. A section left twice under one name
keeps the last numbers.
Returns:
| Type | Description |
|---|---|
str
|
The line to print, naming the section and how many packages |
str
|
it holds. |
Source code in packages/workshop/src/livery/workshop/_metrics.py
sections ¶
The sections the gate job's entries left, by name; a malformed file is left out.
A section is its unit and a number per package.
Source code in packages/workshop/src/livery/workshop/_metrics.py
leg_row ¶
The task half of job's row from its trace; (row, "") or (None, reason).
The trace is the Chrome trace the profiled gate wrote: every
task's slice (its request address and duration), the lane waits,
each step inside its task, and each pytest phase of every test as
a slice of its own. A step is a slice nested in its task, or an
async pair (a begin and an end under one id) where it overlaps a
sibling on the task's track, which is how footman draws the steps
of one parallel() block; both read as the step's whole wall.
The row's items is the seconds each item took, the test file
of each test's node id, every phase of every test in it summed, to
a tenth. A missing or unreadable trace is a reason, never a row.
Source code in packages/workshop/src/livery/workshop/_metrics.py
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 | |
put_leg ¶
Put job's task half and the leg's spool on its per-run ref, in one write.
Returns the lines to print and why the write failed, "" when
it landed or there was nothing to write. The row is read from
trace (livery.workshop._metrics.leg_row), with the scope the
gate ran; a trace that cannot be read leaves the row out, says
why, and the spool's files go alone. A leg that ran as one shard
of several left what it partitioned in SHARD_FILE
(livery.workshop.read_shard), and the row carries that record
under shard for the gate job's fold; a leg that is one shard
of one leaves no such file and its row carries no shard. Every
file the leg's entries left in LEG_SPOOL rides beside the row
under its own name (livery.workshop._metrics.leg_files), so
the leg writes its ref once. A leg without a label, a shard file
that is not a record, and a spool file no reader takes, fail the
write by name.
Source code in packages/workshop/src/livery/workshop/_metrics.py
run_file ¶
The series file for run_id (and attempt): sorted by time and attempt.
Attempt 1 (or an absent attempt) keeps the plain <padded>.json
spelling; a rerun (attempt 2, 3, ...) appends _a<padded> before
.json so . (46) sorts before _ (95) and earlier attempts'
rows stay in the series in chronological order.
Source code in packages/workshop/src/livery/workshop/_metrics.py
collect ¶
collect(root: Path, repo: Repository, run: RunContext, *, sha: str, verdict: str = '', trigger: str = '') -> list[str]
Join the legs' halves with the forge's times into the run's file; what happened.
Every line names what was done or why not. Nothing is written
when neither a leg nor the forge has a job to record; a red run
whose legs failed before writing halves still writes its row from
the forge's jobs with verdict set to red, and writes no
durations. The per-run refs stay: drop_halves
takes them once every half is in, so a re-run of a red gate job
still unions what its legs put, and a point whose every job
collects folds each earlier job's half into its own write. A job
the forge does not know keeps its trace half and is named; a row
of another schema is skipped and named. The run is looked up
under the head the runner's event names (_forge_jobs); sha
is the checkout, the fallback and the row's own record. Every
job the forge lists is recorded, the legs with their traces, the
others with their forge times alone, and the run's own wall from
its start to this collection. A platform that ran as shards has
one row, folded under the platform's display name before the
collect (livery.workshop._fold), a name the forge never ran:
the row takes the forge times of the first shard's job and
concludes as the shards' jobs did, and the forge's rows of the
shards stand beside it with their times alone, for
fm ci.timings. After a green run's file lands, each check leg's
seconds per item go onto its platform leg's series of the
livery.workshop.DURATIONS family, one row per run, which the
next run's shards partition by; a leg without them writes none,
and a refused write is a line.
Source code in packages/workshop/src/livery/workshop/_metrics.py
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 | |
drop_halves ¶
drop_halves(root: Path, repo: Repository, run: RunContext, *, sha: str, job: str, writers: tuple[str, ...]) -> list[str]
Drop the run's per-run refs once every half is in and nothing is red.
Runs as the last entry of a job that collected, after its own
verdict, so its own job is green when it runs and is left out of
the question. writers names the jobs that put a half, as the
schedule spells them (check); a forge job answers to a writer
by its display name's prefix (check (ubuntu-latest, 3.14)).
The refs stay, and the lines say so, while a writer other than
job has not completed green or any completed job is red: a
re-run of a red job finds what the legs put, and the last of a
point's collecting jobs is the one that drops. A job the forge
does not list, or a run it does not know, keeps the refs too; the
janitor's six-hour sweep is the net under every kept ref.
Source code in packages/workshop/src/livery/workshop/_metrics.py
gate_steps ¶
The gate's steps of a leg's row by task key, in milliseconds.
The row's tasks and the steps its tasks ran (task_steps) whose
key GATE_STEPS matches; a key in both is read from the tasks.
Source code in packages/workshop/src/livery/workshop/_metrics.py
tests_ms ¶
The test time summed over packages, a row's packages, in milliseconds.
Source code in packages/workshop/src/livery/workshop/_metrics.py
first_shard_head ¶
The item seconds the first shard's unsplit steps stand for on row.
The unsplit steps are the gate's steps outside the test phase
(TEST_PHASE); only a platform's first shard runs them, and the
folded row of a platform's shards carries the first shard's steps.
Because fm check runs static steps concurrently, the head uses the
actual wall-clock duration W of the unsplit steps (unsplit_ms from
the trace's interval union, or the first shard's non-test wall bounded
between the longest single unsplit step and their sum) rather than
their sequential sum. The partition packs item seconds, and a second
of a shard's test wall holds p of them, p being the parallelism its
tests reach, so the head is W times p. p is the median, over the
shards after the first that the folded row lists under shard, of
each one's summed test time over its wall; with no such shard, the
row's own summed test time over its test steps' wall. When neither
reads, the head is W itself, the least the first shard's tests wait.
Returns:
| Type | Description |
|---|---|
float | None
|
The head, to a tenth of a second; |
float | None
|
no unsplit step. |
Source code in packages/workshop/src/livery/workshop/_metrics.py
render ¶
The timings, rendered: per job and metric the latest, p50, p90, and the movers.
The window is every run the series holds. The latest since runs are the recent side; the base runs before them are the base the movers compare against, by the change of the recent median over the base median. A platform that ran as shards is one section, its folded row, and under its metrics one line per shard with the shard's wall and queue times from the newest run, read from the forge's own rows of the shards; those rows are no sections of their own, and the movers read the platform legs alone. Nothing yet, an unreadable series, and a row of another schema each say so.
Source code in packages/workshop/src/livery/workshop/_metrics.py
1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 | |