Commit 5f6a3ecd by Mitsuhiro Tanda Committed by Torkel Ödegaard

(cloudwatch) don't expand variable when panel or row repeat is used (#6618)

* (cloudwatch) don't expand variable when panel or row repeat is used

* fix test
parent be26c017
......@@ -112,10 +112,18 @@ function (angular, _, kbn) {
this._grafanaVariables[name] = value;
};
this.variableExists = function(expression) {
this.getVariableName = function(expression) {
this._regex.lastIndex = 0;
var match = this._regex.exec(expression);
return match && (self._index[match[1] || match[2]] !== void 0);
if (!match) {
return null;
}
return match[1] || match[2];
};
this.variableExists = function(expression) {
var name = this.getVariableName(expression);
return name && (self._index[name] !== void 0);
};
this.highlightVariablesAsHtml = function(str) {
......
......@@ -31,7 +31,7 @@ function (angular, _, moment, dateMath, kbn, CloudWatchAnnotationQuery) {
var queries = [];
options = angular.copy(options);
options.targets = this.expandTemplateVariable(options.targets, templateSrv);
options.targets = this.expandTemplateVariable(options.targets, options.scopedVars, templateSrv);
_.each(options.targets, function(target) {
if (target.hide || !target.namespace || !target.metricName || _.isEmpty(target.statistics)) {
return;
......@@ -412,12 +412,12 @@ function (angular, _, moment, dateMath, kbn, CloudWatchAnnotationQuery) {
return str.indexOf('$' + variableName) !== -1;
};
this.expandTemplateVariable = function(targets, templateSrv) {
this.expandTemplateVariable = function(targets, scopedVars, templateSrv) {
var self = this;
return _.chain(targets)
.map(function(target) {
var dimensionKey = _.findKey(target.dimensions, function(v) {
return templateSrv.variableExists(v);
return templateSrv.variableExists(v) && !_.has(scopedVars, templateSrv.getVariableName(v));
});
if (dimensionKey) {
......
......@@ -139,6 +139,7 @@ describe('CloudWatchDatasource', function() {
]
}
],
getVariableName: function (e) { return 'instance_id'; },
variableExists: function (e) { return true; },
containsVariable: function (str, variableName) { return str.indexOf('$' + variableName) !== -1; }
};
......@@ -156,7 +157,7 @@ describe('CloudWatchDatasource', function() {
}
];
var result = ctx.ds.expandTemplateVariable(targets, templateSrv);
var result = ctx.ds.expandTemplateVariable(targets, {}, templateSrv);
expect(result[0].dimensions.InstanceId).to.be('i-34567890');
});
});
......
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