-
Notifications
You must be signed in to change notification settings - Fork 5.5k
docs: improve gRPC-JSON filter doc #4184
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,13 @@ This is a filter which allows a RESTful JSON API client to send requests to Envo | |
| and get proxied to a gRPC service. The HTTP mapping for the gRPC service has to be defined by | ||
| `custom options <https://cloud.google.com/service-management/reference/rpc/google.api#http>`_. | ||
|
|
||
| JSON mapping | ||
| ------------ | ||
|
|
||
| The protobuf to JSON mapping is defined `here <https://developers.google.com/protocol-buffers/docs/proto3#json>`_. For | ||
| gRPC stream request parameters, Envoy expects an array of messages, and it returns an array of messages for stream | ||
| response parameters. | ||
|
|
||
| .. _config_grpc_json_generate_proto_descriptor_set: | ||
|
|
||
| How to generate proto descriptor set | ||
|
|
@@ -74,4 +81,81 @@ as its output message type. The implementation needs to set | |
| `content_type <https://github.com/googleapis/googleapis/blob/master/google/api/httpbody.proto#L68>`_ | ||
| (which sets the value of the HTTP response `Content-Type` header) and | ||
| `data <https://github.com/googleapis/googleapis/blob/master/google/api/httpbody.proto#L71>`_ | ||
| (which sets the HTTP response body) accordingly. | ||
| (which sets the HTTP response body) accordingly. | ||
|
|
||
|
|
||
| Sample Envoy configuration | ||
| -------------------------- | ||
|
|
||
| Here's a sample Envoy configuration that proxies to a gRPC server running on localhost:50051. Port 51051 proxies gRPC | ||
| requests, while port 51052 uses the gRPC-JSON transcoder filter to provide the RESTful JSON mapping. | ||
|
|
||
| .. code-block:: yaml | ||
|
|
||
| admin: | ||
| access_log_path: /tmp/admin_access.log | ||
| address: | ||
| socket_address: { address: 0.0.0.0, port_value: 9901 } | ||
|
|
||
| static_resources: | ||
| listeners: | ||
| - name: listener1 | ||
| address: | ||
| socket_address: { address: 0.0.0.0, port_value: 51051 } | ||
| filter_chains: | ||
| - filters: | ||
| - name: envoy.http_connection_manager | ||
| config: | ||
| stat_prefix: grpc | ||
| codec_type: AUTO | ||
| route_config: | ||
| name: local_route | ||
| virtual_hosts: | ||
| - name: local_service | ||
| domains: ["*"] | ||
| routes: | ||
| - match: { prefix: "/" } | ||
| route: { cluster: grpc, timeout: { seconds: 60 } } | ||
| http_filters: | ||
| - name: envoy.router | ||
|
|
||
| - name: listener2 | ||
| address: | ||
| socket_address: { address: 0.0.0.0, port_value: 51052 } | ||
| filter_chains: | ||
| - filters: | ||
| - name: envoy.http_connection_manager | ||
| config: | ||
| stat_prefix: grpc_json | ||
| codec_type: AUTO | ||
| route_config: | ||
| name: local_route | ||
| virtual_hosts: | ||
| - name: local_service | ||
| domains: ["*"] | ||
| routes: | ||
| - match: { prefix: "/" } | ||
| route: { cluster: grpc, timeout: { seconds: 60 } } | ||
| http_filters: | ||
| - name: envoy.grpc_json_transcoder | ||
| config: | ||
| proto_descriptor: "/tmp/envoy/proto.pb" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: 2 space indent |
||
| services: ["HelloWorld"] | ||
| print_options: | ||
| add_whitespace: true | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
| always_print_primitive_fields: true | ||
| always_print_enums_as_ints: false | ||
| preserve_proto_field_names: false | ||
| - name: envoy.router | ||
|
|
||
| clusters: | ||
| - name: grpc | ||
| connect_timeout: 1.25s | ||
| type: logical_dns | ||
| lb_policy: round_robin | ||
| dns_lookup_family: V4_ONLY | ||
| http2_protocol_options: {} | ||
| hosts: | ||
| - socket_address: | ||
| address: docker.for.mac.localhost | ||
| port_value: 50051 | ||
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.
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 don't think you need this, listener2 can serve both gRPC and its RESTful JSON mapping.
Uh oh!
There was an error while loading. Please reload this page.
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.
Good to know, didn't realize that. Will simplify the config.