mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-11 21:02:34 +00:00
Merge pull request #468 from jodh-intel/improve-cid+sid-logging
logging: Reset external loggers when cid+sid available
This commit is contained in:
commit
2865dc21aa
@ -16,7 +16,6 @@ import (
|
|||||||
|
|
||||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
|
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -90,6 +89,7 @@ func create(containerID, bundlePath, console, pidFilePath string, detach bool,
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
kataLog = kataLog.WithField("container", containerID)
|
kataLog = kataLog.WithField("container", containerID)
|
||||||
|
setExternalLoggers(kataLog)
|
||||||
|
|
||||||
// Checks the MUST and MUST NOT from OCI runtime specification
|
// Checks the MUST and MUST NOT from OCI runtime specification
|
||||||
if bundlePath, err = validCreateParams(containerID, bundlePath); err != nil {
|
if bundlePath, err = validCreateParams(containerID, bundlePath); err != nil {
|
||||||
@ -241,6 +241,7 @@ func createSandbox(ociSpec oci.CompatOCISpec, runtimeConfig oci.RuntimeConfig,
|
|||||||
}
|
}
|
||||||
|
|
||||||
kataLog = kataLog.WithField("sandbox", sandbox.ID())
|
kataLog = kataLog.WithField("sandbox", sandbox.ID())
|
||||||
|
setExternalLoggers(kataLog)
|
||||||
|
|
||||||
containers := sandbox.GetAllContainers()
|
containers := sandbox.GetAllContainers()
|
||||||
if len(containers) != 1 {
|
if len(containers) != 1 {
|
||||||
@ -268,6 +269,7 @@ func createContainer(ociSpec oci.CompatOCISpec, containerID, bundlePath,
|
|||||||
}
|
}
|
||||||
|
|
||||||
kataLog = kataLog.WithField("sandbox", sandboxID)
|
kataLog = kataLog.WithField("sandbox", sandboxID)
|
||||||
|
setExternalLoggers(kataLog)
|
||||||
|
|
||||||
_, c, err := vci.CreateContainer(sandboxID, contConfig)
|
_, c, err := vci.CreateContainer(sandboxID, contConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -283,11 +285,7 @@ func createContainer(ociSpec oci.CompatOCISpec, containerID, bundlePath,
|
|||||||
|
|
||||||
func createCgroupsFiles(containerID string, cgroupsDirPath string, cgroupsPathList []string, pid int) error {
|
func createCgroupsFiles(containerID string, cgroupsDirPath string, cgroupsPathList []string, pid int) error {
|
||||||
if len(cgroupsPathList) == 0 {
|
if len(cgroupsPathList) == 0 {
|
||||||
fields := logrus.Fields{
|
kataLog.WithField("pid", pid).Info("Cgroups files not created because cgroupsPath was empty")
|
||||||
"container": containerID,
|
|
||||||
"pid": pid,
|
|
||||||
}
|
|
||||||
kataLog.WithFields(fields).Info("Cgroups files not created because cgroupsPath was empty")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,6 +64,8 @@ func delete(containerID string, force bool) error {
|
|||||||
"sandbox": sandboxID,
|
"sandbox": sandboxID,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
setExternalLoggers(kataLog)
|
||||||
|
|
||||||
containerID = status.ID
|
containerID = status.ID
|
||||||
|
|
||||||
containerType, err := oci.GetContainerType(status.Annotations)
|
containerType, err := oci.GetContainerType(status.Annotations)
|
||||||
|
@ -156,6 +156,8 @@ information is displayed once every 5 seconds.`,
|
|||||||
"sandbox": sandboxID,
|
"sandbox": sandboxID,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
setExternalLoggers(kataLog)
|
||||||
|
|
||||||
if status.State.State == vc.StateStopped {
|
if status.State.State == vc.StateStopped {
|
||||||
return fmt.Errorf("container with id %s is not running", status.ID)
|
return fmt.Errorf("container with id %s is not running", status.ID)
|
||||||
}
|
}
|
||||||
|
@ -194,6 +194,8 @@ func execute(context *cli.Context) error {
|
|||||||
"sandbox": sandboxID,
|
"sandbox": sandboxID,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
setExternalLoggers(kataLog)
|
||||||
|
|
||||||
// Retrieve OCI spec configuration.
|
// Retrieve OCI spec configuration.
|
||||||
ociSpec, err := oci.GetOCIConfig(status)
|
ociSpec, err := oci.GetOCIConfig(status)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -104,6 +104,8 @@ func kill(containerID, signal string, all bool) error {
|
|||||||
"sandbox": sandboxID,
|
"sandbox": sandboxID,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
setExternalLoggers(kataLog)
|
||||||
|
|
||||||
signum, err := processSignal(signal)
|
signum, err := processSignal(signal)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
16
cli/main.go
16
cli/main.go
@ -187,6 +187,16 @@ func setupSignalHandler() {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setExternalLoggers registers the specified logger with the external
|
||||||
|
// packages which accept a logger to handle their own logging.
|
||||||
|
func setExternalLoggers(logger *logrus.Entry) {
|
||||||
|
// Set virtcontainers logger.
|
||||||
|
vci.SetLogger(logger)
|
||||||
|
|
||||||
|
// Set the OCI package logger.
|
||||||
|
oci.SetLogger(logger)
|
||||||
|
}
|
||||||
|
|
||||||
// beforeSubcommands is the function to perform preliminary checks
|
// beforeSubcommands is the function to perform preliminary checks
|
||||||
// before command-line parsing occurs.
|
// before command-line parsing occurs.
|
||||||
func beforeSubcommands(context *cli.Context) error {
|
func beforeSubcommands(context *cli.Context) error {
|
||||||
@ -225,11 +235,7 @@ func beforeSubcommands(context *cli.Context) error {
|
|||||||
return fmt.Errorf("unknown log-format %q", context.GlobalString("log-format"))
|
return fmt.Errorf("unknown log-format %q", context.GlobalString("log-format"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set virtcontainers logger.
|
setExternalLoggers(kataLog)
|
||||||
vci.SetLogger(kataLog)
|
|
||||||
|
|
||||||
// Set the OCI package logger.
|
|
||||||
oci.SetLogger(kataLog)
|
|
||||||
|
|
||||||
ignoreLogging := false
|
ignoreLogging := false
|
||||||
|
|
||||||
|
@ -55,6 +55,8 @@ func toggleContainerPause(containerID string, pause bool) (err error) {
|
|||||||
"sandbox": sandboxID,
|
"sandbox": sandboxID,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
setExternalLoggers(kataLog)
|
||||||
|
|
||||||
if pause {
|
if pause {
|
||||||
err = vci.PauseContainer(sandboxID, containerID)
|
err = vci.PauseContainer(sandboxID, containerID)
|
||||||
} else {
|
} else {
|
||||||
|
@ -61,6 +61,8 @@ func ps(containerID, format string, args []string) error {
|
|||||||
"sandbox": sandboxID,
|
"sandbox": sandboxID,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
setExternalLoggers(kataLog)
|
||||||
|
|
||||||
// container MUST be running
|
// container MUST be running
|
||||||
if status.State.State != vc.StateRunning {
|
if status.State.State != vc.StateRunning {
|
||||||
return fmt.Errorf("Container %s is not running", containerID)
|
return fmt.Errorf("Container %s is not running", containerID)
|
||||||
|
@ -52,6 +52,8 @@ func start(containerID string) (vc.VCSandbox, error) {
|
|||||||
"sandbox": sandboxID,
|
"sandbox": sandboxID,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
setExternalLoggers(kataLog)
|
||||||
|
|
||||||
containerID = status.ID
|
containerID = status.ID
|
||||||
|
|
||||||
containerType, err := oci.GetContainerType(status.Annotations)
|
containerType, err := oci.GetContainerType(status.Annotations)
|
||||||
|
@ -36,6 +36,8 @@ instance of a container.`,
|
|||||||
func state(containerID string) error {
|
func state(containerID string) error {
|
||||||
kataLog = kataLog.WithField("container", containerID)
|
kataLog = kataLog.WithField("container", containerID)
|
||||||
|
|
||||||
|
setExternalLoggers(kataLog)
|
||||||
|
|
||||||
// Checks the MUST and MUST NOT from OCI runtime specification
|
// Checks the MUST and MUST NOT from OCI runtime specification
|
||||||
status, _, err := getExistingContainerInfo(containerID)
|
status, _, err := getExistingContainerInfo(containerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user