-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add feature ID for S3 Transfer Manager (#3921)
## Motivation and Context This PR introduces the `AwsSdkFeature` enum, which will be used for AWS SDK-specific feature identifiers. For now, it includes a single ID for the S3 Transfer Manager. This approach is similar to the existing [SmithySdkFeature](https://github.com/smithy-lang/smithy-rs/blob/aac9becfd469e2479f68c61fd4c8074ddf755482/rust-runtime/aws-smithy-runtime/src/client/sdk_feature.rs#L10) in terms of its module and crate structure (that is for generic client but `AwsSdkFeature` is AWS specific); the `sdk_feature` module is hidden as it is intended for internal use only. ## Testing Added an integration test to verify tracking a business metric for Transfer Manager. Since Transfer Manager is a high-level library, we do not track its business metric directly within the `smithy-rs` repository. Instead, [an s3 client](https://github.com/awslabs/aws-s3-transfer-manager-rs/blob/main/aws-s3-transfer-manager/src/config.rs#L21) used in [aws-s3-transfer-manager-rs](https://github.com/awslabs/aws-s3-transfer-manager-rs) can configure the s3 client as demonstrated in the integration test to track the metric. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ --------- Co-authored-by: Zelda Hessler <[email protected]>
- Loading branch information
1 parent
aac9bec
commit e54cc56
Showing
10 changed files
with
131 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "aws-runtime" | ||
version = "1.4.3" | ||
version = "1.4.4" | ||
authors = ["AWS Rust SDK Team <[email protected]>"] | ||
description = "Runtime support code for the AWS SDK. This crate isn't intended to be used directly." | ||
edition = "2021" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
use aws_smithy_types::config_bag::{Storable, StoreAppend}; | ||
|
||
/// IDs for the features that may be used in the AWS SDK | ||
#[non_exhaustive] | ||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub enum AwsSdkFeature { | ||
/// Indicates that an operation was called by the S3 Transfer Manager | ||
S3Transfer, | ||
} | ||
|
||
impl Storable for AwsSdkFeature { | ||
type Storer = StoreAppend<Self>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
use aws_config::Region; | ||
use aws_runtime::{ | ||
sdk_feature::AwsSdkFeature, user_agent::test_util::assert_ua_contains_metric_values, | ||
}; | ||
use aws_sdk_s3::{ | ||
config::{Intercept, IntoShared}, | ||
primitives::ByteStream, | ||
Client, Config, | ||
}; | ||
use aws_smithy_runtime::client::http::test_util::capture_request; | ||
|
||
#[derive(Debug)] | ||
struct TransferManagerFeatureInterceptor; | ||
|
||
impl Intercept for TransferManagerFeatureInterceptor { | ||
fn name(&self) -> &'static str { | ||
"TransferManagerFeature" | ||
} | ||
|
||
fn read_before_execution( | ||
&self, | ||
_ctx: &aws_sdk_s3::config::interceptors::BeforeSerializationInterceptorContextRef<'_>, | ||
cfg: &mut aws_sdk_s3::config::ConfigBag, | ||
) -> Result<(), aws_sdk_s3::error::BoxError> { | ||
cfg.interceptor_state() | ||
.store_append(AwsSdkFeature::S3Transfer); | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_track_metric_for_s3_transfer_manager() { | ||
let (http_client, captured_request) = capture_request(None); | ||
let mut conf_builder = Config::builder() | ||
.region(Region::new("us-east-1")) | ||
.http_client(http_client.clone()) | ||
.with_test_defaults(); | ||
// The S3 Transfer Manager uses a passed-in S3 client SDK for operations. | ||
// By configuring an interceptor at the client level to track metrics, | ||
// all operations executed by the client will automatically include the metric. | ||
// This eliminates the need to apply `.config_override` on individual operations | ||
// to insert the `TransferManagerFeatureInterceptor`. | ||
conf_builder.push_interceptor(TransferManagerFeatureInterceptor.into_shared()); | ||
let client = Client::from_conf(conf_builder.build()); | ||
|
||
let _ = client | ||
.put_object() | ||
.bucket("doesnotmatter") | ||
.key("doesnotmatter") | ||
.body(ByteStream::from_static("Hello, world".as_bytes())) | ||
.send() | ||
.await | ||
.unwrap(); | ||
|
||
let expected_req = captured_request.expect_request(); | ||
let user_agent = expected_req.headers().get("x-amz-user-agent").unwrap(); | ||
assert_ua_contains_metric_values(user_agent, &["G"]); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "aws-smithy-runtime" | ||
version = "1.7.3" | ||
version = "1.7.4" | ||
authors = ["AWS Rust SDK Team <[email protected]>", "Zelda Hessler <[email protected]>"] | ||
description = "The new smithy runtime crate" | ||
edition = "2021" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters