From d0cf7d9619ec600fd9bbc944669582b1b24b166a Mon Sep 17 00:00:00 2001 From: mrproliu <741550557@qq.com> Date: Tue, 13 Aug 2024 23:05:04 +0800 Subject: [PATCH 1/2] Remove unnecessary process exist check (#138) --- pkg/process/finders/kubernetes/finder.go | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/pkg/process/finders/kubernetes/finder.go b/pkg/process/finders/kubernetes/finder.go index d4e37c83..29b5b1df 100644 --- a/pkg/process/finders/kubernetes/finder.go +++ b/pkg/process/finders/kubernetes/finder.go @@ -382,21 +382,6 @@ func (f *ProcessFinder) ParseProcessID(ps api.DetectedProcess, downstream *v3.EB } func (f *ProcessFinder) ShouldMonitor(pid int32) bool { - pidList, err := process.Pids() - if err != nil { - return false - } - pidExist := false - for _, p := range pidList { - if p == pid { - pidExist = true - break - } - } - if !pidExist { - return false - } - newProcess, err := process.NewProcess(pid) if err != nil { return false From 2f6256e69a16ac9b87f7fb600871273b9fa99134 Mon Sep 17 00:00:00 2001 From: mrproliu <741550557@qq.com> Date: Thu, 29 Aug 2024 16:16:05 +0800 Subject: [PATCH 2/2] Add detect process from `CRI-O` container in Kubernetes. (#139) --- CHANGES.md | 1 + pkg/process/finders/kubernetes/container.go | 1 + pkg/process/finders/kubernetes/finder.go | 8 +++++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index d9fc284c..ffa770c2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,7 @@ Release Notes. * Upgrade LLVM to `18`. * Support propagation the excluding namespaces in the access log to the backend. * Add `pprof` module for observe self. +* Add detect process from `CRI-O` container in Kubernetes. #### Bug Fixes * Fixed the issue where `conntrack` could not find the Reply IP in the access log module. diff --git a/pkg/process/finders/kubernetes/container.go b/pkg/process/finders/kubernetes/container.go index da8ace1e..3ed9c384 100644 --- a/pkg/process/finders/kubernetes/container.go +++ b/pkg/process/finders/kubernetes/container.go @@ -70,6 +70,7 @@ func (c *PodContainer) CGroupID() string { cgroupID = strings.TrimPrefix(cgroupID, "containerd://") cgroupID = strings.TrimPrefix(cgroupID, "dockerd://") cgroupID = strings.TrimPrefix(cgroupID, "docker://") + cgroupID = strings.TrimPrefix(cgroupID, "cri-o://") return cgroupID } diff --git a/pkg/process/finders/kubernetes/finder.go b/pkg/process/finders/kubernetes/finder.go index 29b5b1df..6637a7fe 100644 --- a/pkg/process/finders/kubernetes/finder.go +++ b/pkg/process/finders/kubernetes/finder.go @@ -50,7 +50,10 @@ import ( var log = logger.GetLogger("process", "finder", "kubernetes") -var kubepodsRegex = regexp.MustCompile(`cri-containerd-(?P\w+)\.scope`) +var ( + kubepodsRegex = regexp.MustCompile(`cri-containerd-(?P\w+)\.scope`) + openShiftPodsRegex = regexp.MustCompile(`crio-(?P\w+)\.scope`) +) type ProcessFinder struct { conf *Config @@ -289,6 +292,9 @@ func (f *ProcessFinder) getProcessCGroup(pid int32) ([]string, error) { if kubepod := kubepodsRegex.FindStringSubmatch(path); len(kubepod) >= 1 { path = kubepod[1] } + if openShiftPod := openShiftPodsRegex.FindStringSubmatch(path); len(openShiftPod) >= 1 { + path = openShiftPod[1] + } cache[path] = true } }