0

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.

4

2 回答 2

1

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

于 2021-11-29T21:41:03.700 回答
0

There is no direct Istio config available to update the retriable_status_codes in currently (v1.10.2).

But, we can do it via EnvoyFilter, e.g:

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

The above will inject the retriable_status_codes for outgoing calls on all sidecars (because we put it in istio-system namespace).

于 2021-08-05T11:16:55.013 回答