Skip to content

Add echo_request_headers to the test server filter ResponseOptions.#338

Merged
mum4k merged 10 commits intoenvoyproxy:masterfrom
efimki:echoheaders
Jun 9, 2020
Merged

Add echo_request_headers to the test server filter ResponseOptions.#338
mum4k merged 10 commits intoenvoyproxy:masterfrom
efimki:echoheaders

Conversation

@efimki
Copy link
Copy Markdown
Member

@efimki efimki commented Jun 1, 2020

If echo_request_headers option is set to true, then request headers dump is appended to the response body.

@efimki
Copy link
Copy Markdown
Member Author

efimki commented Jun 1, 2020

@htuch PTAL when you have a chance.

Requests with this path get response with the dump of request headers
instead of generated output.

Signed-off-by: Misha Efimov <mef@google.com>
Signed-off-by: Misha Efimov <mef@google.com>
Copy link
Copy Markdown
Member

@oschaaf oschaaf left a comment

Choose a reason for hiding this comment

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

Some drive-by comments:
This looks like a great feature to me, some thoughts:

  • Maybe an option to allow people to configure /echoheaders would be nice-to-have.
    (It would also allow an escape latch in the (highly unlikely) event someone needs this path to function like it did before this change)
  • A note in README.md would help make this feature discoverable by others.

@eric846 eric846 added the waiting-for-review A PR waiting for a review. label Jun 1, 2020
@efimki
Copy link
Copy Markdown
Member Author

efimki commented Jun 2, 2020

This looks like a great feature to me, some thoughts:

Excellent, thanks for your suggestions!

  • Maybe an option to allow people to configure /echoheaders would be nice-to-have.
    (It would also allow an escape latch in the (highly unlikely) event someone needs this path to function like it did before this change)

The current implementation is inspired by Chromium's Embedded Test Server [1] that is mostly used in net and cronet [2] unit tests.

Your suggestion made me realize that in Nighthawk it will be better to configure special handlers using config instead of pre-defined request path. This way echo behaviors can be configured per individual request, applied to any request path, and combined if necessary (for example, echo headers and echo metadata). I'll update the PR.

  • A note in README.md would help make this feature discoverable by others.

Absolutely! I just wanted to flesh out the implementation before updating the docs.

[1] https://source.chromium.org/chromium/chromium/src/+/master:net/test/embedded_test_server/embedded_test_server.h
[2] https://source.chromium.org/chromium/chromium/src/+/master:components/cronet/test/test_server.h

@efimki efimki changed the title Add /echoheaders request path handler to test-server filter. Add echo_request_headers to the test server filter ResponseOptions. Jun 2, 2020
Signed-off-by: Misha Efimov <mef@google.com>
Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

LGTM, but do you want to talk about the motivation in the README.md? I.e. why would I set this as a Nighthawk user?

efimki added 2 commits June 3, 2020 10:01
Signed-off-by: Misha Efimov <mef@google.com>
Signed-off-by: Misha Efimov <mef@google.com>
@efimki
Copy link
Copy Markdown
Member Author

efimki commented Jun 3, 2020

Thanks for the suggestion!
I've added an example to README.md.
WDYT?

@efimki
Copy link
Copy Markdown
Member Author

efimki commented Jun 3, 2020

On related note, after this PR I'd like to add more response options that I think might be useful:

  • echo_request_metadata - include the dump of request metadata in the response body
  • echo_request_body - include the body of POST request in the response body
  • status_code - set http status code to arbitrary value, like 204 or 302

WDYT?

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.

Thank you for adding this feature and improving the documentation.

@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 Jun 3, 2020
@htuch
Copy link
Copy Markdown
Member

htuch commented Jun 4, 2020

@efimki LGTM modulo the comments from @mum4k. Re: future directions, do you want to eventually have a more structured body. E.g. make it a proto defined JSON format or something like that? To what extent is this going to be human interpreted vs. machine read?

Signed-off-by: Misha Efimov <mef@google.com>
Copy link
Copy Markdown
Member Author

@efimki efimki left a comment

Choose a reason for hiding this comment

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

Thanks for your comments, please take a look.

@efimki
Copy link
Copy Markdown
Member Author

efimki commented Jun 4, 2020

@efimki LGTM modulo the comments from @mum4k. Re: future directions, do you want to eventually have a more structured body. E.g. make it a proto defined JSON format or something like that? To what extent is this going to be human interpreted vs. machine read?

