mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-01 17:52:40 +00:00
logging: Improve cid+sid logging
Refine the changes made on #468 by adding the containerID log field as soon as possible (before *any* virtcontainers calls). This requires that `setExternalLoggers()` be called more times, but it's essential to ensure the correct log fields are available as early as possible. Partially fixes #519. Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
parent
58448bbcb8
commit
3d5ed6669c
@ -53,12 +53,17 @@ EXAMPLE:
|
||||
}
|
||||
|
||||
func delete(containerID string, force bool) error {
|
||||
kataLog = kataLog.WithField("container", containerID)
|
||||
setExternalLoggers(kataLog)
|
||||
|
||||
// Checks the MUST and MUST NOT from OCI runtime specification
|
||||
status, sandboxID, err := getExistingContainerInfo(containerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
containerID = status.ID
|
||||
|
||||
kataLog = kataLog.WithFields(logrus.Fields{
|
||||
"container": containerID,
|
||||
"sandbox": sandboxID,
|
||||
@ -66,8 +71,6 @@ func delete(containerID string, force bool) error {
|
||||
|
||||
setExternalLoggers(kataLog)
|
||||
|
||||
containerID = status.ID
|
||||
|
||||
containerType, err := oci.GetContainerType(status.Annotations)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -141,6 +141,9 @@ information is displayed once every 5 seconds.`,
|
||||
return fmt.Errorf("container id cannot be empty")
|
||||
}
|
||||
|
||||
kataLog = kataLog.WithField("container", containerID)
|
||||
setExternalLoggers(kataLog)
|
||||
|
||||
duration := context.Duration("interval")
|
||||
if duration <= 0 {
|
||||
return fmt.Errorf("duration interval must be greater than 0")
|
||||
@ -151,6 +154,8 @@ information is displayed once every 5 seconds.`,
|
||||
return err
|
||||
}
|
||||
|
||||
containerID = status.ID
|
||||
|
||||
kataLog = kataLog.WithFields(logrus.Fields{
|
||||
"container": containerID,
|
||||
"sandbox": sandboxID,
|
||||
|
15
cli/exec.go
15
cli/exec.go
@ -16,7 +16,6 @@ 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"
|
||||
)
|
||||
|
||||
@ -184,16 +183,16 @@ func generateExecParams(context *cli.Context, specProcess *oci.CompatOCIProcess)
|
||||
|
||||
func execute(context *cli.Context) error {
|
||||
containerID := context.Args().First()
|
||||
|
||||
kataLog = kataLog.WithField("container", containerID)
|
||||
setExternalLoggers(kataLog)
|
||||
|
||||
status, sandboxID, err := getExistingContainerInfo(containerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
kataLog = kataLog.WithFields(logrus.Fields{
|
||||
"container": containerID,
|
||||
"sandbox": sandboxID,
|
||||
})
|
||||
|
||||
kataLog = kataLog.WithField("sandbox", sandboxID)
|
||||
setExternalLoggers(kataLog)
|
||||
|
||||
// Retrieve OCI spec configuration.
|
||||
@ -208,6 +207,10 @@ func execute(context *cli.Context) error {
|
||||
}
|
||||
|
||||
params.cID = status.ID
|
||||
containerID = params.cID
|
||||
|
||||
kataLog = kataLog.WithField("container", containerID)
|
||||
setExternalLoggers(kataLog)
|
||||
|
||||
// container MUST be ready or running.
|
||||
if status.State.State != vc.StateReady &&
|
||||
|
@ -91,8 +91,12 @@ var signals = map[string]syscall.Signal{
|
||||
}
|
||||
|
||||
func kill(containerID, signal string, all bool) error {
|
||||
kataLog = kataLog.WithField("container", containerID)
|
||||
setExternalLoggers(kataLog)
|
||||
|
||||
// Checks the MUST and MUST NOT from OCI runtime specification
|
||||
status, sandboxID, err := getExistingContainerInfo(containerID)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -42,6 +42,9 @@ Where "<container-id>" is the container name to be resumed.`,
|
||||
}
|
||||
|
||||
func toggleContainerPause(containerID string, pause bool) (err error) {
|
||||
kataLog = kataLog.WithField("container", containerID)
|
||||
setExternalLoggers(kataLog)
|
||||
|
||||
// Checks the MUST and MUST NOT from OCI runtime specification
|
||||
status, sandboxID, err := getExistingContainerInfo(containerID)
|
||||
if err != nil {
|
||||
|
@ -48,6 +48,9 @@ func ps(containerID, format string, args []string) error {
|
||||
return fmt.Errorf("Missing container ID")
|
||||
}
|
||||
|
||||
kataLog = kataLog.WithField("container", containerID)
|
||||
setExternalLoggers(kataLog)
|
||||
|
||||
// Checks the MUST and MUST NOT from OCI runtime specification
|
||||
status, sandboxID, err := getExistingContainerInfo(containerID)
|
||||
if err != nil {
|
||||
|
@ -41,12 +41,17 @@ var startCLICommand = cli.Command{
|
||||
}
|
||||
|
||||
func start(containerID string) (vc.VCSandbox, error) {
|
||||
kataLog = kataLog.WithField("container", containerID)
|
||||
setExternalLoggers(kataLog)
|
||||
|
||||
// Checks the MUST and MUST NOT from OCI runtime specification
|
||||
status, sandboxID, err := getExistingContainerInfo(containerID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
containerID = status.ID
|
||||
|
||||
kataLog = kataLog.WithFields(logrus.Fields{
|
||||
"container": containerID,
|
||||
"sandbox": sandboxID,
|
||||
@ -54,8 +59,6 @@ func start(containerID string) (vc.VCSandbox, error) {
|
||||
|
||||
setExternalLoggers(kataLog)
|
||||
|
||||
containerID = status.ID
|
||||
|
||||
containerType, err := oci.GetContainerType(status.Annotations)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Loading…
Reference in New Issue
Block a user