From 08b1b635b7bbc76b606238b0a67f84a965ab8bf6 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Mon, 13 Apr 2020 12:16:44 +0300 Subject: [PATCH] Fix explore mode in Grafana 6.x, closes #888 Migrate target.mode to target.queryType because Explore uses target.mode and overwrites it. --- .../{constants.js => constants.ts} | 0 src/datasource-zabbix/datasource.js | 28 +++++++-------- src/datasource-zabbix/migrations.ts | 35 +++++++++++++------ .../partials/query.editor.html | 34 +++++++++--------- src/datasource-zabbix/query.controller.js | 24 ++++++------- .../specs/datasource.spec.js | 2 +- 6 files changed, 69 insertions(+), 54 deletions(-) rename src/datasource-zabbix/{constants.js => constants.ts} (100%) diff --git a/src/datasource-zabbix/constants.js b/src/datasource-zabbix/constants.ts similarity index 100% rename from src/datasource-zabbix/constants.js rename to src/datasource-zabbix/constants.ts diff --git a/src/datasource-zabbix/datasource.js b/src/datasource-zabbix/datasource.js index 6a9def4..b91437a 100644 --- a/src/datasource-zabbix/datasource.js +++ b/src/datasource-zabbix/datasource.js @@ -133,29 +133,29 @@ export class ZabbixDatasource { let useTrends = this.isUseTrends(timeRange); - // Metrics or Text query mode - if (!target.mode || target.mode === c.MODE_METRICS || target.mode === c.MODE_TEXT) { + // Metrics or Text query + if (!target.queryType || target.queryType === c.MODE_METRICS || target.queryType === c.MODE_TEXT) { // Don't request undefined targets if (!target.group || !target.host || !target.item) { return []; } - if (!target.mode || target.mode === c.MODE_METRICS) { + if (!target.queryType || target.queryType === c.MODE_METRICS) { return this.queryNumericData(target, timeRange, useTrends, options); - } else if (target.mode === c.MODE_TEXT) { + } else if (target.queryType === c.MODE_TEXT) { return this.queryTextData(target, timeRange); } - } else if (target.mode === c.MODE_ITEMID) { - // Item ID mode + } else if (target.queryType === c.MODE_ITEMID) { + // Item ID query if (!target.itemids) { return []; } return this.queryItemIdData(target, timeRange, useTrends, options); - } else if (target.mode === c.MODE_ITSERVICE) { - // IT services mode + } else if (target.queryType === c.MODE_ITSERVICE) { + // IT services query return this.queryITServiceData(target, timeRange, options); - } else if (target.mode === c.MODE_TRIGGERS) { - // Triggers mode + } else if (target.queryType === c.MODE_TRIGGERS) { + // Triggers query return this.queryTriggersData(target, timeRange); } else { return []; @@ -171,7 +171,7 @@ export class ZabbixDatasource { } /** - * Query target data for Metrics mode + * Query target data for Metrics */ queryNumericData(target, timeRange, useTrends, options) { let queryStart, queryEnd; @@ -276,7 +276,7 @@ export class ZabbixDatasource { } /** - * Query target data for Text mode + * Query target data for Text */ queryTextData(target, timeRange) { let options = { @@ -289,7 +289,7 @@ export class ZabbixDatasource { } /** - * Query target data for Item ID mode + * Query target data for Item ID */ queryItemIdData(target, timeRange, useTrends, options) { let itemids = target.itemids; @@ -307,7 +307,7 @@ export class ZabbixDatasource { } /** - * Query target data for IT Services mode + * Query target data for IT Services */ queryITServiceData(target, timeRange, options) { // Don't show undefined and hidden targets diff --git a/src/datasource-zabbix/migrations.ts b/src/datasource-zabbix/migrations.ts index a4f60cc..3023b90 100644 --- a/src/datasource-zabbix/migrations.ts +++ b/src/datasource-zabbix/migrations.ts @@ -1,4 +1,5 @@ import _ from 'lodash'; +import * as c from './constants'; /** * Query format migration. @@ -27,6 +28,29 @@ export function migrateFrom2To3version(target) { return target; } +function migratePercentileAgg(target) { + if (target.functions) { + for (const f of target.functions) { + if (f.def && f.def.name === 'percentil') { + f.def.name = 'percentile'; + } + } + } +} + +function migrateQueryType(target) { + if (target.queryType === undefined) { + if (target.mode === 'Metrics') { + // Explore mode + target.queryType = c.MODE_METRICS; + } else if (target.mode !== undefined) { + target.queryType = target.mode; + delete target.mode; + } + } + +} + export function migrate(target) { target.resultFormat = target.resultFormat || 'time_series'; target = fixTargetGroup(target); @@ -34,6 +58,7 @@ export function migrate(target) { return migrateFrom2To3version(target); } migratePercentileAgg(target); + migrateQueryType(target); return target; } @@ -52,16 +77,6 @@ function convertToRegex(str) { } } -function migratePercentileAgg(target) { - if (target.functions) { - for (const f of target.functions) { - if (f.def && f.def.name === 'percentil') { - f.def.name = 'percentile'; - } - } - } -} - export const DS_CONFIG_SCHEMA = 2; export function migrateDSConfig(jsonData) { if (!jsonData) { diff --git a/src/datasource-zabbix/partials/query.editor.html b/src/datasource-zabbix/partials/query.editor.html index ccf5ee3..c713b74 100644 --- a/src/datasource-zabbix/partials/query.editor.html +++ b/src/datasource-zabbix/partials/query.editor.html @@ -5,13 +5,13 @@
-
+
@@ -23,7 +23,7 @@
-
+
-
+
@@ -91,7 +91,7 @@
-
+
@@ -109,7 +109,7 @@
-
+
-
+
-