kong icon indicating copy to clipboard operation
kong copied to clipboard

Incorrect or Unexpected Outputs from grpc-gateway plugin

Open JKTChua opened this issue 2 years ago • 1 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Kong version ($ kong version)

Kong 3.2.2

Current Behavior

Problem 1 The underlying gRPC service outputs a field with an empty array value.

image

Using the grpc-gateway plugin and a proto config, the output from Kong is a 200 OK Status and an empty string body.

image image

Problem 2 In my attempts to work around this issue, I modified the underlying gRPC service to output an additional field that would not even need to be parsed by the grpc-gateway plugin.

image

The output from Kong is closer to what my expectation. However, the array field is exposed as an object rather than array.

image

Expected Behavior

I would expect the first scenario to output valid JSON at the very least (e.g. empty object {}), but at the most I would want it to output the same result as the response in my first screenshot: valid JSON with an empty array in the single field (e.g. {"decisions": []}).

The second scenario should output the field's value as an empty array (e.g. {"decisions": []}) rather than an empty object.

Steps To Reproduce

  1. With this kong.yml
_format_version: "3.0"

_transform: true

services:
 - host: host.docker.internal
   name: cyber-lifecycle
   port: 9090
   protocol: grpc
   routes:
   - protocols:
     - http
     name: decision
     paths:
     - ~/v1/Packages/[\-0-9a-zA-Z]+/Decisions$
     plugins:
     - name: grpc-gateway
       config:
        proto: /protos/decision.proto
  1. With this proto file
syntax = "proto3";

package decision;
option go_package = "/lifecycle/decision";

import "google/api/annotations.proto";

service DecisionService {
  rpc GetPackageDecisions(GetPackageDecisionsRequest) returns (GetPackageDecisionsResponse) {
    option (google.api.http) = {
      get: "/v1/Packages/{uuid}/Decisions",
    };
  }
}

message GetPackageDecisionsRequest {
  string uuid = 1;
}

message GetPackageDecisionsResponse {
  repeated Decision decisions = 1;
}

message Decision {
  string uuid = 1;
}
  1. Run Kong and also standup a gRPC service with the same protobuf interface that outputs an empty array for the decisions field.
  2. Make an HTTP request via Kong which should route the request to the gRPC service.
  3. Observe the response from Kong.

Anything else?

No response

JKTChua avatar Apr 25 '23 21:04 JKTChua

Thanks for reporting this. This is a known issue of the gRPC-gateway. Lua has an implementation limitation in that we cannot tell an empty array from an empty table(object); also, default values(empty array here) and nil cannot be distinguished, so to Kong, the first message is no different from nil. We are trying to solve this issue and improve the gRPC implementation. Please check the discussion here: https://github.com/Kong/kong/pull/8297

And we always suggest use the latest version(master or most recent release).

StarlightIbuki avatar Aug 31 '23 07:08 StarlightIbuki