diff --git a/conf/defaults.ini b/conf/defaults.ini index b3a459c7df197..401a65c6314a0 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -107,6 +107,12 @@ key_file = # this will log the request and response for each unary gRPC call enable_logging = false +# Maximum size of a message that can be received in bytes. If not set, uses the gRPC default (4MiB). +max_recv_msg_size = + +# Maximum size of a message that can be sent in bytes. If not set, uses the gRPC default (unlimited). +max_send_msg_size = + #################################### Database ############################ [database] # You can configure the database connection by specifying type, host, name, user and password diff --git a/conf/sample.ini b/conf/sample.ini index 2cfef5081a6ab..c9d5b89e50a72 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -101,6 +101,8 @@ ;use_tls = false ;cert_file = ;key_file = +;max_recv_msg_size = +;max_send_msg_size = #################################### Database #################################### [database] diff --git a/pkg/services/grpcserver/service.go b/pkg/services/grpcserver/service.go index 4826ae948da58..ae2f9650a46a8 100644 --- a/pkg/services/grpcserver/service.go +++ b/pkg/services/grpcserver/service.go @@ -85,12 +85,20 @@ func ProvideService(cfg *setting.Cfg, features featuremgmt.FeatureToggles, authe opts = append(opts, grpc.Creds(credentials.NewTLS(cfg.GRPCServerTLSConfig))) } + if s.cfg.GRPCServerMaxRecvMsgSize > 0 { + opts = append(opts, grpc.MaxRecvMsgSize(s.cfg.GRPCServerMaxRecvMsgSize)) + } + + if s.cfg.GRPCServerMaxSendMsgSize > 0 { + opts = append(opts, grpc.MaxSendMsgSize(s.cfg.GRPCServerMaxSendMsgSize)) + } + s.server = grpc.NewServer(opts...) return s, nil } func (s *gPRCServerService) Run(ctx context.Context) error { - s.logger.Info("Running GRPC server", "address", s.cfg.GRPCServerAddress, "network", s.cfg.GRPCServerNetwork, "tls", s.cfg.GRPCServerTLSConfig != nil) + s.logger.Info("Running GRPC server", "address", s.cfg.GRPCServerAddress, "network", s.cfg.GRPCServerNetwork, "tls", s.cfg.GRPCServerTLSConfig != nil, "max_recv_msg_size", s.cfg.GRPCServerMaxRecvMsgSize, "max_send_msg_size", s.cfg.GRPCServerMaxSendMsgSize) listener, err := net.Listen(s.cfg.GRPCServerNetwork, s.cfg.GRPCServerAddress) if err != nil { diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go index 478d28afdcf12..76406ffabece3 100644 --- a/pkg/setting/setting.go +++ b/pkg/setting/setting.go @@ -470,10 +470,12 @@ type Cfg struct { RBACSingleOrganization bool // GRPC Server. - GRPCServerNetwork string - GRPCServerAddress string - GRPCServerTLSConfig *tls.Config - GRPCServerEnableLogging bool // log request and response of each unary gRPC call + GRPCServerNetwork string + GRPCServerAddress string + GRPCServerTLSConfig *tls.Config + GRPCServerEnableLogging bool // log request and response of each unary gRPC call + GRPCServerMaxRecvMsgSize int + GRPCServerMaxSendMsgSize int CustomResponseHeaders map[string]string @@ -1769,6 +1771,8 @@ func readGRPCServerSettings(cfg *Cfg, iniFile *ini.File) error { cfg.GRPCServerNetwork = valueAsString(server, "network", "tcp") cfg.GRPCServerAddress = valueAsString(server, "address", "") cfg.GRPCServerEnableLogging = server.Key("enable_logging").MustBool(false) + cfg.GRPCServerMaxRecvMsgSize = server.Key("max_recv_msg_size").MustInt(0) + cfg.GRPCServerMaxSendMsgSize = server.Key("max_send_msg_size").MustInt(0) switch cfg.GRPCServerNetwork { case "unix": if cfg.GRPCServerAddress != "" {