【问题标题】:Istio Sidecar to retry on specified status codes (503)Istio Sidecar 重试指定状态码 (503)
【发布时间】:2021-02-24 05:51:37
【问题描述】:

默认情况下,如果我们不定义任何VirtualService,Istio 将生成类似以下 Envoy 路由/重试配置:

{
 "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"
}

但如果我们指定自己的VirtualService,例如:

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

生成的配置将如下所示:

{
 "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"
}

请注意retriable_status_codes 丢失了。

对于默认值,看起来它是在https://github.com/istio/istio/blob/1.9.0/pilot/pkg/networking/core/v1alpha3/route/retry/retry.go#L38-L39 中定义的。但是没有通过VirtualService 配置retriable_status_codes 的选项/字段。

我们如何在 Istio 中定义 retriable_status_codes

更新 #1:我的 Istio 版本是 1.6.9。但如果有更新的版本可以支持,也很感激。

【问题讨论】:

  • 您好,您是否尝试将retriable_status_codes 添加到retryOn 字段?
  • 嗨@DawidKruk,是的,已经添加了。我已经修改了上面的VirtualService 定义。生成的是正确的,它有retriable-status-codes,但是找不到我们在哪里可以设置要重试的状态码。
  • 抱歉回复晚了,能否请您添加5XXretryOn?另外你能告诉你Istio的版本吗?
  • 我会避免添加5xx,因为它将重试所有其他 5xx 错误代码(即 500、501、502、504 等)。和这里一样,我的目标是仅重试 503。我的 Istio 版本是 1.6.9。
  • 据我所知,这是不可能的。我需要建议您使用您在此处提供的信息创建一个 github 问题 github.com/istio/istio/issues

标签: istio envoyproxy istio-sidecar


【解决方案1】:

文档中的示例应该可以工作(根据源代码);我可以验证它适用于更高版本。

https://istio.io/latest/docs/reference/config/networking/virtual-service/#HTTPRetry

    retries:
      attempts: 3
      perTryTimeout: 2s
      retryOn: connect-failure,refused-stream,503

source code for 1.6.9 表明上面的例子应该可以工作

【讨论】:

    【解决方案2】:

    目前 (v1.10.2) 中没有可用于更新 retriable_status_codes 的直接 Istio 配置。

    但是,我们可以通过EnvoyFilter 来实现,例如:

    apiVersion: networking.istio.io/v1alpha3
    kind: EnvoyFilter
    metadata:
      name: retriable-status-codes-sidecar-outbound
      namespace: istio-system
    spec:
      configPatches:
      - applyTo: HTTP_ROUTE
        match:
          context: SIDECAR_OUTBOUND
        patch:
          operation: MERGE
          value:
            route:
              retry_policy:
                retriable_status_codes:
                - 503
    

    上面将注入retriable_status_codes 用于所有sidecar 上的传出调用(因为我们将它放在istio-system 命名空间中)。

    【讨论】:

      猜你喜欢
      • 2021-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-24
      • 2017-02-11
      • 1970-01-01
      相关资源
      最近更新 更多