Able to configure API request timeout, #1046

This commit is contained in:
Alexander Zobnin
2020-11-10 16:39:06 +03:00
parent 965216a607
commit 82819b20aa
6 changed files with 40 additions and 11 deletions

View File

@@ -13,6 +13,7 @@ import (
simplejson "github.com/bitly/go-simplejson"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/backend/log"
)
type proxyTransportCache struct {
@@ -46,14 +47,16 @@ var ptc = proxyTransportCache{
}
// GetHttpClient returns new http.Client. Transport either initialized or got from cache.
func GetHttpClient(ds *backend.DataSourceInstanceSettings) (*http.Client, error) {
func GetHttpClient(ds *backend.DataSourceInstanceSettings, timeout time.Duration) (*http.Client, error) {
transport, err := getHttpTransport(ds)
if err != nil {
return nil, err
}
log.DefaultLogger.Debug("Initializing new HTTP client", "timeout", timeout.Seconds())
return &http.Client{
Timeout: time.Duration(time.Second * 30),
Timeout: timeout,
Transport: transport,
}, nil
}