Skip to content

fix(monitoring): Grafana SQLite WAL + lock retries, external Grafana dead-man - #21306

Merged
Git-on-my-level merged 3 commits into
mainfrom
obs/grafana-sqlite-wal-deadman
Oct 12, 2026
Merged

Git-on-my-level merged 3 commits into
mainfrom
obs/grafana-sqlite-wal-deadman

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Why

Prod Grafana is the alerting plane for every alerts/*.json rule, and it runs on the default SQLite store. grafana.ini has no [database] section; the DB lives on a 20Gi standard-rwo PVC.

On 2026-10-12, measured read-only via ro-prod, it logged two bursts of database is locked: 11 lines at 03:02Z and 67 at 09:02Z. During the burst:

  • Tick dropped because alert rule evaluation is too slow
  • Failed to apply Alertmanager config for org … failed to list alert rules … database is locked
  • Failed getting data source … database is locked
  • Unable to sync admin configuration
  • API 500/502 (a provisioning GET took 32.7 s)
  • liveness/readiness probe failures (503 and timeouts)

So alert evaluation and notification are unreliable for minutes at a time, and nothing outside Grafana notices, because Grafana cannot alert on its own outage.

What changes

  1. SQLite contention mitigation (prod and dev values, Grafana 12.1.0). Adds [database] wal = true, query_retries = 10 and transaction_retries = 10.

    • The option names and types are verified against Grafana v12.1.0 conf/defaults.ini and pkg/services/sqlstore/database_config.go. The defaults are false / 0 / 5.
    • The DB type, path, PVC and probes are unchanged. WAL keeps grafana.db-wal/-shm beside grafana.db on the same RWO mount, which is fine for this single-pod deployment.
    • Migrating to Postgres (Cloud SQL) remains the proper follow-up; it's documented in the monitoring README.
  2. External dead-man for Grafana itself.

    • A Cloud Monitoring uptime check on https://monitor.omi.me/api/health: 60 s period, from USA/EUROPE/ASIA_PACIFIC.
    • An alert policy that fires when more than one checker location fails for 5 minutes (ALIGN_NEXT_OLDER + REDUCE_COUNT_FALSE grouped by check_id, > 1), so one region's network blip doesn't page.
    • Both are declared in backend/deploy/monitoring/grafana-deadman.json and reconciled idempotently by .github/scripts/ensure_grafana_deadman.py.
    • Lookup is by display name. The script fails on duplicates and never creates twice. Uptime-check PATCH masks contain only drifted mutable fields; immutable drift fails with delete-and-recreate instructions.
    • The tests' fake API enforces the real update-mask allowlists.
  3. Workflow. gcp_cloud_run_metrics_egress.yml (prod dispatch only):

    • fails closed before credentials or Helm if MONITORING_DEADMAN_NOTIFICATION_CHANNELS is unset;
    • runs the ensure step under the prod monitoring WIF identity.

    This is a new variable; the misnamed SYNC_BACKFILL_ALERT_NOTIFICATION_CHANNELS is not reused.

Before / after merge (operator)

  • Before the prod dispatch:
    • Create the repo or prod-environment variable MONITORING_DEADMAN_NOTIFICATION_CHANNELS (comma-separated full channel resource names).
    • Confirm that [email protected] has Monitoring uptime-check and alert-policy write permission.
  • Deploy: workflow_dispatch gcp_cloud_run_metrics_egress.yml on main with environment=prod. This needs environment approval.
  • Impact: a brief single-pod Grafana restart, during which dashboards, evaluations and Grafana notifications pause. The PVC is retained.

Verification

  • Ensure-script tests (dead-man + generic policy + route-5xx): 59 passed.

  • Monitoring suites through backend/test.sh: 115 passed.

  • make preflight: 40 checks. YAML parses; actionlint is clean; no cached chart was available for helm template.

  • Independent review (Cursor Grok) found two defects, both fixed in ff1195e044b:

    • the per-location condition would page on one region;
    • the uptime PATCH mask would have been rejected by the API.

    The review confirmed the 12.1 option names/types, the WAL file placement, the prod-only fail-closed gate, and the prod identity on the ensure step.

Product invariants affected

  • INV-DATA-1 — touched only because .github/workflows/gcp_cloud_run_metrics_egress.yml matches the gcp_*.yml glob. The change adds a prod-only Cloud Monitoring uptime check + alert policy for monitor.omi.me (Grafana) and a fail-closed variable check. It does not change any artifact's serving authority, Firebase/Firestore project, or release-pipeline routing.

Failure-Class: FC-alert-never-provably-fired

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

Git-on-my-level and others added 2 commits October 12, 2026 17:29
Enable WAL and increase the SQLite query and transaction retry budgets for
Grafana 12.1.0 in dev and prod, preserving the existing database and PVC.
Reconcile a multi-region Cloud Monitoring health check and five-minute
failure policy through the approved prod monitoring workflow. Require
MONITORING_DEADMAN_NOTIFICATION_CHANNELS and document rollout prerequisites.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Require more than one failed checker location for five minutes after
next-older alignment and count-false reduction grouped by check ID.
Patch only drifted mutable uptime fields and reject immutable drift with
manual delete-and-recreate remediation. Enforce real API field allowlists
and multi-location alert semantics in the regression tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T16:53:26.023046Z 16e4cef New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ff1195e044

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

"comparison": "COMPARISON_GT",
"thresholdValue": 1,
"duration": "300s",
"aggregations": [{"alignmentPeriod": "60s", "perSeriesAligner": "ALIGN_NEXT_OLDER", "crossSeriesReducer": "REDUCE_COUNT_FALSE", "groupByFields": ["metric.label.check_id"]}],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Count failing regions rather than checker locations

When two U.S. checker locations fail while Europe and Asia Pacific remain healthy, REDUCE_COUNT_FALSE produces 2, so this > 1 condition pages for an outage confined to one selected region. The USA selection expands to three distinct checkers, while Europe and Asia Pacific each have one, as documented in Google's uptime-check documentation; therefore this does not provide the intended regional quorum and disproportionately treats U.S. failures as global. Encode a region-level quorum rather than reducing all checker-location series directly.

Useful? React with 👍 / 👎.

if immutable:
raise RuntimeError(
f'Uptime check {name} has immutable field drift: {", ".join(immutable)}. '
'Manual remediation: delete and recreate the uptime check, then rerun '

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Remove the alert-policy dependency before deleting the check

When any managed immutable field drifts after the policy has been created, this remediation cannot be followed as written: the policy filter references the existing check ID, and the Monitoring API explicitly rejects deleting an uptime check referenced by an alert policy. The operator must first remove or retarget the dependent policy, so provide that ordering (or automate it) before instructing them to delete and recreate the check.

Useful? React with 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit db1b0d9 into main Oct 12, 2026
58 checks passed
@Git-on-my-level
Git-on-my-level deleted the obs/grafana-sqlite-wal-deadman branch October 12, 2026 17:25
Git-on-my-level added a commit that referenced this pull request Oct 14, 2026
…rrupted-stream rule

Review revision of #21455 round 1:

- Prometheus CPU limit back to "2": load is sustained 1.5-2.2 cores over
  14h (the ~2.9-core spikes were kubelet scrape-timeout artifacts), 0%
  CFS-throttled, and the Prometheus-backed rules already time out - the
  1600m cap would throttle them and the adapter's HPA metrics further.
  Starvation is fixed with requests plus the pool resize runbook instead.
- Loki read path (ingester/querier 50m/256Mi, index-gateway/ruler
  20m/128Mi) gets requests, arithmetic in the values file: jzv7 1913m of
  1930m allocatable, mczx 1488m. loki values normalized CRLF->LF
  (file untouched since #2708; the hygiene check rejects new CRLF lines).
- README: rollback now records the pre-apply helm revision (rolling back
  to rev 14 would revert #21306/#21389/#21358/#21409; #21389 is
  screenshots-off, the 10-13 502 fix); corrected the "renders with no
  diff" claim; added the 4-vCPU pool resize runbook (exact gcloud create
  + cordon/drain, zonal us-central1-a so the Grafana/Prometheus PVCs
  reattach); stack applies marked off-peak (Prometheus WAL replay of
  ~700k-980k head series freezes the pusher/listen/parakeet/VAD/diarizer
  HPAs; #21448's inert diarizer scrape job rides along); the 109/286
  down-target count (34 stale kubelet endpoints) noted as operator
  crash-loop fallout expected to clear.
- New metric rule omi-listen-audio-decode-failures shadows the paused
  corrupted-stream log rule on omi_listen_audio_decode_failures_total
  (startup zero-init children added); listen-429, ASGI-handshake and
  direct-OpenAI-quota gaps tracked in #21461.
Git-on-my-level added a commit that referenced this pull request Oct 14, 2026
…g-node CPU (#21455)

* fix(monitoring): hold raw-line Loki alert rules and reserve monitoring-node CPU

2026-10-14 prod: Grafana /api/health flapped 502, alert evaluation logged
190 failures + 120 dropped ticks over 20 minutes, the prometheus operator
restarted 48x and the adapter 35x in 31h, and every pusher deploy failed on
alert provisioning. Two causes, both read-verified against prod:

1. Four committed alert rules query the Loki datasource for raw log lines
   (whole-namespace regex scans, 60s ticks, one with [$__auto]). They caused
   340 of 410 rule-eval failures in 3h (196 from afd0krbk1bugwf alone), each
   timing out past the 30s datasource budget - the same failure class as the
   2026-10-13 Cloud Logging rule (#21390). Pause all four and hold them in
   metric-inventory admission_holds; re-admit only on bounded counters.

2. Grafana, the operator and the adapter ran BestEffort on a ~1.93
   allocatable-core monitoring node while Prometheus's 2-CPU limit exceeded
   total node capacity, so Prometheus bursts starved kubelet probes (the
   operator/adapter restart mechanism - SIGTERM after probe timeout) and
   Grafana's HTTP server. Cap Prometheus at 1600m and give Grafana, the
   operator and the adapter explicit requests.

New contract test rejects any unpaused rule referencing a log datasource
(type or prod Loki UID); README documents the policy. The 2-vCPU monitoring
node pool remains undersized for 592k head series - resizing it is the
follow-up (owner: infra).

* fix(monitoring): Loki read-path requests, metric shadow for paused corrupted-stream rule

Review revision of #21455 round 1:

- Prometheus CPU limit back to "2": load is sustained 1.5-2.2 cores over
  14h (the ~2.9-core spikes were kubelet scrape-timeout artifacts), 0%
  CFS-throttled, and the Prometheus-backed rules already time out - the
  1600m cap would throttle them and the adapter's HPA metrics further.
  Starvation is fixed with requests plus the pool resize runbook instead.
- Loki read path (ingester/querier 50m/256Mi, index-gateway/ruler
  20m/128Mi) gets requests, arithmetic in the values file: jzv7 1913m of
  1930m allocatable, mczx 1488m. loki values normalized CRLF->LF
  (file untouched since #2708; the hygiene check rejects new CRLF lines).
- README: rollback now records the pre-apply helm revision (rolling back
  to rev 14 would revert #21306/#21389/#21358/#21409; #21389 is
  screenshots-off, the 10-13 502 fix); corrected the "renders with no
  diff" claim; added the 4-vCPU pool resize runbook (exact gcloud create
  + cordon/drain, zonal us-central1-a so the Grafana/Prometheus PVCs
  reattach); stack applies marked off-peak (Prometheus WAL replay of
  ~700k-980k head series freezes the pusher/listen/parakeet/VAD/diarizer
  HPAs; #21448's inert diarizer scrape job rides along); the 109/286
  down-target count (34 stale kubelet endpoints) noted as operator
  crash-loop fallout expected to clear.
- New metric rule omi-listen-audio-decode-failures shadows the paused
  corrupted-stream log rule on omi_listen_audio_decode_failures_total
  (startup zero-init children added); listen-429, ASGI-handshake and
  direct-OpenAI-quota gaps tracked in #21461.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant