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

Feature: Stalled stream protection #3202

Merged
merged 27 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
79bca6c
checkpoint
Velfi Nov 8, 2023
5569064
implement stalled stream protection for downloads
Velfi Nov 14, 2023
041a6dd
Merge remote-tracking branch 'origin/main' into zhessler-stalled-stre…
Velfi Nov 14, 2023
bc0965c
fix import that needed a feature gate
Velfi Nov 15, 2023
bf2040a
Merge branch 'main' into zhessler-stalled-stream-protection
Velfi Nov 15, 2023
48a42f2
fix doc test
Velfi Nov 15, 2023
cb63698
add CHANGELOG
Velfi Nov 15, 2023
d5e3cee
add grace period support
Velfi Nov 15, 2023
6cae978
remove feature gate
Velfi Nov 15, 2023
b7bce2f
Merge remote-tracking branch 'origin/main' into zhessler-stalled-stre…
Velfi Nov 15, 2023
d653f42
add allowed external type to aws-types
Velfi Nov 15, 2023
46920fa
add creds to integration tests
Velfi Nov 15, 2023
3e08632
Apply suggestions from code review
Velfi Nov 16, 2023
5a15468
Merge remote-tracking branch 'origin/main' into zhessler-stalled-stre…
Velfi Nov 16, 2023
b1f4149
remove config suffix from stalled stream function names
Velfi Nov 16, 2023
6d9a7e1
remove blob gate on stalled stream protection interceptor
Velfi Nov 16, 2023
a760a26
move stalled stream protection to runtime API crate
Velfi Nov 16, 2023
3dac27c
Merge branch 'main' into zhessler-stalled-stream-protection
Velfi Nov 16, 2023
f78c4f0
fix external types
Velfi Nov 16, 2023
25f9819
Merge branch 'main' into zhessler-stalled-stream-protection
Velfi Nov 16, 2023
6a52c90
fix dynamoDB retry tests
Velfi Nov 16, 2023
ed660ac
Merge branch 'main' of github.com:smithy-lang/smithy-rs into zhessler…
rcoh Nov 17, 2023
3ca242d
Fix bugs and tests
rcoh Nov 17, 2023
a0ab75a
Fix timestream
rcoh Nov 17, 2023
64f994a
Merge branch 'main' of github.com:smithy-lang/smithy-rs into zhessler…
rcoh Nov 17, 2023
c03f39b
Merge branch 'main' into zhessler-stalled-stream-protection
rcoh Nov 17, 2023
b257a71
Update CHANGELOG.next.toml
rcoh Nov 17, 2023
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
1 change: 1 addition & 0 deletions aws/rust-runtime/aws-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ allow-compilation = [] # our tests use `cargo test --all-features` and native-tl
rt-tokio = ["aws-smithy-async/rt-tokio", "aws-smithy-runtime/rt-tokio", "tokio/rt"]
sso = ["dep:aws-sdk-sso", "dep:aws-sdk-ssooidc", "dep:ring", "dep:hex", "dep:zeroize", "aws-smithy-runtime-api/http-auth"]
credentials-process = ["tokio/process"]
stalled-stream-protection = ["aws-types/stalled-stream-protection", "aws-smithy-types/stalled-stream-protection"]

default = ["client-hyper", "rustls", "rt-tokio", "credentials-process", "sso"]

