From dfc86155d40467b25b402249b1dd0c219ca851cb Mon Sep 17 00:00:00 2001 From: YoannGh Date: Wed, 18 Dec 2024 16:51:01 +0100 Subject: [PATCH] fix security-agent ad storage using nil statd client --- pkg/security/agent/agent_nix.go | 5 +++-- .../security_profile/dump/storage_manager.go | 13 +++++++++---- .../dump/storage_manager_unsupported.go | 4 +++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/pkg/security/agent/agent_nix.go b/pkg/security/agent/agent_nix.go index bc444d6f049fe..8083e3259b87e 100644 --- a/pkg/security/agent/agent_nix.go +++ b/pkg/security/agent/agent_nix.go @@ -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 @@ -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 } diff --git a/pkg/security/security_profile/dump/storage_manager.go b/pkg/security/security_profile/dump/storage_manager.go index 454309068fad4..ab0382257b6de 100644 --- a/pkg/security/security_profile/dump/storage_manager.go +++ b/pkg/security/security_profile/dump/storage_manager.go @@ -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 @@ -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) @@ -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) @@ -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 { diff --git a/pkg/security/security_profile/dump/storage_manager_unsupported.go b/pkg/security/security_profile/dump/storage_manager_unsupported.go index 885c1f2030808..f31fb568d67cb 100644 --- a/pkg/security/security_profile/dump/storage_manager_unsupported.go +++ b/pkg/security/security_profile/dump/storage_manager_unsupported.go @@ -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" ) @@ -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") }