hashicorp / go-plugin

Golang plugin system over RPC.
Mozilla Public License 2.0
5.25k stars 450 forks source link

Add optional support for gRPC Reflection #137

Closed paultyng closed 4 years ago

paultyng commented 4 years ago

I don't believe the gRPC server is exposed to calling applications, so we are unable to turn on reflection.

The diff example from the gRPC docs, walks through the required changes:

--- 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.RegisterGreeterServer(s, &server{})
+       // Register reflection service on gRPC server.
+       reflection.Register(s)
        if err := s.Serve(lis); err != nil {
                log.Fatalf("failed to serve: %v", err)
        }
mitchellh commented 4 years ago

You should have access to the server: https://pkg.go.dev/github.com/hashicorp/go-plugin?tab=doc#ServeConfig the GRPCServer callback. This gives you a chance to register custom services.

Still, I'm not opposed to making this an always-on default either. I've CC'd in @jbardin and @briankassouf. I don't know any downsides.

paultyng commented 4 years ago

Yeah, considering these are local plugins I'm fine with always on as well 👍 In the mean time we can just do this on the plugin SDK on our side in the callback, thanks for the pointer.