mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
(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:
parent
35c05463e7
commit
9c672f6ec1
@ -256,23 +256,14 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS
|
||||
return this.renderTemplate(options.legendFormat, labelData) || '{}';
|
||||
};
|
||||
|
||||
this.renderTemplate = function(format, data) {
|
||||
var originalSettings = _.templateSettings;
|
||||
_.templateSettings = {
|
||||
interpolate: /\{\{(.+?)\}\}/g
|
||||
};
|
||||
|
||||
var template = _.template(templateSrv.replace(format));
|
||||
var result;
|
||||
try {
|
||||
result = template(data);
|
||||
} catch (e) {
|
||||
result = null;
|
||||
}
|
||||
|
||||
_.templateSettings = originalSettings;
|
||||
|
||||
return result;
|
||||
this.renderTemplate = function(aliasPattern, aliasData) {
|
||||
var aliasRegex = /\{\{\s*(.+?)\s*\}\}/g;
|
||||
return aliasPattern.replace(aliasRegex, function(match, g1) {
|
||||
if (aliasData[g1]) {
|
||||
return aliasData[g1];
|
||||
}
|
||||
return g1;
|
||||
});
|
||||
};
|
||||
|
||||
this.getOriginalMetricName = function(labelData) {
|
||||
|
Loading…
Reference in New Issue
Block a user