Fix prometheus label filtering for comparison queries (#13213)

- Now supports click filtering for queries like `metric > 0.1`
This commit is contained in:
David
2018-09-11 16:57:43 +02:00
committed by Torkel Ödegaard
parent 0768a078ed
commit d8a702cba3
2 changed files with 2 additions and 1 deletions
@@ -39,7 +39,7 @@ export function addLabelToQuery(query: string, key: string, value: string): stri
// Add empty selector to bare metric name
let previousWord;
query = query.replace(/(\w+)\b(?![\(\]{=",])/g, (match, word, offset) => {
query = query.replace(/([A-Za-z]\w*)\b(?![\(\]{=",])/g, (match, word, offset) => {
// Check if inside a selector
const nextSelectorStart = query.slice(offset).indexOf('{');
const nextSelectorEnd = query.slice(offset).indexOf('}');
@@ -376,6 +376,7 @@ describe('PrometheusDatasource', () => {
'foo{bar="baz",instance="my-host.com:9100"}'
);
expect(addLabelToQuery('rate(metric[1m])', 'foo', 'bar')).toBe('rate(metric{foo="bar"}[1m])');
expect(addLabelToQuery('metric > 0.001', 'foo', 'bar')).toBe('metric{foo="bar"} > 0.001');
});
});