Updated on 2022-12-05 GMT+08:00

Circuit Breaker Plug-in

Overview

ROMA Connect uses circuit breakers to protect the system when performance issues occur on backend services. When the backend service of an API times out for N consecutive times or there is long latency, the circuit breaker downgrade mechanism is triggered to return an error to the API caller or forward the request to the specified backend. After the backend service recovers, the circuit breaker closes and the request becomes normal.

Parameter Description

Table 1 Parameter description

Parameter

Description

API Sharing

When enabled, all APIs bound to the current plug-in are calculated together for circuit breaker triggering.

Circuit Breaker Type

Specify a circuit breaker triggering type.

  • Timeout downgrade: The circuit breaker is triggered upon backend timeout.
  • Conditional downgrade: The circuit breaker is triggered whenever conditions configured in Match Conditions are met.

Condition Type

Specify a circuit breaker triggering mode.

  • Count: Once the number of requests that meet the conditions specified within the time window reaches the threshold, the circuit breaker is immediately triggered.
  • Percentage: Once the percentage of requests that meet the conditions specified within the time window reaches the threshold, the circuit breaker is triggered at the end of the time window.

Match Conditions

This parameter is mandatory only when Circuit Breaker Type is set to Conditional downgrade.

Configure the match conditions for circuit breaker triggering.

  • Response Error Codes: The circuit breaker is triggered when the backend responds with the status codes specified.
  • Response Latency: The circuit breaker is triggered when the backend response latency exceeds the threshold specified.

Time Window

Configure the time window for circuit breaker triggering. Use this parameter together with Threshold or Min Percentage. Once the number of times or percentage when conditions are met within the time window exceeds the threshold, the circuit breaker is triggered.

Threshold

This parameter is mandatory only when Condition Type is set to Count.

Configure the threshold for circuit breaker triggering. Use this parameter together with Time Window. Once the number of backend requests that meet the conditions within the time window reaches the threshold, the circuit breaker is triggered.

NOTE:

A circuit breaker plug-in is triggered for a single gateway component. If ROMA Connect has multiple components, the triggering for each component is determined separately.

If the threshold is reached within the time window for a gateway component, requests sent to the component trigger the circuit breaker, but other gateway components still forward requests normally.

An IP address indicates a gateway component. To view the number of gateway components, go to the Instance Information page of a ROMA Connect instance by clicking the instance name on the console and view the number of IP addresses in Connection Addresses.

Min Calls

This parameter is mandatory only when Condition Type is set to Percentage.

Configure the minimum number of calls to trigger the circuit breaker. Once the total number of API calls within the time window reaches the threshold specified, the circuit breaker is triggered.

Min Percentage

This parameter is mandatory only when Condition Type is set to Percentage.

Configure the threshold for circuit breaker triggering. Use this parameter together with Time Window. Once the percentage of backend requests that meet the conditions within the time window reaches the threshold, the circuit breaker is triggered.

Control Duration

Configure the duration for which the circuit breaker is open. The circuit breaker is closed when the duration reaches the value specified.

Backend Downgrade Policy

Specify whether to enable the backend downgrade policy.

  • Enable: Requests for APIs that have triggered a downgrade will be forwarded to a specified backend.
  • Disable: Requests for APIs that have triggered a downgrade will not be forwarded to any backend. Instead, an error message indicating that the service is unavailable will be returned.

Backend Policy Type

This parameter is mandatory only when Backend Downgrade Policy is enabled.

Specify the backend type to which requests will be forwarded when the circuit breaker is open.

  • Mock: The defined response will be returned.
    • Status Code: the status code to be included in the response
    • Response: the response body, which is in JSON format
    • Response Header: header parameters to be included in the response
  • HTTP&HTTPS: Backend requests will be forwarded to a specified HTTP&HTTPS backend service.
    • Use Load Balance Channel: specifies whether to use load balance channels to access the backend. If you want to select yes, create a load balance channel in advance.
    • Backend URL: address of the backend service to forward requests to.
    • Timeout (ms): backend request timeout. The default value is 5000 ms.
  • FunctionGraph: Backend requests will be forwarded to a specified function.
    • Function URN: unique identifier of a function request. Click Select Function URN to add a backend function URN.
    • Function Name: automatically displayed after you select a function.
    • Version: version of the function.
    • Invocation Type: invocation type of the function.

      Synchronous: When receiving an invocation request, FunctionGraph immediately processes the request and returns a result. The client closes the connection once it has received a response from the backend.

      Asynchronous: After receiving a calling request, FunctionGraph queues the request and returns the result after the request is successfully executed. The server processes the queuing requests one by one when it is idle. The client does not care about the calling result.

    • Timeout (ms): backend request timeout. The default value is 5000 ms.
  • Passthrough: Backend requests will be forwarded to the original API backend.

    To add header parameters to backend requests, click Add Parameter.

