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

behavior version 2024-03-28 #3617

Merged
merged 21 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d9d3a2f
Enable stalled stream protection for uploads behind new behavior version
jdisanti Mar 27, 2024
477d1d5
Add changelog entries
jdisanti Mar 27, 2024
e72da5e
Merge remote-tracking branch 'origin/main' into jdisanti-bmv-stall-up…
jdisanti Apr 12, 2024
df57d1e
Fix runtime crate version numbers after merge
jdisanti Apr 12, 2024
3f3ac63
Improve changelog message
jdisanti Apr 12, 2024
6d25692
Merge remote-tracking branch 'origin/main' into jdisanti-bmv-stall-up…
jdisanti Apr 23, 2024
4dac882
Fix deprecation error
jdisanti Apr 23, 2024
f7731ba
Fix another deprecation error
jdisanti Apr 24, 2024
a21b6d9
Fix aws-smithy-runtime version number after release
jdisanti Apr 24, 2024
510ce11
Enable stalled stream protection for uploads behind new behavior vers…
jdisanti Apr 24, 2024
27f6b18
create an IdentityCache by default when on latest BehaviorVersion
aajtodd Apr 11, 2024
abddedc
update rfc status
aajtodd Apr 25, 2024
83290df
fixup integration tests
aajtodd Apr 25, 2024
a3002e8
remove API to unset identity cache
aajtodd Apr 26, 2024
c8119f5
fix test cfg
aajtodd Apr 26, 2024
3b87e39
create an IdentityCache by default when on latest BehaviorVersion (#3…
aajtodd Apr 26, 2024
ef380b8
fix todo
aajtodd Apr 30, 2024
46af22d
Merge remote-tracking branch 'origin/main' into behavior-version-2024…
aajtodd May 1, 2024
91f5cd7
bump versions
aajtodd May 1, 2024
79c1b37
fix issue reference
aajtodd May 1, 2024
8c58076
Merge remote-tracking branch 'origin/main' into behavior-version-2024…
aajtodd May 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Enable stalled stream protection for uploads behind new behavior version
  • Loading branch information
jdisanti committed Apr 10, 2024
commit d9d3a2f0fe0a6ad581ba8d51e909662613eae863
2 changes: 1 addition & 1 deletion aws/rust-runtime/aws-inlineable/src/s3_express.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ pub(crate) mod identity_provider {
config_bag: &'a ConfigBag,
) -> Result<SessionCredentials, BoxError> {
let mut config_builder = crate::config::Builder::from_config_bag(config_bag)
.behavior_version(self.behavior_version.clone());
.behavior_version(self.behavior_version);

// inherits all runtime components from a current S3 operation but clears out
// out interceptors configured for that operation
Expand Down
4 changes: 2 additions & 2 deletions aws/rust-runtime/aws-types/src/sdk_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,9 +798,9 @@ impl SdkConfig {
self.stalled_stream_protection_config.clone()
}

/// Behavior major version configured for this client
/// Behavior version configured for this client
pub fn behavior_version(&self) -> Option<BehaviorVersion> {
self.behavior_version.clone()
self.behavior_version
}

/// Return an immutable reference to the service config provider configured for this client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private class S3ExpressServiceRuntimePluginCustomization(codegenContext: ClientC
rustTemplate(
"""
#{DefaultS3ExpressIdentityProvider}::builder()
.behavior_version(${section.serviceConfigName}.behavior_version.clone().expect(${behaviorVersionError.dq()}))
.behavior_version(${section.serviceConfigName}.behavior_version.expect(${behaviorVersionError.dq()}))
.time_source(${section.serviceConfigName}.time_source().unwrap_or_default())
.build()
""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ async fn test_stalled_stream_protection_defaults_for_upload() {
let _ = tokio::spawn(server);

let conf = Config::builder()
// Stalled stream protection MUST BE enabled by default. Do not configure it explicitly.
.credentials_provider(Credentials::for_tests())
.region(Region::new("us-east-1"))
.endpoint_url(format!("http://{server_addr}"))
// TODO(https://github.com/smithy-lang/smithy-rs/issues/3510): make stalled stream protection enabled by default with BMV and remove this line
.stalled_stream_protection(StalledStreamProtectionConfig::enabled().build())
.build();
let client = Client::from_conf(conf);

Expand Down Expand Up @@ -255,6 +254,7 @@ async fn test_stalled_stream_protection_for_downloads_is_enabled_by_default() {

// Stalled stream protection should be enabled by default.
let sdk_config = aws_config::from_env()
// Stalled stream protection MUST BE enabled by default. Do not configure it explicitly.
.credentials_provider(Credentials::for_tests())
.region(Region::new("us-east-1"))
.endpoint_url(format!("http://{server_addr}"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ private fun baseClientRuntimePluginsFn(
.with_client_plugins(#{default_plugins}(
#{DefaultPluginParams}::new()
.with_retry_partition_name(${codegenContext.serviceShape.sdkId().dq()})
.with_behavior_version(config.behavior_version.clone().expect(${behaviorVersionError.dq()}))
.with_behavior_version(config.behavior_version.expect(${behaviorVersionError.dq()}))
))
// user config
.with_client_plugin(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ class ServiceConfigGenerator(
config: self.cloneable.clone(),
runtime_components: self.runtime_components.clone(),
runtime_plugins: self.runtime_plugins.clone(),
behavior_version: self.behavior_version.clone(),
behavior_version: self.behavior_version,
}
}
""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@
* SPDX-License-Identifier: Apache-2.0
*/

//! Behavior Major version of the client
//! Behavior version of the client

/// Behavior major-version of the client
/// Behavior version of the client
///
/// Over time, new best-practice behaviors are introduced. However, these behaviors might not be
/// backwards compatible. For example, a change which introduces new default timeouts or a new
/// retry-mode for all operations might be the ideal behavior but could break existing applications.
#[derive(Clone)]
#[derive(Copy, Clone, PartialEq)]
pub struct BehaviorVersion {
// currently there is only 1 MV so we don't actually need anything in here.
_private: (),
inner: Inner,
}

#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq)]
enum Inner {
// IMPORTANT: Order matters here for the `Ord` derive. Newer versions go to the bottom.
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

V2023_11_09,
V2024_03_28,
}

impl BehaviorVersion {
Expand All @@ -26,23 +32,60 @@ impl BehaviorVersion {
/// If, however, you're writing a service that is very latency sensitive, or that has written
/// code to tune Rust SDK behaviors, consider pinning to a specific major version.
///
/// The latest version is currently [`BehaviorVersion::v2023_11_09`]
/// The latest version is currently [`BehaviorVersion::v2024_03_28`]
pub fn latest() -> Self {
Self::v2023_11_09()
Self::v2024_03_28()
}

/// This method returns the behavior configuration for November 9th, 2023
/// Behavior version for March 28th, 2024.
///
/// This version enables stalled stream protection for uploads (request bodies) by default.
///
/// When a new behavior major version is released, this method will be deprecated.
pub fn v2024_03_28() -> Self {
Self {
inner: Inner::V2024_03_28,
}
}

/// Behavior version for November 9th, 2023.
#[deprecated(
since = "1.4.0",
note = "Superceded by v2024_03_28, which enabled stalled stream protection for uploads (request bodies) by default."
)]
pub fn v2023_11_09() -> Self {
Self { _private: () }
Self {
inner: Inner::V2023_11_09,
}
}

/// True if this version is newer or equal to the given `other` version.
pub fn is_at_least(&self, other: BehaviorVersion) -> bool {
self.inner >= other.inner
}
}

impl std::fmt::Debug for BehaviorVersion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("BehaviorVersion")
.field("name", &"v2023_11_09")
.finish()
f.debug_tuple("BehaviorVersion").field(&self.inner).finish()
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
#[allow(deprecated)]
fn version_comparison() {
assert!(BehaviorVersion::latest() == BehaviorVersion::latest());
assert!(BehaviorVersion::v2023_11_09() == BehaviorVersion::v2023_11_09());
assert!(BehaviorVersion::v2024_03_28() != BehaviorVersion::v2023_11_09());
assert!(BehaviorVersion::latest().is_at_least(BehaviorVersion::latest()));
assert!(BehaviorVersion::latest().is_at_least(BehaviorVersion::v2023_11_09()));
assert!(BehaviorVersion::latest().is_at_least(BehaviorVersion::v2024_03_28()));
assert!(!BehaviorVersion::v2023_11_09().is_at_least(BehaviorVersion::v2024_03_28()));
assert!(Inner::V2024_03_28 > Inner::V2023_11_09);
assert!(Inner::V2023_11_09 < Inner::V2024_03_28);
}
}
61 changes: 53 additions & 8 deletions rust-runtime/aws-smithy-runtime/src/client/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,11 @@ pub fn default_identity_cache_plugin() -> Option<SharedRuntimePlugin> {
note = "This function wasn't intended to be public, and didn't take the behavior major version as an argument, so it couldn't be evolved over time."
)]
pub fn default_stalled_stream_protection_config_plugin() -> Option<SharedRuntimePlugin> {
#[allow(deprecated)]
default_stalled_stream_protection_config_plugin_v2(BehaviorVersion::v2023_11_09())
}
fn default_stalled_stream_protection_config_plugin_v2(
_behavior_version: BehaviorVersion,
behavior_version: BehaviorVersion,
) -> Option<SharedRuntimePlugin> {
Some(
default_plugin(
Expand All @@ -191,13 +192,13 @@ fn default_stalled_stream_protection_config_plugin_v2(
},
)
.with_config(layer("default_stalled_stream_protection_config", |layer| {
layer.store_put(
StalledStreamProtectionConfig::enabled()
// TODO(https://github.com/smithy-lang/smithy-rs/issues/3510): enable behind new behavior version
.upload_enabled(false)
.grace_period(Duration::from_secs(5))
.build(),
);
let mut config =
StalledStreamProtectionConfig::enabled().grace_period(Duration::from_secs(5));
// Before v2024_03_28, upload streams did not have stalled stream protection by default
if !behavior_version.is_at_least(BehaviorVersion::v2024_03_28()) {
config = config.upload_enabled(false);
}
layer.store_put(config.build());
}))
.into_shared(),
)
Expand Down Expand Up @@ -293,3 +294,47 @@ pub fn default_plugins(
.flatten()
.collect::<Vec<SharedRuntimePlugin>>()
}

#[cfg(test)]
mod tests {
use super::*;
use aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins;

fn test_plugin_params(version: BehaviorVersion) -> DefaultPluginParams {
DefaultPluginParams::new()
.with_behavior_version(version)
.with_retry_partition_name("dontcare")
}
fn config_for(plugins: impl IntoIterator<Item = SharedRuntimePlugin>) -> ConfigBag {
let mut config = ConfigBag::base();
let plugins = RuntimePlugins::new().with_client_plugins(plugins);
plugins.apply_client_configuration(&mut config).unwrap();
config
}

#[test]
#[allow(deprecated)]
fn v2024_03_28_stalled_stream_protection_difference() {
let latest = config_for(default_plugins(test_plugin_params(
BehaviorVersion::latest(),
)));
let v2023 = config_for(default_plugins(test_plugin_params(
BehaviorVersion::v2023_11_09(),
)));

assert!(
latest
.load::<StalledStreamProtectionConfig>()
.unwrap()
.upload_enabled(),
"stalled stream protection on uploads MUST be enabled after v2024_03_28"
);
assert!(
!v2023
.load::<StalledStreamProtectionConfig>()
.unwrap()
.upload_enabled(),
"stalled stream protection on uploads MUST NOT be enabled before v2024_03_28"
);
}
}