Skip to content

Commit 0abcdf9

Browse files
dira-AURnewtork
andauthored
feat: expose slowCallDurationThreshold in CircuitBreakerConfiguration (#1153)
Signed-off-by: dira-AUR <243805326+dira-AUR@users.noreply.github.com> Co-authored-by: Alexander Dümont <alexander.duemont@sap.com>
1 parent 58e368d commit 0abcdf9

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

cloudplatform/resilience-api/src/main/java/com/sap/cloud/sdk/cloudplatform/resilience/ResilienceConfiguration.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,18 @@ public static final class CircuitBreakerConfiguration
428428
*/
429429
public static final Duration DEFAULT_WAIT_DURATION = Duration.ofSeconds(10);
430430

431+
/**
432+
* The default duration threshold above which calls are considered as slow. Matches the Resilience4j default of
433+
* 60 seconds.
434+
*/
435+
public static final Duration DEFAULT_SLOW_CALL_DURATION_THRESHOLD = Duration.ofSeconds(60);
436+
437+
/**
438+
* The default slow call rate threshold (as percentage within [0, 100]). Matches the Resilience4j default of
439+
* 100%.
440+
*/
441+
public static final float DEFAULT_SLOW_CALL_RATE_THRESHOLD = 100;
442+
431443
/**
432444
* Flag to indicate active CircuitBreakerConfiguration.
433445
*/
@@ -461,6 +473,26 @@ public static final class CircuitBreakerConfiguration
461473
*/
462474
private int halfOpenBufferSize = DEFAULT_HALF_OPEN_BUFFER_SIZE;
463475

476+
/**
477+
* The duration threshold above which calls are considered as slow and increase the slow call rate. When the
478+
* percentage of slow calls is equal to or greater than {@link #slowCallRateThreshold}, the CircuitBreaker
479+
* transitions to <i>OPEN</i> and starts short-circuiting calls.
480+
*
481+
* @since 5.29.0
482+
*/
483+
@Nonnull
484+
private Duration slowCallDurationThreshold = DEFAULT_SLOW_CALL_DURATION_THRESHOLD;
485+
486+
/**
487+
* The slow call rate threshold (as percentage within [0, 100]). The CircuitBreaker considers a call as slow
488+
* when the call duration is greater than {@link #slowCallDurationThreshold}. When the percentage of slow calls
489+
* is equal to or greater than the threshold, the CircuitBreaker transitions to <i>OPEN</i> and starts
490+
* short-circuiting calls.
491+
*
492+
* @since 5.29.0
493+
*/
494+
private float slowCallRateThreshold = DEFAULT_SLOW_CALL_RATE_THRESHOLD;
495+
464496
/**
465497
* Get the status indicator for the CircuitBreaker.
466498
*

cloudplatform/resilience4j/src/main/java/com/sap/cloud/sdk/cloudplatform/resilience4j/DefaultCircuitBreakerProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public CircuitBreaker getCircuitBreaker( @Nonnull final ResilienceConfiguration
5555
.slidingWindowSize(configuration.circuitBreakerConfiguration().closedBufferSize())
5656
.minimumNumberOfCalls(configuration.circuitBreakerConfiguration().closedBufferSize())
5757
.permittedNumberOfCallsInHalfOpenState(configuration.circuitBreakerConfiguration().halfOpenBufferSize())
58+
.slowCallDurationThreshold(configuration.circuitBreakerConfiguration().slowCallDurationThreshold())
59+
.slowCallRateThreshold(configuration.circuitBreakerConfiguration().slowCallRateThreshold())
5860
.build();
5961

6062
val circuitBreaker = circuitBreakerRegistry.circuitBreaker(identifier, customCircuitBreakerConfig);

0 commit comments

Comments
 (0)