Skip to content

Commit

Permalink
InfluxDB: Use grafana timeout value for flux queries (#81252)
Browse files Browse the repository at this point in the history
* use grafana timeout for flux queries

* get timeout from settings

* fix test
  • Loading branch information
itsmylife authored and rwwiv committed Jan 25, 2024
1 parent f61ec09 commit 2f31121
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
7 changes: 4 additions & 3 deletions pkg/tsdb/influxdb/flux/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
"github.com/grafana/grafana/pkg/util"
)

//--------------------------------------------------------------
// --------------------------------------------------------------
// TestData -- reads result from saved files
//--------------------------------------------------------------
// --------------------------------------------------------------

// MockRunner reads local file path for testdata.
type MockRunner struct {
Expand Down Expand Up @@ -220,7 +220,8 @@ func TestRealQuery(t *testing.T) {
json.Set("organization", "test-org")

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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/tsdb/influxdb/flux/flux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ var (
)

// Query builds flux queries, executes them, and returns the results.
func Query(ctx context.Context, dsInfo *models.DatasourceInfo, tsdbQuery backend.QueryDataRequest) (
*backend.QueryDataResponse, error) {
func Query(ctx context.Context, dsInfo *models.DatasourceInfo, tsdbQuery backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
logger := glog.FromContext(ctx)
tRes := backend.NewQueryDataResponse()
logger.Debug("Received a query", "query", tsdbQuery)
Expand Down Expand Up @@ -76,6 +75,7 @@ func runnerFromDataSource(dsInfo *models.DatasourceInfo) (*runner, error) {
}
opts := influxdb2.DefaultOptions()
opts.HTTPOptions().SetHTTPClient(dsInfo.HTTPClient)
opts.SetHTTPRequestTimeout(uint(dsInfo.Timeout.Seconds()))
return &runner{
client: influxdb2.NewClientWithOptions(url, dsInfo.Token, opts),
org: org,
Expand Down
1 change: 1 addition & 0 deletions pkg/tsdb/influxdb/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func newInstanceSettings(httpClientProvider httpclient.Provider) datasource.Inst
MaxSeries: maxSeries,
SecureGrpc: true,
Token: settings.DecryptedSecureJSONData["token"],
Timeout: opts.Timeouts.Timeout,
}
return model, nil
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/tsdb/influxdb/models/datasource_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package models

import (
"net/http"
"time"
)

type DatasourceInfo struct {
Expand All @@ -17,6 +18,7 @@ type DatasourceInfo struct {
DefaultBucket string `json:"defaultBucket"`
Organization string `json:"organization"`
MaxSeries int `json:"maxSeries"`
Timeout time.Duration

// FlightSQL grpc connection
SecureGrpc bool `json:"secureGrpc"`
Expand Down

0 comments on commit 2f31121

Please sign in to comment.