Skip to content

Commit dbb22c0

Browse files
jonathan343sbiscigl
authored andcommitted
Fix flexible checksum business metrics in the User-Agent
- Report FLEXIBLE_CHECKSUMS_REQ_CRC32 instead of _CRC32C for a provided CRC32 checksum, and match "crc64nvme" so a provided CRC64NVME checksum reports FLEXIBLE_CHECKSUMS_REQ_CRC64. - Correct the metric values of SHA512, XXHASH3, XXHASH64, and XXHASH128 (AF, AG, AH, AI). They were shifted by one. - Add an S3 unit test that checks the metric for every algorithm, for both calculated and provided checksums.
1 parent 97111b0 commit dbb22c0

4 files changed

Lines changed: 79 additions & 6 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "aws-cpp-sdk-core",
4+
"contributor": "jonathan343",
5+
"description": "Fix the flexible checksum business metrics reported in the User-Agent. CRC32 was reported as CRC32C, CRC64NVME was never reported, and the SHA512, XXHASH3, XXHASH64 and XXHASH128 metric IDs were wrong."
6+
}

‎src/aws-cpp-sdk-core/include/smithy/client/features/ChecksumInterceptor.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ class ChecksumInterceptor : public smithy::interceptor::Interceptor {
151151
private:
152152
void addChecksumFeatureForChecksumName(const Aws::String& checksumName, const Aws::AmazonWebServiceRequest& request) {
153153
if (checksumName == "crc32") {
154-
request.AddUserAgentFeature(Aws::Client::UserAgentFeature::FLEXIBLE_CHECKSUMS_REQ_CRC32C);
154+
request.AddUserAgentFeature(Aws::Client::UserAgentFeature::FLEXIBLE_CHECKSUMS_REQ_CRC32);
155155
} else if (checksumName == "crc32c") {
156156
request.AddUserAgentFeature(Aws::Client::UserAgentFeature::FLEXIBLE_CHECKSUMS_REQ_CRC32C);
157-
} else if (checksumName == "crc64") {
157+
} else if (checksumName == "crc64nvme") {
158158
request.AddUserAgentFeature(Aws::Client::UserAgentFeature::FLEXIBLE_CHECKSUMS_REQ_CRC64);
159159
} else if (checksumName == "sha1") {
160160
request.AddUserAgentFeature(Aws::Client::UserAgentFeature::FLEXIBLE_CHECKSUMS_REQ_SHA1);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ const std::pair<UserAgentFeature, const char*> BUSINESS_METRIC_MAPPING[] = {
5555
{UserAgentFeature::CREDENTIALS_LOGIN, "AD"},
5656
{UserAgentFeature::PROTOCOL_RPC_V2_CBOR, "M"},
5757
{UserAgentFeature::BEARER_SERVICE_ENV_VARS, "3"},
58-
{UserAgentFeature::FLEXIBLE_CHECKSUMS_REQ_SHA512, "AE"},
59-
{UserAgentFeature::FLEXIBLE_CHECKSUMS_REQ_XXHASH64, "AG"},
60-
{UserAgentFeature::FLEXIBLE_CHECKSUMS_REQ_XXHASH3, "AF"},
61-
{UserAgentFeature::FLEXIBLE_CHECKSUMS_REQ_XXHASH128, "AH"},
58+
{UserAgentFeature::FLEXIBLE_CHECKSUMS_REQ_SHA512, "AF"},
59+
{UserAgentFeature::FLEXIBLE_CHECKSUMS_REQ_XXHASH64, "AH"},
60+
{UserAgentFeature::FLEXIBLE_CHECKSUMS_REQ_XXHASH3, "AG"},
61+
{UserAgentFeature::FLEXIBLE_CHECKSUMS_REQ_XXHASH128, "AI"},
6262
{UserAgentFeature::PAGINATOR, "C"},
6363
{UserAgentFeature::WAITER, "B"},
6464
};

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
#include <aws/testing/AwsTestHelpers.h>
2121
#include <aws/testing/MemoryTesting.h>
2222
#include <aws/testing/mocks/http/MockHttpClient.h>
23+
#include <aws/testing/utils/UserAgentUtils.h>
2324
#include <gtest/gtest.h>
2425

26+
#include <functional>
2527
#include <memory>
2628

2729
using namespace Aws;
@@ -441,6 +443,71 @@ TEST_F(S3UnitTest, PutObjectShouldHaveCorrectUserAgent) {
441443
EXPECT_TRUE(archMetadata < businessMetrics);
442444
}
443445

446+
namespace {
447+
struct ChecksumFeatureTestCase {
448+
ChecksumAlgorithm algorithm;
449+
std::function<void(PutObjectRequest&)> setChecksum;
450+
Aws::String metric;
451+
};
452+
} // namespace
453+
454+
TEST_F(S3UnitTest, PutObjectShouldTrackChecksumAlgorithmFeature) {
455+
// FLEXIBLE_CHECKSUMS_REQ_* metric values, from the AWS SDK business metrics registry.
456+
const Aws::Vector<ChecksumFeatureTestCase> testCases{
457+
{ChecksumAlgorithm::CRC32, [](PutObjectRequest& r) { r.SetChecksumCRC32("Y2hlY2tzdW0="); }, "U"},
458+
{ChecksumAlgorithm::CRC32C, [](PutObjectRequest& r) { r.SetChecksumCRC32C("Y2hlY2tzdW0="); }, "V"},
459+
{ChecksumAlgorithm::CRC64NVME, [](PutObjectRequest& r) { r.SetChecksumCRC64NVME("Y2hlY2tzdW0="); }, "W"},
460+
{ChecksumAlgorithm::SHA1, [](PutObjectRequest& r) { r.SetChecksumSHA1("Y2hlY2tzdW0="); }, "X"},
461+
{ChecksumAlgorithm::SHA256, [](PutObjectRequest& r) { r.SetChecksumSHA256("Y2hlY2tzdW0="); }, "Y"},
462+
{ChecksumAlgorithm::SHA512, [](PutObjectRequest& r) { r.SetChecksumSHA512("Y2hlY2tzdW0="); }, "AF"},
463+
{ChecksumAlgorithm::XXHASH3, [](PutObjectRequest& r) { r.SetChecksumXXHASH3("Y2hlY2tzdW0="); }, "AG"},
464+
{ChecksumAlgorithm::XXHASH64, [](PutObjectRequest& r) { r.SetChecksumXXHASH64("Y2hlY2tzdW0="); }, "AH"},
465+
{ChecksumAlgorithm::XXHASH128, [](PutObjectRequest& r) { r.SetChecksumXXHASH128("Y2hlY2tzdW0="); }, "AI"},
466+
};
467+
Aws::Vector<Aws::String> allMetrics;
468+
for (const auto& testCase : testCases) {
469+
allMetrics.push_back(testCase.metric);
470+
}
471+
472+
for (const auto& testCase : testCases) {
473+
// The SDK either calculates the checksum, or sends the one set on the request.
474+
for (const bool provided : {false, true}) {
475+
SCOPED_TRACE(Aws::String(ChecksumAlgorithmMapper::GetNameForChecksumAlgorithm(testCase.algorithm)) +
476+
(provided ? " provided" : " calculated"));
477+
// The mock client is shared by the suite, so start each case clean.
478+
_mockHttpClient->Reset();
479+
auto request = PutObjectRequest()
480+
.WithBucket("big-boss")
481+
.WithKey("snake-eater")
482+
.WithChecksumAlgorithm(testCase.algorithm);
483+
if (provided) {
484+
testCase.setChecksum(request);
485+
}
486+
std::shared_ptr<IOStream> body = Aws::MakeShared<StringStream>(ALLOCATION_TAG, "phantom pain");
487+
request.SetBody(body);
488+
489+
auto mockRequest = Aws::MakeShared<Standard::StandardHttpRequest>(ALLOCATION_TAG, "outer.heaven/mother-base", HttpMethod::HTTP_PUT);
490+
mockRequest->SetResponseStreamFactory([]() -> IOStream* {
491+
return Aws::New<StringStream>(ALLOCATION_TAG, "", std::ios_base::in | std::ios_base::binary);
492+
});
493+
auto mockResponse = Aws::MakeShared<Standard::StandardHttpResponse>(ALLOCATION_TAG, mockRequest);
494+
mockResponse->SetResponseCode(HttpResponseCode::OK);
495+
_mockHttpClient->AddResponseToReturn(mockResponse);
496+
497+
const auto response = _s3Client->PutObject(request);
498+
EXPECT_TRUE(response.IsSuccess());
499+
ASSERT_EQ(1u, _mockHttpClient->GetAllRequestsMade().size());
500+
501+
// Exactly one checksum algorithm metric is reported, and it's the right one.
502+
const auto metrics = GetFeaturesForRequest(_mockHttpClient->GetMostRecentHttpRequest());
503+
for (const auto& metric : allMetrics) {
504+
const bool reported = std::find(metrics.begin(), metrics.end(), metric) != metrics.end();
505+
EXPECT_EQ(metric == testCase.metric, reported) << "metric " << metric;
506+
}
507+
}
508+
}
509+
}
510+
444511
TEST_F(S3UnitTest, PutObjectShouldOverrideUserAgent) {
445512
auto request = PutObjectRequest()
446513
.WithBucket("ocelot")

0 commit comments

Comments
 (0)