integration: configure keepalive parameters for server
@@ -53,6 +53,7 @@ import (
"github.com/coreos/pkg/capnslog"
"github.com/soheilhy/cmux"
"google.golang.org/grpc"
+ "google.golang.org/grpc/keepalive"
)
const (
@@ -98,6 +99,9 @@ type ClusterConfig struct {
QuotaBackendBytes int64
MaxTxnOps uint
MaxRequestBytes uint
+ GRPCKeepAliveMinTime time.Duration
+ GRPCKeepAliveInterval time.Duration
+ GRPCKeepAliveTimeout time.Duration
}
type cluster struct {
@@ -231,6 +235,9 @@ func (c *cluster) mustNewMember(t *testing.T) *member {
quotaBackendBytes: c.cfg.QuotaBackendBytes,
maxTxnOps: c.cfg.MaxTxnOps,
maxRequestBytes: c.cfg.MaxRequestBytes,
+ grpcKeepAliveMinTime: c.cfg.GRPCKeepAliveMinTime,
+ grpcKeepAliveInterval: c.cfg.GRPCKeepAliveInterval,
+ grpcKeepAliveTimeout: c.cfg.GRPCKeepAliveTimeout,
})
m.DiscoveryURL = c.cfg.DiscoveryURL
if c.cfg.UseGRPC {
@@ -482,6 +489,7 @@ type member struct {
s *etcdserver.EtcdServer
serverClosers []func()
+ grpcServerOpts []grpc.ServerOption
grpcServer *grpc.Server
grpcServerPeer *grpc.Server
grpcAddr string
@@ -502,6 +510,9 @@ type memberConfig struct {
quotaBackendBytes int64
maxTxnOps uint
maxRequestBytes uint
+ grpcKeepAliveMinTime time.Duration
+ grpcKeepAliveInterval time.Duration
+ grpcKeepAliveTimeout time.Duration
}
// mustNewMember return an inited member with the given name. If peerTLS is
@@ -558,6 +569,21 @@ func mustNewMember(t *testing.T, mcfg memberConfig) *member {
m.MaxRequestBytes = embed.DefaultMaxRequestBytes
}
m.AuthToken = "simple" // for the purpose of integration testing, simple token is enough
+
+ m.grpcServerOpts = []grpc.ServerOption{}
+ if mcfg.grpcKeepAliveMinTime > time.Duration(0) {
+ m.grpcServerOpts = append(m.grpcServerOpts, grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{
+ MinTime: mcfg.grpcKeepAliveMinTime,
+ PermitWithoutStream: false,
+ }))
+ }
+ if mcfg.grpcKeepAliveInterval > time.Duration(0) &&
+ mcfg.grpcKeepAliveTimeout > time.Duration(0) {
+ m.grpcServerOpts = append(m.grpcServerOpts, grpc.KeepaliveParams(keepalive.ServerParameters{
+ Time: mcfg.grpcKeepAliveInterval,
+ Timeout: mcfg.grpcKeepAliveTimeout,
+ }))
+ }
return m
}
@@ -672,7 +698,7 @@ func (m *member) Launch() error {
return err
}
}
- m.grpcServer = v3rpc.Server(m.s, tlscfg)
+ m.grpcServer = v3rpc.Server(m.s, tlscfg, m.grpcServerOpts...)
m.grpcServerPeer = v3rpc.Server(m.s, peerTLScfg)
m.serverClient = v3client.New(m.s)
lockpb.RegisterLockServer(m.grpcServer, v3lock.NewLockServer(m.serverClient))
