Commit 7a41ecb6 by Torkel Ödegaard

Minor work on InfluxDB 0.9 query editor, #1525, hit a roadblock with the new…

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
parent 6fd37779
...@@ -49,8 +49,8 @@ function (angular, _) { ...@@ -49,8 +49,8 @@ function (angular, _) {
$scope.groupBySegments.push(MetricSegment.newPlusButton()); $scope.groupBySegments.push(MetricSegment.newPlusButton());
$scope.removeTagFilterSegment = new MetricSegment({fake: true, value: 'remove tag filter'}); $scope.removeTagFilterSegment = new MetricSegment({fake: true, value: '-- remove tag filter --'});
$scope.removeGroupBySegment = new MetricSegment({fake: true, value: 'remove group by'}); $scope.removeGroupBySegment = new MetricSegment({fake: true, value: '-- remove group by --'});
}; };
$scope.fixTagSegments = function() { $scope.fixTagSegments = function() {
...@@ -129,11 +129,21 @@ function (angular, _) { ...@@ -129,11 +129,21 @@ function (angular, _) {
return segments; 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) { $scope.getTagsOrValues = function(segment, index) {
var query, queryType; var query, queryType;
if (segment.type === 'key' || segment.type === 'plus-button') { if (segment.type === 'key' || segment.type === 'plus-button') {
queryType = 'TAG_KEYS'; queryType = 'TAG_KEYS';
query = 'SHOW TAG KEYS FROM "' + $scope.target.measurement + '"'; query = $scope.buildTagKeysQuery($scope.target, segment);
} else if (segment.type === 'value') { } else if (segment.type === 'value') {
queryType = 'TAG_VALUES'; queryType = 'TAG_VALUES';
query = 'SHOW TAG VALUES FROM "' + $scope.target.measurement + '" WITH KEY = ' + $scope.tagSegments[index-2].value; query = 'SHOW TAG VALUES FROM "' + $scope.target.measurement + '" WITH KEY = ' + $scope.tagSegments[index-2].value;
...@@ -149,7 +159,7 @@ function (angular, _) { ...@@ -149,7 +159,7 @@ function (angular, _) {
.then($scope.addTemplateVariableSegments) .then($scope.addTemplateVariableSegments)
.then(function(results) { .then(function(results) {
if (queryType === 'TAG_KEYS' && segment.type === 'key') { if (queryType === 'TAG_KEYS' && segment.type === 'key') {
results.push(angular.copy($scope.removeTagFilterSegment)); results.splice(0, 0, angular.copy($scope.removeTagFilterSegment));
} }
return results; return results;
}) })
...@@ -164,7 +174,7 @@ function (angular, _) { ...@@ -164,7 +174,7 @@ function (angular, _) {
.then($scope.addTemplateVariableSegments) .then($scope.addTemplateVariableSegments)
.then(function(results) { .then(function(results) {
if (segment.type !== 'plus-button') { if (segment.type !== 'plus-button') {
results.push(angular.copy($scope.removeGroupBySegment)); results.splice(0, 0, angular.copy($scope.removeGroupBySegment));
} }
return results; return results;
}) })
......
...@@ -198,5 +198,23 @@ define([ ...@@ -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');
});
});
});
}); });
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment