mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
InfluxDB: Use grafana timeout value for flux queries (#81252)
* use grafana timeout for flux queries * get timeout from settings * fix test
This commit is contained in:
parent
add5a5c01e
commit
7d0017f3f2
@ -24,9 +24,9 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/util"
|
"github.com/grafana/grafana/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
//--------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
// TestData -- reads result from saved files
|
// TestData -- reads result from saved files
|
||||||
//--------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
|
|
||||||
// MockRunner reads local file path for testdata.
|
// MockRunner reads local file path for testdata.
|
||||||
type MockRunner struct {
|
type MockRunner struct {
|
||||||
@ -220,7 +220,8 @@ func TestRealQuery(t *testing.T) {
|
|||||||
json.Set("organization", "test-org")
|
json.Set("organization", "test-org")
|
||||||
|
|
||||||
dsInfo := &models.DatasourceInfo{
|
dsInfo := &models.DatasourceInfo{
|
||||||
URL: "http://localhost:9999", // NOTE! no api/v2
|
URL: "http://localhost:9999", // NOTE! no api/v2
|
||||||
|
Timeout: 30 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
runner, err := runnerFromDataSource(dsInfo)
|
runner, err := runnerFromDataSource(dsInfo)
|
||||||
|
@ -17,8 +17,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Query builds flux queries, executes them, and returns the results.
|
// Query builds flux queries, executes them, and returns the results.
|
||||||
func Query(ctx context.Context, dsInfo *models.DatasourceInfo, tsdbQuery backend.QueryDataRequest) (
|
func Query(ctx context.Context, dsInfo *models.DatasourceInfo, tsdbQuery backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
||||||
*backend.QueryDataResponse, error) {
|
|
||||||
logger := glog.FromContext(ctx)
|
logger := glog.FromContext(ctx)
|
||||||
tRes := backend.NewQueryDataResponse()
|
tRes := backend.NewQueryDataResponse()
|
||||||
logger.Debug("Received a query", "query", tsdbQuery)
|
logger.Debug("Received a query", "query", tsdbQuery)
|
||||||
@ -76,6 +75,7 @@ func runnerFromDataSource(dsInfo *models.DatasourceInfo) (*runner, error) {
|
|||||||
}
|
}
|
||||||
opts := influxdb2.DefaultOptions()
|
opts := influxdb2.DefaultOptions()
|
||||||
opts.HTTPOptions().SetHTTPClient(dsInfo.HTTPClient)
|
opts.HTTPOptions().SetHTTPClient(dsInfo.HTTPClient)
|
||||||
|
opts.SetHTTPRequestTimeout(uint(dsInfo.Timeout.Seconds()))
|
||||||
return &runner{
|
return &runner{
|
||||||
client: influxdb2.NewClientWithOptions(url, dsInfo.Token, opts),
|
client: influxdb2.NewClientWithOptions(url, dsInfo.Token, opts),
|
||||||
org: org,
|
org: org,
|
||||||
|
@ -84,6 +84,7 @@ func newInstanceSettings(httpClientProvider httpclient.Provider) datasource.Inst
|
|||||||
MaxSeries: maxSeries,
|
MaxSeries: maxSeries,
|
||||||
SecureGrpc: true,
|
SecureGrpc: true,
|
||||||
Token: settings.DecryptedSecureJSONData["token"],
|
Token: settings.DecryptedSecureJSONData["token"],
|
||||||
|
Timeout: opts.Timeouts.Timeout,
|
||||||
}
|
}
|
||||||
return model, nil
|
return model, nil
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package models
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DatasourceInfo struct {
|
type DatasourceInfo struct {
|
||||||
@ -17,6 +18,7 @@ type DatasourceInfo struct {
|
|||||||
DefaultBucket string `json:"defaultBucket"`
|
DefaultBucket string `json:"defaultBucket"`
|
||||||
Organization string `json:"organization"`
|
Organization string `json:"organization"`
|
||||||
MaxSeries int `json:"maxSeries"`
|
MaxSeries int `json:"maxSeries"`
|
||||||
|
Timeout time.Duration
|
||||||
|
|
||||||
// FlightSQL grpc connection
|
// FlightSQL grpc connection
|
||||||
SecureGrpc bool `json:"secureGrpc"`
|
SecureGrpc bool `json:"secureGrpc"`
|
||||||
|
Loading…
Reference in New Issue
Block a user