mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Prometheus: fix rules expansion
Rules expansion (available via query hints in explore) was broken for expressions that contained selectors.
- fix replacing regexp to recognize `{` and `[` as the end of a rule name
- moved logic to language utils
- added tests
This commit is contained in:
@@ -83,3 +83,9 @@ export function parseSelector(query: string, cursorOffset = 1): { labelKeys: any
|
||||
|
||||
return { labelKeys, selector: selectorString };
|
||||
}
|
||||
|
||||
export function expandRecordingRules(query: string, mapping: { [name: string]: string }): string {
|
||||
const ruleNames = Object.keys(mapping);
|
||||
const rulesRegex = new RegExp(`(\\s|^)(${ruleNames.join('|')})(\\s|$|\\(|\\[|\\{)`, 'ig');
|
||||
return query.replace(rulesRegex, (match, pre, name, post) => `${pre}${mapping[name]}${post}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user