Files
beejeebus cfae9d20d2 Add errorsource to InfluxDB datasource plugin fixes #1072 (#99900)
This PR adds `backend.ErrorSourceDownstream` values to all `backend.DataResponse`
values where it's certain that the error wasn't the result of the
InfluxDB datasource plugin.
2025-02-04 09:33:32 -05:00

42 lines
1.1 KiB
Go

package querydata
import (
"fmt"
"io"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/data"
jsoniter "github.com/json-iterator/go"
"github.com/grafana/grafana/pkg/tsdb/influxdb/influxql/converter"
"github.com/grafana/grafana/pkg/tsdb/influxdb/influxql/util"
"github.com/grafana/grafana/pkg/tsdb/influxdb/models"
)
func ResponseParse(buf io.ReadCloser, statusCode int, query *models.Query) *backend.DataResponse {
defer func() {
if err := buf.Close(); err != nil {
fmt.Println("Failed to close response body", "err", err)
}
}()
iter := jsoniter.Parse(jsoniter.ConfigDefault, buf, 1024)
r := converter.ReadInfluxQLStyleResult(iter, query)
if statusCode/100 != 2 {
return &backend.DataResponse{
Error: fmt.Errorf("InfluxDB returned error: %s", r.Error),
ErrorSource: backend.ErrorSourceFromHTTPStatus(statusCode),
}
}
// The ExecutedQueryString can be viewed in QueryInspector in UI
for i, frame := range r.Frames {
if i == 0 {
frame.Meta = &data.FrameMeta{ExecutedQueryString: query.RawQuery, PreferredVisualization: util.GetVisType(query.ResultFormat)}
}
}
return r
}