Skip to content

feat(relay): alert on cell disconnect bursts and database pool herds - #26363

Merged
Jinwoo-H merged 3 commits into
mainfrom
relay-surge-alerts
Oct 8, 2026
Merged

Jinwoo-H merged 3 commits into
mainfrom
relay-surge-alerts

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​45 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​45
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​105 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​104

ELI5

On-call gets two new alerts. One fires when a relay cell suddenly loses hundreds of desktop connections at once. The other fires when a cell has an unusually long line of requests waiting for a database connection. If both fire together, the network dropped the desktops and their reconnects jammed the cell, so the database is fine. If only the second fires, look at the database.

What Changed

Before: on 2026-10-06 at 18:34 UTC, Google's load balancer dropped 1,046 asia-east2 desktop connections at once. An ops-log entry recorded it as a "big DB stall", because nothing distinguished a mass disconnect from a database problem.

After: three additions to relay-observability.tf.

  1. Orca Relay: cell desktop disconnect burst (notifies). Fires when one GCE cell sees more than 120 desktop control sockets end without a close frame (code 1006) within a minute. It is built on a new counter, orca_relay_cell_control_abnormal_closes, which counts the cell's own [orca-relay] control closed ... code=1006 log line.
  2. Orca Relay: cell database pool herd (notifies). Fires when a cell's runtime sample shows more than 200 requests queued at once for a PostgreSQL connection. It is built on orca_relay_cell_pool_herd, which keeps only samples with databasePoolWaitersMax > 200.
  3. orca_relay_host_hellos_shed. A snapshot metric for the refusal counter that fix(relay): refuse host hellos fast when the database pool is timing them out; renewals jump the queue #26362 adds. It stays empty until cells run that image.

Each policy's documentation names the first response, including where to look and what not to touch.

Why

Why not count the load balancer's internal_error log entries (the original plan). The load balancer writes a WebSocket's log entry when the stream closes, but stamps it with the time the stream started, and log-based metrics count by that stamp. In the 18:34 raw data, only 42 of the 1,046 internal_error entries were stamped within 10 minutes of the drop. The median stamp was 2.4 hours earlier and the oldest 7 hours earlier. A per-minute rate on those entries would smear the pulse across hours and never fire, and any stream older than 24 hours isn't counted at all. The cell logs each close at the moment it happens, so its line gives a rate that lines up with the drop.

Why 120 per cell per minute. In the 18:34 minute, the five asia-east2 cells logged 213-247 such closes each. The minutes around it ran 6-49 per cell. US cells logged 17 or fewer closes per minute, counting every close code. The trade-off: the smaller drops that day, at 01:33 and 20:40 UTC (about 60 per cell), stay under the bar. Those cost 152-2,728 failed queries, against 17,912 at 18:34, and #26362 is meant to absorb them.

Why 200 waiters. A healthy cell peaks at 2 waiters (p99 on 2026-10-07). Single-cell stalls of 50-196 waiters recur several times a day, mostly on the asia-east2 cells. Each lasts about 30 seconds and is already timing requests out: the 184-196 readings on 10-07 each came with 96-367 SQL failures. Those stalls are left to the SQL-failure alerts, and this bar pages on herds. Episodes since 2026-10-03, from the review's production sample, reproduced from the raw samples:

Rule Episodes in 4.9 days
> 50, one sample 84
> 150, one sample 29
> 50, two samples in a row 24
> 150, two samples in a row 10
> 200, one sample (chosen) 10

At > 200, six of the ten episodes are herds across several cells: 10-03 17:50, 10-05 06:26 and 18:22, 10-06 01:33 and 18:34, and 10-07 20:00. The other four are a single cell at 201-228. Two samples in a row at > 150 also gives 10 episodes, but it fires a minute late on the 10-05 06:26 herd and still pages on a single cell at 196 (10-07 07:39). It also needs a condition that can straddle a minute boundary, so the simpler bar is the better fit for the data.

