-
Notifications
You must be signed in to change notification settings - Fork 69
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
Failsafe 3 #1416
Conversation
.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)); |
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.
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(); |
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.
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
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.
@Semernitskaya what additional properties that were introduced in failsafe can we support?
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.
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>() { |
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.
Added for Policy<R>
interface compatibility
riptide-failsafe/README.md
Outdated
@@ -11,7 +11,7 @@ and a circuit breaker to every remote call. | |||
## Example | |||
|
|||
```java | |||
Http.builder() | |||
Http.builder().asyncRequestFactory(asyncRequestFactory) |
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.
Given the example, I wonder where we get the instance of asyncRequestFactory
from or is this a Spring injectable dependency?
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.
Fixed, also code sample fixed in resilience.md
public BackupRequest(long delay, TimeUnit unit) { | ||
this.delay = delay; | ||
this.unit = unit; | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") |
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.
As there is no cast done in the implementation, you should be able to remove this annotation, no?
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.
Fixed
return functions.stream() | ||
.map(function -> function.computeDelay(result, failure, context)) | ||
.map(function -> { | ||
try { |
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.
Given that the method signature changed to throw instances of Throwable
, why do we need to wrap this into a RuntimeException
?
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.
map
method can't accept function that throws checked exception
riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/CheckedPredicateConverterTest.java
Outdated
Show resolved
Hide resolved
|
||
import java.util.function.Predicate; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; |
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.
As in the other PR, I don't know in how this project typically expands *
imports.
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.
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; |
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.
Given that this imports where just added, but they are not used, the change looks unintended.
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.
Fixed
@@ -57,6 +61,7 @@ final class MicrometerPluginTest { | |||
|
|||
private final MeterRegistry registry = new SimpleMeterRegistry(); | |||
|
|||
|
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.
Extra new line is unintended, I assume.
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.
Fixed
Co-authored-by: Christoph Berg <christoph.berg@zalando.de>
} | ||
|
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.
} | |
} |
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.
It just deletes the superfluous newline.
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.
Fixed
void shouldRecordSuccessResponseMetric() { | ||
|
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.
void shouldRecordSuccessResponseMetric() { | |
void shouldRecordSuccessResponseMetric() { |
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.
Same as above.
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.
Fixed
👍 |
But take my 👍 with a grain of salt as I am not a Failsafe expert. |
👍 |
@Semernitskaya thank you for the contribution |
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:
CircuitBreaker
)DelayFunction
)In this PR:
MIGRATION.md
file with migration recommendations and links forriptide-failsafe
usersTypes of changes
Checklist: