[#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 <kim@nspcc.ru>
This commit is contained in:
Evgeniy Kulikov 2020-10-14 23:35:48 +03:00 committed by Alex Vanin
parent 1332a6d3a8
commit 53f7b58130
2 changed files with 15 additions and 4 deletions

View file

@ -50,8 +50,9 @@ const (
cfgMaxObjectSize = "node.maxobjectsize" // todo: get value from chain cfgMaxObjectSize = "node.maxobjectsize" // todo: get value from chain
// config keys for cfgGRPC // config keys for cfgGRPC
cfgListenAddress = "grpc.endpoint" cfgListenAddress = "grpc.endpoint"
cfgMaxMsgSize = "grpc.maxmessagesize" cfgMaxMsgSize = "grpc.maxmessagesize"
cfgReflectService = "grpc.enable_reflect_service"
// config keys for cfgMorph // config keys for cfgMorph
cfgMorphRPCAddress = "morph.endpoint" cfgMorphRPCAddress = "morph.endpoint"
@ -124,6 +125,8 @@ type cfgGRPC struct {
maxChunkSize uint64 maxChunkSize uint64
maxAddrAmount uint64 maxAddrAmount uint64
enableReflectService bool
} }
type cfgMorph struct { type cfgMorph struct {
@ -234,8 +237,9 @@ func initCfg(path string) *cfg {
maxObjectSize: viperCfg.GetUint64(cfgMaxObjectSize), maxObjectSize: viperCfg.GetUint64(cfgMaxObjectSize),
}, },
cfgGRPC: cfgGRPC{ cfgGRPC: cfgGRPC{
maxChunkSize: maxChunkSize, maxChunkSize: maxChunkSize,
maxAddrAmount: maxAddrAmount, maxAddrAmount: maxAddrAmount,
enableReflectService: viperCfg.GetBool(cfgReflectService),
}, },
localAddr: netAddr, localAddr: netAddr,
} }

View file

@ -5,6 +5,7 @@ import (
"net" "net"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/reflection"
) )
func initGRPC(c *cfg) { func initGRPC(c *cfg) {
@ -25,6 +26,12 @@ func serveGRPC(c *cfg) {
c.wg.Done() 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 { if err := c.cfgGRPC.server.Serve(c.cfgGRPC.listener); err != nil {
fmt.Println("gRPC server error", err) fmt.Println("gRPC server error", err)
} }