[Retry] Request Retries
ASM lets you define a retry policy to apply when an HTTP request fails. Specify settings such as the timeout allowed for each retry, the number of retries, and the retry conditions. This topic describes how to configure request retries.
Prerequisites
You have completed the preparations and deployed the httpbin service and the sleep service. For more information, see Preparations.
Procedure
-
Verify that the service configuration takes effect.
-
In the KubeConfig environment of the ACK cluster, enter the sleep environment and start bash.
kubectl exec -it deploy/sleep -- sh -
Send a request to the httpbin service.
curl -I httpbin:8000/status/500Expected 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
-
-
Use the following content to set up a test scenario and configure the traffic rules for the httpbin application. The retry policy retries the request five times when the response is
5xx. For more information, see Manage virtual services. -
Verify that the configuration takes effect.
-
In the KubeConfig environment of the ACK cluster, enter the sleep environment and start bash.
kubectl exec -it deploy/sleep -- sh -
Send a request to the httpbin service and set the response status to 500.
curl -I httpbin:8000/status/500Expected 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 -
Modify the sleep log level to view the logs of the retry process.
-
Enter the sleep Pod.
kubectl exec -it {sleep Pod name} -- sh -
Modify the log level.
curl -XPOST http://localhost:15000/logging\?level\=debug
-
-
View the sleep logs.
kubectl logs {sleep Pod name} -c istio-proxy |grep -i retryExpected 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
-
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