Skip to content

Expose grpc client connect timeout config and default to 5s #6523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* [CHANGE] Change default value of `-blocks-storage.bucket-store.index-cache.multilevel.max-async-concurrency` from `50` to `3` #6265
* [CHANGE] Enable Compactor and Alertmanager in target all. #6204
* [CHANGE] Update the `cortex_ingester_inflight_push_requests` metric to represent the maximum number of inflight requests recorded in the last minute. #6437
* [CHANGE] gRPC Client: Expose connection timeout and set default to value to 5s. #6523
* [FEATURE] Ruler: Add an experimental flag `-ruler.query-response-format` to retrieve query response as a proto format. #6345
* [FEATURE] Ruler: Pagination support for List Rules API. #6299
* [FEATURE] Query Frontend/Querier: Add protobuf codec `-api.querier-default-codec` and the option to choose response compression type `-querier.response-compression`. #5527
Expand Down
30 changes: 30 additions & 0 deletions docs/configuration/config-file-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ query_scheduler:
# CLI flag: -query-scheduler.grpc-client-config.tls-insecure-skip-verify
[tls_insecure_skip_verify: <boolean> | default = false]

# The maximum amount of time to establish a connection. A value of 0 means
# using default gRPC client connect timeout 20s.
# CLI flag: -query-scheduler.grpc-client-config.connect-timeout
[connect_timeout: <duration> | default = 5s]

# The tracing_config configures backends cortex uses.
[tracing: <tracing_config>]
```
Expand Down Expand Up @@ -2964,6 +2969,11 @@ grpc_client_config:
# Skip validating server certificate.
# CLI flag: -querier.frontend-client.tls-insecure-skip-verify
[tls_insecure_skip_verify: <boolean> | default = false]

# The maximum amount of time to establish a connection. A value of 0 means
# using default gRPC client connect timeout 20s.
# CLI flag: -querier.frontend-client.connect-timeout
[connect_timeout: <duration> | default = 5s]
```

### `ingester_config`
Expand Down Expand Up @@ -3274,6 +3284,11 @@ grpc_client_config:
# CLI flag: -ingester.client.tls-insecure-skip-verify
[tls_insecure_skip_verify: <boolean> | default = false]

# The maximum amount of time to establish a connection. A value of 0 means
# using default gRPC client connect timeout 20s.
# CLI flag: -ingester.client.connect-timeout
[connect_timeout: <duration> | default = 5s]

# EXPERIMENTAL: If enabled, gRPC clients perform health checks for each target
# and fail the request if the target is marked as unhealthy.
healthcheck_config:
Expand Down Expand Up @@ -4192,6 +4207,11 @@ grpc_client_config:
# CLI flag: -frontend.grpc-client-config.tls-insecure-skip-verify
[tls_insecure_skip_verify: <boolean> | default = false]

# The maximum amount of time to establish a connection. A value of 0 means
# using default gRPC client connect timeout 20s.
# CLI flag: -frontend.grpc-client-config.connect-timeout
[connect_timeout: <duration> | default = 5s]

# When multiple query-schedulers are available, re-enqueue queries that were
# rejected due to too many outstanding requests.
# CLI flag: -frontend.retry-on-too-many-outstanding-requests
Expand Down Expand Up @@ -4418,6 +4438,11 @@ frontend_client:
# CLI flag: -ruler.frontendClient.tls-insecure-skip-verify
[tls_insecure_skip_verify: <boolean> | default = false]

# The maximum amount of time to establish a connection. A value of 0 means
# using default gRPC client connect timeout 20s.
# CLI flag: -ruler.frontendClient.connect-timeout
[connect_timeout: <duration> | default = 5s]

# URL of alerts return path.
# CLI flag: -ruler.external.url
[external_url: <url> | default = ]
Expand Down Expand Up @@ -4493,6 +4518,11 @@ ruler_client:
# CLI flag: -ruler.client.tls-insecure-skip-verify
[tls_insecure_skip_verify: <boolean> | default = false]

# The maximum amount of time to establish a connection. A value of 0 means
# using default gRPC client connect timeout 20s.
# CLI flag: -ruler.client.connect-timeout
[connect_timeout: <duration> | default = 5s]

# Timeout for downstream rulers.
# CLI flag: -ruler.client.remote-timeout
[remote_timeout: <duration> | default = 2m]
Expand Down
14 changes: 14 additions & 0 deletions pkg/util/grpcclient/grpcclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
middleware "github.com/grpc-ecosystem/go-grpc-middleware"
"github.com/pkg/errors"
"google.golang.org/grpc"
grpcbackoff "google.golang.org/grpc/backoff"
"google.golang.org/grpc/encoding/gzip"
"google.golang.org/grpc/keepalive"

Expand All @@ -32,6 +33,8 @@ type Config struct {
TLSEnabled bool `yaml:"tls_enabled"`
TLS tls.ClientConfig `yaml:",inline"`
SignWriteRequestsEnabled bool `yaml:"-"`

ConnectTimeout time.Duration `yaml:"connect_timeout"`
}

type ConfigWithHealthCheck struct {
Expand All @@ -58,6 +61,7 @@ func (cfg *Config) RegisterFlagsWithPrefix(prefix, defaultGrpcCompression string
f.IntVar(&cfg.RateLimitBurst, prefix+".grpc-client-rate-limit-burst", 0, "Rate limit burst for gRPC client.")
f.BoolVar(&cfg.BackoffOnRatelimits, prefix+".backoff-on-ratelimits", false, "Enable backoff and retry when we hit ratelimits.")
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.")
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.")

cfg.BackoffConfig.RegisterFlagsWithPrefix(prefix, f)

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

if cfg.ConnectTimeout > 0 {
opts = append(
opts,
grpc.WithConnectParams(grpc.ConnectParams{
Backoff: grpcbackoff.DefaultConfig,
MinConnectTimeout: cfg.ConnectTimeout,
}),
)
}

if cfg.SignWriteRequestsEnabled {
unaryClientInterceptors = append(unaryClientInterceptors, UnarySigningClientInterceptor)
}
Expand Down
Loading