Merge pull request #182 from mrunalp/req_resp_logging

Add logging for all container/sandbox responses
This commit is contained in:
Antonio Murdaca 2016-10-31 18:58:25 +01:00 committed by GitHub
commit c5cf3bff88
2 changed files with 59 additions and 36 deletions

View file

@ -58,7 +58,7 @@ func (s *Server) getContainerFromRequest(req containerRequest) (*oci.Container,
// CreateContainer creates a new container in specified PodSandbox // CreateContainer creates a new container in specified PodSandbox
func (s *Server) CreateContainer(ctx context.Context, req *pb.CreateContainerRequest) (res *pb.CreateContainerResponse, err error) { func (s *Server) CreateContainer(ctx context.Context, req *pb.CreateContainerRequest) (res *pb.CreateContainerResponse, err error) {
logrus.Debugf("CreateContainer %+v", req) logrus.Debugf("CreateContainerRequest %+v", req)
sbID := req.GetPodSandboxId() sbID := req.GetPodSandboxId()
if sbID == "" { if sbID == "" {
return nil, fmt.Errorf("PodSandboxId should not be empty") return nil, fmt.Errorf("PodSandboxId should not be empty")
@ -131,9 +131,12 @@ func (s *Server) CreateContainer(ctx context.Context, req *pb.CreateContainerReq
return nil, err return nil, err
} }
return &pb.CreateContainerResponse{ resp := &pb.CreateContainerResponse{
ContainerId: &containerID, ContainerId: &containerID,
}, nil }
logrus.Debugf("CreateContainerResponse: %+v", resp)
return resp, nil
} }
func (s *Server) createSandboxContainer(containerID string, containerName string, sb *sandbox, SandboxConfig *pb.PodSandboxConfig, containerDir string, containerConfig *pb.ContainerConfig) (*oci.Container, error) { func (s *Server) createSandboxContainer(containerID string, containerName string, sb *sandbox, SandboxConfig *pb.PodSandboxConfig, containerDir string, containerConfig *pb.ContainerConfig) (*oci.Container, error) {
@ -293,7 +296,7 @@ func (s *Server) createSandboxContainer(containerID string, containerName string
// Join the namespace paths for the pod sandbox container. // Join the namespace paths for the pod sandbox container.
podInfraState := s.runtime.ContainerStatus(sb.infraContainer) podInfraState := s.runtime.ContainerStatus(sb.infraContainer)
logrus.Infof("pod container state %v", podInfraState) logrus.Debugf("pod container state %+v", podInfraState)
for nsType, nsFile := range map[string]string{ for nsType, nsFile := range map[string]string{
"ipc": "ipc", "ipc": "ipc",
@ -346,7 +349,7 @@ func (s *Server) createSandboxContainer(containerID string, containerName string
// StartContainer starts the container. // StartContainer starts the container.
func (s *Server) StartContainer(ctx context.Context, req *pb.StartContainerRequest) (*pb.StartContainerResponse, error) { func (s *Server) StartContainer(ctx context.Context, req *pb.StartContainerRequest) (*pb.StartContainerResponse, error) {
logrus.Debugf("StartContainer %+v", req) logrus.Debugf("StartContainerRequest %+v", req)
c, err := s.getContainerFromRequest(req) c, err := s.getContainerFromRequest(req)
if err != nil { if err != nil {
return nil, err return nil, err
@ -356,12 +359,14 @@ func (s *Server) StartContainer(ctx context.Context, req *pb.StartContainerReque
return nil, fmt.Errorf("failed to start container %s: %v", c.ID(), err) return nil, fmt.Errorf("failed to start container %s: %v", c.ID(), err)
} }
return &pb.StartContainerResponse{}, nil resp := &pb.StartContainerResponse{}
logrus.Debugf("StartContainerResponse %+v", resp)
return resp, nil
} }
// StopContainer stops a running container with a grace period (i.e., timeout). // StopContainer stops a running container with a grace period (i.e., timeout).
func (s *Server) StopContainer(ctx context.Context, req *pb.StopContainerRequest) (*pb.StopContainerResponse, error) { func (s *Server) StopContainer(ctx context.Context, req *pb.StopContainerRequest) (*pb.StopContainerResponse, error) {
logrus.Debugf("StopContainer %+v", req) logrus.Debugf("StopContainerRequest %+v", req)
c, err := s.getContainerFromRequest(req) c, err := s.getContainerFromRequest(req)
if err != nil { if err != nil {
return nil, err return nil, err
@ -371,13 +376,15 @@ func (s *Server) StopContainer(ctx context.Context, req *pb.StopContainerRequest
return nil, fmt.Errorf("failed to stop container %s: %v", c.ID(), err) return nil, fmt.Errorf("failed to stop container %s: %v", c.ID(), err)
} }
return &pb.StopContainerResponse{}, nil resp := &pb.StopContainerResponse{}
logrus.Debugf("StopContainerResponse: %+v", resp)
return resp, nil
} }
// RemoveContainer removes the container. If the container is running, the container // RemoveContainer removes the container. If the container is running, the container
// should be force removed. // should be force removed.
func (s *Server) RemoveContainer(ctx context.Context, req *pb.RemoveContainerRequest) (*pb.RemoveContainerResponse, error) { func (s *Server) RemoveContainer(ctx context.Context, req *pb.RemoveContainerRequest) (*pb.RemoveContainerResponse, error) {
logrus.Debugf("RemoveContainer %+v", req) logrus.Debugf("RemoveContainerRequest %+v", req)
c, err := s.getContainerFromRequest(req) c, err := s.getContainerFromRequest(req)
if err != nil { if err != nil {
return nil, err return nil, err
@ -410,7 +417,9 @@ func (s *Server) RemoveContainer(ctx context.Context, req *pb.RemoveContainerReq
return nil, err return nil, err
} }
return &pb.RemoveContainerResponse{}, nil resp := &pb.RemoveContainerResponse{}
logrus.Debugf("RemoveContainerResponse: %+v", resp)
return resp, nil
} }
// filterContainer returns whether passed container matches filtering criteria // filterContainer returns whether passed container matches filtering criteria
@ -433,7 +442,7 @@ func filterContainer(c *pb.Container, filter *pb.ContainerFilter) bool {
// ListContainers lists all containers by filters. // ListContainers lists all containers by filters.
func (s *Server) ListContainers(ctx context.Context, req *pb.ListContainersRequest) (*pb.ListContainersResponse, error) { func (s *Server) ListContainers(ctx context.Context, req *pb.ListContainersRequest) (*pb.ListContainersResponse, error) {
logrus.Debugf("ListContainers %+v", req) logrus.Debugf("ListContainersRequest %+v", req)
var ctrs []*pb.Container var ctrs []*pb.Container
filter := req.Filter filter := req.Filter
ctrList := s.state.containers.List() ctrList := s.state.containers.List()
@ -500,14 +509,16 @@ func (s *Server) ListContainers(ctx context.Context, req *pb.ListContainersReque
} }
} }
return &pb.ListContainersResponse{ resp := &pb.ListContainersResponse{
Containers: ctrs, Containers: ctrs,
}, nil }
logrus.Debugf("ListContainersResponse: %+v", resp)
return resp, nil
} }
// ContainerStatus returns status of the container. // ContainerStatus returns status of the container.
func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusRequest) (*pb.ContainerStatusResponse, error) { func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusRequest) (*pb.ContainerStatusResponse, error) {
logrus.Debugf("ContainerStatus %+v", req) logrus.Debugf("ContainerStatusRequest %+v", req)
c, err := s.getContainerFromRequest(req) c, err := s.getContainerFromRequest(req)
if err != nil { if err != nil {
return nil, err return nil, err
@ -518,7 +529,7 @@ func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusReq
} }
containerID := c.ID() containerID := c.ID()
csr := &pb.ContainerStatusResponse{ resp := &pb.ContainerStatusResponse{
Status: &pb.ContainerStatus{ Status: &pb.ContainerStatus{
Id: &containerID, Id: &containerID,
}, },
@ -531,27 +542,28 @@ func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusReq
case oci.ContainerStateCreated: case oci.ContainerStateCreated:
rStatus = pb.ContainerState_CREATED rStatus = pb.ContainerState_CREATED
created := cState.Created.Unix() created := cState.Created.Unix()
csr.Status.CreatedAt = int64Ptr(created) resp.Status.CreatedAt = int64Ptr(created)
case oci.ContainerStateRunning: case oci.ContainerStateRunning:
rStatus = pb.ContainerState_RUNNING rStatus = pb.ContainerState_RUNNING
created := cState.Created.Unix() created := cState.Created.Unix()
csr.Status.CreatedAt = int64Ptr(created) resp.Status.CreatedAt = int64Ptr(created)
started := cState.Started.Unix() started := cState.Started.Unix()
csr.Status.StartedAt = int64Ptr(started) resp.Status.StartedAt = int64Ptr(started)
case oci.ContainerStateStopped: case oci.ContainerStateStopped:
rStatus = pb.ContainerState_EXITED rStatus = pb.ContainerState_EXITED
created := cState.Created.Unix() created := cState.Created.Unix()
csr.Status.CreatedAt = int64Ptr(created) resp.Status.CreatedAt = int64Ptr(created)
started := cState.Started.Unix() started := cState.Started.Unix()
csr.Status.StartedAt = int64Ptr(started) resp.Status.StartedAt = int64Ptr(started)
finished := cState.Finished.Unix() finished := cState.Finished.Unix()
csr.Status.FinishedAt = int64Ptr(finished) resp.Status.FinishedAt = int64Ptr(finished)
csr.Status.ExitCode = int32Ptr(cState.ExitCode) resp.Status.ExitCode = int32Ptr(cState.ExitCode)
} }
csr.Status.State = &rStatus resp.Status.State = &rStatus
return csr, nil logrus.Debugf("ContainerStatusResponse: %+v", resp)
return resp, nil
} }
// UpdateRuntimeConfig updates the configuration of a running container. // UpdateRuntimeConfig updates the configuration of a running container.

View file

@ -86,7 +86,7 @@ func (s *Server) getPodSandboxFromRequest(req podSandboxRequest) (*sandbox, erro
// RunPodSandbox creates and runs a pod-level sandbox. // RunPodSandbox creates and runs a pod-level sandbox.
func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest) (*pb.RunPodSandboxResponse, error) { func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest) (*pb.RunPodSandboxResponse, error) {
logrus.Debugf("RunPodSandbox %+v", req) logrus.Debugf("RunPodSandboxRequest %+v", req)
var processLabel, mountLabel string var processLabel, mountLabel string
// process req.Name // process req.Name
name := req.GetConfig().GetMetadata().GetName() name := req.GetConfig().GetMetadata().GetName()
@ -323,13 +323,15 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
return nil, err return nil, err
} }
return &pb.RunPodSandboxResponse{PodSandboxId: &id}, nil resp := &pb.RunPodSandboxResponse{PodSandboxId: &id}
logrus.Debugf("RunPodSandboxResponse: %+v", resp)
return resp, nil
} }
// StopPodSandbox stops the sandbox. If there are any running containers in the // StopPodSandbox stops the sandbox. If there are any running containers in the
// sandbox, they should be force terminated. // sandbox, they should be force terminated.
func (s *Server) StopPodSandbox(ctx context.Context, req *pb.StopPodSandboxRequest) (*pb.StopPodSandboxResponse, error) { func (s *Server) StopPodSandbox(ctx context.Context, req *pb.StopPodSandboxRequest) (*pb.StopPodSandboxResponse, error) {
logrus.Debugf("StopPodSandbox %+v", req) logrus.Debugf("StopPodSandboxRequest %+v", req)
sb, err := s.getPodSandboxFromRequest(req) sb, err := s.getPodSandboxFromRequest(req)
if err != nil { if err != nil {
return nil, err return nil, err
@ -359,13 +361,15 @@ func (s *Server) StopPodSandbox(ctx context.Context, req *pb.StopPodSandboxReque
} }
} }
return &pb.StopPodSandboxResponse{}, nil resp := &pb.StopPodSandboxResponse{}
logrus.Debugf("StopPodSandboxResponse: %+v", resp)
return resp, nil
} }
// RemovePodSandbox deletes the sandbox. If there are any running containers in the // RemovePodSandbox deletes the sandbox. If there are any running containers in the
// sandbox, they should be force deleted. // sandbox, they should be force deleted.
func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxRequest) (*pb.RemovePodSandboxResponse, error) { func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxRequest) (*pb.RemovePodSandboxResponse, error) {
logrus.Debugf("RemovePodSandbox %+v", req) logrus.Debugf("RemovePodSandboxRequest %+v", req)
sb, err := s.getPodSandboxFromRequest(req) sb, err := s.getPodSandboxFromRequest(req)
if err != nil { if err != nil {
return nil, err return nil, err
@ -421,12 +425,14 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR
s.releasePodName(sb.name) s.releasePodName(sb.name)
s.removeSandbox(sb.id) s.removeSandbox(sb.id)
return &pb.RemovePodSandboxResponse{}, nil resp := &pb.RemovePodSandboxResponse{}
logrus.Debugf("RemovePodSandboxResponse %+v", resp)
return resp, nil
} }
// PodSandboxStatus returns the Status of the PodSandbox. // PodSandboxStatus returns the Status of the PodSandbox.
func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusRequest) (*pb.PodSandboxStatusResponse, error) { func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusRequest) (*pb.PodSandboxStatusResponse, error) {
logrus.Debugf("PodSandboxStatus %+v", req) logrus.Debugf("PodSandboxStatusRequest %+v", req)
sb, err := s.getPodSandboxFromRequest(req) sb, err := s.getPodSandboxFromRequest(req)
if err != nil { if err != nil {
return nil, err return nil, err
@ -457,7 +463,7 @@ func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusR
} }
sandboxID := sb.id sandboxID := sb.id
return &pb.PodSandboxStatusResponse{ resp := &pb.PodSandboxStatusResponse{
Status: &pb.PodSandboxStatus{ Status: &pb.PodSandboxStatus{
Id: &sandboxID, Id: &sandboxID,
CreatedAt: int64Ptr(created), CreatedAt: int64Ptr(created),
@ -472,7 +478,10 @@ func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusR
Annotations: sb.annotations, Annotations: sb.annotations,
Metadata: sb.metadata, Metadata: sb.metadata,
}, },
}, nil }
logrus.Infof("PodSandboxStatusResponse: %+v", resp)
return resp, nil
} }
// filterSandbox returns whether passed container matches filtering criteria // filterSandbox returns whether passed container matches filtering criteria
@ -495,7 +504,7 @@ func filterSandbox(p *pb.PodSandbox, filter *pb.PodSandboxFilter) bool {
// ListPodSandbox returns a list of SandBoxes. // ListPodSandbox returns a list of SandBoxes.
func (s *Server) ListPodSandbox(ctx context.Context, req *pb.ListPodSandboxRequest) (*pb.ListPodSandboxResponse, error) { func (s *Server) ListPodSandbox(ctx context.Context, req *pb.ListPodSandboxRequest) (*pb.ListPodSandboxResponse, error) {
logrus.Debugf("ListPodSandbox %+v", req) logrus.Debugf("ListPodSandboxRequest %+v", req)
var pods []*pb.PodSandbox var pods []*pb.PodSandbox
var podList []*sandbox var podList []*sandbox
for _, sb := range s.state.sandboxes { for _, sb := range s.state.sandboxes {
@ -547,9 +556,11 @@ func (s *Server) ListPodSandbox(ctx context.Context, req *pb.ListPodSandboxReque
} }
} }
return &pb.ListPodSandboxResponse{ resp := &pb.ListPodSandboxResponse{
Items: pods, Items: pods,
}, nil }
logrus.Debugf("ListPodSandboxResponse %+v", resp)
return resp, nil
} }
func getSELinuxLabels(selinuxOptions *pb.SELinuxOption) (processLabel string, mountLabel string, err error) { func getSELinuxLabels(selinuxOptions *pb.SELinuxOption) (processLabel string, mountLabel string, err error) {