From 91657dad182127bf577b449ff9d94e5bf86e592a Mon Sep 17 00:00:00 2001 From: Dimitris Sotirakis Date: Tue, 25 May 2021 11:32:41 +0300 Subject: [PATCH] HTTP Client: Make `ResponseHeaderTimeout` default timeout in http client (#34597) * HTTP Client: Add `ResponseHeaderTimeout` - split from `DialContext` timeout * Fixes according to reviewer's comments * Use grafana-plugin-sdk-go v0.100.0 --- conf/defaults.ini | 5 ++++- conf/sample.ini | 5 ++++- go.mod | 2 +- go.sum | 4 ++-- pkg/models/datasource_cache.go | 1 + pkg/setting/setting.go | 4 +++- 6 files changed, 15 insertions(+), 6 deletions(-) diff --git a/conf/defaults.ini b/conf/defaults.ini index c64eb7e9e43..b3afe596fea 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -139,10 +139,13 @@ connstr = # This enables data proxy logging, default is false logging = false -# How long the data proxy waits before timing out, default is 30 seconds. +# How long the data proxy waits to read the headers of the response before timing out, default is 30 seconds. # This setting also applies to core backend HTTP data sources where query requests use an HTTP client with timeout set. timeout = 30 +# How long the data proxy waits to establish a TCP connection before timing out, default is 10 seconds. +dialTimeout = 10 + # How many seconds the data proxy waits before sending a keepalive request. keep_alive_seconds = 30 diff --git a/conf/sample.ini b/conf/sample.ini index ed2e289432c..f86c70b5348 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -145,10 +145,13 @@ # This enables data proxy logging, default is false ;logging = false -# How long the data proxy waits before timing out, default is 30 seconds. +# How long the data proxy waits to read the headers of the response before timing out, default is 30 seconds. # This setting also applies to core backend HTTP data sources where query requests use an HTTP client with timeout set. ;timeout = 30 +# How long the data proxy waits to establish a TCP connection before timing out, default is 10 seconds. +;dialTimeout = 10 + # How many seconds the data proxy waits before sending a keepalive probe request. ;keep_alive_seconds = 30 diff --git a/go.mod b/go.mod index a227ca86274..5ade367b175 100644 --- a/go.mod +++ b/go.mod @@ -51,7 +51,7 @@ require ( github.com/gosimple/slug v1.9.0 github.com/grafana/grafana-aws-sdk v0.4.0 github.com/grafana/grafana-live-sdk v0.0.6 - github.com/grafana/grafana-plugin-sdk-go v0.99.0 + github.com/grafana/grafana-plugin-sdk-go v0.100.0 github.com/grafana/loki v1.6.2-0.20210520072447-15d417efe103 github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 github.com/hashicorp/go-hclog v0.16.0 diff --git a/go.sum b/go.sum index ce078b50bf4..823e47bd3a1 100644 --- a/go.sum +++ b/go.sum @@ -922,8 +922,8 @@ github.com/grafana/grafana-live-sdk v0.0.6 h1:P1QFn0ZradOJp3zVpfG0STZMP+pgZrW0e0 github.com/grafana/grafana-live-sdk v0.0.6/go.mod h1:f15hHmWyLdFjmuWLsjeKeZnq/HnNQ3QkoPcaEww45AY= github.com/grafana/grafana-plugin-sdk-go v0.79.0/go.mod h1:NvxLzGkVhnoBKwzkst6CFfpMFKwAdIUZ1q8ssuLeF60= github.com/grafana/grafana-plugin-sdk-go v0.91.0/go.mod h1:Ot3k7nY7P6DXmUsDgKvNB7oG1v7PRyTdmnYVoS554bU= -github.com/grafana/grafana-plugin-sdk-go v0.99.0 h1:pEmoSSYw7VsF+rhRgG4z+azE3eLwznomxVg9Ezppqzo= -github.com/grafana/grafana-plugin-sdk-go v0.99.0/go.mod h1:D7x3ah+1d4phNXpbnOaxa/osSaZlwh9/ZUnGGzegRbk= +github.com/grafana/grafana-plugin-sdk-go v0.100.0 h1:BryvIFdx/HrsKMt2hkxN7cJ0WrCgKpgjdJW8y8TSol0= +github.com/grafana/grafana-plugin-sdk-go v0.100.0/go.mod h1:D7x3ah+1d4phNXpbnOaxa/osSaZlwh9/ZUnGGzegRbk= github.com/grafana/loki v1.6.2-0.20210520072447-15d417efe103 h1:qCmofFVwQR9QnsinstVqI1NPLMVl33jNCnOCXEAVn6E= github.com/grafana/loki v1.6.2-0.20210520072447-15d417efe103/go.mod h1:GHIsn+EohCChsdu5YouNZewqLeV9L2FNw4DEJU3P9qE= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= diff --git a/pkg/models/datasource_cache.go b/pkg/models/datasource_cache.go index 292c74560ef..1ef513bf64b 100644 --- a/pkg/models/datasource_cache.go +++ b/pkg/models/datasource_cache.go @@ -76,6 +76,7 @@ func (ds *DataSource) HTTPClientOptions() sdkhttpclient.Options { opts := sdkhttpclient.Options{ Timeouts: &sdkhttpclient.TimeoutOptions{ Timeout: ds.getTimeout(), + DialTimeout: time.Duration(setting.DataProxyDialTimeout) * time.Second, KeepAlive: time.Duration(setting.DataProxyKeepAlive) * time.Second, TLSHandshakeTimeout: time.Duration(setting.DataProxyTLSHandshakeTimeout) * time.Second, ExpectContinueTimeout: time.Duration(setting.DataProxyExpectContinueTimeout) * time.Second, diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go index a2ecbb42f40..f34386e8b88 100644 --- a/pkg/setting/setting.go +++ b/pkg/setting/setting.go @@ -78,6 +78,7 @@ var ( // HTTP server options DataProxyLogging bool DataProxyTimeout int + DataProxyDialTimeout int DataProxyTLSHandshakeTimeout int DataProxyExpectContinueTimeout int DataProxyMaxIdleConns int @@ -823,7 +824,8 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error { // read data proxy settings dataproxy := iniFile.Section("dataproxy") DataProxyLogging = dataproxy.Key("logging").MustBool(false) - DataProxyTimeout = dataproxy.Key("timeout").MustInt(30) + DataProxyTimeout = dataproxy.Key("timeout").MustInt(10) + DataProxyDialTimeout = dataproxy.Key("dialTimeout").MustInt(30) 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)