Skip to content

Commit

Permalink
comm: hang option accessors off KeepaliveOptions
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Sykes <[email protected]>
  • Loading branch information
sykesm authored and Jason Yellick committed Mar 5, 2021
1 parent ab9ff14 commit e0fbdf3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion internal/peer/node/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ func secureDialOpts(credSupport *comm.CredentialSupport) func() []grpc.DialOptio
if viper.IsSet("peer.keepalive.client.timeout") {
kaOpts.ClientTimeout = viper.GetDuration("peer.keepalive.client.timeout")
}
dialOpts = append(dialOpts, comm.ClientKeepaliveOptions(kaOpts)...)
dialOpts = append(dialOpts, kaOpts.ClientKeepaliveOptions()...)

if viper.GetBool("peer.tls.enabled") {
dialOpts = append(dialOpts, grpc.WithTransportCredentials(credSupport.GetPeerCredentials()))
Expand Down
22 changes: 11 additions & 11 deletions internal/pkg/comm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,8 @@ type KeepaliveOptions struct {
ServerMinInterval time.Duration
}

type Metrics struct {
// OpenConnCounter keeps track of number of open connections
OpenConnCounter metrics.Counter
// ClosedConnCounter keeps track of number connections closed
ClosedConnCounter metrics.Counter
}

// ServerKeepaliveOptions returns gRPC keepalive options for server.
func ServerKeepaliveOptions(ka KeepaliveOptions) []grpc.ServerOption {
// ServerKeepaliveOptions returns gRPC keepalive options for a server.
func (ka KeepaliveOptions) ServerKeepaliveOptions() []grpc.ServerOption {
var serverOpts []grpc.ServerOption
kap := keepalive.ServerParameters{
Time: ka.ServerInterval,
Expand All @@ -158,8 +151,8 @@ func ServerKeepaliveOptions(ka KeepaliveOptions) []grpc.ServerOption {
return serverOpts
}

// ClientKeepaliveOptions returns gRPC keepalive options for clients.
func ClientKeepaliveOptions(ka KeepaliveOptions) []grpc.DialOption {
// ClientKeepaliveOptions returns gRPC keepalive dial options for clients.
func (ka KeepaliveOptions) ClientKeepaliveOptions() []grpc.DialOption {
var dialOpts []grpc.DialOption
kap := keepalive.ClientParameters{
Time: ka.ClientInterval,
Expand All @@ -169,3 +162,10 @@ func ClientKeepaliveOptions(ka KeepaliveOptions) []grpc.DialOption {
dialOpts = append(dialOpts, grpc.WithKeepaliveParams(kap))
return dialOpts
}

type Metrics struct {
// OpenConnCounter keeps track of number of open connections
OpenConnCounter metrics.Counter
// ClosedConnCounter keeps track of number connections closed
ClosedConnCounter metrics.Counter
}
4 changes: 2 additions & 2 deletions internal/pkg/comm/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestServerKeepaliveOptions(t *testing.T) {
grpc.KeepaliveParams(kap),
grpc.KeepaliveEnforcementPolicy(kep),
}
opts := ServerKeepaliveOptions(DefaultKeepaliveOptions)
opts := DefaultKeepaliveOptions.ServerKeepaliveOptions()

// Unable to test equality of options since the option methods return
// functions and each instance is a different func.
Expand All @@ -52,7 +52,7 @@ func TestClientKeepaliveOptions(t *testing.T) {
PermitWithoutStream: true,
}
expectedOpts := []grpc.DialOption{grpc.WithKeepaliveParams(kap)}
opts := ClientKeepaliveOptions(DefaultKeepaliveOptions)
opts := DefaultKeepaliveOptions.ClientKeepaliveOptions()

// Unable to test equality of options since the option methods return
// functions and each instance is a different func.
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/comm/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func NewGRPCServerFromListener(listener net.Listener, serverConfig ServerConfig)
serverOpts = append(serverOpts, grpc.MaxSendMsgSize(DefaultMaxSendMsgSize))
serverOpts = append(serverOpts, grpc.MaxRecvMsgSize(DefaultMaxRecvMsgSize))
// set the keepalive options
serverOpts = append(serverOpts, ServerKeepaliveOptions(serverConfig.KaOpts)...)
serverOpts = append(serverOpts, serverConfig.KaOpts.ServerKeepaliveOptions()...)
// set connection timeout
if serverConfig.ConnectionTimeout <= 0 {
serverConfig.ConnectionTimeout = DefaultConnectionTimeout
Expand Down

0 comments on commit e0fbdf3

Please sign in to comment.