This is an automated email from the ASF dual-hosted git repository.
sylviasu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 18e687c34 docs(plugin): refactor api-breaker.md (#7666)
18e687c34 is described below
commit 18e687c3428902f89caddcbd3e09e2f472151832
Author: Yuedong Wu <[email protected]>
AuthorDate: Wed Aug 17 09:06:00 2022 +0800
docs(plugin): refactor api-breaker.md (#7666)
* docs: update api-breaker.md
---
docs/en/latest/plugins/api-breaker.md | 34 ++++++++++------
docs/zh/latest/plugins/api-breaker.md | 74 ++++++++++++++++++++---------------
2 files changed, 64 insertions(+), 44 deletions(-)
diff --git a/docs/en/latest/plugins/api-breaker.md
b/docs/en/latest/plugins/api-breaker.md
index 2a519f7d3..137687043 100644
--- a/docs/en/latest/plugins/api-breaker.md
+++ b/docs/en/latest/plugins/api-breaker.md
@@ -2,10 +2,9 @@
title: api-breaker
keywords:
- APISIX
- - Plugin
+ - API Gateway
- API Breaker
- - api-breaker
-description: This document contains information about the Apache APISIX
api-breaker Plugin.
+description: This document describes the information about the Apache APISIX
api-breaker Plugin, you can use it to protect Upstream services.
---
<!--
@@ -31,12 +30,16 @@ description: This document contains information about the
Apache APISIX api-brea
The `api-breaker` Plugin implements circuit breaker functionality to protect
Upstream services.
+:::note
+
Whenever the Upstream service responds with a status code from the configured
`unhealthy.http_statuses` list for the configured `unhealthy.failures` number
of times, the Upstream service will be considered unhealthy.
The request is then retried in 2, 4, 8, 16 ... seconds until the
`max_breaker_sec`.
In an unhealthy state, if the Upstream service responds with a status code
from the configured list `healthy.http_statuses` for `healthy.successes` times,
the service is considered healthy again.
+:::
+
## Attributes
| Name | Type | Required | Default | Valid values
| Description
|
@@ -55,7 +58,8 @@ In an unhealthy state, if the Upstream service responds with
a status code from
The example below shows how you can configure the Plugin on a specific Route:
```shell
-curl "http://127.0.0.1:9080/apisix/admin/routes/1" -H 'X-API-KEY:
edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+curl "http://127.0.0.1:9080/apisix/admin/routes/1" \
+-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"plugins": {
"api-breaker": {
@@ -80,23 +84,28 @@ curl "http://127.0.0.1:9080/apisix/admin/routes/1" -H
'X-API-KEY: edd1c9f034335f
}'
```
-In this configuration, a response code of 500 or 503 three times within a
certain period of time triggers the unhealthy status of the Upstream service. A
response code of 200 restores its healthy status.
+In this configuration, a response code of `500` or `503` three times within a
certain period of time triggers the unhealthy status of the Upstream service. A
response code of `200` restores its healthy status.
## Example usage
-Once you have configured the Plugin as shown above, you can test it out by
sending a request. If the Upstream service responds with an unhealthy response
code, you will receive the configured response code (`break_response_code`).
+Once you have configured the Plugin as shown above, you can test it out by
sending a request.
```shell
curl -i -X POST "http://127.0.0.1:9080/hello"
```
+If the Upstream service responds with an unhealthy response code, you will
receive the configured response code (`break_response_code`).
+
```shell
HTTP/1.1 502 Bad Gateway
-Content-Type: application/octet-stream
-Connection: keep-alive
-Server: APISIX/1.5
-
-... ...
+...
+<html>
+<head><title>502 Bad Gateway</title></head>
+<body>
+<center><h1>502 Bad Gateway</h1></center>
+<hr><center>openresty</center>
+</body>
+</html>
```
## Disable Plugin
@@ -104,7 +113,8 @@ Server: APISIX/1.5
To disable the `api-breaker` Plugin, you can delete the corresponding JSON
configuration from the Plugin configuration. APISIX will automatically reload
and you do not have to restart for this to take effect.
```shell
-curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY:
edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+curl http://127.0.0.1:9080/apisix/admin/routes/1 \
+-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/hello",
"upstream": {
diff --git a/docs/zh/latest/plugins/api-breaker.md
b/docs/zh/latest/plugins/api-breaker.md
index 5563fef9e..9210b5cf8 100644
--- a/docs/zh/latest/plugins/api-breaker.md
+++ b/docs/zh/latest/plugins/api-breaker.md
@@ -1,5 +1,10 @@
---
title: api-breaker
+keywords:
+ - APISIX
+ - API 网关
+ - API Breaker
+description: 本文介绍了 Apache APISIX api-breaker 插件的相关操作,你可以使用此插件的 API
熔断机制来保护上游业务服务。
---
<!--
@@ -23,42 +28,40 @@ title: api-breaker
## 描述
-该插件实现 API 熔断功能,帮助我们保护上游业务服务。
+`api-breaker` 插件实现了 API 熔断功能,从而帮助我们保护上游业务服务。
-> 关于熔断超时逻辑
+:::note 注意
-由代码逻辑自动按**触发不健康状态**的次数递增运算:
+关于熔断超时逻辑,由代码逻辑自动按**触发不健康状态**的次数递增运算:
-每当上游服务返回 `unhealthy.http_statuses` 配置中的状态码(比如:500),达到 `unhealthy.failures` 次时
(比如:3 次),认为上游服务处于不健康状态。
+当上游服务返回 `unhealthy.http_statuses` 配置中的状态码(默认为 `500`),并达到 `unhealthy.failures`
预设次数时(默认为 3 次),则认为上游服务处于不健康状态。
-第一次触发不健康状态,**熔断 2 秒**。
+第一次触发不健康状态时,熔断 2 秒。超过熔断时间后,将重新开始转发请求到上游服务,如果继续返回 `unhealthy.http_statuses`
状态码,记数再次达到 `unhealthy.failures` 预设次数时,熔断 4 秒。依次类推(2,4,8,16,……),直到达到预设的
`max_breaker_sec`值。
-然后,2 秒过后重新开始转发请求到上游服务,如果继续返回 `unhealthy.http_statuses` 状态码,记数再次达到
`unhealthy.failures` 次时,**熔断 4 秒**(倍数方式)。
+当上游服务处于不健康状态时,如果转发请求到上游服务并返回 `healthy.http_statuses` 配置中的状态码(默认为 `200`),并达到
`healthy.successes` 次时,则认为上游服务恢复至健康状态。
-依次类推,2, 4, 8, 16, 32, 64, ..., 256,最大到 300。 300 是 `max_breaker_sec`
的最大值,允许自定义修改。
-
-在不健康状态时,当转发请求到上游服务并返回 `healthy.http_statuses` 配置中的状态码(比如:200),达到
`healthy.successes` 次时 (比如:3 次),认为上游服务恢复健康状态。
+:::
## 属性
| 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述
|
| ----------------------- | -------------- | ------ | ---------- |
--------------- | -------------------------------- |
-| break_response_code | integer | 必须 | 无 | [200, ...,
599] | 不健康返回错误码 |
-| break_response_body | string | 可选 | 无 |
| 不健康返回报文 |
-| break_response_headers | array[object] | 可选 | 无 |
[{"key":"header_name","value":"can contain Nginx $var"}] |
不健康返回报文头,这里可以设置多个。该字段仅在 `break_response_body` 被配置时生效。这个值能够以 `$var` 的格式包含 APISIX
变量,比如 `{"key":"X-Client-Addr","value":"$remote_addr:$remote_port"}`。 |
-| max_breaker_sec | integer | 可选 | 300 | >=3
| 最大熔断持续时间 |
-| unhealthy.http_statuses | array[integer] | 可选 | {500} | [500, ...,
599] | 不健康时候的状态码 |
-| unhealthy.failures | integer | 可选 | 3 | >=1
| 在一定时间内触发不健康状态的异常请求次数 |
-| healthy.http_statuses | array[integer] | 可选 | {200} | [200, ...,
499] | 健康时候的状态码 |
-| healthy.successes | integer | 可选 | 3 | >=1
| 触发健康状态的连续正常请求次数 |
+| break_response_code | integer | 是 | | [200, ..., 599]
| 当上游服务处于不健康状态时返回的 HTTP 错误码。 |
+| break_response_body | string | 否 | |
| 当上游服务处于不健康状态时返回的 HTTP 响应体信息。 |
+| break_response_headers | array[object] | 否 | |
[{"key":"header_name","value":"can contain Nginx $var"}] | 当上游服务处于不健康状态时返回的
HTTP 响应头信息。该字段仅在配置了 `break_response_body` 属性时生效,并能够以 `$var` 的格式包含 APISIX 变量,比如
`{"key":"X-Client-Addr","value":"$remote_addr:$remote_port"}`。 |
+| max_breaker_sec | integer | 否 | 300 | >=3
| 上游服务熔断的最大持续时间,以秒为单位。 |
+| unhealthy.http_statuses | array[integer] | 否 | [500] | [500, ...,
599] | 上游服务处于不健康状态时的 HTTP 状态码。 |
+| unhealthy.failures | integer | 否 | 3 | >=1
| 上游服务在一定时间内触发不健康状态的异常请求次数。 |
+| healthy.http_statuses | array[integer] | 否 | [200] | [200, ...,
499] | 上游服务处于健康状态时的 HTTP 状态码。 |
+| healthy.successes | integer | 否 | 3 | >=1
| 上游服务触发健康状态的连续正常请求次数。 |
-## 启用方式
+## 启用插件
-这是一个示例,在指定的路由上启用 `api-breaker` 插件。
-在一定时间内应答 500 或 503 达到 3 次,触发熔断。应答 200 连续 1 次,恢复健康。
+以下示例展示了如何在指定路由上启用 `api-breaker` 插件,该路由配置表示在一定时间内返回 `500` 或 `503` 状态码达到 3
次后触发熔断,返回 `200` 状态码 1 次后恢复健康:
```shell
-curl "http://127.0.0.1:9080/apisix/admin/routes/1" -H 'X-API-KEY:
edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+curl "http://127.0.0.1:9080/apisix/admin/routes/1" \
+-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"plugins": {
"api-breaker": {
@@ -85,24 +88,33 @@ curl "http://127.0.0.1:9080/apisix/admin/routes/1" -H
'X-API-KEY: edd1c9f034335f
## 测试插件
-使用上游的配置,在一定时间内如果你的上流服务返回 500 达到 3 次。客户端将会收到 502(break_response_code)应答。
+按上述配置启用插件后,使用 `curl` 命令请求该路由:
```shell
-$ curl -i "http://127.0.0.1:9080/hello"
-HTTP/1.1 502 Bad Gateway
-Content-Type: application/octet-stream
-Connection: keep-alive
-Server: APISIX/1.5
+curl -i -X POST "http://127.0.0.1:9080/hello"
+```
+
+如果上游服务在一定时间内返回 `500` 状态码达到 3 次,客户端将会收到 `502 Bad Gateway` 的应答:
-... ...
+```shell
+HTTP/1.1 502 Bad Gateway
+...
+<html>
+<head><title>502 Bad Gateway</title></head>
+<body>
+<center><h1>502 Bad Gateway</h1></center>
+<hr><center>openresty</center>
+</body>
+</html>
```
## 禁用插件
-当想禁用 `api-breaker` 插件时,非常简单,只需要在插件配置中删除相应的 json 配置,无需重启服务,即可立即生效:
+当你需要禁用该插件时,可以通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务:
```shell
-curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY:
edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+curl http://127.0.0.1:9080/apisix/admin/routes/1 \
+-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/hello",
"upstream": {
@@ -113,5 +125,3 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H
'X-API-KEY: edd1c9f034335f13
}
}'
```
-
-`api-breaker` 插件现在已被禁用,它也适用于其他插件。