Skip to content

Commit

Permalink
[KQL] Remove number parsing (elastic#93658)
Browse files Browse the repository at this point in the history
* [KQL] Remove number parsing

* Update test snapshots
  • Loading branch information
lukasolson committed Mar 9, 2021
1 parent b2f95a1 commit 67fe6cf
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 43 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 18 additions & 19 deletions src/plugins/data/common/es_query/kuery/ast/ast.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ describe('kuery AST API', () => {
test('should support exclusive range operators', () => {
const expected = nodeTypes.function.buildNode('and', [
nodeTypes.function.buildNode('range', 'bytes', {
gt: 1000,
gt: '1000',
}),
nodeTypes.function.buildNode('range', 'bytes', {
lt: 8000,
lt: '8000',
}),
]);
const actual = fromKueryExpression('bytes > 1000 and bytes < 8000');
Expand All @@ -181,10 +181,10 @@ describe('kuery AST API', () => {
test('should support inclusive range operators', () => {
const expected = nodeTypes.function.buildNode('and', [
nodeTypes.function.buildNode('range', 'bytes', {
gte: 1000,
gte: '1000',
}),
nodeTypes.function.buildNode('range', 'bytes', {
lte: 8000,
lte: '8000',
}),
]);
const actual = fromKueryExpression('bytes >= 1000 and bytes <= 8000');
Expand Down Expand Up @@ -279,25 +279,24 @@ describe('kuery AST API', () => {
const stringLiteral = nodeTypes.literal.buildNode('foo');
const booleanFalseLiteral = nodeTypes.literal.buildNode(false);
const booleanTrueLiteral = nodeTypes.literal.buildNode(true);
const numberLiteral = nodeTypes.literal.buildNode(42);

expect(fromLiteralExpression('foo')).toEqual(stringLiteral);
expect(fromLiteralExpression('true')).toEqual(booleanTrueLiteral);
expect(fromLiteralExpression('false')).toEqual(booleanFalseLiteral);
expect(fromLiteralExpression('42')).toEqual(numberLiteral);

expect(fromLiteralExpression('.3').value).toEqual(0.3);
expect(fromLiteralExpression('.36').value).toEqual(0.36);
expect(fromLiteralExpression('.00001').value).toEqual(0.00001);
expect(fromLiteralExpression('3').value).toEqual(3);
expect(fromLiteralExpression('-4').value).toEqual(-4);
expect(fromLiteralExpression('0').value).toEqual(0);
expect(fromLiteralExpression('0.0').value).toEqual(0);
expect(fromLiteralExpression('2.0').value).toEqual(2.0);
expect(fromLiteralExpression('0.8').value).toEqual(0.8);
expect(fromLiteralExpression('790.9').value).toEqual(790.9);
expect(fromLiteralExpression('0.0001').value).toEqual(0.0001);
expect(fromLiteralExpression('96565646732345').value).toEqual(96565646732345);

expect(fromLiteralExpression('.3').value).toEqual('.3');
expect(fromLiteralExpression('.36').value).toEqual('.36');
expect(fromLiteralExpression('.00001').value).toEqual('.00001');
expect(fromLiteralExpression('3').value).toEqual('3');
expect(fromLiteralExpression('-4').value).toEqual('-4');
expect(fromLiteralExpression('0').value).toEqual('0');
expect(fromLiteralExpression('0.0').value).toEqual('0.0');
expect(fromLiteralExpression('2.0').value).toEqual('2.0');
expect(fromLiteralExpression('0.8').value).toEqual('0.8');
expect(fromLiteralExpression('790.9').value).toEqual('790.9');
expect(fromLiteralExpression('0.0001').value).toEqual('0.0001');
expect(fromLiteralExpression('96565646732345').value).toEqual('96565646732345');
expect(fromLiteralExpression('070').value).toEqual('070');

expect(fromLiteralExpression('..4').value).toEqual('..4');
expect(fromLiteralExpression('.3text').value).toEqual('.3text');
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/data/common/es_query/kuery/ast/kuery.peg
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ UnquotedLiteral
if (sequence === 'true') return buildLiteralNode(true);
if (sequence === 'false') return buildLiteralNode(false);
if (chars.includes(wildcardSymbol)) return buildWildcardNode(sequence);
const isNumberPattern = /^(-?[1-9]+\d*([.]\d+)?)$|^(-?0[.]\d*[1-9]+)$|^0$|^0.0$|^[.]\d{1,}$/
return buildLiteralNode(isNumberPattern.test(sequence) ? Number(sequence) : sequence);
return buildLiteralNode(sequence);
}

UnquotedCharacter
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data/common/search/aggs/buckets/filters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe('Filters Agg', () => {
"should": Array [
Object {
"match": Object {
"field": 200,
"field": "200",
},
},
],
Expand All @@ -171,7 +171,7 @@ describe('Filters Agg', () => {
Object {
"range": Object {
"field": Object {
"gt": 500,
"gt": "500",
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ describe('get_filter', () => {
"should": Array [
Object {
"match": Object {
"suricata.eve.alert.signature_id": 2610182,
"suricata.eve.alert.signature_id": "2610182",
},
},
],
Expand All @@ -1040,7 +1040,7 @@ describe('get_filter', () => {
"should": Array [
Object {
"match": Object {
"suricata.eve.alert.signature_id": 2610183,
"suricata.eve.alert.signature_id": "2610183",
},
},
],
Expand All @@ -1052,7 +1052,7 @@ describe('get_filter', () => {
"should": Array [
Object {
"match": Object {
"suricata.eve.alert.signature_id": 2610184,
"suricata.eve.alert.signature_id": "2610184",
},
},
],
Expand All @@ -1064,7 +1064,7 @@ describe('get_filter', () => {
"should": Array [
Object {
"match": Object {
"suricata.eve.alert.signature_id": 2610185,
"suricata.eve.alert.signature_id": "2610185",
},
},
],
Expand All @@ -1076,7 +1076,7 @@ describe('get_filter', () => {
"should": Array [
Object {
"match": Object {
"suricata.eve.alert.signature_id": 2610186,
"suricata.eve.alert.signature_id": "2610186",
},
},
],
Expand All @@ -1088,7 +1088,7 @@ describe('get_filter', () => {
"should": Array [
Object {
"match": Object {
"suricata.eve.alert.signature_id": 2610187,
"suricata.eve.alert.signature_id": "2610187",
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ describe('Combined Queries', () => {
kqlQuery: { query: '', language: 'kuery' },
kqlMode: 'search',
})!;
expect(filterQuery).toEqual(
'{"bool":{"must":[],"filter":[{"bool":{"should":[{"range":{"@timestamp":{"gte":1521848183232,"lte":1521848183232}}}],"minimum_should_match":1}}],"should":[],"must_not":[]}}'
expect(filterQuery).toMatchInlineSnapshot(
`"{\\"bool\\":{\\"must\\":[],\\"filter\\":[{\\"bool\\":{\\"should\\":[{\\"range\\":{\\"@timestamp\\":{\\"gte\\":\\"1521848183232\\",\\"lte\\":\\"1521848183232\\"}}}],\\"minimum_should_match\\":1}}],\\"should\\":[],\\"must_not\\":[]}}"`
);
});

Expand All @@ -350,8 +350,8 @@ describe('Combined Queries', () => {
kqlQuery: { query: '', language: 'kuery' },
kqlMode: 'search',
})!;
expect(filterQuery).toEqual(
'{"bool":{"must":[],"filter":[{"bool":{"should":[{"range":{"@timestamp":{"gte":1521848183232,"lte":1521848183232}}}],"minimum_should_match":1}}],"should":[],"must_not":[]}}'
expect(filterQuery).toMatchInlineSnapshot(
`"{\\"bool\\":{\\"must\\":[],\\"filter\\":[{\\"bool\\":{\\"should\\":[{\\"range\\":{\\"@timestamp\\":{\\"gte\\":\\"1521848183232\\",\\"lte\\":\\"1521848183232\\"}}}],\\"minimum_should_match\\":1}}],\\"should\\":[],\\"must_not\\":[]}}"`
);
});

Expand All @@ -368,8 +368,8 @@ describe('Combined Queries', () => {
kqlQuery: { query: '', language: 'kuery' },
kqlMode: 'search',
})!;
expect(filterQuery).toEqual(
'{"bool":{"must":[],"filter":[{"bool":{"should":[{"match":{"event.end":1521848183232}}],"minimum_should_match":1}}],"should":[],"must_not":[]}}'
expect(filterQuery).toMatchInlineSnapshot(
`"{\\"bool\\":{\\"must\\":[],\\"filter\\":[{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"event.end\\":\\"1521848183232\\"}}],\\"minimum_should_match\\":1}}],\\"should\\":[],\\"must_not\\":[]}}"`
);
});

Expand All @@ -386,8 +386,8 @@ describe('Combined Queries', () => {
kqlQuery: { query: '', language: 'kuery' },
kqlMode: 'search',
})!;
expect(filterQuery).toEqual(
'{"bool":{"must":[],"filter":[{"bool":{"should":[{"match":{"event.end":1521848183232}}],"minimum_should_match":1}}],"should":[],"must_not":[]}}'
expect(filterQuery).toMatchInlineSnapshot(
`"{\\"bool\\":{\\"must\\":[],\\"filter\\":[{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"event.end\\":\\"1521848183232\\"}}],\\"minimum_should_match\\":1}}],\\"should\\":[],\\"must_not\\":[]}}"`
);
});

Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/uptime/server/lib/alerts/status_check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ describe('status check alert', () => {
"should": Array [
Object {
"match": Object {
"url.port": 12349,
"url.port": "12349",
},
},
],
Expand All @@ -366,7 +366,7 @@ describe('status check alert', () => {
"should": Array [
Object {
"match": Object {
"url.port": 5601,
"url.port": "5601",
},
},
],
Expand All @@ -378,7 +378,7 @@ describe('status check alert', () => {
"should": Array [
Object {
"match": Object {
"url.port": 443,
"url.port": "443",
},
},
],
Expand Down Expand Up @@ -735,7 +735,7 @@ describe('status check alert', () => {
expect(mockAvailability.mock.calls[0]).toMatchInlineSnapshot(`
Array [
Object {
"filters": "{\\"bool\\":{\\"filter\\":[{\\"bool\\":{\\"should\\":[{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"url.port\\":12349}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"url.port\\":5601}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"url.port\\":443}}],\\"minimum_should_match\\":1}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"observer.geo.name\\":\\"harrisburg\\"}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"monitor.type\\":\\"http\\"}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"tags\\":\\"unsecured\\"}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"tags\\":\\"containers\\"}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"match_phrase\\":{\\"tags\\":\\"org:google\\"}}],\\"minimum_should_match\\":1}}],\\"minimum_should_match\\":1}}]}}",
"filters": "{\\"bool\\":{\\"filter\\":[{\\"bool\\":{\\"should\\":[{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"url.port\\":\\"12349\\"}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"url.port\\":\\"5601\\"}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"url.port\\":\\"443\\"}}],\\"minimum_should_match\\":1}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"observer.geo.name\\":\\"harrisburg\\"}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"monitor.type\\":\\"http\\"}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"tags\\":\\"unsecured\\"}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"tags\\":\\"containers\\"}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"match_phrase\\":{\\"tags\\":\\"org:google\\"}}],\\"minimum_should_match\\":1}}],\\"minimum_should_match\\":1}}]}}",
"range": 35,
"rangeUnit": "d",
"threshold": "99.34",
Expand Down

0 comments on commit 67fe6cf

Please sign in to comment.