From 71ebf83dd00d2246b0823c5026db56697dbcbd1a Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Thu, 20 Apr 2023 11:02:58 +0100 Subject: [PATCH] [v9.5.x] Elasticsearch: Handle multiple annotation structures (#66924) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Elasticsearch: Handle multiple annotation structures (#66762) elastic: fix annotation handling (cherry picked from commit 82ac2bae5faa6de5d9f69b51825526ee20be7716) Co-authored-by: Gábor Farkas --- .../components/QueryEditor/AnnotationQueryEditor.tsx | 8 +++++++- .../plugins/datasource/elasticsearch/datasource.ts | 12 +++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/AnnotationQueryEditor.tsx b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/AnnotationQueryEditor.tsx index 60d12b10cf4..413decf565e 100644 --- a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/AnnotationQueryEditor.tsx +++ b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/AnnotationQueryEditor.tsx @@ -23,9 +23,15 @@ export function ElasticsearchAnnotationsQueryEditor(props: Props) { { + const currentTarget = annotation.target ?? { refId: 'annotation_query' }; + const newTarget = { + ...currentTarget, + query, + }; + onAnnotationChange({ ...annotation, - query, + target: newTarget, }); }} /> diff --git a/public/app/plugins/datasource/elasticsearch/datasource.ts b/public/app/plugins/datasource/elasticsearch/datasource.ts index 7743e324c1e..224681f2bbf 100644 --- a/public/app/plugins/datasource/elasticsearch/datasource.ts +++ b/public/app/plugins/datasource/elasticsearch/datasource.ts @@ -243,7 +243,17 @@ export class ElasticDatasource const annotation = options.annotation; const timeField = annotation.timeField || '@timestamp'; const timeEndField = annotation.timeEndField || null; - const queryString = annotation.query; + + // the `target.query` is the "new" location for the query. + // normally we would write this code as + // try-the-new-place-then-try-the-old-place, + // but we had the bug at + // https://github.com/grafana/grafana/issues/61107 + // that may have stored annotations where + // both the old and the new place are set, + // and in that scenario the old place needs + // to have priority. + const queryString = annotation.query ?? annotation.target?.query; const tagsField = annotation.tagsField || 'tags'; const textField = annotation.textField || null;