From 209e9ebda7e76303e95860f6a6591b33374c2536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 1 Sep 2015 13:01:00 +0200 Subject: [PATCH] fix(influxdb): fixes and refactorings of influxdb 0.9 editor, no longer shows template vars in keys dropdown and group by dropdownm, fixes #2636 --- CHANGELOG.md | 1 + .../plugins/datasource/influxdb/queryCtrl.js | 68 +++++++++++-------- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d8ccbe7618..bfff6ea811a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ it allows you to add queries of differnet data source types & instances to the s - [Issue #2563](https://github.com/grafana/grafana/issues/2563). Annotations: Fixed issue when html sanitizer failes for title to annotation body, now fallbacks to html escaping title and text - [Issue #2564](https://github.com/grafana/grafana/issues/2564). Templating: Another atempt at fixing #2534 (Init multi value template var used in repeat panel from url) - [Issue #2620](https://github.com/grafana/grafana/issues/2620). Graph: multi series tooltip did no highlight correct point when stacking was enabled and series were of different resolution +- [Issue #2636](https://github.com/grafana/grafana/issues/2636). InfluxDB: Do no show template vars in dropdown for tag keys and group by keys **Breaking Changes** - Notice to makers/users of custom data sources, there is a minor breaking change in 2.2 that diff --git a/public/app/plugins/datasource/influxdb/queryCtrl.js b/public/app/plugins/datasource/influxdb/queryCtrl.js index 0d1a9354b65..47f294ff6e7 100644 --- a/public/app/plugins/datasource/influxdb/queryCtrl.js +++ b/public/app/plugins/datasource/influxdb/queryCtrl.js @@ -119,8 +119,7 @@ function (angular, _, InfluxQueryBuilder) { $scope.getMeasurements = function () { var query = $scope.queryBuilder.buildExploreQuery('MEASUREMENTS'); return $scope.datasource.metricFindQuery(query) - .then($scope.transformToSegments) - .then($scope.addTemplateVariableSegments) + .then($scope.transformToSegments(true)) .then(null, $scope.handleQueryError); }; @@ -129,42 +128,46 @@ function (angular, _, InfluxQueryBuilder) { return []; }; - $scope.transformToSegments = function(results) { - return _.map(results, function(segment) { - return new MetricSegment({ value: segment.text, expandable: segment.expandable }); - }); - }; + $scope.transformToSegments = function(addTemplateVars) { + return function(results) { + var segments = _.map(results, function(segment) { + return new MetricSegment({ value: segment.text, expandable: segment.expandable }); + }); - $scope.addTemplateVariableSegments = function(segments) { - _.each(templateSrv.variables, function(variable) { - segments.unshift(new MetricSegment({ type: 'template', value: '/$' + variable.name + '/', expandable: true })); - }); - return segments; + if (addTemplateVars) { + _.each(templateSrv.variables, function(variable) { + segments.unshift(new MetricSegment({ type: 'template', value: '/$' + variable.name + '/', expandable: true })); + }); + } + + return segments; + }; }; $scope.getTagsOrValues = function(segment, index) { - var query; + if (segment.type === 'condition') { + return $q.when([new MetricSegment('AND'), new MetricSegment('OR')]); + } + if (segment.type === 'operator') { + var nextValue = $scope.tagSegments[index+1].value; + if (/^\/.*\/$/.test(nextValue)) { + return $q.when(MetricSegment.newOperators(['=~', '!~'])); + } else { + return $q.when(MetricSegment.newOperators(['=', '<>', '<', '>'])); + } + } + var query, addTemplateVars; if (segment.type === 'key' || segment.type === 'plus-button') { query = $scope.queryBuilder.buildExploreQuery('TAG_KEYS'); + addTemplateVars = false; } else if (segment.type === 'value') { query = $scope.queryBuilder.buildExploreQuery('TAG_VALUES', $scope.tagSegments[index-2].value); - } else if (segment.type === 'condition') { - return $q.when([new MetricSegment('AND'), new MetricSegment('OR')]); - } else if (segment.type === 'operator' && /^(?!\/.*\/$)/.test($scope.tagSegments[index+1].value)) { - return $q.when([MetricSegment.newOperator('='), MetricSegment.newOperator('<>'), - MetricSegment.newOperator('<'), MetricSegment.newOperator('>')]); - - } else if (segment.type === 'operator' && /^\/.*\/$/.test($scope.tagSegments[index+1].value)) { - return $q.when([MetricSegment.newOperator('=~'), MetricSegment.newOperator('!~')]); - } - else { - return $q.when([]); + addTemplateVars = true; } return $scope.datasource.metricFindQuery(query) - .then($scope.transformToSegments) - .then($scope.addTemplateVariableSegments) + .then($scope.transformToSegments(addTemplateVars)) .then(function(results) { if (segment.type === 'key') { results.splice(0, 0, angular.copy($scope.removeTagFilterSegment)); @@ -177,8 +180,8 @@ function (angular, _, InfluxQueryBuilder) { $scope.getFieldSegments = function() { var fieldsQuery = $scope.queryBuilder.buildExploreQuery('FIELDS'); return $scope.datasource.metricFindQuery(fieldsQuery) - .then($scope.transformToSegments) - .then(null, $scope.handleQueryError); + .then($scope.transformToSegments) + .then(null, $scope.handleQueryError); }; $scope.addField = function() { @@ -197,8 +200,7 @@ function (angular, _, InfluxQueryBuilder) { var query = $scope.queryBuilder.buildExploreQuery('TAG_KEYS'); return $scope.datasource.metricFindQuery(query) - .then($scope.transformToSegments) - .then($scope.addTemplateVariableSegments) + .then($scope.transformToSegments(false)) .then(function(results) { if (segment.type !== 'plus-button') { results.splice(0, 0, angular.copy($scope.removeGroupBySegment)); @@ -322,6 +324,12 @@ function (angular, _, InfluxQueryBuilder) { return new MetricSegment({value: op, type: 'operator', cssClass: 'query-segment-operator' }); }; + MetricSegment.newOperators = function(ops) { + return _.map(ops, function(op) { + return new MetricSegment({value: op, type: 'operator', cssClass: 'query-segment-operator' }); + }); + }; + MetricSegment.newPlusButton = function() { return new MetricSegment({fake: true, html: '', type: 'plus-button' }); };