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

Implementing Resilience4j for spring boot 2 #785

Closed
ramsirish opened this issue Dec 20, 2019 · 36 comments
Closed

Implementing Resilience4j for spring boot 2 #785

ramsirish opened this issue Dec 20, 2019 · 36 comments

Comments

@ramsirish
Copy link

Thanks for raising a Resilience4j issue.
Please provide a brief description of your problem along with the versions you are using.
If possible, please also consider putting together a complete JUnit test that reproduces the issue.

Resilience4j version:1.1.0

Java version:8

Problem description:
I tried implementing circuit breaker using resilience4j and it was working fine. My requirement is that it should go to fall back method only when there are 5 errors/min. Is that possible in resilience4j?. Please provide a detailedsolution.

@RobWin
Copy link
Member

RobWin commented Dec 20, 2019

Hi,

you really want to invoke a fallback method if there are 5 errors per minute independently of the number of successful calls per minute? Sounds surprising to me.
Is that really want to you want to achieve? Why?

@ramsirish
Copy link
Author

yeah that is what i am trying to achieve if there are 5 errors per minute it should go to fallback method. is that kind of scenario possible in resilience4j?

@RobWin
Copy link
Member

RobWin commented Dec 25, 2019

But could you please explain why its unimportant for you if all other requests are successful within the minute? Lets assume you have 500 requests per minute. The failure rate would be just 1% if the remaining 495 requests were successful?

@RobWin
Copy link
Member

RobWin commented Dec 25, 2019

It's currently not possible to transition a CircuitBreaker to OPEN just based on the number of failures per time frame.

@ramsirish
Copy link
Author

what is the parameter should we use if we want to transition a circuitbreaker to open based on number of failures per time frame. How the threshold limit is calculated? is it calculated no of calls per minute.
Can you give a detailed explanation on this.

@ramsirish
Copy link
Author

How can we transition circuit breaker to open based on number of failures per timeframe for spring boot application

@RobWin
Copy link
Member

RobWin commented Dec 26, 2019

Sry, it's not possible

@ramsirish
Copy link
Author

can you please tell me how the failure rate threshold limit is calculated? On what basis circuit breaker changes its state to open is it on threshold limit or ring buffer size in closed state?

@RobWin
Copy link
Member

RobWin commented Dec 26, 2019

Its documented here https://resilience4j.readme.io/docs/circuitbreaker

@ramsirish
Copy link
Author

I have gone through the document and can you please tell how the failure rate threshold is calculated is it per minute?

@RobWin
Copy link
Member

RobWin commented Dec 26, 2019

You have to use a Sliding Time Window of size 60 (seconds).
slidingWindowType.TIME_BASED and slidingWindowSize = 60

@ramsirish
Copy link
Author

If I use slidingwindowsize= 60 does failure rate threshold is calculated per every 60 seconds?

@RobWin
Copy link
Member

RobWin commented Dec 26, 2019

No, not every 60 seconds, but the failure rate is calculated based on the requests from the last 60 seconds. The sliding window evicts old request outcomes every second.

@ramsirish
Copy link
Author

Suppose if there are 10 calls in a minute and 3 calls got failed so failure threshold is calculated for that minute right? Can you please give a brief explanation on this please

@ramsirish
Copy link
Author

I am confused about how the failure rate threshold is calculated. How to time based for sliding window in spring boot application.yml and what is eventbufferconsumersize

@kkgulati
Copy link

@ramsirish , I guess you should follow the documentation and do some test run to understand, how it is working, the Lib is working as documented and whats expected out of the design pattern.

@ramsirish
Copy link
Author

@kuldeep gulati can we have a discussion regarding resilience4j offline?

@ramsirish
Copy link
Author

@RobWin How can i add time based sliding window in application.yml for spring boot application

@ramsirish
Copy link
Author

please tell what is eventbuffersize?

@RobWin
Copy link
Member

RobWin commented Dec 28, 2019

It controls how many events are stored internally in a buffer and are shown at this endpoint: https://resilience4j.readme.io/docs/getting-started-3#section-events-endpoint

