1 Star 0 Fork 166

silence_war / Apache APISIX incubating

forked from iresty / Apache APISIX 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
fault-injection.md 3.58 KB
一键复制 编辑 原始数据 按行查看 历史

Chinese

Name

Fault injection plugin, this plugin can be used with other plugins and will be executed before other plugins. The abort attribute will directly return the user-specified http code to the client and terminate the subsequent plugins. The delay attribute will delay a request and execute subsequent plugins.

Attributes

Name Requirement Description
abort.http_status required user-specified http code returned to the client
abort.body optional response data returned to the client
delay.duration required delay time(can be decimal)

Note: abort and delay must have at least one.

How To Enable

Enable the plugin

1: enable the fault-injection plugin for a specific route and specify the abort attribute:

curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "plugins": {
       "fault-injection": {
           "abort": {
              "http_status": 200,
              "body": "Fault Injection!"
           }
       }
    },
    "upstream": {
       "nodes": {
           "127.0.0.1:1980": 1
       },
       "type": "roundrobin"
    },
    "uri": "/hello"
}'

Test plugin:

$ curl http://127.0.0.1:9080/hello -i
HTTP/1.1 200 OK
Date: Mon, 13 Jan 2020 13:50:04 GMT
Content-Type: text/plain
Transfer-Encoding: chunked
Connection: keep-alive
Server: APISIX web server

Fault Injection!

http status is 200 and the response body is "Fault Injection! " indicate that the plugin is enabled.

2: Enable the fault-injection plugin for a specific route and specify the delay attribute:

curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "plugins": {
       "fault-injection": {
           "delay": {
              "duration": 3
           }
       }
    },
    "upstream": {
       "nodes": {
           "127.0.0.1:1980": 1
       },
       "type": "roundrobin"
    },
    "uri": "/hello"
}'

Test plugin:

$ time curl http://127.0.0.1:9080/hello -i
HTTP/1.1 200 OK
Content-Type: application/octet-stream
Content-Length: 6
Connection: keep-alive
Server: APISIX web server
Date: Tue, 14 Jan 2020 14:30:54 GMT
Last-Modified: Sat, 11 Jan 2020 12:46:21 GMT

hello

real    0m3.034s
user    0m0.007s
sys     0m0.010s

Disable Plugin

Remove the corresponding JSON in the plugin configuration to disable the plugin immediately without restarting the service:

curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "uri": "/hello",
    "plugins": {},
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "127.0.0.1:1980": 1
        }
    }
}'

The plugin has been disabled now.

Lua
1
https://gitee.com/silence_war/apisix.git
git@gitee.com:silence_war/apisix.git
silence_war
apisix
Apache APISIX incubating
master

搜索帮助