feat(monitoring): keycloak lockout alert and alert rule unit tests #640

Sammanfogat
supernaut sammanfogade 2 incheckningar från feat/keycloak-alerts in i main 2026-10-10 16:37:53 +00:00
Ägare

What

Finishes the monitoring checklist of #573. Scrape, probe, unit-active and KeycloakMemoryHigh were already merged (#601, #638).

  • KeycloakLoginLockouts (Loki): more than 20 user_temporarily_disabled or user_permanently_disabled login errors in 10 min, read from the realm's jboss-logging events. Thresholds are role defaults.
  • SignupProvisioningFailing matches [signup] Kanidm and/or [signup] Keycloak, following kanidm_enabled and keycloak_enabled. Kanidm keeps working until cutover.
  • scripts/test-alert-rules.py: vmalert-tool unittest for KeycloakNotReady, KeycloakMemoryHigh and CoreUnitDown (keycloak). The Loki rules are LogQL, which no tool unit tests, so the script matches each rendered line filter against sample lines (KeycloakOOMKilled, KeycloakLoginLockouts, SignupProvisioningFailing for both IdPs). Fixture: ansible/roles/monitoring/tests/alert-rules.test.yml. New CI step beside check-alert-rules.py.
  • Runbook: alert table and lockout triage, alert tests, "Rotate a client secret", "Delete a user in Keycloak". Bootstrap, break-glass, upgrade and restore were already in the Keycloak section.

Deliberate differences from the checklist

  • Memory threshold stays 80 %, not 90 %: MemoryHigh is 87.5 %, where the kernel throttles, so 90 % could never be reached for 10 min.
  • Not-ready stays 3 min, not 2: it must exceed the 120 s HealthStartPeriod, and starting reads as 0, so 2 min would fire on every restart.
  • Probes and unit-active already derive from keycloak_enabled / kanidm_enabled (#638). No change.

Test

  • ./scripts/check-alert-rules.py and --self-test: pass.
  • ./scripts/test-alert-rules.py: pass. With alert_keycloak_memory_pct raised to 90 the memory test fails, so the tests can fail.
  • prettier, markdownlint, ruff: pass.

Not proven

  • Live firing on staging. The lockout line shape and container="keycloak" label come from Keycloak docs and the existing Loki rules, not from a captured line. Provoke 11 bad passwords on a seed user on staging and read the line in Loki. Prod Prometheus has no Keycloak series yet (not applied).

Refs #573. The lockout matcher still needs a live check on staging.

## What Finishes the monitoring checklist of #573. Scrape, probe, unit-active and `KeycloakMemoryHigh` were already merged (#601, #638). - `KeycloakLoginLockouts` (Loki): more than 20 `user_temporarily_disabled` or `user_permanently_disabled` login errors in 10 min, read from the realm's `jboss-logging` events. Thresholds are role defaults. - `SignupProvisioningFailing` matches `[signup] Kanidm` and/or `[signup] Keycloak`, following `kanidm_enabled` and `keycloak_enabled`. Kanidm keeps working until cutover. - `scripts/test-alert-rules.py`: `vmalert-tool unittest` for `KeycloakNotReady`, `KeycloakMemoryHigh` and `CoreUnitDown` (keycloak). The Loki rules are LogQL, which no tool unit tests, so the script matches each rendered line filter against sample lines (`KeycloakOOMKilled`, `KeycloakLoginLockouts`, `SignupProvisioningFailing` for both IdPs). Fixture: `ansible/roles/monitoring/tests/alert-rules.test.yml`. New CI step beside `check-alert-rules.py`. - Runbook: alert table and lockout triage, alert tests, "Rotate a client secret", "Delete a user in Keycloak". Bootstrap, break-glass, upgrade and restore were already in the Keycloak section. ## Deliberate differences from the checklist - Memory threshold stays 80 %, not 90 %: `MemoryHigh` is 87.5 %, where the kernel throttles, so 90 % could never be reached for 10 min. - Not-ready stays 3 min, not 2: it must exceed the 120 s `HealthStartPeriod`, and `starting` reads as 0, so 2 min would fire on every restart. - Probes and unit-active already derive from `keycloak_enabled` / `kanidm_enabled` (#638). No change. ## Test - `./scripts/check-alert-rules.py` and `--self-test`: pass. - `./scripts/test-alert-rules.py`: pass. With `alert_keycloak_memory_pct` raised to 90 the memory test fails, so the tests can fail. - prettier, markdownlint, ruff: pass. ## Not proven - Live firing on staging. The lockout line shape and `container="keycloak"` label come from Keycloak docs and the existing Loki rules, not from a captured line. Provoke 11 bad passwords on a seed user on staging and read the line in Loki. Prod Prometheus has no Keycloak series yet (not applied). Refs #573. The lockout matcher still needs a live check on staging.
supernaut lade till 2 incheckningar 2026-10-10 16:33:05 +00:00
supernaut tvångsskickade feat/keycloak-alerts från 9dc5352065
Väntande kontroller
ci / ci (pull_request) Has started running
till ea11843539
Alla kontroller lyckades
ci / ci (pull_request) Successful in 2m5s
2026-10-10 16:35:12 +00:00
Jämför
supernaut schemalade den här ändringsförfrågan för automatisk sammanfogning när alla kontroller lyckas 2026-10-10 16:35:48 +00:00
supernaut sammanfogade incheckning ef2813a398 till main 2026-10-10 16:37:53 +00:00
supernaut tog bort grenen feat/keycloak-alerts 2026-10-10 16:37:53 +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!640
Ingen beskrivning angiven.