@RobWin
Copy link
Member

RobWin commented Dec 28, 2019

slidingWindowType: TIME_BASED

@ramsirish
Copy link
Author

ramsirish commented Jan 1, 2020

Can we make a call to fallback method only after the circuit is open instead of making call to fallback method for every failure(exceptions which we record). Is it possible in resilience4j for spring boot application with annotations.

@ramsirish
Copy link
Author

@RobWin please answer my above question.

@ramsirish
Copy link
Author

I have used slidingWindowType: TIME_BASED and kept slidingWindowSize: 120 sec there were 20 requests failed out of total 20 requests that means failure rate threshold is 100% but still the circuit is not opening.

application.yml-

resilience4j.circuitbreaker:
instances:
service1:
registerHealthIndicator: true
slidingWindowType: TIME_BASED
slidingWindowSize: 120
ringBufferSizeInHalfOpenState: 3
waitDurationInOpenState: 10s
failureRateThreshold: 50
recordExceptions:
- org.springframework.web.client.HttpServerErrorException
- java.io.IOException
- java.util.concurrent.TimeoutException
- org.springframework.web.client.ResourceAccessException
service2:
registerHealthIndicator: true
slidingWindowType: TIME_BASED
slidingWindowSize: 10
ringBufferSizeInHalfOpenState: 3
waitDurationInOpenState: 10s
failureRateThreshold: 50
recordExceptions:
- org.springframework.web.client.HttpServerErrorException
- java.io.IOException
- java.util.concurrent.TimeoutException
- org.springframework.web.client.ResourceAccessException

@ramsirish
Copy link
Author

sorry if slidingWindowType: TIME_BASED is now working for me...I did not add minimum number of calls so failure rate was not calculated...Can we make a call to fallback method only after the circuit is open instead of making call to fallback method for every failure(exceptions which we record). Is it possible in resilience4j for spring boot application with annotations.

@ramsirish
Copy link
Author

@RobWin please help in my question above

@RobWin
Copy link
Member

RobWin commented Jan 2, 2020

Yes, you can define multiple fallback methods with the same name, but with different signatures.
It's important to remember that a fallback method should be placed in the same class and must have the same method signature with just ONE extra exception parameter).
If there are multiple fallbackMethod methods, the method that has the most closest match will be invoked, for example:
You can define one fallback method as follows:

private String fallback(String param, CallNotPermittedExceptione) {
  return "fallback";
}

Please see: https://resilience4j.readme.io/docs/getting-started-3#section-annotations

@ramsirish
Copy link
Author

Hi Robwin,
@RobWin
I was asking if we can make a call to fallback method only when the circuit is open. Now, for every exception which i have defined in record exceptions call is going to fallback method if the main method thrown an error when the circuit is closed.

@RobWin
Copy link
Member

RobWin commented Jan 2, 2020

How many fallback methods did you define? Can you show me the signature?

@ramsirish
Copy link
Author

Hi @RobWin

Do we need to download prometheous for monitoring circuit breaker stats? In what what we can integrate spring boot application where circuit breaker is implemented with prometheous and grafana.

@RobWin
Copy link
Member

RobWin commented Jan 4, 2020

Did you have a look at the Spring Boot 2 Demo?

@ramsirish
Copy link
Author

yeah but you have added micrometer depenency in build.gradle. What are the other changes we need do we need prometheous and graphana download to our local system.

@ramsirish
Copy link
Author

can you please tell complete steps for creating a dashboard to monitor circuit breaker

@RobWin
Copy link
Member

RobWin commented Jan 4, 2020

Not sure what you want to achieve? The demo uses Docker Compose to run Grafana and Prometheus.

@ramsirish
Copy link
Author

can't we do without using docker?

@RobWin
Copy link
Member

RobWin commented Jan 4, 2020

Sure you can. The Grafana Dashboard is included in the demo repository.
Why can't you just read the readme?

@RobWin RobWin closed this as completed Jan 6, 2020
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

No branches or pull requests

3 participants