monitoring(logs): a readable Loki — Logs dashboard + provisioning-reload fix #74

Merged
sirius merged 1 commit from wt/t_050d5bb8 into master 2026-11-27 06:23:32 +00:00
Owner

Loki has 8 days of retained logs and no reader. The gap was not the ConfigMap —
monitoring/loki-datasource was already live and the file was sitting in Grafana's
provisioning volume; Grafana's /api/datasources still listed only Prometheus +
Alertmanager.

Root cause

The datasource sidecar writes the file, then POSTs
/api/admin/provisioning/datasources/reload with monitoring/grafana-admin. That POST
was returning 401 because Grafana's DB password had drifted from the Secret (the
documented "the Secret is only the first-boot seed, the DB owns the password"
behaviour). Grafana reads provisioning/datasources only at startup, so the file on
disk was never loaded — for 40 minutes, with no error anywhere.

Fixed by resetting the DB password to the Secret's value in-pod
(grafana cli admin reset-admin-password, value read from the Secret, never printed),
so seed and DB match again. The reload then answers 200 and the datasource appears.
Post-fix the datasource was loaded by a reload, no Grafana pod restart was needed.

What this PR adds

  • logs dashboard (uid logs, generated by build.py → logs.yaml):
    • secret access over time by user — {job="kube/apiserver-audit", resource="secrets"} | json
      grouped by (user), plus a stat and a readable "verb / object / caller" log panel.
    • pod errors by namespace — {job="kube/pods", namespace=~"$namespace"} |= "error",
      and a wider |~ "(?i)error|exception|fatal|panic" panel.
    • runner namespaces via a runner_ns variable matching .*(runner|forgejo).*,
      so the t_2bbe34a8 move to ci-runners needs no edit here.
    • a note panel documenting the stream labels and retention.
  • validate_panels.py dispatches on the target's datasource and queries Loki for
    loki panels (a logs panel must return rows, not just series).
  • Docs: docs/logging.md (how to query, the reload requirement, the field-name
    trap), docs/monitoring-dashboards.md (four boards), docs/grafana-persistence.md
    (drift breaks the sidecars, not just the login).

The card's query, as written, cannot work

{job="kube/apiserver-audit"} | json | objectRef_resource="secrets" returns 0 rows
(measured through Grafana's proxy). Alloy re-emits each audit record as a flat
allowlist, so objectRef.resource arrives as the stream label resource and
user.username as the field user. The dashboard uses the equivalent that works:
{job="kube/apiserver-audit", resource="secrets"} | json.

No change to Alloy's sources, the audit filter, Loki retention, or any RBAC.

Verification (live)

  • /api/datasources/uid/loki → type: loki, url: http://loki.logging.svc.cluster.local:3100
  • /api/datasources/uid/loki/health → {"status":"OK"}
  • proxy {job="kube/pods"}&limit=5 → 5 rows
  • proxy saved audit query, 6 h → 200 rows, 10 distinct user values
  • validate_panels.py → all 7 Loki panel targets OK (rows, not just series)
Loki has 8 days of retained logs and no reader. The gap was not the ConfigMap — `monitoring/loki-datasource` was already live and the file was sitting in Grafana's provisioning volume; Grafana's `/api/datasources` still listed only Prometheus + Alertmanager. ## Root cause The datasource sidecar writes the file, then POSTs `/api/admin/provisioning/datasources/reload` with `monitoring/grafana-admin`. That POST was returning **401** because Grafana's DB password had drifted from the Secret (the documented "the Secret is only the first-boot seed, the DB owns the password" behaviour). Grafana reads `provisioning/datasources` only at startup, so the file on disk was never loaded — for 40 minutes, with no error anywhere. Fixed by resetting the DB password to the Secret's value in-pod (`grafana cli admin reset-admin-password`, value read from the Secret, never printed), so seed and DB match again. The reload then answers 200 and the datasource appears. Post-fix the datasource was loaded by a reload, **no Grafana pod restart** was needed. ## What this PR adds - `logs` dashboard (uid `logs`, generated by `build.py` → `logs.yaml`): - **secret access over time by user** — `{job="kube/apiserver-audit", resource="secrets"} | json` grouped `by (user)`, plus a stat and a readable "verb / object / caller" log panel. - **pod errors by namespace** — `{job="kube/pods", namespace=~"$namespace"} |= "error"`, and a wider `|~ "(?i)error|exception|fatal|panic"` panel. - **runner namespaces** via a `runner_ns` variable matching `.*(runner|forgejo).*`, so the t_2bbe34a8 move to `ci-runners` needs no edit here. - a note panel documenting the stream labels and retention. - `validate_panels.py` dispatches on the target's datasource and queries Loki for `loki` panels (a logs panel must return rows, not just series). - Docs: `docs/logging.md` (how to query, the reload requirement, the field-name trap), `docs/monitoring-dashboards.md` (four boards), `docs/grafana-persistence.md` (drift breaks the sidecars, not just the login). ## The card's query, as written, cannot work `{job="kube/apiserver-audit"} | json | objectRef_resource="secrets"` returns **0 rows** (measured through Grafana's proxy). Alloy re-emits each audit record as a flat allowlist, so `objectRef.resource` arrives as the **stream label** `resource` and `user.username` as the field `user`. The dashboard uses the equivalent that works: `{job="kube/apiserver-audit", resource="secrets"} | json`. No change to Alloy's sources, the audit filter, Loki retention, or any RBAC. ## Verification (live) - `/api/datasources/uid/loki` → `type: loki`, `url: http://loki.logging.svc.cluster.local:3100` - `/api/datasources/uid/loki/health` → `{"status":"OK"}` - proxy `{job="kube/pods"}&limit=5` → 5 rows - proxy saved audit query, 6 h → 200 rows, 10 distinct `user` values - `validate_panels.py` → all 7 Loki panel targets OK (rows, not just series)
The log store shipped in t_34ddaa83 but nothing could read it: the Loki datasource
ConfigMap was live and written into Grafana's provisioning volume, and Grafana still
listed only Prometheus + Alertmanager. Root cause was not the ConfigMap. The
datasource sidecar writes the file and then POSTs
/api/admin/provisioning/datasources/reload with monitoring/grafana-admin, which was
401-ing because Grafana's DB password had drifted from that Secret (the documented
"the Secret is only the seed" behaviour) — Grafana reads provisioning/datasources
only at startup, so the datasource never loaded.

- Reset the live admin password to the Secret's value (in-pod `grafana cli
  admin reset-admin-password`, value read from the Secret and never printed), so
  seed and DB match again and the sidecar's reload returns 200. Documented in
  docs/grafana-persistence.md, including the sidecar consequence of drift.
- New generated dashboard `logs` (uid: logs) with the two queries worth having:
  secret access over time by user from the apiserver audit stream, and pod errors
  by namespace, plus the runner namespaces and a note panel on field names.
- The audit stream's names are the Alloy allowlist's, not the audit event's:
  objectRef.resource arrives as the stream label `resource` and user.username as
  the field `user`. `| json | objectRef_resource="secrets"` returns 0 rows
  (measured); the panels use `resource="secrets"` in the selector + `| json` for
  the user dimension. No pipeline, retention or filter change.
- Runner panels discover their namespace via a `runner_ns` variable
  (.*(runner|forgejo).*) instead of pinning one name, so the t_2bbe34a8 move to
  ci-runners needs no edit here.
- validate_panels.py now dispatches on the target's datasource and queries Loki
  for `loki` panels (a logs panel must return rows, not just series).
sirius merged commit f625fcfc05 into master 2026-11-27 06:23:32 +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!74
No description provided.