mirror of https://github.com/grafana/grafana.git
				
				
				
			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:
		
							parent
							
								
									7cbf5ae78d
								
							
						
					
					
						commit
						dff5022021
					
				|  | @ -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 | ||||
| } | ||||
|  |  | |||
|  | @ -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 | ||||
| } | ||||
|  |  | |||
|  | @ -1,29 +0,0 @@ | |||
| { | ||||
|   "results": [ | ||||
|     { | ||||
|       "statement_id": 0, | ||||
|       "series": [ | ||||
|         { | ||||
|           "name": "measurements", | ||||
|           "columns": [ | ||||
|             "name" | ||||
|           ], | ||||
|           "values": [ | ||||
|             [ | ||||
|               "cpu" | ||||
|             ], | ||||
|             [ | ||||
|               "disk" | ||||
|             ], | ||||
|             [ | ||||
|               "diskio" | ||||
|             ], | ||||
|             [ | ||||
|               "kernel" | ||||
|             ] | ||||
|           ] | ||||
|         } | ||||
|       ] | ||||
|     } | ||||
|   ] | ||||
| } | ||||
|  | @ -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" | ||||
|           ] | ||||
|         ] | ||||
|       } | ||||
|     } | ||||
|   ] | ||||
| } | ||||
|  | @ -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" | ||||
|           ] | ||||
|         ] | ||||
|       } | ||||
|     } | ||||
|   ] | ||||
| } | ||||
|  | @ -1,13 +1,20 @@ | |||
| //  🌟 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 | | ||||
| //  +----------------+ | ||||
| //  | Type: []*string | | ||||
| //  +-----------------+ | ||||
| //  | cpu             | | ||||
| //  | disk            | | ||||
| //  | diskio          | | ||||
|  | @ -18,7 +25,7 @@ | |||
| //  | 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 | ||||
|             } | ||||
|           } | ||||
|         ] | ||||
|  |  | |||
|  | @ -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 | | ||||
| //  +----------------+ | ||||
| //  | 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 | ||||
|             } | ||||
|           } | ||||
|         ] | ||||
|  |  | |||
|  | @ -1,13 +1,20 @@ | |||
| //  🌟 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 | | ||||
| //  +----------------+ | ||||
| //  | Type: []*string | | ||||
| //  +-----------------+ | ||||
| //  | cpu             | | ||||
| //  | cpu             | | ||||
| //  | cpu             | | ||||
|  | @ -18,7 +25,7 @@ | |||
| //  | 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 | ||||
|             } | ||||
|           } | ||||
|         ] | ||||
|  |  | |||
|  | @ -150,3 +150,7 @@ func GetVisType(resFormat string) data.VisType { | |||
| 		return GraphVisType | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func ToPtr[T any](v T) *T { | ||||
| 	return &v | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue