From 53f7b58130a2ed88db00b8c6ffad6d64a00ecf2c Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Wed, 14 Oct 2020 23:35:48 +0300 Subject: [PATCH] [#93] Add gRPC Reflection service Added gRPC Reflection service that can be enabled by settings `grpc.enable_reflect_service`. Read more about at https://github.com/grpc/grpc-go/blob/master/Documentation/server-reflection-tutorial.md Signed-off-by: Evgeniy Kulikov --- cmd/neofs-node/config.go | 12 ++++++++---- cmd/neofs-node/grpc.go | 7 +++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index 256343f6..1eb56a82 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -50,8 +50,9 @@ const ( cfgMaxObjectSize = "node.maxobjectsize" // todo: get value from chain // config keys for cfgGRPC - cfgListenAddress = "grpc.endpoint" - cfgMaxMsgSize = "grpc.maxmessagesize" + cfgListenAddress = "grpc.endpoint" + cfgMaxMsgSize = "grpc.maxmessagesize" + cfgReflectService = "grpc.enable_reflect_service" // config keys for cfgMorph cfgMorphRPCAddress = "morph.endpoint" @@ -124,6 +125,8 @@ type cfgGRPC struct { maxChunkSize uint64 maxAddrAmount uint64 + + enableReflectService bool } type cfgMorph struct { @@ -234,8 +237,9 @@ func initCfg(path string) *cfg { maxObjectSize: viperCfg.GetUint64(cfgMaxObjectSize), }, cfgGRPC: cfgGRPC{ - maxChunkSize: maxChunkSize, - maxAddrAmount: maxAddrAmount, + maxChunkSize: maxChunkSize, + maxAddrAmount: maxAddrAmount, + enableReflectService: viperCfg.GetBool(cfgReflectService), }, localAddr: netAddr, } diff --git a/cmd/neofs-node/grpc.go b/cmd/neofs-node/grpc.go index e65205e5..d3f5ea61 100644 --- a/cmd/neofs-node/grpc.go +++ b/cmd/neofs-node/grpc.go @@ -5,6 +5,7 @@ import ( "net" "google.golang.org/grpc" + "google.golang.org/grpc/reflection" ) func initGRPC(c *cfg) { @@ -25,6 +26,12 @@ func serveGRPC(c *cfg) { c.wg.Done() }() + // read more about reflect service at + // https://github.com/grpc/grpc-go/blob/master/Documentation/server-reflection-tutorial.md + if c.cfgGRPC.enableReflectService { + reflection.Register(c.cfgGRPC.server) + } + if err := c.cfgGRPC.server.Serve(c.cfgGRPC.listener); err != nil { fmt.Println("gRPC server error", err) }