Skip to content

CDAP-21261 : Add retry logging for GCP Secret Manager SDK calls - #16233

Merged
sahusanket merged 1 commit into
developfrom
CDAP-21261_secretmanager_retry_logging_and_backoff
Sep 25, 2026
Merged

sahusanket merged 1 commit into
developfrom
CDAP-21261_secretmanager_retry_logging_and_backoff

Conversation

@sahusanket

@sahusanket sahusanket commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds retry observability to CloudSecretManagerClient by registering a GAX BaseApiTracerFactory on SecretManagerServiceSettings.

Motivation

In #16227, GAX retries were enabled on CloudSecretManagerClient RPCs (updateSecret, getSecret, addSecretVersion) to handle transient errors and rate limiting (RESOURCE_EXHAUSTED / HTTP 429). However, GAX performs retries silently (only logging at java.util.logging FINEST), leaving no visibility in CDAP logs when Secret Manager quota limits are hit—either when a retry eventually recovers or when all retry attempts are exhausted.

Changes

Registers a BaseApiTracer on SecretManagerServiceSettings to log retry events at appropriate severity levels without polluting normal operational logs:

  • WARN on RESOURCE_EXHAUSTED retry (attemptFailed): Logs when a Secret Manager call hits a quota limit and is being retried, providing early visibility for alerting and capacity planning even if a subsequent retry succeeds.
  • DEBUG on transient 5XX retry (attemptFailed): Logs non-quota transient failures (UNAVAILABLE, INTERNAL, UNKNOWN, DEADLINE_EXCEEDED) at DEBUG level to avoid log noise.
  • ERROR on retry exhaustion (attemptFailedRetriesExhausted): Logs the RPC method name and failure cause when all configured retry attempts are exhausted.

@sahusanket
sahusanket requested a review from vsethi09 September 24, 2026 20:59
@sahusanket sahusanket self-assigned this Sep 24, 2026
@sahusanket sahusanket added the build Triggers github actions build label Sep 24, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

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 configures a custom tracer factory for the GCP Secret Manager client to log transient failures and exhausted retries. Feedback focuses on improving the logging implementation: first, by avoiding logging the full stack trace for transient quota limit warnings to prevent log flooding, and second, by removing a redundant and potentially unsafe call to error.getMessage() when logging exhausted retries.

Comment on lines +328 to +329
LOG.warn("GCP Secret Manager quota limit hit during {}, retrying in {} ms.",
spanName.getMethodName(), delay.toMillis(), error);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Logging the full stack trace (error) at WARN level for every transient quota limit hit can severely flood the logs, especially under high load when quota limits are frequently exceeded. Since this is a transient failure that is being retried, it is better to log a concise warning message with the exception's string representation and avoid printing the entire stack trace. The full stack trace will still be logged at ERROR level if all retry attempts are exhausted.

Suggested change
LOG.warn("GCP Secret Manager quota limit hit during {}, retrying in {} ms.",
spanName.getMethodName(), delay.toMillis(), error);
LOG.warn("GCP Secret Manager quota limit hit during {}, retrying in {} ms. Error: {}",
spanName.getMethodName(), delay.toMillis(), error.toString());

Comment on lines +338 to +339
LOG.error("GCP Secret Manager retries exhausted for {}: {}",
spanName.getMethodName(), error.getMessage(), error);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Passing error.getMessage() as a separate placeholder is redundant because the error object is already passed as the last argument, which automatically logs the exception's class, message, and full stack trace. Additionally, if error is ever null, calling error.getMessage() will throw a NullPointerException. Simplifying the log statement avoids redundancy and potential NPEs.

Suggested change
LOG.error("GCP Secret Manager retries exhausted for {}: {}",
spanName.getMethodName(), error.getMessage(), error);
LOG.error("GCP Secret Manager retries exhausted for {}",
spanName.getMethodName(), error);

public void attemptFailed(Throwable error, Duration delay) {
if (error instanceof ApiException
&& ((ApiException) error).getStatusCode().getCode() == StatusCode.Code.RESOURCE_EXHAUSTED) {
LOG.warn("GCP Secret Manager quota limit hit during {}, retrying in {} ms: {}",

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.

nit: GCP Secret Manager API request quota limit exceeded during...


@Override
public void attemptFailedRetriesExhausted(Throwable error) {
LOG.error("GCP Secret Manager retries exhausted for {}.",

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.

nit: Retries for GCP Secret Manager API Request exhausted for..

@sahusanket
sahusanket force-pushed the CDAP-21261_secretmanager_retry_logging_and_backoff branch from 1c1396a to ab87271 Compare September 25, 2026 03:52
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@sahusanket
sahusanket merged commit 8ee8e2d into develop Sep 25, 2026
18 of 19 checks passed
@sahusanket
sahusanket deleted the CDAP-21261_secretmanager_retry_logging_and_backoff branch September 25, 2026 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Triggers github actions build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants