mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
ListProcesses through PID when cgroup is not found in Linux (#25198)
* ListProcesses through PID when cgroup is not found * add changelog entry * update the ListByPid for windows
This commit is contained in:
3
.changelog/25198.txt
Normal file
3
.changelog/25198.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
```release-note:improvement
|
||||
metrics: Fix the process lookup for raw_exec when running rootless
|
||||
```
|
||||
@@ -38,7 +38,7 @@ func withNetworkIsolation(f func() error, _ *drivers.NetworkIsolationSpec) error
|
||||
func setCmdUser(*exec.Cmd, string) error { return nil }
|
||||
|
||||
func (e *UniversalExecutor) ListProcesses() set.Collection[int] {
|
||||
return procstats.List(e.childCmd.Process.Pid)
|
||||
return procstats.ListByPid(e.childCmd.Process.Pid)
|
||||
}
|
||||
|
||||
func (e *UniversalExecutor) setSubCmdCgroup(*exec.Cmd, string) (func(), error) {
|
||||
|
||||
@@ -103,7 +103,13 @@ func (e *UniversalExecutor) setSubCmdCgroup(cmd *exec.Cmd, cgroup string) (func(
|
||||
}
|
||||
|
||||
func (e *UniversalExecutor) ListProcesses() set.Collection[procstats.ProcessID] {
|
||||
return procstats.List(e.command)
|
||||
switch cgroupslib.GetMode() {
|
||||
case cgroupslib.OFF:
|
||||
// cgroup is unavailable, could possibly due to rootless nomad client
|
||||
return procstats.ListByPid(e.childCmd.Process.Pid)
|
||||
default:
|
||||
return procstats.List(e.command)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *UniversalExecutor) statCG(cgroup string) (int, func(), error) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
//go:build !linux && !windows
|
||||
//go:build !windows
|
||||
|
||||
package procstats
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
// List the process tree starting at the given executorPID
|
||||
func List(executorPID int) set.Collection[ProcessID] {
|
||||
func ListByPid(executorPID int) set.Collection[ProcessID] {
|
||||
result := set.New[ProcessID](10)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/mitchellh/go-ps"
|
||||
)
|
||||
|
||||
// List will scan the process table and return a set of the process family
|
||||
// ListByPid will scan the process table and return a set of the process family
|
||||
// tree starting with executorPID as the root.
|
||||
//
|
||||
// The implementation here specifically avoids using more than one system
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
// See https://github.com/hashicorp/nomad/issues/20042 as an example of what
|
||||
// happens when you use syscalls to work your way from the root down to its
|
||||
// descendants.
|
||||
func List(executorPID int) set.Collection[ProcessID] {
|
||||
func ListByPid(executorPID int) set.Collection[ProcessID] {
|
||||
procs := list(executorPID, ps.Processes)
|
||||
return procs
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user