Repository navigation
fix(relay-ops): align the cloud-data freshness bar with Cloud Monitoring publish lag - #18798
Conversation
|
📝 WalkthroughWalkthroughThe incident monitor now uses separate freshness thresholds for Cloud Monitoring, director-admin data, and lock-wait carry behavior. It tolerates up to two consecutive freshness-only failures and records them in continuity events. Non-freshness failures and later freshness failures reset the monitoring window. Persisted continuity events remain compatible with older state files. Tests and documentation cover the updated thresholds and lifecycle behavior. Merge Risk: 🟡 Moderate · up to After restart, one stale sample can incorrectly reset a healthy continuity window, and the runbook can mislead incident operators. The resume defect should be fixed before merge. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the problem, implementation, rationale, tests, and known limitation. However, it does not follow the required template and omits the mandatory linked issue, visual-proof entry or N/A explanation, review and checklist sections, and required testing checkboxes. Resolution Add a valid issue reference after Full details: Docstring CoverageExplanation Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 7 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: a26369b4-a5e6-494a-92bf-e42ae361ad15
📒 Files selected for processing (8)
cloud/apps/relay-ops/src/incident-live-preflight-cli.test.tscloud/apps/relay-ops/src/incident-live-preflight-cli.tscloud/apps/relay-ops/src/incident-monitor-cli.tscloud/apps/relay-ops/src/incident-monitor-sources.test.tscloud/apps/relay-ops/src/incident-monitor-sources.tscloud/apps/relay-ops/src/incident-monitor.test.tscloud/apps/relay-ops/src/incident-monitor.tscloud/docs/relay-incident-monitor.md
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
| const last = events[events.length - 1] | ||
| if (!last?.tolerated) return streaks |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Anchor resumed streaks to the latest sample.
runIncidentMonitor removes a key from freshnessStreaks when the current sample has no tolerated failure for that key, but fresh samples append no continuityEvents entry. After a restart, resumeFreshnessStreaks can restore a tolerated event from before the latest fresh samples and count the next stale sample against that old streak. Compare the trailing tolerated event with state.lastSampleAt before restoring it. The existing per-key failure check already prevents events for other keys from extending this key’s streak.
| A signal that reads missing or stale may miss up to two consecutive samples | ||
| without restarting the window. The sample still counts and is still checked | ||
| against every threshold it can read, and each tolerated gap is recorded in | ||
| `continuityEvents` with `tolerated: true`. A third consecutive miss of the same | ||
| signal, a failed collector, a runner gap, or any threshold breach restarts or | ||
| freezes as before. |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Correct the stale workflow description.
The production workflow uses this document as an operator runbook. The evaluator tolerates the first two consecutive missing or stale readings for one signal, but a collector failure, runner gap, third consecutive miss, or threshold breach restarts or freezes the window. Update the workflow description to state these conditions accurately.

Problem
The relay incident monitor treats a Cloud Monitoring series older than
cloudDataMaxAgeMs(180 s) assignal_stale, and any freshness failure restarts the 15-minute continuity window. The bar sat below Google's own documented publish delay, so a healthy fleet failed the gate on Google's clock.Production, 2026-09-04/05:
auth.errorsauth.errorscloud_sql.lock_waitscontinuity_deadline_exceeded(1 500 004 > 1 500 000 ms)The last one is the real cost: a 25-minute gate produced no verdict at all while every sample was health-green.
Documented visibility delays
From Google's metric list (read 2026-09-05):
run.googleapis.com/request_countrun.googleapis.com/container/instance_countrun.googleapis.com/container/cpu/utilizationsrun.googleapis.com/container/memory/utilizationsrun.googleapis.com/container/max_request_concurrenciescloudsql.googleapis.com/database/cpu/utilizationcloudsql.googleapis.com/database/memory/utilizationcloudsql.googleapis.com/database/postgresql/num_backendscloudsql.googleapis.com/database/postgresql/backends_in_waitcloudsql.googleapis.com/database/postgresql/deadlock_countSources:
metrics_gcp_p_z(Cloud Run),metrics_gcp_c(Cloud SQL).Derivation of 330 s
The newest visible point can be as old as the sampling period plus the visibility delay: 180 s for Cloud Run, 225 s for Cloud SQL. A third class dominates both. For
window-sumsignals (auth.errors,director.errors,cloud_sql.deadlocks)observedAtis the newest point in the 5-minute query window, so a label series that stops emitting reads as up to 300 s old while its summed value is complete and correct. That is exactly theauth.errorscase above, and it is why 255 s appeared despite Cloud Run documenting 180 s. 300 s (query window) + ~30 s of collect-to-evaluate latency, observed at 9-19 ms-scale seconds in the runs above, gives 330 000 ms.Changes
cloudDataMaxAgeMs180 000 -> 330 000, with the derivation in the comment.directorAdminMaxAgeMs: 180 000(new).director-adminsharedcloudDataMaxAgeMs, so raising the cloud bar would have silently loosened a source that answers live on our own request. Pinned at its current value.relayLogMaxAgeMs,activeProbeMaxAgeMsandheartbeatMaxAgeMsare untouched.cloudLockWaitCarryMs: 180 000(new). The nonzero backends-in-wait carry window also referencedcloudDataMaxAgeMs; carrying a point for the full 330 s would hand the evaluator a reading older than its own freshness bar once collection latency is added, re-creating the 04:46 failure at the new boundary. Pinned at 180 s.signal_missing,signal_stale,source_missing,source_stale) no longer restarts the window. The window continues, the sample counts, and the gap is recorded incontinuityEventswithtolerated: true. A signal may miss at mostINCIDENT_FRESHNESS_TOLERANCE_SAMPLES(2) consecutive samples; the third restarts the window.collector_failed,monitor_gap, a selector mismatch and every threshold breach behave exactly as before, and the continuity deadline is unchanged.Why this is safe for a gate: a stale sample is still evaluated against every threshold it can read, so the value is checked, just against a slightly older point. A signal that goes genuinely dark stays dark for far more than two samples and still restarts. The status quo is not the safe option: it converts a benign publish blip into no verdict, which is how a gate gets routed around by hand.
Tolerance streaks are rebuilt from the trailing
continuityEventson resume, so a restarted monitor cannot hand a signal a fresh budget.FRESHNESS_FAILURE_CODESset inincident-live-preflight-cli.ts; it now imports the one inincident-monitor.ts.Tests
incident-monitor.test.tsgains: the exact 04:46 case (a 189 286 mscloud_sql.lock_waitsreading is green, anddirector-adminat the same age is still stale); a signal past the new bar still fails; a single stale cloud sample carries a 15-minute window to a passing dry run; a signal only regains budget after reading fresh; a resumed monitor keeps its spent budget; a threshold breach arriving with a tolerated stale signal still freezes. The two restart-on-stale tests now inject three consecutive stale samples, and the 25-minute deadline test does the same.Mutation-checked: reverting
cloudDataMaxAgeMsto 180 000,directorAdminMaxAgeMsto 330 000, the lock-wait carry tocloudDataMaxAgeMs, or the tolerance budget to 0 each fails at least one test.pnpm --filter @orca-cloud/relay-ops typecheckis clean.cloud/**is excluded from oxlint, so tsc is the lint gate here.Not done
The Markdown checkpoint summary still reports only
sampleCountand threshold failures. Tolerated freshness gaps are visible instate.jsonundercontinuityEvents, not in the rendered table.