MeshRetry

This policy uses new policy matching algorithm. Do not combine with Retry.

This policy enables Kuma to know how to behave if there are failed requests which could be retried.

TargetRef support matrix

targetRefAllowed kinds
targetRef.kindMesh, MeshSubset
to[].targetRef.kindMesh, MeshService, MeshExternalService
targetRefAllowed kinds
targetRef.kindMesh, MeshGateway, MeshGateway with listener tags
to[].targetRef.kindMesh
targetRefAllowed kinds
targetRef.kindMesh, MeshSubset
to[].targetRef.kindMesh, MeshService, MeshExternalService

To learn more about the information in this table, see the matching docs.

Configuration

The policy let you configure retry behaviour for HTTP, GRPC and TCP protocols. The protocol is selected by picking the most specific protocol.

Each protocol has a separate section under default in the policy yaml. Some sections are common between protocols or have similar meaning.

Retry on

The field retryOn is a list of conditions which will cause a retry.

For HTTP these are related to the response status code or method (5xx, 429, HttpMethodGet). For gRPC these are status codes in response headers (canceled, deadline-exceeded, etc.). There is no equivalent for TCP.

One or more conditions can be specified, for example:

  1. retryOn:
  2. - "429"
  3. - "503"

means that it the policy will retry on a status code 429 or 503.

Full list of available HTTP conditions:

  1. retryOn:
  2. - 5XX
  3. - GatewayError
  4. - Reset
  5. - Retriable4xx
  6. - ConnectFailure
  7. - EnvoyRatelimited
  8. - RefusedStream
  9. - Http3PostConnectFailure
  10. - HttpMethodConnect
  11. - HttpMethodDelete
  12. - HttpMethodGet
  13. - HttpMethodHead
  14. - HttpMethodOptions
  15. - HttpMethodPatch
  16. - HttpMethodPost
  17. - HttpMethodPut
  18. - HttpMethodTrace
  19. - "429" # any HTTP status code
  20. - "503"

Full list of available gRPC conditions:

  1. retryOn:
  2. - Canceled
  3. - DeadlineExceeded
  4. - Internal
  5. - ResourceExhausted
  6. - Unavailable

Back off

This parameter is applicable to both HTTP and GRPC.

It consists of BaseInterval (the amount of time between retries) and MaxInterval (the maximal amount of time taken between retries).

We use an exponential back-off algorithm with jitter for retries. Given a base interval B and retry number N, the back-off for the retry is in the range [0, (2N - 1) × B).

For example, given a 25 ms interval, the first retry will be delayed randomly by 0-24 ms, the second by 0-74 ms, the third by 0-174 ms, and so on.

The interval is capped at a MaxInterval, which defaults to 10 times the BaseInterval.

Rate limited back off

This parameter is applicable to both HTTP and GRPC.

MeshRetry can be configured in such a way that when the upstream server rate limits the request and responds with a header like retry-after or x-ratelimit-reset it uses the value from the header to determine when to send the retry request instead of the back off algorithm.

Example

Given this configuration:

  1. retryOn:
  2. - "503"
  3. rateLimitedBackOff:
  4. resetHeaders:
  5. - name: retry-after
  6. format: Seconds
  7. - name: x-ratelimit-reset
  8. format: UnixTimestamp

and an HTTP response:

  1. HTTP/1.1 503 Service Unavailable
  2. retry-after: 15

The retry request will be issued after 15 seconds.

If the response is as follows:

  1. HTTP/1.1 503 Service Unavailable
  2. x-ratelimit-reset: 1706096119

The request will be retried at Wed Jan 24 2024 11:35:19 GMT+0000.

If the response does not contain retry-after or x-ratelimit-reset header (with valid integer value) then the amount of time to wait before issuing a request is determined by back off algorithm.

Examples

HTTP frontend to backend on 5xx

  1. apiVersion: kuma.io/v1alpha1
  2. kind: MeshRetry
  3. metadata:
  4. name: frontend-to-backend-retry-http
  5. namespace: kuma-demo
  6. labels:
  7. kuma.io/mesh: default
  8. spec:
  9. targetRef:
  10. kind: MeshSubset
  11. tags:
  12. app: frontend
  13. to:
  14. - targetRef:
  15. kind: MeshService
  16. name: backend_kuma-demo_svc_8080
  17. default:
  18. http:
  19. numRetries: 10
  20. backOff:
  21. baseInterval: 15s
  22. maxInterval: 20m
  23. retryOn:
  24. - 5xx
  1. apiVersion: kuma.io/v1alpha1
  2. kind: MeshRetry
  3. metadata:
  4. name: frontend-to-backend-retry-http
  5. namespace: kuma-demo
  6. labels:
  7. kuma.io/mesh: default
  8. spec:
  9. targetRef:
  10. kind: MeshSubset
  11. tags:
  12. app: frontend
  13. to:
  14. - targetRef:
  15. kind: MeshService
  16. name: backend
  17. namespace: kuma-demo
  18. sectionName: http
  19. default:
  20. http:
  21. numRetries: 10
  22. backOff:
  23. baseInterval: 15s
  24. maxInterval: 20m
  25. retryOn:
  26. - 5xx

