Skip to content
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

gRPC/JSON transcoder: enable preserving route after headers modified #2848

Merged
merged 5 commits into from
Apr 10, 2018

Conversation

ilackarms
Copy link
Contributor

json-grpc transcoder filter: add option to skip clearing the route cache

Description:

the purpose of this PR is to add an option to the JSON-gRPC transcoder filter to allow preserving the original routing decision made by Envoy before this filter is called. Sometimes it is not desired that Envoy will not recalculate the route for a transcoded request; this option makes available that use case for the user.

This change depends on envoyproxy/data-plane-api#569 where the option to skip has been added as a parameter for the filter config

Discussion can be found here: #2847

Risk Level: Medium

Testing:
A single unit test that verifies that, when the option is enabled, decoder_callbacks_->clearRouteCache() is not called.

The change was also tested manually, where the outgoing route was matched based on the incoming :path header, rather than the outgoing.

Docs Changes:

Link to Data Plane PR

Release Notes:

Link to Data Plane PR (Same as above, unless I misunderstood)

[Optional Fixes #Issue]

Addresses #2847

[Optional API Changes:]
Link to Data Plane PR

@@ -217,7 +223,9 @@ Http::FilterHeadersStatus JsonTranscoderFilter::decodeHeaders(Http::HeaderMap& h
headers.insertMethod().value().setReference(Http::Headers::get().MethodValues.Post);
headers.insertTE().value().setReference(Http::Headers::get().TEValues.Trailers);

decoder_callbacks_->clearRouteCache();
if (!config_.match_incoming_request_route()) {
Copy link
Member

Choose a reason for hiding this comment

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

Call decoder_callbacks_->route() in before the header conversion if match_incoming_request_route is set, to make sure we're not depending on the behavior that HTTP conn manager pre-calculate route. Since route is cached, this call won't impact performance.

Copy link
Member

Choose a reason for hiding this comment

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

@ilackarms friendly reminder.

@htuch htuch assigned lizan and htuch Mar 21, 2018
match_incoming_request_route_ = proto_config.match_incoming_request_route();
}

bool JsonTranscoderConfig::match_incoming_request_route() {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: bool JsonTranscoderConfig::matchIncomingRequestRoute() const

@@ -62,6 +62,14 @@ class JsonTranscoderConfig : public Logger::Loggable<Logger::Id::config> {
std::unique_ptr<google::grpc::transcoding::Transcoder>& transcoder,
const Protobuf::MethodDescriptor*& method_descriptor);


Copy link
Member

Choose a reason for hiding this comment

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

This file and the .cc are out-of-sync (the newly declared field doesn't match). Can you update? Thanks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

noticed this and hadn't had a chance to push the change. should be fixed now

@ilackarms ilackarms force-pushed the skip-recalculating-route branch from f55ccd5 to 729be7f Compare March 29, 2018 20:03
htuch
htuch previously approved these changes Mar 30, 2018
@@ -74,6 +82,8 @@ class JsonTranscoderConfig : public Logger::Loggable<Logger::Id::config> {
google::grpc::transcoding::PathMatcherPtr<const Protobuf::MethodDescriptor*> path_matcher_;
std::unique_ptr<google::grpc::transcoding::TypeHelper> type_helper_;
Protobuf::util::JsonPrintOptions print_options_;

bool match_incoming_request_route_{false};
Copy link
Member

Choose a reason for hiding this comment

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

Nit: You can make this a const if you initialize it in the constructor initializor list.

Copy link
Member

Choose a reason for hiding this comment

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

Ping on this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

are you sure i can? this gets set from the proto_config passed to the constructor

@htuch
Copy link
Member

htuch commented Mar 30, 2018

@ilackarms this still has build failures.

@ilackarms
Copy link
Contributor Author

@htuch the build is failing because envoyproxy/data-plane-api#569 has not yet been merged.
i can update repository_locations.bzl with my fork of data-plane-api but i assumed it would be better to wait until that's merged

@ilackarms ilackarms force-pushed the skip-recalculating-route branch from 1f04e68 to 73d7d6d Compare April 2, 2018 15:54
* This allows Envoy to select the upstream cluster based on the incoming request
* rather than the outgoing.
*/
bool matchIncomingRequestRoute();
Copy link
Member

Choose a reason for hiding this comment

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

Nit: bool matchIncomingRequestInfo() const;

Copy link
Member

Choose a reason for hiding this comment

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

Ping on this one.

@ilackarms
Copy link
Contributor Author

sorry for the delay on this; having some trouble running bazel on my machine at the moment

Copy link
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 modulo some nits. @ilackarms if you can do a quick cleanup PR we can merge this.

* This allows Envoy to select the upstream cluster based on the incoming request
* rather than the outgoing.
*/
bool matchIncomingRequestRoute();
Copy link
Member

Choose a reason for hiding this comment

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

Ping on this one.

public:
GrpcJsonTranscoderFilterSkipRecalculatingTest() : GrpcJsonTranscoderFilterTest(true) {}
};

Copy link
Member

Choose a reason for hiding this comment

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

Move this down next to the relevant test.

@@ -197,17 +205,20 @@ TEST_F(GrpcJsonTranscoderConfigTest, InvalidVariableBinding) {

class GrpcJsonTranscoderFilterTest : public testing::Test {
public:
GrpcJsonTranscoderFilterTest() : config_(bookstoreProtoConfig()), filter_(config_) {
GrpcJsonTranscoderFilterTest(const bool match_incoming_request_route = false)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: const bool doesn't really do anything here, jsut make it bool.

@@ -74,6 +82,8 @@ class JsonTranscoderConfig : public Logger::Loggable<Logger::Id::config> {
google::grpc::transcoding::PathMatcherPtr<const Protobuf::MethodDescriptor*> path_matcher_;
std::unique_ptr<google::grpc::transcoding::TypeHelper> type_helper_;
Protobuf::util::JsonPrintOptions print_options_;

bool match_incoming_request_route_{false};
Copy link
Member

Choose a reason for hiding this comment

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

Ping on this one.

Signed-off-by: ilackarms <[email protected]>
Signed-off-by: ilackarms <[email protected]>
Copy link
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.

Thanks!

@htuch htuch merged commit d41d06e into envoyproxy:master Apr 10, 2018
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.

3 participants