Maybe? I haven't really thought this through yet.
The chromium test server that I know is very simple and doesn't do any special formatting.
My current use case is fine with plain text dump.
I would follow YAGNI spirit and don't decide on this until we have a clear use case for something more elaborate.

@efimki efimki requested a review from mum4k June 4, 2020 15:37
@mum4k
Copy link
Copy Markdown
Collaborator

mum4k commented Jun 4, 2020

Thank you @efimki for addressing my comments, this looks good in regards to test coverage.

I think @htuch raises a good point. I do agree that we shouldn't implement anything prematurely, however this might be the only time to introduce any structure, since we have a backward compatibility guarantee in the Nighthawk repository. Should we consider at least adding an inner structure (proto definition?) that will for now contain these headers only?

@mum4k
Copy link
Copy Markdown
Collaborator

mum4k commented Jun 4, 2020

@efimki can you please push a commit (or two) to kick the CI jobs (automated check)? We will want them to be green before we proceed.

Signed-off-by: Misha Efimov <mef@google.com>
@efimki
Copy link
Copy Markdown
Member Author

efimki commented Jun 4, 2020

Hopefully this will do. If not, I'll try again later.

@oschaaf
Copy link
Copy Markdown
Member

oschaaf commented Jun 4, 2020

FWIW I suspect CircleCI is hogged, we may just need to wait for that to clear up. Other PRs also seem subject to this now

Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

LGTM. As long as it is just the request headers, I think it's totally fine to dump. If we start building a more structured response, with other fields like request body etc., I think it's time to add a proper structured format.

Signed-off-by: Misha Efimov <mef@google.com>
@efimki
Copy link
Copy Markdown
Member Author

efimki commented Jun 8, 2020

Trying to close / reopen to get ci unstuck.

@efimki efimki closed this Jun 8, 2020
@efimki efimki reopened this Jun 8, 2020
Signed-off-by: Misha Efimov <mef@google.com>
@mum4k
Copy link
Copy Markdown
Collaborator

mum4k commented Jun 8, 2020

If nothing else helps, you can consider closing this PR and creating a new one with the same content. Since we seem to be out of ideas :(

Edit - I see now that you tried just that and it didn't seem to help. @oschaaf any ideas how to move this forward?

@efimki
Copy link
Copy Markdown
Member Author

efimki commented Jun 9, 2020

FWIW I don't seek the fame of authoring this PR. :)
Maybe somebody else could create a new PR based on it that will be not be ignored by CI?

@oschaaf oschaaf mentioned this pull request Jun 9, 2020
@oschaaf
Copy link
Copy Markdown
Member

oschaaf commented Jun 9, 2020

I mirrored this PR into #349, and CI is running fine over there.
@efimki I'm sorry this is such a hassle.
I have checked everything that I have access to with respect to project-settings in github and CircleCI, but couldn't find anything I could relate to CI not running here. So I still can only speculate about potential causes.

@oschaaf
Copy link
Copy Markdown
Member

oschaaf commented Jun 9, 2020

So .. all tests are now passing here

@efimki
Copy link
Copy Markdown
Member Author

efimki commented Jun 9, 2020

Oh, nice, thanks for your help!
I think I've addressed @mum4k change request, but I don't know whether I should somehow explicitly mark it as addressed. Any ideas!

@oschaaf
Copy link
Copy Markdown
Member

oschaaf commented Jun 9, 2020

I think the last step is that @mum4k needs to explicitly add an approving review before this PR becomes mergeable. Apparently the CI run of my clone PR was able to green-light CI for this one by flagging the last (shared) commit as OK for all jobs.

@mum4k
Copy link
Copy Markdown
Collaborator

mum4k commented Jun 9, 2020

Magic, thanks @oschaaf.

@efimki would you mind closing all the related duplicates?

@mum4k mum4k merged commit adfc004 into envoyproxy:master Jun 9, 2020
@efimki efimki deleted the echoheaders branch June 9, 2020 18:26
@efimki
Copy link
Copy Markdown
Member Author

efimki commented Jun 9, 2020

I've closed obsolete PRs #345 and #346 and opened #351 to discuss structure of additional echo responses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-for-changes A PR waiting for comments to be resolved and changes to be applied.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants