Loki Query Builder: Add parsing support for aggregations with grouping (#80145)

Loki Query Builder: Add parsing support for aggregations with grouping arguments
This commit is contained in:
Matias Chomicki 2024-01-08 17:17:19 +01:00 committed by GitHub
parent c60a1dddc2
commit 4950935401
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -673,6 +673,21 @@ describe('buildVisualQueryFromString', () => {
);
});
it('parses quantile queries with grouping', () => {
expect(buildVisualQueryFromString(`quantile_over_time(0.99, {app="frontend"} [1m]) by (host1, host2)`)).toEqual(
noErrors({
labels: [
{
op: '=',
value: 'frontend',
label: 'app',
},
],
operations: [{ id: LokiOperationId.QuantileOverTime, params: ['1m', '0.99', 'host1', 'host2'] }],
})
);
});
it('parses query with line format', () => {
expect(buildVisualQueryFromString('{app="frontend"} | line_format "abc"')).toEqual(
noErrors({

View File

@ -501,11 +501,16 @@ function handleRangeAggregation(expr: string, node: SyntaxNode, context: Context
const params = number !== null && number !== undefined ? [getString(expr, number)] : [];
const range = logExpr?.getChild(Range);
const rangeValue = range ? getString(expr, range) : null;
const grouping = node.getChild(Grouping);
if (rangeValue) {
params.unshift(rangeValue.substring(1, rangeValue.length - 1));
}
if (grouping) {
params.push(...getAllByType(expr, grouping, Identifier));
}
const op = {
id: funcName,
params,