From 53b6b7bf7be504b7b0b3130178d36a05175a5799 Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Mon, 13 Sep 2021 15:58:12 +0200 Subject: [PATCH] Make gRPC ping time and timeout into parameters Signed-off-by: Arve Knudsen --- CHANGELOG.md | 3 ++- grpcclient/grpcclient.go | 13 +++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee265c18d..81b123987 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 \ No newline at end of file +* [ENHANCEMENT] Add grpcclient, grpcencoding and grpcutil packages. #39 diff --git a/grpcclient/grpcclient.go b/grpcclient/grpcclient.go index 6114d15d8..6c5a4948f 100644 --- a/grpcclient/grpcclient.go +++ b/grpcclient/grpcclient.go @@ -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"` @@ -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