From f122da58c1969797282c6686b2061970148a38c3 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Mon, 21 Apr 2014 16:20:08 +0200 Subject: [PATCH 1/6] added support to coustom where conditions --- src/app/controllers/influxTargetCtrl.js | 2 +- src/app/partials/influxdb/editor.html | 18 +++++++++++++++++- .../services/influxdb/influxdbDatasource.js | 14 ++++++++++++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/app/controllers/influxTargetCtrl.js b/src/app/controllers/influxTargetCtrl.js index 66439c5e757..467b135a961 100644 --- a/src/app/controllers/influxTargetCtrl.js +++ b/src/app/controllers/influxTargetCtrl.js @@ -64,4 +64,4 @@ function (angular) { }); -}); \ No newline at end of file +}); diff --git a/src/app/partials/influxdb/editor.html b/src/app/partials/influxdb/editor.html index 4a6927e5984..e4b92fa4b97 100644 --- a/src/app/partials/influxdb/editor.html +++ b/src/app/partials/influxdb/editor.html @@ -74,7 +74,23 @@ function
  • - + +
  • +
  • + condition +
  • +
  • +
  • group by time diff --git a/src/app/services/influxdb/influxdbDatasource.js b/src/app/services/influxdb/influxdbDatasource.js index 9f92627e32d..a9361b5e0de 100644 --- a/src/app/services/influxdb/influxdbDatasource.js +++ b/src/app/services/influxdb/influxdbDatasource.js @@ -30,12 +30,16 @@ function (angular, _, kbn) { return []; } - var template = "select [[func]]([[column]]) from [[series]] where [[timeFilter]] group by time([[interval]]) order asc"; + // var template = "select [[func]]([[column]]) as [[column]]_[[func]] from [[series]] where [[timeFilter]] group by time([[interval]]) order asc"; + var template = "select [[func]]([[column]]) from [[series]] where [[condition]] [[timeFilter]] group by time([[interval]]) order asc"; + + target.condition_joined = (target.condition !== undefined ? target.condition + ' AND ' : ''); var templateData = { series: target.series, column: target.column, func: target.function, + condition: target.condition_joined, timeFilter: getTimeFilter(options), interval: target.interval || options.interval }; @@ -96,6 +100,12 @@ function (angular, _, kbn) { function handleInfluxQueryResponse(results) { var output = []; + var getKey = function (str) { + var key1 = str.split(' where '); + var key2 = key1[1].split(' AND '); + return (key2[0] !== key1[1] ? '.' + key2[0] : ''); + } + _.each(results.data, function(series) { var timeCol = series.columns.indexOf('time'); @@ -106,7 +116,7 @@ function (angular, _, kbn) { console.log("series:"+series.name + ": "+series.points.length + " points"); - var target = series.name + "." + column; + var target = series.name + "." + column + getKey(results.config.params.q); var datapoints = []; for(var i = 0; i < series.points.length; i++) { From 72ab721f2263bc0f35f647e7e99e86bb5fb53baf Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Mon, 21 Apr 2014 18:06:13 +0200 Subject: [PATCH 2/6] Added where condiction operators --- src/app/controllers/influxTargetCtrl.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/controllers/influxTargetCtrl.js b/src/app/controllers/influxTargetCtrl.js index 7ad82ae6807..e481970c254 100644 --- a/src/app/controllers/influxTargetCtrl.js +++ b/src/app/controllers/influxTargetCtrl.js @@ -18,6 +18,7 @@ function (angular) { $scope.rawQuery = false; $scope.functions = ['count', 'mean', 'sum', 'min', 'max', 'mode', 'distinct', 'median', 'derivative', 'stddev', 'first', 'last']; + $scope.operators = ['=', '=~', '>', '<', '!~', '<>']; $scope.oldSeries = $scope.target.series; $scope.$on('typeahead-updated', function(){ $timeout($scope.get_data); From bba76cac4d59af3176889505fc46941d2817f24a Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Mon, 21 Apr 2014 18:07:24 +0200 Subject: [PATCH 3/6] Added conditions management --- src/app/partials/influxdb/editor.html | 38 ++++++++++++++----- .../services/influxdb/influxdbDatasource.js | 18 ++++----- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/app/partials/influxdb/editor.html b/src/app/partials/influxdb/editor.html index 15bfd667a36..fbeaa3fbdf0 100644 --- a/src/app/partials/influxdb/editor.html +++ b/src/app/partials/influxdb/editor.html @@ -57,7 +57,7 @@
  • -
  • -
  • - condition +
  • + + +
  • -
  • +
  • + + +
  • -
  • group by time
  • diff --git a/src/app/services/influxdb/influxdbDatasource.js b/src/app/services/influxdb/influxdbDatasource.js index 9c874d47e8b..ebeb7443c78 100644 --- a/src/app/services/influxdb/influxdbDatasource.js +++ b/src/app/services/influxdb/influxdbDatasource.js @@ -72,17 +72,19 @@ function (angular, _, kbn) { } else { var template = "select [[func]]([[column]]) as [[column]]_[[func]] from [[series]] " + - "where [[condition]] [[timeFilter]]" + - " group by time([[interval]]) order asc"; - - target.condition_joined = (target.condition !== undefined ? target.condition + ' AND ' : ''); + "where [[timeFilter]] [[condition_add]] [[condition_key]] [[condition_op]] [[condition_value]] " + + "group by time([[interval]]) order asc"; var templateData = { series: target.series, column: target.column, func: target.function, timeFilter: timeFilter, - interval: target.interval || options.interval + interval: target.interval || options.interval, + condition_add: target.condiction_filter ? target.condition_add : '', + condition_key: target.condiction_filter ? target.condition_key : '', + condition_op: target.condiction_filter ? target.condition_op : '', + condition_value: target.condiction_filter ? target.condition_value: '' }; query = _.template(template, templateData, this.templateSettings); @@ -159,12 +161,6 @@ function (angular, _, kbn) { function handleInfluxQueryResponse(data) { var output = []; - var getKey = function (str) { - var key1 = str.split(' where '); - var key2 = key1[1].split(' AND '); - return (key2[0] !== key1[1] ? '.' + key2[0] : ''); - } - _.each(data, function(series) { var timeCol = series.columns.indexOf('time'); From 01f3d728ef1678837bcfbb4670e52c1a70d5dc7f Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Mon, 21 Apr 2014 18:07:55 +0200 Subject: [PATCH 4/6] Added labels per series management --- src/app/partials/influxdb/editor.html | 12 ++++++++++++ src/app/services/influxdb/influxdbDatasource.js | 9 ++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/app/partials/influxdb/editor.html b/src/app/partials/influxdb/editor.html index fbeaa3fbdf0..0c7b077bc19 100644 --- a/src/app/partials/influxdb/editor.html +++ b/src/app/partials/influxdb/editor.html @@ -51,6 +51,18 @@ data-min-length=0 data-items=100 ng-blur="get_data()"> +
  • + label +
  • + +
  • + +
  • from series
  • diff --git a/src/app/services/influxdb/influxdbDatasource.js b/src/app/services/influxdb/influxdbDatasource.js index ebeb7443c78..e80f7a82d4c 100644 --- a/src/app/services/influxdb/influxdbDatasource.js +++ b/src/app/services/influxdb/influxdbDatasource.js @@ -91,7 +91,7 @@ function (angular, _, kbn) { target.query = query; } - return this.doInfluxRequest(query).then(handleInfluxQueryResponse); + return this.doInfluxRequest(query, target.label).then(handleInfluxQueryResponse); }, this); @@ -130,7 +130,7 @@ function (angular, _, kbn) { }); } - InfluxDatasource.prototype.doInfluxRequest = function(query) { + InfluxDatasource.prototype.doInfluxRequest = function(query, name) { var _this = this; var deferred = $q.defer(); @@ -151,6 +151,7 @@ function (angular, _, kbn) { }; return $http(options).success(function (data) { + data.label = name; deferred.resolve(data); }); }, 10); @@ -169,9 +170,7 @@ function (angular, _, kbn) { return; } - console.log("series:"+series.name + ": "+series.points.length + " points"); - - var target = series.name + "." + column + getKey(results.config.params.q); + var target = data.label || series.name + "." + column; var datapoints = []; for(var i = 0; i < series.points.length; i++) { From 02696c8bca54be56630174259f173fb47b1276a4 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Mon, 21 Apr 2014 18:13:05 +0200 Subject: [PATCH 5/6] better variable naming --- src/app/services/influxdb/influxdbDatasource.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/services/influxdb/influxdbDatasource.js b/src/app/services/influxdb/influxdbDatasource.js index e80f7a82d4c..23fe317cb7d 100644 --- a/src/app/services/influxdb/influxdbDatasource.js +++ b/src/app/services/influxdb/influxdbDatasource.js @@ -130,7 +130,7 @@ function (angular, _, kbn) { }); } - InfluxDatasource.prototype.doInfluxRequest = function(query, name) { + InfluxDatasource.prototype.doInfluxRequest = function(query, label) { var _this = this; var deferred = $q.defer(); @@ -151,7 +151,7 @@ function (angular, _, kbn) { }; return $http(options).success(function (data) { - data.label = name; + data.label = label; deferred.resolve(data); }); }, 10); From 595aab4edfdf866428ab2a9fffc4eabdaf6e7b6d Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Mon, 21 Apr 2014 18:14:30 +0200 Subject: [PATCH 6/6] removed unrequired variable (error on merge from master) --- src/app/services/influxdb/influxdbDatasource.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/app/services/influxdb/influxdbDatasource.js b/src/app/services/influxdb/influxdbDatasource.js index 23fe317cb7d..d443d3ebb40 100644 --- a/src/app/services/influxdb/influxdbDatasource.js +++ b/src/app/services/influxdb/influxdbDatasource.js @@ -32,15 +32,6 @@ function (angular, _, kbn) { return []; } - var templateData = { - series: target.series, - column: target.column, - func: target.function, - condition: target.condition_joined, - timeFilter: getTimeFilter(options), - interval: target.interval || options.interval - }; - var timeFilter = getTimeFilter(options); if (target.rawQuery) {