Skip to content

Commit

Permalink
Make it possible to nest runtime components (#2909)
Browse files Browse the repository at this point in the history
Runtime plugins need to be able to wrap components configured in other
runtime components. For example, one runtime plugin should be able to
wrap the HTTP connector configured in another runtime plugin.

This PR makes this possible by:
- Introducing the ability to order runtime plugins within the
service/operation plugin "levels".
- Adding an argument to `RuntimePlugin::runtime_components` so that
implementations can reference components configured by previous plugins.

The `order` function has three separate order values: `Defaults`,
`Overrides`, and `NestedComponents`. The `Defaults` order is currently
unused, but will be used later when we refactor how defaults in config
work. Everything defaults to `Overrides` since most runtime plugins will
want to be in this slot. The `NestedComponents` order is specifically
for runtime plugins that want to create nested components, and runs at
the very end.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
  • Loading branch information
jdisanti authored Aug 22, 2023
1 parent b84c02b commit 67830dc
Show file tree
Hide file tree
Showing 12 changed files with 310 additions and 39 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ references = ["smithy-rs#2904"]
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client" }
author = "jdisanti"

[[smithy-rs]]
message = "It's now possible to nest runtime components with the `RuntimePlugin` trait. A `current_components` argument was added to the `runtime_components` method so that components configured from previous runtime plugins can be referenced in the current runtime plugin. Ordering of runtime plugins was also introduced via a new `RuntimePlugin::order` method."
references = ["smithy-rs#2909"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client"}
author = "jdisanti"

[[smithy-rs]]
message = "Fix incorrect summary docs for builders"
references = ["smithy-rs#2914", "aws-sdk-rust#825"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ impl RuntimePlugin for SigV4PresigningRuntimePlugin {
Some(layer.freeze())
}

fn runtime_components(&self) -> Cow<'_, RuntimeComponentsBuilder> {
fn runtime_components(
&self,
_: &RuntimeComponentsBuilder,
) -> Cow<'_, RuntimeComponentsBuilder> {
Cow::Borrowed(&self.runtime_components)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ConfigOverrideRuntimePluginGenerator(
Some(self.config.clone())
}
fn runtime_components(&self) -> #{Cow}<'_, #{RuntimeComponentsBuilder}> {
fn runtime_components(&self, _: &#{RuntimeComponentsBuilder}) -> #{Cow}<'_, #{RuntimeComponentsBuilder}> {
#{Cow}::Borrowed(&self.components)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class OperationRuntimePluginGenerator(
#{Some}(cfg.freeze())
}
fn runtime_components(&self) -> #{Cow}<'_, #{RuntimeComponentsBuilder}> {
fn runtime_components(&self, _: &#{RuntimeComponentsBuilder}) -> #{Cow}<'_, #{RuntimeComponentsBuilder}> {
// Retry classifiers are operation-specific because they need to downcast operation-specific error types.
let retry_classifiers = #{RetryClassifiers}::new()
#{retry_classifier_customizations};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class ServiceRuntimePluginGenerator(
self.config.clone()
}
fn runtime_components(&self) -> #{Cow}<'_, #{RuntimeComponentsBuilder}> {
fn runtime_components(&self, _: &#{RuntimeComponentsBuilder}) -> #{Cow}<'_, #{RuntimeComponentsBuilder}> {
#{Cow}::Borrowed(&self.runtime_components)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ internal class ConfigOverrideRuntimePluginGeneratorTest {
"EndpointResolverParams" to RuntimeType.smithyRuntimeApi(runtimeConfig)
.resolve("client::endpoint::EndpointResolverParams"),
"RuntimePlugin" to RuntimeType.runtimePlugin(runtimeConfig),
"RuntimeComponentsBuilder" to RuntimeType.runtimeComponentsBuilder(runtimeConfig),
)
rustCrate.testModule {
addDependency(CargoDependency.Tokio.toDevDependency().withFeature("test-util"))
Expand All @@ -62,7 +63,8 @@ internal class ConfigOverrideRuntimePluginGeneratorTest {
client_config.config,
&client_config.runtime_components,
);
let sut_components = sut.runtime_components();
let prev = #{RuntimeComponentsBuilder}::new("prev");
let sut_components = sut.runtime_components(&prev);
let endpoint_resolver = sut_components.endpoint_resolver().unwrap();
let endpoint = endpoint_resolver
.resolve_endpoint(&#{EndpointResolverParams}::new(crate::config::endpoint::Params {}))
Expand Down
3 changes: 3 additions & 0 deletions rust-runtime/aws-smithy-runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ tokio = { version = "1.25", features = ["sync"] }
tracing = "0.1"
zeroize = { version = "1", optional = true }

[dev-dependencies]
tokio = { version = "1.25", features = ["rt", "macros"] }

[package.metadata.docs.rs]
all-features = true
targets = ["x86_64-unknown-linux-gnu"]
Expand Down
Loading

0 comments on commit 67830dc

Please sign in to comment.