Skip to content

Latest commit

 

History

History
73 lines (50 loc) · 4.53 KB

File metadata and controls

73 lines (50 loc) · 4.53 KB
description
This page provides the technical details of the Circuit Breaker policy

Circuit Breaker

Overview

This policy allows switching to another backend or making the call fail with a 503 Service Unavailable in case of errors or latency. It guarantees high availability by making your system resilient if your target is detected as failing.

It is possible to configure errors and latency threshold rates to open the circuit breaker.

Implementation is based on Resilience4j. Refer to their documentation for more information.

Functional and implementation information for the circuit-breaker policy is organized into the following sections:

Examples

{% hint style="warning" %} This policy can only be applied to v2 APIs. It cannot be applied to v4 message APIs or v4 proxy APIs. {% endhint %}

{% tabs %} {% tab title="HTTP proxy API example" %} Sample policy configuration:

{
  "name": "Circuit breaker",
  "description": "",
  "enabled": true,
  "policy": "policy-circuit-breaker",
  "configuration": {
    "failureRateThreshold": 1,
    "slowCallRateThreshold": 10,
    "slowCallDurationThreshold": 500,
    "windowSize": 2,
    "waitDurationInOpenState": 50000,
    "redirectToURL": ""
  }
}

{% endtab %} {% endtabs %}

Configuration

Options

You can configure the circuit-breaker policy with the following options:

PropertyRequiredDescriptionTypeDefault
failureRateThresholdtrueFailure rate threshold before the circuit breaker switches to open state. A failure represents a response’s status code >= 500. The threshold is expressed as a percentage.integer (min. 0, max.100)50
slowCallRateThresholdtrueSlow call rate threshold before the circuit breaker switches to open state. A slow call is represented by a response time greater than the configured slowCallDurationThreshold. The threshold is expressed as a percentage.integer (min. 0, max.100)50
slowCallDurationThresholdtrueThe duration threshold above which a call is considered as slow, increasing slowCallRateThreshold. The duration is expressed in milliseconds.integer (min. 1)1000
windowSizetrueThe size of the sliding window which is used to record the outcome of calls when the circuit is closed.integer (min. 0)100
waitDurationInOpenStatefalseThe duration in millisecond before switching from open circuit to half-open.integer (min. 1)1000
redirectToURLfalseRedirect the call to the given URL instead of returning '503 Service Unavailable' status (supports EL)string
scopetrueCached response can be set for a single consumer (application) or for all applications.<br><strong>WARNING:</strong> Please be aware that by using an \"API\" scope, data will be shared between all consumers !API / APPLICATIONAPPLICATION

Phases

The phases checked below are supported by the circuit-breaker policy:

v2 PhasesCompatible?v4 PhasesCompatible?
onRequesttrueonRequestfalse
onResponsefalseonResponsefalse
onRequestContentfalseonMessageRequestfalse
onResponseContentfalseonMessageResponsefalse

Compatibility matrix

The following is the compatibility matrix for APIM and the circuit-breaker policy:

Plugin VersionSupported APIM versions
Up to 1.xAll

Changelogs

{% @github-files/github-code-block url="https://github.com/gravitee-io/gravitee-policy-circuit-breaker/blob/master/CHANGELOG.md" %}