From a87c155c06bf3f92d711342131f68f3086b3f9d0 Mon Sep 17 00:00:00 2001 From: ismail simsek Date: Wed, 5 Jun 2024 21:36:13 +0200 Subject: [PATCH] Chore: Return influxdb query error early before parsing the result (#88549) return error early --- pkg/tsdb/influxdb/influxql/buffered/response_parser.go | 4 ---- pkg/tsdb/influxdb/influxql/influxql.go | 5 +++++ pkg/tsdb/influxdb/influxql/querydata/stream_parser.go | 4 ---- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/pkg/tsdb/influxdb/influxql/buffered/response_parser.go b/pkg/tsdb/influxdb/influxql/buffered/response_parser.go index 0d456329879..f0ee1d167fe 100644 --- a/pkg/tsdb/influxdb/influxql/buffered/response_parser.go +++ b/pkg/tsdb/influxdb/influxql/buffered/response_parser.go @@ -23,10 +23,6 @@ func ResponseParse(buf io.ReadCloser, statusCode int, query *models.Query) *back func parse(buf io.Reader, statusCode int, query *models.Query) *backend.DataResponse { response, jsonErr := parseJSON(buf) - if statusCode/100 != 2 { - return &backend.DataResponse{Error: fmt.Errorf("InfluxDB returned error: %s", response.Error)} - } - if jsonErr != nil { return &backend.DataResponse{Error: jsonErr} } diff --git a/pkg/tsdb/influxdb/influxql/influxql.go b/pkg/tsdb/influxdb/influxql/influxql.go index ada4a2eade3..5bba117aa78 100644 --- a/pkg/tsdb/influxdb/influxql/influxql.go +++ b/pkg/tsdb/influxdb/influxql/influxql.go @@ -174,6 +174,11 @@ func execute(ctx context.Context, tracer trace.Tracer, dsInfo *models.Datasource if err != nil { return backend.DataResponse{}, err } + + if res.StatusCode/100 != 2 { + return backend.DataResponse{Error: fmt.Errorf("InfluxDB returned error: %v", res.Body)}, nil + } + defer func() { if err := res.Body.Close(); err != nil { logger.Warn("Failed to close response body", "err", err) diff --git a/pkg/tsdb/influxdb/influxql/querydata/stream_parser.go b/pkg/tsdb/influxdb/influxql/querydata/stream_parser.go index dde413c8fa4..2efded14ed9 100644 --- a/pkg/tsdb/influxdb/influxql/querydata/stream_parser.go +++ b/pkg/tsdb/influxdb/influxql/querydata/stream_parser.go @@ -23,10 +23,6 @@ func ResponseParse(buf io.ReadCloser, statusCode int, query *models.Query) *back 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)} - } - // The ExecutedQueryString can be viewed in QueryInspector in UI for i, frame := range r.Frames { if i == 0 {