Skip to content

Commit 9d97784

Browse files
committed
cleanup(event): Remove delay event logic
Delay key logic only applies to handle events, which are rarely enabled due to its immense volume. For the sake of codebase simplicity and maintainability, we are sunsetting this functionality.
1 parent 0aada01 commit 9d97784

4 files changed

Lines changed: 5 additions & 145 deletions

File tree

pkg/event/event_windows.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,6 @@ func (e *Event) IsDropped(capture bool) bool {
152152
// current process is dropped.
153153
func IsCurrentProcDropped(pid uint32) bool { return DropCurrentProc && pid == currentPid }
154154

155-
// DelayKey returns the value that is used to
156-
// store and reference delayed events in the event
157-
// backlog state. The delayed event is indexed by
158-
// the sequence identifier.
159-
func (e *Event) DelayKey() uint64 {
160-
switch e.Type {
161-
case CreateHandle, CloseHandle:
162-
return e.Params.MustGetUint64(params.HandleObject)
163-
}
164-
return 0
165-
}
166-
167155
// IsNetworkTCP determines whether the event pertains to network TCP events.
168156
func (e *Event) IsNetworkTCP() bool {
169157
return e.Category == Net && !e.IsNetworkUDP()
@@ -419,26 +407,6 @@ func (e *Event) PartialKey() uint64 {
419407
return 0
420408
}
421409

422-
// BacklogKey represents the key used to index the events in the backlog store.
423-
func (e *Event) BacklogKey() uint64 {
424-
switch e.Type {
425-
case CreateHandle, CloseHandle:
426-
return e.Params.MustGetUint64(params.HandleObject)
427-
}
428-
return 0
429-
}
430-
431-
// CopyState adds parameters, tags, or process state from the provided event.
432-
func (e *Event) CopyState(evt *Event) {
433-
switch evt.Type {
434-
case CloseHandle:
435-
if evt.Params.Contains(params.ImagePath) {
436-
e.Params.Append(params.ImagePath, params.UnicodeString, evt.GetParamAsString(params.ImagePath))
437-
}
438-
_ = e.Params.SetValue(params.HandleObjectName, evt.GetParamAsString(params.HandleObjectName))
439-
}
440-
}
441-
442410
// Summary returns a brief summary of this event. Various important substrings
443411
// in the summary text are highlighted by surrounding them inside <code> HTML tags.
444412
func (e *Event) Summary() string {

pkg/event/queue.go

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,8 @@ package event
2020

2121
import (
2222
"expvar"
23-
"github.com/golang/groupcache/lru"
24-
"github.com/rabbitstack/fibratus/pkg/util/multierror"
2523
)
2624

27-
// backlogCacheSize specifies the max size of the backlog cache.
28-
// When the backlog cache size is reached, the oldest entries are
29-
// removed from the cache.
30-
const backlogCacheSize = 800
31-
3225
// eventsEnqueued counts the number of events that are pushed to the queue
3326
var eventsEnqueued = expvar.NewInt("eventsource.events.enqueued")
3427

@@ -52,7 +45,6 @@ type Listener interface {
5245
type Queue struct {
5346
q chan *Event
5447
listeners []Listener
55-
backlog *backlog
5648
decorator *StackwalkDecorator
5749
stackEnrichment bool
5850
enqueueAlways bool
@@ -63,7 +55,6 @@ func NewQueue(size int, stackEnrichment bool, enqueueAlways bool) *Queue {
6355
q := &Queue{
6456
q: make(chan *Event, size),
6557
listeners: make([]Listener, 0),
66-
backlog: newBacklog(backlogCacheSize),
6758
stackEnrichment: stackEnrichment,
6859
enqueueAlways: enqueueAlways,
6960
}
@@ -76,7 +67,6 @@ func NewQueueWithChannel(ch chan *Event, stackEnrichment bool, enqueueAlways boo
7667
q := &Queue{
7768
q: ch,
7869
listeners: make([]Listener, 0),
79-
backlog: newBacklog(backlogCacheSize),
8070
stackEnrichment: stackEnrichment,
8171
enqueueAlways: enqueueAlways,
8272
}
@@ -128,14 +118,6 @@ func (q *Queue) Push(e *Event) error {
128118
e = q.decorator.Pop(e)
129119
}
130120
}
131-
if isEventDelayed(e) {
132-
q.backlog.put(e)
133-
return nil
134-
}
135-
evt := q.backlog.pop(e)
136-
if evt != nil {
137-
return multierror.Wrap(q.push(evt), q.push(e))
138-
}
139121
// drop stack walk events
140122
if e.IsStackWalk() {
141123
return nil
@@ -167,43 +149,3 @@ func (q *Queue) push(e *Event) error {
167149
}
168150
return nil
169151
}
170-
171-
func isEventDelayed(e *Event) bool {
172-
return e.IsCreateHandle()
173-
}
174-
175-
type backlog struct {
176-
cache *lru.Cache
177-
}
178-
179-
func newBacklog(size int) *backlog {
180-
return &backlog{cache: lru.New(size)}
181-
}
182-
183-
func (b *backlog) put(evt *Event) {
184-
if b.cache.Len() > backlogCacheSize {
185-
b.cache.RemoveOldest()
186-
}
187-
key := evt.BacklogKey()
188-
if key != 0 {
189-
b.cache.Add(key, evt)
190-
}
191-
}
192-
193-
func (b *backlog) pop(evt *Event) *Event {
194-
key := evt.BacklogKey()
195-
if key == 0 {
196-
return nil
197-
}
198-
ev, ok := b.cache.Get(key)
199-
if !ok {
200-
return nil
201-
}
202-
b.cache.Remove(key)
203-
e := ev.(*Event)
204-
e.CopyState(evt)
205-
return e
206-
}
207-
208-
func (b *backlog) size() int { return b.cache.Len() }
209-
func (b *backlog) empty() bool { return b.size() == 0 }

pkg/event/queue_test.go

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ package event
2020

2121
import (
2222
"errors"
23+
"testing"
24+
"time"
25+
2326
"github.com/rabbitstack/fibratus/pkg/event/params"
2427
"github.com/rabbitstack/fibratus/pkg/fs"
2528
"github.com/stretchr/testify/assert"
2629
"github.com/stretchr/testify/mock"
27-
"github.com/stretchr/testify/require"
28-
"reflect"
29-
"testing"
30-
"time"
3130
)
3231

3332
// AddParamListener receives the event and appends a parameter to it
@@ -190,49 +189,3 @@ func TestQueuePush(t *testing.T) {
190189
})
191190
}
192191
}
193-
194-
func TestPushBacklog(t *testing.T) {
195-
e := &Event{
196-
Type: CreateHandle,
197-
Tid: 2484,
198-
PID: 859,
199-
Category: Handle,
200-
Params: Params{
201-
params.HandleID: {Name: params.HandleID, Type: params.Uint32, Value: uint32(21)},
202-
params.HandleObjectTypeID: {Name: params.HandleObjectTypeID, Type: params.AnsiString, Value: "Key"},
203-
params.HandleObject: {Name: params.HandleObject, Type: params.Uint64, Value: uint64(18446692422059208560)},
204-
params.HandleObjectName: {Name: params.HandleObjectName, Type: params.UnicodeString, Value: ""},
205-
},
206-
Metadata: make(Metadata),
207-
}
208-
209-
q := NewQueue(100, false, true)
210-
q.RegisterListener(&DummyListener{})
211-
212-
require.NoError(t, q.Push(e))
213-
require.Len(t, q.Events(), 0)
214-
require.False(t, q.backlog.empty())
215-
216-
e1 := &Event{
217-
Type: CloseHandle,
218-
Tid: 2484,
219-
PID: 859,
220-
Category: Handle,
221-
Params: Params{
222-
params.HandleID: {Name: params.HandleID, Type: params.Uint32, Value: uint32(21)},
223-
params.HandleObjectTypeID: {Name: params.HandleObjectTypeID, Type: params.AnsiString, Value: "Key"},
224-
params.HandleObject: {Name: params.HandleObject, Type: params.Uint64, Value: uint64(18446692422059208560)},
225-
params.HandleObjectName: {Name: params.HandleObjectName, Type: params.UnicodeString, Value: `\REGISTRY\MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces\{b677c565-6ca5-45d3-b618-736b4e09b036}`},
226-
},
227-
Metadata: make(Metadata),
228-
}
229-
230-
require.NoError(t, q.Push(e1))
231-
require.True(t, q.backlog.empty())
232-
233-
ev := <-q.Events()
234-
require.NotNil(t, ev)
235-
assert.Equal(t, `\REGISTRY\MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces\{b677c565-6ca5-45d3-b618-736b4e09b036}`, ev.GetParamAsString(params.HandleObjectName))
236-
237-
require.True(t, reflect.DeepEqual(e1, <-q.Events()))
238-
}

rules/macros/macros.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,10 @@
123123
124124
- macro: load_driver
125125
expr: >
126-
(load_module and (image.name iendswith '.sys' or image.is_driver)) or
127-
(create_handle and handle.type = 'Driver')
126+
(load_module and (image.name iendswith '.sys' or image.is_driver))
128127
description: |
129128
Detects the loading of the kernel driver. Image load events are published when
130-
executable images, DLLs, or driver PE objects are loaded. On the contrary, we can
131-
also detect loading of kernel driver by observing the object manager events and
132-
watching for driver objects being created.
129+
executable images, DLLs, or driver PE objects are loaded.
133130
134131
- macro: unload_driver
135132
expr: unload_module and (image.name iendswith '.sys' or image.is_driver)

0 commit comments

Comments
 (0)