mirror of
https://github.com/grafana/grafana.git
synced 2025-01-07 22:53:56 -06:00
Loki Query Builder: Fix bug parsing range params (#61678)
feat(loki-query-builder): fix bug parsing range params
This commit is contained in:
parent
d042c0b30b
commit
89e77d072f
@ -661,6 +661,27 @@ describe('buildVisualQueryFromString', () => {
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it.each(['$__interval', '5m'])('parses query range with unwrap and regex', (range) => {
|
||||
expect(
|
||||
buildVisualQueryFromString(
|
||||
'avg_over_time({test="value"} |= `restart counter is at` | regexp `restart counter is at (?P<restart_counter>[0-9]+)s*.*.*?$` | unwrap restart_counter [' +
|
||||
range +
|
||||
'])'
|
||||
)
|
||||
).toEqual({
|
||||
errors: [],
|
||||
query: {
|
||||
labels: [{ label: 'test', op: '=', value: 'value' }],
|
||||
operations: [
|
||||
{ id: '__line_contains', params: ['restart counter is at'] },
|
||||
{ id: 'regexp', params: ['restart counter is at (?P<restart_counter>[0-9]+)s*.*.*?$'] },
|
||||
{ id: 'unwrap', params: ['restart_counter', ''] },
|
||||
{ id: 'avg_over_time', params: [range] },
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function noErrors(query: LokiVisualQuery) {
|
||||
|
@ -413,10 +413,11 @@ function handleRangeAggregation(expr: string, node: SyntaxNode, context: Context
|
||||
const number = node.getChild(NumberLezer);
|
||||
const logExpr = node.getChild(LogRangeExpr);
|
||||
const params = number !== null && number !== undefined ? [getString(expr, number)] : [];
|
||||
const range = logExpr?.getChild(Range);
|
||||
const rangeValue = range ? getString(expr, range) : null;
|
||||
|
||||
let match = getString(expr, node).match(/\[(.+)\]/);
|
||||
if (match?.[1]) {
|
||||
params.unshift(match[1]);
|
||||
if (rangeValue) {
|
||||
params.unshift(rangeValue.substring(1, rangeValue.length - 1));
|
||||
}
|
||||
|
||||
const op = {
|
||||
|
Loading…
Reference in New Issue
Block a user