feat(prometheus): added special regex escape for prometheus, fixes #4234

This commit is contained in:
Torkel Ödegaard 2016-03-03 10:49:30 +01:00
parent e7ef79e0d3
commit 8ed8bfb8bc

View File

@ -39,13 +39,22 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS
return backendSrv.datasourceRequest(options);
};
function regexEscape(value) {
return value.replace(/[\\^$*+?.()|[\]{}]/g, '\\\\$&');
}
function interpolateQueryExpr(value, variable, defaultFormatFn) {
// if no multi or include all do not regexEscape
if (!variable.multi && !variable.includeAll) {
return value;
}
return defaultFormatFn(value, 'regex', variable);
if (typeof value === 'string') {
return regexEscape(value);
}
var escapedValues = _.map(value, regexEscape);
return escapedValues.join('|');
};
// Called once per panel (graph)