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 <ascheglov@yandex-team.ru>

Mirrored from https://github.com/envoyproxy/envoy @ 219e8b91809d14cfea2c064c59a5ac98647840b1
pull/620/head
data-plane-api(CircleCI) 5 years ago
parent bdef97ce85
commit f1cae72ae1
  1. 30
      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 <config_grpc_json_generate_proto_descriptor_set>`.
bool convert_grpc_status = 9;
}

Loading…
Cancel
Save