-
Notifications
You must be signed in to change notification settings - Fork 365
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
Conversation
🚀 Thank you for contributing to the Envoy Gateway project! 🚀 Before merging, please ensure to follow the process below:
NOTE: Once your PR is under review, please do not rebase and force push it. Otherwise, it will force your reviewers to review the PR from scratch rather than simply look at your latest changes. What's more, you can help expedite the processing of your PR by
|
🚀 Deployed on https://gateway-pr-2304-preview--eg-preview.netlify.app |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2304 +/- ##
==========================================
- Coverage 64.54% 64.53% -0.02%
==========================================
Files 112 112
Lines 15949 15949
==========================================
- Hits 10295 10293 -2
- Misses 5007 5009 +2
Partials 647 647 ☔ View full report in Codecov by Sentry. |
@@ -65,6 +65,10 @@ type BackendTrafficPolicySpec struct { | |||
// | |||
// +optional | |||
TCPKeepalive *TCPKeepalive `json:"tcpKeepalive,omitempty"` | |||
|
|||
// FaultInjection defines the fault injection policy to be applied. Support delays and aborts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// FaultInjection defines the fault injection policy to be applied. Support delays and aborts. | |
// 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. |
api/v1alpha1/fault_injection.go
Outdated
// FaultInjection defines the fault injection policy to be applied. Support delays and aborts. | ||
type FaultInjection struct { | ||
|
||
// If specified, the delay will inject a fixed delay into the request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// If specified, the delay will inject a fixed delay into the request | |
// If specified, a delay will be injected into the request |
api/v1alpha1/fault_injection.go
Outdated
// +optional | ||
Delay *DelayConfig `json:"delay,omitempty"` | ||
|
||
// If specified, the abort will abort the request with the specified HTTP status code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// If specified, the abort will abort the request with the specified HTTP status code | |
// If specified, the request will be aborted if it meets the configuration criteria. |
api/v1alpha1/fault_injection.go
Outdated
// If specified, the delay will inject a fixed delay into the request | ||
// | ||
// +optional | ||
Delay *DelayConfig `json:"delay,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delay *DelayConfig `json:"delay,omitempty"` | |
Delay *FaultInjectionDelay `json:"delay,omitempty"` |
api/v1alpha1/fault_injection.go
Outdated
// If specified, the abort will abort the request with the specified HTTP status code | ||
// | ||
// +optional | ||
Abort *AbortConfig `json:"abort,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Abort *AbortConfig `json:"abort,omitempty"` | |
Abort *FaultInjectionAbort `json:"abort,omitempty"` |
api/v1alpha1/fault_injection.go
Outdated
// +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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so we can only express int e.g. 1%, 2%, but not fractions such as 0.5% ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update
api/v1alpha1/fault_injection.go
Outdated
// +required | ||
StatusCode *int `json:"statusCode"` | ||
|
||
// Percentage specifies the percentage of requests to be aborted. Default 100%, if set 0, no requests will be aborted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
api/v1alpha1/fault_injection.go
Outdated
|
||
// AbortConfig defines the abort fault injection configuration | ||
type AbortConfig struct { | ||
// StatusCode specifies the HTTP/GRPC status code to be returned |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
grpc status is different from http status
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one way to define this is
status:
type: HTTP
http: 200
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or define httpStatus
& grpcStatus
and use CEL to make sure both cannot be simultaneously defined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, used CEL
Signed-off-by: zhaonan <[email protected]>
Signed-off-by: zhaonan <[email protected]>
c197ba1
to
c5221fe
Compare
api/v1alpha1/fault_injection.go
Outdated
// 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 *float64 `json:"percentage"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
omitempty
?
// +union | ||
// | ||
// +kubebuilder:validation:XValidation:rule=" !(has(self.httpStatus) && has(self.grpcStatus)) && (has(self.httpStatus) || has(self.grpcStatus))",message="httpStatus and grpcStatus cannot be simultaneously defined." | ||
type FaultInjectionAbort struct { |
There was a problem hiding this comment.
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
@@ -30,7 +30,7 @@ CONTROLLERGEN_OBJECT_FLAGS := object:headerFile="$(ROOT_DIR)/tools/boilerplate/ | |||
.PHONY: manifests | |||
manifests: $(tools/controller-gen) generate-gwapi-manifests ## Generate WebhookConfiguration and CustomResourceDefinition objects. | |||
@$(LOG_TARGET) | |||
$(tools/controller-gen) crd paths="./..." output:crd:artifacts:config=charts/gateway-helm/crds/generated | |||
$(tools/controller-gen) crd:allowDangerousTypes=true paths="./..." output:crd:artifacts:config=charts/gateway-helm/crds/generated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why set this to be true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because of float field
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it
@@ -0,0 +1,220 @@ | |||
apiVersion: apps/v1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this shouldnt be part of this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, my bad.
api/v1alpha1/fault_injection.go
Outdated
// FaultInjectionAbort defines the abort fault injection configuration | ||
// +union | ||
// | ||
// +kubebuilder:validation:XValidation:rule=" !(has(self.httpStatus) && has(self.grpcStatus)) && (has(self.httpStatus) || has(self.grpcStatus))",message="httpStatus and grpcStatus cannot be simultaneously defined." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be !(has(self.httpStatus) && has(self.grpcStatus))
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah,Add verification that at least one of httpStatus and grpcStatus is set
Signed-off-by: zhaonan <[email protected]>
661b177
to
c5fcea9
Compare
// +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." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is L45 needed ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah,an error type must be set(not provide default behavior for abort fault),https://github.com/envoyproxy/envoy/blob/6b152468de33832161951348aac5e2219935f258/api/envoy/extensions/filters/http/fault/v3/fault.proto#L41C1-L52C4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks for introducing this API
adding a minor non blocking comment
Signed-off-by: zhaonan <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks
/retest |
What type of PR is this?
API: Support FaultInjection in BackendTrafficPolicy
Provide basic fault injection capabilities:
Supports injecting fixed time delay or abort errors by percentage
Example
Relates to #2124
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #