fix(prometheus): issue with click label to filter for recording rules in Explore

This commit is contained in:
tolwi 2019-05-09 14:54:48 +03:00 committed by David
parent a04b3a13e0
commit f0109be2bc
2 changed files with 8 additions and 1 deletions

View File

@ -30,8 +30,12 @@ export function addLabelToQuery(query: string, key: string, value: string, opera
const insideSelector = isPositionInsideChars(query, offset, '{', '}');
// Handle "sum by (key) (metric)"
const previousWordIsKeyWord = previousWord && keywords.split('|').indexOf(previousWord) > -1;
// check for colon as as "word boundary" symbol
const isColonBounded = word.endsWith(':');
previousWord = word;
if (!insideSelector && !previousWordIsKeyWord && builtInWords.indexOf(word) === -1) {
if (!insideSelector && !isColonBounded && !previousWordIsKeyWord && builtInWords.indexOf(word) === -1) {
return `${word}{}`;
}
return word;

View File

@ -29,6 +29,9 @@ describe('addLabelToQuery()', () => {
'foo{bar="baz",instance="my-host.com:9100"}'
);
expect(addLabelToQuery('foo:metric:rate1m', 'bar', 'baz')).toBe('foo:metric:rate1m{bar="baz"}');
expect(addLabelToQuery('avg(foo:metric:rate1m{a="b"})', 'bar', 'baz')).toBe(
'avg(foo:metric:rate1m{a="b",bar="baz"})'
);
expect(addLabelToQuery('foo{list="a,b,c"}', 'bar', 'baz')).toBe('foo{bar="baz",list="a,b,c"}');
});