istio - Istio Sidecar to retry on specified status codes (503)
问题描述
By default, if we don't define any VirtualService
, Istio will generate something like the following Envoy route/retry configuration:
{
"cluster": "outbound|9100||quote-svc-cip.quote.svc.cluster.local",
"timeout": "0s",
"retry_policy": {
"retry_on": "connect-failure,refused-stream,unavailable,cancelled,retriable-status-codes",
"num_retries": 2,
"retry_host_predicate": [
{
"name": "envoy.retry_host_predicates.previous_hosts"
}
],
"host_selection_retry_max_attempts": "5",
"retriable_status_codes": [
503
]
},
"max_grpc_timeout": "0s"
}
But if we specify our own VirtualService
, e.g.:
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: book-svc-cip
namespace: book
spec:
hosts:
- book-svc-cip.book.svc.cluster.local
http:
- retries:
attempts: 3
retryOn: connect-failure,refused-stream,unavailable,retriable-status-codes
route:
- destination:
host: book-svc-cip.book.svc.cluster.local
The generated config will look like:
{
"cluster": "outbound|9281||book-svc-cip.book.svc.cluster.local",
"timeout": "0s",
"retry_policy": {
"retry_on": "connect-failure,refused-stream,unavailable,retriable-status-codes",
"num_retries": 3,
"retry_host_predicate": [
{
"name": "envoy.retry_host_predicates.previous_hosts"
}
],
"host_selection_retry_max_attempts": "5"
},
"max_grpc_timeout": "0s"
}
Notice that the retriable_status_codes
is missing.
For the default, looks like it's defined in https://github.com/istio/istio/blob/1.9.0/pilot/pkg/networking/core/v1alpha3/route/retry/retry.go#L38-L39. But there is no option/field to configure retriable_status_codes
via VirtualService
.
How could we define the retriable_status_codes
in Istio?
Update #1: My Istio version is 1.6.9
. But if any newer version can support it, it's also appreciated.
解决方案
The example in the documentation should work (according to the source code); I can verify it works on a later version.
https://istio.io/latest/docs/reference/config/networking/virtual-service/#HTTPRetry
retries:
attempts: 3
perTryTimeout: 2s
retryOn: connect-failure,refused-stream,503
The source code for 1.6.9 shows that the above example should work
推荐阅读
- c# - 如何通过发送 OAuthPrompt 与用户开始 1:1 对话
- spring-boot - 升级的 Spring boot:现在从 JDBC 和 JOOQ 中得到“坏 SQL 语法”错误
- javascript - 如何增加 html 画布的宽度并在画布左侧获取新空间
- python-3.6 - python3.6中的SMTP库问题
- r - 如何根据`dbplyr`上的日期在数据帧上留下连接
- pyspark - 如何在 Pyspark 数据框中使用长度拆分和 MaxSplit 拆分列?
- angular - 如何使用打字稿附加innerhtml
- visual-studio - 适用于 Visual Studio 2019 的 Intellij Pycharm 皮肤
- authentication - 如何使用 OTP 请求使用 AADHAR 身份验证 API
- r - 尝试在 R 中解析 bencode / torrent 文件