mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: Parse query with unwrap (#47282)
* Loki: Parse simple unwrap * Update public/app/plugins/datasource/loki/querybuilder/parsing.ts * Simplify
This commit is contained in:
@@ -142,6 +142,27 @@ describe('buildVisualQueryFromString', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('parses query with with simple unwrap', () => {
|
||||||
|
expect(
|
||||||
|
buildVisualQueryFromString('sum_over_time({app="frontend"} | logfmt | unwrap bytes_processed [1m])')
|
||||||
|
).toEqual(
|
||||||
|
noErrors({
|
||||||
|
labels: [
|
||||||
|
{
|
||||||
|
op: '=',
|
||||||
|
value: 'frontend',
|
||||||
|
label: 'app',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
operations: [
|
||||||
|
{ id: 'logfmt', params: [] },
|
||||||
|
{ id: 'unwrap', params: ['bytes_processed'] },
|
||||||
|
{ id: 'sum_over_time', params: ['1m'] },
|
||||||
|
],
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('parses metrics query with function', () => {
|
it('parses metrics query with function', () => {
|
||||||
expect(buildVisualQueryFromString('rate({app="frontend"} | json [5m])')).toEqual(
|
expect(buildVisualQueryFromString('rate({app="frontend"} | json [5m])')).toEqual(
|
||||||
noErrors({
|
noErrors({
|
||||||
|
|||||||
@@ -84,6 +84,11 @@ export function handleExpression(expr: string, node: SyntaxNode, context: Contex
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 'UnwrapExpr': {
|
||||||
|
visQuery.operations.push(getUnwrap(expr, node));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 'RangeAggregationExpr': {
|
case 'RangeAggregationExpr': {
|
||||||
visQuery.operations.push(handleRangeAggregation(expr, node, context));
|
visQuery.operations.push(handleRangeAggregation(expr, node, context));
|
||||||
break;
|
break;
|
||||||
@@ -241,6 +246,16 @@ function getLabelFormat(expr: string, node: SyntaxNode): QueryBuilderOperation {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getUnwrap(expr: string, node: SyntaxNode): QueryBuilderOperation {
|
||||||
|
const id = 'unwrap';
|
||||||
|
const string = getString(expr, node.getChild('Identifier'));
|
||||||
|
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
params: [string],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function handleRangeAggregation(expr: string, node: SyntaxNode, context: Context) {
|
function handleRangeAggregation(expr: string, node: SyntaxNode, context: Context) {
|
||||||
const nameNode = node.getChild('RangeOp');
|
const nameNode = node.getChild('RangeOp');
|
||||||
const funcName = getString(expr, nameNode);
|
const funcName = getString(expr, nameNode);
|
||||||
|
|||||||
Reference in New Issue
Block a user