From a4eaff5ac098ea7eeb7007a492a2280d44143557 Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Fri, 1 Sep 2017 14:01:01 -0700 Subject: [PATCH] server: Add sandbox pid as well to container info We need it to get network stats in cadvisor stats and can avoid an additional REST call. Signed-off-by: Mrunal Patel --- server/inspect.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server/inspect.go b/server/inspect.go index 0d2a6c12..4297bf80 100644 --- a/server/inspect.go +++ b/server/inspect.go @@ -19,6 +19,7 @@ type ContainerInfo struct { LogPath string `json:"log_path"` Root string `json:"root"` Sandbox string `json:"sandbox"` + SandboxPid int `json:"sandbox_pid"` } // CrioInfo stores information about the crio daemon @@ -60,6 +61,16 @@ func (s *Server) GetInfoMux() *bone.Mux { http.Error(w, fmt.Sprintf("container %s state is nil", containerID), http.StatusNotFound) return } + sbContainer := s.getInfraContainer(ctr.Sandbox()) + if sbContainer == nil { + http.Error(w, fmt.Sprintf("can't find the sandbox container for container id: %s", containerID), http.StatusNotFound) + return + } + sbContainerState := sbContainer.State() + if sbContainerState == nil { + http.Error(w, fmt.Sprintf("container %s state is nil", ctr.Sandbox()), http.StatusNotFound) + return + } ci := ContainerInfo{ Pid: ctrState.Pid, @@ -70,6 +81,7 @@ func (s *Server) GetInfoMux() *bone.Mux { Root: ctr.MountPoint(), LogPath: filepath.Dir(ctr.LogPath()), Sandbox: ctr.Sandbox(), + SandboxPid: sbContainerState.Pid, } js, err := json.Marshal(ci) if err != nil {