Description
There's no way to see how far the deployed environments lag main without manually comparing commits. We want the infra dashboard (618457) to show, at a glance, how many commits staging and production are behind main, plus each environment's current commit, so the drift spotcheck becomes self-service.
Proposed approach
Do the git math at build time and let BetterStack do the subtraction. BetterStack already scrapes /metrics, so no exporter or external service is needed.
- At image build, compute commit height with
git rev-list --count HEAD and bake it into the image alongside the commit SHA and version.
- Emit Prometheus gauges from the backend:
dealbot_build_commit_height (integer height)
dealbot_build_info{commit, version} (info metric, value 1)
- optionally
dealbot_build_commit_timestamp for a "time behind" readout
- On the dashboard, a metric expression
height{env="staging"} - height{env="production"} gives the exact commits production is behind. Display each env's commit as a github.com/.../commit/<sha> link.
This is exact because every push to main deploys to staging and production is a release-please promotion of an older main commit, so production is always an ancestor of main on a linear squash history. Height delta equals commit count.
Implementation notes
- The
env label (staging/production) must come from runtime config, not the image. Production reuses the staging-built image via retag (release-please.yml), so a baked-in label would be wrong.
actions/checkout defaults to a shallow clone; set fetch-depth: 0 so rev-list --count sees full history.
Definition of done
- Dashboard 618457 shows commits-behind for staging and production and a clickable current-commit link per env.
- The number is verified against a known deploy (e.g. production N commits behind staging matches
git rev-list --count).
Context: Slack thread
Description
There's no way to see how far the deployed environments lag
mainwithout manually comparing commits. We want the infra dashboard (618457) to show, at a glance, how many commits staging and production are behindmain, plus each environment's current commit, so the drift spotcheck becomes self-service.Proposed approach
Do the git math at build time and let BetterStack do the subtraction. BetterStack already scrapes
/metrics, so no exporter or external service is needed.git rev-list --count HEADand bake it into the image alongside the commit SHA and version.dealbot_build_commit_height(integer height)dealbot_build_info{commit, version}(info metric, value1)dealbot_build_commit_timestampfor a "time behind" readoutheight{env="staging"} - height{env="production"}gives the exact commits production is behind. Display each env'scommitas agithub.com/.../commit/<sha>link.This is exact because every push to
maindeploys to staging and production is a release-please promotion of an oldermaincommit, so production is always an ancestor ofmainon a linear squash history. Height delta equals commit count.Implementation notes
envlabel (staging/production) must come from runtime config, not the image. Production reuses the staging-built image via retag (release-please.yml), so a baked-in label would be wrong.actions/checkoutdefaults to a shallow clone; setfetch-depth: 0sorev-list --countsees full history.Definition of done
git rev-list --count).Context: Slack thread