Skip to content

Test-server extension: use shared configuration base and test facilities#512

Merged
mum4k merged 81 commits intoenvoyproxy:masterfrom
oschaaf:server-extension-refactoring-1
Oct 6, 2020
Merged

Test-server extension: use shared configuration base and test facilities#512
mum4k merged 81 commits intoenvoyproxy:masterfrom
oschaaf:server-extension-refactoring-1

Conversation

@oschaaf
Copy link
Copy Markdown
Member

@oschaaf oschaaf commented Sep 5, 2020

  • Make the test server use the shared configuration handling code.
  • Convert its tests to use the new facilities that are shared accross extensions.

Last in a series of PRs to fix #498

This is on par with what we did for the dynamic delay and timing extensions,
but this extension was slightly more complex to begin with, so saving the
best for last ;-)

Signed-off-by: Otto van der Schaaf oschaaf@we-amp.com


Original PR description:

A first step to deduplicate code across the c++ test server extensions, and help us handle
configuration and testing of behaviour consistently.

Intent was for this to be a functional no-op, but added testing uncovered
issues in request post body handling. this solves that, modulo an issue with larger
request bodies vs the dynamic delay filter, which would need further analysis.

Prerequisites:

  1. land Finalize emission and tracking of latencies in response headers #500 to master & merge here
  2. land Add HttpFilterIntegrationTestBase #517
  3. land Add FilterConfigurationBase #518
  4. land Eliminate configuration references to Envoy's fault filter. #523
  5. land Source/server/configuration.cc/h: const options arg. #530
  6. land Enhance end-to-end test for POST requests with an entity body. #532
  7. land Add generic c++ integration test for uniform extension behavior.  #533
  8. land Switch dynamic delay and time-tracking to use FilterConfigurationBase. #540
  9. land Use shared test facilities for time-tracking and dynamic-delay #541

oschaaf added 30 commits June 15, 2020 17:31
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Will still fail the test because of mismatched expectations,
but this will help merging master periodically in here to
verify (almost) all is well.

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
@oschaaf oschaaf added the waiting-for-review A PR waiting for a review. label Sep 24, 2020
@mum4k mum4k requested a review from pamorgan September 24, 2020 17:58
@mum4k
Copy link
Copy Markdown
Collaborator

mum4k commented Sep 24, 2020

@pamorgan please review and assign back to me once done.

@dubious90 dubious90 requested a review from qqustc September 30, 2020 15:57
@dubious90
Copy link
Copy Markdown
Contributor

Peter is out of office and this PR has been delayed - @qqustc can you please review and assign back to me once done?

@dubious90 dubious90 removed the request for review from pamorgan September 30, 2020 15:58
@dubious90
Copy link
Copy Markdown
Contributor

Qin doesn't have the bandwidth for a review right now. @wjuan-AFK can you please review and assign back to me once done?

