From 749f59b3e36cdb4002f20df438d21e32ebdb956f Mon Sep 17 00:00:00 2001 From: Isabella Siu Date: Tue, 12 Nov 2024 08:46:31 -0500 Subject: [PATCH] Elasticsearch: Mark elasticsearch errors as downstream (#96152) Elasticsearch: mark elasticsearch errors as downstream --- pkg/tsdb/elasticsearch/error_handling_test.go | 6 ++++++ pkg/tsdb/elasticsearch/response_parser.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/tsdb/elasticsearch/error_handling_test.go b/pkg/tsdb/elasticsearch/error_handling_test.go index 353c1e2409d..30cc6c0c43c 100644 --- a/pkg/tsdb/elasticsearch/error_handling_test.go +++ b/pkg/tsdb/elasticsearch/error_handling_test.go @@ -1,8 +1,10 @@ package elasticsearch import ( + "errors" "testing" + "github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource" "github.com/stretchr/testify/require" ) @@ -117,6 +119,10 @@ func TestErrorTooManyDateHistogramBuckets(t *testing.T) { require.True(t, ok) require.Len(t, dataResponse.Frames, 0) require.ErrorContains(t, dataResponse.Error, "Trying to create too many buckets. Must be less than or equal to: [65536].") + var sourceErr errorsource.Error + ok = errors.As(dataResponse.Error, &sourceErr) + require.True(t, ok) + require.Equal(t, sourceErr.ErrorSource().String(), "downstream") } func TestNonElasticError(t *testing.T) { diff --git a/pkg/tsdb/elasticsearch/response_parser.go b/pkg/tsdb/elasticsearch/response_parser.go index ef9d15025cd..158a0fca03b 100644 --- a/pkg/tsdb/elasticsearch/response_parser.go +++ b/pkg/tsdb/elasticsearch/response_parser.go @@ -75,7 +75,7 @@ func parseResponse(ctx context.Context, responses []*es.SearchResponse, targets resSpan.End() logger.Error("Processing error response from Elasticsearch", "error", string(me), "query", string(mt)) errResult := getErrorFromElasticResponse(res) - result.Responses[target.RefID] = errorsource.Response(errorsource.PluginError(errors.New(errResult), false)) + result.Responses[target.RefID] = errorsource.Response(errorsource.DownstreamError(errors.New(errResult), false)) continue }