observability: KSE-0191 total observability v2 — generated dashboards, OpenTofu alerting, fleet agent, collectors, API tracing #163

Merged
founder merged 7 commits from claude/total-observability-v2 into main 2026-08-22 04:02:38 +00:00
Owner

Implements KSE-0191 — Total Observability v2 (evolution/proposals/KSE-0191-total-observability-v2-grafana-as-code.md): every signal, every machine, every dollar, one Grafana as code. Founder direction 2026-08-18: "make our grafana and logging/reporting ultra complete… use opentofu to make dashboards".

What lands

Grafana as code (OpenTofu, infra/grafana)

  • 22 dashboards generated from a zero-dependency TypeScript catalog (services/grafana/src, ~700 panels); bun services/grafana/src/generate.ts + CI gate Scripts/grafana-dashboards-check.sh; the stack reads services/grafana/dashboards/manifest.json — adding a dashboard is one TS file, zero HCL.
  • Folders: key.store (Command Center = home, Service Health Matrix, Every CPU, Traces & Service Map, Logs Explorer, Alerts & SLOs), Fleet (Fleet Hosts, Forge Services, HQ Failsafe, Fly Machines, PlanetScale Postgres, Blob & Data Plane), Services (API, Mail, Authentik & Identity, PostHog Platform, OHTTP & Anonymization), Delivery (CI Pipeline Health, Store Releases & Analytics), Business (Spend & Cash, Product KPIs), Security (Security & Audit).
  • ~70 Grafana-managed alert rules in 7 groups (alerts.tf: fleet, API SLO burn, data plane, PostHog, identity/security, CI, business) + the org home dashboard. The root policy and contact point stay Nix file-provisioned (alerting.dispatcher.routeAll, landed on main in parallel) — this stack is additive. Dashboards bind datasources by name (hidden DS_* variables), alert rules resolve them by name.

