From cf0748895ed578965ccbc003ba5f6474269d3324 Mon Sep 17 00:00:00 2001 From: Jimmi Dyson Date: Tue, 29 Sep 2015 15:54:47 +0100 Subject: [PATCH] Prometheus template params fixes --- .../plugins/datasource/prometheus/datasource.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/public/app/plugins/datasource/prometheus/datasource.js b/public/app/plugins/datasource/prometheus/datasource.js index 158d2cf6ba5..dd8ba8e2b3b 100644 --- a/public/app/plugins/datasource/prometheus/datasource.js +++ b/public/app/plugins/datasource/prometheus/datasource.js @@ -130,8 +130,16 @@ function (angular, _, moment, dateMath) { PrometheusDatasource.prototype.metricFindQuery = function(query) { var url; - var metricsQuery = query.match(/^[a-zA-Z_:*][a-zA-Z0-9_:*]*/); - var labelValuesQuery = query.match(/^label_values\((.+)\)/); + var interpolated; + try { + interpolated = templateSrv.replace(query); + } + catch (err) { + return $q.reject(err); + } + + var metricsQuery = interpolated.match(/^[a-zA-Z_:*][a-zA-Z0-9_:*]*/); + var labelValuesQuery = interpolated.match(/^label_values\((.+)\)/); if (labelValuesQuery) { // return label values @@ -163,11 +171,12 @@ function (angular, _, moment, dateMath) { }); } else { // if query contains full metric name, return metric name and label list - url = '/api/v1/query?query=' + encodeURIComponent(query); + url = '/api/v1/query?query=' + encodeURIComponent(interpolated) + + '&time=' + (moment().valueOf() / 1000); return this._request('GET', url) .then(function(result) { - return _.map(result.data.result, function(metricData) { + return _.map(result.data.data.result, function(metricData) { return { text: getOriginalMetricName(metricData.metric), expandable: true