Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
logging: Add containerID and sandboxID to all log calls
Browse files Browse the repository at this point in the history
Adding cid+sid fields to the log entries generated by most of the CLI
commands will make debugging across the system easier.

Fixes #452.

Signed-off-by: James O. D. Hunt <[email protected]>
  • Loading branch information
jodh-intel committed Jun 28, 2018
1 parent 9377548 commit a3ce121
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cli/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ func create(containerID, bundlePath, console, pidFilePath string, detach bool,
runtimeConfig oci.RuntimeConfig) error {
var err error

kataLog = kataLog.WithField("container", containerID)

// Checks the MUST and MUST NOT from OCI runtime specification
if bundlePath, err = validCreateParams(containerID, bundlePath); err != nil {
return err
Expand Down Expand Up @@ -238,6 +240,8 @@ func createSandbox(ociSpec oci.CompatOCISpec, runtimeConfig oci.RuntimeConfig,
return vc.Process{}, err
}

kataLog = kataLog.WithField("sandbox", sandbox.ID())

containers := sandbox.GetAllContainers()
if len(containers) != 1 {
return vc.Process{}, fmt.Errorf("BUG: Container list from sandbox is wrong, expecting only one container, found %d containers", len(containers))
Expand All @@ -263,6 +267,8 @@ func createContainer(ociSpec oci.CompatOCISpec, containerID, bundlePath,
return vc.Process{}, err
}

kataLog = kataLog.WithField("sandbox", sandboxID)

_, c, err := vci.CreateContainer(sandboxID, contConfig)
if err != nil {
return vc.Process{}, err
Expand Down
6 changes: 6 additions & 0 deletions cli/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -58,6 +59,11 @@ func delete(containerID string, force bool) error {
return err
}

kataLog = kataLog.WithFields(logrus.Fields{
"container": containerID,
"sandbox": sandboxID,
})

containerID = status.ID

containerType, err := oci.GetContainerType(status.Annotations)
Expand Down
5 changes: 5 additions & 0 deletions cli/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ information is displayed once every 5 seconds.`,
return err
}

kataLog = kataLog.WithFields(logrus.Fields{
"container": containerID,
"sandbox": sandboxID,
})

if status.State.State == vc.StateStopped {
return fmt.Errorf("container with id %s is not running", status.ID)
}
Expand Down
6 changes: 6 additions & 0 deletions cli/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -188,6 +189,11 @@ func execute(context *cli.Context) error {
return err
}

kataLog = kataLog.WithFields(logrus.Fields{
"container": containerID,
"sandbox": sandboxID,
})

// Retrieve OCI spec configuration.
ociSpec, err := oci.GetOCIConfig(status)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions cli/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -98,6 +99,11 @@ func kill(containerID, signal string, all bool) error {

containerID = status.ID

kataLog = kataLog.WithFields(logrus.Fields{
"container": containerID,
"sandbox": sandboxID,
})

signum, err := processSignal(signal)
if err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions cli/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package main

import (
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -49,6 +50,11 @@ func toggleContainerPause(containerID string, pause bool) (err error) {

containerID = status.ID

kataLog = kataLog.WithFields(logrus.Fields{
"container": containerID,
"sandbox": sandboxID,
})

if pause {
err = vci.PauseContainer(sandboxID, containerID)
} else {
Expand Down
6 changes: 6 additions & 0 deletions cli/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"

vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -55,6 +56,11 @@ func ps(containerID, format string, args []string) error {

containerID = status.ID

kataLog = kataLog.WithFields(logrus.Fields{
"container": containerID,
"sandbox": sandboxID,
})

// container MUST be running
if status.State.State != vc.StateRunning {
return fmt.Errorf("Container %s is not running", containerID)
Expand Down
6 changes: 6 additions & 0 deletions cli/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -46,6 +47,11 @@ func start(containerID string) (vc.VCSandbox, error) {
return nil, err
}

kataLog = kataLog.WithFields(logrus.Fields{
"container": containerID,
"sandbox": sandboxID,
})

containerID = status.ID

containerType, err := oci.GetContainerType(status.Annotations)
Expand Down
2 changes: 2 additions & 0 deletions cli/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ instance of a container.`,
}

func state(containerID string) error {
kataLog = kataLog.WithField("container", containerID)

// Checks the MUST and MUST NOT from OCI runtime specification
status, _, err := getExistingContainerInfo(containerID)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions cli/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/docker/go-units"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -137,6 +138,12 @@ other options are ignored.
}

containerID = status.ID

kataLog = kataLog.WithFields(logrus.Fields{
"container": containerID,
"sandbox": sandboxID,
})

// container MUST be running
if status.State.State != vc.StateRunning {
return fmt.Errorf("Container %s is not running", containerID)
Expand Down

0 comments on commit a3ce121

Please sign in to comment.