17244: Use crunch-run's cgroup, not init's, for "host" stats.
authorTom Clegg <tom@curii.com>
Fri, 21 Jul 2023 23:05:33 +0000 (19:05 -0400)
committerTom Clegg <tom@curii.com>
Fri, 21 Jul 2023 23:05:33 +0000 (19:05 -0400)
This gets much closer to "everything on the host" with minimal
effort.

Tracking the furthest ancestor of crunch-run's cgroup might be even
better, but will require additional support in crunchstat.

Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

lib/crunchrun/crunchrun.go
lib/crunchrun/docker.go
lib/crunchrun/executor.go

index 1c0cf621dbf730e409193efc7cbe44a0e90daa8e..9add35335f39380ca61f78390f0eae1ce7ebda03 100644 (file)
@@ -742,8 +742,16 @@ func (runner *ContainerRunner) startHoststat() error {
        }
        runner.hoststatLogger = NewThrottledLogger(w)
        runner.hoststatReporter = &crunchstat.Reporter{
-               Logger:     log.New(runner.hoststatLogger, "", 0),
-               Pid:        func() int { return 1 },
+               Logger: log.New(runner.hoststatLogger, "", 0),
+               // Our own cgroup is the "host" cgroup, in the sense
+               // that it accounts for resource usage outside the
+               // container. It doesn't count _all_ resource usage on
+               // the system.
+               //
+               // TODO?: Use the furthest ancestor of our own cgroup
+               // that has stats available. (Currently crunchstat
+               // does not have that capability.)
+               Pid:        os.Getpid,
                PollPeriod: runner.statInterval,
        }
        runner.hoststatReporter.Start()
index 4adc680d9bf7c3402e43048576f917fb3c2ade09..1fd8c4fd256d65d5441f4567b311a07dcf3c318c 100644 (file)
@@ -202,7 +202,7 @@ func (e *dockerExecutor) Pid() int {
        if err != nil && ctr.State != nil {
                return ctr.State.Pid
        } else {
-               return -1
+               return 0
        }
 }
 
index 29abab631f2c03bba9cd2deb7d49bd56571b4ab0..308b05cdeb33b529d46564658cdb5c6dcfc8b1af 100644 (file)
@@ -51,9 +51,8 @@ type containerExecutor interface {
        // Start the container
        Start() error
 
-       // Process ID of a process in the container (return 0 or
-       // negative if container is finished or no process has started
-       // yet)
+       // Process ID of a process in the container.  Return 0 if
+       // container is finished or no process has started yet.
        Pid() int
 
        // Stop the container immediately