Measuring DevOps

Measure the four DORA metrics from GitLab and OpenShift. Deployment frequency, lead time, change failure rate and recovery time.

Updated CompTech Team

You cannot tell whether a platform change helped if you only have a feeling that releases are "faster". The DORA research programme settled on four numbers that describe how a team delivers software. This lab defines each one so two people compute it the same way, and pulls the raw timestamps from GitLab and OpenShift.

It does not include target numbers. A good result depends on the system. Record the four values, change one thing, and record them again.

Prerequisites

  • A GitLab project whose main branch deploys to production, as in the GitLab CI lab
  • A personal access token with read_api on that project
  • oc, and the production Deployment's rollout history

The four metrics

Metric Definition we use Timestamp source
Deployment frequency Successful production deploys in a week GitLab pipelines on main whose release job succeeded
Lead time for changes Commit time to the production deploy of that commit committed_date on the commit, finished_at on the release job
Change failure rate Share of those deploys that were rolled back or needed a hotfix oc rollout history and revert commits on main
Recovery time From the failed deploy's finish to the restoring deploy's finish The two jobs' finished_at values

DORA's earlier reports called the fourth metric mean time to restore. Current reports call it failed deployment recovery time. We measure the failed deploy, not every incident that can happen to a system.

Count a deploy once per pipeline that changed production. A pipeline that only built an image does not count. A rollback counts as a failure of the deploy it undid, and the restoring deploy is the end of the recovery clock, not a second success.

Lead time and frequency from the API

This script prints one line per successful release job on main in the last seven days: the pipeline id, the lead time in hours, and the finish time. It does not decide whether the week was good.

GITLAB=https://gitlab.apps.example.com
PID=42
SINCE=$(date -u -d '7 days ago' +%Y-%m-%dT%H:%M:%SZ)
curl -s --header "PRIVATE-TOKEN: $GL_TOKEN" \
  "$GITLAB/api/v4/projects/$PID/pipelines?ref=main&status=success&updated_after=$SINCE&per_page=100" \
  | jq -r '.[].id' | while read -r id; do
      job=$(curl -s --header "PRIVATE-TOKEN: $GL_TOKEN" \
        "$GITLAB/api/v4/projects/$PID/pipelines/$id/jobs" \
        | jq -r '.[] | select(.name=="release" and .status=="success")')
      [ -z "$job" ] && continue
      sha=$(curl -s --header "PRIVATE-TOKEN: $GL_TOKEN" \
        "$GITLAB/api/v4/projects/$PID/pipelines/$id" | jq -r .sha)
      committed=$(curl -s --header "PRIVATE-TOKEN: $GL_TOKEN" \
        "$GITLAB/api/v4/projects/$PID/repository/commits/$sha" | jq -r .committed_date)
      finished=$(jq -r .finished_at <<<"$job")
      python3 -c 'import sys,datetime
a,b=sys.argv[1:3]
f=lambda s: datetime.datetime.fromisoformat(s.replace("Z","+00:00"))
print(int(sys.argv[3]), round((f(b)-f(a)).total_seconds()/3600, 2), b)' \
        "$committed" "$finished" "$id"
    done

Deployment frequency is the number of lines. Lead time for the week is the median of the hour values, not the mean. One stalled feature should not disappear into an average, and it should not dominate it either. The median is the middle pipeline.

Failures and recovery

A failed change is a production deploy that you reverted. The evidence is one of these:

  • oc rollout undo appears in oc rollout history deployment/payments -n payments-prod for that revision
  • A later pipeline whose commit message reverts the release commit
  • A hotfix pipeline opened specifically to repair that release
oc rollout history deployment/payments -n payments-prod

Recovery time for one failure is the finished_at of the restoring release job minus the finished_at of the failed one. The weekly number is the median of those durations. If you had no failed deploys, write that down. A blank cell hides the difference between "we did not measure" and "nothing failed".

Change failure rate is the count of failed changes divided by the deployment frequency for the same week. Keep the fraction as counts in the notes as well as a ratio, so a quiet week is not compared blindly with a busy one.

A pipeline that built an image and never deployed it does not count. A rerun of a failed job in the same pipeline does not count as a second deploy. A rollback counts once, as the failure of the deploy it undid, and the restoring deploy closes the recovery clock. Counting the restoring deploy as a success as well makes a bad week look busy and healthy.

Write the week as counts first, then as the four summary numbers. The counts are what you will argue about. The summary is what you will plot.

Make it boring

Record the four numbers in the same place every week, with the queries above, not from memory. A short table is enough: week, deploys, median lead time, failed changes, median recovery time.

When you change the platform, change one thing and read the next four weeks against the previous four. A template from Developer Hub should shorten lead time if setup was the delay. A canary from deployment strategies should shorten recovery time if you used to notice failures late. If the number you hoped to move does not move, the bottleneck is somewhere else. Find that, rather than adding another tool.

What's next

  1. The timestamps come from the release job in GitLab CI.
  2. A rollback you can actually perform is part of deployment strategies.
  3. Failing the build on a bad image, which changes failure rate, is DevSecOps.