-
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
transcoding: Teach transcoding filter to be aware of per vhost / per route settings #11188
Conversation
Signed-off-by: Agata Cieplik <[email protected]>
Signed-off-by: Agata Cieplik <[email protected]>
source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.cc
Show resolved
Hide resolved
option (validate.required) = true; | ||
|
||
// Disable the grpc json trasncoder filter for this particular vhost or route. | ||
bool disabled = 1 [(validate.rules).bool = {const: true}]; |
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.
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. |
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: trasncoder typo
api/envoy/extensions/filters/http/grpc_json_transcoder/v3/transcoder.proto
Outdated
Show resolved
Hide resolved
Signed-off-by: Agata Cieplik <[email protected]>
Signed-off-by: Agata Cieplik <[email protected]>
Signed-off-by: Agata Cieplik <[email protected]>
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.
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_; |
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.
what does make this change needed?
|
||
JsonTranscoderConfig& config_; | ||
const JsonTranscoderConfig* per_route_config_{nullptr}; |
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 JsonTranscoderConfig* per_route_config_{};
is equivalent and looks like is more favored in the code base
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.
sounds good, changed in the whole file so it's all consistent
@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. |
We could remove the two validation rules for |
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]>
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? |
api/envoy/extensions/filters/http/grpc_json_transcoder/v3/transcoder.proto
Show resolved
Hide resolved
@@ -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}]; |
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.
You can just drop the annotation completely if min_items
is 0.
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); |
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.
is this still needed?
test/proto/BUILD
Outdated
@@ -44,6 +44,12 @@ envoy_proto_descriptor( | |||
], | |||
) | |||
|
|||
envoy_proto_descriptor( | |||
name = "helloworld_proto_descriptor", |
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.
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()) { |
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.
is it possible that per_route_config_ is not initialized in this call? e.g. decodeHeader() is not called.
Same question for maybeConvertGrpcStatus() function
Signed-off-by: Agata Cieplik <[email protected]>
…ue-11038 Signed-off-by: Agata Cieplik <[email protected]>
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 LGTM with a small comment.
/wait
google::grpc::transcoding::TranscoderInputStream& response_input, | ||
std::unique_ptr<Transcoder>& transcoder, MethodInfoSharedPtr& method_info) const { | ||
|
||
if (disabled_) { |
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.
Generally we don't do defensive coding like this. I would switch this to an ASSERT with a comment if you like.
…ue-11038 Signed-off-by: Agata Cieplik <[email protected]>
Signed-off-by: Agata Cieplik <[email protected]>
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 but I think this needs a release note?
/wait
…-11038 Signed-off-by: Agata Cieplik <[email protected]>
Signed-off-by: Agata Cieplik <[email protected]>
…-11038 Signed-off-by: Agata Cieplik <[email protected]>
@mattklein123 i adjusted the release notes, do you think it's ok? |
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!
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