aws / aws-sdk-java-v2

The official AWS SDK for Java - Version 2
Apache License 2.0
2.16k stars 840 forks source link

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

Closed sugmanue closed 3 months ago

sugmanue commented 3 months ago

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

Checklist

License

joviegas commented 3 months ago

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 commented 3 months ago

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)

sonarcloud[bot] commented 3 months ago

Quality Gate Passed Quality Gate passed

Issues
17 New issues
0 Accepted issues

Measures
0 Security Hotspots
88.7% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud