-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: Create retry modules #710
Conversation
.testTarget( | ||
name: "SmithyRetriesTests", | ||
dependencies: ["ClientRuntime", "SmithyRetriesAPI", "SmithyRetries"] | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create Swift targets for SmithyRetriesAPI
and SmithyRetries
(these are both defined in SRA).
SmithyRetriesAPI
has no tests because it consists only of interfaces & types intended solely for holding data, such as configuration types.
…wift into jbe/modular_retries
- Tests/SmithyXMLTests/* | ||
- Tests/SmithyTimestampsTests/* | ||
- Tests/WeatherSDKTests/* | ||
- Tests/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to list these test exceptions to lint rules 1 by 1
@@ -5,6 +5,8 @@ | |||
// SPDX-License-Identifier: Apache-2.0 | |||
// | |||
|
|||
import struct SmithyRetriesAPI.RetryStrategyOptions | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate imports have to be added in many files for the retry types extracted into modules.
I won't comment in these files every time those are added.
static var defaultRetryStrategyOptions: RetryStrategyOptions { RetryStrategyOptions() } | ||
static var defaultRetryStrategyOptions: RetryStrategyOptions { | ||
RetryStrategyOptions(backoffStrategy: ExponentialBackoffStrategy()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since RetryStrategyOptions
(in SmithyRetriesAPI) has been split from ExponentialBackoffStrategy
(an implementation in SmithyRetries) the backoff strategy must be provided to the retry strategy options when it is created by the caller.
enum RetryError: Error { | ||
case maxAttemptsReached | ||
case insufficientQuota | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error was made public and moved to its own file in SmithyRetriesAPI
.
import enum SmithyRetriesAPI.RetryErrorType | ||
import AwsCommonRuntimeKit | ||
|
||
public extension RetryErrorType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This extension was split from the declaration of RetryErrorType
, which was placed in SmithyRetriesAPI.
This extension goes into the implementation module SmithyRetries since it is dependent on CRT.
public enum RetryError: Error { | ||
case maxAttemptsReached | ||
case insufficientQuota | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type was originally declared along with the DefaultRetryStrategy
and was internal.
Now, it's public and in the SmithyRetriesAPI module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this actually used by/part of SmithyRetriesAPI? I don't see mention of the 'quota' concept anywhere in API, but it is here (unless I've missed something). I also don't see it used anywhere, presumably its meant to be the type of error that could be thrown by refreshTokenForRetry
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, might be a good time to add some more swift docs on what each of these types are, what they do, etc. (in general, not just for RetryError
). Like RetryErrorInfo, RetryErrorType, RetryStrategy.
case .clientError: return .clientError | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This CRT-dependent extension was split off to its own file in SmithyRetries (see above.)
@@ -50,7 +50,7 @@ public struct RetryStrategyOptions { | |||
/// - availableCapacity: The number of available tokens in a retry quota. Defaults to 500. | |||
/// - maxCapacity: The max number of tokens in a retry quota. Defaults to 500. | |||
public init( | |||
backoffStrategy: RetryBackoffStrategy = ExponentialBackoffStrategy(), | |||
backoffStrategy: RetryBackoffStrategy, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ExponentialBackoffStrategy
was moved off to the implementation module, so this default value can't be set anymore - backoff strategy must be passed in when RetryStrategyOptions
is created.
Sources/WeatherSDK/models/Baz.swift
Outdated
@@ -3,7 +3,7 @@ | |||
import ClientRuntime | |||
|
|||
extension WeatherClientTypes { | |||
public struct Baz: Swift.Equatable { | |||
public struct Baz { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not commenting on individual WeatherSDK
files.
Some of the changes seen in WeatherSDK
generated code are from features prior to this PR.
@@ -8,6 +8,8 @@ | |||
import XCTest | |||
|
|||
@testable import ClientRuntime | |||
import SmithyRetriesAPI | |||
import SmithyRetries | |||
|
|||
class OrchestratorTests: XCTestCase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few changes related to the relocation of retry types.
@@ -120,8 +120,6 @@ object ClientRuntimeTypes { | |||
val SDKLogLevel = runtimeSymbol("SDKLogLevel") | |||
val ClientLogMode = runtimeSymbol("ClientLogMode") | |||
val IdempotencyTokenGenerator = runtimeSymbol("IdempotencyTokenGenerator") | |||
val DefaultRetryStrategy = runtimeSymbol("DefaultRetryStrategy") | |||
val RetryStrategyOptions = runtimeSymbol("RetryStrategyOptions") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Symbols moved to a separate file for retry module types
"https://github.com/smithy-lang/smithy-swift", | ||
Resources.computeAbsolutePath("smithy-swift", "", "SMITHY_SWIFT_CI_DIR"), | ||
"smithy-swift" | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our two new modules defined as Swift dependencies
@@ -124,6 +124,7 @@ open class HttpProtocolServiceClient( | |||
val properties: List<ConfigProperty> = ctx.integrations | |||
.flatMap { it.clientConfigurations(ctx).flatMap { it.getProperties(ctx) } } | |||
.let { overrideConfigProperties(it) } | |||
properties.forEach { writer.addImport(it.type) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making sure imports are added as needed
@@ -7,35 +7,7 @@ class ContentMd5MiddlewareTests { | |||
val context = setupTests("Isolated/contentmd5checksum.smithy", "aws.protocoltests.restxml#RestXml") | |||
val contents = getFileContents(context.manifest, "/RestXml/RestXmlProtocolClient.swift") | |||
val expectedContents = """ | |||
public func idempotencyTokenWithStructure(input: IdempotencyTokenWithStructureInput) async throws -> IdempotencyTokenWithStructureOutput { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is ridiculously overbroad for "generates ContentMD5 middleware" so I cut out the expected Swift code unrelated to that test assertion.
import software.amazon.smithy.swift.codegen.SwiftWriter | ||
import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator | ||
import software.amazon.smithy.swift.codegen.integration.middlewares.handlers.MiddlewareShapeUtils | ||
import software.amazon.smithy.swift.codegen.middleware.MiddlewarePosition | ||
import software.amazon.smithy.swift.codegen.middleware.MiddlewareRenderable | ||
import software.amazon.smithy.swift.codegen.middleware.MiddlewareStep | ||
import software.amazon.smithy.swift.codegen.swiftmodules.SmithyRetriesTypes | ||
|
||
class RetryMiddleware( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjust imports and a little code cleanup.
@@ -6,34 +6,7 @@ class IdempotencyTokenTraitTests { | |||
val context = setupTests("Isolated/idempotencyToken.smithy", "aws.protocoltests.restxml#RestXml") | |||
val contents = getFileContents(context.manifest, "/RestXml/RestXmlProtocolClient.swift") | |||
val expectedContents = """ | |||
public func idempotencyTokenWithStructure(input: IdempotencyTokenWithStructureInput) async throws -> IdempotencyTokenWithStructureOutput { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like the test above, the expectation is way way broader than "generates idempotent middleware".
public enum RetryError: Error { | ||
case maxAttemptsReached | ||
case insufficientQuota | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this actually used by/part of SmithyRetriesAPI? I don't see mention of the 'quota' concept anywhere in API, but it is here (unless I've missed something). I also don't see it used anywhere, presumably its meant to be the type of error that could be thrown by refreshTokenForRetry
?
public enum RetryError: Error { | ||
case maxAttemptsReached | ||
case insufficientQuota | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, might be a good time to add some more swift docs on what each of these types are, what they do, etc. (in general, not just for RetryError
). Like RetryErrorInfo, RetryErrorType, RetryStrategy.
smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/ClientRuntimeTypes.kt
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably would add a lot of noise to this PR, but in the future maybe we consider moving ClientRuntimeTypes into swiftmodules
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. I have many more of these modularization PRs to tackle, I can do it in a future one.
Agreed. Also no matter where these go, if these errors are public they should have doc comments. I'll add them. |
@milesziemer Per discussion above:
(Also: fixed a couple unrelated build warnings) Please re-review. |
…ddleware to not force-unwrap
Issue #
awslabs/aws-sdk-swift#1386
Description of changes
SmithyRetriesAPI
module created with retry-related protocols and data typesSmithyRetries
module created with default implementations for retry-related typesWeatherSDK
generated code updated to use modular retryScope
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.