Istioのタイムアウト・リトライのデフォルト値
Istioのタイムアウト・リトライのデフォルト値が気になって調べた。
結論
タイムアウトは15sec。リトライは1回。5xx、タイムアウトなど一般的にリトライしていい状況であればリトライする。
それぞれHTTPHeaderで挙動を上書き可能
Istio
Istioにはタイムアウト、リトライを制御する仕組みがあり、それはx-envoy-upstream-rq-timeout-ms、x-envoy-max-retriesという2つのHTTPヘッダーでデフォルト値を上書きできると書いてある。
リトライ
envoyのx-envoy-max-retriesのデフォルト値を調べる https://www.envoyproxy.io/docs/envoy/latest/configuration/http_filters/router_filter#x-envoy-max-retries
Envoy will default to retrying one time unless explicitly specified
とあるので1回
タイムアウト
x-envoy-upstream-rq-timeout-msを調べる
Setting this header on egress requests will cause Envoy to override the route configuration.
route configuration を上書きするために利用すると書いてあるので、route configurationを調べる。
Specifies the upstream timeout for the route. If not specified, the default is 15s. This spans between the point at which the entire downstream request (i.e. end-of-stream) has been processed and when the upstream response has been completely processed.
デフォルトは15秒
いつリトライするのか
envoyはx-envoy-retry-onというヘッダーでどのステータスコードのときにリトライするのかを設定することができる。 https://www.envoyproxy.io/docs/envoy/latest/configuration/http_filters/router_filter#config-http-filters-router-x-envoy-retry-on
Istioのドキュメントにはなかったが、検索してみたところIssueを発見した。 github.com 1.0時点では、ハードコードされていたが、x-retry-onヘッダーを受け付けるようになったらしい。
ちなみに、1.1時点のデフォルト値は
policy := route.RetryPolicy{ NumRetries: &types.UInt32Value{Value: 2}, RetryOn: "connect-failure,refused-stream,unavailable,cancelled,resource-exhausted,retriable-status-codes", RetriableStatusCodes: []uint32{http.StatusServiceUnavailable},
https://github.com/istio/istio/blob/28f2fbbbb0bb4910130b3362cc18c780e1fac87b/pilot/pkg/networking/core/v1alpha3/route/retry/retry.go#L33 となっています。5xx, タイムアウトなどリトライしてもよさそうな状況では基本的にはリトライする、と認識しておけばよさそうです。
connect-failureなどのそれぞれの定義はこちらにあります。 https://www.envoyproxy.io/docs/envoy/latest/configuration/http_filters/router_filter#x-envoy-retry-on
Istioの理解深めるには、envoy理解するのが効率よさそうだと思いつつ出来てないのでenvoy勉強しないなーと思いました。