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

transcoding: Teach transcoding filter to be aware of per vhost / per route settings #11188

Merged
merged 27 commits into from
Jan 29, 2021

Conversation

gagata
Copy link
Contributor

@gagata gagata commented May 14, 2020

Commit Message:
Adding support for per-route grpc json transcoding filter.

Additional Description:
Risk Level: low (adds a new usage for the transcoding filter, doesn't change the current behavior / use cases)
Testing:
Docs Changes:
Release Notes:

Fixes #11038

Agata Cieplik added 2 commits May 13, 2020 17:55
Signed-off-by: Agata Cieplik <[email protected]>
@gagata gagata requested a review from lizan as a code owner May 14, 2020 01:14
@repokitteh-read-only
Copy link

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

🐱

Caused by: #11188 was opened by gagata.

see: more, trace.

option (validate.required) = true;

// Disable the grpc json trasncoder filter for this particular vhost or route.
bool disabled = 1 [(validate.rules).bool = {const: true}];
Copy link
Member

Choose a reason for hiding this comment

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

Informational: this is another place that #8669 would help.

oneof override {
option (validate.required) = true;

// Disable the grpc json trasncoder filter for this particular vhost or 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: trasncoder typo

@gagata gagata marked this pull request as draft May 23, 2020 00:51
@gagata gagata marked this pull request as ready for review May 27, 2020 03:52
Copy link
Contributor

@euroelessar euroelessar left a comment

Choose a reason for hiding this comment

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

Looks great! few minor comments

@@ -118,12 +132,14 @@ class JsonTranscoderConfig : public Logger::Loggable<Logger::Id::config> {

Protobuf::DescriptorPool descriptor_pool_;
google::grpc::transcoding::PathMatcherPtr<MethodInfoSharedPtr> path_matcher_;
std::unique_ptr<google::grpc::transcoding::TypeHelper> type_helper_;
std::shared_ptr<google::grpc::transcoding::TypeHelper> type_helper_;
Copy link
Contributor

Choose a reason for hiding this comment

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

what does make this change needed?


JsonTranscoderConfig& config_;
const JsonTranscoderConfig* per_route_config_{nullptr};
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: const JsonTranscoderConfig* per_route_config_{}; is equivalent and looks like is more favored in the code base

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good, changed in the whole file so it's all consistent

@euroelessar
Copy link
Contributor

@htuch Can you advice please, what's a recommended way to make this filter opt-in? For instance, we want to disable it by default but then enable (with different configs) for subset of virtual hosts.
It is acceptable to lift requirement for minimum one field in list of services? Or what are other options?

@qiwzhang
Copy link
Contributor

We could remove the two validation rules for descriptor and services to allow empty config at filter config, allow per_route_config to specify a valid one. An empty "descriptor' and services config will be treated as "disabled" since the method will not be matched in the path_matcher.

@htuch
Copy link
Member

htuch commented Jun 1, 2020

Yeah, per-route filter config override seems a good way to provide per-vhost opt-in.

- services list can be empty (and means that filter is then disabled)
- left the requirement on the descriptor set to be still specified (so
that it's more explicit that the intention is to disable the filter /
won't accidentally end up with missing descriptor field)

Signed-off-by: Agata Cieplik <[email protected]>
@gagata
Copy link
Contributor Author

gagata commented Jun 5, 2020

We could remove the two validation rules for descriptor and services to allow empty config at filter config, allow per_route_config to specify a valid one. An empty "descriptor' and services config will be treated as "disabled" since the method will not be matched in the path_matcher.

so I left required validation for descriptor, thinking that it's just going to be more explicit in the configuration... do we prefer to simply not have it specified at all?

@@ -64,7 +64,8 @@ message GrpcJsonTranscoder {
// the transcoder will translate. If the service name doesn't exist in ``proto_descriptor``,
// Envoy will fail at startup. The ``proto_descriptor`` may contain more services than
// the service names specified here, but they won't be translated.
repeated string services = 2 [(validate.rules).repeated = {min_items: 1}];
// If the list of services is empty, filter is considered disabled.
repeated string services = 2 [(validate.rules).repeated = {min_items: 0}];
Copy link
Member

Choose a reason for hiding this comment

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

You can just drop the annotation completely if min_items is 0.

@euroelessar
Copy link
Contributor

@htuch @lizan @qiwzhang Can you check the pull request, please? It's in a limbo mode for a long time now.

@mattklein123 mattklein123 self-assigned this Dec 28, 2020
@mattklein123
Copy link
Member

What is the status of this PR? Is it ready to review? Can someone merge main into it?

/wait

JsonTranscoderConfig(
const envoy::extensions::filters::http::grpc_json_transcoder::v3::GrpcJsonTranscoder&
proto_config,
Api::Api& api, bool disabled);
Copy link
Contributor

Choose a reason for hiding this comment

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

is this still needed?

test/proto/BUILD Outdated
@@ -44,6 +44,12 @@ envoy_proto_descriptor(
],
)

envoy_proto_descriptor(
name = "helloworld_proto_descriptor",
Copy link
Contributor

Choose a reason for hiding this comment

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

is this descriptor used?

@@ -611,7 +643,7 @@ JsonTranscoderFilter::encodeTrailers(Http::ResponseTrailerMap& trailers) {
}

void JsonTranscoderFilter::doTrailers(Http::ResponseHeaderOrTrailerMap& headers_or_trailers) {
if (error_ || !transcoder_) {
if (error_ || !transcoder_ || per_route_config_->disabled()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible that per_route_config_ is not initialized in this call? e.g. decodeHeader() is not called.

Same question for maybeConvertGrpcStatus() function

Agata Cieplik added 2 commits December 29, 2020 21:27
qiwzhang
qiwzhang previously approved these changes Dec 30, 2020
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks LGTM with a small comment.

/wait

google::grpc::transcoding::TranscoderInputStream& response_input,
std::unique_ptr<Transcoder>& transcoder, MethodInfoSharedPtr& method_info) const {

if (disabled_) {
Copy link
Member

Choose a reason for hiding this comment

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

Generally we don't do defensive coding like this. I would switch this to an ASSERT with a comment if you like.

Copy link
Member

@mattklein123 mattklein123 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 I think this needs a release note?

/wait

Base automatically changed from master to main January 15, 2021 23:01
Agata Cieplik added 2 commits January 22, 2021 14:07
@gagata
Copy link
Contributor Author

gagata commented Jan 28, 2021

@mattklein123 i adjusted the release notes, do you think it's ok?

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks!

@mattklein123 mattklein123 merged commit 5ef3f8d into envoyproxy:main Jan 29, 2021
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.

Teach transcoding filter to be aware of per vhost / per route settings
6 participants