From 7a41ecb63f032344cfe46d9c77963a2105261c28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Sat, 16 May 2015 16:08:13 +0200 Subject: [PATCH] Minor work on InfluxDB 0.9 query editor, #1525, hit a roadblock with the new InfluxDB query language, does not support tag and tag values discovery queries with filters, not sure if I need to move to SHOW SERIES style queries --- .../plugins/datasource/influxdb/queryCtrl.js | 20 ++++++++++++++----- public/test/specs/influxdbQueryCtrl-specs.js | 18 +++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/public/app/plugins/datasource/influxdb/queryCtrl.js b/public/app/plugins/datasource/influxdb/queryCtrl.js index e68d10a2067..00729391b59 100644 --- a/public/app/plugins/datasource/influxdb/queryCtrl.js +++ b/public/app/plugins/datasource/influxdb/queryCtrl.js @@ -49,8 +49,8 @@ function (angular, _) { $scope.groupBySegments.push(MetricSegment.newPlusButton()); - $scope.removeTagFilterSegment = new MetricSegment({fake: true, value: 'remove tag filter'}); - $scope.removeGroupBySegment = new MetricSegment({fake: true, value: 'remove group by'}); + $scope.removeTagFilterSegment = new MetricSegment({fake: true, value: '-- remove tag filter --'}); + $scope.removeGroupBySegment = new MetricSegment({fake: true, value: '-- remove group by --'}); }; $scope.fixTagSegments = function() { @@ -129,11 +129,21 @@ function (angular, _) { return segments; }; + $scope.buildTagKeysQuery = function(target) { + var query = 'SHOW TAG KEYS'; + + if (target.measurement) { + query += ' FROM "' + target.measurement + '"'; + } + + return query; + }; + $scope.getTagsOrValues = function(segment, index) { var query, queryType; if (segment.type === 'key' || segment.type === 'plus-button') { queryType = 'TAG_KEYS'; - query = 'SHOW TAG KEYS FROM "' + $scope.target.measurement + '"'; + query = $scope.buildTagKeysQuery($scope.target, segment); } else if (segment.type === 'value') { queryType = 'TAG_VALUES'; query = 'SHOW TAG VALUES FROM "' + $scope.target.measurement + '" WITH KEY = ' + $scope.tagSegments[index-2].value; @@ -149,7 +159,7 @@ function (angular, _) { .then($scope.addTemplateVariableSegments) .then(function(results) { if (queryType === 'TAG_KEYS' && segment.type === 'key') { - results.push(angular.copy($scope.removeTagFilterSegment)); + results.splice(0, 0, angular.copy($scope.removeTagFilterSegment)); } return results; }) @@ -164,7 +174,7 @@ function (angular, _) { .then($scope.addTemplateVariableSegments) .then(function(results) { if (segment.type !== 'plus-button') { - results.push(angular.copy($scope.removeGroupBySegment)); + results.splice(0, 0, angular.copy($scope.removeGroupBySegment)); } return results; }) diff --git a/public/test/specs/influxdbQueryCtrl-specs.js b/public/test/specs/influxdbQueryCtrl-specs.js index 2b106952160..2c9915c6760 100644 --- a/public/test/specs/influxdbQueryCtrl-specs.js +++ b/public/test/specs/influxdbQueryCtrl-specs.js @@ -198,5 +198,23 @@ define([ }); }); + describe('when building tag keys query', function() { + + describe('given picked measurement', function() { + it('build query with measurement filter', function() { + var query = ctx.scope.buildTagKeysQuery({ measurement: 'cpu', tags: [] }, {type: 'key'}); + expect(query).to.be('SHOW TAG KEYS FROM "cpu"'); + }); + }); + + describe('given no picked measurement', function() { + it('build query without filter', function() { + var query = ctx.scope.buildTagKeysQuery({ measurement: '', tags: [] }, {type: 'key'}); + expect(query).to.be('SHOW TAG KEYS'); + }); + }); + + }); + }); });