mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: Add support for distinct operation in autocomplete and query builder (#69003)
* Loki Autocomplete: add support for suggesting distinct * Loki query builder: add distinct as format operation * Remove unused import * Loki visual query: add support to parse distinct filters * Query builder: use label param editor for distinct * Loki Autocomplete: Improve distinct label suggestions * Query Builder: improve distinct parsing * Fix tests * Update tests
This commit is contained in:
@@ -8,6 +8,8 @@ import {
|
||||
By,
|
||||
ConvOp,
|
||||
Decolorize,
|
||||
DistinctFilter,
|
||||
DistinctLabel,
|
||||
Filter,
|
||||
FilterOp,
|
||||
Grouping,
|
||||
@@ -205,6 +207,11 @@ export function handleExpression(expr: string, node: SyntaxNode, context: Contex
|
||||
break;
|
||||
}
|
||||
|
||||
case DistinctFilter: {
|
||||
visQuery.operations.push(handleDistinctFilter(expr, node, context));
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
// Any other nodes we just ignore and go to its children. This should be fine as there are lots of wrapper
|
||||
// nodes that can be skipped.
|
||||
@@ -422,6 +429,7 @@ function handleUnwrapExpr(
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
function handleRangeAggregation(expr: string, node: SyntaxNode, context: Context) {
|
||||
const nameNode = node.getChild(RangeOp);
|
||||
const funcName = getString(expr, nameNode);
|
||||
@@ -632,3 +640,20 @@ function isEmptyQuery(query: LokiVisualQuery) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function handleDistinctFilter(expr: string, node: SyntaxNode, context: Context): QueryBuilderOperation {
|
||||
const labels: string[] = [];
|
||||
let exploringNode = node.getChild(DistinctLabel);
|
||||
while (exploringNode) {
|
||||
const label = getString(expr, exploringNode.getChild(Identifier));
|
||||
if (label) {
|
||||
labels.push(label);
|
||||
}
|
||||
exploringNode = exploringNode?.getChild(DistinctLabel);
|
||||
}
|
||||
labels.reverse();
|
||||
return {
|
||||
id: LokiOperationId.Distinct,
|
||||
params: labels,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user