This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-rover.git


The following commit(s) were added to refs/heads/main by this push:
     new 00b5150  Add support-profiling properties in to process (#19)
00b5150 is described below

commit 00b5150ec70197af13a9e5f1ffc203d433dc886b
Author: mrproliu <[email protected]>
AuthorDate: Fri Apr 29 18:49:40 2022 +0800

    Add support-profiling properties in to process (#19)
---
 pkg/process/finders/kubernetes/finder.go           | 10 ++---
 pkg/process/finders/kubernetes/process.go          |  3 ++
 pkg/process/finders/scanner/finder.go              | 37 ++--------------
 pkg/process/finders/scanner/process.go             | 14 ++++--
 .../agent_sensor/golang/expected/process.yml       |  2 +
 test/e2e/cases/process/istio/expected/process.yml  | 50 ++++++++++++++++++++++
 .../process/istio/expected/service-instance.yml    |  2 +-
 test/e2e/cases/process/istio/expected/service.yml  | 12 ++++++
 8 files changed, 86 insertions(+), 44 deletions(-)

diff --git a/pkg/process/finders/kubernetes/finder.go 
b/pkg/process/finders/kubernetes/finder.go
index 309d11e..d4ba96b 100644
--- a/pkg/process/finders/kubernetes/finder.go
+++ b/pkg/process/finders/kubernetes/finder.go
@@ -156,12 +156,6 @@ func (f *ProcessFinder) analyzeProcesses() error {
                        continue
                }
 
-               // check support profiling
-               _, err = base.BuildProfilingStat(p)
-               if err != nil {
-                       continue
-               }
-
                // find process builder
                ps, err := f.buildProcesses(p, c)
                if err != nil {
@@ -297,6 +291,10 @@ func (f *ProcessFinder) BuildEBPFProcess(ctx 
*base.BuildEBPFProcessContext, ps b
                        Key:   "command_line",
                        Value: ps.(*Process).cmd,
                },
+               {
+                       Key:   "support_ebpf_profiling",
+                       Value: strconv.FormatBool(ps.ProfilingStat() != nil),
+               },
        }
        properties := &v3.EBPFProcessProperties{Metadata: 
&v3.EBPFProcessProperties_K8SProcess{
                K8SProcess: k8sProcess,
diff --git a/pkg/process/finders/kubernetes/process.go 
b/pkg/process/finders/kubernetes/process.go
index 6c35b10..547e2ae 100644
--- a/pkg/process/finders/kubernetes/process.go
+++ b/pkg/process/finders/kubernetes/process.go
@@ -21,6 +21,7 @@ import (
        "github.com/shirou/gopsutil/process"
 
        "github.com/apache/skywalking-rover/pkg/process/api"
+       "github.com/apache/skywalking-rover/pkg/process/finders/base"
        "github.com/apache/skywalking-rover/pkg/tools/profiling"
 )
 
@@ -38,12 +39,14 @@ type Process struct {
 }
 
 func NewProcess(p *process.Process, cmdline string, pc *PodContainer, entity 
*api.ProcessEntity) *Process {
+       stat, _ := base.BuildProfilingStat(p)
        return &Process{
                original:     p,
                pid:          p.Pid,
                cmd:          cmdline,
                podContainer: pc,
                entity:       entity,
+               profiling:    stat,
        }
 }
 
diff --git a/pkg/process/finders/scanner/finder.go 
b/pkg/process/finders/scanner/finder.go
index 0705785..768586f 100644
--- a/pkg/process/finders/scanner/finder.go
+++ b/pkg/process/finders/scanner/finder.go
@@ -112,6 +112,10 @@ func (p *ProcessFinder) BuildEBPFProcess(ctx 
*base.BuildEBPFProcessContext, ps b
                        Key:   "command_line",
                        Value: ps.(*Process).cmd,
                },
+               {
+                       Key:   "support_ebpf_profiling",
+                       Value: strconv.FormatBool(ps.ProfilingStat() != nil),
+               },
        }
        properties := &v3.EBPFProcessProperties{Metadata: 
&v3.EBPFProcessProperties_HostProcess{
                HostProcess: hostProcess,
@@ -166,9 +170,6 @@ func (p *ProcessFinder) regexFindProcesses() 
([]base.DetectedProcess, error) {
                return nil, err
        }
 
-       // validate the process could be profiling
-       processes = p.validateTheProcessesCouldProfiling(processes)
-
        // report to the manager
        psList := make([]base.DetectedProcess, 0)
        for _, ps := range processes {
@@ -237,12 +238,6 @@ func (p *ProcessFinder) agentFindProcesses() 
([]base.DetectedProcess, error) {
                        continue
                }
 
-               // could be profiling
-               if err := p.validateProcessCouldProfiling(agentProcess); err != 
nil {
-                       log.Warnf("found agent process, but it could not 
profiling, so ignore, pid: %d, error: %v", pid, err)
-                       continue
-               }
-
                findedProcesses = append(findedProcesses, agentProcess)
        }
        return findedProcesses, nil
@@ -321,27 +316,6 @@ func (p *ProcessFinder) buildProcessFromAgentMetadata(pro 
*process.Process, meta
        return NewProcessByAgent(pro, cmdline, agent)
 }
 
-func (p *ProcessFinder) validateTheProcessesCouldProfiling(processes 
[]*Process) []*Process {
-       result := make([]*Process, 0)
-       for _, ps := range processes {
-               if err := p.validateProcessCouldProfiling(ps); err != nil {
-                       log.Warnf("could not read process exe file path, pid: 
%d, err: %v", ps.pid, err)
-                       continue
-               }
-               result = append(result, ps)
-       }
-       return result
-}
-
-func (p *ProcessFinder) validateProcessCouldProfiling(ps *Process) error {
-       pf, err := base.BuildProfilingStat(ps.original)
-       if err != nil {
-               return err
-       }
-       ps.profiling = pf
-       return nil
-}
-
 func (p *ProcessFinder) regexFindMatchedProcesses() ([]*Process, error) {
        // all system processes
        processes, err := process.ProcessesWithContext(p.ctx)
@@ -351,9 +325,6 @@ func (p *ProcessFinder) regexFindMatchedProcesses() 
([]*Process, error) {
        // find all matches processes
        findedProcesses := make([]*Process, 0)
        for _, pro := range processes {
-               // TODO should we need verify the process must be in the root 
namespace? such as exclude the container processes
-               // That's mean the same process would could only be detect by 
one finder?
-
                // find the matched process finder
                finderConfig, cmdline, err := p.findMatchesFinder(pro)
                if err != nil {
diff --git a/pkg/process/finders/scanner/process.go 
b/pkg/process/finders/scanner/process.go
index d90b655..d13d77d 100644
--- a/pkg/process/finders/scanner/process.go
+++ b/pkg/process/finders/scanner/process.go
@@ -24,6 +24,7 @@ import (
        "github.com/shirou/gopsutil/process"
 
        "github.com/apache/skywalking-rover/pkg/process/api"
+       "github.com/apache/skywalking-rover/pkg/process/finders/base"
        "github.com/apache/skywalking-rover/pkg/tools/profiling"
 )
 
@@ -42,7 +43,8 @@ type Process struct {
 }
 
 func NewProcessByRegex(p *process.Process, cmdline string, config 
*RegexFinder) *Process {
-       return &Process{original: p, pid: p.Pid, cmd: cmdline, finderConfig: 
config, entity: &api.ProcessEntity{}}
+       stat, _ := base.BuildProfilingStat(p)
+       return &Process{original: p, pid: p.Pid, cmd: cmdline, finderConfig: 
config, profiling: stat, entity: &api.ProcessEntity{}}
 }
 
 func NewProcessByAgent(p *process.Process, cmdline string, agent 
*AgentMetadata) (*Process, error) {
@@ -62,11 +64,15 @@ func NewProcessByAgent(p *process.Process, cmdline string, 
agent *AgentMetadata)
                labels = strings.Split(agent.Labels, ",")
        }
 
+       // profiling status
+       stat, _ := base.BuildProfilingStat(p)
+
        // build result
        return &Process{
-               original: p,
-               pid:      p.Pid,
-               cmd:      cmdline,
+               original:  p,
+               pid:       p.Pid,
+               cmd:       cmdline,
+               profiling: stat,
                entity: &api.ProcessEntity{
                        Layer:        agent.Layer,
                        ServiceName:  agent.ServiceName,
diff --git a/test/e2e/cases/process/agent_sensor/golang/expected/process.yml 
b/test/e2e/cases/process/agent_sensor/golang/expected/process.yml
index ca17857..f116332 100644
--- a/test/e2e/cases/process/agent_sensor/golang/expected/process.yml
+++ b/test/e2e/cases/process/agent_sensor/golang/expected/process.yml
@@ -31,6 +31,8 @@
       value: {{ notEmpty .value }}
     - name: command_line
       value: /main --grpc --oap-server oap:11800
+    - name: support_ebpf_profiling
+      value: true
     {{- end }}
   labels:
     - e2e-label
diff --git a/test/e2e/cases/process/istio/expected/process.yml 
b/test/e2e/cases/process/istio/expected/process.yml
index c86d7d2..645b266 100644
--- a/test/e2e/cases/process/istio/expected/process.yml
+++ b/test/e2e/cases/process/istio/expected/process.yml
@@ -14,6 +14,30 @@
 # limitations under the License.
 
 {{- contains . }}
+- id: {{ notEmpty .id }}
+  name: python
+  serviceid: {{ b64enc "default::productpage" }}.1
+  servicename: default::productpage
+  instanceid: {{ notEmpty .instanceid }}
+  instancename: {{ notEmpty .instancename }}
+  layer: MESH
+  agentid: {{ notEmpty .agentid }}
+  detecttype: KUBERNETES
+  attributes:
+    {{- contains .attributes }}
+    - name: host_ip
+      value: {{ notEmpty .value }}
+    - name: container_ip
+      value: {{ notEmpty .value }}
+    - name: pid
+      value: {{ notEmpty .value }}
+    - name: command_line
+      value: {{ notEmpty .value }}
+    - name: support_ebpf_profiling
+      value: "false"
+    {{- end }}
+  labels:
+    - mesh-application
 - id: {{ notEmpty .id }}
   name: envoy
   serviceid: {{ b64enc "default::productpage" }}.1
@@ -33,6 +57,32 @@
       value: {{ notEmpty .value }}
     - name: command_line
       value: {{ notEmpty .value }}
+    - name: support_ebpf_profiling
+      value: true
+    {{- end }}
+  labels:
+    - mesh-envoy
+- id: {{ notEmpty .id }}
+  name: pilot-agent
+  serviceid: {{ b64enc "default::productpage" }}.1
+  servicename: default::productpage
+  instanceid: {{ notEmpty .instanceid }}
+  instancename: {{ notEmpty .instancename }}
+  layer: MESH_DP
+  agentid: {{ notEmpty .agentid }}
+  detecttype: KUBERNETES
+  attributes:
+    {{- contains .attributes }}
+    - name: host_ip
+      value: {{ notEmpty .value }}
+    - name: container_ip
+      value: {{ notEmpty .value }}
+    - name: pid
+      value: {{ notEmpty .value }}
+    - name: command_line
+      value: {{ notEmpty .value }}
+    - name: support_ebpf_profiling
+      value: "false"
     {{- end }}
   labels:
     - mesh-envoy
diff --git a/test/e2e/cases/process/istio/expected/service-instance.yml 
b/test/e2e/cases/process/istio/expected/service-instance.yml
index b8e3c0f..1d6d6bc 100644
--- a/test/e2e/cases/process/istio/expected/service-instance.yml
+++ b/test/e2e/cases/process/istio/expected/service-instance.yml
@@ -19,5 +19,5 @@
   attributes: []
   language: UNKNOWN
   instanceuuid: {{ notEmpty .instanceuuid }}
-  layer: MESH_DP
+  layer: {{ notEmpty .layer }}
 {{- end }}
diff --git a/test/e2e/cases/process/istio/expected/service.yml 
b/test/e2e/cases/process/istio/expected/service.yml
index 5aa540b..40bbced 100644
--- a/test/e2e/cases/process/istio/expected/service.yml
+++ b/test/e2e/cases/process/istio/expected/service.yml
@@ -19,7 +19,10 @@
   group: default
   shortname: details
   layers:
+    {{- contains .layers }}
     - MESH_DP
+    - MESH
+    {{- end }}
   normal: true
 - id: {{ b64enc "istio-system::istio-ingressgateway" }}.1
   name: istio-system::istio-ingressgateway
@@ -33,21 +36,30 @@
   group: default
   shortname: productpage
   layers:
+    {{- contains .layers }}
     - MESH_DP
+    - MESH
+    {{- end }}
   normal: true
 - id: {{ b64enc "default::ratings" }}.1
   name: default::ratings
   group: default
   shortname: ratings
   layers:
+    {{- contains .layers }}
     - MESH_DP
+    - MESH
+    {{- end }}
   normal: true
 - id: {{ b64enc "default::reviews" }}.1
   name: default::reviews
   group: default
   shortname: reviews
   layers:
+    {{- contains .layers }}
     - MESH_DP
+    - MESH
+    {{- end }}
   normal: true
 - id: {{ b64enc "istio-system::istio-egressgateway" }}.1
   name: istio-system::istio-egressgateway

Reply via email to