Pushing one number from a job that lives ten seconds

A scheduled CI job cannot be scraped, so the metric travels the other way — and every surprise waits on the receiving end.

Monitoring

The whole push

The MSISDN stock workflow runs daily, counts one number and exits (one curl, one gauge, no exporter and no port). The runner is gone long before any scrape interval comes round. A Pushgateway is the only route by which the value outlives the job:

METRIC_DATA="msisdn_stock_available{job=\"$JOB_NAME\",instance=\"$INSTANCE_NAME\"} $MSISDN_COUNT
"
curl -X POST \
  -H "Content-Type: text/plain" \
  --data-binary "$METRIC_DATA" \
  "$PUSHGATEWAY_URL/metrics/job/$JOB_NAME/instance/$INSTANCE_NAME"

if [ $? -eq 0 ]; then
  echo "Successfully pushed metrics to Prometheus Gateway"
else
  echo "Failed to push metrics to Prometheus Gateway"
  exit 1
fi

Three separate things in that block (eleven lines of sixty-one) are worth knowing before anyone copies it.

The labels you write get renamed on arrival

The grouping key comes from the URL path (/metrics/job/msisdn_stock_monitor/instance/wireless_fulfillment_scripts), so writing job= and instance= inside the metric line as well is duplication. What actually bites is downstream. Prometheus scrapes the gateway as an ordinary target under its own job name (job="pushgateway"). A scrape's own labels win unless honor_labels is set, so the pushed pair arrives carrying an exported_ prefix. The alert that consumes this gauge spells that out:

min(msisdn_stock_available{job="pushgateway",
    exported_instance="wireless_fulfillment_scripts",
    exported_job="msisdn_stock_monitor"}) <= 50000

Query msisdn_stock_available{job="msisdn_stock_monitor"} — the obvious thing, the string literally present in the push — and the result is empty, with no error to explain why.

The payload carries no type

There is no # TYPE msisdn_stock_available gauge line in the body (no # HELP either), so the series is exposed untyped. For a bare level that costs nothing on the day; it costs something the first time somebody reaches for rate() on a series the type system cannot object about. One line in the payload would have settled it.

The success check does not check success

curl without --fail exits 0 on an HTTP error (400, 404, 500 — the response body is printed and the exit status stays clean). A rejected push lands in the if [ $? -eq 0 ] branch and prints the success message. The job goes green, the gauge keeps serving its last value, and nothing says the number has stopped moving. The same eleven lines were copied verbatim into the wireless number-discrepancy check (CW-2822, ten weeks later), success message and all.

What the gateway gets wrong for free

A gauge on a Pushgateway never expires. It serves the last value pushed until something issues a DELETE on the group (/metrics/job/<job>/instance/<instance>), and nothing in this repository issues one. A dead workflow and a healthy stock level present the same series at the same value. So the low-stock alert only fires on a number that fell; it stays quiet about a number that stopped arriving.

In March 2026 the discrepancy check dropped the gateway for a Slack webhook (two steps, two conditions, one webhook URL out of vault). It keys on the check's exit status and on if: failure(). That is the right call for a pass/fail signal: it is an event, and events want a channel, not a time series. The stock gauge stayed where it was, because a level genuinely is a time series — what it needs beside it is a staleness alert, never a different transport.