Skip to content

thrift proxy: add request shadowing support#17544

Merged
mattklein123 merged 27 commits intoenvoyproxy:mainfrom
rgs1:thrift-add-shadowing-support
Aug 9, 2021
Merged

thrift proxy: add request shadowing support#17544
mattklein123 merged 27 commits intoenvoyproxy:mainfrom
rgs1:thrift-add-shadowing-support

Conversation

@rgs1
Copy link
Copy Markdown
Member

@rgs1 rgs1 commented Jul 30, 2021

This is the last PR (5/5) in the series dedicated to adding mirroring support.
It adds:

  • the ShadowWriter which is used by the Router filter to mirror requests
  • a ShadowRouter which is a RequestOwner that reuses the existing UpstreamRequest

There's still room for more code sharing and better interfaces, but that
can happen in future iterations.

Signed-off-by: Raul Gutierrez Segales rgs@pinterest.com

This is the last PR in the series dedicated to adding mirroring support.
It adds:

* the ShadowWriter which is used by the Router filter to mirror requests
* a ShadowRouter which is a RequestOwner that reuses the existing UpstreamRequest

There's still room for more code sharing and better interfaces, but that
can happen in future iterations.

Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
@repokitteh-read-only
Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to api/envoy/.
envoyproxy/api-shepherds assignee is @adisuissa
CC @envoyproxy/api-watchers: FYI only for changes made to api/envoy/.

🐱

Caused by: #17544 was opened by rgs1.

see: more, trace.

Raul Gutierrez Segales added 3 commits July 29, 2021 20:41
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Copy link
Copy Markdown
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

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

General API question, as I'm probably missing some context here:
Why not use the RequestMirrorPolicy type that is part of envoy.config.route.v3.RouteAction?

// If not specified, all requests to the target cluster will be mirrored.
//
// For some fraction N/D, a random number in the range [0,D) is selected. If the
// number is <= the value of the numerator N, or if the key is not present, the default
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 think you should remove the "or if the key is not present, the default value," as it complicates things, and you already wrote above "If not specified, all requests..." (I suggest moving this sentence to be the last, so you first explain what this field is, and then note the default value).

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 comes verbatim from the HTTP message, shall I clean up the description for both in a follow-up? Per my other comment, I rather keep them separate but happy to clarify both of them in one go.

@rgs1
Copy link
Copy Markdown
Member Author

rgs1 commented Aug 3, 2021

