From 7a33476eb1100f5c4464cf1db0ae13f7f3ec37df Mon Sep 17 00:00:00 2001 From: qihaiyan Date: Wed, 27 Apr 2022 15:39:11 +0800 Subject: [PATCH 01/11] api-breaker plugin returns default response body --- apisix/plugins/api-breaker.lua | 12 ++++++++++++ docs/en/latest/plugins/api-breaker.md | 2 ++ docs/zh/latest/plugins/api-breaker.md | 2 ++ t/plugin/api-breaker.t | 9 ++++++--- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/apisix/plugins/api-breaker.lua b/apisix/plugins/api-breaker.lua index bf10e0234870..fff23a3a1d4b 100644 --- a/apisix/plugins/api-breaker.lua +++ b/apisix/plugins/api-breaker.lua @@ -35,6 +35,13 @@ local schema = { minimum = 200, maximum = 599, }, + break_response_body = { + type = "string" + }, + break_response_content_type = { + type = "string", + default = "application/json" + }, max_breaker_sec = { type = "integer", minimum = 3, @@ -158,6 +165,11 @@ function _M.access(conf, ctx) -- breaker if lasttime + breaker_time >= ngx.time() then + if conf.break_response_body then + core.response.clear_header_as_body_modified() + ngx.header["Content-Type"] = conf.break_response_content_type + return conf.break_response_code, conf.break_response_body + end return conf.break_response_code end diff --git a/docs/en/latest/plugins/api-breaker.md b/docs/en/latest/plugins/api-breaker.md index bf1d4a0951a4..ec1eb6274209 100644 --- a/docs/en/latest/plugins/api-breaker.md +++ b/docs/en/latest/plugins/api-breaker.md @@ -44,6 +44,8 @@ In an unhealthy state, when a request is forwarded to an upstream service and th | Name | Type | Requirement | Default | Valid | Description | | ----------------------- | ------------- | ----------- | -------- | --------------- | --------------------------------------------------------------------------- | | break_response_code | integer | required | | [200, ..., 599] | Return error code when unhealthy | +| break_response_body | string | optional | | | Return reponse body when unhealthy | +| break_response_content_type | string | optional | application/json | | Return body's content type when unhealthy | | max_breaker_sec | integer | optional | 300 | >=3 | Maximum breaker time(seconds) | | unhealthy.http_statuses | array[integer] | optional | {500} | [500, ..., 599] | Status codes when unhealthy | | unhealthy.failures | integer | optional | 3 | >=1 | Number of consecutive error requests that triggered an unhealthy state | diff --git a/docs/zh/latest/plugins/api-breaker.md b/docs/zh/latest/plugins/api-breaker.md index 0230fc566e89..5f0f70fe56b2 100644 --- a/docs/zh/latest/plugins/api-breaker.md +++ b/docs/zh/latest/plugins/api-breaker.md @@ -44,6 +44,8 @@ title: api-breaker | 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 | | ----------------------- | -------------- | ------ | ---------- | --------------- | -------------------------------- | | break_response_code | integer | 必须 | 无 | [200, ..., 599] | 不健康返回错误码 | +| break_response_body | string | 可选 | 无 | | 不健康返回报文 | +| break_response_content_type | string | 可选 | application/json | | 不健康返回Content-Type | | max_breaker_sec | integer | 可选 | 300 | >=3 | 最大熔断持续时间 | | unhealthy.http_statuses | array[integer] | 可选 | {500} | [500, ..., 599] | 不健康时候的状态码 | | unhealthy.failures | integer | 可选 | 3 | >=1 | 触发不健康状态的连续错误请求次数 | diff --git a/t/plugin/api-breaker.t b/t/plugin/api-breaker.t index 1dc480cfa2f7..85f3448d01e2 100644 --- a/t/plugin/api-breaker.t +++ b/t/plugin/api-breaker.t @@ -77,7 +77,7 @@ done --- request GET /t --- response_body -{"break_response_code":502,"healthy":{"http_statuses":[200],"successes":3},"max_breaker_sec":300,"unhealthy":{"failures":3,"http_statuses":[500]}} +{"break_response_code":502,"break_response_content_type":"application/json","healthy":{"http_statuses":[200],"successes":3},"max_breaker_sec":300,"unhealthy":{"failures":3,"http_statuses":[500]}} --- no_error_log [error] @@ -104,7 +104,7 @@ GET /t --- request GET /t --- response_body -{"break_response_code":502,"healthy":{"http_statuses":[200],"successes":3},"max_breaker_sec":300,"unhealthy":{"failures":3,"http_statuses":[500]}} +{"break_response_code":502,"break_response_content_type":"application/json","healthy":{"http_statuses":[200],"successes":3},"max_breaker_sec":300,"unhealthy":{"failures":3,"http_statuses":[500]}} --- no_error_log [error] @@ -131,7 +131,7 @@ GET /t --- request GET /t --- response_body -{"break_response_code":502,"healthy":{"http_statuses":[200],"successes":3},"max_breaker_sec":300,"unhealthy":{"failures":3,"http_statuses":[500]}} +{"break_response_code":502,"break_response_content_type":"application/json","healthy":{"http_statuses":[200],"successes":3},"max_breaker_sec":300,"unhealthy":{"failures":3,"http_statuses":[500]}} --- no_error_log [error] @@ -458,6 +458,7 @@ breaker_time: 2 "plugins": { "api-breaker": { "break_response_code": 502, + "break_response_body": "{\"message\":\"breaker opened.\"}", "unhealthy": { "failures": 3 }, @@ -509,6 +510,8 @@ GET /api_breaker?code=500 ] --- error_code eval [200, 500, 503, 500, 500, 502] +--- response_body_like eval +[".*", ".*", ".*", ".*", ".*", "{\"message\":\"breaker opened\"}"] --- no_error_log [error] From 367be74856d0f1c7bf43ff5ae64270efa8b05436 Mon Sep 17 00:00:00 2001 From: qihaiyan Date: Wed, 27 Apr 2022 18:50:48 +0800 Subject: [PATCH 02/11] fix docs's lint error --- docs/en/latest/plugins/api-breaker.md | 2 +- docs/zh/latest/plugins/api-breaker.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/latest/plugins/api-breaker.md b/docs/en/latest/plugins/api-breaker.md index ec1eb6274209..03c6e34ee144 100644 --- a/docs/en/latest/plugins/api-breaker.md +++ b/docs/en/latest/plugins/api-breaker.md @@ -44,7 +44,7 @@ In an unhealthy state, when a request is forwarded to an upstream service and th | Name | Type | Requirement | Default | Valid | Description | | ----------------------- | ------------- | ----------- | -------- | --------------- | --------------------------------------------------------------------------- | | break_response_code | integer | required | | [200, ..., 599] | Return error code when unhealthy | -| break_response_body | string | optional | | | Return reponse body when unhealthy | +| break_response_body | string | optional | | | Return response body when unhealthy | | break_response_content_type | string | optional | application/json | | Return body's content type when unhealthy | | max_breaker_sec | integer | optional | 300 | >=3 | Maximum breaker time(seconds) | | unhealthy.http_statuses | array[integer] | optional | {500} | [500, ..., 599] | Status codes when unhealthy | diff --git a/docs/zh/latest/plugins/api-breaker.md b/docs/zh/latest/plugins/api-breaker.md index 5f0f70fe56b2..ba878283e0e3 100644 --- a/docs/zh/latest/plugins/api-breaker.md +++ b/docs/zh/latest/plugins/api-breaker.md @@ -45,7 +45,7 @@ title: api-breaker | ----------------------- | -------------- | ------ | ---------- | --------------- | -------------------------------- | | break_response_code | integer | 必须 | 无 | [200, ..., 599] | 不健康返回错误码 | | break_response_body | string | 可选 | 无 | | 不健康返回报文 | -| break_response_content_type | string | 可选 | application/json | | 不健康返回Content-Type | +| break_response_content_type | string | 可选 | application/json | | 不健康返回 Content-Type | | max_breaker_sec | integer | 可选 | 300 | >=3 | 最大熔断持续时间 | | unhealthy.http_statuses | array[integer] | 可选 | {500} | [500, ..., 599] | 不健康时候的状态码 | | unhealthy.failures | integer | 可选 | 3 | >=1 | 触发不健康状态的连续错误请求次数 | From 51a7710db1c4ea03f8e50a6d6dead0a0a23c991a Mon Sep 17 00:00:00 2001 From: qihaiyan Date: Thu, 28 Apr 2022 12:48:58 +0800 Subject: [PATCH 03/11] fix error in api-breaker's ut --- t/plugin/api-breaker.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/plugin/api-breaker.t b/t/plugin/api-breaker.t index 85f3448d01e2..bde0e8a25b3e 100644 --- a/t/plugin/api-breaker.t +++ b/t/plugin/api-breaker.t @@ -511,7 +511,7 @@ GET /api_breaker?code=500 --- error_code eval [200, 500, 503, 500, 500, 502] --- response_body_like eval -[".*", ".*", ".*", ".*", ".*", "{\"message\":\"breaker opened\"}"] +[".*", ".*", ".*", ".*", ".*", "{\"message\":\"breaker opened.\"}"] --- no_error_log [error] From 2c2f93738524ab011a70fbf1c996f38e1480d4fb Mon Sep 17 00:00:00 2001 From: HaiYan Date: Thu, 28 Apr 2022 21:52:51 +0800 Subject: [PATCH 04/11] Update apisix/plugins/api-breaker.lua Co-authored-by: tzssangglass --- apisix/plugins/api-breaker.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apisix/plugins/api-breaker.lua b/apisix/plugins/api-breaker.lua index fff23a3a1d4b..b1ed908c902c 100644 --- a/apisix/plugins/api-breaker.lua +++ b/apisix/plugins/api-breaker.lua @@ -167,7 +167,9 @@ function _M.access(conf, ctx) if lasttime + breaker_time >= ngx.time() then if conf.break_response_body then core.response.clear_header_as_body_modified() - ngx.header["Content-Type"] = conf.break_response_content_type + if conf.break_response_content_type then + core.response.set_header("Content-Type", conf.break_response_content_type) + end return conf.break_response_code, conf.break_response_body end return conf.break_response_code From 80aeb8a86a106952ac7c279fd6598bf00df6f8f3 Mon Sep 17 00:00:00 2001 From: qihaiyan Date: Fri, 29 Apr 2022 09:57:49 +0800 Subject: [PATCH 05/11] add test case to cover break_response_content_type --- t/plugin/api-breaker.t | 3 +++ 1 file changed, 3 insertions(+) diff --git a/t/plugin/api-breaker.t b/t/plugin/api-breaker.t index bde0e8a25b3e..89730c0a8228 100644 --- a/t/plugin/api-breaker.t +++ b/t/plugin/api-breaker.t @@ -459,6 +459,7 @@ breaker_time: 2 "api-breaker": { "break_response_code": 502, "break_response_body": "{\"message\":\"breaker opened.\"}", + "break_response_content_type": "application/json+v1", "unhealthy": { "failures": 3 }, @@ -510,6 +511,8 @@ GET /api_breaker?code=500 ] --- error_code eval [200, 500, 503, 500, 500, 502] +--- response_headers eval +["Content-Type: text/plain", "Content-Type: text/html", "Content-Type: text/html", "Content-Type: text/html", "Content-Type: text/html", "Content-Type: application/json+v1"] --- response_body_like eval [".*", ".*", ".*", ".*", ".*", "{\"message\":\"breaker opened.\"}"] --- no_error_log From f623360aa868215b8b57fa88ebab18285aaad0e4 Mon Sep 17 00:00:00 2001 From: HaiYan Date: Fri, 29 Apr 2022 17:35:33 +0800 Subject: [PATCH 06/11] Update docs/en/latest/plugins/api-breaker.md Co-authored-by: Alex Zhang --- docs/en/latest/plugins/api-breaker.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/latest/plugins/api-breaker.md b/docs/en/latest/plugins/api-breaker.md index 03c6e34ee144..4156610b8c80 100644 --- a/docs/en/latest/plugins/api-breaker.md +++ b/docs/en/latest/plugins/api-breaker.md @@ -45,7 +45,7 @@ In an unhealthy state, when a request is forwarded to an upstream service and th | ----------------------- | ------------- | ----------- | -------- | --------------- | --------------------------------------------------------------------------- | | break_response_code | integer | required | | [200, ..., 599] | Return error code when unhealthy | | break_response_body | string | optional | | | Return response body when unhealthy | -| break_response_content_type | string | optional | application/json | | Return body's content type when unhealthy | +| break_response_content_type | string | optional | application/json | | Return body's content type when unhealthy. This field is in effective only if `break_response_body` is configured. | | max_breaker_sec | integer | optional | 300 | >=3 | Maximum breaker time(seconds) | | unhealthy.http_statuses | array[integer] | optional | {500} | [500, ..., 599] | Status codes when unhealthy | | unhealthy.failures | integer | optional | 3 | >=1 | Number of consecutive error requests that triggered an unhealthy state | From e594c34877b741d8121989139187fb6b49d4c976 Mon Sep 17 00:00:00 2001 From: HaiYan Date: Fri, 29 Apr 2022 17:35:49 +0800 Subject: [PATCH 07/11] Update docs/zh/latest/plugins/api-breaker.md Co-authored-by: Alex Zhang --- docs/zh/latest/plugins/api-breaker.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/zh/latest/plugins/api-breaker.md b/docs/zh/latest/plugins/api-breaker.md index ba878283e0e3..50caf238217b 100644 --- a/docs/zh/latest/plugins/api-breaker.md +++ b/docs/zh/latest/plugins/api-breaker.md @@ -45,7 +45,7 @@ title: api-breaker | ----------------------- | -------------- | ------ | ---------- | --------------- | -------------------------------- | | break_response_code | integer | 必须 | 无 | [200, ..., 599] | 不健康返回错误码 | | break_response_body | string | 可选 | 无 | | 不健康返回报文 | -| break_response_content_type | string | 可选 | application/json | | 不健康返回 Content-Type | +| break_response_content_type | string | 可选 | application/json | | 不健康返回报文的内容类型,该字段仅在 `break_response_body` 被配置时生效 | | max_breaker_sec | integer | 可选 | 300 | >=3 | 最大熔断持续时间 | | unhealthy.http_statuses | array[integer] | 可选 | {500} | [500, ..., 599] | 不健康时候的状态码 | | unhealthy.failures | integer | 可选 | 3 | >=1 | 触发不健康状态的连续错误请求次数 | From b345605342a08c144f759380a42938e05e18b8c4 Mon Sep 17 00:00:00 2001 From: qihaiyan Date: Mon, 9 May 2022 21:28:45 +0800 Subject: [PATCH 08/11] adding the headers field to add any response headers --- apisix/plugins/api-breaker.lua | 33 +++++++++++++++++++++------ docs/en/latest/plugins/api-breaker.md | 2 +- docs/zh/latest/plugins/api-breaker.md | 2 +- t/plugin/api-breaker.t | 8 +++---- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/apisix/plugins/api-breaker.lua b/apisix/plugins/api-breaker.lua index b1ed908c902c..00c346fad401 100644 --- a/apisix/plugins/api-breaker.lua +++ b/apisix/plugins/api-breaker.lua @@ -20,6 +20,8 @@ local plugin_name = "api-breaker" local ngx = ngx local math = math local error = error +local ipairs = ipairs + local shared_buffer = ngx.shared["plugin-".. plugin_name] if not shared_buffer then @@ -38,9 +40,19 @@ local schema = { break_response_body = { type = "string" }, - break_response_content_type = { - type = "string", - default = "application/json" + headers = { + type = "array", + items = { + type = "object", + properties = { + key = { + type = "string" + }, + value = { + type = "string" + } + } + } }, max_breaker_sec = { type = "integer", @@ -120,7 +132,12 @@ local _M = { function _M.check_schema(conf) - return core.schema.check(schema, conf) + local ok, err = core.schema.check(schema, conf) + if not ok then + return false, err + end + + return true end @@ -166,9 +183,11 @@ function _M.access(conf, ctx) -- breaker if lasttime + breaker_time >= ngx.time() then if conf.break_response_body then - core.response.clear_header_as_body_modified() - if conf.break_response_content_type then - core.response.set_header("Content-Type", conf.break_response_content_type) + if conf.headers then + for _, value in ipairs(conf.headers) do + local val = core.utils.resolve_var(value.value, ctx.var) + core.response.add_header(value.key, val) + end end return conf.break_response_code, conf.break_response_body end diff --git a/docs/en/latest/plugins/api-breaker.md b/docs/en/latest/plugins/api-breaker.md index 4156610b8c80..0eb57764b32a 100644 --- a/docs/en/latest/plugins/api-breaker.md +++ b/docs/en/latest/plugins/api-breaker.md @@ -45,7 +45,7 @@ In an unhealthy state, when a request is forwarded to an upstream service and th | ----------------------- | ------------- | ----------- | -------- | --------------- | --------------------------------------------------------------------------- | | break_response_code | integer | required | | [200, ..., 599] | Return error code when unhealthy | | break_response_body | string | optional | | | Return response body when unhealthy | -| break_response_content_type | string | optional | application/json | | Return body's content type when unhealthy. This field is in effective only if `break_response_body` is configured. | +| headers | array[object] | optional | | | New headers for the response. The values in the header can contain Nginx variables like `$remote_addr` and `$balancer_ip`. This field is in effective only if `break_response_body` is configured. | | max_breaker_sec | integer | optional | 300 | >=3 | Maximum breaker time(seconds) | | unhealthy.http_statuses | array[integer] | optional | {500} | [500, ..., 599] | Status codes when unhealthy | | unhealthy.failures | integer | optional | 3 | >=1 | Number of consecutive error requests that triggered an unhealthy state | diff --git a/docs/zh/latest/plugins/api-breaker.md b/docs/zh/latest/plugins/api-breaker.md index 50caf238217b..83acfad506d6 100644 --- a/docs/zh/latest/plugins/api-breaker.md +++ b/docs/zh/latest/plugins/api-breaker.md @@ -45,7 +45,7 @@ title: api-breaker | ----------------------- | -------------- | ------ | ---------- | --------------- | -------------------------------- | | break_response_code | integer | 必须 | 无 | [200, ..., 599] | 不健康返回错误码 | | break_response_body | string | 可选 | 无 | | 不健康返回报文 | -| break_response_content_type | string | 可选 | application/json | | 不健康返回报文的内容类型,该字段仅在 `break_response_body` 被配置时生效 | +| headers | array[object] | 可选 | 无 | | 不健康返回报文头,这里可以设置多个。这个值能够以 `$var` 的格式包含 Nginx 变量,比如 `$remote_addr $balancer_ip`。该字段仅在 `break_response_body` 被配置时生效 | | max_breaker_sec | integer | 可选 | 300 | >=3 | 最大熔断持续时间 | | unhealthy.http_statuses | array[integer] | 可选 | {500} | [500, ..., 599] | 不健康时候的状态码 | | unhealthy.failures | integer | 可选 | 3 | >=1 | 触发不健康状态的连续错误请求次数 | diff --git a/t/plugin/api-breaker.t b/t/plugin/api-breaker.t index 89730c0a8228..b0ad3951b31c 100644 --- a/t/plugin/api-breaker.t +++ b/t/plugin/api-breaker.t @@ -77,7 +77,7 @@ done --- request GET /t --- response_body -{"break_response_code":502,"break_response_content_type":"application/json","healthy":{"http_statuses":[200],"successes":3},"max_breaker_sec":300,"unhealthy":{"failures":3,"http_statuses":[500]}} +{"break_response_code":502,"healthy":{"http_statuses":[200],"successes":3},"max_breaker_sec":300,"unhealthy":{"failures":3,"http_statuses":[500]}} --- no_error_log [error] @@ -104,7 +104,7 @@ GET /t --- request GET /t --- response_body -{"break_response_code":502,"break_response_content_type":"application/json","healthy":{"http_statuses":[200],"successes":3},"max_breaker_sec":300,"unhealthy":{"failures":3,"http_statuses":[500]}} +{"break_response_code":502,"healthy":{"http_statuses":[200],"successes":3},"max_breaker_sec":300,"unhealthy":{"failures":3,"http_statuses":[500]}} --- no_error_log [error] @@ -131,7 +131,7 @@ GET /t --- request GET /t --- response_body -{"break_response_code":502,"break_response_content_type":"application/json","healthy":{"http_statuses":[200],"successes":3},"max_breaker_sec":300,"unhealthy":{"failures":3,"http_statuses":[500]}} +{"break_response_code":502,"healthy":{"http_statuses":[200],"successes":3},"max_breaker_sec":300,"unhealthy":{"failures":3,"http_statuses":[500]}} --- no_error_log [error] @@ -459,7 +459,7 @@ breaker_time: 2 "api-breaker": { "break_response_code": 502, "break_response_body": "{\"message\":\"breaker opened.\"}", - "break_response_content_type": "application/json+v1", + "headers": [{"key":"Content-Type","value":"application/json"},{"key":"Content-Type","value":"application/json+v1"}], "unhealthy": { "failures": 3 }, From f2ff4d35d97ffc5813ead95e74b9bf90e9e5ee31 Mon Sep 17 00:00:00 2001 From: qihaiyan Date: Tue, 10 May 2022 09:28:18 +0800 Subject: [PATCH 09/11] revert check_schema --- apisix/plugins/api-breaker.lua | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/apisix/plugins/api-breaker.lua b/apisix/plugins/api-breaker.lua index 00c346fad401..4e4fad89173f 100644 --- a/apisix/plugins/api-breaker.lua +++ b/apisix/plugins/api-breaker.lua @@ -132,12 +132,7 @@ local _M = { function _M.check_schema(conf) - local ok, err = core.schema.check(schema, conf) - if not ok then - return false, err - end - - return true + return core.schema.check(schema, conf) end From 6325416ed82609157fb8b87681d4aa016b5456a9 Mon Sep 17 00:00:00 2001 From: HaiYan Date: Tue, 10 May 2022 11:34:05 +0800 Subject: [PATCH 10/11] Update apisix/plugins/api-breaker.lua MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 罗泽轩 --- apisix/plugins/api-breaker.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apisix/plugins/api-breaker.lua b/apisix/plugins/api-breaker.lua index 4e4fad89173f..855a9c1d7934 100644 --- a/apisix/plugins/api-breaker.lua +++ b/apisix/plugins/api-breaker.lua @@ -40,7 +40,7 @@ local schema = { break_response_body = { type = "string" }, - headers = { + break_response_headers = { type = "array", items = { type = "object", From e207ca0c99d96b8ff249445700931025b67e67f1 Mon Sep 17 00:00:00 2001 From: qihaiyan Date: Tue, 10 May 2022 11:46:47 +0800 Subject: [PATCH 11/11] change headers attribute to break_response_headers --- apisix/plugins/api-breaker.lua | 10 ++++++---- docs/en/latest/plugins/api-breaker.md | 2 +- docs/zh/latest/plugins/api-breaker.md | 2 +- t/plugin/api-breaker.t | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/apisix/plugins/api-breaker.lua b/apisix/plugins/api-breaker.lua index 855a9c1d7934..5ccf4404082a 100644 --- a/apisix/plugins/api-breaker.lua +++ b/apisix/plugins/api-breaker.lua @@ -46,10 +46,12 @@ local schema = { type = "object", properties = { key = { - type = "string" + type = "string", + minLength = 1 }, value = { - type = "string" + type = "string", + minLength = 1 } } } @@ -178,8 +180,8 @@ function _M.access(conf, ctx) -- breaker if lasttime + breaker_time >= ngx.time() then if conf.break_response_body then - if conf.headers then - for _, value in ipairs(conf.headers) do + if conf.break_response_headers then + for _, value in ipairs(conf.break_response_headers) do local val = core.utils.resolve_var(value.value, ctx.var) core.response.add_header(value.key, val) end diff --git a/docs/en/latest/plugins/api-breaker.md b/docs/en/latest/plugins/api-breaker.md index 0eb57764b32a..9f561c9145f2 100644 --- a/docs/en/latest/plugins/api-breaker.md +++ b/docs/en/latest/plugins/api-breaker.md @@ -45,7 +45,7 @@ In an unhealthy state, when a request is forwarded to an upstream service and th | ----------------------- | ------------- | ----------- | -------- | --------------- | --------------------------------------------------------------------------- | | break_response_code | integer | required | | [200, ..., 599] | Return error code when unhealthy | | break_response_body | string | optional | | | Return response body when unhealthy | -| headers | array[object] | optional | | | New headers for the response. The values in the header can contain Nginx variables like `$remote_addr` and `$balancer_ip`. This field is in effective only if `break_response_body` is configured. | +| break_response_headers | array[object] | optional | | | New headers for the response. The values in the header can contain Nginx variables like `$remote_addr` and `$balancer_ip`. This field is in effective only if `break_response_body` is configured. | | max_breaker_sec | integer | optional | 300 | >=3 | Maximum breaker time(seconds) | | unhealthy.http_statuses | array[integer] | optional | {500} | [500, ..., 599] | Status codes when unhealthy | | unhealthy.failures | integer | optional | 3 | >=1 | Number of consecutive error requests that triggered an unhealthy state | diff --git a/docs/zh/latest/plugins/api-breaker.md b/docs/zh/latest/plugins/api-breaker.md index 83acfad506d6..6672f8d4fa44 100644 --- a/docs/zh/latest/plugins/api-breaker.md +++ b/docs/zh/latest/plugins/api-breaker.md @@ -45,7 +45,7 @@ title: api-breaker | ----------------------- | -------------- | ------ | ---------- | --------------- | -------------------------------- | | break_response_code | integer | 必须 | 无 | [200, ..., 599] | 不健康返回错误码 | | break_response_body | string | 可选 | 无 | | 不健康返回报文 | -| headers | array[object] | 可选 | 无 | | 不健康返回报文头,这里可以设置多个。这个值能够以 `$var` 的格式包含 Nginx 变量,比如 `$remote_addr $balancer_ip`。该字段仅在 `break_response_body` 被配置时生效 | +| break_response_headers | array[object] | 可选 | 无 | | 不健康返回报文头,这里可以设置多个。这个值能够以 `$var` 的格式包含 Nginx 变量,比如 `$remote_addr $balancer_ip`。该字段仅在 `break_response_body` 被配置时生效 | | max_breaker_sec | integer | 可选 | 300 | >=3 | 最大熔断持续时间 | | unhealthy.http_statuses | array[integer] | 可选 | {500} | [500, ..., 599] | 不健康时候的状态码 | | unhealthy.failures | integer | 可选 | 3 | >=1 | 触发不健康状态的连续错误请求次数 | diff --git a/t/plugin/api-breaker.t b/t/plugin/api-breaker.t index b0ad3951b31c..e1eccfb2b6b1 100644 --- a/t/plugin/api-breaker.t +++ b/t/plugin/api-breaker.t @@ -459,7 +459,7 @@ breaker_time: 2 "api-breaker": { "break_response_code": 502, "break_response_body": "{\"message\":\"breaker opened.\"}", - "headers": [{"key":"Content-Type","value":"application/json"},{"key":"Content-Type","value":"application/json+v1"}], + "break_response_headers": [{"key":"Content-Type","value":"application/json"},{"key":"Content-Type","value":"application/json+v1"}], "unhealthy": { "failures": 3 },