mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: Added support for "or" statements in line filters (#78705)
* Lezer: upgrade to 0.2.2 * Operations: update definitions * Operations: update renderer * Parsing: parse line filters with or operations * Parsing: add unit test * Formatting * getHighlighterExpressionsFromQuery: add support for or statements * Operation editor: trim button title if param name is empty * getHighlighterExpressionsFromQuery: properly handle ip filters
This commit is contained in:
@@ -51,6 +51,7 @@ import {
|
||||
Without,
|
||||
BinOpModifier,
|
||||
OnOrIgnoringModifier,
|
||||
OrFilter,
|
||||
} from '@grafana/lezer-logql';
|
||||
|
||||
import {
|
||||
@@ -275,7 +276,6 @@ function getLineFilter(expr: string, node: SyntaxNode): GetOperationResult {
|
||||
const filter = getString(expr, node.getChild(Filter));
|
||||
const filterExpr = handleQuotes(getString(expr, node.getChild(String)));
|
||||
const ipLineFilter = node.getChild(FilterOp)?.getChild(Ip);
|
||||
|
||||
if (ipLineFilter) {
|
||||
return {
|
||||
operation: {
|
||||
@@ -284,6 +284,14 @@ function getLineFilter(expr: string, node: SyntaxNode): GetOperationResult {
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const params = [filterExpr];
|
||||
let orFilter = node.getChild(OrFilter);
|
||||
while (orFilter) {
|
||||
params.push(handleQuotes(getString(expr, orFilter.getChild(String))));
|
||||
orFilter = orFilter.getChild(OrFilter);
|
||||
}
|
||||
|
||||
const mapFilter: Record<string, LokiOperationId> = {
|
||||
'|=': LokiOperationId.LineContains,
|
||||
'!=': LokiOperationId.LineContainsNot,
|
||||
@@ -294,7 +302,7 @@ function getLineFilter(expr: string, node: SyntaxNode): GetOperationResult {
|
||||
return {
|
||||
operation: {
|
||||
id: mapFilter[filter],
|
||||
params: [filterExpr],
|
||||
params,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user