mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
fix(prometheus): issue with click label to filter for recording rules in Explore
This commit is contained in:
parent
a04b3a13e0
commit
f0109be2bc
@ -30,8 +30,12 @@ export function addLabelToQuery(query: string, key: string, value: string, opera
|
|||||||
const insideSelector = isPositionInsideChars(query, offset, '{', '}');
|
const insideSelector = isPositionInsideChars(query, offset, '{', '}');
|
||||||
// Handle "sum by (key) (metric)"
|
// Handle "sum by (key) (metric)"
|
||||||
const previousWordIsKeyWord = previousWord && keywords.split('|').indexOf(previousWord) > -1;
|
const previousWordIsKeyWord = previousWord && keywords.split('|').indexOf(previousWord) > -1;
|
||||||
|
|
||||||
|
// check for colon as as "word boundary" symbol
|
||||||
|
const isColonBounded = word.endsWith(':');
|
||||||
|
|
||||||
previousWord = word;
|
previousWord = word;
|
||||||
if (!insideSelector && !previousWordIsKeyWord && builtInWords.indexOf(word) === -1) {
|
if (!insideSelector && !isColonBounded && !previousWordIsKeyWord && builtInWords.indexOf(word) === -1) {
|
||||||
return `${word}{}`;
|
return `${word}{}`;
|
||||||
}
|
}
|
||||||
return word;
|
return word;
|
||||||
|
@ -29,6 +29,9 @@ describe('addLabelToQuery()', () => {
|
|||||||
'foo{bar="baz",instance="my-host.com:9100"}'
|
'foo{bar="baz",instance="my-host.com:9100"}'
|
||||||
);
|
);
|
||||||
expect(addLabelToQuery('foo:metric:rate1m', 'bar', 'baz')).toBe('foo:metric:rate1m{bar="baz"}');
|
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"}');
|
expect(addLabelToQuery('foo{list="a,b,c"}', 'bar', 'baz')).toBe('foo{bar="baz",list="a,b,c"}');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user