[v9.5.x] Elasticsearch: Handle multiple annotation structures (#66924)

Elasticsearch: Handle multiple annotation structures (#66762)

elastic: fix annotation handling
(cherry picked from commit 82ac2bae5f)

Co-authored-by: Gábor Farkas <gabor.farkas@gmail.com>
This commit is contained in:
Grot (@grafanabot)
2023-04-20 10:02:58 +00:00
committed by GitHub
co-authored by Gábor Farkas
parent 581cbe4295
commit 71ebf83dd0
2 changed files with 18 additions and 2 deletions
@@ -23,9 +23,15 @@ export function ElasticsearchAnnotationsQueryEditor(props: Props) {
<ElasticSearchQueryField
value={annotation.target?.query}
onChange={(query) => {
const currentTarget = annotation.target ?? { refId: 'annotation_query' };
const newTarget = {
...currentTarget,
query,
};
onAnnotationChange({
...annotation,
query,
target: newTarget,
});
}}
/>
@@ -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;