Skip to content

Commit f5a8524

Browse files
committed
init
Updated S3 unit test for correct user agent updated to only include tracking for s3_express one level deeper to AWSXmlClient Updated S3 unit test for correct user agent
1 parent 41e9c4e commit f5a8524

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

src/aws-cpp-sdk-core/include/aws/core/client/UserAgent.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ enum class UserAgentFeature {
1717
S3_TRANSFER,
1818
S3_CRYPTO_V1N,
1919
S3_CRYPTO_V2,
20+
S3_EXPRESS_BUCKET,
2021
FLEXIBLE_CHECKSUMS_REQ_CRC32,
2122
FLEXIBLE_CHECKSUMS_REQ_CRC32C,
2223
FLEXIBLE_CHECKSUMS_REQ_CRC64,

src/aws-cpp-sdk-core/source/client/AWSXmlClient.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <aws/core/utils/logging/LogMacros.h>
2121
#include <aws/core/utils/event/EventStream.h>
2222
#include <aws/core/utils/UUID.h>
23+
#include <aws/core/client/UserAgent.h>
2324
#include <smithy/tracing/TracingUtils.h>
2425

2526
using namespace Aws;
@@ -53,6 +54,10 @@ XmlOutcome AWSXMLClient::MakeRequest(const Aws::AmazonWebServiceRequest& request
5354
const char* signerServiceNameOverride /* = nullptr */) const
5455
{
5556
const Aws::Http::URI& uri = endpoint.GetURI();
57+
// Add S3Express user agent feature if backend is S3Express
58+
if (endpoint.GetAttributes() && endpoint.GetAttributes()->backend == "S3Express") {
59+
request.AddUserAgentFeature(Aws::Client::UserAgentFeature::S3_EXPRESS_BUCKET);
60+
}
5661
if (endpoint.GetAttributes()) {
5762
signerName = endpoint.GetAttributes()->authScheme.GetName().c_str();
5863
if (endpoint.GetAttributes()->authScheme.GetSigningRegion()) {

src/aws-cpp-sdk-core/source/client/UserAgent.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const std::pair<UserAgentFeature, const char*> BUSINESS_METRIC_MAPPING[] = {
2727
{UserAgentFeature::S3_TRANSFER, "G"},
2828
{UserAgentFeature::S3_CRYPTO_V1N, "H"},
2929
{UserAgentFeature::S3_CRYPTO_V2, "I"},
30+
{UserAgentFeature::S3_EXPRESS_BUCKET, "J"},
3031
{UserAgentFeature::FLEXIBLE_CHECKSUMS_REQ_CRC32, "U"},
3132
{UserAgentFeature::FLEXIBLE_CHECKSUMS_REQ_CRC32C, "V"},
3233
{UserAgentFeature::FLEXIBLE_CHECKSUMS_REQ_CRC64, "W"},

tests/aws-cpp-sdk-s3-unit-tests/S3UnitTests.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,37 @@ TEST_F(S3UnitTest, PutObjectShouldHaveCorrectUserAgent) {
378378
EXPECT_TRUE(archMetadata < businessMetrics);
379379
}
380380

381+
TEST_F(S3UnitTest, PutObjectS3ExpressShouldHaveJMetric) {
382+
auto request = PutObjectRequest()
383+
.WithBucket("o-worthy-heart--usw2-az1--x-s3") // S3Express bucket pattern
384+
.WithKey("who-tempers-anxiety-into-strength");
385+
386+
std::shared_ptr<IOStream> body = Aws::MakeShared<StringStream>(ALLOCATION_TAG, "time marches on, and the age of a new king draws nearer");
387+
request.SetBody(body);
388+
389+
auto mockRequest = Aws::MakeShared<Standard::StandardHttpRequest>(ALLOCATION_TAG, "alonzo.com/faker", HttpMethod::HTTP_PUT);
390+
mockRequest->SetResponseStreamFactory([]() -> IOStream* {
391+
return Aws::New<StringStream>(ALLOCATION_TAG, "", std::ios_base::in | std::ios_base::binary);
392+
});
393+
auto mockResponse = Aws::MakeShared<Standard::StandardHttpResponse>(ALLOCATION_TAG, mockRequest);
394+
mockResponse->SetResponseCode(HttpResponseCode::OK);
395+
396+
_mockHttpClient->AddResponseToReturn(mockResponse);
397+
398+
const auto response = _s3Client->PutObject(request);
399+
400+
const auto requestSeen = _mockHttpClient->GetMostRecentHttpRequest();
401+
EXPECT_TRUE(requestSeen.HasUserAgent());
402+
const auto& userAgent = requestSeen.GetUserAgent();
403+
EXPECT_TRUE(!userAgent.empty());
404+
const auto userAgentParsed = Utils::StringUtils::Split(userAgent, ' ');
405+
406+
// Check for S3Express business metric (J) in user agent
407+
auto businessMetrics = std::find_if(userAgentParsed.begin(), userAgentParsed.end(),
408+
[](const Aws::String & value) { return value.find("m/") != Aws::String::npos && value.find("J") != Aws::String::npos; });
409+
EXPECT_TRUE(businessMetrics != userAgentParsed.end());
410+
}
411+
381412
TEST_F(S3UnitTest, RequestShouldNotIncludeAChecksumIfNotRequired) {
382413
S3ClientConfiguration configuration{};
383414
configuration.checksumConfig.requestChecksumCalculation = RequestChecksumCalculation::WHEN_REQUIRED;

0 commit comments

Comments
 (0)