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
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import { InfluxQuery, InfluxQueryTag } from './types';
|
||||||
|
|
||||||
type LegacyAnnotation = {
|
type LegacyAnnotation = {
|
||||||
query?: string;
|
query?: string;
|
||||||
queryType?: string;
|
queryType?: string;
|
||||||
@@ -7,11 +9,19 @@ type LegacyAnnotation = {
|
|||||||
timeEndColumn?: string;
|
timeEndColumn?: string;
|
||||||
titleColumn?: string;
|
titleColumn?: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
|
target?: {
|
||||||
|
limit?: string | number | undefined;
|
||||||
|
matchAny?: boolean;
|
||||||
|
tags?: InfluxQueryTag[];
|
||||||
|
type?: string;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// this becomes the target in the migrated annotations
|
// this becomes the target in the migrated annotations
|
||||||
const migrateLegacyAnnotation = (json: LegacyAnnotation) => {
|
const migrateLegacyAnnotation = (json: LegacyAnnotation) => {
|
||||||
return {
|
// eslint-ignore-next-line
|
||||||
|
const target: InfluxQuery = {
|
||||||
|
refId: '',
|
||||||
query: json.query ?? '',
|
query: json.query ?? '',
|
||||||
queryType: 'tags',
|
queryType: 'tags',
|
||||||
fromAnnotations: true,
|
fromAnnotations: true,
|
||||||
@@ -21,11 +31,31 @@ const migrateLegacyAnnotation = (json: LegacyAnnotation) => {
|
|||||||
titleColumn: json.titleColumn ?? '',
|
titleColumn: json.titleColumn ?? '',
|
||||||
name: json.name ?? '',
|
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
|
// eslint-ignore-next-line
|
||||||
export const prepareAnnotation = (json: any) => {
|
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;
|
return json;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ export default class ResponseParser {
|
|||||||
function colContainsTag(colText: string, tagsColumn: string): boolean {
|
function colContainsTag(colText: string, tagsColumn: string): boolean {
|
||||||
const tags = (tagsColumn || '').replace(' ', '').split(',');
|
const tags = (tagsColumn || '').replace(' ', '').split(',');
|
||||||
for (const tag of tags) {
|
for (const tag of tags) {
|
||||||
if (colText.includes(tag)) {
|
if (tag !== '' && colText.includes(tag)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,9 @@ export interface InfluxQuery extends DataQuery {
|
|||||||
timeEndColumn?: string;
|
timeEndColumn?: string;
|
||||||
titleColumn?: string;
|
titleColumn?: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
|
matchAny?: boolean;
|
||||||
|
type?: string;
|
||||||
|
|
||||||
textEditor?: boolean;
|
textEditor?: boolean;
|
||||||
adhocFilters?: AdHocVariableFilter[];
|
adhocFilters?: AdHocVariableFilter[];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user