Skip to content

Commit cb983a9

Browse files
authored
EQL: Refine repeatable queries (#78895)
Allow individual queries within a sequence to be repeated through a dedicated keyword without having physical duplication. Change from using [runs=2] to "with runs=2" Before: sequence queryA [runs=2] queryB queryC [runs=3] queryD Now: sequence queryA with runs=2 queryB queryC with runs=3 queryD Which essentially is the same as: sequence queryA queryA queryB queryC queryC queryC queryD but more concise. Supersedes #75082
1 parent c2fd94f commit cb983a9

File tree

7 files changed

+241
-245
lines changed

7 files changed

+241
-245
lines changed

x-pack/plugin/eql/qa/common/src/main/resources/additional_test_queries.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ expected_event_ids = [
241241
name = "sequenceWithMoreThan10Results-Runs"
242242
query = '''
243243
sequence by unique_pid
244-
[any where true] [runs=2]
244+
[any where true] with runs=2
245245
[any where serial_event_id < 72]
246246
'''
247247
expected_event_ids = [

x-pack/plugin/eql/qa/common/src/main/resources/test_queries.toml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ name = "sequenceOneManyMany-Runs"
561561
query = '''
562562
sequence
563563
[process where serial_event_id == 1]
564-
[process where true] [runs=2]
564+
[process where true] with runs=2
565565
'''
566566
expected_event_ids = [1, 2, 3]
567567

@@ -582,7 +582,7 @@ name = "sequenceConditionManyMany-Runs"
582582
query = '''
583583
sequence
584584
[process where serial_event_id <= 3]
585-
[process where true] [runs=2]
585+
[process where true] with runs=2
586586
'''
587587
expected_event_ids = [1, 2, 3,
588588
2, 3, 4,
@@ -613,7 +613,7 @@ expected_event_ids = [1, 2, 3]
613613
name = "sequenceManyManyCondition-Runs"
614614
query = '''
615615
sequence
616-
[process where true] [runs=2]
616+
[process where true] with runs=2
617617
[process where serial_event_id <= 3]
618618
'''
619619
expected_event_ids = [1, 2, 3]
@@ -637,7 +637,7 @@ name = "sequenceThreeManyCondition1-Runs"
637637
query = '''
638638
sequence
639639
[process where serial_event_id <= 4]
640-
[process where true] [runs=3]
640+
[process where true] with runs=3
641641
'''
642642
expected_event_ids = [1, 2, 3, 4,
643643
2, 3, 4, 5,
@@ -663,7 +663,7 @@ query = '''
663663
sequence
664664
[process where true]
665665
[process where serial_event_id <= 4]
666-
[process where true] [runs=2]
666+
[process where true] with runs=2
667667
'''
668668
expected_event_ids = [1, 2, 3, 4,
669669
2, 3, 4, 5,
@@ -685,7 +685,7 @@ expected_event_ids = [1, 2, 3, 4,
685685
name = "sequenceThreeManyCondition3-Runs"
686686
query = '''
687687
sequence
688-
[process where true] [runs=2]
688+
[process where true] with runs=2
689689
[process where serial_event_id <= 4]
690690
[process where true]
691691
'''
@@ -707,7 +707,7 @@ expected_event_ids = [1, 2, 3, 4]
707707
name = "sequenceThreeManyCondition4-Runs"
708708
query = '''
709709
sequence
710-
[process where true] [runs=3]
710+
[process where true] with runs=3
711711
[process where serial_event_id <= 4]
712712
'''
713713
expected_event_ids = [1, 2, 3, 4]
@@ -754,7 +754,7 @@ name = "fourSequencesByPidWithUntil1-Runs"
754754
query = '''
755755
sequence
756756
[process where opcode == 1] by unique_pid
757-
[file where opcode == 0] by unique_pid [runs=3]
757+
[file where opcode == 0] by unique_pid with runs=3
758758
until
759759
[file where opcode == 2] by unique_pid
760760
'''
@@ -779,7 +779,7 @@ name = "fourSequencesByPidWithUntil2-Runs"
779779
query = '''
780780
sequence
781781
[process where opcode == 1] by unique_pid
782-
[file where opcode == 0] by unique_pid [runs=3]
782+
[file where opcode == 0] by unique_pid with runs=3
783783
until
784784
[file where opcode == 200] by unique_pid
785785
'''
@@ -813,7 +813,7 @@ name = "fourSequencesByPid-Runs"
813813
query = '''
814814
sequence
815815
[process where opcode == 1] by unique_pid
816-
[file where opcode == 0] by unique_pid [runs=3]
816+
[file where opcode == 0] by unique_pid with runs=3
817817
'''
818818
expected_event_ids = [54, 55, 61, 67]
819819

@@ -834,7 +834,7 @@ name = "fourSequencesByPidAndProcessPath1-Runs"
834834
query = '''
835835
sequence
836836
[process where opcode == 1] by unique_pid, process_path
837-
[file where opcode == 0] by unique_pid, process_path [runs=3]
837+
[file where opcode == 0] by unique_pid, process_path with runs=3
838838
'''
839839
expected_event_ids = [54, 55, 61, 67]
840840

@@ -856,7 +856,7 @@ name = "fourSequencesByPidAndProcessPathWithUntil-Runs"
856856
query = '''
857857
sequence
858858
[process where opcode == 1] by unique_pid, process_path
859-
[file where opcode == 0] by unique_pid, process_path [runs=3]
859+
[file where opcode == 0] by unique_pid, process_path with runs=3
860860
until
861861
[file where opcode == 200] by unique_pid, process_path
862862
'''
@@ -867,8 +867,8 @@ name = "fourSequencesByPidAndProcessPathWithUntil-RunsExtra"
867867
query = '''
868868
sequence
869869
[process where opcode == 1] by unique_pid, process_path
870-
[file where opcode == 0] by unique_pid, process_path [runs=2]
871-
[file where opcode == 0] by unique_pid, process_path [runs=1]
870+
[file where opcode == 0] by unique_pid, process_path with runs=2
871+
[file where opcode == 0] by unique_pid, process_path with runs=1
872872
until
873873
[file where opcode == 200] by unique_pid, process_path
874874
'''
@@ -1026,7 +1026,7 @@ expected_event_ids = [1, 2,
10261026
name = "doubleSameSequence-Runs"
10271027
query = '''
10281028
sequence
1029-
[process where serial_event_id < 5] [runs=2]
1029+
[process where serial_event_id < 5] with runs=2
10301030
'''
10311031
expected_event_ids = [1, 2,
10321032
2, 3,
@@ -1056,7 +1056,7 @@ expected_event_ids = [55, 61]
10561056
name = "doubleSameSequenceWithBy-Runs"
10571057
query = '''
10581058
sequence
1059-
[file where opcode==0] by unique_pid [runs=2]
1059+
[file where opcode==0] by unique_pid with runs=2
10601060
| head 1
10611061
'''
10621062
expected_event_ids = [55, 61]
@@ -1087,7 +1087,7 @@ expected_event_ids = [55, 61]
10871087
name = "doubleSameSequenceWithByUntilAndHead1-Runs"
10881088
query = '''
10891089
sequence
1090-
[file where opcode==0 and file_name:"*.exe"] by unique_pid [runs=2]
1090+
[file where opcode==0 and file_name:"*.exe"] by unique_pid with runs=2
10911091
until [process where opcode==5000] by unique_ppid
10921092
| head 1
10931093
'''
@@ -1108,7 +1108,7 @@ expected_event_ids = []
11081108
name = "doubleSameSequenceWithByUntilAndHead2-Runs"
11091109
query = '''
11101110
sequence
1111-
[file where opcode==0 and file_name:"*.exe"] by unique_pid [runs=2]
1111+
[file where opcode==0 and file_name:"*.exe"] by unique_pid with runs=2
11121112
until [process where opcode==1] by unique_ppid
11131113
| head 1
11141114
'''

x-pack/plugin/eql/qa/correctness/src/javaRestTest/resources/queries.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ filters = [
396396
]
397397
query = '''
398398
sequence by source_address, hostname with maxspan=5s
399-
[security where hostname != "newyork" and event_id == 4625] [runs=4]
399+
[security where hostname != "newyork" and event_id == 4625] with runs=4
400400
'''
401401
time = 2.8286166191101074
402402
type = "sequence"
@@ -433,7 +433,7 @@ filters = [
433433
]
434434
query = '''
435435
sequence by source_address, hostname with maxspan=10s
436-
[security where hostname != "newyork" and event_id == 4625] [runs=3]
436+
[security where hostname != "newyork" and event_id == 4625] with runs=3
437437
'''
438438
time = 2.765869617462158
439439
type = "sequence"

x-pack/plugin/eql/src/main/antlr/EqlBase.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ joinTerm
5656
;
5757

5858
sequenceTerm
59-
: subquery (by=joinKeys)? (LB key=IDENTIFIER ASGN value=number RB)?
59+
: subquery (by=joinKeys)? (WITH key=IDENTIFIER ASGN value=number)?
6060
;
6161

6262
subquery

0 commit comments

Comments
 (0)