feat: back up, drill, scrape and alert on keycloak behind keycloak_enabled #601

Sammanfogat
supernaut sammanfogade 4 incheckningar från feat/keycloak-backup-monitoring in i main 2026-10-08 20:29:59 +00:00
Ägare

Backup, restore drill, scrape, probe and alerts for Keycloak. Everything is gated on keycloak_enabled. With it false (prod), all 10 changed templates render identical to main, checked with a jinja2 stand-in. Kanidm's backup, drill, probe and alerts are untouched.

Merge after #571 is applied to staging. The probe targets the realm's well-known URL, which returns 404 until the realm exists.

#572 backup and drill

  • Daily and hot pg_dump of the keycloak database. The weekly verify runs pg_restore --list.
  • Drill:
    • restores the dump on the scratch VM;
    • starts the pinned image (start --optimized) and waits for /health/ready;
    • counts users, groups and clients in SQL. SQL, because the dump carries no admin credential;
    • publishes bitborg_backup_drill_keycloak_{status,users,groups,clients}.
    • A failure fires the existing BackupDrillFailed.

#573 monitoring

  • Scrape: vmagent reads keycloak:9000/metrics by container name on the bitborg network, so nothing is published. Checked on staging: keycloak:9000 answers from another container.
  • Probe: blackbox on https://<keycloak_domain>/realms/<realm>/.well-known/openid-configuration.
  • Core unit: keycloak joins the core units (active, restarts, container health).
  • New textfile metrics: bitborg_unit_memory_{current,max}_bytes for the keycloak unit.
  • Alerts:
    • KeycloakNotReady: health check failing for 3 minutes, critical.
    • KeycloakMemoryHigh: above 80% of MemoryMax for 10 minutes, warning. That is below MemoryHigh (87.5%), so it fires before throttling.
    • KeycloakOOMKilled: a Loki rule on the journal OOM line, warning.
  • Brute-force lockout alert: deferred. The image needs event-metrics-user-enabled first.
  • scripts/check-alert-rules.py also checks the rule set with keycloak_enabled on, so CI parses the gated rules.

Checks

  • ansible-lint, prettier, markdownlint, shellcheck, ruff and the repo check scripts pass.
  • vmalert and promtool accept all 56 rules.

Not verified

  • The Loki rule syntax and the rendered vmagent YAML. The monitoring roles run on prod only, so they are exercised at cutover.
  • A drill run on the scratch VM.
  • The OOM journal match.

Refs #572
Refs #573

Backup, restore drill, scrape, probe and alerts for Keycloak. Everything is gated on `keycloak_enabled`. With it false (prod), all 10 changed templates render identical to `main`, checked with a jinja2 stand-in. Kanidm's backup, drill, probe and alerts are untouched. **Merge after #571 is applied to staging.** The probe targets the realm's well-known URL, which returns 404 until the realm exists. ## #572 backup and drill - Daily and hot `pg_dump` of the `keycloak` database. The weekly verify runs `pg_restore --list`. - **Drill:** - restores the dump on the scratch VM; - starts the pinned image (`start --optimized`) and waits for `/health/ready`; - counts users, groups and clients in SQL. SQL, because the dump carries no admin credential; - publishes `bitborg_backup_drill_keycloak_{status,users,groups,clients}`. - A failure fires the existing `BackupDrillFailed`. ## #573 monitoring - **Scrape:** vmagent reads `keycloak:9000/metrics` by container name on the `bitborg` network, so nothing is published. Checked on staging: `keycloak:9000` answers from another container. - **Probe:** blackbox on `https://<keycloak_domain>/realms/<realm>/.well-known/openid-configuration`. - **Core unit:** `keycloak` joins the core units (active, restarts, container health). - **New textfile metrics:** `bitborg_unit_memory_{current,max}_bytes` for the keycloak unit. - **Alerts:** - `KeycloakNotReady`: health check failing for 3 minutes, critical. - `KeycloakMemoryHigh`: above 80% of `MemoryMax` for 10 minutes, warning. That is below `MemoryHigh` (87.5%), so it fires before throttling. - `KeycloakOOMKilled`: a Loki rule on the journal OOM line, warning. - **Brute-force lockout alert:** deferred. The image needs `event-metrics-user-enabled` first. - `scripts/check-alert-rules.py` also checks the rule set with `keycloak_enabled` on, so CI parses the gated rules. ## Checks - ansible-lint, prettier, markdownlint, shellcheck, ruff and the repo check scripts pass. - vmalert and `promtool` accept all 56 rules. ## Not verified - The Loki rule syntax and the rendered vmagent YAML. The monitoring roles run on prod only, so they are exercised at cutover. - A drill run on the scratch VM. - The OOM journal match. Refs #572 Refs #573
supernaut lade till 4 incheckningar 2026-10-08 20:27:39 +00:00
Dump the keycloak database in the daily archive and the hot job, and
check it in the weekly verify. The restore drill starts the pinned image
against the restored dump, waits for /health/ready and counts users,
groups and clients in SQL. All of it is gated on keycloak_enabled.

Refs #572
Scrape :9000/metrics over the bitborg network without publishing the
port, add keycloak to the core units, and emit unit memory metrics.
Add a realm probe and the KeycloakNotReady, KeycloakMemoryHigh and
KeycloakOOMKilled alerts. check-alert-rules also validates the rule set
with keycloak_enabled forced on. All of it is gated on keycloak_enabled.

Refs #573
Refs #573
docs(runbook): match the keycloak memory alert note to the new threshold
Alla kontroller lyckades
ci / ci (pull_request) Successful in 1m41s
c2be02bb78
Refs #573
supernaut schemalade den här ändringsförfrågan för automatisk sammanfogning när alla kontroller lyckas 2026-10-08 20:29:55 +00:00
supernaut sammanfogade incheckning 27af627ba1 till main 2026-10-08 20:29:59 +00:00
supernaut tog bort grenen feat/keycloak-backup-monitoring 2026-10-08 20:29:59 +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!601
Ingen beskrivning angiven.