InfluxDB: Fix handling flux response with no time and value column (#72833)

* Upgrade the influxdb-client-go version

* Handle flux response with no time and value column
This commit is contained in:
ismail simsek
2023-08-08 16:00:52 +03:00
committed by GitHub
parent 533fae4c60
commit 1ac9e7eaab
6 changed files with 354 additions and 14 deletions

View File

@@ -190,23 +190,11 @@ func (fb *frameBuilder) Init(metadata *query.FluxTableMetadata) error {
if col.IsGroup() {
fb.labels = append(fb.labels, col.Name())
} else {
dataType := col.DataType()
name := col.Name()
isTimestamp := isTimestampType(dataType)
converter, err := getConverter(dataType)
info, isTimestamp, err := getColumnInfo(col)
if err != nil {
return err
}
info := &columnInfo{
name: name,
converter: converter,
shouldGetLabels: true, // we default to get-labels
isTheSimpleValue: false,
isTheSimpleTime: false,
}
if isTimestamp {
timestampCols = append(timestampCols, info)
} else {
@@ -243,6 +231,18 @@ func (fb *frameBuilder) Init(metadata *query.FluxTableMetadata) error {
fb.columns = append(fb.columns, *colInfo)
}
// if there is no columns in frame builder we use all the dataColumns
// this can happen with the queries which includes no time and value columns
if len(fb.columns) == 0 {
for _, col := range dataColumns {
info, _, err := getColumnInfo(col)
if err != nil {
return err
}
fb.columns = append(fb.columns, *info)
}
}
return nil
}
@@ -254,6 +254,25 @@ func (e maxPointsExceededError) Error() string {
return fmt.Sprintf("max data points limit exceeded (count is %d)", e.Count)
}
func getColumnInfo(col *query.FluxColumn) (info *columnInfo, isTimestamp bool, err error) {
dataType := col.DataType()
isTimestamp = isTimestampType(dataType)
name := col.Name()
converter, err := getConverter(dataType)
if err != nil {
return nil, false, err
}
return &columnInfo{
name: name,
converter: converter,
shouldGetLabels: true, // we default to get-labels
isTheSimpleValue: false,
isTheSimpleTime: false,
}, isTimestamp, nil
}
func getTableID(record *query.FluxRecord, groupColumns []string) []interface{} {
result := make([]interface{}, len(groupColumns))

View File

@@ -305,3 +305,13 @@ func TestTimestampFirst(t *testing.T) {
require.Equal(t, "Time", dr.Frames[0].Fields[0].Name)
require.Equal(t, "Value", dr.Frames[0].Fields[1].Name)
}
func TestWithoutTimeColumn(t *testing.T) {
dr := verifyGoldenResponse(t, "without-time-column")
require.Len(t, dr.Frames, 5)
// we make sure the timestamp-column is the first column
// in the dataframe, even if it was not the first column
// in the csv.
require.Equal(t, "cpu", dr.Frames[0].Fields[0].Name)
require.Equal(t, "host", dr.Frames[0].Fields[1].Name)
}

View File

@@ -0,0 +1,14 @@
#datatype,string,long,string,string
#group,false,false,true,true
#default,last,,,
,result,table,cpu,host
,,0,cpu-total,cc59eb40ad0f
,,0,cpu-total,cc59eb40ad0f
,,1,cpu0,cc59eb40ad0f
,,1,cpu0,cc59eb40ad0f
,,2,cpu1,cc59eb40ad0f
,,3,cpu2,cc59eb40ad0f
,,3,cpu2,cc59eb40ad0f
,,4,cpu3,cc59eb40ad0f
,,4,cpu3,cc59eb40ad0f
1 #datatype string long string string
2 #group false false true true
3 #default last
4 result table cpu host
5 0 cpu-total cc59eb40ad0f
6 0 cpu-total cc59eb40ad0f
7 1 cpu0 cc59eb40ad0f
8 1 cpu0 cc59eb40ad0f
9 2 cpu1 cc59eb40ad0f
10 3 cpu2 cc59eb40ad0f
11 3 cpu2 cc59eb40ad0f
12 4 cpu3 cc59eb40ad0f
13 4 cpu3 cc59eb40ad0f

View File

@@ -0,0 +1,295 @@
// 🌟 This was machine generated. Do not edit. 🌟
//
// Frame[0] {
// "typeVersion": [
// 0,
// 0
// ]
// }
// Name:
// Dimensions: 2 Fields by 2 Rows
// +------------------------------------------+------------------------------------------+
// | Name: cpu | Name: host |
// | Labels: cpu=cpu-total, host=cc59eb40ad0f | Labels: cpu=cpu-total, host=cc59eb40ad0f |
// | Type: []*string | Type: []*string |
// +------------------------------------------+------------------------------------------+
// | cpu-total | cc59eb40ad0f |
// | cpu-total | cc59eb40ad0f |
// +------------------------------------------+------------------------------------------+
//
//
//
// Frame[1]
// Name:
// Dimensions: 2 Fields by 2 Rows
// +-------------------------------------+-------------------------------------+
// | Name: cpu | Name: host |
// | Labels: cpu=cpu0, host=cc59eb40ad0f | Labels: cpu=cpu0, host=cc59eb40ad0f |
// | Type: []*string | Type: []*string |
// +-------------------------------------+-------------------------------------+
// | cpu0 | cc59eb40ad0f |
// | cpu0 | cc59eb40ad0f |
// +-------------------------------------+-------------------------------------+
//
//
//
// Frame[2]
// Name:
// Dimensions: 2 Fields by 1 Rows
// +-------------------------------------+-------------------------------------+
// | Name: cpu | Name: host |
// | Labels: cpu=cpu1, host=cc59eb40ad0f | Labels: cpu=cpu1, host=cc59eb40ad0f |
// | Type: []*string | Type: []*string |
// +-------------------------------------+-------------------------------------+
// | cpu1 | cc59eb40ad0f |
// +-------------------------------------+-------------------------------------+
//
//
//
// Frame[3]
// Name:
// Dimensions: 2 Fields by 2 Rows
// +-------------------------------------+-------------------------------------+
// | Name: cpu | Name: host |
// | Labels: cpu=cpu2, host=cc59eb40ad0f | Labels: cpu=cpu2, host=cc59eb40ad0f |
// | Type: []*string | Type: []*string |
// +-------------------------------------+-------------------------------------+
// | cpu2 | cc59eb40ad0f |
// | cpu2 | cc59eb40ad0f |
// +-------------------------------------+-------------------------------------+
//
//
//
// Frame[4]
// Name:
// Dimensions: 2 Fields by 2 Rows
// +-------------------------------------+-------------------------------------+
// | Name: cpu | Name: host |
// | Labels: cpu=cpu3, host=cc59eb40ad0f | Labels: cpu=cpu3, host=cc59eb40ad0f |
// | Type: []*string | Type: []*string |
// +-------------------------------------+-------------------------------------+
// | cpu3 | cc59eb40ad0f |
// | cpu3 | cc59eb40ad0f |
// +-------------------------------------+-------------------------------------+
//
//
// 🌟 This was machine generated. Do not edit. 🌟
{
"status": 200,
"frames": [
{
"schema": {
"meta": {
"typeVersion": [
0,
0
]
},
"fields": [
{
"name": "cpu",
"type": "string",
"typeInfo": {
"frame": "string",
"nullable": true
},
"labels": {
"cpu": "cpu-total",
"host": "cc59eb40ad0f"
}
},
{
"name": "host",
"type": "string",
"typeInfo": {
"frame": "string",
"nullable": true
},
"labels": {
"cpu": "cpu-total",
"host": "cc59eb40ad0f"
}
}
]
},
"data": {
"values": [
[
"cpu-total",
"cpu-total"
],
[
"cc59eb40ad0f",
"cc59eb40ad0f"
]
]
}
},
{
"schema": {
"fields": [
{
"name": "cpu",
"type": "string",
"typeInfo": {
"frame": "string",
"nullable": true
},
"labels": {
"cpu": "cpu0",
"host": "cc59eb40ad0f"
}
},
{
"name": "host",
"type": "string",
"typeInfo": {
"frame": "string",
"nullable": true
},
"labels": {
"cpu": "cpu0",
"host": "cc59eb40ad0f"
}
}
]
},
"data": {
"values": [
[
"cpu0",
"cpu0"
],
[
"cc59eb40ad0f",
"cc59eb40ad0f"
]
]
}
},
{
"schema": {
"fields": [
{
"name": "cpu",
"type": "string",
"typeInfo": {
"frame": "string",
"nullable": true
},
"labels": {
"cpu": "cpu1",
"host": "cc59eb40ad0f"
}
},
{
"name": "host",
"type": "string",
"typeInfo": {
"frame": "string",
"nullable": true
},
"labels": {
"cpu": "cpu1",
"host": "cc59eb40ad0f"
}
}
]
},
"data": {
"values": [
[
"cpu1"
],
[
"cc59eb40ad0f"
]
]
}
},
{
"schema": {
"fields": [
{
"name": "cpu",
"type": "string",
"typeInfo": {
"frame": "string",
"nullable": true
},
"labels": {
"cpu": "cpu2",
"host": "cc59eb40ad0f"
}
},
{
"name": "host",
"type": "string",
"typeInfo": {
"frame": "string",
"nullable": true
},
"labels": {
"cpu": "cpu2",
"host": "cc59eb40ad0f"
}
}
]
},
"data": {
"values": [
[
"cpu2",
"cpu2"
],
[
"cc59eb40ad0f",
"cc59eb40ad0f"
]
]
}
},
{
"schema": {
"fields": [
{
"name": "cpu",
"type": "string",
"typeInfo": {
"frame": "string",
"nullable": true
},
"labels": {
"cpu": "cpu3",
"host": "cc59eb40ad0f"
}
},
{
"name": "host",
"type": "string",
"typeInfo": {
"frame": "string",
"nullable": true
},
"labels": {
"cpu": "cpu3",
"host": "cc59eb40ad0f"
}
}
]
},
"data": {
"values": [
[
"cpu3",
"cpu3"
],
[
"cc59eb40ad0f",
"cc59eb40ad0f"
]
]
}
}
]
}