Chore: Return executedString information even with frames has no time column (#78906)

* return executedString for no time column responses

* remove comment
This commit is contained in:
ismail simsek 2023-11-30 14:25:15 +01:00 committed by GitHub
parent 7cbf5ae78d
commit dff5022021
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 115 additions and 205 deletions

View File

@ -285,20 +285,25 @@ func newFrameWithTimeField(row models.Row, column string, colIndex int, query mo
} }
func newFrameWithoutTimeField(row models.Row, query models.Query) *data.Frame { func newFrameWithoutTimeField(row models.Row, query models.Query) *data.Frame {
var values []string var values []*string
for _, valuePair := range row.Values { for _, valuePair := range row.Values {
if strings.Contains(strings.ToLower(query.RawQuery), strings.ToLower("SHOW TAG VALUES")) { if strings.Contains(strings.ToLower(query.RawQuery), strings.ToLower("SHOW TAG VALUES")) {
if len(valuePair) >= 2 { if len(valuePair) >= 2 {
values = append(values, valuePair[1].(string)) values = append(values, util.ToPtr(valuePair[1].(string)))
} }
} else { } else {
if len(valuePair) >= 1 { if len(valuePair) >= 1 {
values = append(values, valuePair[0].(string)) values = append(values, util.ToPtr(valuePair[0].(string)))
} }
} }
} }
field := data.NewField("Value", nil, values) field := data.NewField("Value", nil, values)
return data.NewFrame(row.Name, field) frame := data.NewFrame(row.Name, field)
frame.Meta = &data.FrameMeta{
ExecutedQueryString: query.RawQuery,
PreferredVisualization: util.GetVisType(query.ResultFormat),
}
return frame
} }

View File

