8.8b Metrics of a healthy pipeline (plain English)
Why: the problem
A manager at an Infosys client asks: "Is our delivery getting better or worse?" The team says "I think it is fine". That is a feeling, not an answer. Google's DORA research team studied thousands of companies and found four simple numbers that show the health of delivery. How often do we deploy? How long from commit to production? How often does a deploy cause a problem? How fast do we recover? Add two pipeline numbers: how long the pipeline takes and how often it is red. With these six numbers, a team can see if it is getting faster and safer, or not. You do not need a fancy tool to start. Your CI tool already has the data. You will pull it out with a few commands.
What we will build
You will measure six numbers for the badge API: deployment frequency, lead time for changes, change failure rate, time to restore, pipeline duration and pipeline success rate. You will get them from the GitHub CLI and GitLab API with small scripts, and put them in a weekly table.
What: every term in plain English
- Deployment frequency — How often you deploy to production. Daily is good; weekly is ok for many teams.
- Lead time for changes — Time from commit to running in production.
- Change failure rate — Percent of deploys that cause a problem and need a fix or rollback.
- Time to restore (MTTR) — How long it takes to fix production after a problem.
- Pipeline duration — How long one run takes. Under 10 minutes is a good target.
- Success rate — Percent of runs that are green.
- DORA — DevOps Research and Assessment, a research team at Google that defined the four key metrics.
- Median — The middle value. Better than the average when a few runs are very slow.
How: step by step
-
List recent runs as JSON
gh run list --workflow cicd.yml --limit 50 --json conclusion,createdAt,updatedAt,headSha > runs.jsonWhat it does: Raw data from your CI tool.
Output
(file runs.json) -
Count success rate
jq "[.[]|select(.conclusion==\"success\")]|length" runs.jsonWhat it does: How many of the last 50 are green.
Output
44 -
Get pipeline durations
python3 metrics.py runs.jsonWhat it does: Example 1 script prints median duration.
Output
median duration: 6.4 min -
Count prod deploys this week
gh api repos/ravi/badge-api/deployments -q "[.[]|select(.environment==\"production\")]|length"What it does: Each prod deploy job makes a deployment record.
Output
9 -
Log incidents
Add one line to incidents.csv for each prod problemWhat it does: Needed for change failure rate and time to restore.
Output
2026-10-21,a3f2c1d,35 -
Make the weekly table
python3 weekly.pyWhat it does: Example 3 prints all six numbers.
Output
deploys 9 lead 3.1h cfr 11% mttr 35m
Example 1: Pipeline duration and success rate from CI data
Stack. GitHub CLI, Python
Goal. Pipeline duration and success rate from CI data.
metrics.py
import json, sys, statistics
from datetime import datetime
def t(s):
return datetime.fromisoformat(s.replace("Z", "+00:00"))
runs = json.load(open(sys.argv[1]))
mins = [(t(r["updatedAt"]) - t(r["createdAt"])).total_seconds() / 60 for r in runs]
ok = sum(1 for r in runs if r["conclusion"] == "success")
print(f"runs: {len(runs)}")
print(f"success rate: {100 * ok / len(runs):.0f}%")
print(f"median duration: {statistics.median(mins):.1f} min")
print(f"slowest: {max(mins):.1f} min")
What each line does
json.load— Reads the list from gh run list.updatedAt - createdAt— Time for one run.statistics.median— The middle value, not fooled by one very slow run.success rate— Green runs divided by all runs.
Green output
$ python3 metrics.py runs.json
runs: 50
success rate: 88%
median duration: 6.4 min
slowest: 19.2 min
Expected result. 88 percent green and 6.4 minutes is healthy. If success falls under 80 percent, look for flaky tests.
Example 2: Lead time: commit time to deploy time
Stack. GitHub CLI, GitLab API, Bash
Goal. Lead time: commit time to deploy time.
lead_time.sh
#!/usr/bin/env bash
set -euo pipefail
for sha in $(gh api repos/ravi/badge-api/deployments -q '.[] | select(.environment=="production") | .sha' | head -10); do
c=$(git show -s --format=%ct "$sha")
d=$(gh api repos/ravi/badge-api/deployments -q ".[] | select(.sha==\"$sha\") | .created_at" | head -1)
d=$(date -d "$d" +%s)
echo "$sha $(( (d - c) / 60 )) min"
done
GitLab version
curl -s --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
"https://gitlab.example.com/api/v4/projects/42/deployments?environment=production&per_page=20" \
| jq -r '.[] | [.sha[0:7], .created_at] | @tsv'
What each line does
git show -s --format=%ct— Commit time in seconds.created_at— When the prod deploy happened.(d - c) / 60— Lead time in minutes.GITLAB_TOKEN— A token in your shell env, never written in the script.
Green output
a3f2c1d 182 min
91be0aa 95 min
7c1e0b2 240 min
median lead time: 182 min (about 3 hours)
Expected result. Under one day is strong. If most time is waiting for approval, that is the place to improve.
Example 3: A weekly six-number table
Stack. Python
Goal. A weekly six-number table.
incidents.csv
date,sha,minutes_to_restore
2026-10-21,a3f2c1d,35
weekly.py
import csv
deploys = 9
lead_hours = 3.1
failed = list(csv.DictReader(open("incidents.csv")))
cfr = 100 * len(failed) / deploys
mttr = sum(int(r["minutes_to_restore"]) for r in failed) / max(len(failed), 1)
print("| metric | this week |")
print("|---|---|")
print(f"| deploys to prod | {deploys} |")
print(f"| lead time | {lead_hours} h |")
print(f"| change failure rate | {cfr:.0f}% |")
print(f"| time to restore | {mttr:.0f} min |")
print("| pipeline median | 6.4 min |")
print("| success rate | 88% |")
What each line does
incidents.csv— One line per prod problem caused by a deploy.cfr— Failed deploys divided by all deploys.mttr— Average minutes to restore.max(len, 1)— Avoids divide by zero in a quiet week.
Green output
| metric | this week |
|---|---|
| deploys to prod | 9 |
| lead time | 3.1 h |
| change failure rate | 11% |
| time to restore | 35 min |
| pipeline median | 6.4 min |
| success rate | 88% |
Expected result. Paste this in the weekly team note. Watch the trend over weeks, not one number.
Verify: did it work?
-
Check numbers by hand once
Count prod deploys in the CI Environments pageWhat it does: Should match the script.
Output
9 deployments this week -
Check one lead time
Compare commit time and deploy time for one shaWhat it does: Should match the script within a minute.
Output
a3f2c1d: 182 min
When it is red 1
gh: Not Found (HTTP 404)
Cause. Wrong owner or repo name, or the token cannot read deployments.
Fix, step by step
- Check gh repo view works.
- Run gh auth status and check the token scopes.
When it is red 2
ZeroDivisionError: division by zero
Cause. No deploys or no runs in the period.
Fix, step by step
- Guard with max(count, 1).
- Or print "no data this week".
When it is red 3
Success rate 40 percent
Cause. Many red runs, often flaky tests or a broken main.
Fix, step by step
- Group failures by job name.
- Fix the top failing job first.
Cleanup
-
Remove raw data files
rm -f runs.jsonWhat it does: Keep only the weekly table.
Output
(no output)
Practice tasks
Easy Count green runs
Why: Start simple.
What to do: Count green runs of the last 20.
- Use gh run list.
Check: You have a percent.
Medium Find the slowest job
Why: Fix the right thing.
What to do: List job durations of one run.
- gh run view RUN_ID --json jobs
Check: You name the slowest job.
Hard Trend for four weeks
Why: See direction.
What to do: Make the table for four weeks.
- Plot lead time.
Check: You can say better or worse.
Easy Say pipeline health metrics in two lines
Why: If you can say it simply, you understand it. Juniors and interviewers both want the short version first.
What to do: Write two short lines about pipeline health metrics for a fresher who knows only Linux, Git and Docker basics.
- Write the problem it solves.
- Write the one pipeline line or command you use for it.
- Read it aloud to a friend.
Check: A fresher understands it without asking a question.
Easy Keep a throwaway lab repo
Why: Practice needs a repo you can break. If it gets messy, you delete it and start again.
What to do: Make a small practice repo called badge-api with one Python file, one test and one Dockerfile.
- mkdir badge-api and cd into it
- git init -b main
- Add app.py, test_app.py and Dockerfile from this chapter, then commit.
Check: git log shows one commit and pytest prints 1 passed.
Medium Do it in a second CI tool
Why: CI/CD is the idea. The tool is only the syntax. The same stages must work in GitHub Actions, GitLab CI and Jenkins.
What to do: Write the pipeline from this lesson in a second CI tool.
- If you used GitHub Actions, write .gitlab-ci.yml or a Jenkinsfile now.
- Keep the same stage names and the same commands.
- Only the wrapper syntax should change.
Check: Same green result, same stage names, different tool.
Medium Break it on purpose
Why: You must know the red log by face. In a real outage there is no time to read slowly.
What to do: Cause one error from the "When it is red" part of this lesson and fix it.
- Follow the error section.
- Copy the exact red line from the job log into your notes.
- Write the fix in one line.
Check: You fixed it using only the steps, without searching the web.
Medium Write a one-page runbook
Why: At 2 a.m. nobody remembers pipeline menus. A short page saves the on-call person.
What to do: Write a one-page runbook for this lesson.
- Title, when to use, exact steps or pipeline lines, how to check, how to undo.
Check: A teammate can follow it alone.
Hard Explain it like an interview
Why: Interviewers want real stories, not definitions.
What to do: Record a 60 second answer about this lesson.
- Say the problem, the pipeline lines you wrote, and one error you hit.
Check: Your answer has a real pipeline line and a real error message.
Hard Draw the flow top to bottom
Why: A drawing shows the order of work and which stage waits for which.
What to do: Draw this lesson as boxes from top to bottom.
- Start at git push, go through each stage, end at the green run or the deployed app.
Check: Each box matches a real line in your job log.
Homework: try at home
Try at home
At home, pull the last 50 runs of your repo, compute success rate and median duration, and write a six-number table for one week.
Recap
- Four DORA metrics plus pipeline time and success rate.
- The data is already in your CI tool.
- Use the median, watch trends.
- Log incidents to get failure rate and restore time.
- Improve the slowest part first.
FAQ
Is more deploys always better?
Small, frequent deploys are safer, but only with good tests.
Do I need a dashboard tool?
No. Start with a script and a table.
Who should see these numbers?
The whole team. They are not for blaming people.
What is elite performance?
DORA reports call on-demand deploys, under a day lead time and under an hour restore elite.
Should I track lines of code?
No. It says nothing about delivery health.
Interview questions
-
What are DORA metrics?
Deployment frequency, lead time for changes, change failure rate and time to restore service.
-
How do you measure lead time?
Time from commit to that commit running in production, using commit and deployment timestamps.
-
How would you improve lead time?
Smaller changes, faster pipeline, fewer manual waits, automatic deploys to staging.
-
What does a high change failure rate tell you?
Tests or reviews miss problems. Add tests, canaries and smaller changes.
-
Why use median instead of average?
Outliers like one stuck run distort averages.
Quick quiz
Q1. Name the four DORA metrics.
Deployment frequency, lead time, change failure rate, time to restore.
Q2. Why use the median?
One very slow run does not distort it.
Q3. What is change failure rate?
Percent of deploys that cause a problem.
Q4. What is a good pipeline time?
Under about 10 minutes.
Q5. Where does the data come from?
The CI tool runs and deployments APIs.
Did you understand? Let us try it once more.
Revision card
Interview card