From b9056f74b26ea4f97d4f2e81f96748dc15ff082f Mon Sep 17 00:00:00 2001 From: ysaito1001 Date: Mon, 25 Nov 2024 17:01:17 -0600 Subject: [PATCH 1/4] Add `AwsSdkFeature` to track AWS specific features --- aws/rust-runtime/Cargo.lock | 2 +- aws/rust-runtime/aws-runtime/Cargo.toml | 2 +- aws/rust-runtime/aws-runtime/src/lib.rs | 3 +++ .../aws-runtime/src/sdk_feature.rs | 18 ++++++++++++++++++ .../aws-runtime/src/user_agent/interceptor.rs | 8 ++++++++ .../aws-runtime/src/user_agent/metrics.rs | 10 ++++++++++ 6 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 aws/rust-runtime/aws-runtime/src/sdk_feature.rs diff --git a/aws/rust-runtime/Cargo.lock b/aws/rust-runtime/Cargo.lock index 51b755bf45..0a5a7d1629 100644 --- a/aws/rust-runtime/Cargo.lock +++ b/aws/rust-runtime/Cargo.lock @@ -138,7 +138,7 @@ dependencies = [ [[package]] name = "aws-runtime" -version = "1.4.3" +version = "1.4.4" dependencies = [ "arbitrary", "aws-credential-types", diff --git a/aws/rust-runtime/aws-runtime/Cargo.toml b/aws/rust-runtime/aws-runtime/Cargo.toml index 2265a7f3b4..9656489047 100644 --- a/aws/rust-runtime/aws-runtime/Cargo.toml +++ b/aws/rust-runtime/aws-runtime/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aws-runtime" -version = "1.4.3" +version = "1.4.4" authors = ["AWS Rust SDK Team "] description = "Runtime support code for the AWS SDK. This crate isn't intended to be used directly." edition = "2021" diff --git a/aws/rust-runtime/aws-runtime/src/lib.rs b/aws/rust-runtime/aws-runtime/src/lib.rs index 3030866953..5c2ab19646 100644 --- a/aws/rust-runtime/aws-runtime/src/lib.rs +++ b/aws/rust-runtime/aws-runtime/src/lib.rs @@ -38,6 +38,9 @@ pub mod invocation_id; /// Supporting code for request metadata headers in the AWS SDK. pub mod request_info; +#[doc(hidden)] +pub mod sdk_feature; + /// Interceptor that determines the clock skew between the client and service. pub mod service_clock_skew; diff --git a/aws/rust-runtime/aws-runtime/src/sdk_feature.rs b/aws/rust-runtime/aws-runtime/src/sdk_feature.rs new file mode 100644 index 0000000000..9099ed12bf --- /dev/null +++ b/aws/rust-runtime/aws-runtime/src/sdk_feature.rs @@ -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 called using the S3 Transfer Manager + S3Transfer, +} + +impl Storable for AwsSdkFeature { + type Storer = StoreAppend; +} diff --git a/aws/rust-runtime/aws-runtime/src/user_agent/interceptor.rs b/aws/rust-runtime/aws-runtime/src/user_agent/interceptor.rs index 25d5f4ecf4..1daadd070f 100644 --- a/aws/rust-runtime/aws-runtime/src/user_agent/interceptor.rs +++ b/aws/rust-runtime/aws-runtime/src/user_agent/interceptor.rs @@ -20,6 +20,7 @@ use aws_smithy_types::config_bag::ConfigBag; use aws_types::app_name::AppName; use aws_types::os_shim_internal::Env; +use crate::sdk_feature::AwsSdkFeature; use crate::user_agent::metrics::ProvideBusinessMetric; use crate::user_agent::{AdditionalMetadata, ApiMetadata, AwsUserAgent, InvalidMetadataValue}; @@ -138,6 +139,13 @@ impl Intercept for UserAgentInterceptor { .map(|m| ua.add_business_metric(m)); } + let aws_sdk_features = cfg.load::(); + for aws_sdk_feature in aws_sdk_features { + aws_sdk_feature + .provide_business_metric() + .map(|m| ua.add_business_metric(m)); + } + let maybe_connector_metadata = runtime_components .http_client() .and_then(|c| c.connector_metadata()); diff --git a/aws/rust-runtime/aws-runtime/src/user_agent/metrics.rs b/aws/rust-runtime/aws-runtime/src/user_agent/metrics.rs index 1acaf86fc9..be10fe7be4 100644 --- a/aws/rust-runtime/aws-runtime/src/user_agent/metrics.rs +++ b/aws/rust-runtime/aws-runtime/src/user_agent/metrics.rs @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +use crate::sdk_feature::AwsSdkFeature; use aws_smithy_runtime::client::sdk_feature::SmithySdkFeature; use once_cell::sync::Lazy; use std::borrow::Cow; @@ -155,6 +156,15 @@ impl ProvideBusinessMetric for SmithySdkFeature { } } +impl ProvideBusinessMetric for AwsSdkFeature { + fn provide_business_metric(&self) -> Option { + use AwsSdkFeature::*; + match self { + S3Transfer => Some(BusinessMetric::S3Transfer), + } + } +} + #[derive(Clone, Debug, Default)] pub(super) struct BusinessMetrics(Vec); From 78dc1d1d3ec1716ab4037391bab0f605e4f2b405 Mon Sep 17 00:00:00 2001 From: ysaito1001 Date: Tue, 26 Nov 2024 10:21:48 -0600 Subject: [PATCH 2/4] Add integration test for tracking metric for S3 TM --- .../s3/tests/business_metrics.rs | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 aws/sdk/integration-tests/s3/tests/business_metrics.rs diff --git a/aws/sdk/integration-tests/s3/tests/business_metrics.rs b/aws/sdk/integration-tests/s3/tests/business_metrics.rs new file mode 100644 index 0000000000..f044746850 --- /dev/null +++ b/aws/sdk/integration-tests/s3/tests/business_metrics.rs @@ -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"]); +} From 55f4889051e81696b81e9cf0eceeeb5fb28a52bc Mon Sep 17 00:00:00 2001 From: ysaito1001 Date: Tue, 26 Nov 2024 11:45:44 -0600 Subject: [PATCH 3/4] Update aws/rust-runtime/aws-runtime/src/sdk_feature.rs Co-authored-by: Zelda Hessler --- aws/rust-runtime/aws-runtime/src/sdk_feature.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/rust-runtime/aws-runtime/src/sdk_feature.rs b/aws/rust-runtime/aws-runtime/src/sdk_feature.rs index 9099ed12bf..a87903f316 100644 --- a/aws/rust-runtime/aws-runtime/src/sdk_feature.rs +++ b/aws/rust-runtime/aws-runtime/src/sdk_feature.rs @@ -9,7 +9,7 @@ use aws_smithy_types::config_bag::{Storable, StoreAppend}; #[non_exhaustive] #[derive(Clone, Debug, Eq, PartialEq)] pub enum AwsSdkFeature { - /// Indicates that an operation called using the S3 Transfer Manager + /// Indicates that an operation was called by the S3 Transfer Manager S3Transfer, } From 187b6718f6f0e05da3ead9713c3e5aedd8db4dd9 Mon Sep 17 00:00:00 2001 From: ysaito1001 Date: Tue, 26 Nov 2024 12:02:45 -0600 Subject: [PATCH 4/4] Add comments on hidden modules `sdk_feature`s This commit addresses https://github.com/smithy-lang/smithy-rs/pull/3921#discussion_r1858981365 --- aws/rust-runtime/Cargo.lock | 2 +- aws/rust-runtime/aws-runtime/src/lib.rs | 1 + rust-runtime/Cargo.lock | 44 +++++++++---------- rust-runtime/aws-smithy-runtime/Cargo.toml | 2 +- rust-runtime/aws-smithy-runtime/src/client.rs | 2 + 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/aws/rust-runtime/Cargo.lock b/aws/rust-runtime/Cargo.lock index 0a5a7d1629..9733b7144c 100644 --- a/aws/rust-runtime/Cargo.lock +++ b/aws/rust-runtime/Cargo.lock @@ -292,7 +292,7 @@ dependencies = [ [[package]] name = "aws-smithy-runtime" -version = "1.7.3" +version = "1.7.4" dependencies = [ "aws-smithy-async", "aws-smithy-http", diff --git a/aws/rust-runtime/aws-runtime/src/lib.rs b/aws/rust-runtime/aws-runtime/src/lib.rs index 5c2ab19646..a657a575c2 100644 --- a/aws/rust-runtime/aws-runtime/src/lib.rs +++ b/aws/rust-runtime/aws-runtime/src/lib.rs @@ -38,6 +38,7 @@ pub mod invocation_id; /// Supporting code for request metadata headers in the AWS SDK. pub mod request_info; +/// AWS SDK feature identifies. #[doc(hidden)] pub mod sdk_feature; diff --git a/rust-runtime/Cargo.lock b/rust-runtime/Cargo.lock index 4cdd6c4416..61dd0e4f22 100644 --- a/rust-runtime/Cargo.lock +++ b/rust-runtime/Cargo.lock @@ -192,7 +192,7 @@ dependencies = [ "aws-smithy-async 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "aws-smithy-eventstream 0.60.5 (registry+https://github.com/rust-lang/crates.io-index)", "aws-smithy-http 0.60.11 (registry+https://github.com/rust-lang/crates.io-index)", - "aws-smithy-runtime 1.7.3 (registry+https://github.com/rust-lang/crates.io-index)", + "aws-smithy-runtime 1.7.3", "aws-smithy-runtime-api 1.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "aws-smithy-types 1.2.9 (registry+https://github.com/rust-lang/crates.io-index)", "aws-types", @@ -221,7 +221,7 @@ dependencies = [ "aws-smithy-eventstream 0.60.5 (registry+https://github.com/rust-lang/crates.io-index)", "aws-smithy-http 0.60.11 (registry+https://github.com/rust-lang/crates.io-index)", "aws-smithy-json 0.60.7 (registry+https://github.com/rust-lang/crates.io-index)", - "aws-smithy-runtime 1.7.3 (registry+https://github.com/rust-lang/crates.io-index)", + "aws-smithy-runtime 1.7.3", "aws-smithy-runtime-api 1.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "aws-smithy-types 1.2.9 (registry+https://github.com/rust-lang/crates.io-index)", "aws-smithy-xml 0.60.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -398,7 +398,7 @@ name = "aws-smithy-experimental" version = "0.1.5" dependencies = [ "aws-smithy-async 1.2.1", - "aws-smithy-runtime 1.7.3", + "aws-smithy-runtime 1.7.4", "aws-smithy-runtime-api 1.7.3", "aws-smithy-types 1.2.9", "h2 0.4.6", @@ -612,19 +612,18 @@ dependencies = [ [[package]] name = "aws-smithy-runtime" version = "1.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be28bd063fa91fd871d131fc8b68d7cd4c5fa0869bea68daca50dcb1cbd76be2" dependencies = [ - "approx", - "aws-smithy-async 1.2.1", - "aws-smithy-http 0.60.11", - "aws-smithy-protocol-test 0.63.0", - "aws-smithy-runtime-api 1.7.3", - "aws-smithy-types 1.2.9", + "aws-smithy-async 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "aws-smithy-http 0.60.11 (registry+https://github.com/rust-lang/crates.io-index)", + "aws-smithy-protocol-test 0.63.0 (registry+https://github.com/rust-lang/crates.io-index)", + "aws-smithy-runtime-api 1.7.3 (registry+https://github.com/rust-lang/crates.io-index)", + "aws-smithy-types 1.2.9 (registry+https://github.com/rust-lang/crates.io-index)", "bytes", "fastrand", - "futures-util", "h2 0.3.26", "http 0.2.12", - "http 1.1.0", "http-body 0.4.6", "http-body 1.0.1", "httparse", @@ -634,31 +633,30 @@ dependencies = [ "once_cell", "pin-project-lite", "pin-utils", - "pretty_assertions", "rustls 0.21.12", "serde", "serde_json", "tokio", "tracing", "tracing-subscriber", - "tracing-test", ] [[package]] name = "aws-smithy-runtime" -version = "1.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be28bd063fa91fd871d131fc8b68d7cd4c5fa0869bea68daca50dcb1cbd76be2" +version = "1.7.4" dependencies = [ - "aws-smithy-async 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "aws-smithy-http 0.60.11 (registry+https://github.com/rust-lang/crates.io-index)", - "aws-smithy-protocol-test 0.63.0 (registry+https://github.com/rust-lang/crates.io-index)", - "aws-smithy-runtime-api 1.7.3 (registry+https://github.com/rust-lang/crates.io-index)", - "aws-smithy-types 1.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "approx", + "aws-smithy-async 1.2.1", + "aws-smithy-http 0.60.11", + "aws-smithy-protocol-test 0.63.0", + "aws-smithy-runtime-api 1.7.3", + "aws-smithy-types 1.2.9", "bytes", "fastrand", + "futures-util", "h2 0.3.26", "http 0.2.12", + "http 1.1.0", "http-body 0.4.6", "http-body 1.0.1", "httparse", @@ -668,12 +666,14 @@ dependencies = [ "once_cell", "pin-project-lite", "pin-utils", + "pretty_assertions", "rustls 0.21.12", "serde", "serde_json", "tokio", "tracing", "tracing-subscriber", + "tracing-test", ] [[package]] @@ -1980,7 +1980,7 @@ dependencies = [ "aws-smithy-compression", "aws-smithy-http 0.60.11", "aws-smithy-json 0.60.7", - "aws-smithy-runtime 1.7.3", + "aws-smithy-runtime 1.7.4", "aws-smithy-runtime-api 1.7.3", "aws-smithy-types 1.2.9", "aws-smithy-xml 0.60.9", diff --git a/rust-runtime/aws-smithy-runtime/Cargo.toml b/rust-runtime/aws-smithy-runtime/Cargo.toml index 56f0c33f84..d25e3c3929 100644 --- a/rust-runtime/aws-smithy-runtime/Cargo.toml +++ b/rust-runtime/aws-smithy-runtime/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aws-smithy-runtime" -version = "1.7.3" +version = "1.7.4" authors = ["AWS Rust SDK Team ", "Zelda Hessler "] description = "The new smithy runtime crate" edition = "2021" diff --git a/rust-runtime/aws-smithy-runtime/src/client.rs b/rust-runtime/aws-smithy-runtime/src/client.rs index 473df11e73..33ccc1f09f 100644 --- a/rust-runtime/aws-smithy-runtime/src/client.rs +++ b/rust-runtime/aws-smithy-runtime/src/client.rs @@ -47,7 +47,9 @@ pub mod interceptors; /// Stalled stream protection for clients pub mod stalled_stream_protection; +/// Generic Smithy SDK feature identifies. #[doc(hidden)] pub mod sdk_feature; + /// Smithy support-code for code generated waiters. pub mod waiters;