From 43a353514109fcacc9cd83d08641b50c56389602 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Tue, 19 Mar 2024 13:18:54 -0700 Subject: [PATCH 01/15] user agent changes --- include/aws/s3/private/s3_util.h | 6 ++++++ source/s3_util.c | 23 ++++++++++++++++------- tests/s3_data_plane_tests.c | 21 +++++++++++++++++---- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/include/aws/s3/private/s3_util.h b/include/aws/s3/private/s3_util.h index 2b8053044..d9c06b8a0 100644 --- a/include/aws/s3/private/s3_util.h +++ b/include/aws/s3/private/s3_util.h @@ -108,6 +108,12 @@ extern const struct aws_byte_cursor g_user_agent_header_name; AWS_S3_API extern const struct aws_byte_cursor g_user_agent_header_product_name; +AWS_S3_API +extern const struct aws_byte_cursor g_user_agent_header_platform; + +AWS_S3_API +extern const struct aws_byte_cursor g_user_agent_header_unknown; + AWS_S3_API extern const struct aws_byte_cursor g_acl_header_name; diff --git a/source/s3_util.c b/source/s3_util.c index 5eedf191e..3fd0d8c82 100644 --- a/source/s3_util.c +++ b/source/s3_util.c @@ -6,6 +6,7 @@ #include "aws/s3/private/s3_util.h" #include "aws/s3/private/s3_client_impl.h" #include "aws/s3/private/s3_meta_request_impl.h" +#include "aws/s3/private/s3_platform_info.h" #include "aws/s3/private/s3_request.h" #include #include @@ -66,6 +67,8 @@ const struct aws_byte_cursor g_delete_method = AWS_BYTE_CUR_INIT_FROM_STRING_LIT const struct aws_byte_cursor g_user_agent_header_name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("User-Agent"); const struct aws_byte_cursor g_user_agent_header_product_name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("CRTS3NativeClient"); +const struct aws_byte_cursor g_user_agent_header_platform = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("platform"); +const struct aws_byte_cursor g_user_agent_header_unknown = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("unknown"); const uint32_t g_s3_max_num_upload_parts = 10000; const size_t g_s3_min_upload_part_size = MB_TO_BYTES(5); @@ -352,9 +355,13 @@ void aws_s3_add_user_agent_header(struct aws_allocator *allocator, struct aws_ht const struct aws_byte_cursor space_delimiter = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(" "); const struct aws_byte_cursor forward_slash = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/"); - - const size_t user_agent_product_version_length = - g_user_agent_header_product_name.len + forward_slash.len + g_s3_client_version.len; + struct aws_byte_cursor platform_cursor = aws_s3_get_current_platform_info()->instance_type; + if (!platform_cursor.len) { + platform_cursor = g_user_agent_header_unknown; + } + const size_t user_agent_length = g_user_agent_header_product_name.len + forward_slash.len + + g_s3_client_version.len + space_delimiter.len + g_user_agent_header_platform.len + + forward_slash.len + platform_cursor.len; struct aws_http_headers *headers = aws_http_message_get_headers(message); AWS_ASSERT(headers != NULL); @@ -369,9 +376,7 @@ void aws_s3_add_user_agent_header(struct aws_allocator *allocator, struct aws_ht /* If the header was found, then create a buffer with the total size we'll need, and append the current user * agent header with a trailing space. */ aws_byte_buf_init( - &user_agent_buffer, - allocator, - current_user_agent_header.len + space_delimiter.len + user_agent_product_version_length); + &user_agent_buffer, allocator, current_user_agent_header.len + space_delimiter.len + user_agent_length); aws_byte_buf_append_dynamic(&user_agent_buffer, ¤t_user_agent_header); @@ -382,7 +387,7 @@ void aws_s3_add_user_agent_header(struct aws_allocator *allocator, struct aws_ht /* If the header was not found, then create a buffer with just the size of the user agent string that is about * to be appended to the buffer. */ - aws_byte_buf_init(&user_agent_buffer, allocator, user_agent_product_version_length); + aws_byte_buf_init(&user_agent_buffer, allocator, user_agent_length); } /* Append the client's user-agent string. */ @@ -390,6 +395,10 @@ void aws_s3_add_user_agent_header(struct aws_allocator *allocator, struct aws_ht aws_byte_buf_append_dynamic(&user_agent_buffer, &g_user_agent_header_product_name); aws_byte_buf_append_dynamic(&user_agent_buffer, &forward_slash); aws_byte_buf_append_dynamic(&user_agent_buffer, &g_s3_client_version); + aws_byte_buf_append_dynamic(&user_agent_buffer, &space_delimiter); + aws_byte_buf_append_dynamic(&user_agent_buffer, &g_user_agent_header_platform); + aws_byte_buf_append_dynamic(&user_agent_buffer, &forward_slash); + aws_byte_buf_append_dynamic(&user_agent_buffer, &platform_cursor); } /* Apply the updated header. */ diff --git a/tests/s3_data_plane_tests.c b/tests/s3_data_plane_tests.c index e64b75a10..8b63679ca 100644 --- a/tests/s3_data_plane_tests.c +++ b/tests/s3_data_plane_tests.c @@ -5253,12 +5253,16 @@ static int s_get_expected_user_agent(struct aws_allocator *allocator, struct aws AWS_ASSERT(dest); const struct aws_byte_cursor forward_slash = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/"); + const struct aws_byte_cursor single_space = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(" "); ASSERT_SUCCESS(aws_byte_buf_init(dest, allocator, 32)); ASSERT_SUCCESS(aws_byte_buf_append_dynamic(dest, &g_user_agent_header_product_name)); ASSERT_SUCCESS(aws_byte_buf_append_dynamic(dest, &forward_slash)); ASSERT_SUCCESS(aws_byte_buf_append_dynamic(dest, &g_s3_client_version)); - + aws_byte_buf_append_dynamic(dest, &single_space); + aws_byte_buf_append_dynamic(dest, &g_user_agent_header_platform); + ASSERT_SUCCESS(aws_byte_buf_append_dynamic(dest, &forward_slash)); + aws_byte_buf_append_dynamic(dest, &g_user_agent_header_unknown); return AWS_OP_SUCCESS; } @@ -5290,8 +5294,9 @@ static int s_test_add_user_agent_header(struct aws_allocator *allocator, void *c ASSERT_TRUE(headers != NULL); ASSERT_SUCCESS(aws_http_headers_get(headers, g_user_agent_header_name, &user_agent_value)); - ASSERT_TRUE(aws_byte_cursor_eq(&user_agent_value, &expected_user_agent_value)); - + // ASSERT_TRUE(aws_byte_cursor_eq(&user_agent_value, &expected_user_agent_value)); + ASSERT_BIN_ARRAYS_EQUALS( + user_agent_value.ptr, user_agent_value.len, expected_user_agent_value.ptr, expected_user_agent_value.len); aws_http_message_release(message); } @@ -5307,6 +5312,10 @@ static int s_test_add_user_agent_header(struct aws_allocator *allocator, void *c aws_byte_buf_append_dynamic(&total_expected_user_agent_value_buf, &g_user_agent_header_product_name); aws_byte_buf_append_dynamic(&total_expected_user_agent_value_buf, &forward_slash); aws_byte_buf_append_dynamic(&total_expected_user_agent_value_buf, &g_s3_client_version); + aws_byte_buf_append_dynamic(&total_expected_user_agent_value_buf, &single_space); + aws_byte_buf_append_dynamic(&total_expected_user_agent_value_buf, &g_user_agent_header_platform); + aws_byte_buf_append_dynamic(&total_expected_user_agent_value_buf, &forward_slash); + aws_byte_buf_append_dynamic(&total_expected_user_agent_value_buf, &g_user_agent_header_unknown); struct aws_byte_cursor total_expected_user_agent_value = aws_byte_cursor_from_buf(&total_expected_user_agent_value_buf); @@ -5323,7 +5332,11 @@ static int s_test_add_user_agent_header(struct aws_allocator *allocator, void *c struct aws_byte_cursor user_agent_value; AWS_ZERO_STRUCT(user_agent_value); ASSERT_SUCCESS(aws_http_headers_get(headers, g_user_agent_header_name, &user_agent_value)); - ASSERT_TRUE(aws_byte_cursor_eq(&user_agent_value, &total_expected_user_agent_value)); + ASSERT_BIN_ARRAYS_EQUALS( + user_agent_value.ptr, + user_agent_value.len, + total_expected_user_agent_value.ptr, + total_expected_user_agent_value.len); } aws_byte_buf_clean_up(&total_expected_user_agent_value_buf); From 6d12627aa88901afb4ec85c6cf518f04a67584e2 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Tue, 19 Mar 2024 13:32:47 -0700 Subject: [PATCH 02/15] Log at error --- source/s3_util.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/s3_util.c b/source/s3_util.c index 3fd0d8c82..f53a39ebf 100644 --- a/source/s3_util.c +++ b/source/s3_util.c @@ -401,6 +401,7 @@ void aws_s3_add_user_agent_header(struct aws_allocator *allocator, struct aws_ht aws_byte_buf_append_dynamic(&user_agent_buffer, &platform_cursor); } + AWS_LOGF_ERROR(AWS_LS_S3_META_REQUEST, "UserAgentHeader: %" PRInSTR "", AWS_BYTE_BUF_PRI(user_agent_buffer)); /* Apply the updated header. */ aws_http_headers_set(headers, g_user_agent_header_name, aws_byte_cursor_from_buf(&user_agent_buffer)); From 3e41546ac0aa17947b4ba6f1d21f2c8daab888ae Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Tue, 19 Mar 2024 13:40:13 -0700 Subject: [PATCH 03/15] fix user agent --- source/s3_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/s3_util.c b/source/s3_util.c index f53a39ebf..e7473ed37 100644 --- a/source/s3_util.c +++ b/source/s3_util.c @@ -401,7 +401,7 @@ void aws_s3_add_user_agent_header(struct aws_allocator *allocator, struct aws_ht aws_byte_buf_append_dynamic(&user_agent_buffer, &platform_cursor); } - AWS_LOGF_ERROR(AWS_LS_S3_META_REQUEST, "UserAgentHeader: %" PRInSTR "", AWS_BYTE_BUF_PRI(user_agent_buffer)); + AWS_LOGF_ERROR(AWS_LS_S3_META_REQUEST, "UserAgentHeader:" PRInSTR "\n", AWS_BYTE_BUF_PRI(user_agent_buffer)); /* Apply the updated header. */ aws_http_headers_set(headers, g_user_agent_header_name, aws_byte_cursor_from_buf(&user_agent_buffer)); From 10ccd726614fcbdb3a5d2b0a1034698f63beebdc Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Tue, 19 Mar 2024 14:10:01 -0700 Subject: [PATCH 04/15] Fix test --- source/s3_util.c | 1 - tests/s3_data_plane_tests.c | 10 +--------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/source/s3_util.c b/source/s3_util.c index e7473ed37..3fd0d8c82 100644 --- a/source/s3_util.c +++ b/source/s3_util.c @@ -401,7 +401,6 @@ void aws_s3_add_user_agent_header(struct aws_allocator *allocator, struct aws_ht aws_byte_buf_append_dynamic(&user_agent_buffer, &platform_cursor); } - AWS_LOGF_ERROR(AWS_LS_S3_META_REQUEST, "UserAgentHeader:" PRInSTR "\n", AWS_BYTE_BUF_PRI(user_agent_buffer)); /* Apply the updated header. */ aws_http_headers_set(headers, g_user_agent_header_name, aws_byte_cursor_from_buf(&user_agent_buffer)); diff --git a/tests/s3_data_plane_tests.c b/tests/s3_data_plane_tests.c index 8b63679ca..35d6475ed 100644 --- a/tests/s3_data_plane_tests.c +++ b/tests/s3_data_plane_tests.c @@ -5294,7 +5294,6 @@ static int s_test_add_user_agent_header(struct aws_allocator *allocator, void *c ASSERT_TRUE(headers != NULL); ASSERT_SUCCESS(aws_http_headers_get(headers, g_user_agent_header_name, &user_agent_value)); - // ASSERT_TRUE(aws_byte_cursor_eq(&user_agent_value, &expected_user_agent_value)); ASSERT_BIN_ARRAYS_EQUALS( user_agent_value.ptr, user_agent_value.len, expected_user_agent_value.ptr, expected_user_agent_value.len); aws_http_message_release(message); @@ -5308,14 +5307,7 @@ static int s_test_add_user_agent_header(struct aws_allocator *allocator, void *c aws_byte_buf_init(&total_expected_user_agent_value_buf, allocator, 64); aws_byte_buf_append_dynamic(&total_expected_user_agent_value_buf, &dummy_agent_header_value); aws_byte_buf_append_dynamic(&total_expected_user_agent_value_buf, &single_space); - - aws_byte_buf_append_dynamic(&total_expected_user_agent_value_buf, &g_user_agent_header_product_name); - aws_byte_buf_append_dynamic(&total_expected_user_agent_value_buf, &forward_slash); - aws_byte_buf_append_dynamic(&total_expected_user_agent_value_buf, &g_s3_client_version); - aws_byte_buf_append_dynamic(&total_expected_user_agent_value_buf, &single_space); - aws_byte_buf_append_dynamic(&total_expected_user_agent_value_buf, &g_user_agent_header_platform); - aws_byte_buf_append_dynamic(&total_expected_user_agent_value_buf, &forward_slash); - aws_byte_buf_append_dynamic(&total_expected_user_agent_value_buf, &g_user_agent_header_unknown); + aws_byte_buf_append_dynamic(&total_expected_user_agent_value_buf, &expected_user_agent_value); struct aws_byte_cursor total_expected_user_agent_value = aws_byte_cursor_from_buf(&total_expected_user_agent_value_buf); From f5fc0310788227aa79429c635e5ddde4270864f8 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Tue, 19 Mar 2024 15:18:18 -0700 Subject: [PATCH 05/15] remove unsued literal --- tests/s3_data_plane_tests.c | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/s3_data_plane_tests.c b/tests/s3_data_plane_tests.c index 35d6475ed..8a69b2932 100644 --- a/tests/s3_data_plane_tests.c +++ b/tests/s3_data_plane_tests.c @@ -5274,7 +5274,6 @@ static int s_test_add_user_agent_header(struct aws_allocator *allocator, void *c AWS_ZERO_STRUCT(tester); ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester)); - const struct aws_byte_cursor forward_slash = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/"); const struct aws_byte_cursor single_space = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(" "); struct aws_byte_buf expected_user_agent_value_buf; From d01e0c00f4edbb3dfc37fda4fba0ae790e5e9c21 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Tue, 19 Mar 2024 15:46:37 -0700 Subject: [PATCH 06/15] cached instance type api --- include/aws/s3/private/s3_platform_info.h | 3 ++- include/aws/s3/s3.h | 7 +++++++ source/s3.c | 6 +++++- source/s3_platform_info.c | 7 +++++-- source/s3_util.c | 2 +- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/include/aws/s3/private/s3_platform_info.h b/include/aws/s3/private/s3_platform_info.h index 7aceee011..f03bcc273 100644 --- a/include/aws/s3/private/s3_platform_info.h +++ b/include/aws/s3/private/s3_platform_info.h @@ -42,7 +42,8 @@ const struct aws_s3_platform_info *aws_s3_get_platform_info_for_instance_type( */ AWS_S3_API const struct aws_s3_platform_info *aws_s3_get_platform_info_for_current_environment( - struct aws_s3_platform_info_loader *loader); + struct aws_s3_platform_info_loader *loader, + bool cached_only); /* * Retrieves a list of EC2 instance types with recommended configuration. diff --git a/include/aws/s3/s3.h b/include/aws/s3/s3.h index bb187cd86..7289a8729 100644 --- a/include/aws/s3/s3.h +++ b/include/aws/s3/s3.h @@ -118,6 +118,13 @@ void aws_s3_library_clean_up(void); AWS_S3_API const struct aws_s3_platform_info *aws_s3_get_current_platform_info(void); +/* + * Returns the ec2 instance_type for current platform if already available + * NOTE: THIS API IS EXPERIMENTAL AND UNSTABLE + */ +AWS_S3_API +const struct aws_s3_platform_info *aws_s3_get_cached_current_platform_info(void); + /* * Retrieves a list of EC2 instance types with recommended configuration. * Returns aws_array_list. The caller is responsible for cleaning up the array list. diff --git a/source/s3.c b/source/s3.c index d92c017fd..647e51437 100644 --- a/source/s3.c +++ b/source/s3.c @@ -101,7 +101,11 @@ void aws_s3_library_init(struct aws_allocator *allocator) { } const struct aws_s3_platform_info *aws_s3_get_current_platform_info(void) { - return aws_s3_get_platform_info_for_current_environment(s_loader); + return aws_s3_get_platform_info_for_current_environment(s_loader, false); +} + +const struct aws_s3_platform_info *aws_s3_get_cached_current_platform_info(void) { + return aws_s3_get_platform_info_for_current_environment(s_loader, true); } struct aws_array_list aws_s3_get_platforms_with_recommended_config(void) { diff --git a/source/s3_platform_info.c b/source/s3_platform_info.c index 84e87aa80..e080a6fca 100644 --- a/source/s3_platform_info.c +++ b/source/s3_platform_info.c @@ -554,9 +554,12 @@ struct aws_byte_cursor aws_s3_get_ec2_instance_type(struct aws_s3_platform_info_ } const struct aws_s3_platform_info *aws_s3_get_platform_info_for_current_environment( - struct aws_s3_platform_info_loader *loader) { + struct aws_s3_platform_info_loader *loader, + bool cached_only) { /* getting the instance type will set it on the loader the first time if it can */ - aws_s3_get_ec2_instance_type(loader); + if (cached_only) { + aws_s3_get_ec2_instance_type(loader); + } /* will never be mutated after the above call. */ return &loader->lock_data.current_env_platform_info; } diff --git a/source/s3_util.c b/source/s3_util.c index 3fd0d8c82..ccd370884 100644 --- a/source/s3_util.c +++ b/source/s3_util.c @@ -355,7 +355,7 @@ void aws_s3_add_user_agent_header(struct aws_allocator *allocator, struct aws_ht const struct aws_byte_cursor space_delimiter = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(" "); const struct aws_byte_cursor forward_slash = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/"); - struct aws_byte_cursor platform_cursor = aws_s3_get_current_platform_info()->instance_type; + struct aws_byte_cursor platform_cursor = aws_s3_get_cached_current_platform_info()->instance_type; if (!platform_cursor.len) { platform_cursor = g_user_agent_header_unknown; } From f53abc81e9374644c99f72e7748ddcff01e402e9 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 20 Mar 2024 10:36:37 -0700 Subject: [PATCH 07/15] Log error --- source/s3_util.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/s3_util.c b/source/s3_util.c index ccd370884..39815dced 100644 --- a/source/s3_util.c +++ b/source/s3_util.c @@ -400,6 +400,7 @@ void aws_s3_add_user_agent_header(struct aws_allocator *allocator, struct aws_ht aws_byte_buf_append_dynamic(&user_agent_buffer, &forward_slash); aws_byte_buf_append_dynamic(&user_agent_buffer, &platform_cursor); } + AWS_LOGF_ERROR(AWS_LS_S3_META_REQUEST, "UserAgentHeader:" PRInSTR "\n", AWS_BYTE_BUF_PRI(user_agent_buffer)); /* Apply the updated header. */ aws_http_headers_set(headers, g_user_agent_header_name, aws_byte_cursor_from_buf(&user_agent_buffer)); From 3f402fa1462931dcfcb4f77f14d8f0f19048773a Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 20 Mar 2024 10:52:56 -0700 Subject: [PATCH 08/15] fix not of cached only --- source/s3_platform_info.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/s3_platform_info.c b/source/s3_platform_info.c index e080a6fca..a75afae88 100644 --- a/source/s3_platform_info.c +++ b/source/s3_platform_info.c @@ -557,7 +557,7 @@ const struct aws_s3_platform_info *aws_s3_get_platform_info_for_current_environm struct aws_s3_platform_info_loader *loader, bool cached_only) { /* getting the instance type will set it on the loader the first time if it can */ - if (cached_only) { + if (!cached_only) { aws_s3_get_ec2_instance_type(loader); } /* will never be mutated after the above call. */ From b7c12af386fa61c761aa6d564c0bb188b82b4ac8 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 20 Mar 2024 10:54:03 -0700 Subject: [PATCH 09/15] try caching it first --- source/s3_util.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/s3_util.c b/source/s3_util.c index 39815dced..b3bc8d1f3 100644 --- a/source/s3_util.c +++ b/source/s3_util.c @@ -355,6 +355,7 @@ void aws_s3_add_user_agent_header(struct aws_allocator *allocator, struct aws_ht const struct aws_byte_cursor space_delimiter = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(" "); const struct aws_byte_cursor forward_slash = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/"); + aws_s3_get_current_platform_info(); struct aws_byte_cursor platform_cursor = aws_s3_get_cached_current_platform_info()->instance_type; if (!platform_cursor.len) { platform_cursor = g_user_agent_header_unknown; From 989431cfcb1346f55c4f5a7fed3c09dbcdb4eb57 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 20 Mar 2024 10:54:42 -0700 Subject: [PATCH 10/15] remove temp changes --- source/s3_util.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/s3_util.c b/source/s3_util.c index b3bc8d1f3..ccd370884 100644 --- a/source/s3_util.c +++ b/source/s3_util.c @@ -355,7 +355,6 @@ void aws_s3_add_user_agent_header(struct aws_allocator *allocator, struct aws_ht const struct aws_byte_cursor space_delimiter = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(" "); const struct aws_byte_cursor forward_slash = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/"); - aws_s3_get_current_platform_info(); struct aws_byte_cursor platform_cursor = aws_s3_get_cached_current_platform_info()->instance_type; if (!platform_cursor.len) { platform_cursor = g_user_agent_header_unknown; @@ -401,7 +400,6 @@ void aws_s3_add_user_agent_header(struct aws_allocator *allocator, struct aws_ht aws_byte_buf_append_dynamic(&user_agent_buffer, &forward_slash); aws_byte_buf_append_dynamic(&user_agent_buffer, &platform_cursor); } - AWS_LOGF_ERROR(AWS_LS_S3_META_REQUEST, "UserAgentHeader:" PRInSTR "\n", AWS_BYTE_BUF_PRI(user_agent_buffer)); /* Apply the updated header. */ aws_http_headers_set(headers, g_user_agent_header_name, aws_byte_cursor_from_buf(&user_agent_buffer)); From e905cc22f87f48a626d28198f8b92a936629da44 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 20 Mar 2024 10:57:06 -0700 Subject: [PATCH 11/15] Fix tests --- tests/s3_data_plane_tests.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/s3_data_plane_tests.c b/tests/s3_data_plane_tests.c index 8a69b2932..36047a72e 100644 --- a/tests/s3_data_plane_tests.c +++ b/tests/s3_data_plane_tests.c @@ -5259,10 +5259,10 @@ static int s_get_expected_user_agent(struct aws_allocator *allocator, struct aws ASSERT_SUCCESS(aws_byte_buf_append_dynamic(dest, &g_user_agent_header_product_name)); ASSERT_SUCCESS(aws_byte_buf_append_dynamic(dest, &forward_slash)); ASSERT_SUCCESS(aws_byte_buf_append_dynamic(dest, &g_s3_client_version)); - aws_byte_buf_append_dynamic(dest, &single_space); - aws_byte_buf_append_dynamic(dest, &g_user_agent_header_platform); + ASSERT_SUCCESS(aws_byte_buf_append_dynamic(dest, &single_space)); + ASSERT_SUCCESS(aws_byte_buf_append_dynamic(dest, &g_user_agent_header_platform)); ASSERT_SUCCESS(aws_byte_buf_append_dynamic(dest, &forward_slash)); - aws_byte_buf_append_dynamic(dest, &g_user_agent_header_unknown); + ASSERT_SUCCESS(aws_byte_buf_append_dynamic(dest, &g_user_agent_header_unknown)); return AWS_OP_SUCCESS; } From e66b8ea8c6c24995040136655d21cea2d755a551 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 20 Mar 2024 10:59:06 -0700 Subject: [PATCH 12/15] add param comment --- source/s3.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/s3.c b/source/s3.c index 647e51437..92982ccce 100644 --- a/source/s3.c +++ b/source/s3.c @@ -101,11 +101,11 @@ void aws_s3_library_init(struct aws_allocator *allocator) { } const struct aws_s3_platform_info *aws_s3_get_current_platform_info(void) { - return aws_s3_get_platform_info_for_current_environment(s_loader, false); + return aws_s3_get_platform_info_for_current_environment(s_loader, false /*cached_only*/); } const struct aws_s3_platform_info *aws_s3_get_cached_current_platform_info(void) { - return aws_s3_get_platform_info_for_current_environment(s_loader, true); + return aws_s3_get_platform_info_for_current_environment(s_loader, true /*cached_only*/); } struct aws_array_list aws_s3_get_platforms_with_recommended_config(void) { From b9cb04361db2d534c4e6965a3e65555b40453b25 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Thu, 21 Mar 2024 10:35:25 -0700 Subject: [PATCH 13/15] Use instance type api with lock instead --- include/aws/s3/private/s3_platform_info.h | 5 ++--- include/aws/s3/s3.h | 4 ++-- source/s3.c | 6 +++--- source/s3_platform_info.c | 17 +++++++++++------ source/s3_util.c | 2 +- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/include/aws/s3/private/s3_platform_info.h b/include/aws/s3/private/s3_platform_info.h index f03bcc273..9e9671282 100644 --- a/include/aws/s3/private/s3_platform_info.h +++ b/include/aws/s3/private/s3_platform_info.h @@ -42,8 +42,7 @@ const struct aws_s3_platform_info *aws_s3_get_platform_info_for_instance_type( */ AWS_S3_API const struct aws_s3_platform_info *aws_s3_get_platform_info_for_current_environment( - struct aws_s3_platform_info_loader *loader, - bool cached_only); + struct aws_s3_platform_info_loader *loader); /* * Retrieves a list of EC2 instance types with recommended configuration. @@ -74,7 +73,7 @@ bool aws_s3_is_running_on_ec2_nitro(struct aws_s3_platform_info_loader *loader); * @return byte_cursor containing the instance type. If this is empty, the instance type could not be determined. */ AWS_S3_API -struct aws_byte_cursor aws_s3_get_ec2_instance_type(struct aws_s3_platform_info_loader *loader); +struct aws_byte_cursor aws_s3_get_ec2_instance_type(struct aws_s3_platform_info_loader *loader, bool cached_only); AWS_EXTERN_C_END diff --git a/include/aws/s3/s3.h b/include/aws/s3/s3.h index 7289a8729..99b897c84 100644 --- a/include/aws/s3/s3.h +++ b/include/aws/s3/s3.h @@ -119,11 +119,11 @@ AWS_S3_API const struct aws_s3_platform_info *aws_s3_get_current_platform_info(void); /* - * Returns the ec2 instance_type for current platform if already available + * Returns the ec2 instance_type for current platform if possible * NOTE: THIS API IS EXPERIMENTAL AND UNSTABLE */ AWS_S3_API -const struct aws_s3_platform_info *aws_s3_get_cached_current_platform_info(void); +struct aws_byte_cursor aws_s3_get_current_platform_ec2_intance_type(bool cached_only); /* * Retrieves a list of EC2 instance types with recommended configuration. diff --git a/source/s3.c b/source/s3.c index 92982ccce..61bc0ee3e 100644 --- a/source/s3.c +++ b/source/s3.c @@ -101,11 +101,11 @@ void aws_s3_library_init(struct aws_allocator *allocator) { } const struct aws_s3_platform_info *aws_s3_get_current_platform_info(void) { - return aws_s3_get_platform_info_for_current_environment(s_loader, false /*cached_only*/); + return aws_s3_get_platform_info_for_current_environment(s_loader); } -const struct aws_s3_platform_info *aws_s3_get_cached_current_platform_info(void) { - return aws_s3_get_platform_info_for_current_environment(s_loader, true /*cached_only*/); +struct aws_byte_cursor aws_s3_get_current_platform_ec2_intance_type(bool cached_only) { + return aws_s3_get_ec2_instance_type(s_loader, cached_only); } struct aws_array_list aws_s3_get_platforms_with_recommended_config(void) { diff --git a/source/s3_platform_info.c b/source/s3_platform_info.c index a75afae88..ad00b5c77 100644 --- a/source/s3_platform_info.c +++ b/source/s3_platform_info.c @@ -486,7 +486,7 @@ struct aws_string *s_query_imds_for_instance_type(struct aws_allocator *allocato return callback_info.instance_type; } -struct aws_byte_cursor aws_s3_get_ec2_instance_type(struct aws_s3_platform_info_loader *loader) { +struct aws_byte_cursor aws_s3_get_ec2_instance_type(struct aws_s3_platform_info_loader *loader, bool cached_only) { aws_mutex_lock(&loader->lock_data.lock); struct aws_byte_cursor return_cur; AWS_ZERO_STRUCT(return_cur); @@ -499,6 +499,14 @@ struct aws_byte_cursor aws_s3_get_ec2_instance_type(struct aws_s3_platform_info_ aws_string_bytes(loader->lock_data.detected_instance_type)); goto return_instance_and_unlock; } + if (cached_only) { + AWS_LOGF_TRACE( + AWS_LS_S3_CLIENT, + "id=%p: Instance type has not been cached. Returning without trying to determine instance type.", + (void *)loader, + aws_string_bytes(loader->lock_data.detected_instance_type)); + goto return_instance_and_unlock; + } AWS_LOGF_TRACE( AWS_LS_S3_CLIENT, @@ -554,12 +562,9 @@ struct aws_byte_cursor aws_s3_get_ec2_instance_type(struct aws_s3_platform_info_ } const struct aws_s3_platform_info *aws_s3_get_platform_info_for_current_environment( - struct aws_s3_platform_info_loader *loader, - bool cached_only) { + struct aws_s3_platform_info_loader *loader) { /* getting the instance type will set it on the loader the first time if it can */ - if (!cached_only) { - aws_s3_get_ec2_instance_type(loader); - } + aws_s3_get_ec2_instance_type(loader, false /*cached_only*/); /* will never be mutated after the above call. */ return &loader->lock_data.current_env_platform_info; } diff --git a/source/s3_util.c b/source/s3_util.c index ccd370884..ac21402a2 100644 --- a/source/s3_util.c +++ b/source/s3_util.c @@ -355,7 +355,7 @@ void aws_s3_add_user_agent_header(struct aws_allocator *allocator, struct aws_ht const struct aws_byte_cursor space_delimiter = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(" "); const struct aws_byte_cursor forward_slash = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/"); - struct aws_byte_cursor platform_cursor = aws_s3_get_cached_current_platform_info()->instance_type; + struct aws_byte_cursor platform_cursor = aws_s3_get_current_platform_ec2_intance_type(true /* cached_only */); if (!platform_cursor.len) { platform_cursor = g_user_agent_header_unknown; } From 535ef235f38656983f327bbb7686f311c389cd99 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Thu, 21 Mar 2024 10:39:07 -0700 Subject: [PATCH 14/15] Update log statement --- source/s3_platform_info.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/s3_platform_info.c b/source/s3_platform_info.c index ad00b5c77..7d9272117 100644 --- a/source/s3_platform_info.c +++ b/source/s3_platform_info.c @@ -502,7 +502,8 @@ struct aws_byte_cursor aws_s3_get_ec2_instance_type(struct aws_s3_platform_info_ if (cached_only) { AWS_LOGF_TRACE( AWS_LS_S3_CLIENT, - "id=%p: Instance type has not been cached. Returning without trying to determine instance type.", + "id=%p: Instance type has not been cached. Returning without trying to determine instance type since " + "cached_only is set.", (void *)loader, aws_string_bytes(loader->lock_data.detected_instance_type)); goto return_instance_and_unlock; From 5448eb242b6421bd1836dc7cdd687b8c7118963c Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Thu, 21 Mar 2024 10:42:22 -0700 Subject: [PATCH 15/15] fix typo --- source/s3_platform_info.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/s3_platform_info.c b/source/s3_platform_info.c index 7d9272117..05deedd9f 100644 --- a/source/s3_platform_info.c +++ b/source/s3_platform_info.c @@ -504,8 +504,7 @@ struct aws_byte_cursor aws_s3_get_ec2_instance_type(struct aws_s3_platform_info_ AWS_LS_S3_CLIENT, "id=%p: Instance type has not been cached. Returning without trying to determine instance type since " "cached_only is set.", - (void *)loader, - aws_string_bytes(loader->lock_data.detected_instance_type)); + (void *)loader); goto return_instance_and_unlock; }