Commit d8a702cb by David Committed by Torkel Ödegaard

Fix prometheus label filtering for comparison queries (#13213)

- Now supports click filtering for queries like `metric > 0.1`
parent 0768a078
......@@ -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');
});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment