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

impl: custom error response #4415

Merged
merged 24 commits into from
Oct 22, 2024

Conversation

zhaohuabing
Copy link
Member

@zhaohuabing zhaohuabing commented Oct 9, 2024

Implement: #4259

Issue: #1400

@zhaohuabing zhaohuabing requested a review from a team as a code owner October 9, 2024 09:55
@zhaohuabing zhaohuabing marked this pull request as draft October 9, 2024 09:55
Copy link

codecov bot commented Oct 9, 2024

Codecov Report

Attention: Patch coverage is 74.39516% with 127 lines in your changes missing coverage. Please review.

Project coverage is 65.97%. Comparing base (33ac6ca) to head (6f7d2c1).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/xds/translator/custom_response.go 80.11% 46 Missing and 22 partials ⚠️
internal/provider/kubernetes/controller.go 10.34% 23 Missing and 3 partials ⚠️
internal/provider/kubernetes/indexers.go 10.00% 17 Missing and 1 partial ⚠️
internal/provider/kubernetes/predicates.go 28.57% 6 Missing and 4 partials ⚠️
internal/gatewayapi/backendtrafficpolicy.go 94.44% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4415      +/-   ##
==========================================
+ Coverage   65.85%   65.97%   +0.11%     
==========================================
  Files         202      203       +1     
  Lines       30679    31154     +475     
==========================================
+ Hits        20205    20555     +350     
- Misses       9320     9415      +95     
- Partials     1154     1184      +30     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zhaohuabing zhaohuabing force-pushed the custom-error-response branch 5 times, most recently from fce9138 to c0cb97e Compare October 15, 2024 06:04
@zhaohuabing zhaohuabing marked this pull request as ready for review October 15, 2024 07:04
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
if ro.Response.Body.Type != nil && *ro.Response.Body.Type == egv1a1.ResponseValueTypeValueRef {
foundCM := false
for _, cm := range configMaps {
if cm.Namespace == policy.Namespace && cm.Name == string(ro.Response.Body.ValueRef.Name) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is this a ptr, will it work for default ?

Copy link
Member Author

Choose a reason for hiding this comment

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

if *ro.Response.Body.Type == egv1a1.ResponseValueTypeValueRef, then ro.Response.Body.ValueRef is not nil, otherwise, it would be a bug in Gateway API translation.

name: cel-matcher
typedConfig:
'@type': type.googleapis.com/xds.type.matcher.v3.CelMatcher
exprMatch:
Copy link
Contributor

Choose a reason for hiding this comment

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

👀

Copy link
Contributor

Choose a reason for hiding this comment

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

trusting the e2e, this API is complex, thanks for implementing this !

Copy link
Member Author

Choose a reason for hiding this comment

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

The Envoy CEL matcher API is terrible :-) It's the AST for CEL: response.code >= 501 && response.code <= 511 .

arkodg
arkodg previously approved these changes Oct 18, 2024
Copy link
Contributor

@arkodg arkodg left a comment

Choose a reason for hiding this comment

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

LGTM ! implementing the feature using the custom response filter doesnt look easy, thanks for building this out

@arkodg arkodg requested review from a team October 18, 2024 22:00
@@ -124,6 +124,8 @@ type EnvoyProxySpec struct {
//
// - envoy.filters.http.ratelimit
//
// - envoy.filters.http.custom_response
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible to override the 429 response if we place custom response filter behind ratelimit filterm should this filter be the first one of http filters?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. Should we allow users to override the ratelimit response if they added a matching conditing for 429 in the ResponseOrverride? @envoyproxy/gateway-maintainers

Copy link
Contributor

Choose a reason for hiding this comment

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

it's not just ratelimit, does authz/authn has same problem?

Copy link
Member Author

@zhaohuabing zhaohuabing Oct 21, 2024

Choose a reason for hiding this comment

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

Yeah, the custom response filter has been added to the last because users may want to override the direct responses generated by other filters, if they explicitly adding these status codes in the matching conditions. For example, to set the response body of a denide request to a message format algined with the style of the reponses of the applications.

If we put it at the first, the users won't be able to override them even if they intend to.

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO, it's better to put it at the first but no strong option, @arkodg please chime in as API designer.

cc @envoyproxy/gateway-maintainers

Copy link
Contributor

Choose a reason for hiding this comment

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

as a user, I would want the custom response to kick in after all filters have finished processing, to unify the way I deal with status code and error pages, so +1 to adding it to the end

Copy link
Contributor

Choose a reason for hiding this comment

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

we can change the order in the future, maybe we can open a ticket to continue our discussion.

Copy link
Member Author

@zhaohuabing zhaohuabing Oct 22, 2024

Choose a reason for hiding this comment

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

we can change the order in the future, maybe we can open a ticket to continue our discussion.

Let's keep the custom response filter at the last since there're use cases to override the responses of other filters. Users can change the default order using EnvoyProxy if they want to reorder the filters.

@arkodg arkodg requested review from zirain and a team October 21, 2024 22:47
@zirain
Copy link
Contributor

zirain commented Oct 21, 2024

@zhaohuabing can you make CI happy?

Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
zirain
zirain previously approved these changes Oct 21, 2024
@zirain zirain requested a review from arkodg October 21, 2024 23:48
arkodg
arkodg previously approved these changes Oct 22, 2024
@arkodg
Copy link
Contributor

arkodg commented Oct 22, 2024

e2es are failing ...

Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
@zhaohuabing zhaohuabing dismissed stale reviews from arkodg and zirain via 6f7d2c1 October 22, 2024 00:26
@zhaohuabing zhaohuabing merged commit 04fc944 into envoyproxy:main Oct 22, 2024
23 of 26 checks passed
@zhaohuabing zhaohuabing deleted the custom-error-response branch October 22, 2024 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants