router: add direct response with body format#41821
router: add direct response with body format#41821ravenblackx merged 27 commits intoenvoyproxy:mainfrom
Conversation
Adds support for passing a body_format to a route's direct response. Fixes envoyproxy#39463 Signed-off-by: Six <23470032+6ixfalls@users.noreply.github.com>
Signed-off-by: Six <23470032+6ixfalls@users.noreply.github.com>
|
Hi @6ixfalls, welcome and thank you for your contribution. We will try to review your Pull Request as quickly as possible. In the meantime, please take a look at the contribution guidelines if you have not done so already. |
|
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to |
Signed-off-by: Bryan Lee <me@bryanl.ee>
Signed-off-by: Bryan Lee <me@bryanl.ee>
Signed-off-by: Bryan Lee <me@bryanl.ee>
|
Existing tests need to be rewritten to pass - not sure if this was the right way to implement it. |
New mock, updated bodyFormat to return a string instead of modifying an argument Signed-off-by: Bryan Lee <me@bryanl.ee>
Signed-off-by: Bryan Lee <me@bryanl.ee>
Signed-off-by: Bryan Lee <me@bryanl.ee>
|
It seems like there are no more references to |
Yes, I think that's the cleanest solution here. A little unfortunate that formatBody requires more arguments, but there's not that many of them so I think it's not a big cost. |
|
/coverage |
|
Coverage for this Pull Request will be rendered here: https://storage.googleapis.com/envoy-cncf-pr/41821/coverage/index.html For comparison, current coverage on https://storage.googleapis.com/envoy-cncf-postsubmit/main/coverage/index.html The coverage results are (re-)rendered each time the CI |
Signed-off-by: Bryan Lee <me@bryanl.ee>
Signed-off-by: Bryan Lee <me@bryanl.ee>
…rmatting Signed-off-by: Bryan Lee <me@bryanl.ee>
Signed-off-by: Bryan Lee <me@bryanl.ee>
8ed36bd to
f19d3de
Compare
Signed-off-by: Bryan Lee <me@bryanl.ee>
Signed-off-by: Bryan Lee <me@bryanl.ee>
Signed-off-by: Bryan Lee <me@bryanl.ee>
Signed-off-by: Bryan Lee <me@bryanl.ee>
|
/retest |
Signed-off-by: Bryan Lee <me@bryanl.ee>
Signed-off-by: Bryan Lee <me@bryanl.ee>
e327eb0 to
c443b75
Compare
Signed-off-by: Bryan Lee <me@bryanl.ee>
9e0f12d to
2c47f7f
Compare
Signed-off-by: Bryan Lee <me@bryanl.ee>
Signed-off-by: Bryan Lee <me@bryanl.ee>
Signed-off-by: Bryan Lee <me@bryanl.ee>
adisuissa
left a comment
There was a problem hiding this comment.
Thanks for you contribution and making the happy-path less costly.
| // Specifies a format string for the response body. If ``body_format`` is not provided, | ||
| // and ``body`` is, the contents of ``body`` will be used to populate the body of the |
There was a problem hiding this comment.
I think the !body_format && body is pretty clear. What should probably be clarified is:
body_format && body, and in this case I assumebody_formatwill take precedence (please also update the comment ofbody- see example). (after briefly looking at the code changes, it is not clear to me if this requires thebodyto be present, and works on top of that or not - this should be clarified).!body_format && !body, no body will be in the generated response.
There was a problem hiding this comment.
I copied the definition from the custom_response_filter - but I can definitely make this clearer. This should be updated within that as well, but that's out of scope for this PR.
| } | ||
|
|
||
| TEST_P(DirectResponseIntegrationTest, DirectResponseWithBodyFormatAndNoBody) { | ||
| testDirectResponseWithBodyFormatAndNoBody(); |
There was a problem hiding this comment.
OOC what's the benefit of having a function call here?
If the code is not reused, IMHO it should just be here.
(same applies to the test below)
There was a problem hiding this comment.
I thought that too, but this is how it's already structured elsewhere in this file, and I try not to ask for cleaning up other people's mess, or being inconsistent with it.
(I was thinking I might clean it up afterwards.)
There was a problem hiding this comment.
I thought that the testDirectResponseBodySize() method is being reused in some tests, and that's why it was made a function. Granted, there may be a better approach here.
Specifically the new functions don't seem to be reused, so IMHO the additional dereference just makes it a bit more complex to understand.
There was a problem hiding this comment.
The whole subfunction thing is part of my pet testing peeve, that if you do a subfunction like that and the test fails, the output you get is frequently much less helpful than it would be if you did the helper functions differently.
e.g. instead of
testDirectResponseBodySize(1);
you could structure it
auto body = getDirectResponseBody();
EXPECT_THAT(body, HasLength(1));
which is very slightly longer but significantly clearer and makes any test failure occur in the test function, and also can log more useful information on failure (e.g. that the body is "banana" rather than just that the body's length was not 1.)
Anyway, for the purposes of this PR my point is just that I'm recommending not fixing this in this PR, because there were bad precedents, and I'll clean it up better afterwards. :)
There was a problem hiding this comment.
testDirectResponseFile() is also not being reused anywhere else, but was also made into a function.
Signed-off-by: Bryan Lee <me@bryanl.ee>
Signed-off-by: Bryan Lee <me@bryanl.ee>
|
/assign-from @envoyproxy/senior-maintainers |
|
@envoyproxy/senior-maintainers assignee is @RyanTheOptimist |
|
/retest |
1 similar comment
|
/retest |
Adds support for passing a body_format to a route's direct response. Fixes envoyproxy#39463 Commit Message: Allows a body_format to be passed for a route's direct_response. The body_format follows the same convention as the local_response_policy body. If a body is present & body_format is not, continue prior behavior with no formatting. If both are present, return the formatted content, and if neither is specified, no body is returned. Additional Description: Not sure if I covered all places where this could be used (libraries)? Risk Level: Medium Testing: Unit & integration Docs Changes: In line with API protos Release Notes: New feature - Added support for substitution formatting in direct response bodies via the new :ref:`body_format <envoy_v3_api_field_config.route.v3.DirectResponseAction.body_format>` field in :ref:`DirectResponseAction <envoy_v3_api_msg_config.route.v3.DirectResponseAction>`. Platform Specific Features: N/A Optional Runtime guard: Unsure if required Optional Fixes envoyproxy#39463 Optional [API Considerations](https://github.com/envoyproxy/envoy/blob/main/api/review_checklist.md): Should be satisfied --------- Signed-off-by: Six <23470032+6ixfalls@users.noreply.github.com> Signed-off-by: Bryan Lee <me@bryanl.ee> Signed-off-by: Gustavo <grnmeira@gmail.com>
Adds support for passing a body_format to a route's direct response. Fixes #39463
Commit Message: Allows a body_format to be passed for a route's direct_response. The body_format follows the same convention as the local_response_policy body. If a body is present & body_format is not, continue prior behavior with no formatting. If both are present, return the formatted content, and if neither is specified, no body is returned.
Additional Description: Not sure if I covered all places where this could be used (libraries)?
Risk Level: Medium
Testing: Unit & integration
Docs Changes: In line with API protos
Release Notes: New feature - Added support for substitution formatting in direct response bodies via the new :ref:
body_format <envoy_v3_api_field_config.route.v3.DirectResponseAction.body_format>fieldin :ref:
DirectResponseAction <envoy_v3_api_msg_config.route.v3.DirectResponseAction>.Platform Specific Features: N/A
Optional Runtime guard: Unsure if required
Optional Fixes #39463
Optional API Considerations: Should be satisfied