Skip to content

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

Merged
Git-on-my-level merged 2 commits into
mainfrom
lane/grafana-stabilize
Oct 14, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
lane/grafana-stabilize

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

What

Stabilizes prod Grafana alert evaluation (2026-10-14 incident: /api/health 502s, 190 Failed to evaluate rule + 120 dropped ticks in 20 min, operator 48 restarts / adapter 35 in 31h, every pusher deploy failing on alert provisioning). Revised per review of round 1: the Prometheus CPU cap is back at 2 — the starvation fix is requests plus the node-pool resize runbook.

1. Raw-line Loki alert rules (the #21390 failure class, again)

Four committed rules query the Loki datasource for raw log lines on a 60s tick — one scans the whole prod-omi-backend namespace with a regex (afd0krbk1bugwf, 196 of 410 rule-eval failures in 3h), another uses the unbounded [$__auto] range. Each evaluation blew the 30s datasource timeout, retried, and dropped ticks:

rule failures/3h
afd0krbk1bugwf OpenAI - Quota Exceeded 196
fewwk2goqfklcf Backend - API Quota Exceeded (429) 50
devzd05c0bocgc Transcription Service Error Rate 48
df2a40h2fbjswe TS Error Rate: Data corrupted 46

Fix: pause all four (split files + combined export kept byte-equal) and record admission_holds in metric-inventory.prod.json. Re-admission requires a bounded counter, never a log datasource.

Coverage after pausing:

  • Corrupted stream → new metric rule omi-listen-audio-decode-failures reads omi_listen_audio_decode_failures_total (backend-listen scrape job; children zero-initialized at startup in utils/metrics.py so family absence is unambiguous).
  • OpenAI quota through the LLM Gateway is already covered by the existing lane rules (omi-llm-gateway-lane-failure-ratio, omi-llm-gateway-lane-zero-success, fallback rate) — llm_gateway_requests_total carries outcome/error_class/upstream_http_status.
  • Listen-429 quota responses, ASGI handshake failures, and direct (non-gateway) OpenAI quota have no counter today — tracked in Alerting coverage gaps after pausing raw-line Loki rules: listen 429 quota, ASGI handshake, direct OpenAI quota #21461.

2. Monitoring-node CPU: requests, not a lower Prometheus cap

The Prometheus CPU limit stays 2 (review): load is sustained at 1.5–2.2 cores across 14h with the node pinned near its 1930m allocatable — the ~2.9-core readings were an artifact of kubelet scrapes timing out mid-sample — and Prometheus is 0% CFS-throttled. The Prometheus-backed rules (omi-stt-fallback-leg-dead 34×, omi-stt-leg-lifecycle-gap 21×) already time out; a lower cap would throttle them further and stall the adapter's custom-metrics reads behind every HPA. Shipped instead:

  • Grafana 250m/384Mi and operator 50m/64Mi requests (stack values), adapter 100m/128Mi (adapter values) — these fix the liveness-probe starvation restarts.
  • Loki read path requests (loki values; file normalized CRLF→LF, untouched since Deploy alternative monitoring logging stack #2708): ingester/querier 50m/256Mi, index-gateway/ruler 20m/128Mi, sized over measured use (ingester 128–210m, querier 21–45m, index-gateway 5m, ruler 9m). Limits stay unset — ingestion must not be throttled.

Requests arithmetic (two pool nodes, 1930m allocatable each; live listing 2026-10-14, nominal replica spread):

  • jzv7 = 1373m (system daemons 373m + Prometheus request 1000m) + 400m (grafana+operator+adapter) + 140m (ingester+querier+index-gateway+ruler) = 1913m ≤ 1930m
  • mczx = 1368m (incl. two 500m memcached caches) + 120m (ingester+querier+index-gateway) = 1488m ≤ 1930m

The durable fix is the 4-vCPU pool resize runbook now in the monitoring README: gcloud container node-pools create monitoring-pool-v2 (e2-highmem-4, zonal us-central1-a so the Grafana/Prometheus standard-rwo PVCs reattach, labels env=prod,service=monitoring, no taints to replicate), then cordon + drain the old pool. Not run here — owner: lead.

Regression guards

  • test_live_alert_rules_never_query_log_datasources rejects any unpaused rule referencing a log datasource (type or prod Loki UID).
  • test_corrupted_stream_log_rule_stays_shadowed_by_the_decode_failures_counter — the paused corrupted-stream log rule must keep its metric shadow; removing one requires deciding both.
  • The decode-failures zero-init is enforced by the startup-exposition contract (test_monitoring_stt_metric_zero_init).

Failure-Class: new

Line-Count-Exception: backend/utils/metrics.py | 1540 -> 1556 | zero-init the 54 bounded omi_listen_audio_decode_failures_total children (codec x client_platform) so the new omi-listen-audio-decode-failures alert has an unambiguous family baseline per the startup-exposition contract

Apply steps (owner: lead — no prod mutations in this PR) — apply off-peak

  1. Record the rollback point: helm history prod-omi-kube-prometheus-stack -n prod-omi-monitoring --kube-context gke_based-hardware_us-central1_prod-omi-gke → note the highest deployed revision (<pre-apply-revision> below).
  2. Pause the four rules live. Grafana's provisioning API has no PATCH on alert-rules/{uid} — GET the full rule, set isPaused: true, PUT the whole body back (with X-Disable-Provenance), checking the HTTP status per uid so a 404/405 cannot look like success:
    for uid in afd0krbk1bugwf fewwk2goqfklcf devzd05c0bocgc df2a40h2fbjswe; do
      curl -fsS -H "Authorization: Bearer $MONITOR_GRAFANA_TOKEN" \
        "https://monitor.omi.me/api/v1/provisioning/alert-rules/$uid" -o "/tmp/$uid.json" \
        || { echo "GET failed: $uid"; exit 1; }
      jq '.isPaused = true' "/tmp/$uid.json" > "/tmp/$uid.paused.json"
      code=$(curl -sS -o /dev/null -w '%{http_code}' -X PUT \
        -H "Authorization: Bearer $MONITOR_GRAFANA_TOKEN" \
        -H 'Content-Type: application/json' -H 'X-Disable-Provenance: true' \
        --data-binary @"/tmp/$uid.paused.json" \
        "https://monitor.omi.me/api/v1/provisioning/alert-rules/$uid")
      if [ "$code" != "200" ]; then echo "PUT $uid -> HTTP $code"; exit 1; fi
      echo "paused $uid (200)"
    done
    # verify all four report isPaused=true
    for uid in afd0krbk1bugwf fewwk2goqfklcf devzd05c0bocgc df2a40h2fbjswe; do
      curl -fsS -H "Authorization: Bearer $MONITOR_GRAFANA_TOKEN" \
        "https://monitor.omi.me/api/v1/provisioning/alert-rules/$uid" \
        | jq -r --arg uid "$uid" '"\($uid): isPaused=\(.isPaused)"'
    done
  3. Stack values (grafana/operator requests): workflow_dispatch Deploy Cloud Run Metrics Egress (gcp_cloud_run_metrics_egress.yml) on main with environment=prod (requires prod Environment approval). Off-peak because the Prometheus pod restarts and replays its WAL (~700k–980k head series): during replay the adapter serves stale custom metrics and the pusher/listen/parakeet/VAD/diarizer HPAs freeze. The rollout also carries Make batch diarizer installation isolated, observable and image-qualified #21448's diarizer-batch-metrics scrape job + adapter rule, which are inert (no batch pods exist yet).
  4. Loki values (read-path requests): manual helm per the README (helm upgrade --install prod-omi-loki grafana/loki -f loki/prod_omi_loki_values.yaml, prod context/namespace).
  5. Adapter values: manual helm per the README — render/diff prerequisite first, then the pinned helm upgrade ... --atomic --wait --timeout 10m.

Rollback

Verify

  • https://monitor.omi.me/api/health: 10 consecutive 200s at 30s spacing.
  • Grafana logs 30 min post-rollout: Failed to evaluate rule = 0, Tick dropped = 0.
  • Operator/adapter restart counters flat for 1h.
  • A pusher deploy (gcp_backend_pusher.yml) passes Grafana alert provisioning + post-rollout reverify.
  • Replacement rule live: sum(omi_listen_audio_decode_failures_total) returns the zero-initialized series.
  • The down-target count (2026-10-14: 109 of 286, incl. 34 stale kubelet endpoints from the operator crash-loop) converges upward once the operator stays running.

Evidence commands (read-only)

kubectl --context gke_based-hardware_us-central1_prod-omi-gke -n prod-omi-monitoring logs <grafana-pod> -c grafana --since=3h (failure counts by rule_uid), kubectl get events --field-selector involvedObject.name=<operator-pod>, kubectl top nodes, Prometheus prometheus_tsdb_head_series, max_over_time(scrape_duration_seconds[3h]), count(up==0) / count(up).

View guided diff Turn on auto-fix

…g-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).
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 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-14T06:45:44.414841Z e4aa051 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: 62fe7ad004

ℹ️ 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".

# SIGTERM-killed by its own liveness probe 48 times in 31h whenever Prometheus
# bursts consumed the node. Requests buy it a guaranteed share (measured use:
# 2-25m CPU, 25Mi). Probe timeout stays at the chart default.
operator:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Move operator resources under prometheusOperator

The kube-prometheus-stack chart renders operator resources from .Values.prometheusOperator.resources (see the vendored template at backend/charts/deepgram-self-hosted/nova-3/charts/kube-prometheus-stack/templates/prometheus-operator/deployment.yaml:157-158), so this unknown top-level operator block is ignored during the workflow's Helm upgrade. Consequently, the operator remains BestEffort and retains the probe-starvation/restart failure this change is intended to fix; rename this key to prometheusOperator.

Useful? React with 👍 / 👎.

# Referenced here so a rule that names the datasource only by UID cannot slip
# past the type check below.
LOG_DATASOURCE_UIDS = {"aet29e27cgmwwc"}
LOG_DATASOURCE_TYPES = {"loki", "cloudlogging"}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Recognize the actual Cloud Logging datasource type

Grafana exports the Cloud Logging plugin as googlecloud-logging-datasource, not cloudlogging; for example, the currently unpaused omi-cr-start-fail rule uses that exact type and UID deuxlwt1d569sb in alerts/backend.json. This test therefore passes while a live rule still scans raw Cloud Logging lines, and future rules using the same datasource also evade the incident-prevention guard. Include the exported type and/or the production Cloud Logging datasource UID.

Useful? React with 👍 / 👎.

Comment thread backend/charts/monitoring/README.md Outdated
Comment on lines +1006 to +1010
1 CPU / 2Gi memory requests, 1600m CPU / 8Gi memory limits, and a 100Gi
`standard-rwo` claim. The CPU limit sits below the monitoring node's ~1930m
allocatable so Prometheus bursts cannot starve the kubelet probes, Grafana and
the operator on the same node (2026-10-14: 48 operator and 35 adapter
liveness-probe restarts in 31h, Grafana `/api/health` 502s); Grafana and the

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 Update the preflight's expected production diff

This section now documents intentional Grafana resource and Prometheus CPU changes, but the same production procedure still says at lines 1044-1049 that rendering these values against revision 14 must produce an empty diff and that a Helm revision should not be created otherwise. An operator following the runbook for this incident will necessarily see the resource changes and receive contradictory guidance about applying them; update the expected-diff text to enumerate the intended manifests or compare against the new post-rollout baseline.

Useful? React with 👍 / 👎.

…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.

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

ℹ️ 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".

Comment on lines +1456 to +1457
"id": 86,
"uid": "omi-listen-audio-decode-failures",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add the replacement rule to the Grafana import path

When this change is rolled out through the documented production workflow, this replacement remains repository-only: gcp_cloud_run_metrics_egress.yml invokes verify_pusher_live_alert_route.py --mode import, but that importer reads alerts/live-stt.json and its LIVE_STT_IMPORT_UIDS does not contain this UID; the subsequent fleet check only fails for gated rules. Because Helm does not provision Grafana alerts and production is the live source, pausing df2a40h2fbjswe as prescribed leaves corrupted-audio failures without the claimed live replacement unless this UID is added to an import path or explicitly created through the provisioning API.

Useful? React with 👍 / 👎.

Comment on lines +97 to +101
queryFrontend:
replicas: 2
maxUnavailable: 1
nodeSelector:
<<: *nodeSelector

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 Reserve CPU for the complete Loki read path

Under the CPU-saturation scenario this change is intended to fix, the two queryFrontend pods remain without resource requests, as do the configured queryScheduler pods immediately below them. In distributed Loki, every query is received by the query frontend and passed through the scheduler before a querier executes it, so these BestEffort stages can still be starved even though the downstream queriers and index gateways are now Burstable (Grafana Loki read-path documentation). Add requests for both components so the reservation actually covers the end-to-end query path.

Useful? React with 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit 9a54787 into main Oct 14, 2026
56 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/grafana-stabilize branch October 14, 2026 06:58
Git-on-my-level added a commit that referenced this pull request Oct 14, 2026
…Operator key (#21468)

#21455 used a top-level operator: key, which kube-prometheus-stack ignores, so
prod kept the operator BestEffort. Rename the key and guard top-level keys.

Co-authored-by: Claude Opus 5.5 <[email protected]>
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