Fault Injection(0.8)

这个课题展示如果为你地应用注入延迟并进行弹性测试。

Before you begin

  • 按照 Installation guide 指南安装Istio。
  • 部署 Bookinfo 示例应用。
  • 通过首先完成 request routing 课题或运行如下命令来初始化应用版本路由:
istioctl create -f samples/bookinfo/routing/route-rule-all-v1.yaml
istioctl replace -f samples/bookinfo/routing/route-rule-reviews-test-v2.yaml

samples/bookinfo/routing/route-rule-all-v1.yaml

samples/bookinfo/routing/route-rule-reviews-test-v2.yaml

Fault injection using HTTP delay

为了测试我们的Bookinfo微服务应用的弹性,我们将针对用户ratings 在reviews:v2和ratings 微服务之间注入7s延迟。因为 reviews:v2 服务有10s的超时时间去调用ratings服务,我们期望这种端对端的流能够没有任何错误的继续下去。
1.为来自用户 “jason” (我们的测试用户)的流量创建一个故障注入规则来延迟访问

istioctl replace -f samples/bookinfo/routing/route-rule-ratings-test-delay.yaml

samples/bookinfo/routing/route-rule-ratings-test-delay.yaml

确认创建的规则:

istioctl get virtualservice ratings -o yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: ratings
  ...
spec:
  hosts:
  - ratings
  http:
  - fault:
      delay:
        fixedDelay: 7s
        percent: 100
    match:
    - headers:
        cookie:
          regex: ^(.*?;)?(user=jason)(;.*)?$
    route:
    - destination:
        host: ratings
        subset: v1
  - route:
    - destination:
        host: ratings
        subset: v1

为账户的规则延迟传播到所有pods而等待几秒。

2.观察应用行为
以用户 “jason” 登陆,如果应用的前端页面正确的处理延时,我们期望大约加载7s。为了观察页面响应时间,开放开发者工具菜单的IE、Chrome或Firefox(通常,命令组合 Ctrl+Shift+I or Alt+Cmd+I )、tag Network,和重新加载 productpage 的网页。
你可能会观察到网页加载了大约6s。评论部分将展示: Sorry, product reviews are currently unavailable for this book.

Understanding what happened

整个reviews服务失败的原因是我们的Bookinfo应用有一个bug。在productpagereviews 服务间的超时时间(3s + 1 retry = 6s total)低于reviewsratings 服务之间的超时时间 (10s)。这种bug发生在典型由不同队伍分别开发不同微服务的企业应用。Istio的故障注入规则在不影响终端用户的情况下,帮助你确认这种反常现象。

注意: 我们限制失败仅影响用户“jason”,如果你用其他用户登陆,将不会体验任何延迟。

Fixing the bug: 这种情况下,我们通常通过增加productpage 的超时时间或减少reviewsratings 服务的超时时间,中止并重启修复后的微服务,然后确认productpage 返回中没有返回带任何错误的响应来修复这个问题。
然而,我们已经在reviews服务的v3版本中修复了,因此我们可以按照 traffic shifting 中的描述简单的通过迁移所有流量到 reviews:v3 来解决这个问题。
(留给读者练习-将延迟规则更改为使用2.8s延迟,然后针对v3的评论运行延迟规则。)

Fault injection using HTTP Abort

如其他弹性测试,我们继续使用用户“jason”访问ratings 这个服务来介绍HTTP 中断。我们希望页面立刻加载,不像延迟示例,并展示“product ratings not available” 信息。

1.为用户“jason”创建故障注入规则去发送一个HTTP中断。

istioctl replace -f samples/bookinfo/routing/route-rule-ratings-test-abort.yaml

samples/bookinfo/routing/route-rule-ratings-test-abort.yaml

确认规则被创建:

istioctl get virtualservice ratings -o yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: ratings
  ...
spec:
  hosts:
  - ratings
  http:
  - fault:
      abort:
        httpStatus: 500
        percent: 100
    match:
    - headers:
        cookie:
          regex: ^(.*?;)?(user=jason)(;.*)?$
    route:
    - destination:
        host: ratings
        subset: v1
  - route:
    - destination:
        host: ratings
        subset: v1

2.观察应用行为
以用户 “jason”登陆。如果规则成功传播到所有pods,你将会看看到页面立刻加载,并带有“product ratings not available” 信息。登出 “jason”用户,你应该会看到productpage 网页中成功展示带有星际评定的reviews。

Cleanup

  • 清除应用路由规则
istioctl delete -f samples/bookinfo/routing/route-rule-all-v1.yaml

samples/bookinfo/routing/route-rule-all-v1.yaml

  • 如果你不打算探索接下来地任何课题,参考 Bookinfo cleanup 指南来关闭应用。

猜你喜欢

转载自blog.csdn.net/ybt_c_index/article/details/80737233