Commit 9ccdd4b8 by zhulongcheng Committed by GitHub

TSDB: show influxdb error message (#24393)

Closes #21647

Signed-off-by: zhulongcheng <zhulongcheng.dev@gmail.com>
parent cc6df0ac
......@@ -26,6 +26,9 @@ func (rp *ResponseParser) Parse(response *Response, query *Query) *tsdb.QueryRes
for _, result := range response.Results {
queryRes.Series = append(queryRes.Series, rp.transformRows(result.Series, queryRes, query)...)
if result.Err != nil {
queryRes.Error = result.Err
}
}
return queryRes
......
......@@ -2,6 +2,7 @@ package influxdb
import (
"encoding/json"
"fmt"
"testing"
"github.com/grafana/grafana/pkg/setting"
......@@ -172,5 +173,55 @@ func TestInfluxdbResponseParser(t *testing.T) {
})
})
})
Convey("Response parser with errors", func() {
parser := &ResponseParser{}
cfg := setting.NewCfg()
err := cfg.Load(&setting.CommandLineArgs{
HomePath: "../../../",
})
So(err, ShouldBeNil)
response := &Response{
Results: []Result{
{
Series: []Row{
{
Name: "cpu",
Columns: []string{"time", "mean", "sum"},
Tags: map[string]string{"datacenter": "America"},
Values: [][]interface{}{
{json.Number("111"), json.Number("222"), json.Number("333")},
{json.Number("111"), json.Number("222"), json.Number("333")},
{json.Number("111"), json.Number("null"), json.Number("333")},
},
},
},
},
{
Err: fmt.Errorf("query-timeout limit exceeded"),
},
},
}
query := &Query{}
result := parser.Parse(response, query)
Convey("can parse all series", func() {
So(len(result.Series), ShouldEqual, 2)
})
Convey("can parse all points", func() {
So(len(result.Series[0].Points), ShouldEqual, 3)
So(len(result.Series[1].Points), ShouldEqual, 3)
})
Convey("can parse errors ", func() {
So(result.Error, ShouldNotBeNil)
So(result.Error.Error(), ShouldEqual, "query-timeout limit exceeded")
})
})
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment