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:
@@ -73,7 +73,7 @@ describe('LokiQueryModeller', () => {
|
|||||||
labels: [{ label: 'app', op: '=', value: 'grafana' }],
|
labels: [{ label: 'app', op: '=', value: 'grafana' }],
|
||||||
operations: [{ id: LokiOperationId.LineContains, params: [''] }],
|
operations: [{ id: LokiOperationId.LineContains, params: [''] }],
|
||||||
})
|
})
|
||||||
).toBe('{app="grafana"}');
|
).toBe('{app="grafana"} |= ``');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Can query with line filter contains not operation', () => {
|
it('Can query with line filter contains not operation', () => {
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ export class LokiQueryModeller extends LokiAndPromQueryModellerBase {
|
|||||||
{ id: LokiOperationId.LineContains, params: [''] },
|
{ id: LokiOperationId.LineContains, params: [''] },
|
||||||
{ id: LokiOperationId.Logfmt, params: [] },
|
{ id: LokiOperationId.Logfmt, params: [] },
|
||||||
{ id: LokiOperationId.LabelFilterNoErrors, params: [] },
|
{ id: LokiOperationId.LabelFilterNoErrors, params: [] },
|
||||||
{ id: LokiOperationId.Unwrap, params: [] },
|
{ id: LokiOperationId.Unwrap, params: [''] },
|
||||||
{ id: LokiOperationId.LabelFilterNoErrors, params: [] },
|
{ id: LokiOperationId.LabelFilterNoErrors, params: [] },
|
||||||
{ id: LokiOperationId.SumOverTime, params: ['$__interval'] },
|
{ id: LokiOperationId.SumOverTime, params: ['$__interval'] },
|
||||||
{ id: LokiOperationId.Sum, params: [] },
|
{ id: LokiOperationId.Sum, params: [] },
|
||||||
@@ -106,7 +106,7 @@ export class LokiQueryModeller extends LokiAndPromQueryModellerBase {
|
|||||||
operations: [
|
operations: [
|
||||||
{ id: LokiOperationId.LineContains, params: [''] },
|
{ id: LokiOperationId.LineContains, params: [''] },
|
||||||
{ id: LokiOperationId.CountOverTime, params: ['$__interval'] },
|
{ 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',
|
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: [
|
operations: [
|
||||||
{ id: LokiOperationId.Logfmt, params: [] },
|
{ id: LokiOperationId.Logfmt, params: [] },
|
||||||
{ id: LokiOperationId.LabelFilterNoErrors, params: [] },
|
{ id: LokiOperationId.LabelFilterNoErrors, params: [] },
|
||||||
|
|||||||
@@ -400,9 +400,6 @@ function operationWithRangeVectorRendererAndParam(
|
|||||||
|
|
||||||
function getLineFilterRenderer(operation: string) {
|
function getLineFilterRenderer(operation: string) {
|
||||||
return function lineFilterRenderer(model: QueryBuilderOperation, def: QueryBuilderOperationDef, innerExpr: string) {
|
return function lineFilterRenderer(model: QueryBuilderOperation, def: QueryBuilderOperationDef, innerExpr: string) {
|
||||||
if (model.params[0] === '') {
|
|
||||||
return innerExpr;
|
|
||||||
}
|
|
||||||
return `${innerExpr} ${operation} \`${model.params[0]}\``;
|
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', () => {
|
it('parses template variables in strings', () => {
|
||||||
expect(buildVisualQueryFromString('{instance="$label_variable"}')).toEqual(
|
expect(buildVisualQueryFromString('{instance="$label_variable"}')).toEqual(
|
||||||
noErrors({
|
noErrors({
|
||||||
|
|||||||
@@ -360,7 +360,13 @@ function handleVectorAggregation(expr: string, node: SyntaxNode, context: Contex
|
|||||||
let funcName = getString(expr, nameNode);
|
let funcName = getString(expr, nameNode);
|
||||||
|
|
||||||
const grouping = node.getChild('Grouping');
|
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) {
|
if (grouping) {
|
||||||
const byModifier = grouping.getChild(`By`);
|
const byModifier = grouping.getChild(`By`);
|
||||||
@@ -373,11 +379,11 @@ function handleVectorAggregation(expr: string, node: SyntaxNode, context: Contex
|
|||||||
funcName = `__${funcName}_without`;
|
funcName = `__${funcName}_without`;
|
||||||
}
|
}
|
||||||
|
|
||||||
labels.push(...getAllByType(expr, grouping, 'Identifier'));
|
params.push(...getAllByType(expr, grouping, 'Identifier'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const metricExpr = node.getChild('MetricExpr');
|
const metricExpr = node.getChild('MetricExpr');
|
||||||
const op: QueryBuilderOperation = { id: funcName, params: labels };
|
const op: QueryBuilderOperation = { id: funcName, params };
|
||||||
|
|
||||||
if (metricExpr) {
|
if (metricExpr) {
|
||||||
handleExpression(expr, metricExpr, context);
|
handleExpression(expr, metricExpr, context);
|
||||||
|
|||||||
Reference in New Issue
Block a user