CI metrics and failure triage
A minimal set of CI metrics: duration in percentiles p50 and p90/p95, flaky rate from retries, pass rate of main and time to restore a green main. A metric is useful only if it has an owner and a threshold. Mass failures are grouped by message and stack, since 30 red tests usually have two or three causes, and then classified.
CI · Metrics and triage
Nightly: 30 red tests. Open them one by one or is there a faster way?
In the morning the nightly run shows 30 red tests. Opening them one by one takes half a day, and there are usually two or three causes. A pipeline is a product too, and its quality shows in numbers: how long it runs, how often it lies, how fast green is restored on main. The lesson covers a minimal set of CI metrics and the order for investigating mass failures.
Which metrics and why
- Duration: p50 and p90/p95, not only the average. The average hides the long tail that annoys the team. Runner queue wait is measured separately.
- Flaky rate: the share of test runs that passed only on a retry out of all test runs in a period. The weekly trend and the top most unstable tests are watched.
- Pass rate of the main branch and the share of red PRs caused by non-code: infrastructure or flakiness.
- MTTR of a red main: how fast green is restored.
- Cost: runner minutes per PR, artifact size.
Where to get the data: the Playwright JSON reporter (stats.flaky is the number of tests with the flaky status) or JUnit XML, plus your CI's API. A metric is useful only if it has an owner and a threshold after which something is done.
Triage: the order
Investigating 30 failures
An example: of 30 failures 22 share "net::ERR_CONNECTION_REFUSED on staging", 6 fell on one locator after a button release, 2 are one-off timeouts. That is three causes: infrastructure, a test (or product) defect, flakiness. Tickets and owners differ, and different people should handle them.
// grouping failures from a JSON report: count by the start of the message
type Suite = { specs?: Spec[]; suites?: Suite[] };
type Spec = { tests: { results: { status: string; error?: { message?: string } }[] }[] };
const groups = new Map<string, number>();
const walk = (s: Suite) => {
for (const spec of s.specs ?? [])
for (const test of spec.tests)
for (const r of test.results)
if (r.status === 'failed' || r.status === 'timedOut') {
const key = (r.error?.message ?? 'no message').split('\n')[0].slice(0, 80);
groups.set(key, (groups.get(key) ?? 0) + 1);
}
(s.suites ?? []).forEach(walk);
};
report.suites.forEach(walk);
console.table([...groups].sort((a, b) => b[1] - a[1]));
The first rows of the table show the main cause at once. The script is crude: messages with different numbers or ids will fall into different groups, so they are worth normalising (replace numbers and identifiers). Even this version saves most of the time.
What to do with each class
- Product defect: a ticket to developers with the trace.
- Test defect: locator, race, data: a fix or quarantine with an owner and a deadline.
- Infrastructure: a re-run and a ticket to the platform, not "raise the timeout".
Limits and mistakes
- The difference between "red because of a bug" (the test did its job) and "red because of noise". If they are not told apart, the team learns to ignore red.
- A retry that "cures" flakiness masks the flaky rate: it must be counted from retries, not only from the final status.
- Collecting metrics without a threshold and an owner turns into a dashboard nobody opens.
Check yourself
Why is p90/p95 used for pipeline duration instead of the average?
Answer
The average hides the long tail: most runs are fast, but every tenth takes twice as long and that is the one the team remembers. Percentiles show the tail.
30 tests failed after a deploy. What is the first investigation step and why not open them one by one?
Answer
Group by message and stack: 30 failures usually come down to 2-3 causes, so you investigate causes, not tests.