Skip to content

Commit 42bf90c

Browse files
jasondellalucepoiana
authored andcommitted
refactor(sdk): move in-memory implementation to sdk/internal package
Signed-off-by: Jason Dellaluce <[email protected]>
1 parent 998a463 commit 42bf90c

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

pkg/sdk/inmemory.go renamed to pkg/sdk/internal/sdk/inmemory.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"bytes"
2121
"io"
2222
"unsafe"
23+
24+
"github.com/falcosecurity/plugin-sdk-go/pkg/sdk"
2325
)
2426

2527
// InMemoryExtractRequest is an in-memory implementation of
@@ -75,10 +77,10 @@ func (i *InMemoryExtractRequest) SetPtr(ptr unsafe.Pointer) {
7577
// InMemoryExtractRequestPool is an in-memory implementation of
7678
// sdk.ExtractRequestPool that allows changing its internal values.
7779
type InMemoryExtractRequestPool struct {
78-
Requests map[int]ExtractRequest
80+
Requests map[int]sdk.ExtractRequest
7981
}
8082

81-
func (i *InMemoryExtractRequestPool) Get(requestIndex int) ExtractRequest {
83+
func (i *InMemoryExtractRequestPool) Get(requestIndex int) sdk.ExtractRequest {
8284
return i.Requests[requestIndex]
8385
}
8486

@@ -105,12 +107,12 @@ func (i *InMemoryEventWriter) SetTimestamp(value uint64) {
105107
// InMemoryEventWriters is an in-memory implementation of
106108
// sdk.EventWriters that allows changing its internal values.
107109
type InMemoryEventWriters struct {
108-
Writers []EventWriter
110+
Writers []sdk.EventWriter
109111
ValArrayPtr unsafe.Pointer
110112
OnFree func()
111113
}
112114

113-
func (i *InMemoryEventWriters) Get(eventIndex int) EventWriter {
115+
func (i *InMemoryEventWriters) Get(eventIndex int) sdk.EventWriter {
114116
return i.Writers[eventIndex]
115117
}
116118

pkg/sdk/plugins/source/instance_test.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"time"
2525

2626
"github.com/falcosecurity/plugin-sdk-go/pkg/sdk"
27+
sdkint "github.com/falcosecurity/plugin-sdk-go/pkg/sdk/internal/sdk"
2728
)
2829

2930
const (
@@ -36,9 +37,9 @@ const (
3637
)
3738

3839
func benchNextBatch(b *testing.B, inst Instance, batchSize uint32, evtCount int) {
39-
batch := &sdk.InMemoryEventWriters{}
40+
batch := &sdkint.InMemoryEventWriters{}
4041
for i := uint32(0); i < batchSize; i++ {
41-
batch.Writers = append(batch.Writers, &sdk.InMemoryEventWriter{})
42+
batch.Writers = append(batch.Writers, &sdkint.InMemoryEventWriter{})
4243
}
4344
b.ResetTimer()
4445
tot := 0
@@ -143,9 +144,9 @@ func TestPullInstance(t *testing.T) {
143144
timeout := time.Millisecond * 10
144145

145146
// create batch
146-
batch := &sdk.InMemoryEventWriters{}
147+
batch := &sdkint.InMemoryEventWriters{}
147148
for i := uint32(0); i < sdk.DefaultBatchSize; i++ {
148-
batch.Writers = append(batch.Writers, &sdk.InMemoryEventWriter{})
149+
batch.Writers = append(batch.Writers, &sdkint.InMemoryEventWriter{})
149150
}
150151

151152
// setup evt generation callback
@@ -213,9 +214,9 @@ func TestPullInstance(t *testing.T) {
213214

214215
func TestPullInstanceCtxCanceling(t *testing.T) {
215216
// create batch
216-
batch := &sdk.InMemoryEventWriters{}
217+
batch := &sdkint.InMemoryEventWriters{}
217218
for i := uint32(0); i < sdk.DefaultBatchSize; i++ {
218-
batch.Writers = append(batch.Writers, &sdk.InMemoryEventWriter{})
219+
batch.Writers = append(batch.Writers, &sdkint.InMemoryEventWriter{})
219220
}
220221

221222
ctx, cancel := context.WithCancel(context.Background())
@@ -251,9 +252,9 @@ func TestPushInstance(t *testing.T) {
251252
timeout := time.Millisecond * 100
252253

253254
// create batch
254-
batch := &sdk.InMemoryEventWriters{}
255+
batch := &sdkint.InMemoryEventWriters{}
255256
for i := uint32(0); i < sdk.DefaultBatchSize; i++ {
256-
batch.Writers = append(batch.Writers, &sdk.InMemoryEventWriter{})
257+
batch.Writers = append(batch.Writers, &sdkint.InMemoryEventWriter{})
257258
}
258259

259260
// setup evt generation worker
@@ -322,9 +323,9 @@ func TestPushInstance(t *testing.T) {
322323

323324
func TestPushInstanceChanClosing(t *testing.T) {
324325
// create batch
325-
batch := &sdk.InMemoryEventWriters{}
326+
batch := &sdkint.InMemoryEventWriters{}
326327
for i := uint32(0); i < sdk.DefaultBatchSize; i++ {
327-
batch.Writers = append(batch.Writers, &sdk.InMemoryEventWriter{})
328+
batch.Writers = append(batch.Writers, &sdkint.InMemoryEventWriter{})
328329
}
329330

330331
evtChan := make(chan PushEvent)
@@ -355,9 +356,9 @@ func TestPushInstanceChanClosing(t *testing.T) {
355356

356357
func TestPushInstanceCtxCanceling(t *testing.T) {
357358
// create batch
358-
batch := &sdk.InMemoryEventWriters{}
359+
batch := &sdkint.InMemoryEventWriters{}
359360
for i := uint32(0); i < sdk.DefaultBatchSize; i++ {
360-
batch.Writers = append(batch.Writers, &sdk.InMemoryEventWriter{})
361+
batch.Writers = append(batch.Writers, &sdkint.InMemoryEventWriter{})
361362
}
362363

363364
ctx, cancel := context.WithCancel(context.Background())

0 commit comments

Comments
 (0)