feat(auth): add retry loop for generate_access_token#6092
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the generate_access_token function in src/auth/src/credentials/impersonated.rs to use a new GenerateAccessTokenClient struct, integrating a retry loop with exponential backoff and strict AIP-194 retry policies from google-cloud-gax. It also adds corresponding unit tests to verify successful retries and exhausted retry attempts. Feedback on the changes highlights an issue where formatting err_payload (of type bytes::Bytes) with {:?} results in a non-human-readable debug representation of byte integers. The reviewer suggests passing the raw payload directly to GaxError::http to preserve the response body and avoid redundant error message wrapping.
| return Err(GaxError::http( | ||
| status.as_u16(), | ||
| err_headers, | ||
| format!("{MSG}: {err_payload:?}").into(), | ||
| )); |
There was a problem hiding this comment.
Formatting err_payload (which is of type bytes::Bytes) using {:?} inside format! will output a debug representation of the bytes (e.g., a list of integers like [123, 34, ...]), which is not human-readable and makes debugging HTTP errors extremely difficult.
Additionally, prepending {MSG} here is redundant because the caller (fetch) already wraps the returned error using errors::from_gax_error(e, MSG).
We should pass the raw err_payload directly to GaxError::http to preserve the raw HTTP response body (e.g., JSON error details) so that it can be properly formatted or parsed later.
| return Err(GaxError::http( | |
| status.as_u16(), | |
| err_headers, | |
| format!("{MSG}: {err_payload:?}").into(), | |
| )); | |
| return Err(GaxError::http( | |
| status.as_u16(), | |
| err_headers, | |
| err_payload, | |
| )); |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6092 +/- ##
==========================================
- Coverage 97.04% 97.04% -0.01%
==========================================
Files 253 253
Lines 63682 63793 +111
==========================================
+ Hits 61798 61905 +107
- Misses 1884 1888 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Towards #4459