Skip to content

Commit 9782a35

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 11ab687 commit 9782a35

4 files changed

Lines changed: 8 additions & 146 deletions

File tree

pkg/event/event_windows.go

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ package event
2121
import (
2222
"encoding/binary"
2323
"fmt"
24+
"os"
25+
"strings"
26+
"sync"
27+
"unsafe"
28+
2429
"github.com/rabbitstack/fibratus/pkg/event/params"
2530
"github.com/rabbitstack/fibratus/pkg/sys"
2631
"github.com/rabbitstack/fibratus/pkg/sys/etw"
@@ -29,10 +34,6 @@ import (
2934
"github.com/rabbitstack/fibratus/pkg/util/hostname"
3035
"github.com/rabbitstack/fibratus/pkg/util/ntstatus"
3136
"golang.org/x/sys/windows"
32-
"os"
33-
"strings"
34-
"sync"
35-
"unsafe"
3637
)
3738

3839
var (
@@ -153,18 +154,6 @@ func (e *Event) IsDropped(capture bool) bool {
153154
// current process is dropped.
154155
func IsCurrentProcDropped(pid uint32) bool { return DropCurrentProc && pid == currentPid }
155156

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

404-
// BacklogKey represents the key used to index the events in the backlog store.
405-
func (e *Event) BacklogKey() uint64 {
406-
switch e.Type {
407-
case CreateHandle, CloseHandle:
408-
return e.Params.MustGetUint64(params.HandleObject)
409-
}
410-
return 0
411-
}
412-
413-
// CopyState adds parameters, tags, or process state from the provided event.
414-
func (e *Event) CopyState(evt *Event) {
415-
switch evt.Type {
416-
case CloseHandle:
417-
if evt.Params.Contains(params.ImagePath) {
418-
e.Params.Append(params.ImagePath, params.UnicodeString, evt.GetParamAsString(params.ImagePath))
419-
}
420-
_ = e.Params.SetValue(params.HandleObjectName, evt.GetParamAsString(params.HandleObjectName))
421-
}
422-
}
423-
424393
// Summary returns a brief summary of this event. Various important substrings
425394
// in the summary text are highlighted by surrounding them inside <code> HTML tags.
426395
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: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@
126126
- macro: load_driver
127127
expr: >
128128
(load_module and (image.name iendswith '.sys' or image.is_driver))
129-
or
130-
(create_handle and handle.type = 'Driver')
131129
description: |
132130
Detects the loading of the kernel driver. Image load events are published when
133131
executable images, DLLs, or driver PE objects are loaded. On the contrary, we can

0 commit comments

Comments
 (0)