@dubious90 dubious90 requested review from wjuan-AFK and removed request for qqustc September 30, 2020 17:49
sendReply();
if (!config_->maybeSendErrorReply(*decoder_callbacks_)) {
const auto effective_config = config_->getEffectiveConfiguration();
if (effective_config.value()->echo_request_headers()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we check that the value is ok instead of just calling value() directly? Or do we prefer to throw an exception here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

maybeSendErrorReply() will have returned true if the value wasn't OK, so we can't hit this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, got it. I had missed the connection between getEffective config and maybeSendError.

config_->computeEffectiveConfiguration(headers);
if (end_stream) {
sendReply();
if (!config_->maybeSendErrorReply(*decoder_callbacks_)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure that this is worth bothering with, but I did find it mildly confusing that the result of maybeSendErrorReply is true if it did send an error reply.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Do you think that this would easier to read if bool maybeSendErrorReply() would be split up into bool haveErrorReply() and void sendErrorReply()?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Probably. I'm not sure if I'm alone in feeling uncertain on which boolean value to expect from a maybe naming scheme though.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What if we called it validateOrSendError.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was following up on this, I like the suggestion, but while doing that, I realised that the return value would have to be inverted. The maybeXXX "naming scheme" usually returns true iff it did what it said it might do (sendErrorReply() in this case). When we rename to validateOrSendError() the method should probably return true if the configuration was valid? I think this would still be a good change to make, but it would become a little intrusive as there's a bunch of places where this is used already. The good part is that when this PR gets merged, we are in a much better to position to make mechanical refactors like this across all extensions. Filed #558 to track following up.


TEST_P(HttpTestServerIntegrationTest, TestMaxBoundaryLengthRequest) {
initializeFilterConfiguration(kDefaultProto);
const int max = 1024 * 1024 * 4;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we define max this way? Is there another expression that would be equivalent?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This equates to / could be expressed as 4194304, or 0x400000, but I was hoping that the way it is expressed now would be easiest to grok it as being the equivalent of 4MB for readers of this code?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Makes sense.


// Here we test config-level merging as well as its application at the response-header level.
TEST_F(HttpTestServerDecoderFilterTest, HeaderMerge) {
TEST(HttpTestServerDecoderFilterTest, HeaderMerge) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I might be misunderstanding how this test works. Is there any chance this could be split into a couple separate cases being tested? It feels like it's trying to test several different kind of header merge.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You're right, this test has organically grown as different contributors added to it, and splitting this up makes sense.
As this is pre-existing, I prefer to file an issue and address this in a follow up, would you be ok with that?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ok.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Filed #559

@wjuan-AFK wjuan-AFK added waiting-for-changes A PR waiting for comments to be resolved and changes to be applied. and removed waiting-for-review A PR waiting for a review. labels Oct 2, 2020
@oschaaf oschaaf added waiting-for-review A PR waiting for a review. and removed waiting-for-changes A PR waiting for comments to be resolved and changes to be applied. labels Oct 2, 2020
…refactoring-1

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
@wjuan-AFK
Copy link
Copy Markdown
Contributor

LGTM

@mum4k mum4k assigned mum4k and unassigned dubious90 Oct 5, 2020
…refactoring-1

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Copy link
Copy Markdown
Collaborator

@mum4k mum4k left a comment

Choose a reason for hiding this comment

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

Looks good, just one nit really.

if (end_stream) {
sendReply();
if (!config_->maybeSendErrorReply(*decoder_callbacks_)) {
const auto effective_config = config_->getEffectiveConfiguration();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we replace the "auto" with a type for improved readability?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done in 2529ea6

return makeSingleRequest(addr, method, url, body, type, host, content_type,
request_header_delegate);
}
const std::string kDefaultProto = R"EOF(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(optional) It is typically not recommended to create globals of object that have non-trivial destructors, since c++ doesn't guarantee or specify the order in which these objects get destructed. So it is very easy to end up in an undefined state where object A depends on B, but B gets destructed before A. We had a lot of crashes of servers while attempting proper shutdown due to this.

A good trick around it is to ensure that the global never gets destructed. One way of doing that is what the original code had, i.e. a constexpr absl::string_view instead of an std::string.

Doesn't really matter here, since this is a test file, so optional. It's just something that triggers my muscle memory.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done in 2529ea6

@mum4k mum4k added waiting-for-changes A PR waiting for comments to be resolved and changes to be applied. and removed waiting-for-review A PR waiting for a review. labels Oct 6, 2020
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
@oschaaf oschaaf added waiting-for-review A PR waiting for a review. and removed waiting-for-changes A PR waiting for comments to be resolved and changes to be applied. labels Oct 6, 2020
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
@oschaaf
Copy link
Copy Markdown
Member Author

oschaaf commented Oct 6, 2020

Also, added 2bcbb2b, which raises the coverage thresholds to match where we are now.

@mum4k mum4k merged commit 9d77161 into envoyproxy:master Oct 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-for-review A PR waiting for a review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Look into an extension base class for our test server

4 participants