From 45660c94af9d869f01c026c6dfb396ef930352e6 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Fri, 28 Apr 2023 08:54:02 -0400 Subject: [PATCH] [v9.3.x] Influxdb: Handle legacy Influxdb influxql annotations with target in migration (#67502) Influxdb: Handle legacy Influxdb influxql annotations with target in migration (#63225) * handle legacy influxdb annotations with target in migration * add types * don't check tags that are empty strings and give annotation a type (cherry picked from commit 7a3f7e26cefb2a85c8762ff24960eeb69cf33236) Co-authored-by: Brendan O'Handley --- .../plugins/datasource/influxdb/migrations.ts | 34 +++++++++++++++++-- .../datasource/influxdb/response_parser.ts | 2 +- .../app/plugins/datasource/influxdb/types.ts | 3 ++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/public/app/plugins/datasource/influxdb/migrations.ts b/public/app/plugins/datasource/influxdb/migrations.ts index ad53c824d3b..e0ebecf0169 100644 --- a/public/app/plugins/datasource/influxdb/migrations.ts +++ b/public/app/plugins/datasource/influxdb/migrations.ts @@ -1,3 +1,5 @@ +import { InfluxQuery, InfluxQueryTag } from './types'; + type LegacyAnnotation = { query?: string; queryType?: string; @@ -7,11 +9,19 @@ type LegacyAnnotation = { timeEndColumn?: string; titleColumn?: string; name?: string; + target?: { + limit?: string | number | undefined; + matchAny?: boolean; + tags?: InfluxQueryTag[]; + type?: string; + }; }; // this becomes the target in the migrated annotations const migrateLegacyAnnotation = (json: LegacyAnnotation) => { - return { + // eslint-ignore-next-line + const target: InfluxQuery = { + refId: '', query: json.query ?? '', queryType: 'tags', fromAnnotations: true, @@ -21,11 +31,31 @@ const migrateLegacyAnnotation = (json: LegacyAnnotation) => { titleColumn: json.titleColumn ?? '', name: json.name ?? '', }; + + // handle json target fields + if (json.target && json.target.limit) { + target.limit = json.target.limit; + } + + if (json.target && json.target.matchAny) { + target.matchAny = json.target.matchAny; + } + + if (json.target && json.target.tags) { + target.tags = json.target.tags; + } + + if (json.target && json.target.type) { + target.type = json.target.type; + } + + return target; }; // eslint-ignore-next-line export const prepareAnnotation = (json: any) => { - json.target = json.target ?? migrateLegacyAnnotation(json); + // make sure that any additional target fields are migrated + json.target = json.target && !json.target?.query ? migrateLegacyAnnotation(json) : json.target; return json; }; diff --git a/public/app/plugins/datasource/influxdb/response_parser.ts b/public/app/plugins/datasource/influxdb/response_parser.ts index a156e98be56..4dc1c2b6326 100644 --- a/public/app/plugins/datasource/influxdb/response_parser.ts +++ b/public/app/plugins/datasource/influxdb/response_parser.ts @@ -158,7 +158,7 @@ export default class ResponseParser { function colContainsTag(colText: string, tagsColumn: string): boolean { const tags = (tagsColumn || '').replace(' ', '').split(','); for (const tag of tags) { - if (colText.includes(tag)) { + if (tag !== '' && colText.includes(tag)) { return true; } } diff --git a/public/app/plugins/datasource/influxdb/types.ts b/public/app/plugins/datasource/influxdb/types.ts index 90fd819216e..f1bf13e2f1a 100644 --- a/public/app/plugins/datasource/influxdb/types.ts +++ b/public/app/plugins/datasource/influxdb/types.ts @@ -69,6 +69,9 @@ export interface InfluxQuery extends DataQuery { timeEndColumn?: string; titleColumn?: string; name?: string; + matchAny?: boolean; + type?: string; + textEditor?: boolean; adhocFilters?: AdHocVariableFilter[]; }