From b44df6c8d1dd7bf2377d31b4db8988eb62ee3f6e Mon Sep 17 00:00:00 2001 From: Ruud van der Weijde Date: Fri, 20 Jan 2023 11:46:31 +0100 Subject: [PATCH] ElasticSearch: Improve ES error handling message (#61471) Look for 'caused_by.reason' in ES error response When the ES response does not contain `reason` or `root_cause[0].reason` is empty, there is no information for the user to know what is going wrong. An example of the error message after this change: ``` Failed to evaluate queries and expressions: failed to execute query A: Trying to create too many buckets. Must be less than or equal to: [65536] but this number of buckets was exceeded. This limit can be set by changing the [search.max_buckets] cluster level setting. ``` Related to https://github.com/grafana/grafana/issues/61246 --- pkg/tsdb/elasticsearch/response_parser.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/tsdb/elasticsearch/response_parser.go b/pkg/tsdb/elasticsearch/response_parser.go index 15d1485d560..50b6adcd822 100644 --- a/pkg/tsdb/elasticsearch/response_parser.go +++ b/pkg/tsdb/elasticsearch/response_parser.go @@ -711,12 +711,15 @@ func getErrorFromElasticResponse(response *es.SearchResponse) string { json := simplejson.NewFromAny(response.Error) reason := json.Get("reason").MustString() rootCauseReason := json.Get("root_cause").GetIndex(0).Get("reason").MustString() + causedByReason := json.Get("caused_by").Get("reason").MustString() switch { case rootCauseReason != "": errorString = rootCauseReason case reason != "": errorString = reason + case causedByReason != "": + errorString = causedByReason default: errorString = "Unknown elasticsearch error response" }