Skip to content

Commit

Permalink
Merge branch 'main' into day/document-type
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelkins committed Sep 13, 2024
2 parents 8aafd4a + 517490d commit bf60eb2
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,30 @@ public class AWSClientConfigDefaultsProvider {
return resolvedRetryMode!
}

public static func retryStrategyOptions() throws -> RetryStrategyOptions {
private static func maxAttempts(_ maxAttempts: Int? = nil) throws -> Int {
let fileBasedConfig = try CRTFileBasedConfiguration.make()
let resolvedMaxAttempts = AWSRetryConfig.maxAttempts(
configValue: nil,
profileName: nil,
fileBasedConfig: fileBasedConfig
)
let resolvedMaxAttempts: Int?
if let maxAttempts {
resolvedMaxAttempts = maxAttempts
} else {
resolvedMaxAttempts = AWSRetryConfig.maxAttempts(
configValue: nil,
profileName: nil,
fileBasedConfig: fileBasedConfig
)
}
return resolvedMaxAttempts!
}

public static func retryStrategyOptions(
_ retryMode: AWSRetryMode? = nil,
_ maxAttempts: Int? = nil
) throws -> RetryStrategyOptions {
let resolvedMaxAttempts = try self.maxAttempts(maxAttempts)

let resolvedRateLimitingMode: RetryStrategyOptions.RateLimitingMode

switch try self.retryMode(nil) {
switch try self.retryMode(retryMode) {
case .legacy, .standard:
resolvedRateLimitingMode = .standard
case .adaptive:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,19 @@ public protocol AWSDefaultClientConfiguration {

/// The AWS retry mode to be used.
///
/// This value is set after resolving retry mode from the standard progression of potential sources.
/// May be one of `legacy`, `standard`, or `adaptive`.
/// For the Swift SDK, `legacy` is the same behavior as `standard`.
/// `standard` and `adaptive` retry strategies are as documented in `AWSClientRuntime.AWSRetryMode`.
///
/// May be one of `legacy`, `standard`, or `adaptive`. `standard` and `adaptive` retry strategies are as defined in
/// Smithy Reference Architecture. For the Swift SDK, `legacy` is the same behavior as `standard`.
/// This value is set after resolving retry mode from the standard progression of potential sources.
/// Default mode is `legacy`.
var awsRetryMode: AWSRetryMode { get set }

/// The max number of times to attempt the request until success.
///
/// This number includes the initial request, and the number of subsequent retries.
/// For example, value of 3 for this config variable would mean maximum of 2 retries.
///
/// If set, this value gets used when resolving max attempts value from the standard progression of potential sources. If no value could be resolved, the SDK uses max attempts value of 3 by default.
var maxAttempts: Int? { get set }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ public class DefaultAWSClientPlugin: Plugin {
}

public func configureClient(clientConfiguration: ClientConfiguration) throws {
if var config = clientConfiguration as? DefaultClientConfiguration
if var config = clientConfiguration as? (DefaultClientConfiguration
& AWSDefaultClientConfiguration
& AWSRegionClientConfiguration {
config.retryStrategyOptions = try AWSClientConfigDefaultsProvider.retryStrategyOptions()
& AWSRegionClientConfiguration) {
config.retryStrategyOptions = try AWSClientConfigDefaultsProvider.retryStrategyOptions(
config.awsRetryMode,
config.maxAttempts
)
config.awsCredentialIdentityResolver = try AWSClientConfigDefaultsProvider.awsCredentialIdentityResolver()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class AWSHttpProtocolServiceClient(
ConfigProperty(
"retryStrategyOptions",
SmithyRetriesAPITypes.RetryStrategyOptions,
{ it.format("AWSClientConfigDefaultsProvider.retryStrategyOptions()") },
{ it.format("AWSClientConfigDefaultsProvider.retryStrategyOptions(awsRetryMode, maxAttempts)") },
true
)
}
Expand Down Expand Up @@ -123,6 +123,9 @@ class AWSHttpProtocolServiceClient(
"awsCredentialIdentityResolver" -> {
"try AWSClientConfigDefaultsProvider.awsCredentialIdentityResolver()"
}
"retryStrategyOptions" -> {
"try AWSClientConfigDefaultsProvider.retryStrategyOptions()"
}
else -> {
it.default?.render(writer) ?: "nil"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ class AWSDefaultClientConfiguration : ClientConfiguration {
{ it.format("\$N.retryMode()", AWSClientRuntimeTypes.Core.AWSClientConfigDefaultsProvider) },
true
),
ConfigProperty("maxAttempts", SwiftTypes.Int.toOptional())
)
}
Loading

0 comments on commit bf60eb2

Please sign in to comment.