Преглед на файлове

fix pre gui queries shortcircuit

Sven Klemm преди 7 години
родител
ревизия
84d7743939
променени са 2 файла, в които са добавени 15 реда и са изтрити 2 реда
  1. 13 1
      pkg/tsdb/postgres/postgres.go
  2. 2 1
      public/app/plugins/datasource/postgres/postgres_query.ts

+ 13 - 1
pkg/tsdb/postgres/postgres.go

@@ -170,6 +170,8 @@ func (e PostgresQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *co
 	rowCount := 0
 	timeIndex := -1
 	metricIndex := -1
+	metricPrefix := false
+	metricPrefixValue := ""
 
 	// check columns of resultset: a column named time is mandatory
 	// the first text column is treated as metric name unless a column named metric is present
@@ -179,6 +181,10 @@ func (e PostgresQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *co
 			timeIndex = i
 		case "metric":
 			metricIndex = i
+			// use metric column as prefix with multiple value columns
+			if len(columnNames) > 3 {
+				metricPrefix = true
+			}
 		default:
 			if metricIndex == -1 {
 				switch columnTypes[i].DatabaseTypeName() {
@@ -234,7 +240,11 @@ func (e PostgresQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *co
 
 		if metricIndex >= 0 {
 			if columnValue, ok := values[metricIndex].(string); ok {
-				metric = columnValue
+				if metricPrefix {
+					metricPrefixValue = columnValue
+				} else {
+					metric = columnValue
+				}
 			} else {
 				return fmt.Errorf("Column metric must be of type char,varchar or text, got: %T %v", values[metricIndex], values[metricIndex])
 			}
@@ -251,6 +261,8 @@ func (e PostgresQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *co
 
 			if metricIndex == -1 {
 				metric = col
+			} else if metricPrefix {
+				metric = metricPrefixValue + " " + col
 			}
 
 			series, exist := pointsBySeries[metric]

+ 2 - 1
public/app/plugins/datasource/postgres/postgres_query.ts

@@ -77,7 +77,8 @@ export default class PostgresQuery {
   render(interpolate?) {
     let target = this.target;
 
-    if (!('table' in this.target)) {
+    // new query with no table set yet
+    if (!this.target.rawQuery && !('table' in this.target)) {
       return '';
     }