(prometheus) support new legend format (with backward compatibility) (#5096)

* (prometheus) support new legend format (with backward compatibility)

* (prometheus) use regex replace for legend format

* (prometheus) allow white space
This commit is contained in:
Mitsuhiro Tanda 2016-05-20 19:29:10 +09:00 committed by Torkel Ödegaard
parent 35c05463e7
commit 9c672f6ec1

View File

@ -256,23 +256,14 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS
return this.renderTemplate(options.legendFormat, labelData) || '{}'; return this.renderTemplate(options.legendFormat, labelData) || '{}';
}; };
this.renderTemplate = function(format, data) { this.renderTemplate = function(aliasPattern, aliasData) {
var originalSettings = _.templateSettings; var aliasRegex = /\{\{\s*(.+?)\s*\}\}/g;
_.templateSettings = { return aliasPattern.replace(aliasRegex, function(match, g1) {
interpolate: /\{\{(.+?)\}\}/g if (aliasData[g1]) {
}; return aliasData[g1];
}
var template = _.template(templateSrv.replace(format)); return g1;
var result; });
try {
result = template(data);
} catch (e) {
result = null;
}
_.templateSettings = originalSettings;
return result;
}; };
this.getOriginalMetricName = function(labelData) { this.getOriginalMetricName = function(labelData) {