feat(runner-controller): break queue wait down by state #592

Sammanfogat
supernaut sammanfogade 5 incheckningar från feat/runner-queue-wait-states in i main 2026-10-08 15:17:25 +00:00
Ägare

Closes #567. Follows #591 (merged).

The pickup gauges said how long a job waited, not why.

Change

  • Every second a queued job waits is booked to one state: at_cap, quota, booting, registering, unclaimed or controller_error. It uses only data the loop already reads.
  • New series:
    • bitborg_runner_controller_queue_wait_seconds_total{state}
    • bitborg_runner_controller_queued_jobs_by_state{state}
    • bitborg_runner_controller_pickup_seconds_max_15m
  • First-seen times persist across restarts, with a save time.
    • A file older than three poll intervals is discarded.
    • After a restart, jobs that left the queue while the controller was down are dropped, not sampled.
  • The wait step uses a monotonic clock, floored at 0, so the counter never decreases.
  • Classification errors book the cycle as controller_error and never block VM creation.
  • A spent VM is no supply. An ACTIVE VM with no runner id counts as registering.
  • RunnerPickupSlow reads the 15-minute max with for: 5m, so one slow pickup fires and the alert clears about 15 minutes after. The threshold variable is renamed alert_runner_pickup_max_seconds.
  • The active_vms gauge now counts VMs actually booted this cycle, not the planned number.
  • Runners dashboard: new stacked "Queue wait by state" panel. Stale p90 wording fixed.
  • Runbook: the slow-CI section reads the new panel first, with a state-to-cause table.

Tests

test_controller_logic.py: 109/109. check-metric-names.py and check-alert-rules.py (53 rules, self-test 4/4) pass. Pre-push hooks pass.

Not exercised: an end-to-end reconcile() run. The new wiring is covered by unit tests of its helpers.

Closes #567. Follows #591 (merged). The pickup gauges said how long a job waited, not why. ## Change - Every second a queued job waits is booked to one state: `at_cap`, `quota`, `booting`, `registering`, `unclaimed` or `controller_error`. It uses only data the loop already reads. - New series: - `bitborg_runner_controller_queue_wait_seconds_total{state}` - `bitborg_runner_controller_queued_jobs_by_state{state}` - `bitborg_runner_controller_pickup_seconds_max_15m` - First-seen times persist across restarts, with a save time. - A file older than three poll intervals is discarded. - After a restart, jobs that left the queue while the controller was down are dropped, not sampled. - The wait step uses a monotonic clock, floored at 0, so the counter never decreases. - Classification errors book the cycle as `controller_error` and never block VM creation. - A spent VM is no supply. An ACTIVE VM with no runner id counts as `registering`. - `RunnerPickupSlow` reads the 15-minute max with `for: 5m`, so one slow pickup fires and the alert clears about 15 minutes after. The threshold variable is renamed `alert_runner_pickup_max_seconds`. - The `active_vms` gauge now counts VMs actually booted this cycle, not the planned number. - Runners dashboard: new stacked "Queue wait by state" panel. Stale p90 wording fixed. - Runbook: the slow-CI section reads the new panel first, with a state-to-cause table. ## Tests `test_controller_logic.py`: 109/109. `check-metric-names.py` and `check-alert-rules.py` (53 rules, self-test 4/4) pass. Pre-push hooks pass. Not exercised: an end-to-end `reconcile()` run. The new wiring is covered by unit tests of its helpers.
supernaut lade till 4 incheckningar 2026-10-08 15:08:23 +00:00
fix(runner-controller): count a finished VM as spent, not idle (#566)
Alla kontroller lyckades
ci / ci (pull_request) Successful in 1m45s
ca2a4d96cb
A one-job VM stays ACTIVE until Nova reports SHUTOFF. Its job has left
"running", so _compute_capacity counted it as idle and booted nothing
while a job waited.

Count VMs whose Forgejo registration is gone as spent and leave them out
of idle capacity. A failed runners read counts nothing spent, so an
error can only under-boot.
Book every second a queued job waits to one state: at_cap, quota,
booting, registering, unclaimed or controller_error. Uses the server,
runner and queue reads the loop already makes. No new API calls.

spent_counted_idle is dropped. The previous commit removes the
condition it described.

- Counter queue_wait_seconds_total{state} and gauge
  queued_jobs_by_state{state}. The queued_jobs gauge is unchanged.
- Persist first-seen times in queued_first_seen.json beside the
  metrics file. Atomic write. A missing or corrupt file starts empty.
- Add pickup_seconds_max_15m. RunnerPickupSlow reads it, so it clears
  after the queue drains. The threshold variable is unchanged.
- Add a stacked queue-wait-by-state panel to the runners dashboard.
- Runbook: read the new panel first on slow CI.
- Persist a save time with the first-seen map and discard a file older
  than three poll intervals. After a restart, drop loaded ids that are no
  longer queued without sampling them, so downtime is not a slow pickup.
  Skip saving until the first queue read confirms the loaded ids.
- Book wait steps from time.monotonic(), floored at zero, so a clock
  step back cannot lower the counter.
- Run the wait-state classification in a guard. A failure logs a warning
  and books the cycle as controller_error. VM creation is unaffected.
- Count an ACTIVE VM with no runner id or no listed registration as
  registering. ERROR VMs are reaped before the supply count.
- RunnerPickupSlow: for 5m on pickup_seconds_max_15m. Rename
  alert_runner_pickup_p90_seconds to alert_runner_pickup_max_seconds.
- Fix dashboard and runbook text that called the alert p90-based.

Behaviour change: reconcile now returns active_count + created, so
active_vms counts VMs actually booted, not VMs requested.
fix(runner-controller): a spent VM is no supply (#567)
Alla kontroller lyckades
ci / ci (pull_request) Successful in 1m47s
57e8806e06
A VM whose runner id is set but missing from the live runners list has
finished its job. It is no supply, so it must not count as registering.
Only an ACTIVE VM with no runner id counts as registering.
supernaut lade till 1 incheckning 2026-10-08 15:15:08 +00:00
Merge remote-tracking branch 'origin/main' into feat/runner-queue-wait-states
Alla kontroller lyckades
ci / ci (pull_request) Successful in 1m39s
b809e384d9
# Conflicts:
#	ansible/roles/runner-controller/files/controller.py
supernaut schemalade den här ändringsförfrågan för automatisk sammanfogning när alla kontroller lyckas 2026-10-08 15:16:11 +00:00
supernaut sammanfogade incheckning d15d5b4c72 till main 2026-10-08 15:17:25 +00:00
supernaut tog bort grenen feat/runner-queue-wait-states 2026-10-08 15:17:25 +00:00
Logga in för att delta i denna konversation.
Inga granskare
Ingen milstolpe
Inget projekt
Inga tilldelade
1 deltagare
Notiser
Förfallodatum
Förfallodatumet är ogiltigt eller utanför gränserna. Använd formatet "åååå-mm-dd".

Inget förfallodatum satt.

Beroenden

Inga beroenden satta

Referens
bitborg/bitborg-infra!592
Ingen beskrivning angiven.