Commit ffc9a832 by Torkel Ödegaard

Merge pull request #4054 from mtanda/cloudwatch_template_dimension_fix

(cloudwatch) fix template replace in legend
parents 84e50f90 f28eec8b
...@@ -58,7 +58,7 @@ function (angular, _, moment, dateMath) { ...@@ -58,7 +58,7 @@ function (angular, _, moment, dateMath) {
var result = []; var result = [];
_.each(allResponse, function(response, index) { _.each(allResponse, function(response, index) {
var metrics = transformMetricData(response, options.targets[index]); var metrics = transformMetricData(response, options.targets[index], options.scopedVars);
result = result.concat(metrics); result = result.concat(metrics);
}); });
...@@ -302,15 +302,21 @@ function (angular, _, moment, dateMath) { ...@@ -302,15 +302,21 @@ function (angular, _, moment, dateMath) {
return this.defaultRegion; return this.defaultRegion;
}; };
function transformMetricData(md, options) { function transformMetricData(md, options, scopedVars) {
var aliasRegex = /\{\{(.+?)\}\}/g; var aliasRegex = /\{\{(.+?)\}\}/g;
var aliasPattern = options.alias || '{{metric}}_{{stat}}'; var aliasPattern = options.alias || '{{metric}}_{{stat}}';
var aliasData = { var aliasData = {
region: templateSrv.replace(options.region), region: templateSrv.replace(options.region, scopedVars),
namespace: templateSrv.replace(options.namespace), namespace: templateSrv.replace(options.namespace, scopedVars),
metric: templateSrv.replace(options.metricName), metric: templateSrv.replace(options.metricName, scopedVars),
}; };
_.extend(aliasData, options.dimensions); var aliasDimensions = {};
_.each(_.keys(options.dimensions), function(origKey) {
var key = templateSrv.replace(origKey, scopedVars);
var value = templateSrv.replace(options.dimensions[origKey], scopedVars);
aliasDimensions[key] = value;
});
_.extend(aliasData, aliasDimensions);
var periodMs = options.period * 1000; var periodMs = options.period * 1000;
return _.map(options.statistics, function(stat) { return _.map(options.statistics, function(stat) {
......
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