Why the interval maximum, and why the threshold sits in the filter.

  • databasePoolWaitersMax is the largest queue seen during each 30-second sample, so a herd that lasts under a minute still shows. An instantaneous sample can miss it.
  • The runtime metrics use exponential buckets (…128, 256…). A percentile alert would read any value from 128 to 255 as above 200, so the bar goes in the metric filter instead, the same as the existing long-lock-hold metric.

Linked Issue

Fixes # (no issue; follow-up to the 2026-10-06 18:34Z asia-east2 RCA)

Visual Proof

N/A. Monitoring configuration only; no UI.

Testing

  • terraform validate (init with -backend=false) is clean, and terraform fmt -check passes.

  • New dev/scripts/relay-reconnect-herd-alerts.test.mjs pins both filters to text the relay actually writes: the close log line in host-session-registry.ts and the databasePoolWaitersMax field. A rename on either side now fails CI instead of silencing the alert.

  • Added the three new resource families to dev/fixtures/terraform-root-partition/families.json.

  • The cloud pretest set passes (193 tests), and so does the dev-script test set (737). The pin test now checks the > 200 bar.

  • Not applied anywhere. The thresholds come from the 18:33-18:37 UTC cell logs and the RCA, not from a longer baseline, so the 120 bar may need tuning after a week of data.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Merge timing: relay-observability.tf and cloud/package.json are in the relay evidence-code set (relay-evidence-code-provenance.mjs). Merging this invalidates any sealed or in-flight monitor dry-run, so merge between rolls, then run a fresh monitor.
  • Applying this creates three new resources and changes no existing ones. Only GCE cells are covered; production runs no Cloud Run cells.
  • Independent of fix(relay): refuse host hellos fast when the database pool is timing them out; renewals jump the queue #26362: it can merge before or after, and the shed metric fills in once cells roll.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Two alert policies that separate a load-balancer mass disconnect from a
database stall, after the 2026-10-06 18:34Z asia-east2 drop:

- Disconnect burst: over 120 code-1006 desktop control closes on one cell
  in a minute, counted from the cell's own close line. The LB's
  internal_error log entries carry the stream start as their timestamp
  (median 2.4 h before the drop), so an LB-log rate never shows the pulse.
- Pool herd: a cell runtime sample with more than 50 requests queued for a
  PostgreSQL connection (interval maximum, bar in the filter).

Also publishes orca_relay_host_hellos_shed for the refusal counter from
#26362, and pins both filters to the relay's text in a contract test.
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 468e095a-e400-4bec-a454-c6f12aeeefaa
📥 Commits

Reviewing files that changed from the base of the PR and between a7b4a10 and e9eba9f.

📒 Files selected for processing (2)
  • cloud/dev/scripts/relay-reconnect-herd-alerts.test.mjs
  • cloud/infra/terraform/relay-observability.tf
🚧 Files skipped from review as they are similar to previous changes (2)
  • cloud/dev/scripts/relay-reconnect-herd-alerts.test.mjs
  • cloud/infra/terraform/relay-observability.tf

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.


📝 Walkthrough

Walkthrough

The change adds Terraform metrics and alerts for abnormal relay control closes and database pool queue pressure. It adds tests for the metric and alert configuration, registers the alert resources in the relay fixture family list, and includes the test in the root pretest suite.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to e9eba

This change adds monitoring alerts for relay disconnect bursts and database pool herds. It does not alter application behavior. The thresholds may need tuning after real data arrives, but no merge-blocking risk is evident.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the two primary changes: alerts for relay cell disconnect bursts and database pool herds.
Description check ✅ Passed The description is detailed and mostly complete. It explains the user impact, implementation, rationale, testing, visual-proof status, scope, risks, and checklist results. The Linked Issue section doe…
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

asia-east2 cells reach 184-196 waiters outside any herd, so >50 would have
fired in 84 episodes since 2026-10-03. >200 fires in 10, covering every known
herd. Drops the false 'healthy peak is 2 waiters' baseline from the policy text.
A healthy cell peaks at 2 waiters (p99); the 50-196 readings are single-cell
stalls that already time out. The 200 bar is unchanged.
@Jinwoo-H
Jinwoo-H merged commit 8cf6228 into main Oct 8, 2026
23 checks passed
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