Skip to content

Commit

Permalink
[CWS] retry self tests
Browse files Browse the repository at this point in the history
  • Loading branch information
safchain committed Oct 15, 2024
1 parent aa3d423 commit 419e17e
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pkg/security/module/cws.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"time"

"github.com/DataDog/datadog-go/v5/statsd"
"go.uber.org/atomic"

workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def"
"github.com/DataDog/datadog-agent/pkg/eventmonitor"
Expand All @@ -34,6 +35,11 @@ import (
"github.com/DataDog/datadog-agent/pkg/security/utils"
)

const (
maxSelftestRetry = 3
selftestDelay = 5 * time.Second
)

// CWSConsumer represents the system-probe module for the runtime security agent
type CWSConsumer struct {
sync.RWMutex
Expand All @@ -52,6 +58,7 @@ type CWSConsumer struct {
grpcServer *GRPCServer
ruleEngine *rulesmodule.RuleEngine
selfTester *selftests.SelfTester
selfTestRetry *atomic.Int32
reloader ReloaderInterface
crtelemetry *telemetry.ContainersRunningTelemetry
}
Expand Down Expand Up @@ -92,6 +99,7 @@ func NewCWSConsumer(evm *eventmonitor.EventMonitor, cfg *config.RuntimeSecurityC
sendStatsChan: make(chan chan bool, 1),
grpcServer: NewGRPCServer(family, address),
selfTester: selfTester,
selfTestRetry: atomic.NewInt32(0),
reloader: NewReloader(),
crtelemetry: crtelemetry,
}
Expand Down Expand Up @@ -172,11 +180,17 @@ func (c *CWSConsumer) Start() error {

// we can now wait for self test events
cb := func(success []eval.RuleID, fails []eval.RuleID, testEvents map[eval.RuleID]*serializers.EventSerializer) {
seclog.Debugf("self-test results : success : %v, failed : %v, retry %d/%d", success, fails, c.selfTestRetry.Load()+1, maxSelftestRetry)

if len(fails) > 0 && c.selfTestRetry.Load() < maxSelftestRetry {
c.RunSelfTest(false)
c.selfTestRetry.Inc()
return
}

if c.config.SelfTestSendReport {
c.reportSelfTest(success, fails, testEvents)
}

seclog.Debugf("self-test results : success : %v, failed : %v", success, fails)
}
if c.selfTester != nil {
go c.selfTester.WaitForResult(cb)
Expand Down

0 comments on commit 419e17e

Please sign in to comment.