mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -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', () => {
|
it('parses query with line format', () => {
|
||||||
expect(buildVisualQueryFromString('{app="frontend"} | line_format "abc"')).toEqual(
|
expect(buildVisualQueryFromString('{app="frontend"} | line_format "abc"')).toEqual(
|
||||||
noErrors({
|
noErrors({
|
||||||
|
@ -501,11 +501,16 @@ function handleRangeAggregation(expr: string, node: SyntaxNode, context: Context
|
|||||||
const params = number !== null && number !== undefined ? [getString(expr, number)] : [];
|
const params = number !== null && number !== undefined ? [getString(expr, number)] : [];
|
||||||
const range = logExpr?.getChild(Range);
|
const range = logExpr?.getChild(Range);
|
||||||
const rangeValue = range ? getString(expr, range) : null;
|
const rangeValue = range ? getString(expr, range) : null;
|
||||||
|
const grouping = node.getChild(Grouping);
|
||||||
|
|
||||||
if (rangeValue) {
|
if (rangeValue) {
|
||||||
params.unshift(rangeValue.substring(1, rangeValue.length - 1));
|
params.unshift(rangeValue.substring(1, rangeValue.length - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (grouping) {
|
||||||
|
params.push(...getAllByType(expr, grouping, Identifier));
|
||||||
|
}
|
||||||
|
|
||||||
const op = {
|
const op = {
|
||||||
id: funcName,
|
id: funcName,
|
||||||
params,
|
params,
|
||||||
|
Loading…
Reference in New Issue
Block a user