Skip to content

Commit

Permalink
Update QueryController to conform with OpenTSDB Controller
Browse files Browse the repository at this point in the history
  • Loading branch information
espenfjo committed Jul 8, 2015
1 parent 48975e6 commit d97f24c
Showing 1 changed file with 13 additions and 39 deletions.
52 changes: 13 additions & 39 deletions public/app/plugins/datasource/kairosdb/queryCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ function (angular, _) {
'use strict';

var module = angular.module('grafana.controllers');
var metricList = [];
var tagList = [];

module.controller('KairosDBQueryCtrl', function($scope) {

Expand Down Expand Up @@ -48,50 +46,26 @@ function (angular, _) {
_.move($scope.panel.targets, fromIndex, toIndex);
};

$scope.getTextValues = function(metricFindResult) {
return _.map(metricFindResult, function(value) { return value.text; });
};

$scope.suggestMetrics = function(query, callback) {
if (!_.isEmpty(metricList)) {
return metricList;
}
else {
$scope.datasource._performMetricSuggestQuery().then(function(result) {
metricList = result;
callback(metricList);
});
}
$scope.datasource.metricFindQuery('metrics(' + query + ')')
.then($scope.getTextValues)
.then(callback);
};

$scope.suggestTagKeys = function(query, callback) {
if (!_.isEmpty(tagList)) {
var result = _.find(tagList, { name : $scope.target.metric });

if (!_.isEmpty(result)) {
return _.keys(result.tags);
}
}

$scope.datasource._performTagSuggestQuery($scope.target.metric).then(function(result) {
if (!_.isEmpty(result)) {
tagList.push(result);
callback(_.keys(result.tags));
}
});
$scope.datasource.metricFindQuery('tag_names(' + $scope.target.metric + ')')
.then($scope.getTextValues)
.then(callback);
};

$scope.suggestTagValues = function(query, callback) {
if (!_.isEmpty(tagList)) {
var result = _.find(tagList, { name : $scope.target.metric });

if (!_.isEmpty(result)) {
return result.tags[$scope.target.currentTagKey];
}
}

$scope.datasource.performTagSuggestQuery($scope.target.metric).then(function(result) {
if (!_.isEmpty(result)) {
tagList.push(result);
callback(result.tags[$scope.target.currentTagKey]);
}
});
$scope.datasource.metricFindQuery('tag_values(' + $scope.target.metric + ',' + $scope.target.currentTagKey + ')')
.then($scope.getTextValues)
.then(callback);
};

// Filter metric by tag
Expand Down

0 comments on commit d97f24c

Please sign in to comment.