Explore: Fix label filtering for rate queries

- exclude `]` from match expression for selector injection to ignore
  range vectors like `[10m]`
This commit is contained in:
David Kaltschmidt
2018-08-13 12:53:12 +02:00
parent bdd9af0864
commit 978e89657e
2 changed files with 2 additions and 1 deletions

View File

@@ -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('}');

View File

@@ -351,6 +351,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])');
});
});