Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/103611.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 103611
summary: Fix NPE on missing event queries
area: EQL
type: bug
issues:
- 103608
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,16 @@ join_keys = ["foo", "foo",
"foo", "foo",
"baz", "baz"]

[[queries]]
name = "interleaved_3_missing"
query = '''
sequence with maxspan=1h
![ test1 where tag == "foobar" ]
[ test1 where tag == "normal" ]
![ test1 where tag == "foobar" ]
[ test1 where tag == "normal" ]
![ test1 where tag == "foobar" ]
'''
expected_event_ids = [-1, 1, -1, 2, -1,
-1, 2, -1, 4, -1]

Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ public class Sequence implements Comparable<Sequence>, Accountable {

private final SequenceKey key;
private final Match[] matches;
private int firstStage;
private int currentStage = 0;

@SuppressWarnings({ "rawtypes", "unchecked" })
public Sequence(SequenceKey key, int stages, Ordinal ordinal, HitReference firstHit) {
public Sequence(SequenceKey key, int stages, int firstStage, Ordinal ordinal, HitReference firstHit) {
Check.isTrue(stages >= 2, "A sequence requires at least 2 criteria, given [{}]", stages);
this.key = key;
this.matches = new Match[stages];
this.matches[0] = new Match(ordinal, firstHit);
this.matches[firstStage] = new Match(ordinal, firstHit);
this.firstStage = firstStage;
this.currentStage = firstStage;
}

public void putMatch(int stage, Ordinal ordinal, HitReference hit) {
Expand All @@ -56,7 +59,7 @@ public Ordinal ordinal() {
}

public Ordinal startOrdinal() {
return matches[0].ordinal();
return matches[firstStage].ordinal();
}

public List<HitReference> hits() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ boolean match(int stage, Iterable<Tuple<KeyAndOrdinal, HitReference>> hits) {

if (isFirstPositiveStage(stage)) {
log.trace("Matching hit {} - track sequence", ko.ordinal);
Sequence seq = new Sequence(ko.key, numberOfStages, ko.ordinal, hit);
Sequence seq = new Sequence(ko.key, numberOfStages, stage, ko.ordinal, hit);
if (lastPositiveStage == stage) {
tryComplete(seq);
} else {
Expand Down