istio 故障注入
参照 istio 官方文档的 故障注入章节open in new window,生成如下配置:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: dhcp-cn
namespace: dhcp-cn
...
spec:
hosts:
- dhcp.cn
gateways:
- dhcp-cn/dhcp-cn-ipv6
http:
- match:
- uri:
exact: /demo/isito/fault-injection
route:
- destination:
host: dhcp.dhcp-cn.svc.cluster.local
port:
number: 80
fault:
delay:
fixedDelay: 500ms
percentage:
value: 50
abort:
httpStatus: 333
percentage:
value: 50
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
当访问 https://dhcp.cn/demo/isito/fault-injection
会有 50% 的流量到 注入 HTTP 延迟故障
(延迟 500ms),另外 50%流量到 注入 HTTP abort 故障
(设置返回码为 333)
使用 curl 测试一下,第一次请求的流量是 HTTP 延迟故障,耗时 0.8s,返回码 404 是因为该 URL 不存在(符合预期)。
$ time curl https://dhcp.cn/demo/isito/fault-injection -I
HTTP/2 404
server: istio-envoy
date: Sun, 27 Feb 2022 02:27:40 GMT
content-type: text/html
content-length: 153
x-envoy-upstream-service-time: 1
real 0m0.806s
user 0m0.015s
sys 0m0.006s
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
再次请求时,返回码为 333,耗时0.07s,符合预期。
$ time curl https://dhcp.cn/demo/isito/fault-injection -I
HTTP/2 333
content-length: 18
content-type: text/plain
date: Sun, 27 Feb 2022 02:27:43 GMT
server: istio-envoy
real 0m0.070s
user 0m0.016s
sys 0m0.006s
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11