The exporter that reported nothing, quietly

A Prometheus exporter whose queries ran, returned rows, and populated no metric at all — because a column alias did not match a metric name.

Monitoring

What the thing is

wireless-query-exporter is upstream query-exporter (pinned at 2.8.1) with two SQL statements pointed at a read replica, and the gauges it exposes are inventory counts. The configuration is three YAML files that get concatenated at validation time and rendered by envtpl at container start:

# databases.yaml
databases:
  wireless_manager:
    dsn: postgresql://{{ WIRELESS_USER }}:{{ WIRELESS_PASSWORD }}@{{ WIRELESS_HOST }}:{{ WIRELESS_PORT }}/{{ WIRELESS_DB }}
    keep-connected: true
# metrics.yaml
metrics:
  query_vendor_inventory:
    type: gauge
    description: Remaining eSIM profiles, vendor-partitioned

A query runs on an interval (600 seconds for both of ours — inventory moves in hours, never in seconds) and query-exporter maps each result column onto a metric of the same name. That mapping is the whole mechanism (column name in, metric name out), and it is where the fault was.

The fault

This is what shipped:

query_vendor_inventory:
  interval: 600
  databases: [wireless_manager]
  metrics: [vendor_inventory]
  sql: |
    SELECT
    COUNT(*) AS "count"
    FROM "public"."sim_cards"
    ...

Three names, and no two of them agree (metric, reference, column). The metric defined in metrics.yaml is query_vendor_inventory; the query claims vendor_inventory; the column comes back as count. The second query was worse, selecting a bare COUNT(*) with no alias at all (Postgres then names the column count).

The query executed. The replica answered. The row count was correct, every ten minutes, for weeks. The metric was never set, because no column in the result was named after a metric, and nothing raised a word about it. Scraping /metrics returned a healthy response with the gauge absent — and an absent gauge in Prometheus looks identical to a gauge that has yet to be scraped, so neither the exporter nor the dashboard had anything to complain about.

A monitoring system that fails loudly is a nuisance; one that fails silently is worse, because the silence is also what success looks like. The only signal available was the absence of a signal.

The fix

Align the column with the metric, in both queries:

SELECT
COUNT(*) AS "query_vendor_inventory"
FROM "public"."sim_cards"
LEFT JOIN "public"."sim_card_codes" AS "Sim Card Codes"
  ON "public"."sim_cards"."id" = "Sim Card Codes"."sim_card_id"
WHERE ("public"."sim_cards"."type" = CAST('esim' AS sim_type))
AND ("Sim Card Codes"."dp_plus_vendor" = '<vendor>')   -- name elided
AND ("public"."sim_cards"."customer_allocated" = FALSE)
AND (("public"."sim_cards"."organization_id" IS NULL)
     OR ("public"."sim_cards"."organization_id" = ''))
AND "Sim Card Codes"."profile_version"::numeric >= 4.0

Six lines of change across two queries (two aliases, two metric references, two descriptions). The useful part of that ticket is the other 335 lines.

The validator

There was already a schema check (schema_validator.py, wrapping upstream's own _validate_config) and it passed the broken config, correctly. The config was valid; the names merely disagreed, which no schema can see. So validate_config.py went in beside it (335 lines, pyyaml plus sqlvalidator) to check what crosses files:

  • every metric a query references exists in metrics.yaml
  • every database a query references exists in databases.yaml
  • every SQL column alias matches a metric the query names

The third check is the one that catches this bug, and the only awkward one — it has to recover aliases from the SQL text, matching both AS "name" and bare AS name, then fall back to reading the select list ahead of FROM. Parsing SQL with regular expressions is a bad idea in general; here the queries are ours, short, and conventionally formatted, so a regex that handles our two shapes beats a dependency that handles every shape.

Both checks now run as separate Make targets (make validate_config, make validate_schemas) before anything is built:

validate_config:
    . venv/bin/activate; python validate_config.py

validate_schemas: schema_validator

Two targets and not one, deliberately. They fail for different reasons — validate_schemas rejects a config upstream would refuse to load, validate_config rejects a config that loads fine and measures nothing.

What it cost

One ticket in October 2025, 418 insertions, and a validator ten times the size of the config it validates (335 lines against 30-odd of YAML). That ratio looks wrong until you count what the config is worth: two numbers, on a dashboard, that somebody plans eSIM stock against. A wrong number would have been caught in a day. A missing one went unnoticed because the chart was simply empty, and an empty chart reads as quiet.