diff --git a/public/app/plugins/datasource/prometheus/datasource.ts b/public/app/plugins/datasource/prometheus/datasource.ts index 69dae38e358..acfc4b876d3 100644 --- a/public/app/plugins/datasource/prometheus/datasource.ts +++ b/public/app/plugins/datasource/prometheus/datasource.ts @@ -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)