Fleet & forge (Nix)

  • New services."key.store".observabilityAgent module (Grafana Alloy): host metrics, journald (level label), local OTLP → forge via the authenticated ingest. HQ enabled (it was completely dark) + hq-watchdog → textfile metrics.
  • traces.key.store becomes the authenticated fleet ingest (Caddy basic_auth, principals hq/staging/api, hashes rendered from age secrets into /run/caddy/security.env; PENDING/missing → unsatisfiable hash, never an empty account). It was an unauthenticated public OTLP gRPC ingress before.
  • Collector: otlp (behind Caddy) + otlp/local; PII-scrubbing attributes processor (ips, user ids, UAs, auth headers, query strings; db.statement hashed), transform/normalize for http.route/status, spanmetrics with exemplars, OTLP logs → Loki /otlp, OTLP metrics → Prometheus remote-write (validated with otelcol-contrib validate).
  • Prometheus: 45d retention, remote-write receiver, exemplar storage; new scrapes: cAdvisor (per-unit/container CPU+mem with real names — process_exporter re-keyed to {{.Comm}} from 5,878 cgroup ids), blackbox (HTTPS probes + TLS expiry for every public hostname incl. relay.oblivious.network), postgres, redis ×3, smartctl, Caddy (metrics global), otelcol, Loki, Tempo, Grafana (via local Host-header proxy), Authentik server :9300, PostHog capture, ClickHouse (prometheus block :9363), Kafka JMX (jmx_prometheus_httpserver :7071) + consumer-group lag textfile, forgejo-ci-exporter :9570.
  • Datasources re-keyed to stable key-store-* uids (follows main's scheme, always-delete re-key), Tempo↔Loki↔Prometheus correlations, dead Jaeger entry removed, PostHog ClickHouse datasource (read-only, posthog db) + plugin; file-provisioned dashboards removed (OpenTofu owns them now). Loki: level label from priority, Caddy JSON access logs re-labelled job=caddy-access.
  • Prometheus-side rules in Nix retired (they had no Alertmanager).

Collectors (services/observability/*.cjs, systemd timers → node_exporter textfile)

  • forgejo-ci-exporter (Forgejo Postgres → runs/jobs/runners/durations/queue wait/last status, 1.4k series in 154 ms live), store-analytics (ASC sales + analytics reports + TestFlight + reviews, Play stats bucket + Reporting API vitals, Chrome Web Store listing, AMO, Flathub, Microsoft Store, GitHub, Homebrew → Prometheus counters/gauges and PostHog store_daily_metrics events), spend-and-cash (Anthropic + OpenAI admin cost/usage APIs, Mercury, Base USDC, beancount, Hetzner cloud, PlanetScale invoices, fixed contracts → spend/tokens/cash/runway), planetscale-org-exporter, posthog-health-exporter (readyz, capture liveness, ClickHouse ingest lag), kafka-consumer-lag-textfile.sh, hq-watchdog-textfile.sh. All degrade per-source; live read-only runs on the forge verified each.

API / Fly edge

  • Server spans named METHOD /route with http.route/http.status_code (the spanmetrics dimensions — RED per route finally works), W3C trace-context extraction (Fly edge Caddy span → API span → dependencies), /v1/telemetry/otlp/{traces,logs} behind the OHTTP trust header (anonymized client traces/logs travel the same relay path as analytics; ≤1 MiB; collector scrubs), Caddy tracing (service key.store-api-edge) + metrics on :9091 ([metrics] in fly.toml → Fly org Prometheus), entrypoint derives OTEL_EXPORTER_OTLP_HEADERS from KEY_STORE_TELEMETRY_INGEST_{USER,PASSWORD}, deploy-api optional (lenient while PENDING) secret. cargo check/cargo test (59 pass), rustfmt.

Validation

tofu validate + live read-only plan against graphs.key.store (38 to add, datasource lookups resolved); alloy validate on the rendered HQ config; otelcol-contrib validate; caddy validate on the forge ingest vhost and the Fly Caddyfile; nix eval of keystore-forge and keystore-hq (pre-rebase — see note); generator self-validates (unique uids, non-overlapping grid, datasource refs).

Post-rebase check (on the forge, branch head 4ee20377): nix eval of keystore-forge and keystore-hq succeeds and tofu validate is green after re-merging the Grafana module on top of main's concurrent policy/forge-health/uid changes.

Go-live order (details: services/observability/graphs-on-forge.md)

  1. Merge → deploy-api ships the new API automatically.
  2. deploy-forge-host (switch).
  3. Scripts/grafana-tofu-adopt.sh (imports the pre-existing key-store folder) → cloud-tofu stack grafana plan/apply → Scripts/grafana-tofu-adopt.sh --retire (deletes the 3 superseded hand-written dashboards).
  4. Deploy HQ once secrets/observability/ingest-password-hq.age is real.

Founder steps (secrets created as PENDING placeholders; nothing was decrypted or rekeyed)

  • generate secrets/observability/ingest-password-{hq,api,staging}.age (openssl rand -base64 36; api is picked up by deploy-api, until then the API exports OTLP unauthenticated and the forge answers 401),
  • secrets/anthropic/admin-api-key.age (Admin API key, usage/cost scope), secrets/openai/admin-api-key.age (org admin key), secrets/observability/mercury-api-token.age (read-only twin of the finance token, forge-readable),
  • optional /etc/key-store/{store-analytics,spend-and-cash}.env on the forge (ASC vendor number, Play reports bucket, CWS/AMO/Flathub ids, Base addresses, fixed vendor contracts) — the dashboards show exactly which item is missing.

Not in this PR (KSE-0191 Phase B): client-side OTEL exporters in the Swift core/Web (the endpoints and scrubbing are ready), relay-origin attestation at the edge.

🤖 Generated with Claude Code

Implements **KSE-0191 — Total Observability v2** (`evolution/proposals/KSE-0191-total-observability-v2-grafana-as-code.md`): every signal, every machine, every dollar, one Grafana as code. Founder direction 2026-08-18: "make our grafana and logging/reporting ultra complete… use opentofu to make dashboards". ## What lands **Grafana as code (OpenTofu, `infra/grafana`)** - 22 dashboards generated from a zero-dependency TypeScript catalog (`services/grafana/src`, ~700 panels); `bun services/grafana/src/generate.ts` + CI gate `Scripts/grafana-dashboards-check.sh`; the stack reads `services/grafana/dashboards/manifest.json` — adding a dashboard is one TS file, zero HCL. - Folders: key.store (Command Center = home, Service Health Matrix, Every CPU, Traces & Service Map, Logs Explorer, Alerts & SLOs), Fleet (Fleet Hosts, Forge Services, HQ Failsafe, Fly Machines, PlanetScale Postgres, Blob & Data Plane), Services (API, Mail, Authentik & Identity, PostHog Platform, OHTTP & Anonymization), Delivery (CI Pipeline Health, Store Releases & Analytics), Business (Spend & Cash, Product KPIs), Security (Security & Audit). - ~70 Grafana-managed alert rules in 7 groups (`alerts.tf`: fleet, API SLO burn, data plane, PostHog, identity/security, CI, business) + the org home dashboard. The root policy and contact point stay Nix file-provisioned (`alerting.dispatcher.routeAll`, landed on main in parallel) — this stack is additive. Dashboards bind datasources **by name** (hidden `DS_*` variables), alert rules resolve them by name. **Fleet & forge (Nix)** - New `services."key.store".observabilityAgent` module (Grafana Alloy): host metrics, journald (`level` label), local OTLP → forge via the authenticated ingest. **HQ enabled** (it was completely dark) + `hq-watchdog` → textfile metrics. - `traces.key.store` becomes the authenticated fleet ingest (Caddy `basic_auth`, principals `hq`/`staging`/`api`, hashes rendered from age secrets into `/run/caddy/security.env`; PENDING/missing → unsatisfiable hash, never an empty account). It was an **unauthenticated public OTLP gRPC ingress** before. - Collector: `otlp` (behind Caddy) + `otlp/local`; PII-scrubbing `attributes` processor (ips, user ids, UAs, auth headers, query strings; `db.statement` hashed), `transform/normalize` for `http.route`/status, spanmetrics with exemplars, OTLP logs → Loki `/otlp`, OTLP metrics → Prometheus remote-write (validated with `otelcol-contrib validate`). - Prometheus: 45d retention, remote-write receiver, exemplar storage; new scrapes: cAdvisor (per-unit/container CPU+mem with real names — process_exporter re-keyed to `{{.Comm}}` from 5,878 cgroup ids), blackbox (HTTPS probes + TLS expiry for every public hostname incl. relay.oblivious.network), postgres, redis ×3, smartctl, Caddy (`metrics` global), otelcol, Loki, Tempo, Grafana (via local Host-header proxy), Authentik server :9300, PostHog capture, ClickHouse (`prometheus` block :9363), Kafka JMX (jmx_prometheus_httpserver :7071) + consumer-group lag textfile, forgejo-ci-exporter :9570. - Datasources re-keyed to stable `key-store-*` uids (follows main's scheme, always-delete re-key), Tempo↔Loki↔Prometheus correlations, dead Jaeger entry removed, **PostHog ClickHouse** datasource (read-only, `posthog` db) + plugin; file-provisioned dashboards removed (OpenTofu owns them now). Loki: `level` label from priority, Caddy JSON access logs re-labelled `job=caddy-access`. - Prometheus-side `rules` in Nix retired (they had no Alertmanager). **Collectors (`services/observability/*.cjs`, systemd timers → node_exporter textfile)** - `forgejo-ci-exporter` (Forgejo Postgres → runs/jobs/runners/durations/queue wait/last status, 1.4k series in 154 ms live), `store-analytics` (ASC sales + analytics reports + TestFlight + reviews, Play stats bucket + Reporting API vitals, Chrome Web Store listing, AMO, Flathub, Microsoft Store, GitHub, Homebrew → Prometheus counters/gauges **and** PostHog `store_daily_metrics` events), `spend-and-cash` (Anthropic + OpenAI admin cost/usage APIs, Mercury, Base USDC, beancount, Hetzner cloud, PlanetScale invoices, fixed contracts → spend/tokens/cash/runway), `planetscale-org-exporter`, `posthog-health-exporter` (readyz, capture liveness, ClickHouse ingest lag), `kafka-consumer-lag-textfile.sh`, `hq-watchdog-textfile.sh`. All degrade per-source; live read-only runs on the forge verified each. **API / Fly edge** - Server spans named `METHOD /route` with `http.route`/`http.status_code` (the spanmetrics dimensions — RED per route finally works), W3C trace-context extraction (Fly edge Caddy span → API span → dependencies), `/v1/telemetry/otlp/{traces,logs}` behind the OHTTP trust header (anonymized client traces/logs travel the same relay path as analytics; ≤1 MiB; collector scrubs), Caddy `tracing` (service `key.store-api-edge`) + `metrics` on :9091 (`[metrics]` in fly.toml → Fly org Prometheus), entrypoint derives `OTEL_EXPORTER_OTLP_HEADERS` from `KEY_STORE_TELEMETRY_INGEST_{USER,PASSWORD}`, deploy-api optional (lenient while PENDING) secret. `cargo check`/`cargo test` (59 pass), rustfmt. ## Validation `tofu validate` + live read-only `plan` against graphs.key.store (38 to add, datasource lookups resolved); `alloy validate` on the rendered HQ config; `otelcol-contrib validate`; `caddy validate` on the forge ingest vhost and the Fly Caddyfile; `nix eval` of `keystore-forge` and `keystore-hq` (pre-rebase — see note); generator self-validates (unique uids, non-overlapping grid, datasource refs). **Post-rebase check (on the forge, branch head 4ee20377):** `nix eval` of `keystore-forge` and `keystore-hq` succeeds and `tofu validate` is green after re-merging the Grafana module on top of main's concurrent policy/forge-health/uid changes. ## Go-live order (details: `services/observability/graphs-on-forge.md`) 1. Merge → `deploy-api` ships the new API automatically. 2. `deploy-forge-host` (switch). 3. `Scripts/grafana-tofu-adopt.sh` (imports the pre-existing `key-store` folder) → `cloud-tofu` stack `grafana` plan/apply → `Scripts/grafana-tofu-adopt.sh --retire` (deletes the 3 superseded hand-written dashboards). 4. Deploy HQ once `secrets/observability/ingest-password-hq.age` is real. ## Founder steps (secrets created as `PENDING` placeholders; nothing was decrypted or rekeyed) - generate `secrets/observability/ingest-password-{hq,api,staging}.age` (`openssl rand -base64 36`; `api` is picked up by deploy-api, until then the API exports OTLP unauthenticated and the forge answers 401), - `secrets/anthropic/admin-api-key.age` (Admin API key, usage/cost scope), `secrets/openai/admin-api-key.age` (org admin key), `secrets/observability/mercury-api-token.age` (read-only twin of the finance token, forge-readable), - optional `/etc/key-store/{store-analytics,spend-and-cash}.env` on the forge (ASC vendor number, Play reports bucket, CWS/AMO/Flathub ids, Base addresses, fixed vendor contracts) — the dashboards show exactly which item is missing. Not in this PR (KSE-0191 Phase B): client-side OTEL exporters in the Swift core/Web (the endpoints and scrubbing are ready), relay-origin attestation at the edge. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
- evolution: KSE-0191 design record (every signal, every machine, every dollar)
- services/grafana/src: zero-dep TS dashboard generator (22 dashboards, ~700
  panels) + manifest; Scripts/grafana-dashboards-check.sh freshness gate
- infra/grafana: folders/dashboards from manifest, ~70 Grafana-managed alert
  rules, notification policy + mute timing, home dashboard, adopt script
- nixos: observability-agent module (Alloy → traces.key.store with basic_auth),
  HQ enabled; forge: authenticated telemetry ingest vhost, Caddy metrics,
  collector PII scrub + logs/metrics pipelines + exemplars, Prometheus
  remote-write receiver/45d, cAdvisor, blackbox, postgres/redis/smartctl
  exporters, Authentik/PostHog/ClickHouse/Kafka/Caddy/otelcol/forgejo-ci
  scrapes, ClickHouse datasource, stable datasource uids + correlations,
  level label + caddy-access stream in Loki
- services/observability: forgejo-ci-exporter, store-analytics (→ Prometheus
  + PostHog), spend-and-cash, planetscale-org, posthog-health, hq-watchdog and
  kafka-lag textfile collectors
- secrets: ingest passwords, admin cost-API keys, mercury twin (PENDING)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- TraceLayer: spans named METHOD /route with http.route/http.status_code
  (what the forge spanmetrics connector keys RED metrics on), W3C parent
  extraction so the Fly edge Caddy span parents the API span
- /v1/telemetry/otlp/{traces,logs}: OHTTP-trust-gated forwarding of client
  OTLP (≤1 MiB, protobuf/json) to the forge collector with the api ingest
  credential — anonymized client traces/logs ride the same relay path as
  analytics
- Fly edge: Caddy tracing (service key.store-api-edge) + metrics on :9091
  ([metrics] in fly.toml); entrypoint derives OTEL_EXPORTER_OTLP_HEADERS
  from KEY_STORE_TELEMETRY_INGEST_{USER,PASSWORD}
- deploy-api: optional (lenient while PENDING) KEY_STORE_TELEMETRY_INGEST_PASSWORD

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
observability: KSE-0191 — follow main's Nix-provisioned root policy; restore incidental file modes
All checks were successful
Build: KaiOS / Build (KaiOS) (pull_request) Successful in 26s
4ee2037755
- infra/grafana: drop the tofu notification policy/mute timing (main now
  file-provisions the root policy via alerting.dispatcher.routeAll and the
  forge-health rule groups); this stack keeps folders, dashboards, rule
  groups and the home dashboard
- datasource uids follow main's key-store-* scheme (re-keyed on every start)
- KSE/runbook/README aligned

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
observability: KSE-0191 — read collector/ingest secrets from OpenBao; fill-dir apply script; known store ids in Nix
Some checks failed
Build: KaiOS / Build (KaiOS) (pull_request) Successful in 23s
Build: Apple / Check (SwiftLint) (pull_request) Has been cancelled
Build: Apple / Build (macOS) (pull_request) Has been cancelled
Build: Apple / Build (iOS) (pull_request) Has been cancelled
Build: Apple / Build (visionOS) (pull_request) Has been cancelled
Build: Linux / Build (Linux x86_64) (pull_request) Has been cancelled
Build: Linux / Build (keystore-forge x86_64) (pull_request) Has been cancelled
Build: sqlite3mc / sqlite3mc smoke (macOS) (pull_request) Has been cancelled
Build: sqlite3mc / sqlite3mc smoke (Linux x86_64) (pull_request) Has been cancelled
Build: Web / Build (Web) (pull_request) Has been cancelled
c4ae00a526
- forge: telemetry ingest passwords as transitional OpenBao entries (age
  fallback, caddy-security-env on the boot frontier); admin cost-API keys,
  Mercury token and Hetzner token as OpenBao-only entries for spend-and-cash
- HQ: ingest password via openbaoSecrets (age fallback)
- Scripts/observability-secrets-apply.sh: txt fill-dir → OpenBao KV + age
  escrow + forge env files + materializer refresh (--template/--generate/
  --seed-pending); collectors treat PENDING values as unset
- ingest passwords generated and written (OpenBao + escrow); PENDING
  placeholders seeded so the materializer never fails on absent entries
- Chrome Web Store item, Firefox add-on guid, Flatpak id, Tuyo wallet in Nix

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
observability: runbook — OpenBao-materialised ingest passwords, stable uid names, go-live wording
All checks were successful
Build: KaiOS / Build (KaiOS) (pull_request) Successful in 23s
Build: Web / Build (Web) (pull_request) Successful in 34s
Build: sqlite3mc / sqlite3mc smoke (Linux x86_64) (pull_request) Successful in 45s
Build: sqlite3mc / sqlite3mc smoke (macOS) (pull_request) Has been skipped
Build: Linux / Build (Linux x86_64) (pull_request) Successful in 3m30s
Build: Linux / Build (keystore-forge x86_64) (pull_request) Has been skipped
Build: Apple / Check (SwiftLint) (pull_request) Successful in 5m13s
Build: Apple / Build (visionOS) (pull_request) Successful in 30s
Build: Apple / Build (iOS) (pull_request) Successful in 48s
Build: Apple / Build (macOS) (pull_request) Successful in 2m41s
c954ef2686
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
founder force-pushed claude/total-observability-v2 from c954ef2686
All checks were successful
Build: KaiOS / Build (KaiOS) (pull_request) Successful in 23s
Build: Web / Build (Web) (pull_request) Successful in 34s
Build: sqlite3mc / sqlite3mc smoke (Linux x86_64) (pull_request) Successful in 45s
Build: sqlite3mc / sqlite3mc smoke (macOS) (pull_request) Has been skipped
Build: Linux / Build (Linux x86_64) (pull_request) Successful in 3m30s
Build: Linux / Build (keystore-forge x86_64) (pull_request) Has been skipped
Build: Apple / Check (SwiftLint) (pull_request) Successful in 5m13s
Build: Apple / Build (visionOS) (pull_request) Successful in 30s
Build: Apple / Build (iOS) (pull_request) Successful in 48s
Build: Apple / Build (macOS) (pull_request) Successful in 2m41s
to a8900a629b
All checks were successful
Build: KaiOS / Build (KaiOS) (pull_request) Successful in 31s
2026-08-22 04:01:14 +00:00
Compare
founder force-pushed claude/total-observability-v2 from a8900a629b
All checks were successful
Build: KaiOS / Build (KaiOS) (pull_request) Successful in 31s
to 6d42839169
Some checks failed
Deploy: API / Deploy (API) (push) Failing after 4s
Namespace: Build Images / Refresh macOS runner lane (push) Successful in 5s
Release: If Needed / Check (Release Needed) (push) Successful in 6s
Build: KaiOS / Build (KaiOS) (pull_request) Successful in 23s
Build: KaiOS / Build (KaiOS) (push) Successful in 23s
Infra: Cloud OpenTofu / Infra (Cloud OpenTofu) (push) Failing after 38s
Namespace: Build Images / Refresh Linux runner image (push) Successful in 42s
Namespace: Build Images / Refresh macOS Nix snapshot application (push) Failing after 41s
Deploy: Web / Deploy (Web) (push) Successful in 3m1s
2026-08-22 04:02:31 +00:00
Compare
Sign in to join this conversation.
No labels
No milestone
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
key-store/key.store!163
No description provided.