feat: Token caching for external identity providers#935
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
Nice! Quick question: do you think it would be possible to run the token acquisition as a background task instead? That way, the token is always fresh when accessed for creating server connections. |
d5c05c8 to
acb481a
Compare
|
Sorry for the delay, I finally had some time to circle back to your comments. That was a great suggestion. I’ve added Let me know if this looks good! |
|
I tried my best to address your review comments. I learned a lot going through the codebase. Happy to make changes based on feedback. |
levkk
left a comment
There was a problem hiding this comment.
This is great, thank you!
Summary
Introduces an in-memory token cache shared by
azure_workload_identityandrds_iamauthentication backends. Tokens are now fetched once and reused until expiry, instead of being fetched on every connection.Motivation
Token fetching from external identity providers can be slow — Azure Workload Identity in particular was measured at ~30s per token fetch. This was directly impacting pool startup time, as each connection attempt would block waiting for a fresh token.
Changes
token_cachemodule with get/set helpers keyed by host, port, and userazure_workload_identityto extractfetch_token()returning(String, SystemTime), using theexpires_onfield from the Azure SDK response as the cache TTLrds_iamto follow the same pattern, with a fixed 15-minute TTL (RDS IAM tokens are valid for 15 minutes but the AWS SDK does not return an expiry)Impact