Elasticsearch: Add error source for DataQuery (#77386)

* WIP

* Refactor, plus update source of error in response_parser

* Adjust test

* Use methods and httpclient from errorsource

* Update pkg/tsdb/elasticsearch/data_query.go

Co-authored-by: Scott Lepper <scott.lepper@gmail.com>

* Return nil error

* Fix test

* Fix integration test

---------

Co-authored-by: Scott Lepper <scott.lepper@gmail.com>
This commit is contained in:
Ivana Huckova
2023-11-06 11:36:39 +01:00
committed by GitHub
co-authored by Scott Lepper
parent f88a0f36ec
commit a1718aafce
8 changed files with 26 additions and 15 deletions
+5 -2
View File
@@ -1428,10 +1428,12 @@ func TestExecuteElasticsearchDataQuery(t *testing.T) {
t.Run("With invalid query should return error", (func(t *testing.T) {
c := newFakeClient()
_, err := executeElasticsearchDataQuery(c, `{
res, err := executeElasticsearchDataQuery(c, `{
"query": "foo",
}`, from, to)
require.Error(t, err)
require.NoError(t, err)
require.Equal(t, res.Responses["A"].ErrorSource, backend.ErrorSourcePlugin)
require.Equal(t, res.Responses["A"].Error.Error(), "invalid character '}' looking for beginning of object key string")
}))
})
}
@@ -1856,6 +1858,7 @@ func executeElasticsearchDataQuery(c es.Client, body string, from, to time.Time)
{
JSON: json.RawMessage(body),
TimeRange: timeRange,
RefID: "A",
},
},
}