mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #12893 from grafana/davkal/12889-explore-fix-rate-filter
Explore: Fix label filtering for rate queries
This commit is contained in:
commit
6ace01fbed
@ -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])');
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user