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
|
|
@ -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