From 141ea7ba9124e3681b376d11929c8e8ba1183d3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 1 Sep 2014 16:55:54 +0200 Subject: [PATCH] More work InfluxDB templated queries and required changes to editor and datasource --- src/app/controllers/templateEditorCtrl.js | 2 +- src/app/panels/graph/styleEditor.html | 2 +- src/app/partials/influxdb/editor.html | 65 +++++-------------- src/app/services/dashboard/dashboardSrv.js | 2 +- .../services/influxdb/influxdbDatasource.js | 44 +++++++------ src/css/less/grafana.less | 1 + src/test/specs/influxdb-datasource-specs.js | 7 +- 7 files changed, 48 insertions(+), 75 deletions(-) diff --git a/src/app/controllers/templateEditorCtrl.js b/src/app/controllers/templateEditorCtrl.js index d133413ca22..e4e93b568b3 100644 --- a/src/app/controllers/templateEditorCtrl.js +++ b/src/app/controllers/templateEditorCtrl.js @@ -16,7 +16,7 @@ function (angular, _) { name: '', options: [], includeAll: false, - allFormat: 'Glob', + allFormat: 'glob', }; $scope.init = function() { diff --git a/src/app/panels/graph/styleEditor.html b/src/app/panels/graph/styleEditor.html index a699ae4e1a4..d26fe1610b8 100644 --- a/src/app/panels/graph/styleEditor.html +++ b/src/app/panels/graph/styleEditor.html @@ -93,7 +93,7 @@ {{option.name}}: {{option.value}} diff --git a/src/app/partials/influxdb/editor.html b/src/app/partials/influxdb/editor.html index 5ed42499ccf..995ba362121 100644 --- a/src/app/partials/influxdb/editor.html +++ b/src/app/partials/influxdb/editor.html @@ -108,73 +108,42 @@
  • - +
  • +
  • - +
  • +
  • - - - +
  • +
  • group by time
  • - +
  • - +
  • - +
  • diff --git a/src/app/services/dashboard/dashboardSrv.js b/src/app/services/dashboard/dashboardSrv.js index 0c7e433e138..91587feda38 100644 --- a/src/app/services/dashboard/dashboardSrv.js +++ b/src/app/services/dashboard/dashboardSrv.js @@ -216,7 +216,7 @@ function (angular, $, kbn, _, moment) { if (variable.datasource === void 0) { variable.datasource = null; } if (variable.type === 'filter') { variable.type = 'query'; } if (variable.type === void 0) { variable.type = 'query'; } - if (variable.allFormat === void 0) { variable.allFormat = 'Glob'; } + if (variable.allFormat === void 0) { variable.allFormat = 'glob'; } } } diff --git a/src/app/services/influxdb/influxdbDatasource.js b/src/app/services/influxdb/influxdbDatasource.js index 64f0b7e706a..0db4f3626ba 100644 --- a/src/app/services/influxdb/influxdbDatasource.js +++ b/src/app/services/influxdb/influxdbDatasource.js @@ -76,30 +76,32 @@ function (angular, _, kbn, InfluxSeries) { query = templateSrv.replace(query); } else { + query = 'select '; + var seriesName = target.series; - var template = "select [[group]][[group_comma]] [[func]]([[column]]) from [[series]] " + - "where [[timeFilter]] [[condition_add]] [[condition_key]] [[condition_op]] [[condition_value]] " + - "group by time([[interval]])[[group_comma]] [[group]] order asc"; - - var templateData = { - series: target.series, - column: target.column, - func: target.function, - timeFilter: timeFilter, - interval: target.interval || options.interval, - condition_add: target.condition_filter ? 'and' : '', - condition_key: target.condition_filter ? target.condition_key : '', - condition_op: target.condition_filter ? target.condition_op : '', - condition_value: target.condition_filter ? target.condition_value : '', - group_comma: target.groupby_field_add && target.groupby_field ? ',' : '', - group: target.groupby_field_add ? target.groupby_field : '', - }; - - if(!templateData.series.match('^/.*/')) { - templateData.series = '"' + templateData.series + '"'; + if(!seriesName.match('^/.*/')) { + seriesName = '"' + seriesName+ '"'; } - query = _.template(template, templateData, this.templateSettings); + if (target.groupby_field_add) { + query += target.groupby_field + ', '; + } + + query += target.function + '(' + target.column + ')'; + query += ' from ' + seriesName + ' where ' + timeFilter; + + if (target.condition_filter) { + query += ' and ' + target.condition_expression; + } + + query += ' group by time(' + (target.interval || options.interval) + ')'; + + if (target.groupby_field_add) { + query += ',' + target.groupby_field; + } + + query += " order asc"; + query = templateSrv.replace(query); if (target.groupby_field_add) { diff --git a/src/css/less/grafana.less b/src/css/less/grafana.less index e9184ac41c2..a0c2407a075 100644 --- a/src/css/less/grafana.less +++ b/src/css/less/grafana.less @@ -255,6 +255,7 @@ input[type=text].grafana-target-text-input { float: left; color: @grafanaTargetColor; border-radius: 0; + border-right: 1px solid @grafanaTargetSegmentBorder; } input[type=text].grafana-target-segment-input { diff --git a/src/test/specs/influxdb-datasource-specs.js b/src/test/specs/influxdb-datasource-specs.js index b66d9eb3304..68ae33fbc18 100644 --- a/src/test/specs/influxdb-datasource-specs.js +++ b/src/test/specs/influxdb-datasource-specs.js @@ -12,11 +12,12 @@ define([ describe('When querying influxdb with one target using query editor target spec', function() { var results; - var urlExpected = "/series?p=mupp&q=select++mean(value)+from+%22test%22"+ - "+where++time+%3E+now()+-+1h+++++group+by+time()++order+asc&time_precision=s"; + var urlExpected = "/series?p=mupp&q=select+mean(value)+from+%22test%22"+ + "+where+time+%3E+now()+-+1h+group+by+time(1s)+order+asc&time_precision=s"; var query = { range: { from: 'now-1h', to: 'now' }, - targets: [{ series: 'test', column: 'value', function: 'mean' }] + targets: [{ series: 'test', column: 'value', function: 'mean' }], + interval: '1s' }; var response = [{