A stock gauge that counts files, not subscribers
A daily count of unallocated MSISDNs, where the thing being counted is text files in a git repository.
What the workflow is
.github/workflows/msisdn-monitoring.yml is 61 lines. It wakes on a cron (0 8 * * *, daily,
plus workflow_dispatch so it can be run by hand), checks the repository out at ref: master,
runs one command and pushes one number:
- name: Count available MSISDNs
id: count_msisdns
run: |
cd msisdns-for-sim-batch/
MSISDN_COUNT=$(./msisdn-calculator-linux-amd64 -remaining \
| grep "Remaining MSISDNs" | awk '{print $3}')
echo "msisdn_count=$MSISDN_COUNT" >> $GITHUB_OUTPUT
The workflow is mine; the calculator is not. msisdn-calculator is a small Go CLI a colleague
added in January 2024 (-count -sim-batch to allocate, -remaining to count) to stop two
people handing the same number to two different SIM batches. My part was making its output a
time series instead of something you read over a colleague's shoulder.
What -remaining means
Two lines of Go decide the whole metric:
remainingCount := len(allMSISDNs) - len(usedMSISDNs)
fmt.Printf("Remaining MSISDNs %d\n", remainingCount)
allMSISDNs is every number in stock/ (7 files); usedMSISDNs is every number in used/
(93 files, one per SIM batch). The gauge is a difference of two line counts over committed
text — a measurement of the repository instead of the subscriber database or the warehouse.
That is a weaker claim than "available MSISDNs", and it is the claim the tool's own README
already makes. Pull first, it says, because somebody may have pushed an allocation since your
last commit. Push the new batch file straight away, or a double allocation happens.
The workflow inherits that constraint whole. It checks out master, so a batch allocated but
still unpushed stays invisible to it, and the gauge reads high until the push lands.
What picked it up
A week later the number acquired an alert, which came from someone else. Under CW-2625 a rule went into the wireless alerts repository:
Low MSISDN Stock Alert:
prometheus_expression: 'min(msisdn_stock_available{job="pushgateway",
exported_instance="wireless_fulfillment_scripts",
exported_job="msisdn_stock_monitor"}) <= 50000'
prometheus_for: "5m"
destination: "slack"
Allocations recorded in used/ run from 5 numbers to 200,000. A 50,000 floor is therefore
less than one large batch of head-room. It buys the time needed to raise a request (days, not
weeks), and the alert links the runbook for doing so.
What it cost, and what is still wrong
One commit (61 lines, one scheduled job), and no new service to run. It was also the first
workflow this repository had other than a semgrep scan from 2022, so it set the local shape —
daily at 08:00 UTC, actions/checkout pinned to a commit SHA, ref: master, a small
self-hosted runner. The number-discrepancy check added ten weeks later copied that shape line
for line.
Two claims I avoid making for it. The job declares no permissions: block at all, so it runs
with whatever the repository default grants; that is unexamined, not least privilege. And a
gauge reports a level, so "stock is healthy" and "nobody has pushed for a week" arrive looking
identical; only the allocation log says which one you are seeing.