@ -54,7 +54,6 @@ var testFiles = []string{
"show_tag_values_response", "show_tag_values_response",
"retention_policy", "retention_policy",
"simple_response_with_diverse_data_types", "simple_response_with_diverse_data_types",
"measurements",
"multiple_measurements", "multiple_measurements",
// "many_columns", skipped for now // "many_columns", skipped for now
"response_with_nil_bools_and_nil_strings", "response_with_nil_bools_and_nil_strings",
@ -109,7 +108,7 @@ func TestInfluxdbResponseParser(t *testing.T) {
labels, err := data.LabelsFromString("/cluster/name/=Cluster/, @cluster@name@=Cluster@, cluster-name=Cluster, datacenter=America, dc.region.name=Northeast") labels, err := data.LabelsFromString("/cluster/name/=Cluster/, @cluster@name@=Cluster@, cluster-name=Cluster, datacenter=America, dc.region.name=Northeast")
require.Nil(t, err) require.Nil(t, err)
newField := data.NewField("Value", labels, []*float64{ newField := data.NewField("Value", labels, []*float64{
toPtr(222.0), util.ToPtr(222.0),
}) })
newField.Config = &data.FieldConfig{DisplayNameFromDS: "series alias"} newField.Config = &data.FieldConfig{DisplayNameFromDS: "series alias"}
testFrame := data.NewFrame("series alias", testFrame := data.NewFrame("series alias",
@ -150,7 +149,7 @@ func TestInfluxdbResponseParser(t *testing.T) {
name = "alias sum" name = "alias sum"
testFrameWithoutMeta.Name = name testFrameWithoutMeta.Name = name
newField = data.NewField("Value", labels, []*float64{ newField = data.NewField("Value", labels, []*float64{
toPtr(333.0), util.ToPtr(333.0),
}) })
testFrameWithoutMeta.Fields[1] = newField testFrameWithoutMeta.Fields[1] = newField
testFrameWithoutMeta.Fields[1].Config = &data.FieldConfig{DisplayNameFromDS: name} testFrameWithoutMeta.Fields[1].Config = &data.FieldConfig{DisplayNameFromDS: name}
@ -163,7 +162,7 @@ func TestInfluxdbResponseParser(t *testing.T) {
name = "alias America" name = "alias America"
testFrame.Name = name testFrame.Name = name
newField = data.NewField("Value", labels, []*float64{ newField = data.NewField("Value", labels, []*float64{
toPtr(222.0), util.ToPtr(222.0),
}) })
testFrame.Fields[1] = newField testFrame.Fields[1] = newField
testFrame.Fields[1].Config = &data.FieldConfig{DisplayNameFromDS: name} testFrame.Fields[1].Config = &data.FieldConfig{DisplayNameFromDS: name}
@ -175,7 +174,7 @@ func TestInfluxdbResponseParser(t *testing.T) {
name = "alias America/America" name = "alias America/America"
testFrame.Name = name testFrame.Name = name
newField = data.NewField("Value", labels, []*float64{ newField = data.NewField("Value", labels, []*float64{
toPtr(222.0), util.ToPtr(222.0),
}) })
testFrame.Fields[1] = newField testFrame.Fields[1] = newField
testFrame.Fields[1].Config = &data.FieldConfig{DisplayNameFromDS: name} testFrame.Fields[1].Config = &data.FieldConfig{DisplayNameFromDS: name}
@ -340,7 +339,7 @@ func TestInfluxdbResponseParser(t *testing.T) {
t.Run("Influxdb response parser with invalid timestamp-format", func(t *testing.T) { t.Run("Influxdb response parser with invalid timestamp-format", func(t *testing.T) {
newField := data.NewField("Value", nil, []*float64{ newField := data.NewField("Value", nil, []*float64{
toPtr(50.0), toPtr(52.0), util.ToPtr(50.0), util.ToPtr(52.0),
}) })
newField.Config = &data.FieldConfig{DisplayNameFromDS: "cpu.mean"} newField.Config = &data.FieldConfig{DisplayNameFromDS: "cpu.mean"}
testFrame := data.NewFrame("cpu.mean", testFrame := data.NewFrame("cpu.mean",
@ -373,7 +372,3 @@ func TestInfluxdbResponseParser(t *testing.T) {
require.Error(t, err) require.Error(t, err)
}) })
} }
func toPtr[T any](v T) *T {
return &v
}

View File

@ -1,29 +0,0 @@
{
"results": [
{
"statement_id": 0,
"series": [
{
"name": "measurements",
"columns": [
"name"
],
"values": [
[
"cpu"
],
[
"disk"
],
[
"diskio"
],
[
"kernel"
]
]
}
]
}
]
}

View File

@ -1,66 +0,0 @@
// 🌟 This was machine generated. Do not edit. 🌟
//
// Frame[0] {
// "typeVersion": [
// 0,
// 0
// ],
// "preferredVisualisationType": "table",
// "executedQueryString": "Test raw query"
// }
// Name: measurements
// Dimensions: 1 Fields by 4 Rows
// +-----------------+
// | Name: name |
// | Labels: |
// | Type: []*string |
// +-----------------+
// | cpu |
// | disk |
// | diskio |
// | kernel |
// +-----------------+
//
//
// 🌟 This was machine generated. Do not edit. 🌟
{
"status": 200,
"frames": [
{
"schema": {
"name": "measurements",
"meta": {
"typeVersion": [
0,
0
],
"preferredVisualisationType": "table",
"executedQueryString": "Test raw query"
},
"fields": [
{
"name": "name",
"type": "string",
"typeInfo": {
"frame": "string",
"nullable": true
},
"config": {
"displayNameFromDS": "name"
}
}
]
},
"data": {
"values": [
[
"cpu",
"disk",
"diskio",
"kernel"
]
]
}
}
]
}

View File

@ -1,47 +0,0 @@
// 🌟 This was machine generated. Do not edit. 🌟
//
// Frame[0]
// Name: measurements
// Dimensions: 1 Fields by 4 Rows
// +----------------+
// | Name: Value |
// | Labels: |
// | Type: []string |
// +----------------+
// | cpu |
// | disk |
// | diskio |
// | kernel |
// +----------------+
//
//
// 🌟 This was machine generated. Do not edit. 🌟
{
"status": 200,
"frames": [
{
"schema": {
"name": "measurements",
"fields": [
{
"name": "Value",
"type": "string",
"typeInfo": {
"frame": "string"
}
}
]
},
"data": {
"values": [
[
"cpu",
"disk",
"diskio",
"kernel"
]
]
}
}
]
}

View File

@ -1,24 +1,31 @@
// 🌟 This was machine generated. Do not edit. 🌟 // 🌟 This was machine generated. Do not edit. 🌟
// //
// Frame[0] // Frame[0] {
// "typeVersion": [
// 0,
// 0
// ],
// "preferredVisualisationType": "graph",
// "executedQueryString": "Test raw query"
// }
// Name: measurements // Name: measurements
// Dimensions: 1 Fields by 10 Rows // Dimensions: 1 Fields by 10 Rows
// +----------------+ // +-----------------+
// | Name: Value | // | Name: Value |
// | Labels: | // | Labels: |
// | Type: []string | // | Type: []*string |
// +----------------+ // +-----------------+
// | cpu | // | cpu |
// | disk | // | disk |
// | diskio | // | diskio |
// | kernel | // | kernel |
// | logs | // | logs |
// | mem | // | mem |
// | myMeasurement | // | myMeasurement |
// | processes | // | processes |
// | swap | // | swap |
// | system | // | system |
// +----------------+ // +-----------------+
// //
// //
// 🌟 This was machine generated. Do not edit. 🌟 // 🌟 This was machine generated. Do not edit. 🌟
@ -28,12 +35,21 @@
{ {
"schema": { "schema": {
"name": "measurements", "name": "measurements",
"meta": {
"typeVersion": [
0,
0
],
"preferredVisualisationType": "graph",
"executedQueryString": "Test raw query"
},
"fields": [ "fields": [
{ {
"name": "Value", "name": "Value",
"type": "string", "type": "string",
"typeInfo": { "typeInfo": {
"frame": "string" "frame": "string",
"nullable": true
} }
} }
] ]

View File

@ -1,19 +1,26 @@
// 🌟 This was machine generated. Do not edit. 🌟 // 🌟 This was machine generated. Do not edit. 🌟
// //
// Frame[0] // Frame[0] {
// "typeVersion": [
// 0,
// 0
// ],
// "preferredVisualisationType": "graph",
// "executedQueryString": "Test raw query"
// }
// Name: // Name:
// Dimensions: 1 Fields by 5 Rows // Dimensions: 1 Fields by 5 Rows
// +----------------+ // +-----------------+
// | Name: Value | // | Name: Value |
// | Labels: | // | Labels: |
// | Type: []string | // | Type: []*string |
// +----------------+ // +-----------------+
// | default | // | default |
// | autogen | // | autogen |
// | bar | // | bar |
// | 5m_avg | // | 5m_avg |
// | 1m_avg | // | 1m_avg |
// +----------------+ // +-----------------+
// //
// //
// 🌟 This was machine generated. Do not edit. 🌟 // 🌟 This was machine generated. Do not edit. 🌟
@ -22,12 +29,21 @@
"frames": [ "frames": [
{ {
"schema": { "schema": {
"meta": {
"typeVersion": [
0,
0
],
"preferredVisualisationType": "graph",
"executedQueryString": "Test raw query"
},
"fields": [ "fields": [
{ {
"name": "Value", "name": "Value",
"type": "string", "type": "string",
"typeInfo": { "typeInfo": {
"frame": "string" "frame": "string",
"nullable": true
} }
} }
] ]

View File

@ -1,24 +1,31 @@
// 🌟 This was machine generated. Do not edit. 🌟 // 🌟 This was machine generated. Do not edit. 🌟
// //
// Frame[0] // Frame[0] {
// "typeVersion": [
// 0,
// 0
// ],
// "preferredVisualisationType": "graph",
// "executedQueryString": "Test raw query"
// }
// Name: cpu // Name: cpu
// Dimensions: 1 Fields by 11 Rows // Dimensions: 1 Fields by 11 Rows
// +----------------+ // +-----------------+
// | Name: Value | // | Name: Value |
// | Labels: | // | Labels: |
// | Type: []string | // | Type: []*string |
// +----------------+ // +-----------------+
// | cpu | // | cpu |
// | cpu | // | cpu |
// | cpu | // | cpu |
// | cpu | // | cpu |
// | cpu | // | cpu |
// | cpu | // | cpu |
// | cpu | // | cpu |
// | cpu | // | cpu |
// | cpu | // | cpu |
// | ... | // | ... |
// +----------------+ // +-----------------+
// //
// //
// 🌟 This was machine generated. Do not edit. 🌟 // 🌟 This was machine generated. Do not edit. 🌟
@ -28,12 +35,21 @@
{ {
"schema": { "schema": {
"name": "cpu", "name": "cpu",
"meta": {
"typeVersion": [
0,
0
],
"preferredVisualisationType": "graph",
"executedQueryString": "Test raw query"
},
"fields": [ "fields": [
{ {
"name": "Value", "name": "Value",
"type": "string", "type": "string",
"typeInfo": { "typeInfo": {
"frame": "string" "frame": "string",
"nullable": true
} }
} }
] ]

View File

@ -150,3 +150,7 @@ func GetVisType(resFormat string) data.VisType {
return GraphVisType return GraphVisType
} }
} }
func ToPtr[T any](v T) *T {
return &v
}