Skip to content

fix(it): retry transient Cloud Monitoring errors when reading load test metrics - #4650

Merged
aasthabharill merged 6 commits into
GoogleCloudPlatform:mainfrom
aasthabharill:fix/lt-monitoring-retry
Nov 30, 2026
Merged

aasthabharill merged 6 commits into
GoogleCloudPlatform:mainfrom
aasthabharill:fix/lt-monitoring-retry

Conversation

@aasthabharill

@aasthabharill aasthabharill commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Why

In the scheduled Spanner load test run on 2026-11-24 (run 45309794552), SpannerToCassandraSourceLT failed 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 one listTimeSeries call to Cloud Monitoring returned:

INTERNAL: Internal error encountered. Please retry after a few seconds.

MonitoringClient has 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 on LoadTestBase reads its metrics this way.

What

MonitoringClient now retries time series reads when Cloud Monitoring returns INTERNAL, UNAVAILABLE or DEADLINE_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.

  • Up to 6 retries with exponential backoff and jitter: about 1s, 2s, 4s, 8s, 16s, 32s. A read that fails fast and never recovers fails about 63s later than it does today.
  • Slow failures take longer than that, because each attempt can run up to the client's own timeout. The client library also retries UNAVAILABLE by itself, so that code is retried at both levels.
  • The retry covers reading all pages of the response, since later pages are fetched with further calls.
  • Any other error still fails on the first attempt. RESOURCE_EXHAUSTED and ABORTED are left out on purpose: a quota error may not clear within the backoff window, and ABORTED is 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 INTERNAL has been seen in a real run so far.

Testing

New MonitoringClientTest covers: retry then success, an error while paging, no retry on RESOURCE_EXHAUSTED, and giving up after 6 retries.

The change has not been exercised in a load test run.

…metrics

A single INTERNAL from listTimeSeries failed SpannerToCassandraSourceLT after
its pipeline and row count check had already passed.
@codecov

codecov Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.70%. Comparing base (3ce86d9) to head (45928cc).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...pache/beam/it/gcp/monitoring/MonitoringClient.java 85.71% 3 Missing and 1 partial ⚠️
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     
Components Coverage Δ
spanner-templates 84.03% <ø> (+<0.01%) ⬆️
spanner-import-export 72.61% <ø> (-0.14%) ⬇️
spanner-live-forward-migration 87.66% <ø> (+<0.01%) ⬆️
spanner-live-reverse-replication 79.94% <ø> (ø)
spanner-bulk-migration 88.29% <ø> (ø)
gcs-spanner-dv 86.58% <ø> (ø)
Files with missing lines Coverage Δ
...pache/beam/it/gcp/monitoring/MonitoringClient.java 13.54% <85.71%> (+13.10%) ⬆️

... and 16 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…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.
@aasthabharill
aasthabharill marked this pull request as ready for review November 30, 2026 09:37
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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

  • Added Retry Logic: Implemented a Failsafe-based retry policy in MonitoringClient to handle transient Cloud Monitoring errors (INTERNAL, UNAVAILABLE, DEADLINE_EXCEEDED) during metric collection.
  • Configured Exponential Backoff: Added a retry strategy with truncated exponential backoff and jitter, ranging from 1s to 32s, following Google Cloud Monitoring troubleshooting recommendations.
  • Enhanced Test Coverage: Introduced MonitoringClientTest to verify retry behavior, success after transient failures, and proper handling of non-retryable errors.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist 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.

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.
@aasthabharill
aasthabharill merged commit de01947 into GoogleCloudPlatform:main Nov 30, 2026
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants