Skip to content

Commit

Permalink
Make gRPC ping time and timeout into parameters
Browse files Browse the repository at this point in the history
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
  • Loading branch information
aknuds1 committed Oct 7, 2021
1 parent 01fc8a1 commit 67bade2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions grpcclient/grpcclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ type Config struct {
GRPCCompression string `yaml:"grpc_compression"`
RateLimit float64 `yaml:"rate_limit"`
RateLimitBurst int `yaml:"rate_limit_burst"`
// PingTime is the number of seconds after which the client will ping the server in case of inactivity.
//
// See `google.golang.org/grpc/keepalive.ClientParameters.Time` for reference.
PingTime int64 `yaml:"ping_time"`
// PingTimeOut is the number of seconds the client waits after pinging the server, and if no activity is seen
// after that, the connection is closed.
//
// See `google.golang.org/grpc/keepalive.ClientParameters.Timeout` for reference.
PingTimeout int64 `yaml:"ping_timeout"`

BackoffOnRatelimits bool `yaml:"backoff_on_ratelimits"`
BackoffConfig backoff.Config `yaml:"backoff_config"`
Expand Down Expand Up @@ -95,8 +104,8 @@ func (cfg *Config) DialOption(unaryClientInterceptors []grpc.UnaryClientIntercep
grpc.WithUnaryInterceptor(middleware.ChainUnaryClient(unaryClientInterceptors...)),
grpc.WithStreamInterceptor(middleware.ChainStreamClient(streamClientInterceptors...)),
grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: time.Second * 20,
Timeout: time.Second * 10,
Time: time.Duration(cfg.PingTime) * time.Second,
Timeout: time.Duration(cfg.PingTimeout) * time.Second,
PermitWithoutStream: true,
}),
), nil
Expand Down

0 comments on commit 67bade2

Please sign in to comment.