Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: Support FaultInjection in BackendTrafficPolicy #2304

Merged
merged 6 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/v1alpha1/backendtrafficpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ type BackendTrafficPolicySpec struct {
// +optional
TCPKeepalive *TCPKeepalive `json:"tcpKeepalive,omitempty"`

// FaultInjection defines the fault injection policy to be applied. This configuration can be used to
// inject delays and abort requests to mimic failure scenarios such as service failures and overloads
// +optional
FaultInjection *FaultInjection `json:"faultInjection,omitempty"`
// Circuit Breaker settings for the upstream connections and requests.
// If not set, circuit breakers will be enabled with the default thresholds
//
Expand Down
62 changes: 62 additions & 0 deletions api/v1alpha1/fault_injection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// 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"

// FaultInjection defines the fault injection policy to be applied. This configuration can be used to
// inject delays and abort requests to mimic failure scenarios such as service failures and overloads
// +union
//
// +kubebuilder:validation:XValidation:rule=" has(self.delay) || has(self.abort) ",message="Delay and abort faults are set at least one."
type FaultInjection struct {

// If specified, a delay will be injected into the request.
//
// +optional
Delay *FaultInjectionDelay `json:"delay,omitempty"`

// If specified, the request will be aborted if it meets the configuration criteria.
//
// +optional
Abort *FaultInjectionAbort `json:"abort,omitempty"`
}

// FaultInjectionDelay defines the delay fault injection configuration
type FaultInjectionDelay struct {
// FixedDelay specifies the fixed delay duration
//
// +required
FixedDelay *metav1.Duration `json:"fixedDelay"`

// Percentage specifies the percentage of requests to be delayed. Default 100%, if set 0, no requests will be delayed. Accuracy to 0.0001%.
// +optional
// +kubebuilder:default=100
Percentage *float32 `json:"percentage,omitempty"`
}

// FaultInjectionAbort defines the abort fault injection configuration
// +union
//
// +kubebuilder:validation:XValidation:rule=" !(has(self.httpStatus) && has(self.grpcStatus)) ",message="httpStatus and grpcStatus cannot be simultaneously defined."
// +kubebuilder:validation:XValidation:rule=" has(self.httpStatus) || has(self.grpcStatus) ",message="httpStatus and grpcStatus are set at least one."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is L45 needed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type FaultInjectionAbort struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also missing omitempty for optional fields

// StatusCode specifies the HTTP status code to be returned
//
// +optional
// +kubebuilder:validation:Minimum=200
// +kubebuilder:validation:Maximum=600
HTTPStatus *int32 `json:"httpStatus,omitempty"`

// GrpcStatus specifies the GRPC status code to be returned
//
// +optional
GrpcStatus *int32 `json:"grpcStatus,omitempty"`

// Percentage specifies the percentage of requests to be aborted. Default 100%, if set 0, no requests will be aborted. Accuracy to 0.0001%.
// +optional
Percentage *float32 `json:"percentage,omitempty"`
}
85 changes: 85 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,59 @@ spec:
minimum: 0
type: integer
type: object
faultInjection:
description: FaultInjection defines the fault injection policy to
be applied. This configuration can be used to inject delays and
abort requests to mimic failure scenarios such as service failures
and overloads
properties:
abort:
description: If specified, the request will be aborted if it meets
the configuration criteria.
properties:
grpcStatus:
description: GrpcStatus specifies the GRPC status code to
be returned
format: int32
type: integer
httpStatus:
description: StatusCode specifies the HTTP status code to
be returned
format: int32
maximum: 600
minimum: 200
type: integer
percentage:
description: Percentage specifies the percentage of requests
to be aborted. Default 100%, if set 0, no requests will
be aborted. Accuracy to 0.0001%.
type: number
type: object
x-kubernetes-validations:
- message: httpStatus and grpcStatus cannot be simultaneously
defined.
rule: ' !(has(self.httpStatus) && has(self.grpcStatus)) '
- message: httpStatus and grpcStatus are set at least one.
rule: ' has(self.httpStatus) || has(self.grpcStatus) '
delay:
description: If specified, a delay will be injected into the request.
properties:
fixedDelay:
description: FixedDelay specifies the fixed delay duration
type: string
percentage:
default: 100
description: Percentage specifies the percentage of requests
to be delayed. Default 100%, if set 0, no requests will
be delayed. Accuracy to 0.0001%.
type: number
required:
- fixedDelay
type: object
type: object
x-kubernetes-validations:
- message: Delay and abort faults are set at least one.
rule: ' has(self.delay) || has(self.abort) '
loadBalancer:
description: LoadBalancer policy to apply when routing traffic from
the gateway to the backend endpoints
Expand Down
47 changes: 47 additions & 0 deletions site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ _Appears in:_
| `loadBalancer` _[LoadBalancer](#loadbalancer)_ | LoadBalancer policy to apply when routing traffic from the gateway to the backend endpoints |
| `proxyProtocol` _[ProxyProtocol](#proxyprotocol)_ | ProxyProtocol enables the Proxy Protocol when communicating with the backend. |
| `tcpKeepalive` _[TCPKeepalive](#tcpkeepalive)_ | TcpKeepalive settings associated with the upstream client connection. Disabled by default. |
| `faultInjection` _[FaultInjection](#faultinjection)_ | FaultInjection defines the fault injection policy to be applied. This configuration can be used to inject delays and abort requests to mimic failure scenarios such as service failures and overloads |
| `circuitBreaker` _[CircuitBreaker](#circuitbreaker)_ | Circuit Breaker settings for the upstream connections and requests. If not set, circuit breakers will be enabled with the default thresholds |


Expand Down Expand Up @@ -792,6 +793,52 @@ _Appears in:_
CertificateRef can only reference a Kubernetes Secret at this time. |


#### FaultInjection



FaultInjection defines the fault injection policy to be applied. This configuration can be used to inject delays and abort requests to mimic failure scenarios such as service failures and overloads

_Appears in:_
- [BackendTrafficPolicySpec](#backendtrafficpolicyspec)

| Field | Description |
| --- | --- |
| `delay` _[FaultInjectionDelay](#faultinjectiondelay)_ | If specified, a delay will be injected into the request. |
| `abort` _[FaultInjectionAbort](#faultinjectionabort)_ | If specified, the request will be aborted if it meets the configuration criteria. |


#### FaultInjectionAbort



FaultInjectionAbort defines the abort fault injection configuration

_Appears in:_
- [FaultInjection](#faultinjection)

| Field | Description |
| --- | --- |
| `httpStatus` _integer_ | StatusCode specifies the HTTP status code to be returned |
| `grpcStatus` _integer_ | GrpcStatus specifies the GRPC status code to be returned |
| `percentage` _float_ | Percentage specifies the percentage of requests to be aborted. Default 100%, if set 0, no requests will be aborted. Accuracy to 0.0001%. |


#### FaultInjectionDelay



FaultInjectionDelay defines the delay fault injection configuration

_Appears in:_
- [FaultInjection](#faultinjection)

| Field | Description |
| --- | --- |
| `fixedDelay` _[Duration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.26/#duration-v1-meta)_ | FixedDelay specifies the fixed delay duration |
| `percentage` _float_ | Percentage specifies the percentage of requests to be delayed. Default 100%, if set 0, no requests will be delayed. Accuracy to 0.0001%. |


#### FileEnvoyProxyAccessLog


Expand Down
Loading