如何设置熔断规则
安装完成后,可以看到集群中增加了下面两个 NS,这两个 NS 中分别安装了基于 MetaProtocol 实现的 Dubbo 和 Thrift 协议的示例程序。 你可以选用任何一个程序进行测试。
apiVersion: apps/v1
kind: Deployment
metadata:
name: thrift-sample-server-fake
namespace: meta-thrift
labels:
app: thrift-sample-server
spec:
selector:
matchLabels:
app: thrift-sample-server
replicas: 1
metadata:
annotations:
sidecar.istio.io/proxyImage: aeraki/meta-protocol-proxy:1.0.1
sidecar.istio.io/rewriteAppHTTPProbers: "false"
labels:
app: thrift-sample-server
spec:
containers:
- name: thrift-sample-server
image: nginx
ports:
- containerPort: 9090
EOF
现在 thrift-sample-server service 中有三个 endpoint,其中 thrift-sample-server-fake 这个 deployment 中没有 thrift sample server,因此其对应的 endpoint “172.19.0.102” 并不能处理客户端的请求。从客户端的日志中可以看到每三次请求中就有一次错误信息:
kubectl apply -f- <<EOF
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
namespace: meta-thrift
spec:
host: thrift-sample-server
trafficPolicy:
outlierDetection:
baseEjectionTime: 15m
consecutive5xxErrors: 5
interval: 5m
EOF
此时查看客户端的输出,可以看到客户端在熔断规则指定的错误次数后,不再将请求发送到出错的 endpoint “172.19.0.102”。
aerakictl_sidecar_stats client meta-thrift|grep -i outlier
cluster.outbound|9090||thrift-sample-server.meta-thrift.svc.cluster.local.outlier_detection.ejections_active: 1
cluster.outbound|9090||thrift-sample-server.meta-thrift.svc.cluster.local.outlier_detection.ejections_consecutive_5xx: 1
cluster.outbound|9090||thrift-sample-server.meta-thrift.svc.cluster.local.outlier_detection.ejections_detected_consecutive_5xx: 1
cluster.outbound|9090||thrift-sample-server.meta-thrift.svc.cluster.local.outlier_detection.ejections_enforced_consecutive_5xx: 1
luster.outbound|9090||thrift-sample-server.meta-thrift.svc.cluster.local.outlier_detection.ejections_enforced_total: 1