ASMGrpcJsonTranscoder is a custom resource (CR) used for transcoding between HTTP/JSON and gRPC/Protobuf. This topic describes the fields of ASMGrpcJsonTranscoder.
Field description
Field | Type | Required | Description |
workloadSelector | map<string, string> | Yes | Labels that select the pods where transcoding takes effect. The label scope is limited to the namespace where the ASMGrpcJsonTranscoder resource resides. For more information, see Workload Selector. |
isGateway | bool | No | Whether to apply transcoding at the gateway. Default: |
portNumber | int | Yes | The corresponding service port. When |
services | string[] | Yes | gRPC service names declared in the proto file, in |
protoDescriptorBin | string | Yes | Base64-encoded content of the proto descriptor file. The value of this field must be Base64-encoded. |
transcodeFirst | bool | No | Whether to transcode the HTTP request before other processing in the filter chain. Default: |
convertGrpcStatus | bool | No | Whether to convert |
ignoredQueryParameters | \[\]string | No | Query parameters to skip during proto field mapping. By default, the transcoder does not transcode requests that contain unknown or invalid query parameters. Parameters listed here are ignored during mapping, allowing the request to be transcoded. |
ignoreUnknownQueryParameters | bool | No | Whether to ignore all query parameters that cannot be mapped to proto fields. Default: Important When both |
services field example
Specify each gRPC service as {package name}.{service name}:
services:
- 'helloworld.Greeter'gRPC status conversion
When convertGrpcStatus is true and a gRPC error is returned without an HTTP response body, the transcoder converts the error to a JSON response as follows:
If the
grpc-status-details-binheader exists, the transcoder decodes the Base64-encodedgoogle.rpc.Statusprotobuf message and returns it as the JSON body.If the header does not exist, the transcoder constructs a
google.rpc.Statusmessage from thegrpc-statusandgrpc-messageheaders.
Example
The upstream service returns the following gRPC headers:
grpc-status: 5
grpc-status-details-bin: CAUaMwoqdHlwZS5nb29nbGVhcGlzLmNvbS9nb29nbGUucnBjLlJlcXVlc3RJbmZvEgUKA3ItMQThe grpc-status-details-bin header contains a Base64-encoded google.rpc.Status protobuf message. The transcoder converts this to the following HTTP response:
HTTP/1.1 404 Not Found
content-type: application/json
{
"code": 5,
"details": [
{
"@type": "type.googleapis.com/google.rpc.RequestInfo",
"requestId": "r-1"
}
]
}