Netflix / Hystrix

Hystrix is a latency and fault tolerance library designed to isolate points of access to remote systems, services and 3rd party libraries, stop cascading failure and enable resilience in complex distributed systems where failure is inevitable.
24.13k stars 4.71k forks source link

How to find out the last exception which caused the circuit to trip open? #1815

Open bjethwan opened 6 years ago

bjethwan commented 6 years ago

How to find out the last exception which caused the circuit to trip open?

For example I call an API which throw different kind of exceptions for different failures. Now when the circuit is open I want to know the last application exception which caused it to trip open. As I want my fallback method to return a different response based on last exception.

I created a small sample to find out the Hystrix behavior Here's the output: (1 to 11 are success, 12 to 22 are application exceptions, and 23 to 34 is when circuit is open). 1 [value1, value2, value3]and it took 156ms 2 [value1, value2, value3]and it took 5ms 3 [value1, value2, value3]and it took 4ms 4 [value1, value2, value3]and it took 6ms 5 [value1, value2, value3]and it took 5ms 6 [value1, value2, value3]and it took 5ms 7 [value1, value2, value3]and it took 6ms 8 [value1, value2, value3]and it took 5ms 9 [value1, value2, value3]and it took 5ms 10 [value1, value2, value3]and it took 2ms 11 [value1, value2, value3]and it took 0ms 12 caught exception com.bjethwan.Failure1Exception and it took 416ms 13 caught exception com.bjethwan.Failure1Exception and it took 400ms 14 caught exception com.bjethwan.Failure1Exception and it took 420ms 15 caught exception com.bjethwan.Failure1Exception and it took 412ms 16 caught exception com.bjethwan.Failure1Exception and it took 405ms 17 caught exception com.bjethwan.Failure1Exception and it took 411ms 18 caught exception com.bjethwan.Failure1Exception and it took 416ms 19 caught exception com.bjethwan.Failure1Exception and it took 436ms 20 caught exception com.bjethwan.Failure1Exception and it took 426ms 21 caught exception com.bjethwan.Failure1Exception and it took 408ms 22 caught exception com.bjethwan.Failure2Exception and it took 460ms 23 caught exception java.lang.RuntimeException: Hystrix circuit short-circuited and is OPEN and it took 8ms 24 caught exception java.lang.RuntimeException: Hystrix circuit short-circuited and is OPEN and it took 0ms 25 caught exception java.lang.RuntimeException: Hystrix circuit short-circuited and is OPEN and it took 0ms 26 caught exception java.lang.RuntimeException: Hystrix circuit short-circuited and is OPEN and it took 0ms 27 caught exception java.lang.RuntimeException: Hystrix circuit short-circuited and is OPEN and it took 0ms 28 caught exception java.lang.RuntimeException: Hystrix circuit short-circuited and is OPEN and it took 0ms 29 caught exception java.lang.RuntimeException: Hystrix circuit short-circuited and is OPEN and it took 0ms 30 caught exception java.lang.RuntimeException: Hystrix circuit short-circuited and is OPEN and it took 0ms 31 caught exception java.lang.RuntimeException: Hystrix circuit short-circuited and is OPEN and it took 0ms 32 caught exception java.lang.RuntimeException: Hystrix circuit short-circuited and is OPEN and it took 0ms 33 caught exception java.lang.RuntimeException: Hystrix circuit short-circuited and is OPEN and it took 0ms 34 caught exception java.lang.RuntimeException: Hystrix circuit short-circuited and is OPEN and it took 0ms

bjethwan commented 6 years ago

These below methods are useful but I couldn't find any API to find the exception which tripped the circuit. -isCircuitBreakerOpen():true -isResponseShortCircuited():true

bjethwan commented 6 years ago

Imagine old behavior where using Spring AOP we used to replay the same exception without invoking backend service.