-
Notifications
You must be signed in to change notification settings - Fork 224
Improve credentials tracing #2062
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f026d03
717072b
9ad65ef
147c7e7
216d867
3bcd7b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,11 +6,11 @@ | |
| //! Lazy, caching, credentials provider implementation | ||
|
|
||
| use std::sync::Arc; | ||
| use std::time::Duration; | ||
| use std::time::{Duration, Instant}; | ||
|
|
||
| use aws_smithy_async::future::timeout::Timeout; | ||
| use aws_smithy_async::rt::sleep::AsyncSleep; | ||
| use tracing::{trace_span, Instrument}; | ||
| use tracing::{debug, info, info_span, Instrument}; | ||
|
|
||
| use aws_types::credentials::{future, CredentialsError, ProvideCredentials}; | ||
| use aws_types::os_shim_internal::TimeSource; | ||
|
|
@@ -77,17 +77,18 @@ impl ProvideCredentials for LazyCachingCredentialsProvider { | |
| future::ProvideCredentials::new(async move { | ||
| // Attempt to get cached credentials, or clear the cache if they're expired | ||
| if let Some(credentials) = cache.yield_or_clear_if_expired(now).await { | ||
| tracing::debug!("loaded credentials from cache"); | ||
| debug!("loaded credentials from cache"); | ||
| Ok(credentials) | ||
| } else { | ||
| // If we didn't get credentials from the cache, then we need to try and load. | ||
| // There may be other threads also loading simultaneously, but this is OK | ||
| // since the futures are not eagerly executed, and the cache will only run one | ||
| // of them. | ||
| let future = Timeout::new(loader.provide_credentials(), timeout_future); | ||
| cache | ||
| let start_time = Instant::now(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we should use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
| let result = cache | ||
| .get_or_load(|| { | ||
| let span = trace_span!("lazy_load_credentials"); | ||
| let span = info_span!("lazy_load_credentials"); | ||
| async move { | ||
| let credentials = future.await.map_err(|_err| { | ||
| CredentialsError::provider_timed_out(load_timeout) | ||
|
|
@@ -102,7 +103,12 @@ impl ProvideCredentials for LazyCachingCredentialsProvider { | |
| // is opened if the cache decides not to execute it. | ||
| .instrument(span) | ||
| }) | ||
| .await | ||
| .await; | ||
| info!( | ||
| "credentials cache miss occurred; retrieved new AWS credentials (took {:?})", | ||
| start_time.elapsed() | ||
| ); | ||
| result | ||
| } | ||
| }) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
users are gonna love this