Skip to content

Commit

Permalink
fix security-agent ad storage using nil statd client
Browse files Browse the repository at this point in the history
  • Loading branch information
YoannGh committed Dec 18, 2024
1 parent 52f0517 commit dfc8615
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
5 changes: 3 additions & 2 deletions pkg/security/agent/agent_nix.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (

"go.uber.org/atomic"

"github.com/DataDog/datadog-go/v5/statsd"

workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def"
"github.com/DataDog/datadog-agent/pkg/security/security_profile/dump"
"github.com/DataDog/datadog-go/v5/statsd"
)

// NewRuntimeSecurityAgent instantiates a new RuntimeSecurityAgent
Expand All @@ -30,7 +31,7 @@ func NewRuntimeSecurityAgent(statsdClient statsd.ClientInterface, hostname strin
}

// on windows do no storage manager
storage, err := dump.NewAgentStorageManager()
storage, err := dump.NewAgentStorageManager(statsdClient)
if err != nil {
return nil, err
}
Expand Down
13 changes: 9 additions & 4 deletions pkg/security/security_profile/dump/storage_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ type ActivityDumpStorage interface {
type ActivityDumpStorageManager struct {
statsdClient statsd.ClientInterface
storages map[config.StorageType]ActivityDumpStorage
isFowarder bool
}

// NewAgentStorageManager returns a new instance of ActivityDumpStorageManager
func NewAgentStorageManager() (*ActivityDumpStorageManager, error) {
func NewAgentStorageManager(statsdClient statsd.ClientInterface) (*ActivityDumpStorageManager, error) {
manager := &ActivityDumpStorageManager{
storages: make(map[config.StorageType]ActivityDumpStorage),
statsdClient: statsdClient,
storages: make(map[config.StorageType]ActivityDumpStorage),
isFowarder: false,
}

// create remote storage
Expand All @@ -54,7 +57,8 @@ func NewAgentStorageManager() (*ActivityDumpStorageManager, error) {
// NewAgentCommandStorageManager returns a new instance of ActivityDumpStorageManager
func NewAgentCommandStorageManager(cfg *config.Config) (*ActivityDumpStorageManager, error) {
manager := &ActivityDumpStorageManager{
storages: make(map[config.StorageType]ActivityDumpStorage),
storages: make(map[config.StorageType]ActivityDumpStorage),
isFowarder: false,
}

storage, err := NewActivityDumpLocalStorage(cfg, nil)
Expand All @@ -78,6 +82,7 @@ func NewActivityDumpStorageManager(cfg *config.Config, statsdClient statsd.Clien
manager := &ActivityDumpStorageManager{
storages: make(map[config.StorageType]ActivityDumpStorage),
statsdClient: statsdClient,
isFowarder: true,
}

storage, err := NewActivityDumpLocalStorage(cfg, m)
Expand Down Expand Up @@ -133,7 +138,7 @@ func (manager *ActivityDumpStorageManager) PersistRaw(requests []config.StorageR
}

// send dump metric
if manager.statsdClient != nil {
if manager.statsdClient != nil && manager.isFowarder {
if size := len(raw.Bytes()); size > 0 {
tags := []string{"format:" + request.Format.String(), "storage_type:" + request.Type.String(), fmt.Sprintf("compression:%v", request.Compression)}
if err := manager.statsdClient.Count(metrics.MetricActivityDumpSizeInBytes, int64(size), tags, 1.0); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"bytes"
"fmt"

"github.com/DataDog/datadog-go/v5/statsd"

"github.com/DataDog/datadog-agent/pkg/security/config"
"github.com/DataDog/datadog-agent/pkg/security/proto/api"
)
Expand All @@ -28,7 +30,7 @@ func (manager *ActivityDumpStorageManager) PersistRaw(_ []config.StorageRequest,
func (manager *ActivityDumpStorageManager) SendTelemetry() {}

// NewAgentStorageManager returns a new instance of ActivityDumpStorageManager
func NewAgentStorageManager() (*ActivityDumpStorageManager, error) {
func NewAgentStorageManager(statsdClient statsd.ClientInterface) (*ActivityDumpStorageManager, error) {
return nil, fmt.Errorf("the activity dump manager is unsupported on this platform")
}

Expand Down

0 comments on commit dfc8615

Please sign in to comment.