Skip to content
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

feat(chunks): support custom MaxIdleConns and MaxIdleConnsPerHost in AWS s3 storage client #15976

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions docs/sources/shared/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,16 @@ http_config:
# CLI flag: -s3.http.idle-conn-timeout
[idle_conn_timeout: <duration> | default = 1m30s]

# Maximum number of idle (keep-alive) connections across all hosts. Set to 0
# for no limit.
# CLI flag: -s3.http.max-idle-connections
[max_idle_connections: <int> | default = 200]

# Maximum number of idle (keep-alive) connections to keep per-host. Set to 0
# to use a built-in default value of 2.
JStickler marked this conversation as resolved.
Show resolved Hide resolved
# CLI flag: -s3.http.max-idle-connections-per-host
[max_idle_connections_per_host: <int> | default = 200]

# If non-zero, specifies the amount of time to wait for a server's response
# headers after fully writing the request.
# CLI flag: -s3.http.response-header-timeout
Expand Down Expand Up @@ -5155,6 +5165,16 @@ http_config:
# CLI flag: -<prefix>.storage.s3.http.idle-conn-timeout
[idle_conn_timeout: <duration> | default = 1m30s]

# Maximum number of idle (keep-alive) connections across all hosts. Set to 0
# for no limit.
# CLI flag: -<prefix>.storage.s3.http.max-idle-connections
[max_idle_connections: <int> | default = 200]

# Maximum number of idle (keep-alive) connections to keep per-host. Set to 0
# to use a built-in default value of 2.
# CLI flag: -<prefix>.storage.s3.http.max-idle-connections-per-host
[max_idle_connections_per_host: <int> | default = 200]

# If non-zero, specifies the amount of time to wait for a server's response
# headers after fully writing the request.
# CLI flag: -<prefix>.storage.s3.http.response-header-timeout
Expand Down
10 changes: 7 additions & 3 deletions pkg/storage/chunk/client/aws/s3_storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ type S3Config struct {
type HTTPConfig struct {
Timeout time.Duration `yaml:"timeout"`
IdleConnTimeout time.Duration `yaml:"idle_conn_timeout"`
MaxIdleConns int `yaml:"max_idle_connections"`
MaxIdleConnsPerHost int `yaml:"max_idle_connections_per_host"`
ResponseHeaderTimeout time.Duration `yaml:"response_header_timeout"`
InsecureSkipVerify bool `yaml:"insecure_skip_verify"`
CAFile string `yaml:"ca_file"`
Expand Down Expand Up @@ -118,6 +120,8 @@ func (cfg *S3Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
cfg.SSEConfig.RegisterFlagsWithPrefix(prefix+"s3.sse.", f)

f.DurationVar(&cfg.HTTPConfig.IdleConnTimeout, prefix+"s3.http.idle-conn-timeout", 90*time.Second, "The maximum amount of time an idle connection will be held open.")
f.IntVar(&cfg.HTTPConfig.MaxIdleConns, prefix+"s3.http.max-idle-connections", 200, "Maximum number of idle (keep-alive) connections across all hosts. Set to 0 for no limit.")
f.IntVar(&cfg.HTTPConfig.MaxIdleConnsPerHost, prefix+"s3.http.max-idle-connections-per-host", 200, "Maximum number of idle (keep-alive) connections to keep per-host. Set to 0 to use a built-in default value of 2.")
f.DurationVar(&cfg.HTTPConfig.Timeout, prefix+"s3.http.timeout", 0, "Timeout specifies a time limit for requests made by s3 Client.")
f.DurationVar(&cfg.HTTPConfig.ResponseHeaderTimeout, prefix+"s3.http.response-header-timeout", 0, "If non-zero, specifies the amount of time to wait for a server's response headers after fully writing the request.")
f.BoolVar(&cfg.HTTPConfig.InsecureSkipVerify, prefix+"s3.http.insecure-skip-verify", false, "Set to true to skip verifying the certificate chain and hostname.")
Expand Down Expand Up @@ -230,7 +234,7 @@ func buildS3Client(cfg S3Config, hedgingCfg hedging.Config, hedging bool) (*s3.S
}

tlsConfig := &tls.Config{
InsecureSkipVerify: cfg.HTTPConfig.InsecureSkipVerify, //#nosec G402 -- User has explicitly requested to disable TLS
InsecureSkipVerify: cfg.HTTPConfig.InsecureSkipVerify,
}

if cfg.HTTPConfig.CAFile != "" {
Expand All @@ -253,9 +257,9 @@ func buildS3Client(cfg S3Config, hedgingCfg hedging.Config, hedging bool) (*s3.S
KeepAlive: 30 * time.Second,
DualStack: !cfg.DisableDualstack,
}).DialContext,
MaxIdleConns: 200,
MaxIdleConns: cfg.HTTPConfig.MaxIdleConns,
IdleConnTimeout: cfg.HTTPConfig.IdleConnTimeout,
MaxIdleConnsPerHost: 200,
MaxIdleConnsPerHost: cfg.HTTPConfig.MaxIdleConnsPerHost,
TLSHandshakeTimeout: 3 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
ResponseHeaderTimeout: cfg.HTTPConfig.ResponseHeaderTimeout,
Expand Down
Loading