配置故障注入
混沌工程对于构建可靠系统至关重要。fault-injection 插件可以在请求到达上游服务之前,在网关层模拟故障和延迟,从而测试应用的韧性。
前置条件
- API7 企业版实例正在运行。
- 已创建网关组且网关实例正在运行。
- 按照从控制台获取令牌中的步骤准备一个令牌。
配置 HTTP 中止
可以对一定比例的请求返回指定 HTTP 状态码,以模拟服务故障。
- Admin API
- ADC
curl -k "https://localhost:7443/apisix/admin/services/fault-injection-service?gateway_group_id={gateway_group_id}" -X PUT \
-H "X-API-KEY: ${API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"name": "fault-injection-service",
"upstream": {
"type": "roundrobin",
"scheme": "http",
"nodes": [
{
"host": "httpbin.org",
"port": 80,
"weight": 100
}
]
}
}'
curl -k "https://localhost:7443/apisix/admin/routes/fault-injection-route?gateway_group_id={gateway_group_id}" -X PUT \
-H "X-API-KEY: ${API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"name": "fault-injection-route",
"paths": ["/get"],
"service_id": "fault-injection-service",
"plugins": {
"fault-injection": {
"abort": {
"http_status": 503,
"body": "Service Temporarily Unavailable",
"percentage": 10
}
}
}
}'
adc.yaml
services:
- name: fault-injection-service
upstream:
nodes:
- host: httpbin.org
port: 80
weight: 1
routes:
- name: fault-injection-route
uris:
- /get
plugins:
fault-injection:
abort:
http_status: 503
body: "Service Temporarily Unavailable"
percentage: 10
adc sync -f adc.yaml