diff --git a/public/app/plugins/datasource/prometheus/datasource.js b/public/app/plugins/datasource/prometheus/datasource.js index e6eaa71a392..4eb83f4e5a3 100644 --- a/public/app/plugins/datasource/prometheus/datasource.js +++ b/public/app/plugins/datasource/prometheus/datasource.js @@ -5,7 +5,7 @@ define([ 'moment', 'app/core/utils/datemath', './directives', - './queryCtrl', + './query_ctrl', ], function (angular, _, kbn, dateMath) { 'use strict'; @@ -22,7 +22,6 @@ function (angular, _, kbn, dateMath) { var url = datasource.url; if (url[url.length-1] === '/') { - // remove trailing slash url = url.substr(0, url.length - 1); } this.url = url; diff --git a/public/app/plugins/datasource/prometheus/partials/query.editor.html b/public/app/plugins/datasource/prometheus/partials/query.editor.html index 29cb2acd3d7..8090476e213 100644 --- a/public/app/plugins/datasource/prometheus/partials/query.editor.html +++ b/public/app/plugins/datasource/prometheus/partials/query.editor.html @@ -48,13 +48,7 @@ placeholder="query expression" data-min-length=0 data-items=100 ng-model-onblur - ng-change="refreshMetricData()" - > - - - + ng-change="refreshMetricData()">
  • Metric @@ -66,13 +60,7 @@ spellcheck='false' bs-typeahead="suggestMetrics" placeholder="metric name" - data-min-length=0 data-items=100 - > - - - + data-min-length=0 data-items=100>
  • @@ -113,7 +101,7 @@ bs-tooltip="'Leave blank for auto handling based on time range and panel width'" data-placement="right" spellcheck='false' - placeholder="{{target.calculatedInterval}}" + placeholder="{{interval}}" data-min-length=0 data-items=100 ng-model-onblur ng-change="refreshMetricData()" @@ -131,12 +119,6 @@ -
  • - - - -
  • -
    diff --git a/public/app/plugins/datasource/prometheus/queryCtrl.js b/public/app/plugins/datasource/prometheus/queryCtrl.js deleted file mode 100644 index 88257c824f5..00000000000 --- a/public/app/plugins/datasource/prometheus/queryCtrl.js +++ /dev/null @@ -1,133 +0,0 @@ -define([ - 'angular', - 'lodash', - 'kbn', - 'app/core/utils/datemath', -], -function (angular, _, kbn, dateMath) { - 'use strict'; - - var module = angular.module('grafana.controllers'); - - module.controller('PrometheusQueryCtrl', function($scope) { - - $scope.init = function() { - $scope.target.errors = validateTarget(); - $scope.target.datasourceErrors = {}; - - if (!$scope.target.expr) { - $scope.target.expr = ''; - } - $scope.target.metric = ''; - - $scope.resolutions = [ - { factor: 1, }, - { factor: 2, }, - { factor: 3, }, - { factor: 5, }, - { factor: 10, }, - ]; - $scope.resolutions = _.map($scope.resolutions, function(r) { - r.label = '1/' + r.factor; - return r; - }); - if (!$scope.target.intervalFactor) { - $scope.target.intervalFactor = 2; // default resolution is 1/2 - } - - $scope.calculateInterval(); - $scope.$on('render', function() { - $scope.calculateInterval(); // re-calculate interval when time range is updated - }); - $scope.target.prometheusLink = $scope.linkToPrometheus(); - - $scope.$on('typeahead-updated', function() { - $scope.$apply($scope.inputMetric); - $scope.refreshMetricData(); - }); - - $scope.datasource.lastErrors = {}; - $scope.$watch('datasource.lastErrors', function() { - $scope.target.datasourceErrors = $scope.datasource.lastErrors; - }, true); - }; - - $scope.refreshMetricData = function() { - $scope.target.errors = validateTarget($scope.target); - $scope.calculateInterval(); - $scope.target.prometheusLink = $scope.linkToPrometheus(); - - // this does not work so good - if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) { - $scope.oldTarget = angular.copy($scope.target); - $scope.get_data(); - } - }; - - $scope.inputMetric = function() { - $scope.target.expr += $scope.target.metric; - $scope.target.metric = ''; - }; - - $scope.moveMetricQuery = function(fromIndex, toIndex) { - _.move($scope.panel.targets, fromIndex, toIndex); - }; - - $scope.suggestMetrics = function(query, callback) { - $scope.datasource - .performSuggestQuery(query) - .then(callback); - }; - - $scope.linkToPrometheus = function() { - var from = dateMath.parse($scope.dashboard.time.from, false); - var to = dateMath.parse($scope.dashboard.time.to, true); - - if ($scope.panel.timeFrom) { - from = dateMath.parseDateMath('-' + $scope.panel.timeFrom, to, false); - } - if ($scope.panel.timeShift) { - from = dateMath.parseDateMath('-' + $scope.panel.timeShift, from, false); - to = dateMath.parseDateMath('-' + $scope.panel.timeShift, to, true); - } - - var range = Math.ceil((to.valueOf()- from.valueOf()) / 1000); - - var endTime = to.format('YYYY-MM-DD HH:MM'); - - var step = kbn.interval_to_seconds(this.target.calculatedInterval); - if (step !== 0 && range / step > 11000) { - step = Math.floor(range / 11000); - } - - var expr = { - expr: $scope.target.expr, - range_input: range + 's', - end_input: endTime, - //step_input: step, - step_input: '', - stacked: $scope.panel.stack, - tab: 0 - }; - - var hash = encodeURIComponent(JSON.stringify([expr])); - return $scope.datasource.url + '/graph#' + hash; - }; - - $scope.calculateInterval = function() { - var interval = $scope.target.interval || $scope.interval; - var calculatedInterval = $scope.datasource.calculateInterval(interval, $scope.target.intervalFactor); - $scope.target.calculatedInterval = kbn.secondsToHms(calculatedInterval); - }; - - // TODO: validate target - function validateTarget() { - var errs = {}; - - return errs; - } - - $scope.init(); - }); - -}); diff --git a/public/app/plugins/datasource/prometheus/query_ctrl.js b/public/app/plugins/datasource/prometheus/query_ctrl.js new file mode 100644 index 00000000000..809531f96ac --- /dev/null +++ b/public/app/plugins/datasource/prometheus/query_ctrl.js @@ -0,0 +1,50 @@ +define([ + 'angular', + 'lodash', +], +function (angular, _) { + 'use strict'; + + var module = angular.module('grafana.controllers'); + + module.controller('PrometheusQueryCtrl', function($scope) { + + $scope.init = function() { + var target = $scope.target; + + target.expr = target.expr || ''; + target.intervalFactor = target.intervalFactor || 2; + + $scope.metric = ''; + $scope.resolutions = _.map([1,2,3,4,5,10], function(f) { + return {factor: f, label: '1/' + f}; + }); + + $scope.$on('typeahead-updated', function() { + $scope.$apply($scope.inputMetric); + $scope.refreshMetricData(); + }); + }; + + $scope.refreshMetricData = function() { + if (!_.isEqual($scope.oldTarget, $scope.target)) { + $scope.oldTarget = angular.copy($scope.target); + $scope.get_data(); + } + }; + + $scope.inputMetric = function() { + $scope.target.expr += $scope.target.metric; + $scope.metric = ''; + }; + + $scope.suggestMetrics = function(query, callback) { + $scope.datasource + .performSuggestQuery(query) + .then(callback); + }; + + $scope.init(); + }); + +}); diff --git a/tasks/options/requirejs.js b/tasks/options/requirejs.js index a21ebcc8580..a1636af98e5 100644 --- a/tasks/options/requirejs.js +++ b/tasks/options/requirejs.js @@ -63,7 +63,6 @@ module.exports = function(config,grunt) { 'app/plugins/datasource/grafana/datasource', 'app/plugins/datasource/graphite/datasource', 'app/plugins/datasource/influxdb/datasource', - 'app/plugins/datasource/prometheus/datasource', ] }, ];