mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
Loki: Fix issues with using query patterns (#50414)
* WIP * Loki: Fix running of query patterns * Remove console.log * Add test * Update empty line filter test
This commit is contained in:
parent
1231e0dd69
commit
88279dda1c
@ -73,7 +73,7 @@ describe('LokiQueryModeller', () => {
|
||||
labels: [{ label: 'app', op: '=', value: 'grafana' }],
|
||||
operations: [{ id: LokiOperationId.LineContains, params: [''] }],
|
||||
})
|
||||
).toBe('{app="grafana"}');
|
||||
).toBe('{app="grafana"} |= ``');
|
||||
});
|
||||
|
||||
it('Can query with line filter contains not operation', () => {
|
||||
|
@ -94,7 +94,7 @@ export class LokiQueryModeller extends LokiAndPromQueryModellerBase {
|
||||
{ id: LokiOperationId.LineContains, params: [''] },
|
||||
{ id: LokiOperationId.Logfmt, params: [] },
|
||||
{ id: LokiOperationId.LabelFilterNoErrors, params: [] },
|
||||
{ id: LokiOperationId.Unwrap, params: [] },
|
||||
{ id: LokiOperationId.Unwrap, params: [''] },
|
||||
{ id: LokiOperationId.LabelFilterNoErrors, params: [] },
|
||||
{ id: LokiOperationId.SumOverTime, params: ['$__interval'] },
|
||||
{ id: LokiOperationId.Sum, params: [] },
|
||||
@ -106,7 +106,7 @@ export class LokiQueryModeller extends LokiAndPromQueryModellerBase {
|
||||
operations: [
|
||||
{ id: LokiOperationId.LineContains, params: [''] },
|
||||
{ id: LokiOperationId.CountOverTime, params: ['$__interval'] },
|
||||
{ id: LokiOperationId.Sum, params: ['label'] },
|
||||
{ id: LokiOperationId.Sum, params: [] },
|
||||
],
|
||||
},
|
||||
{
|
||||
@ -149,7 +149,7 @@ export class LokiQueryModeller extends LokiAndPromQueryModellerBase {
|
||||
},
|
||||
{
|
||||
name: 'Metrics query for extracted quantile',
|
||||
// quantile_over_time(0.99,{} | logfmt | unwrap latency[$__interval]) by ()
|
||||
// quantile_over_time(0.5,{} | logfmt | unwrap latency[$__interval]) by ()
|
||||
operations: [
|
||||
{ id: LokiOperationId.Logfmt, params: [] },
|
||||
{ id: LokiOperationId.LabelFilterNoErrors, params: [] },
|
||||
|
@ -400,9 +400,6 @@ function operationWithRangeVectorRendererAndParam(
|
||||
|
||||
function getLineFilterRenderer(operation: string) {
|
||||
return function lineFilterRenderer(model: QueryBuilderOperation, def: QueryBuilderOperationDef, innerExpr: string) {
|
||||
if (model.params[0] === '') {
|
||||
return innerExpr;
|
||||
}
|
||||
return `${innerExpr} ${operation} \`${model.params[0]}\``;
|
||||
};
|
||||
}
|
||||
|
@ -374,6 +374,29 @@ describe('buildVisualQueryFromString', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('parses metrics query with vector aggregation with number', () => {
|
||||
expect(
|
||||
buildVisualQueryFromString('topk(10, sum(count_over_time({app="frontend"} | logfmt | __error__=`` [5m])))')
|
||||
).toEqual(
|
||||
noErrors({
|
||||
labels: [
|
||||
{
|
||||
op: '=',
|
||||
value: 'frontend',
|
||||
label: 'app',
|
||||
},
|
||||
],
|
||||
operations: [
|
||||
{ id: 'logfmt', params: [] },
|
||||
{ id: '__label_filter_no_errors', params: [] },
|
||||
{ id: 'count_over_time', params: ['5m'] },
|
||||
{ id: 'sum', params: [] },
|
||||
{ id: 'topk', params: [10] },
|
||||
],
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('parses template variables in strings', () => {
|
||||
expect(buildVisualQueryFromString('{instance="$label_variable"}')).toEqual(
|
||||
noErrors({
|
||||
|
@ -360,7 +360,13 @@ function handleVectorAggregation(expr: string, node: SyntaxNode, context: Contex
|
||||
let funcName = getString(expr, nameNode);
|
||||
|
||||
const grouping = node.getChild('Grouping');
|
||||
const labels: string[] = [];
|
||||
const params = [];
|
||||
|
||||
const numberNode = node.getChild('Number');
|
||||
|
||||
if (numberNode) {
|
||||
params.push(Number(getString(expr, numberNode)));
|
||||
}
|
||||
|
||||
if (grouping) {
|
||||
const byModifier = grouping.getChild(`By`);
|
||||
@ -373,11 +379,11 @@ function handleVectorAggregation(expr: string, node: SyntaxNode, context: Contex
|
||||
funcName = `__${funcName}_without`;
|
||||
}
|
||||
|
||||
labels.push(...getAllByType(expr, grouping, 'Identifier'));
|
||||
params.push(...getAllByType(expr, grouping, 'Identifier'));
|
||||
}
|
||||
|
||||
const metricExpr = node.getChild('MetricExpr');
|
||||
const op: QueryBuilderOperation = { id: funcName, params: labels };
|
||||
const op: QueryBuilderOperation = { id: funcName, params };
|
||||
|
||||
if (metricExpr) {
|
||||
handleExpression(expr, metricExpr, context);
|
||||
|
Loading…
Reference in New Issue
Block a user