如何在 CloudRun 上通过反射来 grpcurl 列出 gRPC 服务?

gsp*_*spq 6 go grpc google-cloud-run

按照这个例子:

\n

Google Cloud Run 中的 gRPC

\n

https://github.com/grpc-ecosystem/grpc-cloud-run-example/blob/master/golang/README.md

\n

我已经在 CloudRun 上部署了带有反射的 gRPC 服务。

\n

使用 grpcurl 进行测试:\n https://github.com/fullstorydev/grpcurl

\n
grpcurl \\\n-proto protos/calculator.proto \\\n-d \'{"first_operand": 2.0, "second_operand": 3.0, "operation": "ADD"}\' \\\n${ENDPOINT}:443 \\\nCalculator.Calculate\n
Run Code Online (Sandbox Code Playgroud)\n

GRPC 服务器反射协议\n https://github.com/grpc/grpc/blob/master/doc/server-reflection.md

\n

现在我想按照这些说明使用反射。

\n
--- a/examples/helloworld/greeter_server/main.go\n+++ b/examples/helloworld/greeter_server/main.go\n@@ -40,6 +40,7 @@ import (\n        "google.golang.org/grpc"\n        pb "google.golang.org/grpc/examples/helloworld/helloworld"\n+       "google.golang.org/grpc/reflection"\n )\n\n const (\n@@ -61,6 +62,8 @@ func main() {\n        }\n        s := grpc.NewServer()\n        pb.RegisterGreeterService(s, &pb.GreeterService{SayHello: sayHello})\n+       // Register reflection service on gRPC server.\n+       reflection.Register(s)\n        if err := s.Serve(lis); err != nil {\n                log.Fatalf("failed to serve: %v", err)\n        }\n
Run Code Online (Sandbox Code Playgroud)\n

https://github.com/grpc/grpc-go/blob/master/Documentation/server-reflection-tutorial.md#enable-server-reflection

\n

你尝试过什么:

\n

本地测试。请注意:\ngrpcurl -plaintext 表示不是 TLS。省略 -plaintext 表示 TLS。

\n

什么有效:

\n
############################\n# local testing\n############################\nrequest list:\ngrpcurl -plaintext localhost:8080 list\n\nresult:\nCalculator\ngrpc.reflection.v1alpha.ServerReflection\n\nrequest ADD function:\ngrpcurl -plaintext \\\n    -d \'{"first_operand": 2.0, "second_operand": 3.0, "operation": "ADD"}\' \\\n    localhost:8080 \\\n    Calculator.Calculate\n\nresult:\n{\n  "result": 5\n}\n############################\n
Run Code Online (Sandbox Code Playgroud)\n

您尝试过的操作:\na GCP CloudRun 测试。请注意:\ngrpcurl -plaintext 表示不是 TLS。省略 -plaintext 表示 TLS。

\n

什么有效:

\n
request:\ngrpcurl \\\n    -proto protos/calculator.proto \\\n    -d \'{"first_operand": 2.0, "second_operand": 3.0, "operation": "ADD"}\' \\\n    ${ENDPOINT}:443 \\\n    Calculator.Calculate\n\nresult:\n{\n  "result": 5\n}\n
Run Code Online (Sandbox Code Playgroud)\n

\xe2\x80\x99 不起作用:\n我想使用反射,因此省略:

\n
-proto protos/calculator.proto \\\n
Run Code Online (Sandbox Code Playgroud)\n

我想使用 TLS 所以省略:

\n
-plaintext\n
Run Code Online (Sandbox Code Playgroud)\n

要求:

\n
grpcurl \\\n    -d \'{"first_operand": 2.0, "second_operand": 3.0, "operation": "ADD"}\' \\\n    ${ENDPOINT}:443 \\\n    Calculator.Calculate\n
Run Code Online (Sandbox Code Playgroud)\n

回复:

\n

暂停

\n

底线。本地测试显示反射工作正常。\n部署到 CloudRun 时无法工作。

\n

我想是因为它需要双向流:

\n

https://github.com/grpc/grpc/blob/master/src/proto/grpc/reflection/v1alpha/reflection.proto

\n
service ServerReflection {\n  // The reflection service is structured as a bidirectional stream, ensuring\n  // all related requests go to a single server.\n  rpc ServerReflectionInfo(stream ServerReflectionRequest)\n      returns (stream ServerReflectionResponse);\n}\n
Run Code Online (Sandbox Code Playgroud)\n

Ahm*_*gle 2

gRPC Reflection 需要双向流,因此请确保在部署时选中启用 HTTP/2 选项 (--use-http2)。这将启用双向流。

另请确保使用 :443 端口,并在需要时通过添加身份验证元数据对服务器进行身份验证(请参阅服务到服务身份验证文档)。