From 2a214bee7453091e96cf88dbf7798af4f8b48a06 Mon Sep 17 00:00:00 2001 From: Ramanan Ravikumar <38394463+ramanan-ravi@users.noreply.github.com> Date: Mon, 9 Oct 2023 22:29:57 +0530 Subject: [PATCH] Add short name in agent report (#1649) * Short process name * Update dependencies --- deepfence_agent/plugins/YaraHunter | 2 +- deepfence_agent/tools/apache/scope/probe/cri/reporter.go | 2 +- .../tools/apache/scope/probe/docker/reporter.go | 2 +- .../tools/apache/scope/probe/endpoint/reporter.go | 2 +- .../tools/apache/scope/probe/kubernetes/reporter.go | 2 +- .../tools/apache/scope/probe/process/reporter.go | 8 +++++++- deepfence_agent/tools/apache/scope/report/metadata.go | 9 +++++---- deepfence_server/go.mod | 2 +- deepfence_server/model/lookup.go | 1 + deepfence_server/pkg/scope/report/metadata.go | 9 +++++---- 10 files changed, 24 insertions(+), 15 deletions(-) diff --git a/deepfence_agent/plugins/YaraHunter b/deepfence_agent/plugins/YaraHunter index 1f6e9b3777..936c03eb7d 160000 --- a/deepfence_agent/plugins/YaraHunter +++ b/deepfence_agent/plugins/YaraHunter @@ -1 +1 @@ -Subproject commit 1f6e9b3777eeb0a69911c1f81388f5062b4e99b2 +Subproject commit 936c03eb7d448618a32874004294d38bab7ae967 diff --git a/deepfence_agent/tools/apache/scope/probe/cri/reporter.go b/deepfence_agent/tools/apache/scope/probe/cri/reporter.go index 5495bfce5b..50be7ec829 100644 --- a/deepfence_agent/tools/apache/scope/probe/cri/reporter.go +++ b/deepfence_agent/tools/apache/scope/probe/cri/reporter.go @@ -39,7 +39,7 @@ func NewReporter(cri client.RuntimeServiceClient, hostID string, criImageClient } // Name of this reporter, for metrics gathering -func (Reporter) Name() string { return "CRI" } +func (*Reporter) Name() string { return "CRI" } // Report generates a Report containing Container topologies func (r *Reporter) Report() (report.Report, error) { diff --git a/deepfence_agent/tools/apache/scope/probe/docker/reporter.go b/deepfence_agent/tools/apache/scope/probe/docker/reporter.go index aeb186073b..534289692a 100644 --- a/deepfence_agent/tools/apache/scope/probe/docker/reporter.go +++ b/deepfence_agent/tools/apache/scope/probe/docker/reporter.go @@ -42,7 +42,7 @@ func NewReporter(registry Registry, hostID string, probeID string, probe *probe. } // Name of this reporter, for metrics gathering -func (Reporter) Name() string { return "Docker" } +func (*Reporter) Name() string { return "Docker" } // Report generates a Report containing Container and ContainerImage topologies func (r *Reporter) Report() (report.Report, error) { diff --git a/deepfence_agent/tools/apache/scope/probe/endpoint/reporter.go b/deepfence_agent/tools/apache/scope/probe/endpoint/reporter.go index 758b125e56..d3565a2f4e 100644 --- a/deepfence_agent/tools/apache/scope/probe/endpoint/reporter.go +++ b/deepfence_agent/tools/apache/scope/probe/endpoint/reporter.go @@ -20,4 +20,4 @@ type ReporterConfig struct { } // Name of this reporter, for metrics gathering -func (Reporter) Name() string { return "Endpoint" } +func (*Reporter) Name() string { return "Endpoint" } diff --git a/deepfence_agent/tools/apache/scope/probe/kubernetes/reporter.go b/deepfence_agent/tools/apache/scope/probe/kubernetes/reporter.go index 0b0a922732..6cb0db8993 100644 --- a/deepfence_agent/tools/apache/scope/probe/kubernetes/reporter.go +++ b/deepfence_agent/tools/apache/scope/probe/kubernetes/reporter.go @@ -55,7 +55,7 @@ func (r *Reporter) Stop() { } // Name of this reporter, for metrics gathering -func (Reporter) Name() string { return "K8s" } +func (*Reporter) Name() string { return "K8s" } //func (r *Reporter) podEvent(e Event, pod Pod) { // // filter out non-local pods, if we have been given a node name to report on diff --git a/deepfence_agent/tools/apache/scope/probe/process/reporter.go b/deepfence_agent/tools/apache/scope/probe/process/reporter.go index 6b7e36d938..e8c3a9f869 100644 --- a/deepfence_agent/tools/apache/scope/probe/process/reporter.go +++ b/deepfence_agent/tools/apache/scope/probe/process/reporter.go @@ -1,6 +1,7 @@ package process import ( + "path/filepath" "strconv" "sync" "time" @@ -70,7 +71,7 @@ func NewReporter(walker Walker, hostID string, jiffies Jiffies, noCommandLineArg } // Name of this reporter, for metrics gathering -func (Reporter) Name() string { return "Process" } +func (*Reporter) Name() string { return "Process" } func (r *Reporter) updateProcessCache() { @@ -110,6 +111,10 @@ func (r *Reporter) Report() (report.Report, error) { return result, nil } +func shortProcessName(processName string) string { + return filepath.Base(processName) +} + func (r *Reporter) processTopology() (report.Topology, error) { t := report.MakeTopology() deltaTotal, maxCPU, err := r.jiffies() @@ -124,6 +129,7 @@ func (r *Reporter) processTopology() (report.Topology, error) { Timestamp: time.Now().UTC().Format(time.RFC3339Nano), NodeID: nodeID, NodeName: p.Name, + ShortNodeName: shortProcessName(p.Name), NodeType: report.Process, HostName: r.hostName, Pid: p.PID, diff --git a/deepfence_agent/tools/apache/scope/report/metadata.go b/deepfence_agent/tools/apache/scope/report/metadata.go index 0c0fcbd170..16b7e857f2 100644 --- a/deepfence_agent/tools/apache/scope/report/metadata.go +++ b/deepfence_agent/tools/apache/scope/report/metadata.go @@ -22,10 +22,11 @@ func (m Metadata) WithID(id string) Metadata { } type Metadata struct { - NodeID string `json:"node_id"` - NodeType string `json:"node_type,omitempty"` - NodeName string `json:"node_name,omitempty"` - Timestamp string `json:"timestamp"` + NodeID string `json:"node_id"` + NodeType string `json:"node_type,omitempty"` + NodeName string `json:"node_name,omitempty"` + ShortNodeName string `json:"short_name,omitempty"` + Timestamp string `json:"timestamp"` // cloud metadata InstanceID string `json:"instance_id,omitempty"` diff --git a/deepfence_server/go.mod b/deepfence_server/go.mod index 9a13f7d41a..2e9b8273ef 100644 --- a/deepfence_server/go.mod +++ b/deepfence_server/go.mod @@ -37,6 +37,7 @@ require ( go.opentelemetry.io/otel v1.18.0 go.opentelemetry.io/otel/exporters/jaeger v1.16.0 go.opentelemetry.io/otel/sdk v1.18.0 + go.opentelemetry.io/otel/trace v1.18.0 golang.org/x/crypto v0.12.0 gotest.tools v2.2.0+incompatible k8s.io/api v0.28.0 @@ -119,7 +120,6 @@ require ( github.com/twmb/franz-go/pkg/kmsg v1.6.1 // indirect go.opentelemetry.io/contrib v1.0.0 // indirect go.opentelemetry.io/otel/metric v1.18.0 // indirect - go.opentelemetry.io/otel/trace v1.18.0 // indirect golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect golang.org/x/mod v0.10.0 // indirect golang.org/x/net v0.14.0 // indirect diff --git a/deepfence_server/model/lookup.go b/deepfence_server/model/lookup.go index 5b507f6a13..ee3d6611b5 100644 --- a/deepfence_server/model/lookup.go +++ b/deepfence_server/model/lookup.go @@ -253,6 +253,7 @@ func (c Container) id() string { type Process struct { ID string `json:"node_id" required:"true"` Name string `json:"node_name" required:"true"` + ShortNodeName string `json:"short_name" required:"true"` PID int `json:"pid" required:"true"` Command string `json:"cmdline" required:"true"` PPID int `json:"ppid" required:"true"` diff --git a/deepfence_server/pkg/scope/report/metadata.go b/deepfence_server/pkg/scope/report/metadata.go index f09ecf6a0e..abba608b8c 100644 --- a/deepfence_server/pkg/scope/report/metadata.go +++ b/deepfence_server/pkg/scope/report/metadata.go @@ -22,10 +22,11 @@ func (m Metadata) WithID(id string) Metadata { } type Metadata struct { - NodeID string `json:"node_id"` - NodeType string `json:"node_type"` - NodeName string `json:"node_name"` - Timestamp string `json:"timestamp"` + NodeID string `json:"node_id"` + NodeType string `json:"node_type"` + NodeName string `json:"node_name"` + ShortNodeName string `json:"short_name,omitempty"` + Timestamp string `json:"timestamp"` // cloud metadata InstanceID string `json:"instance_id,omitempty"`