Skip to content

Commit b542ec6

Browse files
committed
perf(rule_engine,filter): Improve bound sequences
Refactor bound sequence evaluation logic to speed it up, most notably, by deferring the field hash calculation only when the event matches. Furthermore, the accessor is tied to the bound field avoiding iteration across filter's registered accessors.
1 parent 9b06895 commit b542ec6

File tree

4 files changed

+272
-190
lines changed

4 files changed

+272
-190
lines changed

pkg/filter/accessor.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (*evtAccessor) Get(f Field, evt *event.Event) (params.Value, error) {
153153
// referenced in the bound field.
154154
func (f *filter) narrowAccessors() {
155155
var (
156-
removeKevtAccessor = true
156+
removeEvtAccessor = true
157157
removePsAccessor = true
158158
removeThreadAccessor = true
159159
removeImageAccessor = true
@@ -169,8 +169,8 @@ func (f *filter) narrowAccessors() {
169169

170170
for _, field := range f.fields {
171171
switch {
172-
case field.Name.IsKevtField():
173-
removeKevtAccessor = false
172+
case field.Name.IsKevtField(), field.Name.IsEvtField():
173+
removeEvtAccessor = false
174174
case field.Name.IsPsField():
175175
removePsAccessor = false
176176
case field.Name.IsThreadField():
@@ -196,7 +196,7 @@ func (f *filter) narrowAccessors() {
196196
}
197197
}
198198

199-
if removeKevtAccessor {
199+
if removeEvtAccessor {
200200
f.removeAccessor(&evtAccessor{})
201201
}
202202
if removePsAccessor {

pkg/filter/fields/fields_windows.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,8 @@ func (f Field) String() string { return string(f) }
619619
func (f Field) Type() params.Type { return fields[f].Type }
620620

621621
func (f Field) IsPsField() bool { return strings.HasPrefix(string(f), "ps.") }
622-
func (f Field) IsKevtField() bool { return strings.HasPrefix(string(f), "evt.") }
622+
func (f Field) IsKevtField() bool { return strings.HasPrefix(string(f), "kevt.") }
623+
func (f Field) IsEvtField() bool { return strings.HasPrefix(string(f), "evt.") }
623624
func (f Field) IsThreadField() bool { return strings.HasPrefix(string(f), "thread.") }
624625
func (f Field) IsImageField() bool { return strings.HasPrefix(string(f), "image.") }
625626
func (f Field) IsFileField() bool { return strings.HasPrefix(string(f), "file.") }

0 commit comments

Comments
 (0)