Skip to content

Commit 21d15a6

Browse files
author
Brian Buchanan
committedApr 19, 2018
[FAB-9592] Export private default keepalive options
Exported the private variable that was referenced by DefaultKeepaliveOptions(). Also, added simple tests for core/comm config. Change-Id: I7c25b4c935b0a0c78fe6816c762609b5ffb33ff5 Signed-off-by: Brian Buchanan <bpbuch@gmail.com>
1 parent 625c0cc commit 21d15a6

File tree

11 files changed

+20
-22
lines changed

11 files changed

+20
-22
lines changed
 

‎core/comm/client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func NewGRPCClient(config ClientConfig) (*GRPCClient, error) {
5151
} else {
5252
// use defaults
5353
kap = keepalive.ClientParameters{
54-
Time: keepaliveOptions.ClientInterval,
55-
Timeout: keepaliveOptions.ClientTimeout}
54+
Time: DefaultKeepaliveOptions.ClientInterval,
55+
Timeout: DefaultKeepaliveOptions.ClientTimeout}
5656
}
5757
kap.PermitWithoutStream = true
5858
// set keepalive and blocking

‎core/comm/config.go

+3-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var (
1919
MaxRecvMsgSize = 100 * 1024 * 1024
2020
MaxSendMsgSize = 100 * 1024 * 1024
2121
// Default peer keepalive options
22-
keepaliveOptions = &KeepaliveOptions{
22+
DefaultKeepaliveOptions = &KeepaliveOptions{
2323
ClientInterval: time.Duration(1) * time.Minute, // 1 min
2424
ClientTimeout: time.Duration(20) * time.Second, // 20 sec - gRPC default
2525
ServerInterval: time.Duration(2) * time.Hour, // 2 hours - gRPC default
@@ -102,18 +102,12 @@ type KeepaliveOptions struct {
102102
ServerMinInterval time.Duration
103103
}
104104

105-
// DefaultKeepaliveOptions returns sane default keepalive settings for gRPC
106-
// servers and clients
107-
func DefaultKeepaliveOptions() *KeepaliveOptions {
108-
return keepaliveOptions
109-
}
110-
111105
// ServerKeepaliveOptions returns gRPC keepalive options for server. If
112106
// opts is nil, the default keepalive options are returned
113107
func ServerKeepaliveOptions(ka *KeepaliveOptions) []grpc.ServerOption {
114108
// use default keepalive options if nil
115109
if ka == nil {
116-
ka = keepaliveOptions
110+
ka = DefaultKeepaliveOptions
117111
}
118112
var serverOpts []grpc.ServerOption
119113
kap := keepalive.ServerParameters{
@@ -135,7 +129,7 @@ func ServerKeepaliveOptions(ka *KeepaliveOptions) []grpc.ServerOption {
135129
func ClientKeepaliveOptions(ka *KeepaliveOptions) []grpc.DialOption {
136130
// use default keepalive options if nil
137131
if ka == nil {
138-
ka = keepaliveOptions
132+
ka = DefaultKeepaliveOptions
139133
}
140134

141135
var dialOpts []grpc.DialOption

‎core/comm/config_test.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import (
1414

1515
func TestConfig(t *testing.T) {
1616
t.Parallel()
17-
// check the defaults
18-
assert.EqualValues(t, keepaliveOptions, DefaultKeepaliveOptions())
17+
18+
serverOptions := ServerKeepaliveOptions(nil)
19+
assert.NotNil(t, serverOptions)
20+
21+
clientOptions := ClientKeepaliveOptions(nil)
22+
assert.NotNil(t, clientOptions)
1923
}

‎core/comm/connection.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func NewClientConnectionWithAddress(peerAddress string, block bool, tslEnabled b
194194
opts = ClientKeepaliveOptions(ka)
195195
} else {
196196
// set to the default options
197-
opts = ClientKeepaliveOptions(DefaultKeepaliveOptions())
197+
opts = ClientKeepaliveOptions(DefaultKeepaliveOptions)
198198
}
199199

200200
if tslEnabled {

‎core/deliverservice/deliveryclient.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func DefaultConnectionFactory(channelID string) func(endpoint string) (*grpc.Cli
242242
dialOpts = append(dialOpts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(comm.MaxRecvMsgSize),
243243
grpc.MaxCallSendMsgSize(comm.MaxSendMsgSize)))
244244
// set the keepalive options
245-
kaOpts := comm.DefaultKeepaliveOptions()
245+
kaOpts := comm.DefaultKeepaliveOptions
246246
if viper.IsSet("peer.keepalive.deliveryClient.interval") {
247247
kaOpts.ClientInterval = viper.GetDuration(
248248
"peer.keepalive.deliveryClient.interval")

‎core/peer/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func GetServerConfig() (comm.ServerConfig, error) {
166166
}
167167
}
168168
// get the default keepalive options
169-
serverConfig.KaOpts = comm.DefaultKeepaliveOptions()
169+
serverConfig.KaOpts = comm.DefaultKeepaliveOptions
170170
// check to see if minInterval is set for the env
171171
if viper.IsSet("peer.keepalive.minInterval") {
172172
serverConfig.KaOpts.ServerMinInterval = viper.GetDuration("peer.keepalive.minInterval")

‎core/peer/config_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func TestGetServerConfig(t *testing.T) {
138138
"ServerConfig.SecOpts.UseTLS should be false")
139139

140140
// keepalive options
141-
assert.Equal(t, comm.DefaultKeepaliveOptions(), sc.KaOpts,
141+
assert.Equal(t, comm.DefaultKeepaliveOptions, sc.KaOpts,
142142
"ServerConfig.KaOpts should be set to default values")
143143
viper.Set("peer.keepalive.minInterval", "2m")
144144
sc, _ = GetServerConfig()

‎examples/events/eventsclient/eventsclient.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func main() {
160160
}
161161

162162
clientConfig := comm.ClientConfig{
163-
KaOpts: comm.DefaultKeepaliveOptions(),
163+
KaOpts: comm.DefaultKeepaliveOptions,
164164
SecOpts: &comm.SecureOptions{},
165165
Timeout: 5 * time.Minute,
166166
}

‎orderer/common/server/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func initializeServerConfig(conf *config.TopLevel) comm.ServerConfig {
182182
secureOpts.ClientRootCAs = clientRootCAs
183183
logger.Infof("Starting orderer with %s enabled", msg)
184184
}
185-
kaOpts := comm.DefaultKeepaliveOptions()
185+
kaOpts := comm.DefaultKeepaliveOptions
186186
// keepalive settings
187187
// ServerMinInterval must be greater than 0
188188
if conf.General.Keepalive.ServerMinInterval > time.Duration(0) {

‎orderer/common/server/main_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func TestInitializeServerConfig(t *testing.T) {
8989
},
9090
}
9191
sc := initializeServerConfig(conf)
92-
defaultOpts := comm.DefaultKeepaliveOptions()
92+
defaultOpts := comm.DefaultKeepaliveOptions
9393
assert.Equal(t, defaultOpts.ServerMinInterval, sc.KaOpts.ServerMinInterval)
9494
assert.Equal(t, time.Duration(0), sc.KaOpts.ServerInterval)
9595
assert.Equal(t, time.Duration(0), sc.KaOpts.ServerTimeout)

‎peer/node/start.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func serve(args []string) error {
276276
grpc.MaxCallRecvMsgSize(comm.MaxRecvMsgSize),
277277
grpc.MaxCallSendMsgSize(comm.MaxSendMsgSize)))
278278
// set the keepalive options
279-
kaOpts := comm.DefaultKeepaliveOptions()
279+
kaOpts := comm.DefaultKeepaliveOptions
280280
if viper.IsSet("peer.keepalive.client.interval") {
281281
kaOpts.ClientInterval = viper.GetDuration("peer.keepalive.client.interval")
282282
}
@@ -608,7 +608,7 @@ func createEventHubServer(serverConfig comm.ServerConfig) (*comm.GRPCServer, err
608608
}
609609

610610
// set the keepalive options
611-
serverConfig.KaOpts = comm.DefaultKeepaliveOptions()
611+
serverConfig.KaOpts = comm.DefaultKeepaliveOptions
612612
if viper.IsSet("peer.events.keepalive.minInterval") {
613613
serverConfig.KaOpts.ServerMinInterval = viper.GetDuration("peer.events.keepalive.minInterval")
614614
}

0 commit comments

Comments
 (0)
Please sign in to comment.