← Statpro dev log

Read-only diagnostics for a migration I couldn't see fail

#automation#infra#data

A caliper clamps one glowing amber block in a row of seven dim blocks, measuring it without moving the others.

My production database migration failed somewhere I couldn't see from the outside. The failure sat between the CI workflow that starts a migration and the container job in my cloud account where it actually runs. I needed to look at what that one failed run saw without changing anything.

One read-only workflow, eight commits

Statpro is a sports stats and betting-research site, and its database changes ship through that migration pipeline. I started with a single read-only workflow that validates one exact failed run. It took eight commits to get into shape, and the ones that mattered each narrowed what the workflow could look at:

  • Split the lookups by domain, so each step runs one query.
  • Scope each read to exactly the one definition it needs.
  • Bind the workflow to a single pipeline.
  • Check the container image's layer references, including ones that repeat.
  • Put the network facts the job actually saw into the output file.

Refuse to run on anything unexpected

Every step checks its inputs against exact expected values before doing any work. The commit must be a full 40-character hex SHA, and the failed run's id is pinned to a literal. Anything else stops the run:

set -euo pipefail
[[ "$APPROVED_SHA" =~ ^[a-f0-9]{40}$ ]] || fail
[[ "$FAILED_EXECUTION" == "execution-12345" ]] || fail
# stop here if anything does not match
artifact_dir="$(mktemp -d)"

Here "execution-12345" stands in for the real run id. That strictness is what makes it safe to point a diagnostic at production. It can't wander to a different run, and it reports only the facts I asked for.

Build the smallest window that shows the failure

A broad debugging tool for production is hard to review, and a hard review is one I'll put off. A tool that reads one thing about one failure is easy to check and easy to throw away. When I can't see why something failed, I build the smallest read-only window onto it and tighten that window until it shows only the facts I need.

This is the build log for Statpro (statpro.io) · All entries · Weekly essays