-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
thrift: allow translation between downstream and upstream protocols #4136
thrift: allow translation between downstream and upstream protocols #4136
Conversation
We use the new extension_protocol_options field on Cluster to allow clusters to be configured with a transport and/or protocol. Downstream requests are automatically translated to the upstream dialect and upstream responses are translated back to the downstream's dialect. Moves the TransportType and ProtocolType protobuf enums out of the ThriftProxy message to allow their re-use in ThriftProtocolOptions. *Risk Level*: low *Testing*: integration test *Docs Changes*: added thrift filter docs *Release Notes*: n/a Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
tag @rgs1, @fishcakez |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 nits
@@ -125,6 +126,19 @@ ThriftFilters::FilterStatus Router::messageBegin(MessageMetadataSharedPtr metada | |||
return ThriftFilters::FilterStatus::StopIteration; | |||
} | |||
|
|||
std::shared_ptr<const ProtocolOptionsConfig> options = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: const
NetworkFilterNames::get().ThriftProxy); | ||
|
||
TransportType transport_type = callbacks_->downstreamTransportType(); | ||
ProtocolType protocol_type = callbacks_->downstreamProtocolType(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: these could be const, if the conditional from below is folded into these statements with ternary operators
Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this feature. Based on the latest commits, this PR lgtm.
Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
@envoyproxy/maintainers would appreciate a quick review for style/c++ gotchas so that I can merge this. |
Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
(merged clang-6.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zuercher sorry about the delayed review, it looks great, just the style/nits pass you were after.
// [#comment:next free field: 3] | ||
message ThriftProtocolOptions { | ||
// Supplies the type of transport that the Thrift proxy should use for upstream connections. | ||
// Selecting `AUTO_TRANSPORT` causes the proxy to use the same transport as the downstream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: optionally link back with :ref
to the enum definition/values.
Thrift proxy | ||
============ | ||
|
||
* The Thrift proxy is not supported in the v1 API. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd drop any mention of v1 API; it's about to disappear at the next release cycle, so one fewer places to clean up.
ProtocolType protocol(ProtocolType downstream_protocol) const override; | ||
|
||
private: | ||
TransportType transport_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: these can be const
.
@@ -35,6 +35,14 @@ class Config { | |||
virtual Router::Config& routerConfig() PURE; | |||
}; | |||
|
|||
class ProtocolOptionsConfig : public Upstream::ProtocolOptionsConfig { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments, since this is an abstract interface?
namespace ThriftProxy { | ||
|
||
const std::string& PayloadOptions::modeName() const { | ||
static const std::string success = "success"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: technically a violation of the static initialization fiasco rule. The easy workaround is to make these char[]
or just inline them below, which is clearer IMHO.
Buffer::Instance& response_buffer) { | ||
std::vector<std::string> args = { | ||
TestEnvironment::runfilesPath( | ||
"test/extensions/filters/network/thrift_proxy/driver/generate_fixture.sh"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wow, I know this is refactored code, but this is quite the elaborate input generation system. How do you guarantee the availability of the thrift
Python libraries and tooling? I had a quick look, it was unclear how Bazel's hermeticity is respected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The libraries were added to the external dependencies: 56a047b
As far as tooling, the generated python bindings are checked in under the test hierarchy so no tools are needed at build or test time. The upshot is that if ever one wanted to change the service or object definitions you'd need to install apache-thrift to regenerate them, but I think this is better than making the whole of apache-thrift a build dependency.
This seemed like the least invasive way to allow Thrift integration tests. I considered running the client.py/server.py rather than generating fixtures, but orchestrating the processes and ports seemed like more trouble than it was worth.
|
||
std::ifstream::pos_type len = is.tellg(); | ||
if (len > 0) { | ||
std::vector<char> bytes(len, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespace NetworkFilters { | ||
namespace ThriftProxy { | ||
namespace { | ||
std::string thrift_config; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not make this a member of the test fixture below? The name should be thrift_config_
in any case, to prevent confusion with local variables.
GetParam(); | ||
|
||
envoy::config::filter::network::thrift_proxy::v2alpha1::TransportType upstream_transport_proto; | ||
switch (upstream_transport) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Factor these switches out to utility functions in a common library? Seems generally useful across tests, etc.
Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, feel free to merge if you feel this is final.
* origin/master: (34 commits) fuzz: fixes oss-fuzz: 9895 (envoyproxy#4189) docs: added developer docs for pprof/tcmalloc testing (envoyproxy#4194) fix sometimes returns response body to HEAD requests (envoyproxy#3985) admin: fix config dump order (envoyproxy#4197) thrift: allow translation between downstream and upstream protocols (envoyproxy#4136) Use local_info.node() instead of bootstrap.node() whenever possible (envoyproxy#4120) upstream: allow extension protocol options to be used with http filters (envoyproxy#4165) [thrift_proxy] Replace local HeaderMap with Http::HeaderMap[Impl] (envoyproxy#4169) docs: improve gRPC-JSON filter doc (envoyproxy#4184) stats: refactoring MetricImpl without strings (envoyproxy#4190) fuzz: coverage profile generation instructions. (envoyproxy#4193) upstream: rebuild cluster when health check config is changed (envoyproxy#4075) build: use clang-6.0. (envoyproxy#4168) thrift_proxy: introduce header transport (envoyproxy#4082) tcp: allow connection pool callers to store protocol state (envoyproxy#4131) configs: match latest API changes (envoyproxy#4185) Fix wrong mock function name. (envoyproxy#4187) Bump yaml-cpp so it builds with Visual Studio 15.8 (envoyproxy#4182) Converting envoy configs to V2 (envoyproxy#2957) Add timestamp to HealthCheckEvent definition (envoyproxy#4119) ... Signed-off-by: Snow Pettersen <snowp@squareup.com>
We use the new extension_protocol_options field on Cluster to allow clusters
to be configured with a transport and/or protocol. Downstream requests are
automatically translated to the upstream dialect and upstream responses are
translated back to the downstream's dialect.
Moves the TransportType and ProtocolType protobuf enums out of the
ThriftProxy message to allow their re-use in ThriftProtocolOptions.
Risk Level: low
Testing: integration test
Docs Changes: added thrift filter docs
Release Notes: n/a
Signed-off-by: Stephan Zuercher stephan@turbinelabs.io