Skip to content
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

Retry mechanism #577

Open
wants to merge 6 commits into
base: 3.1.x
Choose a base branch
from
Open

Retry mechanism #577

wants to merge 6 commits into from

Conversation

pmv
Copy link

@pmv pmv commented Mar 3, 2021

Opening for discussion - I believe vault is critical enough infrastructure that clients should have a retry mechanism out of the box.

Relates to spring-projects/spring-vault#504
and
#236

Due to the similarities (both bootstrap property sources), default retry properties were set to match spring cloud config's defaults (https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_client.html#config-client-retry)

I have not added tests - I can/will do so once a maintainer indicates this PR on the right track and has potential to be merged.

Thank you

@pivotal-issuemaster
Copy link

@pmv Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@mp911de
Copy link
Member

mp911de commented Mar 3, 2021

Adding retry support here seems fine. However, we should not make use of aspect-oriented programming features. Instead, using RetryTemplate directly is much more efficient. Actually, the ideal variant would be a Retry-enabled ClientHttpRequestFactory.

PR feedback - remove AOP and retry-enable ClientHttpRequestFactory
@pmv
Copy link
Author

pmv commented Mar 8, 2021

Adding retry support here seems fine. However, we should not make use of aspect-oriented programming features.

Originally I did not until I saw this: https://github.com/spring-cloud/spring-cloud-config/blob/master/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigServiceBootstrapConfiguration.java#L62-L78, and then I modeled my changes after those. However, I am not set on that particular implementation.

Actually, the ideal variant would be a Retry-enabled ClientHttpRequestFactory.

Pushing an update to that effect.

@mp911de mp911de self-assigned this Mar 8, 2021
@pivotal-issuemaster
Copy link

@pmv Thank you for signing the Contributor License Agreement!

@pmv
Copy link
Author

pmv commented Mar 31, 2021

Let me know if there's any more legwork you'd like me to do for this one - thanks

Copy link
Member

@mp911de mp911de left a comment

Choose a reason for hiding this comment

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

I left two comments regarding the integration points with Spring Retry infrastructure beans. The PR looks pretty decent. What's missing is a bit of documentation on how/when Spring Retry is used.

*
* @since 3.0.2
*/
public static class Retry {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Implemented in updated changes.

@@ -129,7 +130,15 @@ protected RestTemplateBuilder restTemplateBuilder(ClientHttpRequestFactory reque
@Bean
@ConditionalOnMissingBean
public ClientFactoryWrapper clientHttpRequestFactoryWrapper() {
return new ClientFactoryWrapper(this.configuration.createClientHttpRequestFactory());
Copy link
Member

Choose a reason for hiding this comment

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

It would make sense to reuse potentially existing RetryTemplate beans (or instances when using the ConfigData boostrapper, see https://github.com/spring-cloud/spring-cloud-config/blob/master/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigClientRetryBootstrapper.java)

Copy link
Author

Choose a reason for hiding this comment

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

New changes re-use existing RetryTemplate beans

* Tests without spring-retry on the classpath to be sure there is no hard dependency
*/
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions({ "spring-retry-*.jar" })
Copy link
Author

Choose a reason for hiding this comment

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

This seemed like an improvement over having a separate module to run tests without spring-retry on the classpath (assuming you're fine with spring-cloud-test-support as a test dependency)

* {@link VaultReactiveBootstrapConfigurationTests#shouldNotConfigureReactiveSupport()}
*/
@Test
public void shouldNotConfigureReactiveSupport() {
Copy link
Author

Choose a reason for hiding this comment

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

This is something I happened to stumble across - perhaps it belongs in a separate PR. I assume you want 'spring.cloud.vault.reactive.enabled' to behave the same across ConfigData & bootstrap configuration.

I added the property to VaultProperties so I could reference it in the ConfigData path - perhaps there is another way if you don't want it in VaultProperties.

@pmv
Copy link
Author

pmv commented Jun 11, 2021

Let me know if you have any more feedback - I believe suggestions up to this point have been addressed.

@mp911de
Copy link
Member

mp911de commented Jun 11, 2021

Thanks. I want to have a look at this in the upcoming days.

@stefan-g
Copy link

stefan-g commented Sep 10, 2021

Hi, are there any timelines when retry will be supported? Is there a workaround example how to setup retry for spring-cloud-vault.3.0.3?

@mp911de
Copy link
Member

mp911de commented Sep 14, 2021

Right now, we don't have bandwidth to follow up timely.

First, you need to set `spring.cloud.vault.fail-fast=true`.
Then you need to add `spring-retry` to your classpath.
The default behavior is to retry six times with an initial backoff interval of 1000ms and an exponential multiplier of 1.1 for subsequent backoffs.
You can configure these properties by setting the `spring.cloud.config.retry.*` configuration properties.
Copy link
Contributor

@krisiye krisiye Apr 15, 2022

Choose a reason for hiding this comment

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

This should read spring.cloud.vault.retry.* instead?

Copy link
Author

Choose a reason for hiding this comment

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

Great catch - fixed.

@krisiye
Copy link
Contributor

krisiye commented Apr 15, 2022

@mp911de - It will be great if this can be reviewed and supported for a subsequent release as it could save us from implementing custom retry solutions within every vault client app. Thanks!

@juriohacc
Copy link

juriohacc commented Apr 23, 2022

Iam agree, it will be be nice if this feature is implemented, the usage of vault for database access is very critical.

For the moment, if someone could share a full example of code workaround to handle retry (without AOP and forking the repository is better) it will be nice.

Thank you.

pmv added 2 commits September 8, 2022 11:18
…retry

# Conflicts:
#	spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultConfigDataLoader.java
Detect and throw exception if retry properties are set but spring-retry is not on the classpath
@pmv pmv changed the base branch from main to 3.1.x September 9, 2022 02:49
@iozho
Copy link

iozho commented Nov 24, 2022

Hi guys:

Are you planing to merge this branch? The future seems to be great!

Thanks

@desprez
Copy link

desprez commented Jan 2, 2023

Hi
When you plan to merge this ?

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

Successfully merging this pull request may close these issues.

8 participants