Skip to content

Commit 517490d

Browse files
sichanyooSichan Yoo
andauthored
fix!: Retry config (#1744)
* Add maxAttempts retry config back to AWS config; update doc comments. * Add maxAttempts retry config property in AWS config to codegen side. * Fix AWS config defaults provider so that top level config values from user for awsRetryMode and maxAttempts actually get used when resolving retryStrategyOptions. * Update config plugin to actually use top level retry config values set by user when constructing retry strategy options. * Update default provider calling site for retry strategy options in codegen. * Update codegen test. --------- Co-authored-by: Sichan Yoo <[email protected]>
1 parent 629d1c7 commit 517490d

File tree

6 files changed

+54
-21
lines changed

6 files changed

+54
-21
lines changed

Sources/Core/AWSClientRuntime/Sources/AWSClientRuntime/AWSClientConfigDefaultsProvider.swift

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,30 @@ public class AWSClientConfigDefaultsProvider {
9999
return resolvedRetryMode!
100100
}
101101

102-
public static func retryStrategyOptions() throws -> RetryStrategyOptions {
102+
private static func maxAttempts(_ maxAttempts: Int? = nil) throws -> Int {
103103
let fileBasedConfig = try CRTFileBasedConfiguration.make()
104-
let resolvedMaxAttempts = AWSRetryConfig.maxAttempts(
105-
configValue: nil,
106-
profileName: nil,
107-
fileBasedConfig: fileBasedConfig
108-
)
104+
let resolvedMaxAttempts: Int?
105+
if let maxAttempts {
106+
resolvedMaxAttempts = maxAttempts
107+
} else {
108+
resolvedMaxAttempts = AWSRetryConfig.maxAttempts(
109+
configValue: nil,
110+
profileName: nil,
111+
fileBasedConfig: fileBasedConfig
112+
)
113+
}
114+
return resolvedMaxAttempts!
115+
}
116+
117+
public static func retryStrategyOptions(
118+
_ retryMode: AWSRetryMode? = nil,
119+
_ maxAttempts: Int? = nil
120+
) throws -> RetryStrategyOptions {
121+
let resolvedMaxAttempts = try self.maxAttempts(maxAttempts)
109122

110123
let resolvedRateLimitingMode: RetryStrategyOptions.RateLimitingMode
111124

112-
switch try self.retryMode(nil) {
125+
switch try self.retryMode(retryMode) {
113126
case .legacy, .standard:
114127
resolvedRateLimitingMode = .standard
115128
case .adaptive:

Sources/Core/AWSClientRuntime/Sources/AWSClientRuntime/Config/AWSDefaultClientConfiguration.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,19 @@ public protocol AWSDefaultClientConfiguration {
3131

3232
/// The AWS retry mode to be used.
3333
///
34-
/// This value is set after resolving retry mode from the standard progression of potential sources.
34+
/// May be one of `legacy`, `standard`, or `adaptive`.
35+
/// For the Swift SDK, `legacy` is the same behavior as `standard`.
36+
/// `standard` and `adaptive` retry strategies are as documented in `AWSClientRuntime.AWSRetryMode`.
3537
///
36-
/// May be one of `legacy`, `standard`, or `adaptive`. `standard` and `adaptive` retry strategies are as defined in
37-
/// Smithy Reference Architecture. For the Swift SDK, `legacy` is the same behavior as `standard`.
38+
/// This value is set after resolving retry mode from the standard progression of potential sources.
39+
/// Default mode is `legacy`.
3840
var awsRetryMode: AWSRetryMode { get set }
41+
42+
/// The max number of times to attempt the request until success.
43+
///
44+
/// This number includes the initial request, and the number of subsequent retries.
45+
/// For example, value of 3 for this config variable would mean maximum of 2 retries.
46+
///
47+
/// 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.
48+
var maxAttempts: Int? { get set }
3949
}

Sources/Core/AWSClientRuntime/Sources/AWSClientRuntime/Plugins/DefaultAWSClientPlugin.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ public class DefaultAWSClientPlugin: Plugin {
1515
}
1616

1717
public func configureClient(clientConfiguration: ClientConfiguration) throws {
18-
if var config = clientConfiguration as? DefaultClientConfiguration
18+
if var config = clientConfiguration as? (DefaultClientConfiguration
1919
& AWSDefaultClientConfiguration
20-
& AWSRegionClientConfiguration {
21-
config.retryStrategyOptions = try AWSClientConfigDefaultsProvider.retryStrategyOptions()
20+
& AWSRegionClientConfiguration) {
21+
config.retryStrategyOptions = try AWSClientConfigDefaultsProvider.retryStrategyOptions(
22+
config.awsRetryMode,
23+
config.maxAttempts
24+
)
2225
config.awsCredentialIdentityResolver = try AWSClientConfigDefaultsProvider.awsCredentialIdentityResolver()
2326
}
2427
}

codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/AWSHttpProtocolServiceClient.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class AWSHttpProtocolServiceClient(
6767
ConfigProperty(
6868
"retryStrategyOptions",
6969
SmithyRetriesAPITypes.RetryStrategyOptions,
70-
{ it.format("AWSClientConfigDefaultsProvider.retryStrategyOptions()") },
70+
{ it.format("AWSClientConfigDefaultsProvider.retryStrategyOptions(awsRetryMode, maxAttempts)") },
7171
true
7272
)
7373
}
@@ -123,6 +123,9 @@ class AWSHttpProtocolServiceClient(
123123
"awsCredentialIdentityResolver" -> {
124124
"try AWSClientConfigDefaultsProvider.awsCredentialIdentityResolver()"
125125
}
126+
"retryStrategyOptions" -> {
127+
"try AWSClientConfigDefaultsProvider.retryStrategyOptions()"
128+
}
126129
else -> {
127130
it.default?.render(writer) ?: "nil"
128131
}

codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/config/AWSDefaultClientConfiguration.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ class AWSDefaultClientConfiguration : ClientConfiguration {
3939
{ it.format("\$N.retryMode()", AWSClientRuntimeTypes.Core.AWSClientConfigDefaultsProvider) },
4040
true
4141
),
42+
ConfigProperty("maxAttempts", SwiftTypes.Int.toOptional())
4243
)
4344
}

0 commit comments

Comments
 (0)