HTTP请求重试条件
-
重试条件(同x-envoy-retry-on标头)
-
5xx:上游主机返回5xx响应码,或者根本未予响应(断开/重置/读取超时)
-
gateway-error:网关错误,类似于5xx策略,但仅为502、503或504的应用进行重试
-
connection-failure:在TCP级别与上游服务建立连接失败时进行重试
-
retriable-4xx:上游服务器返回可重复的4xx响应码时进行重试
-
refused-stream:上游服器务使用REFUSED——STREAM错误码重置时进行重试
-
retriable-status-codes:上游服务器的响应码与重试策略或x-envoy-retriable-status-codes标头值中定义的响应码匹配时进行重试
-
reset:上游主机完全不响应时(disconnect/reset/read超时),Envoy将进行重试;
-
retriable-headers:如果上游服务器响应报文匹配重试策略或 x-envoy-retriable-header-names标头中包含的任何标头,则Envoy将尝试重试
-
envoy-ratelimited:标头中存在x-envoy-ratelimited时进行重试
-
-
重试条件2(同x-envoy-retry-grpc-on标头)
-
cancelled:gRPC应答标头中的状态码是“cancelled”时进行重试
-
deadline-exceeded:gRPC应答标头中的状态码是“deadline-exceeded”时进行重试
-
internal:gRPC应答标头中的状态码是“internal”时进行重试
-
resource-exhausted:gRPC应答标头中的状态码是“resource-exhausted”时进行重试
-
unavailable:gRPC应答标头中的状态码是“unavailable”时进行重试
-
-
默认情况下,Envoy不会进行任何类型的重试操作,除非明确定义
virtualservice-proxy.yaml
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: proxy
spec:
hosts:
- "app.wgs.com" # 对应于gateways/proxy-gateway
- "proxy"
- "proxy.default.svc"
gateways:
- istio-system/proxy-gateway # 相关定义仅应用于Ingress Gateway上
#- mesh
http:
- name: default
route:
- destination:
host: proxy
timeout: 1s
retries:
attempts: 5
perTryTimeout: 1s
retryOn: 5xx,connect-failure,refused-stream
virtualservice-demoapp.yaml
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: demoapp
spec:
hosts:
- demoapp
http:
- name: canary
match:
- uri:
prefix: /canary
rewrite:
uri: /
route:
- destination:
host: demoapp
subset: v11
fault:
abort:
percentage:
value: 50
httpStatus: 555
- name: default
route:
- destination:
host: demoapp
subset: v10
fault:
delay:
percentage:
value: 50
fixedDelay: 3s
更新demoapp svc
# kubectl apply -f virtualservice-demoapp.yaml -f virtualservice-proxy.yaml
virtualservice.networking.istio.io/demoapp configured
virtualservice.networking.istio.io/proxy configured
访问demoapp
测试超时
upstream request timeout
~# while true;do curl app.wgs.com;sleep 0.5;done
upstream request timeoutProxying value: iKubernetes demoapp v1.0 !! ClientIP: 127.0.0.6, ServerName: demoappv10-78b6586d58-kdv4m, ServerIP: 172.20.154.195!
- Took 5 milliseconds.
Proxying value: iKubernetes demoapp v1.0 !! ClientIP: 127.0.0.6, ServerName: demoappv10-78b6586d58-kdv4m, ServerIP: 172.20.154.195!
- Took 5 milliseconds.
upstream request timeoutupstream request timeoutupstream request timeoutProxying value: iKubernetes demoapp v1.0 !! ClientIP: 127.0.0.6, ServerName: demoappv10-78b6586d58-kdv4m, ServerIP: 172.20.154.195!
- Took 4 milliseconds.
upstream request timeoutProxying value: iKubernetes demoapp v1.0 !! ClientIP: 127.0.0.6, ServerName: demoappv10-78b6586d58-kdv4m, ServerIP: 172.20.154.195!
- Took 4 milliseconds.
image
测试中断
~# while true;do curl app.wgs.com/canary;sleep 0.5;done
Proxying value: fault filter abort - Took 2 milliseconds.
Proxying value: iKubernetes demoapp v1.1 !! ClientIP: 127.0.0.6, ServerName: demoappv11-78bf898c74-hckjf, ServerIP: 172.20.89.189!
- Took 4 milliseconds.
Proxying value: iKubernetes demoapp v1.1 !! ClientIP: 127.0.0.6, ServerName: demoappv11-78bf898c74-hckjf, ServerIP: 172.20.89.189!
- Took 4 milliseconds.
Proxying value: iKubernetes demoapp v1.1 !! ClientIP: 127.0.0.6, ServerName: demoappv11-78bf898c74-hckjf, ServerIP: 172.20.89.189!
- Took 5 milliseconds.
Proxying value: iKubernetes demoapp v1.1 !! ClientIP: 127.0.0.6, ServerName: demoappv11-78bf898c74-hckjf, ServerIP: 172.20.89.189!
- Took 4 milliseconds.
Proxying value: iKubernetes demoapp v1.1 !! ClientIP: 127.0.0.6, ServerName: demoappv11-78bf898c74-hckjf, ServerIP: 172.20.89.189!
- Took 5 milliseconds.
Proxying value: iKubernetes demoapp v1.1 !! ClientIP: 127.0.0.6, ServerName: demoappv11-78bf898c74-sn9qp, ServerIP: 172.20.154.253!
- Took 3 milliseconds.
Proxying value: fault filter abort - Took 4 milliseconds.
Proxying value: fault filter abort - Took 2 milliseconds.
Proxying value: fault filter abort - Took 2 milliseconds.
Proxying value: iKubernetes demoapp v1.1 !! ClientIP: 127.0.0.6, ServerName: demoappv11-78bf898c74-hckjf, ServerIP: 172.20.89.189!
- Took 4 milliseconds.
Proxying value: fault filter abort - Took 2 milliseconds.
Proxying value: iKubernetes demoapp v1.1 !! ClientIP: 127.0.0.6, ServerName: demoappv11-78bf898c74-hckjf, ServerIP: 172.20.89.189!
- Took 4 milliseconds.
Proxying value: iKubernetes demoapp v1.1 !! ClientIP: 127.0.0.6, ServerName: demoappv11-78bf898c74-sn9qp, ServerIP: 172.20.154.253!
- Took 4 milliseconds.
image
参考文档
https://istio.io/latest/zh/docs/reference/config/networking/virtual-service/#HTTPRetry
网友评论