Following this example:
gRPC in Google Cloud Run
https://github.com/grpc-ecosystem/grpc-cloud-run-example/blob/master/golang/README.md
I've deployed a gRPC service with reflection on CloudRun.
Using grpcurl for testing: https://github.com/fullstorydev/grpcurl
grpcurl \
-proto protos/calculator.proto \
-d '{"first_operand": 2.0, "second_operand": 3.0, "operation": "ADD"}' \
${ENDPOINT}:443 \
Calculator.Calculate
GRPC Server Reflection Protocol https://github.com/grpc/grpc/blob/master/doc/server-reflection.md
Now I want to use reflection following these instructions.
--- a/examples/helloworld/greeter_server/main.go
+++ b/examples/helloworld/greeter_server/main.go
@@ -40,6 +40,7 @@ import (
"google.golang.org/grpc"
pb "google.golang.org/grpc/examples/helloworld/helloworld"
+ "google.golang.org/grpc/reflection"
)
const (
@@ -61,6 +62,8 @@ func main() {
}
s := grpc.NewServer()
pb.RegisterGreeterService(s, &pb.GreeterService{SayHello: sayHello})
+ // Register reflection service on gRPC server.
+ reflection.Register(s)
if err := s.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}
what you tried:
a local test. Please note: grpcurl -plaintext means not TLS. Ommiting -plaintext means TLS.
what worked:
############################
# local testing
############################
request list:
grpcurl -plaintext localhost:8080 list
result:
Calculator
grpc.reflection.v1alpha.ServerReflection
request ADD function:
grpcurl -plaintext \
-d '{"first_operand": 2.0, "second_operand": 3.0, "operation": "ADD"}' \
localhost:8080 \
Calculator.Calculate
result:
{
"result": 5
}
############################
what you tried: a GCP CloudRun test. Please note: grpcurl -plaintext means not TLS. Ommiting -plaintext means TLS.
what worked:
request:
grpcurl \
-proto protos/calculator.proto \
-d '{"first_operand": 2.0, "second_operand": 3.0, "operation": "ADD"}' \
${ENDPOINT}:443 \
Calculator.Calculate
result:
{
"result": 5
}
what didn’t work: I want to use reflection so omitted:
-proto protos/calculator.proto \
I want to use TLS so omitted:
-plaintext
request:
grpcurl \
-d '{"first_operand": 2.0, "second_operand": 3.0, "operation": "ADD"}' \
${ENDPOINT}:443 \
Calculator.Calculate
response:
timeout
Bottom line. The local test shows reflection is working fine. It cannot work when deployed to CloudRun.
I suppose because it requires bidirectional stream:
https://github.com/grpc/grpc/blob/master/src/proto/grpc/reflection/v1alpha/reflection.proto
service ServerReflection {
// The reflection service is structured as a bidirectional stream, ensuring
// all related requests go to a single server.
rpc ServerReflectionInfo(stream ServerReflectionRequest)
returns (stream ServerReflectionResponse);
}