From 42bf90c6de7f3157fde7533f1fe930c9ba43928f Mon Sep 17 00:00:00 2001 From: Jason Dellaluce Date: Mon, 13 Jun 2022 16:03:01 +0000 Subject: [PATCH] refactor(sdk): move in-memory implementation to sdk/internal package Signed-off-by: Jason Dellaluce --- pkg/sdk/{ => internal/sdk}/inmemory.go | 10 ++++++---- pkg/sdk/plugins/source/instance_test.go | 25 +++++++++++++------------ 2 files changed, 19 insertions(+), 16 deletions(-) rename pkg/sdk/{ => internal/sdk}/inmemory.go (92%) diff --git a/pkg/sdk/inmemory.go b/pkg/sdk/internal/sdk/inmemory.go similarity index 92% rename from pkg/sdk/inmemory.go rename to pkg/sdk/internal/sdk/inmemory.go index afd5bfa..fd598de 100644 --- a/pkg/sdk/inmemory.go +++ b/pkg/sdk/internal/sdk/inmemory.go @@ -20,6 +20,8 @@ import ( "bytes" "io" "unsafe" + + "github.com/falcosecurity/plugin-sdk-go/pkg/sdk" ) // InMemoryExtractRequest is an in-memory implementation of @@ -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] } @@ -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] } diff --git a/pkg/sdk/plugins/source/instance_test.go b/pkg/sdk/plugins/source/instance_test.go index e078776..1a80863 100644 --- a/pkg/sdk/plugins/source/instance_test.go +++ b/pkg/sdk/plugins/source/instance_test.go @@ -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 ( @@ -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 @@ -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 @@ -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()) @@ -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 @@ -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) @@ -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())