mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 08:05:43 -06:00
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:
parent
c60a1dddc2
commit
4950935401
@ -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({
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user