mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 08:42:15 +08:00
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:

committed by
GitHub

parent
eff2410bae
commit
d15d87db8a
@ -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
|
||||
|
Reference in New Issue
Block a user