monitoring(logs): a readable Loki — Logs dashboard + provisioning-reload runbook
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).
This commit is contained in:
parent
2ae67faf98
commit
6b91152a79
7 changed files with 828 additions and 35 deletions
|
|
@ -53,6 +53,16 @@ So: changing `grafana-admin` alone on a populated PVC does **nothing**. That is
|
|||
by design (no silent password resets on redeploy), and it is exactly why the
|
||||
recovery path below matters.
|
||||
|
||||
> **Drift breaks the sidecars, not just the login.** The pod's sidecars (`grafana-sc-dashboard`,
|
||||
> `grafana-sc-datasources`) carry `REQ_USERNAME`/`REQ_PASSWORD` from `grafana-admin` and POST
|
||||
> `/api/admin/provisioning/{dashboards,datasources}/reload` as their "make Grafana read what I just
|
||||
> wrote" step. Once the DB password has drifted from the Secret that POST returns **401**, so a
|
||||
> datasource ConfigMap is written into `/etc/grafana/provisioning/datasources` and never loaded:
|
||||
> the datasource is simply absent from `/api/datasources` while the file sits in the pod. Observable
|
||||
> 2026-11-27 with the Loki datasource (ConfigMap live, file in the volume, no datasource in Grafana
|
||||
> for 40 minutes). The DB was then reset to the Secret's value, so the seed and the DB match again
|
||||
> and the reload answers **200**. Fix drift the same way before debugging a "missing" datasource.
|
||||
|
||||
## Recovery: reset a lost admin password
|
||||
|
||||
The trap with a persistent DB is that re-applying the Secret no longer helps.
|
||||
|
|
|
|||
|
|
@ -186,13 +186,47 @@ the audit history was then re-ingested through the fixed pipeline.
|
|||
## Querying
|
||||
|
||||
Grafana datasource `Loki` (`uid: loki`, `infrastructure/logging/datasource.yaml`,
|
||||
loaded by the kube-prometheus-stack datasource sidecar) → Explore → Loki.
|
||||
loaded by the kube-prometheus-stack datasource sidecar) → Explore → Loki. The
|
||||
saved queries live on the **Logs** dashboard (`uid: logs`,
|
||||
`monitoring/controllers/home/dashboards/logs.yaml`, generated by `build.py`):
|
||||
|
||||
```
|
||||
http://10.10.0.2:8081/d/logs/
|
||||
```
|
||||
|
||||
From inside the cluster: `http://loki.logging.svc.cluster.local:3100`.
|
||||
From the Legion over WireGuard: `kubectl -n logging port-forward svc/loki 3100:3100`.
|
||||
No Gateway/listener is published for this — the store is not exposed outside the
|
||||
mesh and has no auth layer of its own.
|
||||
|
||||
**A new or edited datasource ConfigMap needs a provisioning reload.** Grafana
|
||||
reads `provisioning/datasources` only at startup; the sidecar writes the file but
|
||||
the thing that makes Grafana read it is the sidecar's own
|
||||
`POST /api/admin/provisioning/datasources/reload`, authenticated with
|
||||
`monitoring/grafana-admin`. If the DB password has drifted from that Secret the
|
||||
POST 401s, the file is on disk and the datasource never appears — which looks
|
||||
like a broken ConfigMap. Reload by hand with the Secret's credential:
|
||||
|
||||
```bash
|
||||
kubectl -n monitoring port-forward svc/kube-prometheus-stack-grafana 3000:80 &
|
||||
curl -u "admin:$GF_ADMIN_PASSWORD" -X POST \
|
||||
http://127.0.0.1:3000/api/admin/provisioning/datasources/reload # 200
|
||||
```
|
||||
|
||||
**The audit stream's field names are not the audit event's.** Alloy re-emits each
|
||||
record as a flat allowlist (`infrastructure/logging/alloy/config.alloy`), so
|
||||
`objectRef.resource` arrives as the **stream label** `resource` and
|
||||
`user.username` as the line field `user`:
|
||||
|
||||
```logql
|
||||
{job="kube/apiserver-audit", resource="secrets"} | json # who touched a Secret
|
||||
```
|
||||
|
||||
`{job="kube/apiserver-audit"} | json | objectRef_resource="secrets"` returns
|
||||
**zero rows** — measured 2026-11-27. `resource`/`verb` are stream labels, so put
|
||||
them in the selector (Loki prunes streams before parsing); `user`, `ns`, `name`,
|
||||
`code`, `sourceIP` are JSON fields and need `| json`.
|
||||
|
||||
Useful LogQL:
|
||||
|
||||
```logql
|
||||
|
|
@ -200,6 +234,7 @@ Useful LogQL:
|
|||
{namespace="kube-system", container="cilium-agent"} |= "error"
|
||||
{job="systemd-journal", node="siriussec"} |= "sshd" # node-level auth activity
|
||||
sum by (namespace) (count_over_time({job="kube/pods"}[1h]))
|
||||
sum by (user) (count_over_time({job="kube/apiserver-audit", resource="secrets"} | json [5m]))
|
||||
```
|
||||
|
||||
Label cardinality is bounded: `namespace, pod, container, node, stream, job`
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# Monitoring dashboards
|
||||
|
||||
Three custom Grafana dashboards, all provisioned from this repo. Nothing on these
|
||||
Four custom Grafana dashboards, all provisioned from this repo. Nothing on these
|
||||
boards is created in the UI: the `kube-prometheus-stack` Grafana sidecar watches
|
||||
for ConfigMaps labelled `grafana_dashboard=1` in **every** namespace
|
||||
(`NAMESPACE=ALL`, `LABEL_VALUE=1`, `FOLDER=/tmp/dashboards`) and reloads them, so
|
||||
|
|
@ -11,6 +11,7 @@ a UI edit is overwritten on the next sidecar poll.
|
|||
| Forgejo Runners | `forgejo-runners` | Are the runners alive and polling, is CI queueing, how do runs end, and how full is the disk CI fills? |
|
||||
| CNPG Postgres | `cnpg-postgres` | Are both Postgres clusters up, how busy, how big, how much WAL, is anything erroring? |
|
||||
| Home lab workloads | `home-lab-workloads` | Which namespace is burning CPU/memory, what is Pending or restarting, are the nodes healthy, do the internal services answer? |
|
||||
| Logs | `logs` | Who read a Secret (apiserver audit, by user), what did a pod say before it died, what did the CI runners print? |
|
||||
|
||||
Open them (WireGuard only, no public hostname — see
|
||||
`docs/internal-wireguard-services.md`):
|
||||
|
|
@ -19,28 +20,37 @@ Open them (WireGuard only, no public hostname — see
|
|||
http://10.10.0.2:8081/d/forgejo-runners/
|
||||
http://10.10.0.2:8081/d/cnpg-postgres/
|
||||
http://10.10.0.2:8081/d/home-lab-workloads/
|
||||
http://10.10.0.2:8081/d/logs/
|
||||
```
|
||||
|
||||
`logs` is the odd one out: its panels query the **Loki** datasource (`uid: loki`,
|
||||
`infrastructure/logging/datasource.yaml`) rather than Prometheus, and its two
|
||||
template variables are filled from Loki's label API. The audit field names there
|
||||
are the Alloy pipeline's allowlist, not the raw audit event's — `objectRef.resource`
|
||||
arrives as the stream label `resource` and `user.username` as the field `user`;
|
||||
`docs/logging.md` §Querying has the detail and the zero-row proof.
|
||||
|
||||
They land in the default **General** folder, next to the chart's own dashboards —
|
||||
not in a custom folder. That is a consequence of *how* they get imported: the
|
||||
sidecar's API-backed import POSTs to `/api/admin/provisioning/dashboards/reload`
|
||||
with `GF_SECURITY_ADMIN_USER/PASSWORD`, and on this Grafana that returns **401**
|
||||
because the live admin password is the out-of-band one set in the UI
|
||||
(`docs/grafana-persistence.md`) while `monitoring/grafana-admin` is only the
|
||||
first-boot seed. Grafana's own **file** provider then imports `/tmp/dashboards`
|
||||
on its 10 s rescan anyway — that is what actually registers these boards — and
|
||||
the file provider has no per-dashboard folder option. Hence no `grafana_folder`
|
||||
annotation: it would only describe a path the boards do not take.
|
||||
with `GF_SECURITY_ADMIN_USER/PASSWORD`, and that call only succeeds while the live
|
||||
admin password still matches `monitoring/grafana-admin`. When the two have drifted
|
||||
the POST returns **401** and Grafana's own **file** provider imports
|
||||
`/tmp/dashboards` on its 10 s rescan instead — that is what actually registers
|
||||
these boards — and the file provider has no per-dashboard folder option. Hence no
|
||||
`grafana_folder` annotation: it would only describe a path the boards do not take.
|
||||
(The drift was repaired on 2026-11-27; see `docs/grafana-persistence.md`.)
|
||||
|
||||
## Where the files live
|
||||
|
||||
```
|
||||
monitoring/controllers/home/dashboards/
|
||||
├── build.py # source of truth: panel definitions + PromQL
|
||||
├── build.py # source of truth: panel definitions + PromQL/LogQL
|
||||
├── kustomization.yaml
|
||||
├── forgejo-runners.yaml # GENERATED ConfigMap (JSON inside)
|
||||
├── cnpg-postgres.yaml # GENERATED
|
||||
└── home-lab-workloads.yaml # GENERATED
|
||||
├── home-lab-workloads.yaml # GENERATED
|
||||
└── logs.yaml # GENERATED (Loki panels)
|
||||
```
|
||||
|
||||
**Edit `build.py`, then regenerate.** The generated YAML is committed so Flux
|
||||
|
|
@ -157,17 +167,22 @@ throughput panels query "how many rows stopped inside the last hour" directly
|
|||
## Adding a panel
|
||||
|
||||
1. Edit `monitoring/controllers/home/dashboards/build.py` — `ts()` for a
|
||||
timeseries, `stat()` for a single number, `note()` for markdown.
|
||||
timeseries, `stat()` for a single number, `note()` for markdown, `logs()` for
|
||||
a Loki log panel (its target must come from `loki_target()`, and the panel
|
||||
needs `ds=DS_LOKI`).
|
||||
2. Regenerate (command above).
|
||||
3. **Validate the PromQL, not just the YAML.** `validate_panels.py` (next to
|
||||
3. **Validate the query, not just the YAML.** `validate_panels.py` (next to
|
||||
`build.py`) reads the dashboard JSON *out of the provisioned ConfigMap*,
|
||||
extracts every target expression, substitutes the `$namespace` "All" case and
|
||||
queries Prometheus. Anything that returns no series is a failed panel. It
|
||||
needs a Prometheus port-forward (`kubectl -n monitoring port-forward
|
||||
svc/kube-prometheus-stack-prometheus 9090:9090`).
|
||||
extracts every target expression, substitutes the `$namespace` / `$runner_ns`
|
||||
"All" cases and queries the target's own datasource — Prometheus for
|
||||
PromQL panels, Loki for panels whose datasource is `loki` (a Loki panel is a
|
||||
failure unless it returns rows, not just series). Anything that returns no
|
||||
data is a failed panel. It needs both port-forwards:
|
||||
```bash
|
||||
kubectl -n monitoring port-forward svc/kube-prometheus-stack-prometheus 9090:9090 &
|
||||
kubectl -n logging port-forward svc/loki 3100:3100 &
|
||||
python3 monitoring/controllers/home/dashboards/validate_panels.py \
|
||||
monitoring/controllers/home/dashboards http://127.0.0.1:9090
|
||||
monitoring/controllers/home/dashboards http://127.0.0.1:9090 http://127.0.0.1:3100
|
||||
```
|
||||
4. Commit + push to `master`, then force the reconcile:
|
||||
```bash
|
||||
|
|
|
|||
Loading…
Reference in a new issue