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

Failsafe 3 #1416

Merged
merged 28 commits into from Mar 10, 2023
Merged

Failsafe 3 #1416

merged 28 commits into from Mar 10, 2023

Conversation

Semernitskaya
Copy link
Contributor

@Semernitskaya Semernitskaya commented Feb 22, 2023

Description

Upgrade Failsafe dependency to the latest version (3.3.0)

Motivation and Context

Task: #1394
Details: there are many breaking changes were introduced between current (2.4.3) and latest (3.3.0) Failsafe versions, including:

  • Packages renaming
  • Replacing constructors with builders (e.g. CircuitBreaker)
  • Renaming methods
  • Removing classes and interfaces (e.g. DelayFunction )

In this PR:

  • Code and tests are fixed based on introduced changes
  • Code samples in documentation are fixed
  • New section is added to MIGRATION.md file with migration recommendations and links for riptide-failsafe users

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

.filter(HttpResponseException.class::isInstance)
.map(HttpResponseException.class::cast)
.map(response -> response.getResponseHeaders().getFirst("X-RateLimit-Reset"))
.map(parser::parse)
.orElse(null);
.orElse(Duration.ofMinutes(-1));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to prevent NPE in DelayablePolicy line 52, behaviour for negative result and null result is the same at the end - see DelayablePolicy line 62

public static CircuitBreaker<ClientHttpResponse> createCircuitBreaker(
final Client client,
final CircuitBreakerListener listener) {

final CircuitBreaker<ClientHttpResponse> breaker = new CircuitBreaker<>();
final CircuitBreakerBuilder<ClientHttpResponse> breakerBuilder = CircuitBreaker.builder();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now CircuitBreaker and other policies are created via builder() method and can't be changed after - this limits how developers can modify beans after creation.
We can think about supporting more Failsafe properties in our configuration

Copy link
Member

Choose a reason for hiding this comment

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

@Semernitskaya what additional properties that were introduced in failsafe can we support?

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 meant not new properties, but supporting more of existing properties. Earlier developers could autowire CircuitBreaker bean for example and add some logic like handleIf(...) - now CircuitBreaker and other policies can't be changed after creation. So we can support more of their properties in our autoconfiguration instead

@Getter
public final class BackupRequest<R> implements Policy<R> {

private final long delay;
private final TimeUnit unit;
private final PolicyConfig<R> config = new PolicyConfig<R>() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added for Policy<R> interface compatibility

MIGRATION.md Outdated Show resolved Hide resolved
@@ -11,7 +11,7 @@ and a circuit breaker to every remote call.
## Example

```java
Http.builder()
Http.builder().asyncRequestFactory(asyncRequestFactory)
Copy link
Member

Choose a reason for hiding this comment

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

Given the example, I wonder where we get the instance of asyncRequestFactory from or is this a Spring injectable dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, also code sample fixed in resilience.md

public BackupRequest(long delay, TimeUnit unit) {
this.delay = delay;
this.unit = unit;
}

@Override
@SuppressWarnings("unchecked")
Copy link
Member

Choose a reason for hiding this comment

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

As there is no cast done in the implementation, you should be able to remove this annotation, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

return functions.stream()
.map(function -> function.computeDelay(result, failure, context))
.map(function -> {
try {
Copy link
Member

Choose a reason for hiding this comment

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

Given that the method signature changed to throw instances of Throwable, why do we need to wrap this into a RuntimeException?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

map method can't accept function that throws checked exception


import java.util.function.Predicate;

import static org.junit.jupiter.api.Assertions.*;
Copy link
Member

Choose a reason for hiding this comment

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

As in the other PR, I don't know in how this project typically expands * imports.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replaced with full import similarly to other tests

@@ -12,6 +12,8 @@
import org.zalando.riptide.httpclient.ApacheClientHttpRequestFactory;

import java.io.IOException;
import java.time.Duration;
Copy link
Member

Choose a reason for hiding this comment

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

Given that this imports where just added, but they are not used, the change looks unintended.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@@ -57,6 +61,7 @@ final class MicrometerPluginTest {

private final MeterRegistry registry = new SimpleMeterRegistry();


Copy link
Member

Choose a reason for hiding this comment

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

Extra new line is unintended, I assume.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment on lines 20 to 21
}

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
}

Copy link
Member

Choose a reason for hiding this comment

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

It just deletes the superfluous newline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment on lines 83 to 84
void shouldRecordSuccessResponseMetric() {

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
void shouldRecordSuccessResponseMetric() {
void shouldRecordSuccessResponseMetric() {

Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@cberg-zalando
Copy link
Member

👍

@cberg-zalando
Copy link
Member

But take my 👍 with a grain of salt as I am not a Failsafe expert.

@fatroom
Copy link
Member

fatroom commented Mar 10, 2023

👍

@fatroom
Copy link
Member

fatroom commented Mar 10, 2023

@Semernitskaya thank you for the contribution
@cberg-zalando thank you for the review

@fatroom fatroom merged commit 2f120ad into zalando:main Mar 10, 2023
@fatroom fatroom mentioned this pull request Mar 10, 2023
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.

None yet

3 participants