Просмотр исходного кода

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

Torkel Ödegaard 10 лет назад
Родитель
Сommit
7a41ecb63f

+ 15 - 5
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;
       })

+ 18 - 0
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');
+        });
+      });
+
+    });
+
   });
 });