03-故障注入

Catalogue
  1. 1. 准备前提
  2. 2. 配置延时
  3. 3. 发生场景
  4. 4. 解决方案
  5. 5. 参考资料

准备前提

该演示还是采用bookinfo项目,状态为《02-流量管理-03-故障注入》完成后的状态,请求流如下:

  • productpagereviews:v2ratings (only for user jason)
  • productpagereviews:v1 (for everyone else)

配置延时

如下配置为ratings设置了一个7秒的延时,只对登录的jason用户有效

  • virtual-service-ratings-test-delay.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: ratings
spec:
hosts:
- ratings
http:
- match:
- headers:
end-user:
exact: jason
fault:
delay:
percent: 100
fixedDelay: 7s
route:
- destination:
host: ratings
subset: v1
- route:
- destination:
host: ratings
subset: v1
  • 其他服务已知相关配置
  1. reviews-v2调用ratings是有一个10秒的调用超时
  2. productpage调用review有一个3秒的超时配置和1次重试,共6秒
  • 访问测试
  1. 访问:http://bookinfo.example.com/productpage,首页实时响应,无星图标
  2. 使用jason登录后,大约经过6秒,评论区显示如下:
1
2
Error fetching product reviews!
Sorry, product reviews are currently unavailable for this book.

发生场景

此类错误可能发生在典型的企业应用程序中,其中不同的团队独立开发不同的微服务。 Istio的故障注入规则可帮助您识别此类异常而不会影响最终用户。

解决方案

  1. 传统方法:使下游服务超时时间小于上游服务
  2. 采用故障注入
  • virtual-service-ratings-test-abort.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: ratings
spec:
hosts:
- ratings
http:
- match:
- headers:
end-user:
exact: jason
fault:
abort:
percent: 100
httpStatus: 500
route:
- destination:
host: ratings
subset: v1
- route:
- destination:
host: ratings
subset: v1
  • 访问测试
  1. 访问:http://bookinfo.example.com/productpage,首页实时响应,无星图标
  2. 使用jason登录后,也实时响应,productPage调用review正常,ratings服务直接显示如下:
1
Ratings service is currently unavailable
  1. 对比之前,由于ratings的延时,导致了review也调用失败,此时只有ratings失败。

参考资料