Skip to content

fix(relay-ops): align the cloud-data freshness bar with Cloud Monitoring publish lag - #18798

Merged
Jinwoo-H merged 1 commit into
mainfrom
relay-monitor-cloud-freshness-bar
Sep 5, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
relay-monitor-cloud-freshness-bar

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​257 $\color{#cf222e}{\Huge{\mathbf{−}}}$​20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​237
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​131 $\color{#cf222e}{\Huge{\mathbf{−}}}$​14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​117

Problem

The relay incident monitor treats a Cloud Monitoring series older than cloudDataMaxAgeMs (180 s) as signal_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:

Run Time (UTC) Signal Observed age Outcome
33928912676 23:24:01 auth.errors 181 397 ms window restart
33928912676 23:25:14 auth.errors 254 951 ms window restart
33944873727 04:46:09 cloud_sql.lock_waits 189 286 ms restart, then continuity_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):

Metric Sampling Not visible for up to
run.googleapis.com/request_count 60 s 120 s
run.googleapis.com/container/instance_count 60 s 120 s
run.googleapis.com/container/cpu/utilizations 60 s 120 s
run.googleapis.com/container/memory/utilizations 60 s 120 s
run.googleapis.com/container/max_request_concurrencies 60 s 120 s
cloudsql.googleapis.com/database/cpu/utilization 60 s 165 s
cloudsql.googleapis.com/database/memory/utilization 60 s 165 s
cloudsql.googleapis.com/database/postgresql/num_backends 60 s 165 s
cloudsql.googleapis.com/database/postgresql/backends_in_wait 60 s 165 s
cloudsql.googleapis.com/database/postgresql/deadlock_count 60 s 165 s

Sources: 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-sum signals (auth.errors, director.errors, cloud_sql.deadlocks) observedAt is 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 the auth.errors case 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

  1. cloudDataMaxAgeMs 180 000 -> 330 000, with the derivation in the comment.
  2. directorAdminMaxAgeMs: 180 000 (new). director-admin shared cloudDataMaxAgeMs, so raising the cloud bar would have silently loosened a source that answers live on our own request. Pinned at its current value. relayLogMaxAgeMs, activeProbeMaxAgeMs and heartbeatMaxAgeMs are untouched.
  3. cloudLockWaitCarryMs: 180 000 (new). The nonzero backends-in-wait carry window also referenced cloudDataMaxAgeMs; 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.
  4. Bounded freshness tolerance (item 2 of the task, implemented). A sample whose only continuity failures are freshness-only (signal_missing, signal_stale, source_missing, source_stale) no longer restarts the window. The window continues, the sample counts, and the gap is recorded in continuityEvents with tolerated: true. A signal may miss at most INCIDENT_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 continuityEvents on resume, so a restarted monitor cannot hand a signal a fresh budget.

  1. Removed the duplicated FRESHNESS_FAILURE_CODES set in incident-live-preflight-cli.ts; it now imports the one in incident-monitor.ts.

Tests

incident-monitor.test.ts gains: the exact 04:46 case (a 189 286 ms cloud_sql.lock_waits reading is green, and director-admin at 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 cloudDataMaxAgeMs to 180 000, directorAdminMaxAgeMs to 330 000, the lock-wait carry to cloudDataMaxAgeMs, or the tolerance budget to 0 each fails at least one test.

Test Files  12 passed (12)
     Tests  92 passed (92)

pnpm --filter @orca-cloud/relay-ops typecheck is clean. cloud/** is excluded from oxlint, so tsc is the lint gate here.

Not done

The Markdown checkpoint summary still reports only sampleCount and threshold failures. Tolerated freshness gaps are visible in state.json under continuityEvents, not in the rendered table.

@pullfrog

pullfrog Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Pullfrog  | View workflow run | via Pullfrog | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H
Jinwoo-H merged commit ba4bbac into main Sep 5, 2026
25 of 26 checks passed
@Jinwoo-H
Jinwoo-H deleted the relay-monitor-cloud-freshness-bar branch September 5, 2026 05:18
@coderabbitai

coderabbitai Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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 8b4b0

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning 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… Add a valid issue reference after Fixes #. Add the required template sections, including ## ELI5, ## What Changed, ## Why, ## Visual Proof with N/A and a reason if applicable, ## Review, ## Agent skill upstream boundary, `##…
Docstring Coverage ⚠️ Warning 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… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary change: aligning the Cloud Monitoring freshness threshold with its publish lag.
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.
Full details: Description check

Explanation

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 Fixes #. Add the required template sections, including ## ELI5, ## What Changed, ## Why, ## Visual Proof with N/A and a reason if applicable, ## Review, ## Agent skill upstream boundary, ## Notes, and ## Checklist. Complete the testing and checklist items, or state clearly which checks CI will cover.

Full details: Docstring Coverage

Explanation

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

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: a26369b4-a5e6-494a-92bf-e42ae361ad15

📥 Commits

Reviewing files that changed from the base of the PR and between 436ef82 and 8b4b0ab.

📒 Files selected for processing (8)
  • cloud/apps/relay-ops/src/incident-live-preflight-cli.test.ts
  • cloud/apps/relay-ops/src/incident-live-preflight-cli.ts
  • cloud/apps/relay-ops/src/incident-monitor-cli.ts
  • cloud/apps/relay-ops/src/incident-monitor-sources.test.ts
  • cloud/apps/relay-ops/src/incident-monitor-sources.ts
  • cloud/apps/relay-ops/src/incident-monitor.test.ts
  • cloud/apps/relay-ops/src/incident-monitor.ts
  • cloud/docs/relay-incident-monitor.md

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment on lines +666 to +667
const last = events[events.length - 1]
if (!last?.tolerated) return streaks

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Comment on lines +76 to +81
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

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