Request Retry

更新时间:
复制 MD 格式

ASM lets you define a retry policy for failed HTTP requests. You can specify the timeout for each retry, the number of retries, and the retry conditions. This topic describes how to configure request retries.

Preparations

Complete the required preparations and deploy the httpbin and sleep services. For more information, see Preparations.

Procedure

  1. Verify that the service configuration is effective.

    1. In the KubeConfig environment of your ACK cluster, run the following command to enter the sleep pod and start a bash session.

      kubectl exec -it deploy/sleep -- sh
    2. Run the following command to send a request to the httpbin service.

      curl -I httpbin:8000/status/500

      Expected output:

      HTTP/1.1 500 Internal Server Error
      server: envoy
      date: Fri, 11 Aug 2023 10:03:06 GMT
      content-type: text/html; charset=utf-8
      access-control-allow-origin: *
      access-control-allow-credentials: true
      content-length: 0
      x-envoy-upstream-service-time: 2
  2. Use the following content to create a test scenario and configure a traffic rule for the httpbin application. Set the retry policy to five retries when a 5xx response is received. For more information, see Manage virtual services.

  3. apiVersion: networking.istio.io/v1beta1
    kind: VirtualService
    metadata:
      name: httpbin-vs
      namespace: default
    spec:
      hosts:
        - httpbin
      http:
        - retries:
            attempts: 5
            retryOn: 5xx
          route:
            - destination:
                host: httpbin
  4. Verify that the configuration is effective.

    1. In the KubeConfig environment of your ACK cluster, run the following command to enter the sleep pod and start a bash session.

      kubectl exec -it deploy/sleep -- sh
    2. Run the following command to send a request to the httpbin service and set the response status to 500.

      curl -I httpbin:8000/status/500

      Expected output:

      HTTP/1.1 500 Internal Server Error
      server: envoy
      date: Fri, 11 Aug 2023 10:03:35 GMT
      content-type: text/html; charset=utf-8
      access-control-allow-origin: *
      access-control-allow-credentials: true
      content-length: 0
      x-envoy-upstream-service-time: 382
    3. Change the log level for the sleep service to view the logs of the retry process.

      1. Run the following command to enter the sleep pod.

        kubectl exec -it {sleep-pod-name} -- sh 
      2. Run the following command to change the log level.

        curl -XPOST http://localhost:15000/logging\?level\=debug
    4. Run the following command to view the sleep logs.

      kubectl logs {sleep-pod-name} -c istio-proxy |grep -i retry

      Expected output:

      2023-08-14T02:11:01.896684Z	debug	envoy router external/envoy/source/common/router/router.cc:1862	[C159776][S1686768772862290****] performing retry	thread=36
      2023-08-14T02:11:01.932148Z	debug	envoy router external/envoy/source/common/router/router.cc:1862	[C159776][S1686768772862290****] performing retry	thread=36
      2023-08-14T02:11:02.020689Z	debug	envoy router external/envoy/source/common/router/router.cc:1862	[C159776][S1686768772862290****] performing retry	thread=36
      2023-08-14T02:11:02.170440Z	debug	envoy router external/envoy/source/common/router/router.cc:1862	[C159776][S1686768772862290****] performing retry	thread=36
      2023-08-14T02:11:02.275478Z	debug	envoy router external/envoy/source/common/router/router.cc:1862	[C159776][S1686768772862290****] performing retry	thread=36