server: allow configuration default send/recv message sizes

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day 2018-03-23 14:16:52 -07:00
parent 3e8e9d3ed7
commit acc71293c5
No known key found for this signature in database
GPG Key ID: 67B3DED84EDC823F
6 changed files with 44 additions and 5 deletions

View File

@ -38,6 +38,7 @@ import (
versionservice "github.com/containerd/containerd/api/services/version/v1" versionservice "github.com/containerd/containerd/api/services/version/v1"
"github.com/containerd/containerd/containers" "github.com/containerd/containerd/containers"
"github.com/containerd/containerd/content" "github.com/containerd/containerd/content"
"github.com/containerd/containerd/defaults"
"github.com/containerd/containerd/dialer" "github.com/containerd/containerd/dialer"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/events" "github.com/containerd/containerd/events"
@ -90,6 +91,10 @@ func New(address string, opts ...ClientOpt) (*Client, error) {
grpc.FailOnNonTempDialError(true), grpc.FailOnNonTempDialError(true),
grpc.WithBackoffMaxDelay(3 * time.Second), grpc.WithBackoffMaxDelay(3 * time.Second),
grpc.WithDialer(dialer.Dialer), grpc.WithDialer(dialer.Dialer),
// TODO(stevvooe): We may need to allow configuration of this on the client.
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(defaults.DefaultMaxRecvMsgSize)),
grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(defaults.DefaultMaxSendMsgSize)),
} }
if len(copts.dialOptions) > 0 { if len(copts.dialOptions) > 0 {
gopts = copts.dialOptions gopts = copts.dialOptions

View File

@ -26,7 +26,9 @@ func defaultConfig() *server.Config {
Root: defaults.DefaultRootDir, Root: defaults.DefaultRootDir,
State: defaults.DefaultStateDir, State: defaults.DefaultStateDir,
GRPC: server.GRPCConfig{ GRPC: server.GRPCConfig{
Address: defaults.DefaultAddress, Address: defaults.DefaultAddress,
MaxRecvMsgSize: defaults.DefaultMaxRecvMsgSize,
MaxSendMsgSize: defaults.DefaultMaxSendMsgSize,
}, },
} }
} }

View File

@ -26,7 +26,9 @@ func defaultConfig() *server.Config {
Root: defaults.DefaultRootDir, Root: defaults.DefaultRootDir,
State: defaults.DefaultStateDir, State: defaults.DefaultStateDir,
GRPC: server.GRPCConfig{ GRPC: server.GRPCConfig{
Address: defaults.DefaultAddress, Address: defaults.DefaultAddress,
MaxRecvMsgSize: defaults.DefaultMaxRecvMsgSize,
MaxSendMsgSize: defaults.DefaultMaxSendMsgSize,
}, },
} }
} }

26
defaults/defaults.go Normal file
View File

@ -0,0 +1,26 @@
/*
Copyright The containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package defaults
const (
// DefaultMaxRecvMsgSize defines the default maximum message size for
// receiving protobufs passed over the GRPC API.
DefaultMaxRecvMsgSize = 16 << 20
// DefaultMaxSendMsgSize defines the default maximum message size for
// sending protobufs passed over the GRPC API.
DefaultMaxSendMsgSize = 16 << 20
)

View File

@ -49,9 +49,11 @@ type Config struct {
// GRPCConfig provides GRPC configuration for the socket // GRPCConfig provides GRPC configuration for the socket
type GRPCConfig struct { type GRPCConfig struct {
Address string `toml:"address"` Address string `toml:"address"`
UID int `toml:"uid"` UID int `toml:"uid"`
GID int `toml:"gid"` GID int `toml:"gid"`
MaxRecvMsgSize int `toml:"max_recv_message_size"`
MaxSendMsgSize int `toml:"max_send_message_size"`
} }
// Debug provides debug configuration // Debug provides debug configuration

View File

@ -67,6 +67,8 @@ func New(ctx context.Context, config *Config) (*Server, error) {
return nil, err return nil, err
} }
rpc := grpc.NewServer( rpc := grpc.NewServer(
grpc.MaxRecvMsgSize(config.GRPC.MaxRecvMsgSize),
grpc.MaxSendMsgSize(config.GRPC.MaxSendMsgSize),
grpc.UnaryInterceptor(grpc_prometheus.UnaryServerInterceptor), grpc.UnaryInterceptor(grpc_prometheus.UnaryServerInterceptor),
grpc.StreamInterceptor(grpc_prometheus.StreamServerInterceptor), grpc.StreamInterceptor(grpc_prometheus.StreamServerInterceptor),
) )