Loki: Implement keep and drop operations (#73636)

* Update lezer

* Add functionalities for code and builder

* Add comment
This commit is contained in:
Ivana Huckova
2023-08-23 14:52:19 +02:00
committed by GitHub
parent 356d8872bd
commit fc9b8f6be1
10 changed files with 341 additions and 6 deletions

View File

@@ -776,6 +776,96 @@ describe('buildVisualQueryFromString', () => {
})
);
});
it('parses a log query with drop and no labels', () => {
expect(buildVisualQueryFromString('{app="frontend"} | drop')).toEqual(
noErrors({
labels: [
{
op: '=',
value: 'frontend',
label: 'app',
},
],
operations: [{ id: LokiOperationId.Drop, params: [] }],
})
);
});
it('parses a log query with drop and labels', () => {
expect(buildVisualQueryFromString('{app="frontend"} | drop id, email')).toEqual(
noErrors({
labels: [
{
op: '=',
value: 'frontend',
label: 'app',
},
],
operations: [{ id: LokiOperationId.Drop, params: ['id', 'email'] }],
})
);
});
it('parses a log query with drop, labels and expressions', () => {
expect(buildVisualQueryFromString('{app="frontend"} | drop id, email, test="test1"')).toEqual(
noErrors({
labels: [
{
op: '=',
value: 'frontend',
label: 'app',
},
],
operations: [{ id: LokiOperationId.Drop, params: ['id', 'email', 'test="test1"'] }],
})
);
});
it('parses a log query with keep and no labels', () => {
expect(buildVisualQueryFromString('{app="frontend"} | keep')).toEqual(
noErrors({
labels: [
{
op: '=',
value: 'frontend',
label: 'app',
},
],
operations: [{ id: LokiOperationId.Keep, params: [] }],
})
);
});
it('parses a log query with keep and labels', () => {
expect(buildVisualQueryFromString('{app="frontend"} | keep id, email')).toEqual(
noErrors({
labels: [
{
op: '=',
value: 'frontend',
label: 'app',
},
],
operations: [{ id: LokiOperationId.Keep, params: ['id', 'email'] }],
})
);
});
it('parses a log query with keep, labels and expressions', () => {
expect(buildVisualQueryFromString('{app="frontend"} | keep id, email, test="test1"')).toEqual(
noErrors({
labels: [
{
op: '=',
value: 'frontend',
label: 'app',
},
],
operations: [{ id: LokiOperationId.Keep, params: ['id', 'email', 'test="test1"'] }],
})
);
});
});
function noErrors(query: LokiVisualQuery) {