Skip to content

Retry Policies

The Retry Policy configuration defines how the APK should handle failed API requests. It allows you to specify the number of retries, the base retry interval, and the HTTP status codes for which the retries should be attempted.

Configuration Description
count Specifies the maximum number of retry attempts for API backend requests. If the backend returns any of the specified response codes, the APK will automatically retry the request according to the specified count.
baseIntervalInMillis Specifies the base retry interval in milliseconds. The APK will wait for this interval before attempting the next retry.
statusCodes Specifies an array of HTTP status codes (as integers) for which the APK should attempt retries. If the backend returns any of these status codes, the APK will trigger the retry mechanism.

You can configure retry policy to a backend using following methods:

Via Rest API Interface

When deploying APIs add the configurations to the apk-conf file as shown in the following sample.

endpointConfigurations: production: - endpoint: "http://backend-service:443" resiliency: retryPolicy: count: 3 baseIntervalMillis: 200 statusCodes: - 500 - 501 - 502 An example apk-conf file with the above configurations is shown below.

yaml name: "Sample API" basePath: "/sample-api" version: "0.1.0" type: "REST" defaultVersion: false endpointConfigurations: production: - endpoint: "https://dev-tools.wso2.com/gs/helpers/v1.0" resiliency: retryPolicy: count: 3 baseIntervalMillis: 200 statusCodes: - 500 - 501 - 502 operations: - target: "/ai/spelling" verb: "POST" secured: true scopes: [] - target: "/base64/decode/{value}" verb: "POST" secured: true scopes: [] - target: "/base64/encode/{value}" verb: "POST" secured: true scopes: [] - target: "/ip" verb: "GET" secured: true scopes: [] - target: "/user-agent" verb: "GET" secured: true scopes: [] - target: "/uuid" verb: "GET" secured: true scopes: []

You can then deploy this API by following the steps in the Deploy the API in APK documentation.

Via CRs

Step 1 - Define the CRs

Define the Backend resource for the API as below. apiVersion: dp.wso2.com/v1alpha1 kind: Backend metadata: name: sample-backend spec: protocol: http retry: baseIntervalMillis: 200 count: 3 statusCodes: - 500 - 501 - 502 services: - host: backend-service port: 443

For more information, see x-envoy-max-retries in the official Envoy documentation.

Step 2 - Apply the CRs

Apply CRs to the Kubernetes API server using the kubectl.

command kubectl apply -f <path-to-crs>

command kubectl apply -f samples/

Note

  • The APIs should be created in the Kubernetes Gateway deployment namespace.