monitoring(forgejo): make the actions_runners metric duplicate-proof #75

Merged
sirius merged 1 commit from wt/t_290ff037 into master 2026-11-27 06:29:36 +00:00
Owner

Summary

forgejo/cnpg-pg (CNPG instance-manager exporter on pg-1) returned HTTP 500 on every scrape, so every
Forgejo DB metric was missing — all cnpg_actions_* queue/runner series did not exist and 8 panels on the
forgejo-runners dashboard were EMPTY.

Root cause: action_runner held three rows named siriussec-amd64 (id 8 = the live identity from the
runner's runner.ini; ids 15/16 = soft-deleted tombstones left by the forgejo → ci-runners move), and
actions_runners selected r.name as the runner label with no filtering or aggregation. The exporter treats
a duplicate name+label set as a programming error and fails the entire /metrics response, taking
pg_stat_* / cnpg_pg_* down with it.

Changes (apps/base/forgejo/pg-actions-queries.yaml)

  • WHERE r.deleted IS NULL — Forgejo soft-deletes a removed runner (deleted = epoch, row kept); those
    tombstones are not runners and are hidden from the admin API, but a raw table read sees them.
  • GROUP BY r.name with max(r.last_online) — the label is the name, so no duplicate name can ever produce a
    duplicate series again; "most recent poll per name" is the intended semantic anyway.
  • cnpg.io/reload: "" label — the instance manager now re-reads the queries when the ConfigMap changes (live
    reload, no PostgreSQL restart, no kubectl cnpg reload). Without it a query fix appears to do nothing and the
    endpoint keeps 500ing.

Verification (live, before this PR was opened)

  • curl :19187/metrics → HTTP 200, 429 cnpg_* series (was 500 / 0).
  • cnpg_actions_runners_last_online_seconds → exactly one series each for pi-runner, pi-deploy-arm64,
    siriussec-amd64 (3 rows total).
  • All 16 cnpg_actions_* series present; cnpg_actions_queue_depth 0, cnpg_actions_running_total 3,
    1h/24h job windows populated.
  • No PostgreSQL restart: pg-1 still creationTimestamp 2026-11-21T17:33:42Z, restartCount 2 (unchanged).

Card: t_290ff037

## Summary `forgejo/cnpg-pg` (CNPG instance-manager exporter on `pg-1`) returned **HTTP 500** on every scrape, so *every* Forgejo DB metric was missing — all `cnpg_actions_*` queue/runner series did not exist and 8 panels on the `forgejo-runners` dashboard were EMPTY. Root cause: `action_runner` held **three** rows named `siriussec-amd64` (id 8 = the live identity from the runner's `runner.ini`; ids 15/16 = soft-deleted tombstones left by the `forgejo` → `ci-runners` move), and `actions_runners` selected `r.name` as the `runner` label with no filtering or aggregation. The exporter treats a duplicate name+label set as a programming error and fails the **entire** `/metrics` response, taking `pg_stat_*` / `cnpg_pg_*` down with it. ## Changes (`apps/base/forgejo/pg-actions-queries.yaml`) - `WHERE r.deleted IS NULL` — Forgejo soft-deletes a removed runner (`deleted` = epoch, row kept); those tombstones are not runners and are hidden from the admin API, but a raw table read sees them. - `GROUP BY r.name` with `max(r.last_online)` — the label *is* the name, so no duplicate name can ever produce a duplicate series again; "most recent poll per name" is the intended semantic anyway. - `cnpg.io/reload: ""` label — the instance manager now re-reads the queries when the ConfigMap changes (live reload, no PostgreSQL restart, no `kubectl cnpg reload`). Without it a query fix appears to do nothing and the endpoint keeps 500ing. ## Verification (live, before this PR was opened) - `curl :19187/metrics` → **HTTP 200**, 429 `cnpg_*` series (was 500 / 0). - `cnpg_actions_runners_last_online_seconds` → exactly one series each for `pi-runner`, `pi-deploy-arm64`, `siriussec-amd64` (3 rows total). - All 16 `cnpg_actions_*` series present; `cnpg_actions_queue_depth 0`, `cnpg_actions_running_total 3`, 1h/24h job windows populated. - No PostgreSQL restart: `pg-1` still `creationTimestamp 2026-11-21T17:33:42Z`, `restartCount 2` (unchanged). Card: t_290ff037
The CNPG exporter answers the whole /metrics request with HTTP 500 when a
custom query emits two rows with the same series name + label set, which
also drops every pg_stat_*/cnpg_pg_* series (Prometheus target down).

action_runner held three rows named siriussec-amd64 (one live, two
soft-deleted tombstones from the runner renames), so
cnpg_actions_runners_last_online_seconds was collected twice and the
endpoint returned 500.

- WHERE r.deleted IS NULL -> ignore Forgejo's soft-deleted runner rows.
- GROUP BY r.name with max(last_online) -> the label is the name, so a
  duplicate name can never produce a duplicate series again; reporting the
  most recent poll per name is the intended semantic.
- label cnpg.io/reload -> the instance manager re-reads the queries on
  change instead of needing a pod restart (or kubectl cnpg reload) before
  a query fix takes effect.
sirius merged commit 588c17a3e4 into master 2026-11-27 06:29:36 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/homek8s!75
No description provided.