Datasource: Fix storing timeout option as numeric (#35441)

#31871 introduced support for configuring timeout in seconds
for HTTP data sources. That had a bug where backend expected
a numeric timeout value where it was actually stored as a
string. This should resolve this by requiring input to be
numbers, storing input as numeric and falling back to string
value if there's no numeric value.

Ref #31871
This commit is contained in:
Marcus Efraimsson
2021-06-10 10:27:14 +02:00
committed by GitHub
parent eff2410bae
commit d15d87db8a
3 changed files with 33 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import (
"crypto/tls"
"fmt"
"net/http"
"strconv"
"sync"
"time"
@ -17,8 +18,15 @@ func (ds *DataSource) getTimeout() time.Duration {
timeout := 0
if ds.JsonData != nil {
timeout = ds.JsonData.Get("timeout").MustInt()
if timeout <= 0 {
if timeoutStr := ds.JsonData.Get("timeout").MustString(); timeoutStr != "" {
if t, err := strconv.Atoi(timeoutStr); err == nil {
timeout = t
}
}
}
}
if timeout == 0 {
if timeout <= 0 {
timeout = setting.DataProxyTimeout
}
return time.Duration(timeout) * time.Second