mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
InfluxDB: use released client 1.3.0 (#25725)
This commit is contained in:
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
influxdb2 "github.com/influxdata/influxdb-client-go"
|
||||
"github.com/influxdata/influxdb-client-go/api/query"
|
||||
)
|
||||
|
||||
// Copied from: (Apache 2 license)
|
||||
@@ -26,9 +26,9 @@ type columnInfo struct {
|
||||
converter *data.FieldConverter
|
||||
}
|
||||
|
||||
// This is an interface to help testing
|
||||
// FrameBuilder This is an interface to help testing
|
||||
type FrameBuilder struct {
|
||||
tableId int64
|
||||
tableID int64
|
||||
active *data.Frame
|
||||
frames []*data.Frame
|
||||
value *data.FieldConverter
|
||||
@@ -72,10 +72,10 @@ func getConverter(t string) (*data.FieldConverter, error) {
|
||||
// Init initializes the frame to be returned
|
||||
// fields points at entries in the frame, and provides easier access
|
||||
// names indexes the columns encountered
|
||||
func (fb *FrameBuilder) Init(metadata *influxdb2.FluxTableMetadata) error {
|
||||
func (fb *FrameBuilder) Init(metadata *query.FluxTableMetadata) error {
|
||||
columns := metadata.Columns()
|
||||
fb.frames = make([]*data.Frame, 0)
|
||||
fb.tableId = -1
|
||||
fb.tableID = -1
|
||||
fb.value = nil
|
||||
fb.columns = make([]columnInfo, 0)
|
||||
fb.isTimeSeries = false
|
||||
@@ -120,9 +120,9 @@ func (fb *FrameBuilder) Init(metadata *influxdb2.FluxTableMetadata) error {
|
||||
// Tags are appended as labels
|
||||
// _measurement holds the dataframe name
|
||||
// _field holds the field name.
|
||||
func (fb *FrameBuilder) Append(record *influxdb2.FluxRecord) error {
|
||||
func (fb *FrameBuilder) Append(record *query.FluxRecord) error {
|
||||
table, ok := record.ValueByKey("table").(int64)
|
||||
if ok && table != fb.tableId {
|
||||
if ok && table != fb.tableID {
|
||||
fb.totalSeries++
|
||||
if fb.totalSeries > fb.maxSeries {
|
||||
return fmt.Errorf("reached max series limit (%d)", fb.maxSeries)
|
||||
@@ -153,7 +153,7 @@ func (fb *FrameBuilder) Append(record *influxdb2.FluxRecord) error {
|
||||
}
|
||||
|
||||
fb.frames = append(fb.frames, fb.active)
|
||||
fb.tableId = table
|
||||
fb.tableID = table
|
||||
}
|
||||
|
||||
if fb.isTimeSeries {
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
influxdb2 "github.com/influxdata/influxdb-client-go"
|
||||
"github.com/influxdata/influxdb-client-go/api"
|
||||
)
|
||||
|
||||
// ExecuteQuery runs a flux query using the QueryModel to interpolate the query and the runner to execute it.
|
||||
@@ -45,7 +45,7 @@ func ExecuteQuery(ctx context.Context, query QueryModel, runner queryRunner, max
|
||||
return dr
|
||||
}
|
||||
|
||||
func readDataFrames(result *influxdb2.QueryTableResult, maxPoints int, maxSeries int) (dr backend.DataResponse) {
|
||||
func readDataFrames(result *api.QueryTableResult, maxPoints int, maxSeries int) (dr backend.DataResponse) {
|
||||
dr = backend.DataResponse{}
|
||||
|
||||
builder := &FrameBuilder{
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
influxdb2 "github.com/influxdata/influxdb-client-go"
|
||||
"github.com/influxdata/influxdb-client-go/api"
|
||||
)
|
||||
|
||||
//--------------------------------------------------------------
|
||||
@@ -22,7 +23,7 @@ type MockRunner struct {
|
||||
testDataPath string
|
||||
}
|
||||
|
||||
func (r *MockRunner) runQuery(ctx context.Context, q string) (*influxdb2.QueryTableResult, error) {
|
||||
func (r *MockRunner) runQuery(ctx context.Context, q string) (*api.QueryTableResult, error) {
|
||||
bytes, err := ioutil.ReadFile("./testdata/" + r.testDataPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/tsdb"
|
||||
influxdb2 "github.com/influxdata/influxdb-client-go"
|
||||
"github.com/influxdata/influxdb-client-go/api"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -53,11 +54,11 @@ type Runner struct {
|
||||
|
||||
// This is an interface to help testing
|
||||
type queryRunner interface {
|
||||
runQuery(ctx context.Context, q string) (*influxdb2.QueryTableResult, error)
|
||||
runQuery(ctx context.Context, q string) (*api.QueryTableResult, error)
|
||||
}
|
||||
|
||||
// runQuery executes fluxQuery against the Runner's organization and returns an flux typed result.
|
||||
func (r *Runner) runQuery(ctx context.Context, fluxQuery string) (*influxdb2.QueryTableResult, error) {
|
||||
func (r *Runner) runQuery(ctx context.Context, fluxQuery string) (*api.QueryTableResult, error) {
|
||||
return r.client.QueryApi(r.org).Query(ctx, fluxQuery)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user