@zuercher here's a quick exegesis of this implementation, before you jump into the details:

  • all copy/pasta is gone, thanks to the previous refactoring PRs (there's a few nits for improvement, but really small).

  • UpstreamRequest was originally designed around two things: a) the upstream connection being ready and b) events generated by the downstream connection (namely, parts of the request message becoming available). Given that – in the case of a shadow request – these two things will happen independently of the original request, I introduced a std::list to save pending request events so that we can delay things until the shadow request's upstream connection becomes available. I am more than happy to discuss more appropriate data structures for this, but I do think the scheme of saving events from the original request for whenever the shadow request is ready probably works OK given it allows us to avoid additional plumbing to UpstreamRequest.

  • Finally, there's the dance between the Router and the ShadowRouter – they are technically independent but there are a few check points in which they need to coordinate. I think there's room for improvement for how this is implemented now (basically the Router signaling that it's done and thus allowing the ShadowRouter to clean itself up), so happy to explore alternative approaches.

There's also the fact that there's no timeouts for shadow requests in this first iteration, but I think that can be done in a follow-up. And of course I'll address the low coverage issue once we agree on the general direction of the PR.

cc: @fishcakez for feedback as well.

Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Copy link
Copy Markdown
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

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

We'll need to address this:

Code coverage for source/extensions/filters/network/thrift_proxy is lower than limit of 96.6 (93.4)
Code coverage for source/extensions/filters/network/thrift_proxy/router is lower than limit of 96.6 (77.5)

I expect it's probably because the pending_callbacks_ path isn't exercise in the tests (or isn't exercised for all the struct/field/list/map/set begin/end pairs.

@zuercher
Copy link
Copy Markdown
Member

zuercher commented Aug 6, 2021

I'm out next week, but I think this is fine to merge once the code coverage failure is resolved.

Raul Gutierrez Segales added 14 commits August 7, 2021 09:07
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Otherwise I get:

```
source/extensions/filters/network/thrift_proxy/protocol_converter.h:66:33: runtime error: load of value 208, which is not a valid value for type 'bool'
```

Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Raul Gutierrez Segales added 6 commits August 8, 2021 11:32
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
@rgs1
Copy link
Copy Markdown
Member Author

rgs1 commented Aug 8, 2021

/retest

@repokitteh-read-only
Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #17544 (comment) was created by @rgs1.

see: more, trace.

@rgs1
Copy link
Copy Markdown
Member Author

rgs1 commented Aug 8, 2021

Windows failure is unrelated:

//test/integration:proxy_proto_integration_test                          FAILED in 2 out of 2 in 6.0s

@rgs1
Copy link
Copy Markdown
Member Author

rgs1 commented Aug 8, 2021

General API question, as I'm probably missing some context here:
Why not use the RequestMirrorPolicy type that is part of envoy.config.route.v3.RouteAction?

We could potentially, however I am hesitant to reuse given the comments there have HTTP-isms in them, e.g.: the host/authority headers and there's also the trace span bits which currently aren't implemented for ThriftProxy.

So I think it's probably better to have a bit of duplication but a cleaner self contained configuration message.

@repokitteh-read-only repokitteh-read-only bot removed the api label Aug 9, 2021
@mattklein123 mattklein123 merged commit 7a93615 into envoyproxy:main Aug 9, 2021
mpuncel added a commit to mpuncel/envoy that referenced this pull request Aug 11, 2021
* main: (687 commits)
  ci: set build debug information from env (envoyproxy#17635)
  ext_authz: do the authentication even the direct response is set (envoyproxy#17546)
  upstream: various cleanups in connection pool code (envoyproxy#17644)
  owners: promote Dmitry to maintainer (envoyproxy#17642)
  quiche: client session supports creating bidi stream (envoyproxy#17543)
  Update HTTP/2 METADATA documentation. (envoyproxy#17637)
  ext_proc: Check validity of the :status header (envoyproxy#17596)
  test: add ASSERT indicating that gRPC stream has not been started yet (envoyproxy#17614)
  ensure that the inline cookie header will be folded correctly  (envoyproxy#17560)
  cluster_manager: Make ClusterEntry a class instead of a struct (envoyproxy#17616)
  owners: make Raúl a Thrift senior extension maintainer (envoyproxy#17641)
  quiche: update QUICHE dependency (envoyproxy#17618)
  Delete mock for removed RouteEntry::perFilterConfig() method (envoyproxy#17623)
  REPO_LAYOUT.md: fix outdated link (envoyproxy#17626)
  hcm: forbid use of detection extensions with use_remote_addr/xff_num_trusted_hops (envoyproxy#17558)
  thrift proxy: add request shadowing support (envoyproxy#17544)
  ext_proc: Ensure that timer is always cancelled (envoyproxy#17569)
  Proposal: Add CachePolicy interface to allow for custom cache behavior (envoyproxy#17362)
  proto: fix verify to point at v3 only (envoyproxy#17622)
  api: move generic matcher proto to its own package (envoyproxy#17096)
  ...
mpuncel added a commit to mpuncel/envoy that referenced this pull request Aug 16, 2021
* main: (687 commits)
  ci: set build debug information from env (envoyproxy#17635)
  ext_authz: do the authentication even the direct response is set (envoyproxy#17546)
  upstream: various cleanups in connection pool code (envoyproxy#17644)
  owners: promote Dmitry to maintainer (envoyproxy#17642)
  quiche: client session supports creating bidi stream (envoyproxy#17543)
  Update HTTP/2 METADATA documentation. (envoyproxy#17637)
  ext_proc: Check validity of the :status header (envoyproxy#17596)
  test: add ASSERT indicating that gRPC stream has not been started yet (envoyproxy#17614)
  ensure that the inline cookie header will be folded correctly  (envoyproxy#17560)
  cluster_manager: Make ClusterEntry a class instead of a struct (envoyproxy#17616)
  owners: make Raúl a Thrift senior extension maintainer (envoyproxy#17641)
  quiche: update QUICHE dependency (envoyproxy#17618)
  Delete mock for removed RouteEntry::perFilterConfig() method (envoyproxy#17623)
  REPO_LAYOUT.md: fix outdated link (envoyproxy#17626)
  hcm: forbid use of detection extensions with use_remote_addr/xff_num_trusted_hops (envoyproxy#17558)
  thrift proxy: add request shadowing support (envoyproxy#17544)
  ext_proc: Ensure that timer is always cancelled (envoyproxy#17569)
  Proposal: Add CachePolicy interface to allow for custom cache behavior (envoyproxy#17362)
  proto: fix verify to point at v3 only (envoyproxy#17622)
  api: move generic matcher proto to its own package (envoyproxy#17096)
  ...

Signed-off-by: Michael Puncel <mpuncel@squareup.com>
leyao-daily pushed a commit to leyao-daily/envoy that referenced this pull request Sep 30, 2021
This is the last PR in the series dedicated to adding mirroring support.
It adds:

* the ShadowWriter which is used by the Router filter to mirror requests
* a ShadowRouter which is a RequestOwner that reuses the existing UpstreamRequest

There's still room for more code sharing and better interfaces, but that
can happen in future iterations.

Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
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.

4 participants