Expand Down
38 changes: 38 additions & 0 deletions aws/rust-runtime/aws-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ mod loader {
use aws_types::sdk_config::SharedHttpClient;
use aws_types::SdkConfig;

#[cfg(feature = "stalled-stream-protection")]
use aws_smithy_types::stalled_stream_protection::StalledStreamProtectionConfig;
Velfi marked this conversation as resolved.
Show resolved Hide resolved

#[derive(Default, Debug)]
enum CredentialsProviderOption {
/// No provider was set by the user. We can set up the default credentials provider chain.
Expand Down Expand Up @@ -210,6 +213,8 @@ mod loader {
use_fips: Option<bool>,
use_dual_stack: Option<bool>,
time_source: Option<SharedTimeSource>,
#[cfg(feature = "stalled-stream-protection")]
stalled_stream_protection_config: Option<StalledStreamProtectionConfig>,
env: Option<Env>,
fs: Option<Fs>,
}
Expand Down Expand Up @@ -555,6 +560,37 @@ mod loader {
self
}

#[cfg(feature = "stalled-stream-protection")]
/// Override [`the StoppedStreamProtectionConfig`] used to build [`SdkConfig`](aws_types::SdkConfig).
Velfi marked this conversation as resolved.
Show resolved Hide resolved
///
/// This configures stalled stream protection. When enabled, download streams
/// that stop (stream no data) for longer than a configured grace period will return an error.
///
/// _Note_: When an override is provided, the default implementation is replaced.
Velfi marked this conversation as resolved.
Show resolved Hide resolved
///
/// # Examples
/// ```no_run
/// # async fn create_config() {
/// use aws_smithy_types::stalled_stream_protection::StalledStreamProtectionConfig;
Velfi marked this conversation as resolved.
Show resolved Hide resolved
/// use std::time::Duration;
/// let config = aws_config::from_env()
/// .stalled_stream_protection_config(
/// StalledStreamProtectionConfig::new_enabled()
/// .with_grace_period(Duration::from_secs(1))
/// .build()
/// )
/// .load()
/// .await;
/// # }
/// ```
pub fn stalled_stream_protection_config(
mut self,
stalled_stream_protection_config: StalledStreamProtectionConfig,
) -> Self {
self.stalled_stream_protection_config = Some(stalled_stream_protection_config);
self
}

/// Set configuration for all sub-loaders (credentials, region etc.)
///
/// Update the `ProviderConfig` used for all nested loaders. This can be used to override
Expand Down Expand Up @@ -700,6 +736,8 @@ mod loader {
builder.set_endpoint_url(self.endpoint_url);
builder.set_use_fips(use_fips);
builder.set_use_dual_stack(use_dual_stack);
#[cfg(feature = "stalled-stream-protection")]
builder.set_stalled_stream_protection_config(self.stalled_stream_protection_config);
builder.build()
}
}
Expand Down
1 change: 1 addition & 0 deletions aws/rust-runtime/aws-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ repository = "https://github.com/smithy-lang/smithy-rs"
[features]
# This feature is to be used only for doc comments
examples = ["dep:hyper-rustls", "aws-smithy-runtime/client", "aws-smithy-runtime/connector-hyper-0-14-x", "aws-smithy-runtime/tls-rustls"]
stalled-stream-protection = ["aws-smithy-types/stalled-stream-protection"]

[dependencies]
aws-credential-types = { path = "../aws-credential-types" }
Expand Down
85 changes: 85 additions & 0 deletions aws/rust-runtime/aws-types/src/sdk_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub use aws_smithy_runtime_api::client::http::SharedHttpClient;
use aws_smithy_runtime_api::client::identity::{ResolveCachedIdentity, SharedIdentityCache};
use aws_smithy_runtime_api::shared::IntoShared;
pub use aws_smithy_types::retry::RetryConfig;
#[cfg(feature = "stalled-stream-protection")]
pub use aws_smithy_types::stalled_stream_protection::StalledStreamProtectionConfig;
pub use aws_smithy_types::timeout::TimeoutConfig;

#[doc(hidden)]
Expand Down Expand Up @@ -59,6 +61,8 @@ pub struct SdkConfig {
sleep_impl: Option<SharedAsyncSleep>,
time_source: Option<SharedTimeSource>,
timeout_config: Option<TimeoutConfig>,
#[cfg(feature = "stalled-stream-protection")]
stalled_stream_protection_config: Option<StalledStreamProtectionConfig>,
http_client: Option<SharedHttpClient>,
use_fips: Option<bool>,
use_dual_stack: Option<bool>,
Expand All @@ -80,6 +84,8 @@ pub struct Builder {
sleep_impl: Option<SharedAsyncSleep>,
time_source: Option<SharedTimeSource>,
timeout_config: Option<TimeoutConfig>,
#[cfg(feature = "stalled-stream-protection")]
stalled_stream_protection_config: Option<StalledStreamProtectionConfig>,
http_client: Option<SharedHttpClient>,
use_fips: Option<bool>,
use_dual_stack: Option<bool>,
Expand Down Expand Up @@ -551,10 +557,81 @@ impl Builder {
use_fips: self.use_fips,
use_dual_stack: self.use_dual_stack,
time_source: self.time_source,
#[cfg(feature = "stalled-stream-protection")]
stalled_stream_protection_config: self.stalled_stream_protection_config,
}
}
}

#[cfg(feature = "stalled-stream-protection")]
impl Builder {
/// Set the [`StalledStreamProtectionConfig`] to configure protection for stalled streams.
Velfi marked this conversation as resolved.
Show resolved Hide resolved
///
/// This configures stalled stream protection. When enabled, download streams
/// that stall (stream no data) for longer than a configured grace period will return an error.
///
/// _Note:_ Stalled stream protection requires both a sleep implementation and a time source
/// in order to work. When enabling stalled stream protection, make sure to set
/// - A sleep impl with [Self::sleep_impl] or [Self::set_sleep_impl].
/// - A time source with [Self::time_source] or [Self::set_time_source].
///
/// # Examples
/// ```rust
/// use std::time::Duration;
/// use aws_types::SdkConfig;
/// pub use aws_smithy_types::stalled_stream_protection::StalledStreamProtectionConfig;
///
/// let stalled_stream_protection_config = StalledStreamProtectionConfig::enabled()
/// .grace_period(Duration::from_secs(1))
/// .build();
/// let config = SdkConfig::builder()
/// .stalled_stream_protection_config(stalled_stream_protection_config)
/// .build();
/// ```
pub fn stalled_stream_protection_config(
Velfi marked this conversation as resolved.
Show resolved Hide resolved
mut self,
stalled_stream_protection_config: StalledStreamProtectionConfig,
) -> Self {
self.set_stalled_stream_protection_config(Some(stalled_stream_protection_config));
self
}

/// Set the [`StalledStreamProtectionConfig`] to configure protection for stalled streams.
///
/// This configures stalled stream protection. When enabled, download streams
/// that stall (stream no data) for longer than a configured grace period will return an error.
///
/// _Note:_ Stalled stream protection requires both a sleep implementation and a time source
/// in order to work. When enabling stalled stream protection, make sure to set
/// - A sleep impl with [Self::sleep_impl] or [Self::set_sleep_impl].
/// - A time source with [Self::time_source] or [Self::set_time_source].
///
/// # Examples
/// ```rust
/// use std::time::Duration;
/// use aws_types::sdk_config::{SdkConfig, Builder};
/// pub use aws_smithy_types::stalled_stream_protection::StalledStreamProtectionConfig;
///
/// fn set_stalled_stream_protection(builder: &mut Builder) {
/// let stalled_stream_protection_config = StalledStreamProtectionConfig::enabled()
/// .grace_period(Duration::from_secs(1))
/// .build();
/// builder.set_stalled_stream_protection_config(Some(stalled_stream_protection_config));
/// }
///
/// let mut builder = SdkConfig::builder();
/// set_stalled_stream_protection(&mut builder);
/// let config = builder.build();
/// ```
pub fn set_stalled_stream_protection_config(
&mut self,
stalled_stream_protection_config: Option<StalledStreamProtectionConfig>,
) -> &mut Self {
self.stalled_stream_protection_config = stalled_stream_protection_config;
self
}
}

impl SdkConfig {
/// Configured region
pub fn region(&self) -> Option<&Region> {
Expand Down Expand Up @@ -617,6 +694,12 @@ impl SdkConfig {
self.use_dual_stack
}

/// Configured stalled stream protection
#[cfg(feature = "stalled-stream-protection")]
pub fn stalled_stream_protection_config(&self) -> Option<StalledStreamProtectionConfig> {
self.stalled_stream_protection_config.clone()
}

/// Config builder
///
/// _Important:_ Using the `aws-config` crate to configure the SDK is preferred to invoking this
Expand Down Expand Up @@ -646,6 +729,8 @@ impl SdkConfig {
http_client: self.http_client,
use_fips: self.use_fips,
use_dual_stack: self.use_dual_stack,
#[cfg(feature = "stalled-stream-protection")]
stalled_stream_protection_config: self.stalled_stream_protection_config,
}
}
}
4 changes: 2 additions & 2 deletions aws/sdk/integration-tests/s3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ test-util = []

[dev-dependencies]
async-std = "1.12.0"
aws-config = { path = "../../build/aws-sdk/sdk/aws-config" }
aws-config = { path = "../../build/aws-sdk/sdk/aws-config", features = ["stalled-stream-protection"] }
aws-credential-types = { path = "../../build/aws-sdk/sdk/aws-credential-types", features = ["test-util"] }
aws-http = { path = "../../build/aws-sdk/sdk/aws-http" }
aws-runtime = { path = "../../build/aws-sdk/sdk/aws-runtime", features = ["test-util"] }
aws-sdk-s3 = { path = "../../build/aws-sdk/sdk/s3", features = ["test-util"] }
aws-sdk-s3 = { path = "../../build/aws-sdk/sdk/s3", features = ["test-util", "stalled-stream-protection"] }
aws-sdk-sts = { path = "../../build/aws-sdk/sdk/sts" }
aws-smithy-async = { path = "../../build/aws-sdk/sdk/aws-smithy-async", features = ["test-util", "rt-tokio"] }
aws-smithy-http = { path = "../../build/aws-sdk/sdk/aws-smithy-http" }
Expand Down
Loading
Loading