CDAP-21261 : Add retry logging for GCP Secret Manager SDK calls - #16233
Conversation
There was a problem hiding this comment.
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.
| LOG.warn("GCP Secret Manager quota limit hit during {}, retrying in {} ms.", | ||
| spanName.getMethodName(), delay.toMillis(), error); |
There was a problem hiding this comment.
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.
| 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()); |
| LOG.error("GCP Secret Manager retries exhausted for {}: {}", | ||
| spanName.getMethodName(), error.getMessage(), error); |
There was a problem hiding this comment.
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.
| LOG.error("GCP Secret Manager retries exhausted for {}: {}", | |
| spanName.getMethodName(), error.getMessage(), error); | |
| LOG.error("GCP Secret Manager retries exhausted for {}", | |
| spanName.getMethodName(), error); |
4a5be3d to
1c1396a
Compare
| 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: {}", |
There was a problem hiding this comment.
nit: GCP Secret Manager API request quota limit exceeded during...
|
|
||
| @Override | ||
| public void attemptFailedRetriesExhausted(Throwable error) { | ||
| LOG.error("GCP Secret Manager retries exhausted for {}.", |
There was a problem hiding this comment.
nit: Retries for GCP Secret Manager API Request exhausted for..
1c1396a to
ab87271
Compare
|


Summary
Adds retry observability to
CloudSecretManagerClientby registering a GAXBaseApiTracerFactoryonSecretManagerServiceSettings.Motivation
In #16227, GAX retries were enabled on
CloudSecretManagerClientRPCs (updateSecret,getSecret,addSecretVersion) to handle transient errors and rate limiting (RESOURCE_EXHAUSTED/ HTTP 429). However, GAX performs retries silently (only logging atjava.util.loggingFINEST), 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
BaseApiTraceronSecretManagerServiceSettingsto log retry events at appropriate severity levels without polluting normal operational logs:WARNonRESOURCE_EXHAUSTEDretry (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.DEBUGon transient 5XX retry (attemptFailed): Logs non-quota transient failures (UNAVAILABLE,INTERNAL,UNKNOWN,DEADLINE_EXCEEDED) atDEBUGlevel to avoid log noise.ERRORon retry exhaustion (attemptFailedRetriesExhausted): Logs the RPC method name and failure cause when all configured retry attempts are exhausted.