IT七剑客 IT七剑客
首页
wresource
郭霖
孤寒者
IT邦德
沉默王二
老麦
stackoverflow
GitHub (opens new window)
首页
wresource
郭霖
孤寒者
IT邦德
沉默王二
老麦
stackoverflow
GitHub (opens new window)
  • 从零开始写 k8s 发布工具(一)

  • 从零开始写 k8s 发布工具(二)

  • 从零开始写 k8s 发布工具(三)

  • 从零开始写 k8s 发布工具(四)

  • istio的环境准备

  • istioVirtualService

    • vs-and-ingress
    • gateway
    • vs-http-rewrite-by-uri
    • dr-subset
    • vs-http-rewrite-by-header
    • vs-http-redirect
    • vs-http-retry
    • vs-http-fault-injection
      • Http Fault Injection Delay 延迟
      • Http Fault Injection Abort 中止
      • 案例
    • vs-http-delegate
    • vs-http-header-operation
    • gw-https-support-standard
    • dr-simple-loadbalance
  • 老麦 Go
  • istioVirtualService
老麦
2023-02-01
目录

vs-http-fault-injection

# VirtualService 混沌测试/错误注入

在 Istio 中还实现了一个很重要的功能: 错误注入。 可以设置 一定几率 出现 延迟(delay) 和 中止(abort) 错误。

# Http Fault Injection Delay 延迟

一定概率出现 缓慢 相应。

  1. fixedDelay: 延迟时间。 格式 1h / 1m / 1s。 最小 1ms。
  2. percentage: 错误触发几率。 0-100 之间。 可以为 double 类型的小数。
---
# fault injection
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: review-fault-injection
spec:
  hosts:
    - svc-review
  http:
    - match:
      route:
        - destination:
            host: svc-review
      fault:
        delay:
          percentage:
            value: 50
          fixedDelay: 5s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# Http Fault Injection Abort 中止

一定概率出现 中止 相应, 并返回错误响应 http code

  1. httpStatus: 错误响应 http code。
  2. percentage: 错误触发几率。 0-100 之间。 可以为 double 类型的小数。
---
# fault injection
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: review-fault-injection
spec:
  hosts:
    - svc-review
  http:
    - match:
      route:
        - destination:
            host: svc-review
      fault:
        abort:
          percentage:
            value: 50
          httpStatus: 400
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# 案例

在本案例中

  1. srv-review 对 user 不可见
  2. 请求过程
    • (1) user 请求 srv-prod 时。
    • (2) srv-prod 根据请求参数 srv-review 获取对应的 review 信息
    • (3) srv-review 返回应答给 srv-prod
    • (4) srv-prod 组合应答信息,统一返回 user

除了上述提到的 srv-review 的错误注入。

还在 prod 的 VirtualService 上使用了 timeout 参数, 当总请求超过 3秒 的时候, 将会出现 request timeout 错误; 如果不加此参数,会在 延迟5秒 后得到正确相应结果。

# normal prod
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: vs-prod
spec:
  gateways:
    - istio-tangx-in
  hosts:
    - svc-prod
    - istio.tangx.in
  
  http:
    - match:
      route:
        - destination:
            host: svc-prod
      timeout: 3s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

测试请求与结果如下。

# 正常请求
time curl http://istio.tangx.in/prod/list

    {"data":{"Name":"istio in action","Price":300,"Reviews":{"1":{"id":"1","name":"zhangsan","commment":"istio 功能很强大, 就是配置太麻烦"},"2":{"id":"1","name":"wangwu","commment":"《istio in action》 真是一本了不起的书"}}},"version":"v1.1.0"}

    real    0m0.011s
    user    0m0.004s
    sys     0m0.005s

# 延迟5秒。 3秒请求超时
time curl http://istio.tangx.in/prod/list

    upstream request timeout

    real    0m3.014s
    user    0m0.004s
    sys     0m0.005s

# 相应中止
time curl http://istio.tangx.in/prod/list

    {"error":"Error: svc-review request abort. resp code is 400, failed","message":"获取评论失败, 内部错误"}

    real	0m0.011s
    user	0m0.005s
    sys	0m0.004s
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
编辑 (opens new window)
上次更新: 2023/02/05, 02:48:13
vs-http-retry
vs-http-delegate

← vs-http-retry vs-http-delegate→

最近更新
01
Coding 102 Writing code other people can read
02-26
02
Kotlin Flow响应式编程,StateFlow和SharedFlow
02-05
03
Kotlin Flow响应式编程,操作符函数进阶
02-05
更多文章>
Theme by Vdoing | Copyright © 2022-2023 IT七剑客 | MIT License
  • 闽ICP备2021006579号-4
  • 闽公网安备 35012102500470号
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式