Repository navigation
fix(it): retry transient Cloud Monitoring errors when reading load test metrics - #4650
Conversation
…metrics A single INTERNAL from listTimeSeries failed SpannerToCassandraSourceLT after its pipeline and row count check had already passed.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4650 +/- ##
============================================
- Coverage 59.75% 59.70% -0.06%
- Complexity 7926 8688 +762
============================================
Files 1123 1122 -1
Lines 72741 72762 +21
Branches 8854 8855 +1
============================================
- Hits 43470 43442 -28
- Misses 26375 26417 +42
- Partials 2896 2903 +7
🚀 New features to boost your workflow:
|
…ries The Monitoring troubleshooting guide recommends truncated exponential backoff with jitter, from 1 second up to 32 seconds, for INTERNAL, UNAVAILABLE and DEADLINE_EXCEEDED: https://cloud.google.com/monitoring/api/troubleshooting#server-errors Replace the 5s to 60s delays borrowed from CloudSqlResourceManager with 1s to 32s, add jitter, and use six retries so the last wait reaches the 32 second cap.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request improves the robustness of load test metric collection by introducing automatic retries for transient errors encountered when interacting with the Cloud Monitoring API. By handling specific server-side errors that occur after a pipeline has successfully finished, the change prevents unnecessary load test failures caused by temporary network or service instability. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a retry mechanism using Failsafe in MonitoringClient to handle transient server-side errors (such as INTERNAL, UNAVAILABLE, and DEADLINE_EXCEEDED) when querying Google Cloud Monitoring. It also adds comprehensive unit tests in MonitoringClientTest to verify the retry behavior. A review comment suggests logging only the exception message instead of the full stack trace during retries to prevent log clutter.
Each retry logged the full gax stack trace, which repeats on every attempt. Log the exception as text instead. If the retries run out, the exception is still rethrown with its stack trace.
Stop starting new retries once a read has taken 5 minutes in total, so slow attempts cannot stretch one read to many minutes. Import java.time.Duration instead of writing its full name. The protobuf Duration values are now built with Durations.fromSeconds, so the two types no longer clash.
Go back to building the alignment periods with the protobuf Duration builder and writing java.time.Duration in full for the retry settings. Swapping the existing call sites to Durations.fromSeconds was not worth it just to import java.time.Duration.
Why
In the scheduled Spanner load test run on 2026-11-24 (run 45309794552),
SpannerToCassandraSourceLTfailed after its own checks had passed. The pipeline finished and the Cassandra row count check found all 300,000 rows. The test then failed while collecting job metrics for export, because onelistTimeSeriescall to Cloud Monitoring returned:MonitoringClienthas no retry of its own, so a single server-side error while reading metrics fails a load test that otherwise passed. Every load test built onLoadTestBasereads its metrics this way.What
MonitoringClientnow retries time series reads when Cloud Monitoring returnsINTERNAL,UNAVAILABLEorDEADLINE_EXCEEDED.This follows the Cloud Monitoring troubleshooting guide. The guide lists these three codes together, quotes the same "Internal error encountered. Please retry after a few seconds" message, and recommends truncated exponential backoff with jitter, from 1 second up to 32 seconds.
UNAVAILABLEby itself, so that code is retried at both levels.RESOURCE_EXHAUSTEDandABORTEDare left out on purpose: a quota error may not clear within the backoff window, andABORTEDis not expected from a read-only call.The 1s to 32s range comes from the guide. The guide does not give a retry count or a jitter amount, so 6 retries (enough for the last wait to reach 32s) and 25% jitter are our choice. Only
INTERNALhas been seen in a real run so far.Testing
New
MonitoringClientTestcovers: retry then success, an error while paging, no retry onRESOURCE_EXHAUSTED, and giving up after 6 retries.The change has not been exercised in a load test run.