From 7bbeea5121926a9f7436cc3bcf433ea9bf54abc4 Mon Sep 17 00:00:00 2001 From: Javier Palomo Date: Thu, 10 Jun 2021 17:13:37 +0200 Subject: [PATCH] [v7.5.x] Datasource: Allow configuring `MaxConnsPerHost` (#35519) Allow configuring MaxConnsPerHost for HTTP data sources. Ref #35321 Ref #35257 --- conf/defaults.ini | 5 +++++ conf/sample.ini | 5 +++++ docs/sources/administration/configuration.md | 5 +++++ pkg/models/datasource_cache.go | 3 ++- pkg/setting/setting.go | 2 ++ 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/conf/defaults.ini b/conf/defaults.ini index 408f45b699d..b716c9e35a2 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -155,6 +155,11 @@ tls_handshake_timeout_seconds = 10 # waiting for the server to approve. expect_continue_timeout_seconds = 1 +# Optionally limits the total number of connections per host, including connections in the dialing, +# active, and idle states. On limit violation, dials will block. +# A value of zero (0) means no limit. +max_conns_per_host = 0 + # The maximum number of idle connections that Grafana will keep alive. max_idle_connections = 100 diff --git a/conf/sample.ini b/conf/sample.ini index 7c12f4f86dd..73528e3734e 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -161,6 +161,11 @@ # waiting for the server to approve. ;expect_continue_timeout_seconds = 1 +# Optionally limits the total number of connections per host, including connections in the dialing, +# active, and idle states. On limit violation, dials will block. +# A value of zero (0) means no limit. +;max_conns_per_host = 0 + # The maximum number of idle connections that Grafana will keep alive. ;max_idle_connections = 100 diff --git a/docs/sources/administration/configuration.md b/docs/sources/administration/configuration.md index a9ea94de131..68059bbb9a2 100644 --- a/docs/sources/administration/configuration.md +++ b/docs/sources/administration/configuration.md @@ -414,6 +414,11 @@ The length of time that Grafana will wait for a successful TLS handshake with th The length of time that Grafana will wait for a datasource’s first response headers after fully writing the request headers, if the request has an “Expect: 100-continue” header. A value of `0` will result in the body being sent immediately. Default is `1` second. For more details check the [Transport.ExpectContinueTimeout](https://golang.org/pkg/net/http/#Transport.ExpectContinueTimeout) documentation. +### max_conns_per_host + +Optionally limits the total number of connections per host, including connections in the dialing, active, and idle states. On limit violation, dials are blocked. A value of `0` means that there are no limits. Default is `0`. +For more details check the [Transport.MaxConnsPerHost](https://golang.org/pkg/net/http/#Transport.MaxConnsPerHost) documentation. + ### max_idle_connections The maximum number of idle connections that Grafana will maintain. Default is `100`. For more details check the [Transport.MaxIdleConns](https://golang.org/pkg/net/http/#Transport.MaxIdleConns) documentation. diff --git a/pkg/models/datasource_cache.go b/pkg/models/datasource_cache.go index c3ecec176d2..5c368e14da6 100644 --- a/pkg/models/datasource_cache.go +++ b/pkg/models/datasource_cache.go @@ -167,7 +167,8 @@ func (ds *DataSource) GetHttpTransport() (*dataSourceTransport, error) { TLSHandshakeTimeout: time.Duration(setting.DataProxyTLSHandshakeTimeout) * time.Second, ExpectContinueTimeout: time.Duration(setting.DataProxyExpectContinueTimeout) * time.Second, MaxIdleConns: setting.DataProxyMaxIdleConns, - MaxConnsPerHost: setting.DataProxyMaxIdleConnsPerHost, + MaxConnsPerHost: setting.DataProxyMaxConnsPerHost, + MaxIdleConnsPerHost: setting.DataProxyMaxIdleConnsPerHost, IdleConnTimeout: time.Duration(setting.DataProxyIdleConnTimeout) * time.Second, } diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go index 52a36e605e8..530f61fcc8f 100644 --- a/pkg/setting/setting.go +++ b/pkg/setting/setting.go @@ -82,6 +82,7 @@ var ( DataProxyTimeout int DataProxyTLSHandshakeTimeout int DataProxyExpectContinueTimeout int + DataProxyMaxConnsPerHost int DataProxyMaxIdleConns int DataProxyMaxIdleConnsPerHost int DataProxyKeepAlive int @@ -809,6 +810,7 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error { DataProxyKeepAlive = dataproxy.Key("keep_alive_seconds").MustInt(30) DataProxyTLSHandshakeTimeout = dataproxy.Key("tls_handshake_timeout_seconds").MustInt(10) DataProxyExpectContinueTimeout = dataproxy.Key("expect_continue_timeout_seconds").MustInt(1) + DataProxyMaxConnsPerHost = dataproxy.Key("max_conns_per_host").MustInt(0) DataProxyMaxIdleConns = dataproxy.Key("max_idle_connections").MustInt(100) DataProxyMaxIdleConnsPerHost = dataproxy.Key("max_idle_connections_per_host").MustInt(2) DataProxyIdleConnTimeout = dataproxy.Key("idle_conn_timeout_seconds").MustInt(90)