Commit 6ace01fb by Marcus Efraimsson Committed by GitHub

Merge pull request #12893 from grafana/davkal/12889-explore-fix-rate-filter

Explore: Fix label filtering for rate queries
parents dc608483 dd796bfb
......@@ -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(/(\w+)\b(?![\(\]{=",])/g, (match, word, offset) => {
// Check if inside a selector
const nextSelectorStart = query.slice(offset).indexOf('{');
const nextSelectorEnd = query.slice(offset).indexOf('}');
......
......@@ -375,6 +375,7 @@ describe('PrometheusDatasource', () => {
expect(addLabelToQuery('foo{instance="my-host.com:9100"}', 'bar', 'baz')).toBe(
'foo{bar="baz",instance="my-host.com:9100"}'
);
expect(addLabelToQuery('rate(metric[1m])', 'foo', 'bar')).toBe('rate(metric{foo="bar"}[1m])');
});
});
......
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