liuhengloveyou commented on a change in pull request #2339: URL: https://github.com/apache/apisix/pull/2339#discussion_r502755526
########## File path: doc/zh-cn/plugins/api-breaker.md ########## @@ -0,0 +1,107 @@ +<!-- +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +--> + +- [English](../../plugins/api-blocker.md) + +# 目录 + +- [**定义**](#定义) +- [**属性列表**](#属性列表) +- [**启用方式**](#启用方式) +- [**测试插件**](#测试插件) +- [**禁用插件**](#禁用插件) + +## 定义 + +该插件实现API熔断功能,帮助我们保护上游业务服务。 + +关于熔断超时逻辑;当前版本没有开放相关配置项给用户,由代码逻辑自动按**触发不健康状态**的次数递增运算。 + +比如:上流服务第一次返回`unhealthy.http_statuses`状态达到`unhealthy.failures`次时,**熔断2秒**。然后,过2秒以后,上流服务再次连续返回`unhealthy.http_statuses`状态达到`unhealthy.failures`次时,**熔断4秒**。依次类推,最大达到300秒不再增加。 + + +## 属性列表 + +| 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 | +| ----------------------- | -------------- | ------ | ---------- | --------------- | -------------------------------- | +| unhealthy_response_code | integer | 必须 | 无 | [200, ..., 600] | 不健康返回错误码 | +| unhealthy.http_statuses | array[integer] | 可选 | {500} | [500, ..., 599] | 不健康时候的状态码 | +| unhealthy.failures | integer | 可选 | 1 | >=1 | 触发不健康状态的连续错误请求次数 | +| healthy.http_statuses | array[integer] | 可选 | {200, 206} | [200, ..., 499] | 健康时候的状态码 | +| successes.successes | integer | 可选 | 1 | >=1 | 触发健康状态的连续正常请求次数 | + +## 启用方式 + +这是一个示例,在指定的路由上启用`api-breaker`插件: + +```shell +curl "http://127.0.0.1:9080/apisix/admin/routes/5" -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + { + "plugins": { + "api-breaker": { + "unhealthy_response_code": 502, + "unhealthy": { + "http_statuses": [500, 503], + "failures": 3 + }, + "healthy": { + "http_statuses": [200], + "successes": 1 + } + } + }, + "uri": "/get", + "host": "127.0.0.1", + "upstream_id": 50 + }' +``` + +## 测试插件 + +```shell Review comment: added ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
