Documentation
¶
Overview ¶
Package timing is the machine behind the committed script cmd/nova-ci/timing.go, which prints one pull request's time from open to all-green split into queue, setup and test per job, for the last 200 pull requests of the project's own repositories.
The measurement reads a harvested events log: one JSON object per line, one line per CI job of one pull request, carrying the moments the forge reported -- when the PR opened, when the job was queued, when it left the queue, when setup finished and testing began, and when it finished, plus whether it was green. The three spans of a job are the job's own: queue is queued to started, the wait for a runner; setup is started to setup-done; test is setup-done to done. A PR's open-to-all-green is the envelope from its open to the latest done among its jobs, and it exists only when every one of the PR's jobs is green -- a PR still red or still open has no all-green, and its rows print "-" for it, the same reading the measured size tables give a size they refuse to guess downward.
The package is deterministic on purpose: no clock, no network, no map order in the output. The same log renders byte-for-byte the same table, and re-running the script reproduces the committed table -- that is the whole point, and TestTimingTableReproduces holds the script's own output against the table committed beside it.
Index ¶
Constants ¶
const DefaultLast = 200
DefaultLast is how many pull requests per repository the script measures when --last is not given.
Variables ¶
var DefaultRepos = []string{"example-account/nova-tools", "example-account/schema"}
DefaultRepos are the repositories the script measures when --repos is not given: the two the card names, schema and nova-tools.
Functions ¶
Types ¶
type Event ¶
type Event struct {
Repo string `json:"repo"` // <owner>/<name>
PR int `json:"pr"` // the pull request's number
Job string `json:"job"` // the job's name, as the forge prints it
Opened string `json:"opened"` // when the PR opened
Queued string `json:"queued"` // when the job entered the queue
Started string `json:"started"` // when the job left the queue
SetupDone string `json:"setup_done"` // when setup finished and testing began
Done string `json:"done"` // when the job finished
Green *bool `json:"green"` // whether the job finished green
}
Event is one line of the harvested log: one CI job of one pull request, with the moments the forge reported. Times are RFC 3339 in UTC; Done and Green must be stated -- a job still running is not in the harvest yet, and a line that does not say whether its job was green is a line the table cannot use.
func Load ¶
Load reads the harvested events log, one JSON object per line, and refuses what a table cannot use: a line that is not JSON, a field missing or a time unparseable, a clock that runs backwards, and a job named twice. A blank line is skipped. Every refusal names its line, so a bad harvest is a one-line fix and not a hunt.
func Select ¶
Select keeps the events of the named repositories and, per repository, of the last `last` pull requests the log holds -- the `last` greatest distinct PR numbers, the log's own ordering of recency (numbers may have gaps). A pull request is selected WHOLE, every line of it or none, because a table that dropped one job of a PR it kept would invent an all-green the forge never reported. A `last` of zero or less keeps everything.
type Row ¶
type Row struct {
Repo string
PR int
Job string
Opened time.Time
Queue time.Duration
Setup time.Duration
Test time.Duration
AllGreen bool
AllGreenAt time.Time
}
Row is one line of the rendered table. Queue, Setup and Test are one job's own spans; Opened, AllGreen and AllGreenAt are its pull request's: AllGreen is true only when every job of the PR was green, and AllGreenAt is the moment it went all-green, the latest Done among its jobs.