Skip to content

Fix a bug that prevents a retry strategy override to get used #5300

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

Merged
merged 23 commits into from
Jun 19, 2024

Conversation

sugmanue
Copy link
Contributor

@sugmanue sugmanue commented Jun 15, 2024

Motivation and Context

Fixes a bug that was found that prevents a retry strategy override from being used as it was overwritten once again to configure it for AWS.

The original logic was there to add AWS-specific retry conditions for when the user set the retry strategy using RetryMode or using the mutator to tailor the default one Consumer<RetryStrategy.Builder>. We eagerly created the retry strategy, but since this package (sdk-core) does not know about AWS packages was not able to set the correct one, thus we did patch it after the fact, but this logic is not correct as it prevents user defined overrides to take place and will "over-configure" if an already AWS aware retry strategy is given.

Modifications

We now resolve the retry strategy lazily, either when using RetryMode or the default one to apply the configured configurator. We need to add logic to the client builder classes and to the client to accomplish this in three different scenarios:

  1. Client builder using client override configuration
  2. Client builder using plugins
  3. Request override configuration using plugins

For that the following method was added to the client builder and to the client to update the configuration after the plugins are run:

    private void updateRetryStrategyClientConfiguration(SdkClientConfiguration.Builder configuration) {
        ClientOverrideConfiguration.Builder builder = configuration.asOverrideConfigurationBuilder();
        RetryMode retryMode = builder.retryMode();
        if (retryMode != null) {
            configuration.option(SdkClientOption.RETRY_STRATEGY, AwsRetryStrategy.forRetryMode(retryMode));
            return;
        }
        Consumer<RetryStrategy.Builder<?, ?>> configurator = builder.retryStrategyConfigurator();
        if (configurator != null) {
            RetryStrategy.Builder<?, ?> defaultBuilder = AwsRetryStrategy.defaultRetryStrategy().toBuilder();
            configurator.accept(defaultBuilder);
            configuration.option(SdkClientOption.RETRY_STRATEGY, defaultBuilder.build());
            return;
        }
        RetryStrategy retryStrategy = builder.retryStrategy();
        if (retryStrategy != null) {
            configuration.option(SdkClientOption.RETRY_STRATEGY, retryStrategy);
        }
    }

This implies that now the clients themselves have a direct dependency on retries-spi which was also added for all services updating their pom.xml.

Testing

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

@sugmanue sugmanue marked this pull request as ready for review June 17, 2024 18:15
@sugmanue sugmanue requested a review from a team as a code owner June 17, 2024 18:15
@sugmanue sugmanue requested a review from joviegas June 17, 2024 18:24
@joviegas
Copy link
Contributor

joviegas commented Jun 17, 2024

There we lot of test files so was not able to pin point which test covers functional testing of this bug ? Could you please help with the Java test files which actually test the functionality when retry strategy is overridden.

@sugmanue
Copy link
Contributor Author

Could you please help with the Java test files which actually test the functionality when retry strategy is overridden.

CanOverrideRetryStrategy.java (the link might not work but that's the name of the file at the very bottom of the changes)

public static final SdkClientOption<RetryStrategy> RETRY_STRATEGY = new SdkClientOption<>(RetryStrategy.class);

/**
* The internal retry strategy set by the customer. This is likely only useful within configuration
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usage of the word internal here is confusing to me. Can we say The retry strategy set by the customer [where/when] instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the docs, e.g.,

    /**
     * The retry mode set by the customer using {@link ClientOverrideConfiguration.Builder#retryStrategy(RetryMode)}. This is
     * likely only useful within configuration classes, and will be converted into a {@link #RETRY_STRATEGY} for the SDK's
     * runtime.
     *
     * @see ClientOverrideConfiguration#retryMode()
     */

Let me know if you have a better wording that I can use.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this wording, thanks for updating.

joviegas
joviegas previously approved these changes Jun 18, 2024
@joviegas joviegas self-requested a review June 18, 2024 20:43
@joviegas joviegas dismissed their stale review June 18, 2024 20:45

Additional changes suggested by Zoe and Anna-karin not yet reviewe

@sugmanue sugmanue force-pushed the sugmanue/fix-override-retry-strategy2 branch from 23fe873 to 1051b53 Compare June 18, 2024 21:40
@sugmanue sugmanue enabled auto-merge (squash) June 18, 2024 22:58
@sugmanue sugmanue removed the request for review from joviegas June 18, 2024 23:01
Copy link

@sugmanue sugmanue merged commit 0b85357 into master Jun 19, 2024
17 checks passed
@sugmanue sugmanue deleted the sugmanue/fix-override-retry-strategy2 branch June 19, 2024 00:46
sugmanue added a commit that referenced this pull request Jun 19, 2024
akidambisrinivasan pushed a commit to akidambisrinivasan/aws-sdk-java-v2 that referenced this pull request Jun 28, 2024
)

* Scenarios that we need to support when using RetryMode

* Use SdkClientOption and lazily set the strategies at build time

* Update client tests for the new updateRetryStrategyClientConfiguration method

* Create a new change entry for the PR

* Fix checkstyle and japicmp issues

* Add dependency to retries-spi for all services

* Change to client builder properly set retry strategy from plugins

* Remove added files by mistake

* Add missing dependency to retries-spi module

* Add test cases for plugins

* Move the retries-spi dependencies to services pom.xml

* Update javadocs in an attempt to make them more clear

* Update the javadocs

* Remove a comment that might be confusing

* Put back the original link for the deprecated tag

* Address PR comments

* Address PR comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants