From dff50220218fbad1c00c8d43891df6146ff8aeb4 Mon Sep 17 00:00:00 2001 From: ismail simsek Date: Thu, 30 Nov 2023 14:25:15 +0100 Subject: [PATCH] Chore: Return executedString information even with frames has no time column (#78906) * return executedString for no time column responses * remove comment --- pkg/tsdb/influxdb/influxql/response_parser.go | 13 ++-- .../influxdb/influxql/response_parser_test.go | 15 ++--- .../influxql/testdata/measurements.json | 29 -------- .../testdata/measurements.table.golden.jsonc | 66 ------------------- .../measurements.time_series.golden.jsonc | 47 ------------- ...tric_find_queries.time_series.golden.jsonc | 52 ++++++++++----- .../retention_policy.time_series.golden.jsonc | 42 ++++++++---- ...g_values_response.time_series.golden.jsonc | 52 ++++++++++----- pkg/tsdb/influxdb/influxql/util/util.go | 4 ++ 9 files changed, 115 insertions(+), 205 deletions(-) delete mode 100644 pkg/tsdb/influxdb/influxql/testdata/measurements.json delete mode 100644 pkg/tsdb/influxdb/influxql/testdata/measurements.table.golden.jsonc delete mode 100644 pkg/tsdb/influxdb/influxql/testdata/measurements.time_series.golden.jsonc diff --git a/pkg/tsdb/influxdb/influxql/response_parser.go b/pkg/tsdb/influxdb/influxql/response_parser.go index 79dcfd81c9a..b4ee368f1f7 100644 --- a/pkg/tsdb/influxdb/influxql/response_parser.go +++ b/pkg/tsdb/influxdb/influxql/response_parser.go @@ -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 { - var values []string + var values []*string for _, valuePair := range row.Values { if strings.Contains(strings.ToLower(query.RawQuery), strings.ToLower("SHOW TAG VALUES")) { if len(valuePair) >= 2 { - values = append(values, valuePair[1].(string)) + values = append(values, util.ToPtr(valuePair[1].(string))) } } else { if len(valuePair) >= 1 { - values = append(values, valuePair[0].(string)) + values = append(values, util.ToPtr(valuePair[0].(string))) } } } 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 } diff --git a/pkg/tsdb/influxdb/influxql/response_parser_test.go b/pkg/tsdb/influxdb/influxql/response_parser_test.go index a3925a34119..787e801251c 100644 --- a/pkg/tsdb/influxdb/influxql/response_parser_test.go +++ b/pkg/tsdb/influxdb/influxql/response_parser_test.go @@ -54,7 +54,6 @@ var testFiles = []string{ "show_tag_values_response", "retention_policy", "simple_response_with_diverse_data_types", - "measurements", "multiple_measurements", // "many_columns", skipped for now "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") require.Nil(t, err) newField := data.NewField("Value", labels, []*float64{ - toPtr(222.0), + util.ToPtr(222.0), }) newField.Config = &data.FieldConfig{DisplayNameFromDS: "series alias"} testFrame := data.NewFrame("series alias", @@ -150,7 +149,7 @@ func TestInfluxdbResponseParser(t *testing.T) { name = "alias sum" testFrameWithoutMeta.Name = name newField = data.NewField("Value", labels, []*float64{ - toPtr(333.0), + util.ToPtr(333.0), }) testFrameWithoutMeta.Fields[1] = newField testFrameWithoutMeta.Fields[1].Config = &data.FieldConfig{DisplayNameFromDS: name} @@ -163,7 +162,7 @@ func TestInfluxdbResponseParser(t *testing.T) { name = "alias America" testFrame.Name = name newField = data.NewField("Value", labels, []*float64{ - toPtr(222.0), + util.ToPtr(222.0), }) testFrame.Fields[1] = newField testFrame.Fields[1].Config = &data.FieldConfig{DisplayNameFromDS: name} @@ -175,7 +174,7 @@ func TestInfluxdbResponseParser(t *testing.T) { name = "alias America/America" testFrame.Name = name newField = data.NewField("Value", labels, []*float64{ - toPtr(222.0), + util.ToPtr(222.0), }) testFrame.Fields[1] = newField 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) { 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"} testFrame := data.NewFrame("cpu.mean", @@ -373,7 +372,3 @@ func TestInfluxdbResponseParser(t *testing.T) { require.Error(t, err) }) } - -func toPtr[T any](v T) *T { - return &v -} diff --git a/pkg/tsdb/influxdb/influxql/testdata/measurements.json b/pkg/tsdb/influxdb/influxql/testdata/measurements.json deleted file mode 100644 index ee19b875f3a..00000000000 --- a/pkg/tsdb/influxdb/influxql/testdata/measurements.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "results": [ - { - "statement_id": 0, - "series": [ - { - "name": "measurements", - "columns": [ - "name" - ], - "values": [ - [ - "cpu" - ], - [ - "disk" - ], - [ - "diskio" - ], - [ - "kernel" - ] - ] - } - ] - } - ] -} diff --git a/pkg/tsdb/influxdb/influxql/testdata/measurements.table.golden.jsonc b/pkg/tsdb/influxdb/influxql/testdata/measurements.table.golden.jsonc deleted file mode 100644 index 00e659ac831..00000000000 --- a/pkg/tsdb/influxdb/influxql/testdata/measurements.table.golden.jsonc +++ /dev/null @@ -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" - ] - ] - } - } - ] -} \ No newline at end of file diff --git a/pkg/tsdb/influxdb/influxql/testdata/measurements.time_series.golden.jsonc b/pkg/tsdb/influxdb/influxql/testdata/measurements.time_series.golden.jsonc deleted file mode 100644 index 376432c628c..00000000000 --- a/pkg/tsdb/influxdb/influxql/testdata/measurements.time_series.golden.jsonc +++ /dev/null @@ -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" - ] - ] - } - } - ] -} \ No newline at end of file diff --git a/pkg/tsdb/influxdb/influxql/testdata/metric_find_queries.time_series.golden.jsonc b/pkg/tsdb/influxdb/influxql/testdata/metric_find_queries.time_series.golden.jsonc index cdf10bda7f2..100f21e55f3 100644 --- a/pkg/tsdb/influxdb/influxql/testdata/metric_find_queries.time_series.golden.jsonc +++ b/pkg/tsdb/influxdb/influxql/testdata/metric_find_queries.time_series.golden.jsonc @@ -1,24 +1,31 @@ // 🌟 This was machine generated. Do not edit. 🌟 // -// Frame[0] +// Frame[0] { +// "typeVersion": [ +// 0, +// 0 +// ], +// "preferredVisualisationType": "graph", +// "executedQueryString": "Test raw query" +// } // Name: measurements // Dimensions: 1 Fields by 10 Rows -// +----------------+ -// | Name: Value | -// | Labels: | -// | Type: []string | -// +----------------+ -// | cpu | -// | disk | -// | diskio | -// | kernel | -// | logs | -// | mem | -// | myMeasurement | -// | processes | -// | swap | -// | system | -// +----------------+ +// +-----------------+ +// | Name: Value | +// | Labels: | +// | Type: []*string | +// +-----------------+ +// | cpu | +// | disk | +// | diskio | +// | kernel | +// | logs | +// | mem | +// | myMeasurement | +// | processes | +// | swap | +// | system | +// +-----------------+ // // // 🌟 This was machine generated. Do not edit. 🌟 @@ -28,12 +35,21 @@ { "schema": { "name": "measurements", + "meta": { + "typeVersion": [ + 0, + 0 + ], + "preferredVisualisationType": "graph", + "executedQueryString": "Test raw query" + }, "fields": [ { "name": "Value", "type": "string", "typeInfo": { - "frame": "string" + "frame": "string", + "nullable": true } } ] diff --git a/pkg/tsdb/influxdb/influxql/testdata/retention_policy.time_series.golden.jsonc b/pkg/tsdb/influxdb/influxql/testdata/retention_policy.time_series.golden.jsonc index c32cb95c2e8..f41fcbc2ba0 100644 --- a/pkg/tsdb/influxdb/influxql/testdata/retention_policy.time_series.golden.jsonc +++ b/pkg/tsdb/influxdb/influxql/testdata/retention_policy.time_series.golden.jsonc @@ -1,19 +1,26 @@ // 🌟 This was machine generated. Do not edit. 🌟 // -// Frame[0] +// Frame[0] { +// "typeVersion": [ +// 0, +// 0 +// ], +// "preferredVisualisationType": "graph", +// "executedQueryString": "Test raw query" +// } // Name: // Dimensions: 1 Fields by 5 Rows -// +----------------+ -// | Name: Value | -// | Labels: | -// | Type: []string | -// +----------------+ -// | default | -// | autogen | -// | bar | -// | 5m_avg | -// | 1m_avg | -// +----------------+ +// +-----------------+ +// | Name: Value | +// | Labels: | +// | Type: []*string | +// +-----------------+ +// | default | +// | autogen | +// | bar | +// | 5m_avg | +// | 1m_avg | +// +-----------------+ // // // 🌟 This was machine generated. Do not edit. 🌟 @@ -22,12 +29,21 @@ "frames": [ { "schema": { + "meta": { + "typeVersion": [ + 0, + 0 + ], + "preferredVisualisationType": "graph", + "executedQueryString": "Test raw query" + }, "fields": [ { "name": "Value", "type": "string", "typeInfo": { - "frame": "string" + "frame": "string", + "nullable": true } } ] diff --git a/pkg/tsdb/influxdb/influxql/testdata/show_tag_values_response.time_series.golden.jsonc b/pkg/tsdb/influxdb/influxql/testdata/show_tag_values_response.time_series.golden.jsonc index bdf9fcee2c0..8703367b352 100644 --- a/pkg/tsdb/influxdb/influxql/testdata/show_tag_values_response.time_series.golden.jsonc +++ b/pkg/tsdb/influxdb/influxql/testdata/show_tag_values_response.time_series.golden.jsonc @@ -1,24 +1,31 @@ // 🌟 This was machine generated. Do not edit. 🌟 // -// Frame[0] +// Frame[0] { +// "typeVersion": [ +// 0, +// 0 +// ], +// "preferredVisualisationType": "graph", +// "executedQueryString": "Test raw query" +// } // Name: cpu // Dimensions: 1 Fields by 11 Rows -// +----------------+ -// | Name: Value | -// | Labels: | -// | Type: []string | -// +----------------+ -// | cpu | -// | cpu | -// | cpu | -// | cpu | -// | cpu | -// | cpu | -// | cpu | -// | cpu | -// | cpu | -// | ... | -// +----------------+ +// +-----------------+ +// | Name: Value | +// | Labels: | +// | Type: []*string | +// +-----------------+ +// | cpu | +// | cpu | +// | cpu | +// | cpu | +// | cpu | +// | cpu | +// | cpu | +// | cpu | +// | cpu | +// | ... | +// +-----------------+ // // // 🌟 This was machine generated. Do not edit. 🌟 @@ -28,12 +35,21 @@ { "schema": { "name": "cpu", + "meta": { + "typeVersion": [ + 0, + 0 + ], + "preferredVisualisationType": "graph", + "executedQueryString": "Test raw query" + }, "fields": [ { "name": "Value", "type": "string", "typeInfo": { - "frame": "string" + "frame": "string", + "nullable": true } } ] diff --git a/pkg/tsdb/influxdb/influxql/util/util.go b/pkg/tsdb/influxdb/influxql/util/util.go index ede64b21d4b..d7c4b67cc2d 100644 --- a/pkg/tsdb/influxdb/influxql/util/util.go +++ b/pkg/tsdb/influxdb/influxql/util/util.go @@ -150,3 +150,7 @@ func GetVisType(resFormat string) data.VisType { return GraphVisType } } + +func ToPtr[T any](v T) *T { + return &v +}