Skip to content

Commit

Permalink
refactor(sdk): move in-memory implementation to sdk/internal package
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
  • Loading branch information
jasondellaluce authored and poiana committed Jun 13, 2022
1 parent 998a463 commit 42bf90c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
10 changes: 6 additions & 4 deletions pkg/sdk/inmemory.go → pkg/sdk/internal/sdk/inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"bytes"
"io"
"unsafe"

"github.com/falcosecurity/plugin-sdk-go/pkg/sdk"
)

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

func (i *InMemoryExtractRequestPool) Get(requestIndex int) ExtractRequest {
func (i *InMemoryExtractRequestPool) Get(requestIndex int) sdk.ExtractRequest {
return i.Requests[requestIndex]
}

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

func (i *InMemoryEventWriters) Get(eventIndex int) EventWriter {
func (i *InMemoryEventWriters) Get(eventIndex int) sdk.EventWriter {
return i.Writers[eventIndex]
}

Expand Down
25 changes: 13 additions & 12 deletions pkg/sdk/plugins/source/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"time"

"github.com/falcosecurity/plugin-sdk-go/pkg/sdk"
sdkint "github.com/falcosecurity/plugin-sdk-go/pkg/sdk/internal/sdk"
)

const (
Expand All @@ -36,9 +37,9 @@ const (
)

func benchNextBatch(b *testing.B, inst Instance, batchSize uint32, evtCount int) {
batch := &sdk.InMemoryEventWriters{}
batch := &sdkint.InMemoryEventWriters{}
for i := uint32(0); i < batchSize; i++ {
batch.Writers = append(batch.Writers, &sdk.InMemoryEventWriter{})
batch.Writers = append(batch.Writers, &sdkint.InMemoryEventWriter{})
}
b.ResetTimer()
tot := 0
Expand Down Expand Up @@ -143,9 +144,9 @@ func TestPullInstance(t *testing.T) {
timeout := time.Millisecond * 10

// create batch
batch := &sdk.InMemoryEventWriters{}
batch := &sdkint.InMemoryEventWriters{}
for i := uint32(0); i < sdk.DefaultBatchSize; i++ {
batch.Writers = append(batch.Writers, &sdk.InMemoryEventWriter{})
batch.Writers = append(batch.Writers, &sdkint.InMemoryEventWriter{})
}

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

func TestPullInstanceCtxCanceling(t *testing.T) {
// create batch
batch := &sdk.InMemoryEventWriters{}
batch := &sdkint.InMemoryEventWriters{}
for i := uint32(0); i < sdk.DefaultBatchSize; i++ {
batch.Writers = append(batch.Writers, &sdk.InMemoryEventWriter{})
batch.Writers = append(batch.Writers, &sdkint.InMemoryEventWriter{})
}

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

// create batch
batch := &sdk.InMemoryEventWriters{}
batch := &sdkint.InMemoryEventWriters{}
for i := uint32(0); i < sdk.DefaultBatchSize; i++ {
batch.Writers = append(batch.Writers, &sdk.InMemoryEventWriter{})
batch.Writers = append(batch.Writers, &sdkint.InMemoryEventWriter{})
}

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

func TestPushInstanceChanClosing(t *testing.T) {
// create batch
batch := &sdk.InMemoryEventWriters{}
batch := &sdkint.InMemoryEventWriters{}
for i := uint32(0); i < sdk.DefaultBatchSize; i++ {
batch.Writers = append(batch.Writers, &sdk.InMemoryEventWriter{})
batch.Writers = append(batch.Writers, &sdkint.InMemoryEventWriter{})
}

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

func TestPushInstanceCtxCanceling(t *testing.T) {
// create batch
batch := &sdk.InMemoryEventWriters{}
batch := &sdkint.InMemoryEventWriters{}
for i := uint32(0); i < sdk.DefaultBatchSize; i++ {
batch.Writers = append(batch.Writers, &sdk.InMemoryEventWriter{})
batch.Writers = append(batch.Writers, &sdkint.InMemoryEventWriter{})
}

ctx, cancel := context.WithCancel(context.Background())
Expand Down

0 comments on commit 42bf90c

Please sign in to comment.