mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
loki: better handle an empty-response (#52397)
This commit is contained in:
parent
ba543343c4
commit
46eec85b1a
@ -163,6 +163,14 @@ func (api *LokiAPI) DataQuery(ctx context.Context, query lokiQuery) (data.Frames
|
||||
iter := jsoniter.Parse(jsoniter.ConfigDefault, resp.Body, 1024)
|
||||
res := converter.ReadPrometheusStyleResult(iter, converter.Options{MatrixWideSeries: false, VectorWideSeries: false})
|
||||
|
||||
if res == nil {
|
||||
// it's hard to say if this is an error-case or not.
|
||||
// we know the http-response was a success-response
|
||||
// (otherwise we wouldn't be here in the code),
|
||||
// so we will go with a success, with no data.
|
||||
return data.Frames{}, nil
|
||||
}
|
||||
|
||||
if res.Error != nil {
|
||||
return nil, res.Error
|
||||
}
|
||||
|
@ -48,6 +48,8 @@ func TestSuccessResponse(t *testing.T) {
|
||||
{name: "parse a simple streams response", filepath: "streams_simple", query: streamsQuery},
|
||||
|
||||
{name: "parse a streams response with parse errors", filepath: "streams_parse_errors", query: streamsQuery},
|
||||
|
||||
{name: "parse an empty response", filepath: "empty", query: matrixQuery},
|
||||
}
|
||||
|
||||
for _, test := range tt {
|
||||
|
5
pkg/tsdb/loki/testdata/empty.golden.jsonc
vendored
Normal file
5
pkg/tsdb/loki/testdata/empty.golden.jsonc
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
// 🌟 This was machine generated. Do not edit. 🌟
|
||||
// 🌟 This was machine generated. Do not edit. 🌟
|
||||
{
|
||||
"frames": []
|
||||
}
|
1
pkg/tsdb/loki/testdata/empty.json
vendored
Normal file
1
pkg/tsdb/loki/testdata/empty.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{}
|
Loading…
Reference in New Issue
Block a user