I am using MeshService

  1. type: MeshRetry
  2. name: frontend-to-backend-retry-http
  3. mesh: default
  4. spec:
  5. targetRef:
  6. kind: MeshSubset
  7. tags:
  8. app: frontend
  9. to:
  10. - targetRef:
  11. kind: MeshService
  12. name: backend
  13. default:
  14. http:
  15. numRetries: 10
  16. backOff:
  17. baseInterval: 15s
  18. maxInterval: 20m
  19. retryOn:
  20. - 5xx
  1. type: MeshRetry
  2. name: frontend-to-backend-retry-http
  3. mesh: default
  4. spec:
  5. targetRef:
  6. kind: MeshSubset
  7. tags:
  8. app: frontend
  9. to:
  10. - targetRef:
  11. kind: MeshService
  12. name: backend
  13. sectionName: http
  14. default:
  15. http:
  16. numRetries: 10
  17. backOff:
  18. baseInterval: 15s
  19. maxInterval: 20m
  20. retryOn:
  21. - 5xx

gRPC frontend to backend on DeadlineExceeded

  1. apiVersion: kuma.io/v1alpha1
  2. kind: MeshRetry
  3. metadata:
  4. name: frontend-to-backend-retry-grpc
  5. namespace: kuma-demo
  6. labels:
  7. kuma.io/mesh: default
  8. spec:
  9. targetRef:
  10. kind: MeshSubset
  11. tags:
  12. app: frontend
  13. to:
  14. - targetRef:
  15. kind: MeshService
  16. name: backend_kuma-demo_svc_8080
  17. default:
  18. grpc:
  19. numRetries: 5
  20. backOff:
  21. baseInterval: 5s
  22. maxInterval: 1m
  23. retryOn:
  24. - DeadlineExceeded
  1. apiVersion: kuma.io/v1alpha1
  2. kind: MeshRetry
  3. metadata:
  4. name: frontend-to-backend-retry-grpc
  5. namespace: kuma-demo
  6. labels:
  7. kuma.io/mesh: default
  8. spec:
  9. targetRef:
  10. kind: MeshSubset
  11. tags:
  12. app: frontend
  13. to:
  14. - targetRef:
  15. kind: MeshService
  16. name: backend
  17. namespace: kuma-demo
  18. sectionName: http
  19. default:
  20. grpc:
  21. numRetries: 5
  22. backOff:
  23. baseInterval: 5s
  24. maxInterval: 1m
  25. retryOn:
  26. - DeadlineExceeded

I am using MeshService

  1. type: MeshRetry
  2. name: frontend-to-backend-retry-grpc
  3. mesh: default
  4. spec:
  5. targetRef:
  6. kind: MeshSubset
  7. tags:
  8. app: frontend
  9. to:
  10. - targetRef:
  11. kind: MeshService
  12. name: backend
  13. default:
  14. grpc:
  15. numRetries: 5
  16. backOff:
  17. baseInterval: 5s
  18. maxInterval: 1m
  19. retryOn:
  20. - DeadlineExceeded
  1. type: MeshRetry
  2. name: frontend-to-backend-retry-grpc
  3. mesh: default
  4. spec:
  5. targetRef:
  6. kind: MeshSubset
  7. tags:
  8. app: frontend
  9. to:
  10. - targetRef:
  11. kind: MeshService
  12. name: backend
  13. sectionName: http
  14. default:
  15. grpc:
  16. numRetries: 5
  17. backOff:
  18. baseInterval: 5s
  19. maxInterval: 1m
  20. retryOn:
  21. - DeadlineExceeded

TCP frontend to backend

  1. apiVersion: kuma.io/v1alpha1
  2. kind: MeshRetry
  3. metadata:
  4. name: frontend-to-backend-retry-tcp
  5. namespace: kuma-demo
  6. labels:
  7. kuma.io/mesh: default
  8. spec:
  9. targetRef:
  10. kind: MeshSubset
  11. tags:
  12. app: frontend
  13. to:
  14. - targetRef:
  15. kind: MeshService
  16. name: backend_kuma-demo_svc_8080
  17. default:
  18. tcp:
  19. maxConnectAttempt: 5
  1. apiVersion: kuma.io/v1alpha1
  2. kind: MeshRetry
  3. metadata:
  4. name: frontend-to-backend-retry-tcp
  5. namespace: kuma-demo
  6. labels:
  7. kuma.io/mesh: default
  8. spec:
  9. targetRef:
  10. kind: MeshSubset
  11. tags:
  12. app: frontend
  13. to:
  14. - targetRef:
  15. kind: MeshService
  16. name: backend
  17. namespace: kuma-demo
  18. sectionName: http
  19. default:
  20. tcp:
  21. maxConnectAttempt: 5

I am using MeshService

  1. type: MeshRetry
  2. name: frontend-to-backend-retry-tcp
  3. mesh: default
  4. spec:
  5. targetRef:
  6. kind: MeshSubset
  7. tags:
  8. app: frontend
  9. to:
  10. - targetRef:
  11. kind: MeshService
  12. name: backend
  13. default:
  14. tcp:
  15. maxConnectAttempt: 5
  1. type: MeshRetry
  2. name: frontend-to-backend-retry-tcp
  3. mesh: default
  4. spec:
  5. targetRef:
  6. kind: MeshSubset
  7. tags:
  8. app: frontend
  9. to:
  10. - targetRef:
  11. kind: MeshService
  12. name: backend
  13. sectionName: http
  14. default:
  15. tcp:
  16. maxConnectAttempt: 5

All policy options