Downgrade Parameter Settings

Specify whether to enable downgrade parameter configuration. When enabled, custom rules take precedence over the default ones configured above:

  • If a custom rule is matched, its trigger conditions and downgrade policy take effect. If the custom rule contains no trigger condition or downgrade policy, the default settings in Trigger Configuration and Backend Downgrade Policy take effect.
  • If the custom rules are not matched, the default settings take effect.

Parameters

Define the parameters for rule matching.

  • Parameter Location: position of a parameter in an API request.
  • Parameter: name of a parameter used for rule matching.

By default, the system contains the reqPath (request path) and method (request method) parameters. Click Add Parameter to add parameters.

Rules

Customize matching rules for the circuit breaker. Click Add Rule to add rules. The system matches rules from top to bottom. Adjust the rule priority by moving the rules up or down.

  • Conditions: Click to edit the condition expressions. If there are three or more expressions, you can layer them by clicking Set Lower Level.
    • =: equal
    • !=: not equal to
    • pattern: regular expression
    • enum: enumerated values. Separate them with commas (,).
  • For details about how to configure the triggering conditions and backend downgrade, see the instructions for the default settings above.

Example: You have enabled Downgrade Parameter Settings and added rules rule01 and rule02 in sequence. And you have disabled Trigger Configuration and enabled Backend Downgrade Policy for rule01, and have enabled both parameters for rule02. Analysis: The circuit breaker first checks whether the match conditions of rule01 are met. If yes, the circuit breaker opens based on the default settings because no trigger condition is defined in rule01, and the backend downgrade policy in rule01 is executed. If no, rule02 is checked.

Script Configuration Example

{
  "breaker_condition":{
    "breaker_type":"timeout",
    "breaker_mode":"counter",
    "unhealthy_threshold":30,
    "time_window":15,
    "open_breaker_time":15,
    "unhealthy_percentage":51,
    "min_call_threshold":20
  },
  "scope":"share",
  "downgrade_default":{
    "type":"http",
    "passthrough_infos":null,
    "func_info":null,
    "mock_info":null,
    "http_info":{
      "isVpc":false,
      "vpc_channel_id":"",
      "address":"10.10.10.10",
      "scheme":"HTTP",
      "method":"GET",
      "path":"/demo",
      "timeout":5000
    },
    "http_vpc_info":null
  },
  "downgrade_parameters":[
  {
    "name":"reqPath",
    "type":"path",
    "value":"path",
    "disabled":true,
    "focused":true,
    "id":"92002eqbpilg6g"
  },
  {
    "name":"method",
    "type":"method",
    "value":"method",
    "disabled":true,
    "focused":true,
    "id":"tuvxetsdqvcos8"
  }],
  "downgrade_rules":[
  {
    "rule_name":"rule-test1",
    "parameters":[
      "reqPath",
      "method"
    ],
    "match_regex":"[\"reqPath\",\"==\",\"/test\"]",
    "downgrade_backend":{
      "type":"mock",
      "passthrough_infos":null,
      "func_info":null,
      "mock_info":{
        "status_code":200,
        "result_content":"{status: ok}",
        "headers":[]
      },
      "http_info":null,
      "http_vpc_info":null
    },
    "breaker_condition":{
      "breaker_type":"timeout",
      "breaker_mode":"percentage",
      "unhealthy_threshold":30,
      "time_window":15,
      "open_breaker_time":15,
      "unhealthy_percentage":51,
      "min_call_threshold":20
    }
  }]
}