Skip to content

Commit 67bade2

Browse files
committed
Make gRPC ping time and timeout into parameters
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
1 parent 01fc8a1 commit 67bade2

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

grpcclient/grpcclient.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ type Config struct {
2323
GRPCCompression string `yaml:"grpc_compression"`
2424
RateLimit float64 `yaml:"rate_limit"`
2525
RateLimitBurst int `yaml:"rate_limit_burst"`
26+
// PingTime is the number of seconds after which the client will ping the server in case of inactivity.
27+
//
28+
// See `google.golang.org/grpc/keepalive.ClientParameters.Time` for reference.
29+
PingTime int64 `yaml:"ping_time"`
30+
// PingTimeOut is the number of seconds the client waits after pinging the server, and if no activity is seen
31+
// after that, the connection is closed.
32+
//
33+
// See `google.golang.org/grpc/keepalive.ClientParameters.Timeout` for reference.
34+
PingTimeout int64 `yaml:"ping_timeout"`
2635

2736
BackoffOnRatelimits bool `yaml:"backoff_on_ratelimits"`
2837
BackoffConfig backoff.Config `yaml:"backoff_config"`
@@ -95,8 +104,8 @@ func (cfg *Config) DialOption(unaryClientInterceptors []grpc.UnaryClientIntercep
95104
grpc.WithUnaryInterceptor(middleware.ChainUnaryClient(unaryClientInterceptors...)),
96105
grpc.WithStreamInterceptor(middleware.ChainStreamClient(streamClientInterceptors...)),
97106
grpc.WithKeepaliveParams(keepalive.ClientParameters{
98-
Time: time.Second * 20,
99-
Timeout: time.Second * 10,
107+
Time: time.Duration(cfg.PingTime) * time.Second,
108+
Timeout: time.Duration(cfg.PingTimeout) * time.Second,
100109
PermitWithoutStream: true,
101110
}),
102111
), nil

0 commit comments

Comments
 (0)