Skip to content

Commit 08245d4

Browse files
authored
Expose grpc client connect timeout config and default to 5s (#6523)
* expose grpc client connect timeout config Signed-off-by: yeya24 <[email protected]> * changelog Signed-off-by: yeya24 <[email protected]> --------- Signed-off-by: yeya24 <[email protected]>
1 parent 60b5b09 commit 08245d4

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* [CHANGE] Change default value of `-blocks-storage.bucket-store.index-cache.multilevel.max-async-concurrency` from `50` to `3` #6265
1111
* [CHANGE] Enable Compactor and Alertmanager in target all. #6204
1212
* [CHANGE] Update the `cortex_ingester_inflight_push_requests` metric to represent the maximum number of inflight requests recorded in the last minute. #6437
13+
* [CHANGE] gRPC Client: Expose connection timeout and set default to value to 5s. #6523
1314
* [FEATURE] Ruler: Add an experimental flag `-ruler.query-response-format` to retrieve query response as a proto format. #6345
1415
* [FEATURE] Ruler: Pagination support for List Rules API. #6299
1516
* [FEATURE] Query Frontend/Querier: Add protobuf codec `-api.querier-default-codec` and the option to choose response compression type `-querier.response-compression`. #5527

docs/configuration/config-file-reference.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@ query_scheduler:
266266
# CLI flag: -query-scheduler.grpc-client-config.tls-insecure-skip-verify
267267
[tls_insecure_skip_verify: <boolean> | default = false]
268268

269+
# The maximum amount of time to establish a connection. A value of 0 means
270+
# using default gRPC client connect timeout 20s.
271+
# CLI flag: -query-scheduler.grpc-client-config.connect-timeout
272+
[connect_timeout: <duration> | default = 5s]
273+
269274
# The tracing_config configures backends cortex uses.
270275
[tracing: <tracing_config>]
271276
```
@@ -2972,6 +2977,11 @@ grpc_client_config:
29722977
# Skip validating server certificate.
29732978
# CLI flag: -querier.frontend-client.tls-insecure-skip-verify
29742979
[tls_insecure_skip_verify: <boolean> | default = false]
2980+
2981+
# The maximum amount of time to establish a connection. A value of 0 means
2982+
# using default gRPC client connect timeout 20s.
2983+
# CLI flag: -querier.frontend-client.connect-timeout
2984+
[connect_timeout: <duration> | default = 5s]
29752985
```
29762986

29772987
### `ingester_config`
@@ -3282,6 +3292,11 @@ grpc_client_config:
32823292
# CLI flag: -ingester.client.tls-insecure-skip-verify
32833293
[tls_insecure_skip_verify: <boolean> | default = false]
32843294
3295+
# The maximum amount of time to establish a connection. A value of 0 means
3296+
# using default gRPC client connect timeout 20s.
3297+
# CLI flag: -ingester.client.connect-timeout
3298+
[connect_timeout: <duration> | default = 5s]
3299+
32853300
# EXPERIMENTAL: If enabled, gRPC clients perform health checks for each target
32863301
# and fail the request if the target is marked as unhealthy.
32873302
healthcheck_config:
@@ -4200,6 +4215,11 @@ grpc_client_config:
42004215
# CLI flag: -frontend.grpc-client-config.tls-insecure-skip-verify
42014216
[tls_insecure_skip_verify: <boolean> | default = false]
42024217
4218+
# The maximum amount of time to establish a connection. A value of 0 means
4219+
# using default gRPC client connect timeout 20s.
4220+
# CLI flag: -frontend.grpc-client-config.connect-timeout
4221+
[connect_timeout: <duration> | default = 5s]
4222+
42034223
# When multiple query-schedulers are available, re-enqueue queries that were
42044224
# rejected due to too many outstanding requests.
42054225
# CLI flag: -frontend.retry-on-too-many-outstanding-requests
@@ -4426,6 +4446,11 @@ frontend_client:
44264446
# CLI flag: -ruler.frontendClient.tls-insecure-skip-verify
44274447
[tls_insecure_skip_verify: <boolean> | default = false]
44284448

4449+
# The maximum amount of time to establish a connection. A value of 0 means
4450+
# using default gRPC client connect timeout 20s.
4451+
# CLI flag: -ruler.frontendClient.connect-timeout
4452+
[connect_timeout: <duration> | default = 5s]
4453+
44294454
# URL of alerts return path.
44304455
# CLI flag: -ruler.external.url
44314456
[external_url: <url> | default = ]
@@ -4501,6 +4526,11 @@ ruler_client:
45014526
# CLI flag: -ruler.client.tls-insecure-skip-verify
45024527
[tls_insecure_skip_verify: <boolean> | default = false]
45034528

4529+
# The maximum amount of time to establish a connection. A value of 0 means
4530+
# using default gRPC client connect timeout 20s.
4531+
# CLI flag: -ruler.client.connect-timeout
4532+
[connect_timeout: <duration> | default = 5s]
4533+
45044534
# Timeout for downstream rulers.
45054535
# CLI flag: -ruler.client.remote-timeout
45064536
[remote_timeout: <duration> | default = 2m]

pkg/util/grpcclient/grpcclient.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
middleware "github.com/grpc-ecosystem/go-grpc-middleware"
99
"github.com/pkg/errors"
1010
"google.golang.org/grpc"
11+
grpcbackoff "google.golang.org/grpc/backoff"
1112
"google.golang.org/grpc/encoding/gzip"
1213
"google.golang.org/grpc/keepalive"
1314

@@ -32,6 +33,8 @@ type Config struct {
3233
TLSEnabled bool `yaml:"tls_enabled"`
3334
TLS tls.ClientConfig `yaml:",inline"`
3435
SignWriteRequestsEnabled bool `yaml:"-"`
36+
37+
ConnectTimeout time.Duration `yaml:"connect_timeout"`
3538
}
3639

3740
type ConfigWithHealthCheck struct {
@@ -58,6 +61,7 @@ func (cfg *Config) RegisterFlagsWithPrefix(prefix, defaultGrpcCompression string
5861
f.IntVar(&cfg.RateLimitBurst, prefix+".grpc-client-rate-limit-burst", 0, "Rate limit burst for gRPC client.")
5962
f.BoolVar(&cfg.BackoffOnRatelimits, prefix+".backoff-on-ratelimits", false, "Enable backoff and retry when we hit ratelimits.")
6063
f.BoolVar(&cfg.TLSEnabled, prefix+".tls-enabled", cfg.TLSEnabled, "Enable TLS in the GRPC client. This flag needs to be enabled when any other TLS flag is set. If set to false, insecure connection to gRPC server will be used.")
64+
f.DurationVar(&cfg.ConnectTimeout, prefix+".connect-timeout", 5*time.Second, "The maximum amount of time to establish a connection. A value of 0 means using default gRPC client connect timeout 20s.")
6165

6266
cfg.BackoffConfig.RegisterFlagsWithPrefix(prefix, f)
6367

@@ -111,6 +115,16 @@ func (cfg *Config) DialOption(unaryClientInterceptors []grpc.UnaryClientIntercep
111115
unaryClientInterceptors = append([]grpc.UnaryClientInterceptor{NewRateLimiter(cfg)}, unaryClientInterceptors...)
112116
}
113117

118+
if cfg.ConnectTimeout > 0 {
119+
opts = append(
120+
opts,
121+
grpc.WithConnectParams(grpc.ConnectParams{
122+
Backoff: grpcbackoff.DefaultConfig,
123+
MinConnectTimeout: cfg.ConnectTimeout,
124+
}),
125+
)
126+
}
127+
114128
if cfg.SignWriteRequestsEnabled {
115129
unaryClientInterceptors = append(unaryClientInterceptors, UnarySigningClientInterceptor)
116130
}

0 commit comments

Comments
 (0)