Skip to content
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

Simplify default config and add default async sleep #3071

Merged
merged 6 commits into from
Oct 17, 2023

Conversation

jdisanti
Copy link
Collaborator

While implementing identity caching, I noticed we don't have a default async sleep impl wired up for generic clients, which was causing caching to panic in many tests since it needs a sleep impl for timeouts. I likely need to figure out what to do other than panic if there's no sleep impl, but that's a problem for a different PR.

This PR adds a default sleep impl to generic clients, and also simplifies how default config works. Previously, the generated config Builder::build method set all the defaults with a series of "if not set, then set default" statements. In this PR, defaults are registered via default ordered runtime plugins.

Additionally, I cleaned up the standard retry strategy:

  • The TokenBucketPartition didn't appear to be used at all, so I deleted it.
  • StandardRetryStrategy was taking retry config at construction, which means it isn't possible to config override the retry config unless the strategy is recreated. It now doesn't take any config at all during construction.
  • The adaptive retry client rate limiter was created at construction based on retry config at that point in time. This means config overrides wouldn't work with it, so it is also no longer set up at construction time.
  • Removed some unused runtime plugins.

Checklist

  • I have updated CHANGELOG.next.toml if I made changes to the smithy-rs codegen or runtime crates
  • I have updated CHANGELOG.next.toml if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Copy link
Collaborator

@rcoh rcoh left a comment

Choose a reason for hiding this comment

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

just skimmed, need to come back for detailed review

rust-runtime/aws-smithy-runtime/src/client/defaults.rs Outdated Show resolved Hide resolved
rust-runtime/aws-smithy-runtime/src/client/defaults.rs Outdated Show resolved Hide resolved
Comment on lines -22 to -38
pub struct ClientRateLimiterRuntimePlugin {
rate_limiter: ClientRateLimiter,
}

impl ClientRateLimiterRuntimePlugin {
/// Create a new [`ClientRateLimiterRuntimePlugin`].
pub fn new(seconds_since_unix_epoch: f64) -> Self {
Self {
rate_limiter: ClientRateLimiter::new(seconds_since_unix_epoch),
}
}
}

impl RuntimePlugin for ClientRateLimiterRuntimePlugin {
fn config(&self) -> Option<FrozenLayer> {
let mut cfg = Layer::new("client rate limiter");
cfg.store_put(self.rate_limiter.clone());
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this something a customer would want to use directly? Seems like it could be helpful.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is an implementation detail for adaptive retry, so I don't believe so.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@jdisanti jdisanti added the breaking-change This will require a breaking change label Oct 16, 2023
Comment on lines +47 to +56
let _default: Option<SharedHttpClient> = None;
#[cfg(feature = "connector-hyper-0-14-x")]
let _default = crate::client::http::hyper_014::default_client();

_default.map(|default| {
default_plugin("default_http_client_plugin", |components| {
components.with_http_client(Some(default))
})
.into_shared()
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
let _default: Option<SharedHttpClient> = None;
#[cfg(feature = "connector-hyper-0-14-x")]
let _default = crate::client::http::hyper_014::default_client();
_default.map(|default| {
default_plugin("default_http_client_plugin", |components| {
components.with_http_client(Some(default))
})
.into_shared()
})
let default_client: Option<SharedHttpClient> = None;
#[cfg(feature = "connector-hyper-0-14-x")]
let default_client = crate::client::http::hyper_014::default_client();
default_client.map(|client| {
default_plugin("default_http_client_plugin", |components| {
components.with_http_client(Some(client))
})
.into_shared()
})

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It definitely needs the underscore prefix to avoid compilation warnings.

Comment on lines +71 to +76
Some(
default_plugin("default_time_source_plugin", |components| {
components.with_time_source(Some(SystemTimeSource::new()))
})
.into_shared(),
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nonblocking—I wonder if we could figure out at compile time if SystemTimeSource was going to work or not 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Probably need to look at the compilation target to determine that.

@@ -16,6 +17,8 @@ import software.amazon.smithy.rust.codegen.core.testutil.integrationTest

class SensitiveOutputDecoratorTest {
private fun codegenScope(runtimeConfig: RuntimeConfig): Array<Pair<String, Any>> = arrayOf(
"capture_test_logs" to CargoDependency.smithyRuntimeTestUtil(runtimeConfig).toType()
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for starting to use this, which I did not when adding this test.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@jdisanti jdisanti added this pull request to the merge queue Oct 17, 2023
Merged via the queue into main with commit bcfc211 Oct 17, 2023
40 of 41 checks passed
@jdisanti jdisanti deleted the jdisanti-generic-default-sleep branch October 17, 2023 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change This will require a breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants