|
@@ -2,6 +2,7 @@ package prometheus
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"context"
|
|
"context"
|
|
|
|
|
+ "fmt"
|
|
|
"net/http"
|
|
"net/http"
|
|
|
"regexp"
|
|
"regexp"
|
|
|
"strings"
|
|
"strings"
|
|
@@ -69,7 +70,11 @@ func (e *PrometheusExecutor) Execute(queries tsdb.QuerySlice, queryContext *tsdb
|
|
|
return resultWithError(result, err)
|
|
return resultWithError(result, err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- result.QueryResults = parseResponse(value, query)
|
|
|
|
|
|
|
+ queryResult, err := parseResponse(value, query)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return resultWithError(result, err)
|
|
|
|
|
+ }
|
|
|
|
|
+ result.QueryResults = queryResult
|
|
|
return result
|
|
return result
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -125,18 +130,21 @@ func parseQuery(queries tsdb.QuerySlice, queryContext *tsdb.QueryContext) (*Prom
|
|
|
}, nil
|
|
}, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func parseResponse(value pmodel.Value, query *PrometheusQuery) map[string]*tsdb.QueryResult {
|
|
|
|
|
|
|
+func parseResponse(value pmodel.Value, query *PrometheusQuery) (map[string]*tsdb.QueryResult, error) {
|
|
|
queryResults := make(map[string]*tsdb.QueryResult)
|
|
queryResults := make(map[string]*tsdb.QueryResult)
|
|
|
queryRes := &tsdb.QueryResult{}
|
|
queryRes := &tsdb.QueryResult{}
|
|
|
|
|
|
|
|
- data := value.(pmodel.Matrix)
|
|
|
|
|
|
|
+ data, ok := value.(pmodel.Matrix)
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ return queryResults, fmt.Errorf("Unsupported result format: %s", value.Type().String())
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
for _, v := range data {
|
|
for _, v := range data {
|
|
|
var points [][2]*float64
|
|
var points [][2]*float64
|
|
|
for _, k := range v.Values {
|
|
for _, k := range v.Values {
|
|
|
- dummie := float64(k.Timestamp)
|
|
|
|
|
- d2 := float64(k.Value)
|
|
|
|
|
- points = append(points, [2]*float64{&d2, &dummie})
|
|
|
|
|
|
|
+ timestamp := float64(k.Timestamp)
|
|
|
|
|
+ val := float64(k.Value)
|
|
|
|
|
+ points = append(points, [2]*float64{&val, ×tamp})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
queryRes.Series = append(queryRes.Series, &tsdb.TimeSeries{
|
|
queryRes.Series = append(queryRes.Series, &tsdb.TimeSeries{
|
|
@@ -146,7 +154,7 @@ func parseResponse(value pmodel.Value, query *PrometheusQuery) map[string]*tsdb.
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
queryResults["A"] = queryRes
|
|
queryResults["A"] = queryRes
|
|
|
- return queryResults
|
|
|
|
|
|
|
+ return queryResults, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func resultWithError(result *tsdb.BatchResult, err error) *tsdb.BatchResult {
|
|
func resultWithError(result *tsdb.BatchResult, err error) *tsdb.BatchResult {
|