From f1cae72ae100fd41221f1ff4db5b7ae3821ae9e0 Mon Sep 17 00:00:00 2001 From: "data-plane-api(CircleCI)" Date: Thu, 19 Sep 2019 05:43:03 +0000 Subject: [PATCH] grpc-json: add option to convert gRPC status into JSON body (#3383) (#8009) When trailer indicates a gRPC error and there was no HTTP body, with the `convert_grpc_status option` enabled, take `google.rpc.Status` from the `grpc-status-details-bin` header and use it as a JSON body. If there was no such header, make `google.rpc.Status` out of the `grpc-status` and `grpc-message` headers. This also adds `google.rpc.Status` to user-provided protobuf descriptor. Risk Level: Small-medium Testing: Added unit and integration tests tests, tested manually. Docs Changes: Added field description in api/envoy/config/filter/http/transcoder/v2/transcoder.proto Release Notes: Fixes #3383 Signed-off-by: Anatoly Scheglov Mirrored from https://github.com/envoyproxy/envoy @ 219e8b91809d14cfea2c064c59a5ac98647840b1 --- .../http/transcoder/v2/transcoder.proto | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/envoy/config/filter/http/transcoder/v2/transcoder.proto b/envoy/config/filter/http/transcoder/v2/transcoder.proto index 85f837fa..248f78bb 100644 --- a/envoy/config/filter/http/transcoder/v2/transcoder.proto +++ b/envoy/config/filter/http/transcoder/v2/transcoder.proto @@ -119,4 +119,34 @@ message GrpcJsonTranscoder { // not know them beforehand. Otherwise use ``ignored_query_parameters``. // Defaults to false. bool ignore_unknown_query_parameters = 8; + + // Whether to convert gRPC status headers to JSON. + // When trailer indicates a gRPC error and there was no HTTP body, take ``google.rpc.Status`` + // from the ``grpc-status-details-bin`` header and use it as JSON body. + // If there was no such header, make ``google.rpc.Status`` out of the ``grpc-status`` and + // ``grpc-message`` headers. + // The error details types must be present in the ``proto_descriptor``. + // + // For example, if an upstream server replies with headers: + // + // .. code-block:: none + // + // grpc-status: 5 + // grpc-status-details-bin: + // CAUaMwoqdHlwZS5nb29nbGVhcGlzLmNvbS9nb29nbGUucnBjLlJlcXVlc3RJbmZvEgUKA3ItMQ + // + // The ``grpc-status-details-bin`` header contains a base64-encoded protobuf message + // ``google.rpc.Status``. It will be transcoded into: + // + // .. code-block:: none + // + // HTTP/1.1 404 Not Found + // content-type: application/json + // + // {"code":5,"details":[{"@type":"type.googleapis.com/google.rpc.RequestInfo","requestId":"r-1"}]} + // + // In order to transcode the message, the ``google.rpc.RequestInfo`` type from + // the ``google/rpc/error_details.proto`` should be included in the configured + // :ref:`proto descriptor set `. + bool convert_grpc_status = 9; }