Skip to content

Commit

Permalink
Add business metric feature ID tracking for flexible checksum v2.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sichan Yoo committed Nov 8, 2024
1 parent 3aa8ac0 commit 5eb46b3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public struct FlexibleChecksumsRequestMiddleware<OperationStackInput, OperationS
}
}

// Save resolved ChecksumAlgorithm to interceptor context.
attributes.checksum = checksumHashFunction

// Determine the header name
let headerName = "x-amz-checksum-\(checksumHashFunction)"
logger.debug("Resolved checksum header name: \(headerName)")
Expand All @@ -85,7 +88,6 @@ public struct FlexibleChecksumsRequestMiddleware<OperationStackInput, OperationS
case .stream(let stream):
if stream.isEligibleForChunkedStreaming {
// Handle calculating and adding checksum header in ChunkedStream
attributes.checksum = checksumHashFunction
builder.updateHeader(name: "x-amz-trailer", value: [headerName])
} else {
// If not eligible for chunked streaming, calculate and add checksum to request header now
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import ClientRuntime
import class Smithy.Context
import enum AWSSDKChecksums.AWSChecksumCalculationMode

public struct AWSUserAgentMetadata {
let sdkMetadata: SDKMetadata
Expand Down Expand Up @@ -103,16 +104,28 @@ public class UserAgentValuesFromConfig {
var appID: String?
var endpoint: String?
var awsRetryMode: AWSRetryMode
var requestChecksumCalculation: AWSChecksumCalculationMode
var responseChecksumValidation: AWSChecksumCalculationMode

public init(appID: String?, endpoint: String?, awsRetryMode: AWSRetryMode) {
public init(
appID: String?,
endpoint: String?,
awsRetryMode: AWSRetryMode,
requestChecksumCalculation: AWSChecksumCalculationMode,
responseChecksumValidation: AWSChecksumCalculationMode
) {
self.endpoint = endpoint
self.awsRetryMode = awsRetryMode
self.appID = appID
self.requestChecksumCalculation = requestChecksumCalculation
self.responseChecksumValidation = responseChecksumValidation
}

public init(config: DefaultClientConfiguration & AWSDefaultClientConfiguration) {
self.appID = config.appID
self.endpoint = config.endpoint
self.awsRetryMode = config.awsRetryMode
self.requestChecksumCalculation = config.requestChecksumCalculation
self.responseChecksumValidation = config.responseChecksumValidation
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,34 +59,10 @@ public extension Context {

public let businessMetricsKey = AttributeKey<Dictionary<String, String>>(name: "BusinessMetrics")

/* List of readable "feature ID" to "metric value"; last updated on 08/19/2024
[Feature ID] [Metric Value] [Flag Supported]
"RESOURCE_MODEL" : "A" :
"WAITER" : "B" :
"PAGINATOR" : "C" :
"RETRY_MODE_LEGACY" : "D" : Y
"RETRY_MODE_STANDARD" : "E" : Y
"RETRY_MODE_ADAPTIVE" : "F" : Y
"S3_TRANSFER" : "G" :
"S3_CRYPTO_V1N" : "H" :
"S3_CRYPTO_V2" : "I" :
"S3_EXPRESS_BUCKET" : "J" :
"S3_ACCESS_GRANTS" : "K" :
"GZIP_REQUEST_COMPRESSION" : "L" :
"PROTOCOL_RPC_V2_CBOR" : "M" :
"ENDPOINT_OVERRIDE" : "N" : Y
"ACCOUNT_ID_ENDPOINT" : "O" :
"ACCOUNT_ID_MODE_PREFERRED" : "P" :
"ACCOUNT_ID_MODE_DISABLED" : "Q" :
"ACCOUNT_ID_MODE_REQUIRED" : "R" :
"SIGV4A_SIGNING" : "S" : Y
"RESOLVED_ACCOUNT_ID" : "T" :
*/
private func setFlagsIntoContext(
config: UserAgentValuesFromConfig,
context: Context
) {
// Handle D, E, F
switch config.awsRetryMode {
case .legacy:
context.businessMetrics = ["RETRY_MODE_LEGACY": "D"]
Expand All @@ -95,12 +71,34 @@ private func setFlagsIntoContext(
case .adaptive:
context.businessMetrics = ["RETRY_MODE_ADAPTIVE": "F"]
}
// Handle N
if let endpoint = config.endpoint, !endpoint.isEmpty {
context.businessMetrics = ["ENDPOINT_OVERRIDE": "N"]
}
// Handle S
if context.selectedAuthScheme?.schemeID == "aws.auth#sigv4a" {
context.businessMetrics = ["SIGV4A_SIGNING": "S"]
}
switch context.checksum {
case .crc32:
context.businessMetrics = ["FLEXIBLE_CHECKSUMS_REQ_CRC32": "U"]
case .crc32c:
context.businessMetrics = ["FLEXIBLE_CHECKSUMS_REQ_CRC32C": "V"]
case .crc64nvme:
context.businessMetrics = ["FLEXIBLE_CHECKSUMS_REQ_CRC64": "W"]
case .sha1:
context.businessMetrics = ["FLEXIBLE_CHECKSUMS_REQ_SHA1": "X"]
case .sha256:
context.businessMetrics = ["FLEXIBLE_CHECKSUMS_REQ_SHA256": "Y"]
default:
break
}
if config.requestChecksumCalculation == .whenSupported {
context.businessMetrics = ["FLEXIBLE_CHECKSUMS_REQ_WHEN_SUPPORTED": "Z"]
} else {
context.businessMetrics = ["FLEXIBLE_CHECKSUMS_REQ_WHEN_REQUIRED": "a"]
}
if config.responseChecksumValidation == .whenSupported {
context.businessMetrics = ["FLEXIBLE_CHECKSUMS_RES_WHEN_SUPPORTED": "b"]
} else {
context.businessMetrics = ["FLEXIBLE_CHECKSUMS_RES_WHEN_REQUIRED": "c"]
}
}

0 comments on commit 5eb46b3

Please sign in to comment.