-
Notifications
You must be signed in to change notification settings - Fork 31
Implement updated standard retry behavior #733
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
Open
Alan4506
wants to merge
2
commits into
smithy-lang:develop
Choose a base branch
from
Alan4506:retries-2.1-sep-update-v2
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
.../src/main/java/software/amazon/smithy/python/aws/codegen/AwsDynamoDbRetryIntegration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package software.amazon.smithy.python.aws.codegen; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Set; | ||
| import software.amazon.smithy.aws.traits.ServiceTrait; | ||
| import software.amazon.smithy.python.codegen.GenerationContext; | ||
| import software.amazon.smithy.python.codegen.RuntimeTypes; | ||
| import software.amazon.smithy.python.codegen.integrations.PythonIntegration; | ||
| import software.amazon.smithy.python.codegen.sections.InitRetryStrategyResolverSection; | ||
| import software.amazon.smithy.python.codegen.writer.PythonWriter; | ||
| import software.amazon.smithy.utils.CodeInterceptor; | ||
| import software.amazon.smithy.utils.CodeSection; | ||
|
|
||
| /** | ||
| * Injects DynamoDB's default retry options (max attempts 4, 25ms non-throttling | ||
| * base backoff). | ||
| */ | ||
| public final class AwsDynamoDbRetryIntegration implements PythonIntegration { | ||
|
|
||
| private static final Set<String> DYNAMODB_SDK_IDS = Set.of("DynamoDB", "DynamoDB Streams"); | ||
|
|
||
| private static final double DYNAMODB_BASE_BACKOFF_SECONDS = 0.025; | ||
| private static final int DYNAMODB_MAX_ATTEMPTS = 4; | ||
|
|
||
| private static boolean isDynamoDb(GenerationContext context) { | ||
| return context.settings() | ||
| .service(context.model()) | ||
| .getTrait(ServiceTrait.class) | ||
| .map(trait -> DYNAMODB_SDK_IDS.contains(trait.getSdkId())) | ||
| .orElse(false); | ||
| } | ||
|
|
||
| @Override | ||
| public List<? extends CodeInterceptor<? extends CodeSection, PythonWriter>> interceptors( | ||
| GenerationContext context | ||
| ) { | ||
| if (!isDynamoDb(context)) { | ||
| return List.of(); | ||
| } | ||
| return List.of(new DynamoDbRetryStrategyResolverInterceptor()); | ||
| } | ||
|
|
||
| private static final class DynamoDbRetryStrategyResolverInterceptor | ||
| implements CodeInterceptor<InitRetryStrategyResolverSection, PythonWriter> { | ||
|
|
||
| @Override | ||
| public Class<InitRetryStrategyResolverSection> sectionType() { | ||
| return InitRetryStrategyResolverSection.class; | ||
| } | ||
|
|
||
| @Override | ||
| public void write(PythonWriter writer, String previousText, InitRetryStrategyResolverSection section) { | ||
| writer.write( | ||
| "self._retry_strategy_resolver = $T(default_max_attempts=$L, default_backoff_scale=$L)", | ||
| RuntimeTypes.RETRY_STRATEGY_RESOLVER, | ||
| DYNAMODB_MAX_ATTEMPTS, | ||
| DYNAMODB_BASE_BACKOFF_SECONDS); | ||
| } | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions
45
...re/src/main/java/software/amazon/smithy/python/aws/codegen/AwsLongPollingIntegration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package software.amazon.smithy.python.aws.codegen; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import software.amazon.smithy.aws.traits.ServiceTrait; | ||
| import software.amazon.smithy.model.Model; | ||
| import software.amazon.smithy.model.shapes.OperationShape; | ||
| import software.amazon.smithy.model.shapes.ServiceShape; | ||
| import software.amazon.smithy.model.traits.LongPollTrait; | ||
| import software.amazon.smithy.python.codegen.integrations.PythonIntegration; | ||
|
|
||
| /** | ||
| * Marks long-polling operations so the generic client generator applies | ||
| * long-polling retry behavior to them. | ||
| * | ||
| * <p>An operation is long-polling if it carries the {@code smithy.api#longPoll} | ||
| * trait. Service models do not yet apply the trait, so the known operations are | ||
| * hard-coded as a fallback. Once the trait ships in the models, the fallback | ||
| * can be removed. | ||
| */ | ||
| public final class AwsLongPollingIntegration implements PythonIntegration { | ||
|
|
||
| private static final Map<String, Set<String>> LONG_POLLING_OPERATIONS = Map.of( | ||
| "SQS", | ||
| Set.of("ReceiveMessage"), | ||
| "SFN", | ||
| Set.of("GetActivityTask"), | ||
| "SWF", | ||
| Set.of("PollForActivityTask", "PollForDecisionTask")); | ||
|
|
||
| @Override | ||
| public boolean isLongPollingOperation(Model model, ServiceShape service, OperationShape operation) { | ||
| if (operation.hasTrait(LongPollTrait.class)) { | ||
| return true; | ||
| } | ||
| return service.getTrait(ServiceTrait.class) | ||
| .map(trait -> LONG_POLLING_OPERATIONS.get(trait.getSdkId())) | ||
| .map(operations -> operations.contains(operation.getId().getName())) | ||
| .orElse(false); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...java/software/amazon/smithy/python/codegen/sections/InitRetryStrategyResolverSection.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package software.amazon.smithy.python.codegen.sections; | ||
|
|
||
| import software.amazon.smithy.utils.CodeSection; | ||
| import software.amazon.smithy.utils.SmithyInternalApi; | ||
|
|
||
| /** | ||
| * A section that controls constructing the client's {@code RetryStrategyResolver}. | ||
| */ | ||
| @SmithyInternalApi | ||
| public record InitRetryStrategyResolverSection() implements CodeSection {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...-core/.changes/next-release/smithy-aws-core-feature-881860b5bda049d1b000983dd2a3bd0e.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "type": "feature", | ||
| "description": "Added support for the `x-amz-retry-after` response header." | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
[Question, maybe blocking?]
Does it really make sense for us to do this now before the trait is ready? I'd rather not have to track the separate work of updating this generator to function based on the trait and just update it when the rest of the SDKs do.
If we are already committed to shipping this, it's fine, but it is extra effort on our part for no customer benefit.
Uh oh!
There was an error while loading. Please reload this page.
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.
After a deeper look into other SDKs, I think it makes more sense to keep long polling in this PR, implemented as trait-first with a hardcoded fallback:
smithy.api#longPolltrait shipped in Smithy 1.69 (Add a long-poll trait smithy#3019), sohasTrait(LongPollTrait)compiles and works today. The service models don't carry the trait yet, so it currently falls through to the hardcoded table.