Commit 28ccd632 by Mitsuhiro Tanda

fix templating

parent 4f42dae3
...@@ -189,8 +189,8 @@ function (angular, _, kbn) { ...@@ -189,8 +189,8 @@ function (angular, _, kbn) {
query.metricName = templateSrv.replace(target.metricName, options.scopedVars); query.metricName = templateSrv.replace(target.metricName, options.scopedVars);
query.dimensions = _.map(_.keys(target.dimensions), function(key) { query.dimensions = _.map(_.keys(target.dimensions), function(key) {
return { return {
Name: key, Name: templateSrv.replace(key, options.scopedVars),
Value: target.dimensions[key] Value: templateSrv.replace(target.dimensions[key], options.scopedVars)
}; };
}); });
query.statistics = getActivatedStatistics(target.statistics); query.statistics = getActivatedStatistics(target.statistics);
...@@ -264,14 +264,20 @@ function (angular, _, kbn) { ...@@ -264,14 +264,20 @@ function (angular, _, kbn) {
}; };
CloudWatchDatasource.prototype.performSuggestMetrics = function(namespace) { CloudWatchDatasource.prototype.performSuggestMetrics = function(namespace) {
namespace = templateSrv.replace(namespace);
return this.supportedMetrics[namespace] || []; return this.supportedMetrics[namespace] || [];
}; };
CloudWatchDatasource.prototype.performSuggestDimensionKeys = function(namespace) { CloudWatchDatasource.prototype.performSuggestDimensionKeys = function(namespace) {
namespace = templateSrv.replace(namespace);
return this.supportedDimensions[namespace] || []; return this.supportedDimensions[namespace] || [];
}; };
CloudWatchDatasource.prototype.performSuggestDimensionValues = function(region, namespace, metricName, dimensions) { CloudWatchDatasource.prototype.performSuggestDimensionValues = function(region, namespace, metricName, dimensions) {
region = templateSrv.replace(region);
namespace = templateSrv.replace(namespace);
metricName = templateSrv.replace(metricName);
var cloudwatch = this.getCloudWatchClient(region); var cloudwatch = this.getCloudWatchClient(region);
var params = { var params = {
...@@ -281,8 +287,8 @@ function (angular, _, kbn) { ...@@ -281,8 +287,8 @@ function (angular, _, kbn) {
if (!_.isEmpty(dimensions)) { if (!_.isEmpty(dimensions)) {
params.Dimensions = _.map(_.keys(dimensions), function(key) { params.Dimensions = _.map(_.keys(dimensions), function(key) {
return { return {
Name: key, Name: templateSrv.replace(key),
Value: dimensions[key] Value: templateSrv.replace(dimensions[key])
}; };
}); });
} }
...@@ -333,23 +339,23 @@ function (angular, _, kbn) { ...@@ -333,23 +339,23 @@ function (angular, _, kbn) {
var metricNameQuery = query.match(/^metrics\(([^\)]+?)\)/); var metricNameQuery = query.match(/^metrics\(([^\)]+?)\)/);
if (metricNameQuery) { if (metricNameQuery) {
namespace = metricNameQuery[1]; namespace = templateSrv.replace(metricNameQuery[1]);
d.resolve(transformSuggestData(this.performSuggestMetrics(namespace))); d.resolve(transformSuggestData(this.performSuggestMetrics(namespace)));
return d.promise; return d.promise;
} }
var dimensionKeysQuery = query.match(/^dimension_keys\(([^\)]+?)\)/); var dimensionKeysQuery = query.match(/^dimension_keys\(([^\)]+?)\)/);
if (dimensionKeysQuery) { if (dimensionKeysQuery) {
namespace = dimensionKeysQuery[1]; namespace = templateSrv.replace(dimensionKeysQuery[1]);
d.resolve(transformSuggestData(this.performSuggestDimensionKeys(namespace))); d.resolve(transformSuggestData(this.performSuggestDimensionKeys(namespace)));
return d.promise; return d.promise;
} }
var dimensionValuesQuery = query.match(/^dimension_values\(([^,]+?),\s?([^,]+?),\s?([^,]+?)\)/); var dimensionValuesQuery = query.match(/^dimension_values\(([^,]+?),\s?([^,]+?),\s?([^,]+?)\)/);
if (dimensionValuesQuery) { if (dimensionValuesQuery) {
region = dimensionValuesQuery[1]; region = templateSrv.replace(dimensionValuesQuery[1]);
namespace = dimensionValuesQuery[2]; namespace = templateSrv.replace(dimensionValuesQuery[2]);
metricName = dimensionValuesQuery[3]; metricName = templateSrv.replace(dimensionValuesQuery[3]);
var dimensions = {}; var dimensions = {};
return this.performSuggestDimensionValues(region, namespace, metricName, dimensions) return this.performSuggestDimensionValues(region, namespace, metricName, dimensions)
...@@ -399,7 +405,7 @@ function (angular, _, kbn) { ...@@ -399,7 +405,7 @@ function (angular, _, kbn) {
function transformMetricData(md, options) { function transformMetricData(md, options) {
var result = []; var result = [];
var dimensionPart = JSON.stringify(options.dimensions); var dimensionPart = templateSrv.replace(JSON.stringify(options.dimensions));
_.each(getActivatedStatistics(options.statistics), function(s) { _.each(getActivatedStatistics(options.statistics), function(s) {
var metricLabel = md.Label + '_' + s + dimensionPart; var metricLabel = md.Label + '_' + s + dimensionPart;
......
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