-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api: support retry on in BackendTrafficPolicy
Signed-off-by: zhaonan <[email protected]>
- Loading branch information
zhaonan
committed
Nov 9, 2023
1 parent
ad38383
commit 0aa689c
Showing
6 changed files
with
829 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
// Copyright Envoy Gateway Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// The full text of the Apache license is available in the LICENSE file at | ||
// the root of the repo. | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// RetryStrategy defines the retry strategy to be applied. | ||
// | ||
// +kubebuilder:validation:XValidation:rule="self.type == 'Grpc' ? has(self.grpc) : !has(self.grpc)",message="If RetryStrategy type is Grpc, grpc field needs to be set." | ||
// +kubebuilder:validation:XValidation:rule="self.type == 'Htttp' ? has(self.http) : !has(self.http)",message="If RetryStrategy type is Http, http field needs to be set." | ||
type RetryStrategy struct { | ||
// Type decides the type of RetryStrategy . | ||
// Valid RetryStrategyType values are | ||
// "Http", | ||
// "Grpc", | ||
// | ||
Type RetryStrategyType `json:"type"` | ||
// HttpRetry defines the retry triggering conditions for HTTP protocol. | ||
// | ||
// +optional | ||
Http *HttpRetry `json:"http,omitempty"` | ||
// GrpcRetry defines the retry triggering conditions for GRPC protocol. | ||
// | ||
// +optional | ||
Grpc *GrpcRetry `json:"grpc,omitempty"` | ||
// NumRetries is the number of retries to be attempted. Defaults to 1. | ||
// | ||
// +optional | ||
NumRetries int `json:"numRetries,omitempty"` | ||
// PerRetry is the retry policy to be applied per retry attempt. | ||
// | ||
// +optional | ||
PerRetry PerRetryPolicy `json:"perRetry,omitempty"` | ||
// RetryLimit is the retry limit policy to be applied. | ||
// | ||
// +optional | ||
RetryLimit RetryLimitPolicy `json:"retryLimit,omitempty"` | ||
} | ||
|
||
// RetryStrategyType specifies the types of RetryStrategy. | ||
// +kubebuilder:validation:Enum=Grpc;Http; | ||
type RetryStrategyType string | ||
|
||
const ( | ||
// HttpRetryStrategyType for http protocol. | ||
HttpRetryStrategyType RetryStrategyType = "Http" | ||
// GrpcRetryStrategyType for grpc protocol. | ||
GrpcRetryStrategyType LoadBalancerType = "Grpc" | ||
) | ||
|
||
// HttpRetry defines the retry triggering conditions for HTTP protocol. | ||
type HttpRetry struct { | ||
// RetryOn indicates the retry policy. One or more policies can be specified using a ',' delimited list. | ||
// The supported policies are: | ||
// * 5xx: gateway will attempt a retry if the upstream server responds with any 5xx response code, or does not respond at all (disconnect/reset/read timeout). | ||
// (Includes connect-failure and refused-stream) | ||
// * gateway-error: gateway will attempt a retry when the response is a gateway error (502,503 or 504). | ||
// * reset: gateway will attempt a retry if the upstream server does not respond at all (disconnect/reset/read timeout.) | ||
// * connect-failure: gateway will attempt a retry if a request is failed because of a connection failure to the upstream | ||
// server (connect timeout, etc.). (Included in *5xx*) | ||
// * retriable-4xx: gateway will attempt a retry if the upstream server responds with a retriable 4xx response code. | ||
// Currently, the only response code in this category is 409. | ||
// * refused-stream: gateway will attempt a retry if the upstream server resets the stream with a REFUSED_STREAM error code. | ||
// This reset type indicates that a request is safe to retry. (Included in 5xx) | ||
// * retriable-status-codes: gateway will attempt a retry if the upstream server responds with any response code | ||
// matching one defined in the RetriableStatusCodes. | ||
// For additional details, see https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/router_filter#x-envoy-retry-on | ||
RetryOn RetryOn `json:"retryOn"` | ||
// HTTP status codes that should trigger a retry in addition to those specified by retry_on, required when retry_on is set to retriable-status-codes. | ||
// | ||
// +optional | ||
RetriableStatusCodes RetriableStatusCodes `json:"retriableStatusCodes"` | ||
} | ||
|
||
// GrpcRetry defines the retry triggering conditions for GRPC protocol. | ||
type GrpcRetry struct { | ||
// GRPC retries are currently only supported for gRPC status codes in response headers. RetryOn indicates the retry policy. One or more policies can be specified using a ',' delimited list. | ||
// The supported policies are: | ||
// * cancelled: gateway will attempt a retry if the gRPC status code in the response headers is “cancelled”. | ||
// * deadline-exceeded: gateway will attempt a retry if the gRPC status code in the response headers is “deadline-exceeded”. | ||
// * internal: gateway will attempt a retry if the gRPC status code in the response headers is “internal”. | ||
// * resource-exhausted: gateway will attempt a retry if the gRPC status code in the response headers is “resource-exhausted”. | ||
// * unavailable: gateway will attempt a retry if the gRPC status code in the response headers is “unavailable”. | ||
// For additional details, see https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/router_filter#x-envoy-retry-grpc-on | ||
RetryOn RetryOn `json:"retryOn,omitempty"` | ||
} | ||
|
||
type RetryOn string | ||
type RetriableStatusCodes []int | ||
|
||
type PerRetryPolicy struct { | ||
// Timeout is the timeout per retry attempt. | ||
// | ||
// +optional | ||
// +kubebuilder:validation:Format=duration | ||
Timeout *metav1.Duration `json:"timeout,omitempty"` | ||
// IdleTimeout is the upstream idle timeout per retry attempt.This parameter is optional and if absent there is no per try idle timeout. | ||
// | ||
// +optional | ||
// +kubebuilder:validation:Format=duration | ||
IdleTimeout *metav1.Duration `json:"idleTimeout,omitempty"` | ||
// Backoff is the backoff policy to be applied per retry attempt. gateway uses a fully jittered exponential | ||
// back-off algorithm for retries. For additional details, | ||
// see https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/router_filter#config-http-filters-router-x-envoy-max-retries | ||
// | ||
// +optional | ||
BackOff *BackOffPolicy `json:"backOff,omitempty"` | ||
} | ||
|
||
type BackOffPolicy struct { | ||
// BaseInterval is the base interval between retries. | ||
// | ||
// +kubebuilder:validation:Format=duration | ||
BaseInterval *metav1.Duration `json:"baseInterval,omitempty"` | ||
// MaxInterval is the maximum interval between retries. This parameter is optional, but must be greater than or equal to the base_interval if set. | ||
// The default is 10 times the base_interval | ||
// | ||
// +optional | ||
// +kubebuilder:validation:Format=duration | ||
MaxInterval *metav1.Duration `json:"maxInterval,omitempty"` | ||
} | ||
|
||
// RetryLimit is the retry limit policy to be applied. | ||
|
||
// +kubebuilder:validation:XValidation:rule="self.type == 'Static' ? has(self.static) : !has(self.static)",message="If RetryLimitType type is Static, static field needs to be set." | ||
// +kubebuilder:validation:XValidation:rule="self.type == 'RetryBudget' ? has(self.retryBudget) : !has(self.retryBudget)",message="If RetryLimitType type is RetryBudget, retryBudget field needs to be set." | ||
type RetryLimitPolicy struct { | ||
// Valid RetryLimitType values are | ||
// "Static", | ||
// "RetryBudget", | ||
Type RetryLimitType `json:"type,omitempty"` | ||
// Static specifies a limit on concurrent retries. | ||
// | ||
// +optional | ||
Static StaticPolicy `json:"static,omitempty"` | ||
// RetryBudget specifies a limit on concurrent retries in relation to the number of active requests. For additional details, | ||
// see https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/cluster/v3/circuit_breaker.proto#envoy-v3-api-msg-config-cluster-v3-circuitbreakers-thresholds-retrybudget | ||
// | ||
// +optional | ||
RetryBudget RetryBudgetPolicy `json:"retryBudget,omitempty"` | ||
} | ||
|
||
// RetryLimitType specifies the types of RetryLimit. | ||
// +kubebuilder:validation:Enum=Static;RetryBudget; | ||
type RetryLimitType string | ||
|
||
const ( | ||
// StaticRetryStrategyType for static retry limit policy. | ||
StaticRetryLimitType RetryLimitType = "Http" | ||
// RetryBudgetRetryStrategyType for retry budget limit policy. | ||
RetryBudgetRetryLimitType RetryLimitType = "Grpc" | ||
) | ||
|
||
type StaticPolicy struct { | ||
// MaxParallel is the maximum number of parallel retries. If not specified, the default is 3. | ||
// | ||
// +optional | ||
MaxParallel int `json:"maxParallel,omitempty"` | ||
} | ||
|
||
type RetryBudgetPolicy struct { | ||
// BudgetPercent specifies the limit on concurrent retries as a percentage of the sum of active requests and active pending requests. | ||
// For example, if there are 100 active requests and the budget_percent is set to 25, there may be 25 active retries. | ||
// This parameter is optional. Defaults to 20%. | ||
// | ||
// +optional | ||
ActiveRequestPercent int `json:"activeRequestPercent,omitempty"` | ||
// Minconcurrent Specifies the minimum retry concurrency allowed for the retry budget. The limit on the number of active retries may never go below this number. | ||
// This parameter is optional. Defaults to 3. | ||
// | ||
// +optional | ||
MinConcurrent int `json:"minConcurrent,omitempty"` | ||
} |
Oops, something went wrong.