feat(grpc-transcode): resolve service and method from google.api.http annotations - #13812
Open
alirezashamsabad wants to merge 4 commits into
Open
feat(grpc-transcode): resolve service and method from google.api.http annotations#13812alirezashamsabad wants to merge 4 commits into
alirezashamsabad wants to merge 4 commits into
Conversation
Author
|
For anyone triaging the size:XXL label: of the 3,196 added lines, 1,160 are Related: #13811 fixes a separate pre-existing bug in the same plugin |
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Today a Route using
grpc-transcodeis bound to exactly one gRPC method throughserviceandmethod, so a service with ten methods needs ten Routes. That duplicatesconfiguration the proto usually already declares via
google.api.httpannotations.This adds an optional
use_http_annotationsflag. When enabled, the plugin reads thoseannotations and selects the method whose path template and HTTP method match the request.
One Route can then serve a whole annotated service:
{ "uri": "/api/v1/*", "plugins": { "grpc-transcode": { "proto_id": "1", "use_http_annotations": true } }, "upstream": { "scheme": "grpc", "type": "roundrobin", "nodes": { "127.0.0.1:50051": 1 } } }GET /api/v1/items/42reachesItemService/GetItemwithidbound to42, andPOST /api/v1/itemsreachesItemService/CreateItem, without per-method Routes.Which issue(s) this PR fixes:
Relates to #3406, which was closed as
not planned before any implementation existed. This PR provides one, with tests and
documentation, so the trade-offs can be judged concretely.
What is supported
google.api.httpgrammar: literals,{var},{var=*},{var=a/*/b},**, nested field paths such as{user.id}, and a trailing:verbadditional_bindingsbodysemantics: omitted means the payload is not read;"*"means the whole payloadis the message;
"<field>"maps the payload to that field and leaves siblings to thequery string
:verbis matched separately and is not part of the rankingserviceandmethodare ignoredBackwards compatibility
The flag defaults to
false. When it is off,serviceandmethodstay mandatory, soexisting configs and validation errors are unchanged.
Behavior change in both modes:
accessreturns503when the proto cannot be loaded.Previously the request was forwarded untranscoded and often surfaced as a confusing
upstream
405. The gateway now fails closed and logs the reason.Notes for reviewers
protoc --include_imports --descriptor_set_out=.... A plain.protouploaded to/apisix/admin/protoscannot resolvegoogle/api/annotations.proto.method.options.http.t/grpc_server_example/proto/google/api/{annotations,http}.protoare checked in for the fixture descriptor set (Apache-2.0 under Google's copyright;
listed in
LICENSEand ignored in.licenserc.yaml).bodysupports a top-level field name only (notbody: "item.nested").failed to find proto by idcan still occur whilethe etcd config sync is in flight. It reproduces on legacy
service/methodroutesas well, and its cause is distinct from the type mismatch in
#8952. I have not root-caused it, so
it is not addressed here.
Tests
t/plugin/grpc-transcode-http-annotations.tcovers path-template parsing and rejection,end-to-end routing,
bodymodes,:verb, path-over-query/body,404,405withAllow,400,503,proxy-rewrite, and rebuilding the table after proto replacement.t/plugin/grpc-transcode*.tpasses (297 assertions).Developed with AI assistance; design decisions, review and testing are my own.
Checklist