mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -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:
@@ -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) {
|
function noErrors(query: LokiVisualQuery) {
|
||||||
|
|||||||
@@ -413,10 +413,11 @@ function handleRangeAggregation(expr: string, node: SyntaxNode, context: Context
|
|||||||
const number = node.getChild(NumberLezer);
|
const number = node.getChild(NumberLezer);
|
||||||
const logExpr = node.getChild(LogRangeExpr);
|
const logExpr = node.getChild(LogRangeExpr);
|
||||||
const params = number !== null && number !== undefined ? [getString(expr, number)] : [];
|
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 (rangeValue) {
|
||||||
if (match?.[1]) {
|
params.unshift(rangeValue.substring(1, rangeValue.length - 1));
|
||||||
params.unshift(match[1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const op = {
|
const op = {
|
||||||
|
|||||||
Reference in New Issue
Block a user