From e3ba6a2be73012ac5bbfdcf98920d4ef42f0b768 Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Fri, 7 Jul 2023 16:42:58 -0700 Subject: [PATCH 1/6] Fix Timestream in the orchestrator --- CHANGELOG.next.toml | 12 ++--- .../aws-inlineable/src/endpoint_discovery.rs | 3 ++ .../timestream/TimestreamDecorator.kt | 49 +++++++++++-------- .../s3/tests/config_to_builder.rs | 17 +++++++ .../timestreamquery/Cargo.toml | 5 +- .../timestreamquery/tests/endpoint_disco.rs | 5 +- .../ConfigOverrideRuntimePluginGenerator.kt | 6 +-- .../config/ServiceConfigGenerator.kt | 31 +++++++++--- .../aws-smithy-client/src/dvr/replay.rs | 2 +- .../src/client/config_override.rs | 17 ++++--- .../src/client/orchestrator/endpoints.rs | 1 + .../check-aws-sdk-orchestrator-impl | 8 +-- 12 files changed, 101 insertions(+), 55 deletions(-) create mode 100644 aws/sdk/integration-tests/s3/tests/config_to_builder.rs diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index d603759359..4cb2c8f097 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -127,7 +127,7 @@ author = "rcoh" message = "Bump dependency on `lambda_http` by `aws-smithy-http-server` to 0.8.0. This version of `aws-smithy-http-server` is only guaranteed to be compatible with 0.8.0, or semver-compatible versions of 0.8.0 of the `lambda_http` crate. It will not work with versions prior to 0.8.0 _at runtime_, making requests to your smithy-rs service unroutable, so please make sure you're running your service in a compatible configuration" author = "david-perez" references = ["smithy-rs#2676", "smithy-rs#2685"] -meta = { "breaking" = true, "tada" = false, "bug" = false } +meta = { "breaking" = true, "tada" = false, "bug" = false, target = "server" } [[smithy-rs]] message = """Remove `PollError` from an operations `Service::Error`. @@ -141,9 +141,9 @@ meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "server" } author = "hlbarber" [[aws-sdk-rust]] -message = "The SDK has added support for timestreamwrite and timestreamquery. Support for these services is considered experimental at this time. In order to use these services, you MUST call `.enable_endpoint_discovery()` on the `Client` after construction." +message = "The SDK has added support for timestreamwrite and timestreamquery. Support for these services is considered experimental at this time. In order to use these services, you MUST call `.with_endpoint_discovery_enabled()` on the `Client` after construction." meta = { "breaking" = false, "tada" = true, "bug" = false } -references = ["smithy-rs#2707", "aws-sdk-rust#114"] +references = ["smithy-rs#2707", "aws-sdk-rust#114", "smithy-rs#2846"] author = "rcoh" [[smithy-rs]] @@ -197,7 +197,7 @@ filter_by_operation_id(plugin, |id| id.absolute() != "namespace#name"); """ author = "82marbag" references = ["smithy-rs#2678"] -meta = { "breaking" = true, "tada" = false, "bug" = false } +meta = { "breaking" = true, "tada" = false, "bug" = false, target = "server" } [[smithy-rs]] message = "The occurrences of `Arc` have now been replaced with `SharedEndpointResolver` in public APIs." @@ -532,7 +532,7 @@ let scoped_plugin = Scoped::new::(plugin); """ references = ["smithy-rs#2740", "smithy-rs#2759", "smithy-rs#2779", "smithy-rs#2827"] -meta = { "breaking" = true, "tada" = true, "bug" = false } +meta = { "breaking" = true, "tada" = true, "bug" = false, target = "server" } author = "hlbarber" [[smithy-rs]] @@ -608,7 +608,7 @@ let plugin = plugin_from_operation_fn(map); ``` """ references = ["smithy-rs#2740", "smithy-rs#2759", "smithy-rs#2779"] -meta = { "breaking" = true, "tada" = false, "bug" = false } +meta = { "breaking" = true, "tada" = false, "bug" = false, target = "server" } author = "hlbarber" [[smithy-rs]] diff --git a/aws/rust-runtime/aws-inlineable/src/endpoint_discovery.rs b/aws/rust-runtime/aws-inlineable/src/endpoint_discovery.rs index d4ffc7d116..de870fecc9 100644 --- a/aws/rust-runtime/aws-inlineable/src/endpoint_discovery.rs +++ b/aws/rust-runtime/aws-inlineable/src/endpoint_discovery.rs @@ -39,6 +39,7 @@ impl ReloadEndpoint { pub async fn reload_once(&self) { match (self.loader)().await { Ok((endpoint, expiry)) => { + tracing::debug!("caching resolved endpoint: {:?}", (&endpoint, &expiry)); *self.endpoint.lock().unwrap() = Some(ExpiringEndpoint { endpoint, expiry }) } Err(err) => *self.error.lock().unwrap() = Some(err), @@ -128,6 +129,7 @@ where sleep, time, }; + tracing::debug!("populating initial endpoint discovery cache"); reloader.reload_once().await; // if we didn't successfully get an endpoint, bail out so the client knows // configuration failed to work @@ -137,6 +139,7 @@ where impl EndpointCache { fn resolve_endpoint(&self) -> aws_smithy_http::endpoint::Result { + tracing::trace!("resolving endpoint from endpoint discovery cache"); self.endpoint .lock() .unwrap() diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/timestream/TimestreamDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/timestream/TimestreamDecorator.kt index 55a9e7f7bd..31eb1e3dc1 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/timestream/TimestreamDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/timestream/TimestreamDecorator.kt @@ -6,6 +6,7 @@ package software.amazon.smithy.rustsdk.customize.timestream import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext +import software.amazon.smithy.rust.codegen.client.smithy.ClientRustModule import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.endpoint.Types import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency @@ -14,7 +15,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.Visibility import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.rustlang.toType import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.preludeScope import software.amazon.smithy.rust.codegen.core.smithy.RustCrate import software.amazon.smithy.rust.codegen.core.smithy.customize.AdHocCustomization import software.amazon.smithy.rust.codegen.core.smithy.customize.adhocCustomization @@ -25,7 +25,7 @@ import software.amazon.smithy.rustsdk.InlineAwsDependency /** * This decorator does two things: * 1. Adds the `endpoint_discovery` inlineable - * 2. Adds a `enable_endpoint_discovery` method on client that returns a wrapped client with endpoint discovery enabled + * 2. Adds a `with_endpoint_discovery_enabled` method on client that returns a wrapped client with endpoint discovery enabled */ class TimestreamDecorator : ClientCodegenDecorator { override val name: String = "Timestream" @@ -38,8 +38,8 @@ class TimestreamDecorator : ClientCodegenDecorator { rustTemplate( """ let config = aws_config::load_from_env().await; - // You MUST call `enable_endpoint_discovery` to produce a working client for this service. - let ${it.clientName} = ${it.crateName}::Client::new(&config).enable_endpoint_discovery().await; + // You MUST call `with_endpoint_discovery_enabled` to produce a working client for this service. + let ${it.clientName} = ${it.crateName}::Client::new(&config).with_endpoint_discovery_enabled().await; """.replaceIndent(it.indent), ) }, @@ -52,7 +52,7 @@ class TimestreamDecorator : ClientCodegenDecorator { Visibility.PUBLIC, CargoDependency.Tokio.copy(scope = DependencyScope.Compile, features = setOf("sync")), ) - rustCrate.lib { + rustCrate.withModule(ClientRustModule.client) { // helper function to resolve an endpoint given a base client rustTemplate( """ @@ -76,33 +76,40 @@ class TimestreamDecorator : ClientCodegenDecorator { /// Enable endpoint discovery for this client /// /// This method MUST be called to construct a working client. - pub async fn enable_endpoint_discovery(self) -> #{Result}<(Self, #{endpoint_discovery}::ReloadEndpoint), #{ResolveEndpointError}> { - let mut new_conf = self.conf().clone(); - let sleep = self.conf().sleep_impl().expect("sleep impl must be provided"); - let time = self.conf().time_source().expect("time source must be provided"); + pub async fn with_endpoint_discovery_enabled(self) -> #{Result}<(Self, #{endpoint_discovery}::ReloadEndpoint), #{ResolveEndpointError}> { + let handle = self.handle.clone(); + + // The original client without endpoint discover gets moved into the endpoint discovery + // resolver since calls to DescribeEndpoint without discovery need to be made. + let client_without_discovery = self; let (resolver, reloader) = #{endpoint_discovery}::create_cache( move || { - let client = self.clone(); + let client = client_without_discovery.clone(); async move { resolve_endpoint(&client).await } }, - sleep, - time - ) - .await?; - new_conf.endpoint_resolver = #{SharedEndpointResolver}::new(resolver); - Ok((Self::from_conf(new_conf), reloader)) + handle.conf.sleep_impl() + .expect("endpoint discovery requires the client config to have a sleep impl"), + handle.conf.time_source() + .expect("endpoint discovery requires the client config to have a time source"), + ).await?; + + let client_with_discovery = crate::Client::from_conf( + handle.conf.to_builder() + .endpoint_resolver(#{SharedEndpointResolver}::new(resolver)) + .build() + ); + Ok((client_with_discovery, reloader)) } } """, - "endpoint_discovery" to endpointDiscovery.toType(), - "SystemTime" to RuntimeType.std.resolve("time::SystemTime"), + *RuntimeType.preludeScope, + "Arc" to RuntimeType.Arc, "Duration" to RuntimeType.std.resolve("time::Duration"), "SharedEndpointResolver" to RuntimeType.smithyHttp(codegenContext.runtimeConfig) .resolve("endpoint::SharedEndpointResolver"), - "SystemTimeSource" to RuntimeType.smithyAsync(codegenContext.runtimeConfig) - .resolve("time::SystemTimeSource"), + "SystemTime" to RuntimeType.std.resolve("time::SystemTime"), + "endpoint_discovery" to endpointDiscovery.toType(), *Types(codegenContext.runtimeConfig).toArray(), - *preludeScope, ) } } diff --git a/aws/sdk/integration-tests/s3/tests/config_to_builder.rs b/aws/sdk/integration-tests/s3/tests/config_to_builder.rs new file mode 100644 index 0000000000..83827e458f --- /dev/null +++ b/aws/sdk/integration-tests/s3/tests/config_to_builder.rs @@ -0,0 +1,17 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +use aws_sdk_s3::config::AppName; + +#[tokio::test] +async fn test_config_to_builder() { + let config = aws_config::load_from_env().await; + let config = aws_sdk_s3::Config::new(&config); + // should not panic + let _ = config + .to_builder() + .app_name(AppName::new("SomeAppName").unwrap()) + .build(); +} diff --git a/aws/sdk/integration-tests/timestreamquery/Cargo.toml b/aws/sdk/integration-tests/timestreamquery/Cargo.toml index b81b618c88..99955e4764 100644 --- a/aws/sdk/integration-tests/timestreamquery/Cargo.toml +++ b/aws/sdk/integration-tests/timestreamquery/Cargo.toml @@ -13,8 +13,9 @@ publish = false [dev-dependencies] aws-credential-types = { path = "../../build/aws-sdk/sdk/aws-credential-types", features = ["test-util"] } aws-sdk-timestreamquery = { path = "../../build/aws-sdk/sdk/timestreamquery" } -tokio = { version = "1.23.1", features = ["full", "test-util"] } -aws-smithy-client = { path = "../../build/aws-sdk/sdk/aws-smithy-client", features = ["test-util"] } aws-smithy-async = { path = "../../build/aws-sdk/sdk/aws-smithy-async", features = ["test-util"] } +aws-smithy-client = { path = "../../build/aws-sdk/sdk/aws-smithy-client", features = ["test-util"] } +aws-smithy-runtime = { path = "../../build/aws-sdk/sdk/aws-smithy-runtime", features = ["test-util"] } aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } +tokio = { version = "1.23.1", features = ["full", "test-util"] } tracing-subscriber = "0.3.17" diff --git a/aws/sdk/integration-tests/timestreamquery/tests/endpoint_disco.rs b/aws/sdk/integration-tests/timestreamquery/tests/endpoint_disco.rs index d15244825f..ce8e7ad1a9 100644 --- a/aws/sdk/integration-tests/timestreamquery/tests/endpoint_disco.rs +++ b/aws/sdk/integration-tests/timestreamquery/tests/endpoint_disco.rs @@ -16,7 +16,8 @@ use std::time::{Duration, UNIX_EPOCH}; #[tokio::test] async fn do_endpoint_discovery() { - tracing_subscriber::fmt::init(); + let _logs = aws_smithy_runtime::test_util::capture_test_logs::capture_test_logs(); + let conn = ReplayingConnection::from_file("tests/traffic.json").unwrap(); //let conn = aws_smithy_client::dvr::RecordingConnection::new(conn); let start = UNIX_EPOCH + Duration::from_secs(1234567890); @@ -32,7 +33,7 @@ async fn do_endpoint_discovery() { .idempotency_token_provider("0000-0000-0000") .build(); let (client, reloader) = query::Client::from_conf(conf) - .enable_endpoint_discovery() + .with_endpoint_discovery_enabled() .await .expect("initial setup of endpoint discovery failed"); diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ConfigOverrideRuntimePluginGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ConfigOverrideRuntimePluginGenerator.kt index 5a37375e56..b199eaf5a5 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ConfigOverrideRuntimePluginGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ConfigOverrideRuntimePluginGenerator.kt @@ -54,8 +54,7 @@ class ConfigOverrideRuntimePluginGenerator( initial_config: #{FrozenLayer}, initial_components: &#{RuntimeComponentsBuilder} ) -> Self { - let mut layer = #{Layer}::from(config_override.config) - .with_name("$moduleUseName::config::ConfigOverrideRuntimePlugin"); + let mut layer = config_override.config; let mut components = config_override.runtime_components; let mut resolver = #{Resolver}::overrid(initial_config, initial_components, &mut layer, &mut components); @@ -63,7 +62,8 @@ class ConfigOverrideRuntimePluginGenerator( let _ = resolver; Self { - config: layer.freeze(), + config: #{Layer}::from(layer) + .with_name("$moduleUseName::config::ConfigOverrideRuntimePlugin").freeze(), components, } } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGenerator.kt index f3cbe633af..d0bc26f889 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGenerator.kt @@ -335,7 +335,11 @@ class ServiceConfigGenerator( if (runtimeMode.defaultToOrchestrator) { rustTemplate( """ + // Both `config` and `cloneable` are the same config, but the cloneable one + // is kept around so that it is possible to convert back into a builder. This can be + // optimized in the future. pub(crate) config: #{FrozenLayer}, + cloneable: #{CloneableLayer}, pub(crate) runtime_components: #{RuntimeComponentsBuilder}, pub(crate) runtime_plugins: #{Vec}<#{SharedRuntimePlugin}>, """, @@ -368,6 +372,20 @@ class ServiceConfigGenerator( pub fn builder() -> Builder { Builder::default() } """, ) + if (runtimeMode.defaultToOrchestrator) { + writer.rustTemplate( + """ + /// Converts this config back into a builder so that it can be tweaked. + pub fn to_builder(&self) -> Builder { + Builder { + config: self.cloneable.clone(), + runtime_components: self.runtime_components.clone(), + runtime_plugins: self.runtime_plugins.clone(), + } + } + """, + ) + } customizations.forEach { it.section(ServiceConfig.ConfigImpl)(this) } @@ -460,12 +478,7 @@ class ServiceConfigGenerator( rustBlock("pub fn build(mut self) -> Config") { rustTemplate( """ - // The builder is being turned into a service config. While doing so, we'd like to avoid - // requiring that items created and stored _during_ the build method be `Clone`, since they - // will soon be part of a `FrozenLayer` owned by the service config. So we will convert the - // current `CloneableLayer` into a `Layer` that does not impose the `Clone` requirement. - let mut layer = #{Layer}::from(self.config).with_name("$moduleUseName::config::Config"); - ##[allow(unused)] + let mut layer = self.config; let mut resolver = #{Resolver}::initial(&mut layer, &mut self.runtime_components); """, *codegenScope, @@ -477,12 +490,14 @@ class ServiceConfigGenerator( customizations.forEach { it.section(ServiceConfig.BuilderBuildExtras)(this) } - rust( + rustTemplate( """ - config: layer.freeze(), + config: #{Layer}::from(layer.clone()).with_name("$moduleUseName::config::Config").freeze(), + cloneable: layer, runtime_components: self.runtime_components, runtime_plugins: self.runtime_plugins, """, + *codegenScope, ) } } diff --git a/rust-runtime/aws-smithy-client/src/dvr/replay.rs b/rust-runtime/aws-smithy-client/src/dvr/replay.rs index 54065e5fc7..94d9123e0e 100644 --- a/rust-runtime/aws-smithy-client/src/dvr/replay.rs +++ b/rust-runtime/aws-smithy-client/src/dvr/replay.rs @@ -113,7 +113,7 @@ impl ReplayingConnection { ))? .take() .await; - aws_smithy_protocol_test::assert_uris_match(actual.uri(), expected.uri()); + aws_smithy_protocol_test::assert_uris_match(expected.uri(), actual.uri()); body_comparer(expected.body().as_ref(), actual.body().as_ref())?; let expected_headers = expected .headers() diff --git a/rust-runtime/aws-smithy-runtime/src/client/config_override.rs b/rust-runtime/aws-smithy-runtime/src/client/config_override.rs index c89352e139..b72a7c4c8c 100644 --- a/rust-runtime/aws-smithy-runtime/src/client/config_override.rs +++ b/rust-runtime/aws-smithy-runtime/src/client/config_override.rs @@ -5,7 +5,9 @@ use aws_smithy_async::rt::sleep::SharedAsyncSleep; use aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder; -use aws_smithy_types::config_bag::{FrozenLayer, Layer, Storable, Store, StoreReplace}; +use aws_smithy_types::config_bag::{ + CloneableLayer, FrozenLayer, Layer, Storable, Store, StoreReplace, +}; macro_rules! component { ($typ:ty, $accessor:ident, $latest_accessor:ident) => { @@ -39,14 +41,14 @@ macro_rules! latest_component { } struct Initial<'a> { - config: &'a mut Layer, + config: &'a mut CloneableLayer, components: &'a mut RuntimeComponentsBuilder, } struct Override<'a> { initial_config: FrozenLayer, initial_components: &'a RuntimeComponentsBuilder, - config: &'a mut Layer, + config: &'a mut CloneableLayer, components: &'a mut RuntimeComponentsBuilder, } @@ -74,7 +76,10 @@ pub struct Resolver<'a> { impl<'a> Resolver<'a> { /// Construct a new [`Resolver`] in _initial mode_. - pub fn initial(config: &'a mut Layer, components: &'a mut RuntimeComponentsBuilder) -> Self { + pub fn initial( + config: &'a mut CloneableLayer, + components: &'a mut RuntimeComponentsBuilder, + ) -> Self { Self { inner: Inner::Initial(Initial { config, components }), } @@ -84,7 +89,7 @@ impl<'a> Resolver<'a> { pub fn overrid( initial_config: FrozenLayer, initial_components: &'a RuntimeComponentsBuilder, - config: &'a mut Layer, + config: &'a mut CloneableLayer, components: &'a mut RuntimeComponentsBuilder, ) -> Self { Self { @@ -103,7 +108,7 @@ impl<'a> Resolver<'a> { } /// Returns a mutable reference to the latest config. - pub fn config_mut(&mut self) -> &mut Layer { + pub fn config_mut(&mut self) -> &mut CloneableLayer { match &mut self.inner { Inner::Initial(initial) => initial.config, Inner::Override(overrid) => overrid.config, diff --git a/rust-runtime/aws-smithy-runtime/src/client/orchestrator/endpoints.rs b/rust-runtime/aws-smithy-runtime/src/client/orchestrator/endpoints.rs index 1b22b3c5d9..be6fc51bf0 100644 --- a/rust-runtime/aws-smithy-runtime/src/client/orchestrator/endpoints.rs +++ b/rust-runtime/aws-smithy-runtime/src/client/orchestrator/endpoints.rs @@ -117,6 +117,7 @@ pub(super) async fn orchestrate_endpoint( .endpoint_resolver() .resolve_endpoint(params) .await?; + tracing::debug!("will use endpoint {:?}", endpoint); apply_endpoint(request, &endpoint, endpoint_prefix)?; // Make the endpoint config available to interceptors diff --git a/tools/ci-scripts/check-aws-sdk-orchestrator-impl b/tools/ci-scripts/check-aws-sdk-orchestrator-impl index 0104e7f03d..b86ebf3f0f 100755 --- a/tools/ci-scripts/check-aws-sdk-orchestrator-impl +++ b/tools/ci-scripts/check-aws-sdk-orchestrator-impl @@ -12,12 +12,6 @@ C_RESET='\033[0m' set -eu cd smithy-rs -# TODO(enableNewSmithyRuntimeLaunch): Move these into `services_that_compile` as more progress is made -services_that_dont_compile=(\ - "timestreamquery", - "timestreamwrite", -) - services_that_pass_tests=(\ "aws-config"\ "config"\ @@ -35,6 +29,8 @@ services_that_pass_tests=(\ "s3control"\ "sso"\ "sts"\ + "timestreamquery"\ + "timestreamwrite"\ "transcribestreaming"\ ) From 470717f2d5f3633c963bf845350276e0d59ae7cd Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Thu, 13 Jul 2023 17:33:16 -0700 Subject: [PATCH 2/6] Fix config override tests --- rust-runtime/aws-smithy-runtime/src/client/config_override.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust-runtime/aws-smithy-runtime/src/client/config_override.rs b/rust-runtime/aws-smithy-runtime/src/client/config_override.rs index b72a7c4c8c..c69770a974 100644 --- a/rust-runtime/aws-smithy-runtime/src/client/config_override.rs +++ b/rust-runtime/aws-smithy-runtime/src/client/config_override.rs @@ -185,7 +185,7 @@ mod tests { #[test] fn initial_mode_config() { - let mut config = Layer::new("test"); + let mut config = CloneableLayer::new("test"); let mut components = RuntimeComponentsBuilder::new("test"); let mut resolver = Resolver::initial(&mut config, &mut components); @@ -204,7 +204,7 @@ mod tests { fn override_mode_config() { let mut initial_config = CloneableLayer::new("initial"); let initial_components = RuntimeComponentsBuilder::new("initial"); - let mut config = Layer::new("override"); + let mut config = CloneableLayer::new("override"); let mut components = RuntimeComponentsBuilder::new("override"); let resolver = Resolver::overrid( From 1ef1d5d5ed5badd63678f4f327213277cdd991fa Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Fri, 14 Jul 2023 10:14:54 -0700 Subject: [PATCH 3/6] Fix missing dependency for inline file --- .../smithy/rustsdk/customize/timestream/TimestreamDecorator.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/timestream/TimestreamDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/timestream/TimestreamDecorator.kt index 31eb1e3dc1..8ddcba2b1b 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/timestream/TimestreamDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/timestream/TimestreamDecorator.kt @@ -51,6 +51,7 @@ class TimestreamDecorator : ClientCodegenDecorator { "endpoint_discovery", Visibility.PUBLIC, CargoDependency.Tokio.copy(scope = DependencyScope.Compile, features = setOf("sync")), + CargoDependency.smithyAsync(codegenContext.runtimeConfig).toDevDependency().withFeature("test-util"), ) rustCrate.withModule(ClientRustModule.client) { // helper function to resolve an endpoint given a base client From 2b608e9cbdf073da454b7ebb0c5fe64ded564e4b Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Fri, 14 Jul 2023 10:41:34 -0700 Subject: [PATCH 4/6] Don't test timestream in middleware mode --- .../timestream/TimestreamDecorator.kt | 37 ++++++++++++------- .../timestreamquery/tests/endpoint_disco.rs | 23 ++++++------ 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/timestream/TimestreamDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/timestream/TimestreamDecorator.kt index 8ddcba2b1b..44c7767bd3 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/timestream/TimestreamDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/timestream/TimestreamDecorator.kt @@ -18,6 +18,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.RustCrate import software.amazon.smithy.rust.codegen.core.smithy.customize.AdHocCustomization import software.amazon.smithy.rust.codegen.core.smithy.customize.adhocCustomization +import software.amazon.smithy.rust.codegen.core.util.letIf import software.amazon.smithy.rustsdk.AwsCargoDependency import software.amazon.smithy.rustsdk.DocSection import software.amazon.smithy.rustsdk.InlineAwsDependency @@ -31,22 +32,30 @@ class TimestreamDecorator : ClientCodegenDecorator { override val name: String = "Timestream" override val order: Byte = -1 - override fun extraSections(codegenContext: ClientCodegenContext): List { - return listOf( - adhocCustomization { - addDependency(AwsCargoDependency.awsConfig(codegenContext.runtimeConfig).toDevDependency()) - rustTemplate( - """ - let config = aws_config::load_from_env().await; - // You MUST call `with_endpoint_discovery_enabled` to produce a working client for this service. - let ${it.clientName} = ${it.crateName}::Client::new(&config).with_endpoint_discovery_enabled().await; - """.replaceIndent(it.indent), - ) - }, - ) - } + private fun applies(codegenContext: ClientCodegenContext): Boolean = + codegenContext.smithyRuntimeMode.defaultToOrchestrator + + override fun extraSections(codegenContext: ClientCodegenContext): List = + emptyList().letIf(applies(codegenContext)) { + listOf( + adhocCustomization { + addDependency(AwsCargoDependency.awsConfig(codegenContext.runtimeConfig).toDevDependency()) + rustTemplate( + """ + let config = aws_config::load_from_env().await; + // You MUST call `with_endpoint_discovery_enabled` to produce a working client for this service. + let ${it.clientName} = ${it.crateName}::Client::new(&config).with_endpoint_discovery_enabled().await; + """.replaceIndent(it.indent), + ) + }, + ) + } override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { + if (!applies(codegenContext)) { + return + } + val endpointDiscovery = InlineAwsDependency.forRustFile( "endpoint_discovery", Visibility.PUBLIC, diff --git a/aws/sdk/integration-tests/timestreamquery/tests/endpoint_disco.rs b/aws/sdk/integration-tests/timestreamquery/tests/endpoint_disco.rs index ce8e7ad1a9..447bdead21 100644 --- a/aws/sdk/integration-tests/timestreamquery/tests/endpoint_disco.rs +++ b/aws/sdk/integration-tests/timestreamquery/tests/endpoint_disco.rs @@ -3,19 +3,20 @@ * SPDX-License-Identifier: Apache-2.0 */ -use aws_credential_types::provider::SharedCredentialsProvider; -use aws_sdk_timestreamquery as query; -use aws_sdk_timestreamquery::config::Credentials; -use aws_smithy_async::rt::sleep::SharedAsyncSleep; -use aws_smithy_async::test_util::controlled_time_and_sleep; -use aws_smithy_async::time::{SharedTimeSource, TimeSource}; -use aws_smithy_client::dvr::{MediaType, ReplayingConnection}; -use aws_types::region::Region; -use aws_types::SdkConfig; -use std::time::{Duration, UNIX_EPOCH}; - +#[cfg(aws_sdk_orchestrator_mode)] #[tokio::test] async fn do_endpoint_discovery() { + use aws_credential_types::provider::SharedCredentialsProvider; + use aws_sdk_timestreamquery as query; + use aws_sdk_timestreamquery::config::Credentials; + use aws_smithy_async::rt::sleep::SharedAsyncSleep; + use aws_smithy_async::test_util::controlled_time_and_sleep; + use aws_smithy_async::time::{SharedTimeSource, TimeSource}; + use aws_smithy_client::dvr::{MediaType, ReplayingConnection}; + use aws_types::region::Region; + use aws_types::SdkConfig; + use std::time::{Duration, UNIX_EPOCH}; + let _logs = aws_smithy_runtime::test_util::capture_test_logs::capture_test_logs(); let conn = ReplayingConnection::from_file("tests/traffic.json").unwrap(); From 83a5160279a464ed23bfb7de0a5ba0e020161491 Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Fri, 14 Jul 2023 10:59:22 -0700 Subject: [PATCH 5/6] Fix S3 test --- aws/sdk/integration-tests/s3/tests/config_to_builder.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/aws/sdk/integration-tests/s3/tests/config_to_builder.rs b/aws/sdk/integration-tests/s3/tests/config_to_builder.rs index 83827e458f..edf291dbc7 100644 --- a/aws/sdk/integration-tests/s3/tests/config_to_builder.rs +++ b/aws/sdk/integration-tests/s3/tests/config_to_builder.rs @@ -5,6 +5,7 @@ use aws_sdk_s3::config::AppName; +#[cfg(aws_sdk_orchestrator_mode)] #[tokio::test] async fn test_config_to_builder() { let config = aws_config::load_from_env().await; From 2fef42f0df44e0572479aac8d0a54f9b1ff97268 Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Fri, 14 Jul 2023 13:32:41 -0700 Subject: [PATCH 6/6] Fix unused import --- aws/sdk/integration-tests/s3/tests/config_to_builder.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aws/sdk/integration-tests/s3/tests/config_to_builder.rs b/aws/sdk/integration-tests/s3/tests/config_to_builder.rs index edf291dbc7..122b0418b6 100644 --- a/aws/sdk/integration-tests/s3/tests/config_to_builder.rs +++ b/aws/sdk/integration-tests/s3/tests/config_to_builder.rs @@ -3,11 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -use aws_sdk_s3::config::AppName; - #[cfg(aws_sdk_orchestrator_mode)] #[tokio::test] async fn test_config_to_builder() { + use aws_sdk_s3::config::AppName; + let config = aws_config::load_from_env().await; let config = aws_sdk_s3::Config::new(&config); // should not panic