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 <[email protected]>
  • Loading branch information
aknuds1 committed Oct 7, 2021
1 parent 01fc8a1 commit 53b6b7b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
* [CHANGE] Added CHANGELOG.md and Pull Request template to reference the changelog
* [CHANGE] Remove `cortex_` prefix for metrics registered in the ring. #46
* [CHANGE] Rename `kv/kvtls` to `crypto/tls`. #39
* [CHANGE] grpcclient: Make ping time and timeout into configuration parameters. #56
* [ENHANCEMENT] Add middleware package. #38
* [ENHANCEMENT] Add the ring package #45
* [ENHANCEMENT] Add limiter package. #41
* [ENHANCEMENT] Add grpcclient, grpcencoding and grpcutil packages. #39
* [ENHANCEMENT] Add grpcclient, grpcencoding and grpcutil packages. #39
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 53b6b7b

Please sign in to comment.