Commit 8ed0df64 by Torkel Ödegaard

Fixes to OpenTSDB datasource, and added support for repeat panels and repeat rows

parent e8c65dc3
...@@ -27,7 +27,7 @@ function (angular, _, kbn) { ...@@ -27,7 +27,7 @@ function (angular, _, kbn) {
var qs = []; var qs = [];
_.each(options.targets, function(target) { _.each(options.targets, function(target) {
qs.push(convertTargetToQuery(target, options.interval)); qs.push(convertTargetToQuery(target, options));
}); });
var queries = _.compact(qs); var queries = _.compact(qs);
...@@ -47,10 +47,10 @@ function (angular, _, kbn) { ...@@ -47,10 +47,10 @@ function (angular, _, kbn) {
}); });
return this.performTimeSeriesQuery(queries, start, end).then(function(response) { return this.performTimeSeriesQuery(queries, start, end).then(function(response) {
var metricToTargetMapping = mapMetricsToTargets(response.data, options.targets); var metricToTargetMapping = mapMetricsToTargets(response.data, options);
var result = _.map(response.data, function(metricData, index) { var result = _.map(response.data, function(metricData, index) {
index = metricToTargetMapping[index]; index = metricToTargetMapping[index];
return transformMetricData(metricData, groupByTags, options.targets[index]); return transformMetricData(metricData, groupByTags, options.targets[index], options);
}); });
return { data: result }; return { data: result };
}); });
...@@ -125,6 +125,8 @@ function (angular, _, kbn) { ...@@ -125,6 +125,8 @@ function (angular, _, kbn) {
}; };
OpenTSDBDatasource.prototype.metricFindQuery = function(query) { OpenTSDBDatasource.prototype.metricFindQuery = function(query) {
if (!query) { return $q.when([]); }
var interpolated; var interpolated;
try { try {
interpolated = templateSrv.replace(query); interpolated = templateSrv.replace(query);
...@@ -147,8 +149,8 @@ function (angular, _, kbn) { ...@@ -147,8 +149,8 @@ function (angular, _, kbn) {
if (metrics_query) { if (metrics_query) {
return this._performSuggestQuery(metrics_query[1]).then(responseTransform); return this._performSuggestQuery(metrics_query[1]).then(responseTransform);
} }
var tag_names_query = interpolated.match(tag_names_regex);
var tag_names_query = interpolated.match(tag_names_regex);
if (tag_names_query) { if (tag_names_query) {
return this._performMetricKeyLookup(tag_names_query[1]).then(responseTransform); return this._performMetricKeyLookup(tag_names_query[1]).then(responseTransform);
} }
...@@ -157,6 +159,8 @@ function (angular, _, kbn) { ...@@ -157,6 +159,8 @@ function (angular, _, kbn) {
if (tag_values_query) { if (tag_values_query) {
return this._performMetricKeyValueLookup(tag_values_query[1], tag_values_query[2]).then(responseTransform); return this._performMetricKeyValueLookup(tag_values_query[1], tag_values_query[2]).then(responseTransform);
} }
return $q.when([]);
}; };
OpenTSDBDatasource.prototype.testDatasource = function() { OpenTSDBDatasource.prototype.testDatasource = function() {
...@@ -165,8 +169,8 @@ function (angular, _, kbn) { ...@@ -165,8 +169,8 @@ function (angular, _, kbn) {
}); });
}; };
function transformMetricData(md, groupByTags, options) { function transformMetricData(md, groupByTags, target, options) {
var metricLabel = createMetricLabel(md, options, groupByTags); var metricLabel = createMetricLabel(md, target, groupByTags, options);
var dps = []; var dps = [];
// TSDB returns datapoints has a hash of ts => value. // TSDB returns datapoints has a hash of ts => value.
...@@ -178,13 +182,13 @@ function (angular, _, kbn) { ...@@ -178,13 +182,13 @@ function (angular, _, kbn) {
return { target: metricLabel, datapoints: dps }; return { target: metricLabel, datapoints: dps };
} }
function createMetricLabel(md, options, groupByTags) { function createMetricLabel(md, target, groupByTags, options) {
if (!_.isUndefined(options) && options.alias) { if (target.alias) {
var scopedVars = {}; var scopedVars = _.clone(options.scopedVars || {});
_.each(md.tags, function(value, key) { _.each(md.tags, function(value, key) {
scopedVars['tag_' + key] = {value: value}; scopedVars['tag_' + key] = {value: value};
}); });
return templateSrv.replace(options.alias, scopedVars); return templateSrv.replace(target.alias, scopedVars);
} }
var label = md.metric; var label = md.metric;
...@@ -205,13 +209,13 @@ function (angular, _, kbn) { ...@@ -205,13 +209,13 @@ function (angular, _, kbn) {
return label; return label;
} }
function convertTargetToQuery(target, interval) { function convertTargetToQuery(target, options) {
if (!target.metric || target.hide) { if (!target.metric || target.hide) {
return null; return null;
} }
var query = { var query = {
metric: templateSrv.replace(target.metric), metric: templateSrv.replace(target.metric, options.scopedVars),
aggregator: "avg" aggregator: "avg"
}; };
...@@ -235,7 +239,7 @@ function (angular, _, kbn) { ...@@ -235,7 +239,7 @@ function (angular, _, kbn) {
} }
if (!target.disableDownsampling) { if (!target.disableDownsampling) {
interval = templateSrv.replace(target.downsampleInterval || interval); var interval = templateSrv.replace(target.downsampleInterval || options.interval);
if (interval.match(/\.[0-9]+s/)) { if (interval.match(/\.[0-9]+s/)) {
interval = parseFloat(interval)*1000 + "ms"; interval = parseFloat(interval)*1000 + "ms";
...@@ -247,20 +251,20 @@ function (angular, _, kbn) { ...@@ -247,20 +251,20 @@ function (angular, _, kbn) {
query.tags = angular.copy(target.tags); query.tags = angular.copy(target.tags);
if(query.tags){ if(query.tags){
for(var key in query.tags){ for(var key in query.tags){
query.tags[key] = templateSrv.replace(query.tags[key]); query.tags[key] = templateSrv.replace(query.tags[key], options.scopedVars);
} }
} }
return query; return query;
} }
function mapMetricsToTargets(metrics, targets) { function mapMetricsToTargets(metrics, options) {
var interpolatedTagValue; var interpolatedTagValue;
return _.map(metrics, function(metricData) { return _.map(metrics, function(metricData) {
return _.findIndex(targets, function(target) { return _.findIndex(options.targets, function(target) {
return target.metric === metricData.metric && return target.metric === metricData.metric &&
_.all(target.tags, function(tagV, tagK) { _.all(target.tags, function(tagV, tagK) {
interpolatedTagValue = templateSrv.replace(tagV); interpolatedTagValue = templateSrv.replace(tagV, options.scopedVars);
return metricData.tags[tagK] === interpolatedTagValue || interpolatedTagValue === "*"; return metricData.tags[tagK] === interpolatedTagValue || interpolatedTagValue === "*";
}); });
}); });
......
...@@ -59,7 +59,7 @@ function (angular, _, kbn) { ...@@ -59,7 +59,7 @@ function (angular, _, kbn) {
}; };
$scope.suggestTagValues = function(query, callback) { $scope.suggestTagValues = function(query, callback) {
$scope.datasource.metricFindQuery('tag_names(' + $scope.target.metric + ',' + $scope.target.currentTagKey + ')') $scope.datasource.metricFindQuery('tag_values(' + $scope.target.metric + ',' + $scope.target.currentTagKey + ')')
.then($scope.getTextValues) .then($scope.getTextValues)
.then(callback); .then(callback);
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment