mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #13341 from grafana/davkal/13336-fix-recording-rules-labels-suggestions
Explore: Fix label suggestions for recording rules
This commit is contained in:
commit
68d5738c48
@ -57,5 +57,8 @@ describe('parseSelector()', () => {
|
|||||||
|
|
||||||
parsed = parseSelector('baz{foo="bar"}', 12);
|
parsed = parseSelector('baz{foo="bar"}', 12);
|
||||||
expect(parsed.selector).toBe('{__name__="baz",foo="bar"}');
|
expect(parsed.selector).toBe('{__name__="baz",foo="bar"}');
|
||||||
|
|
||||||
|
parsed = parseSelector('bar:metric:1m{}', 14);
|
||||||
|
expect(parsed.selector).toBe('{__name__="bar:metric:1m"}');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -32,7 +32,7 @@ const labelRegexp = /\b\w+="[^"\n]*?"/g;
|
|||||||
export function parseSelector(query: string, cursorOffset = 1): { labelKeys: any[]; selector: string } {
|
export function parseSelector(query: string, cursorOffset = 1): { labelKeys: any[]; selector: string } {
|
||||||
if (!query.match(selectorRegexp)) {
|
if (!query.match(selectorRegexp)) {
|
||||||
// Special matcher for metrics
|
// Special matcher for metrics
|
||||||
if (query.match(/^\w+$/)) {
|
if (query.match(/^[A-Za-z:][\w:]*$/)) {
|
||||||
return {
|
return {
|
||||||
selector: `{__name__="${query}"}`,
|
selector: `{__name__="${query}"}`,
|
||||||
labelKeys: ['__name__'],
|
labelKeys: ['__name__'],
|
||||||
@ -76,7 +76,7 @@ export function parseSelector(query: string, cursorOffset = 1): { labelKeys: any
|
|||||||
|
|
||||||
// Add metric if there is one before the selector
|
// Add metric if there is one before the selector
|
||||||
const metricPrefix = query.slice(0, prefixOpen);
|
const metricPrefix = query.slice(0, prefixOpen);
|
||||||
const metricMatch = metricPrefix.match(/\w+$/);
|
const metricMatch = metricPrefix.match(/[A-Za-z:][\w:]*$/);
|
||||||
if (metricMatch) {
|
if (metricMatch) {
|
||||||
labels['__name__'] = `"${metricMatch[0]}"`;
|
labels['__name__'] = `"${metricMatch[0]}"`;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user