|
|
@ -17,6 +17,8 @@ import { |
|
|
|
MetricExpr, |
|
|
|
MetricExpr, |
|
|
|
Matcher, |
|
|
|
Matcher, |
|
|
|
Identifier, |
|
|
|
Identifier, |
|
|
|
|
|
|
|
Nre, |
|
|
|
|
|
|
|
Neq, |
|
|
|
} from '@grafana/lezer-logql'; |
|
|
|
} from '@grafana/lezer-logql'; |
|
|
|
import { DataQuery } from '@grafana/schema'; |
|
|
|
import { DataQuery } from '@grafana/schema'; |
|
|
|
|
|
|
|
|
|
|
@ -31,7 +33,7 @@ export function formatQuery(selector: string | undefined): string { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Returns search terms from a LogQL query. |
|
|
|
* Returns search terms from a LogQL query. |
|
|
|
* E.g., `{} |= foo |=bar != baz` returns `['foo', 'bar']`. |
|
|
|
* E.g.: `{} |= foo |=bar != baz` returns `['foo', 'bar', '-baz']`. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
export function getHighlighterExpressionsFromQuery(input: string): string[] { |
|
|
|
export function getHighlighterExpressionsFromQuery(input: string): string[] { |
|
|
|
const results = []; |
|
|
|
const results = []; |
|
|
@ -49,9 +51,10 @@ export function getHighlighterExpressionsFromQuery(input: string): string[] { |
|
|
|
for (let filter of filters) { |
|
|
|
for (let filter of filters) { |
|
|
|
const pipeExact = filter.getChild(Filter)?.getChild(PipeExact); |
|
|
|
const pipeExact = filter.getChild(Filter)?.getChild(PipeExact); |
|
|
|
const pipeMatch = filter.getChild(Filter)?.getChild(PipeMatch); |
|
|
|
const pipeMatch = filter.getChild(Filter)?.getChild(PipeMatch); |
|
|
|
|
|
|
|
const negativeExp = filter.getChild(Filter)?.getChild(Neq) || filter.getChild(Filter)?.getChild(Nre); |
|
|
|
const string = filter.getChild(String); |
|
|
|
const string = filter.getChild(String); |
|
|
|
|
|
|
|
|
|
|
|
if ((!pipeExact && !pipeMatch) || !string) { |
|
|
|
if ((!pipeExact && !pipeMatch && !negativeExp) || !string) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -76,7 +79,7 @@ export function getHighlighterExpressionsFromQuery(input: string): string[] { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (resultTerm) { |
|
|
|
if (resultTerm) { |
|
|
|
results.push(resultTerm); |
|
|
|
results.push(negativeExp ? `-${resultTerm}` : resultTerm); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return results; |
|
|
|
return results; |
|
|
|