[lxc-devel] [lxd/master] 2016 09 18/logging issue 1928
brauner on Github
lxc-bot at linuxcontainers.org
Sun Sep 18 21:04:15 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 318 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160918/6cc45bf9/attachment.bin>
-------------- next part --------------
From 838611c47e5ba86becbb34ab712a5b41c2e2fe65 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at canonical.com>
Date: Sun, 18 Sep 2016 17:28:43 +0200
Subject: [PATCH 1/9] lxd/container_lxc: improve log for container stop
Signed-off-by: Christian Brauner <christian.brauner at canonical.com>
---
lxd/container_lxc.go | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 4356cd8..9ea8bdd 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -1555,12 +1555,22 @@ func (c *containerLXC) OnStart() error {
// Stop functions
func (c *containerLXC) Stop(stateful bool) error {
+ var ctxMap log.Ctx
// Setup a new operation
op, err := c.createOperation("stop", 30)
if err != nil {
return err
}
+ ctxMap = log.Ctx{"name": c.name,
+ "action": op.action,
+ "creation date": c.creationDate,
+ "ephemeral": c.ephemeral,
+ "last used": c.lastUsedDate,
+ "stateful": stateful}
+
+ shared.LogInfo("Stopping container", ctxMap)
+
// Handle stateful stop
if stateful {
// Cleanup any existing state
@@ -1570,6 +1580,7 @@ func (c *containerLXC) Stop(stateful bool) error {
err := os.MkdirAll(stateDir, 0700)
if err != nil {
op.Done(err)
+ shared.LogError("Failed stopping container", ctxMap)
return err
}
@@ -1577,6 +1588,7 @@ func (c *containerLXC) Stop(stateful bool) error {
err = c.Migrate(lxc.MIGRATE_DUMP, stateDir, "snapshot", true, false)
if err != nil {
op.Done(err)
+ shared.LogError("Failed stopping container", ctxMap)
return err
}
@@ -1584,10 +1596,12 @@ func (c *containerLXC) Stop(stateful bool) error {
err = dbContainerSetStateful(c.daemon.db, c.id, true)
if err != nil {
op.Done(err)
+ shared.LogError("Failed stopping container", ctxMap)
return err
}
op.Done(nil)
+ shared.LogInfo("Stopped container", ctxMap)
return nil
}
@@ -1595,6 +1609,7 @@ func (c *containerLXC) Stop(stateful bool) error {
err = c.initLXC()
if err != nil {
op.Done(err)
+ shared.LogError("Failed stopping container", ctxMap)
return err
}
@@ -1603,10 +1618,18 @@ func (c *containerLXC) Stop(stateful bool) error {
if err := c.c.Stop(); err != nil {
op.Done(err)
+ shared.LogError("Failed stopping container", ctxMap)
return err
}
- return op.Wait()
+ err = op.Wait()
+ if err != nil {
+ shared.LogError("Failed stopping container", ctxMap)
+ return err
+ }
+
+ shared.LogInfo("Stopped container", ctxMap)
+ return err
}
func (c *containerLXC) Shutdown(timeout time.Duration) error {
From 64e431c620b1a7b8288bcd9ac462f546410b4162 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at canonical.com>
Date: Sun, 18 Sep 2016 17:33:32 +0200
Subject: [PATCH 2/9] lxd/container_lxc: improve log on shutdown
Signed-off-by: Christian Brauner <christian.brauner at canonical.com>
---
lxd/container_lxc.go | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 9ea8bdd..f19c22a 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -1633,25 +1633,46 @@ func (c *containerLXC) Stop(stateful bool) error {
}
func (c *containerLXC) Shutdown(timeout time.Duration) error {
+ var ctxMap log.Ctx
+
// Setup a new operation
op, err := c.createOperation("shutdown", 30)
if err != nil {
return err
}
+ ctxMap = log.Ctx{"name": c.name,
+ "action": op.action,
+ "creation date": c.creationDate,
+ "ephemeral": c.ephemeral,
+ "last used": c.lastUsedDate,
+ "timeout": timeout}
+
+ shared.LogInfo("Shutting down container", ctxMap)
+
// Load the go-lxc struct
err = c.initLXC()
if err != nil {
op.Done(err)
+ shared.LogError("Failed shutting down container", ctxMap)
return err
}
if err := c.c.Shutdown(timeout); err != nil {
op.Done(err)
+ shared.LogError("Failed shutting down container", ctxMap)
return err
}
- return op.Wait()
+ err = op.Wait()
+ if err != nil {
+ shared.LogError("Failed shutting down container", ctxMap)
+ return err
+ }
+
+ shared.LogInfo("Shut down container", ctxMap)
+
+ return err
}
func (c *containerLXC) OnStop(target string) error {
From 0374ef0cde7faf55679594aff8848f002169f843 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at canonical.com>
Date: Sun, 18 Sep 2016 17:39:19 +0200
Subject: [PATCH 3/9] lxd/container_lxc: improve log on container freeze
Signed-off-by: Christian Brauner <christian.brauner at canonical.com>
---
lxd/container_lxc.go | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index f19c22a..83425b1 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -1777,13 +1777,29 @@ func (c *containerLXC) OnStop(target string) error {
// Freezer functions
func (c *containerLXC) Freeze() error {
+ ctxMap := log.Ctx{"name": c.name,
+ "creation date": c.creationDate,
+ "ephemeral": c.ephemeral,
+ "last used": c.lastUsedDate}
+
+ shared.LogInfo("Freezing container", ctxMap)
+
// Load the go-lxc struct
err := c.initLXC()
if err != nil {
+ shared.LogError("Failed freezing container", ctxMap)
+ return err
+ }
+
+ err = c.c.Freeze()
+ if err != nil {
+ shared.LogError("Failed freezing container", ctxMap)
return err
}
- return c.c.Freeze()
+ shared.LogInfo("Froze container", ctxMap)
+
+ return err
}
func (c *containerLXC) Unfreeze() error {
From 07757efc426e71057fd371d00dce33cbfb2c3e17 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at canonical.com>
Date: Sun, 18 Sep 2016 17:45:50 +0200
Subject: [PATCH 4/9] lxd/container_lxc: improve log for unfreeze
Signed-off-by: Christian Brauner <christian.brauner at canonical.com>
---
lxd/container_lxc.go | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 83425b1..bfb2822 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -1667,7 +1667,7 @@ func (c *containerLXC) Shutdown(timeout time.Duration) error {
err = op.Wait()
if err != nil {
shared.LogError("Failed shutting down container", ctxMap)
- return err
+ return err
}
shared.LogInfo("Shut down container", ctxMap)
@@ -1803,13 +1803,28 @@ func (c *containerLXC) Freeze() error {
}
func (c *containerLXC) Unfreeze() error {
+ ctxMap := log.Ctx{"name": c.name,
+ "creation date": c.creationDate,
+ "ephemeral": c.ephemeral,
+ "last used": c.lastUsedDate}
+
+ shared.LogInfo("Unfreezing container", ctxMap)
+
// Load the go-lxc struct
err := c.initLXC()
if err != nil {
+ shared.LogError("Failed unfreezing container", ctxMap)
return err
}
- return c.c.Unfreeze()
+ err = c.c.Unfreeze()
+ if err != nil {
+ shared.LogError("Failed unfreezing container", ctxMap)
+ }
+
+ shared.LogInfo("Unfroze container", ctxMap)
+
+ return err
}
var LxcMonitorStateError = fmt.Errorf("Monitor is hung")
From 9436c5d69118584c650d703cb2224f3fa518d90c Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at canonical.com>
Date: Sun, 18 Sep 2016 17:48:25 +0200
Subject: [PATCH 5/9] lxd/container_lxc: rm LogError() from Restore()
With recent changes Stop() will write a LogError*() itself.
Signed-off-by: Christian Brauner <christian.brauner at canonical.com>
---
lxd/container_lxc.go | 5 -----
1 file changed, 5 deletions(-)
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index bfb2822..3b11769 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -1975,11 +1975,6 @@ func (c *containerLXC) Restore(sourceContainer container) error {
if c.IsRunning() {
wasRunning = true
if err := c.Stop(false); err != nil {
- shared.LogError(
- "Could not stop container",
- log.Ctx{
- "container": c.Name(),
- "err": err})
return err
}
}
From 01888232657c19dfc0fe6fb25790bff20425d632 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at canonical.com>
Date: Sun, 18 Sep 2016 18:01:48 +0200
Subject: [PATCH 6/9] lxd/container_lxc: smarter logs on container start
Before, no log entry was created when a stateful container was started. This
commit makes sure that a log entry is created for stateful container starts.
Signed-off-by: Christian Brauner <christian.brauner at canonical.com>
---
lxd/container_lxc.go | 43 +++++++++++++++++++++++--------------------
1 file changed, 23 insertions(+), 20 deletions(-)
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 3b11769..9b8577e 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -1353,6 +1353,8 @@ func (c *containerLXC) startCommon() (string, error) {
}
func (c *containerLXC) Start(stateful bool) error {
+ var ctxMap log.Ctx
+
// Setup a new operation
op, err := c.createOperation("start", 30)
if err != nil {
@@ -1371,6 +1373,15 @@ func (c *containerLXC) Start(stateful bool) error {
return err
}
+ ctxMap = log.Ctx{"name": c.name,
+ "action": op.action,
+ "creation date": c.creationDate,
+ "ephemeral": c.ephemeral,
+ "last used": c.lastUsedDate,
+ "stateful": stateful}
+
+ shared.LogInfo("Starting container", ctxMap)
+
// If stateful, restore now
if stateful {
if !c.stateful {
@@ -1384,7 +1395,16 @@ func (c *containerLXC) Start(stateful bool) error {
os.RemoveAll(c.StatePath())
c.stateful = false
- return dbContainerSetStateful(c.daemon.db, c.id, false)
+
+ err = dbContainerSetStateful(c.daemon.db, c.id, false)
+ if err != nil {
+ shared.LogError("Failed starting container", ctxMap)
+ return err
+ }
+
+ shared.LogInfo("Started container", ctxMap)
+
+ return err
} else if c.stateful {
/* stateless start required when we have state, let's delete it */
err := os.RemoveAll(c.StatePath())
@@ -1399,13 +1419,6 @@ func (c *containerLXC) Start(stateful bool) error {
}
}
- shared.LogInfo("Starting container",
- log.Ctx{"name": c.name,
- "action": op.action,
- "creation date": c.creationDate,
- "ephemeral": c.ephemeral,
- "last used": c.lastUsedDate})
-
// Start the LXC container
out, err := exec.Command(
execPath,
@@ -1449,12 +1462,7 @@ func (c *containerLXC) Start(stateful bool) error {
}
}
- shared.LogError("Failed starting container",
- log.Ctx{"name": c.name,
- "action": op.action,
- "creation date": c.creationDate,
- "ephemeral": c.ephemeral,
- "last used": c.lastUsedDate})
+ shared.LogError("Failed starting container", ctxMap)
// Return the actual error
return fmt.Errorf(
@@ -1465,12 +1473,7 @@ func (c *containerLXC) Start(stateful bool) error {
err, lxcLog)
}
- shared.LogInfo("Started container",
- log.Ctx{"name": c.name,
- "action": op.action,
- "creation date": c.creationDate,
- "ephemeral": c.ephemeral,
- "last used": c.lastUsedDate})
+ shared.LogInfo("Started container", ctxMap)
return nil
}
From 63ebd1bf7ccbdca695fc5d7a56580ca3613c48af Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at canonical.com>
Date: Sun, 18 Sep 2016 18:14:50 +0200
Subject: [PATCH 7/9] lxd/container_lxc: improve log for restore
Signed-off-by: Christian Brauner <christian.brauner at canonical.com>
---
lxd/container_lxc.go | 28 ++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 9b8577e..b61286b 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -1958,6 +1958,8 @@ func (c *containerLXC) Snapshots() ([]container, error) {
}
func (c *containerLXC) Restore(sourceContainer container) error {
+ var ctxMap log.Ctx
+
// Check if we can restore the container
err := c.storage.ContainerCanRestore(c, sourceContainer)
if err != nil {
@@ -1982,13 +1984,18 @@ func (c *containerLXC) Restore(sourceContainer container) error {
}
}
+ ctxMap = log.Ctx{"name": c.name,
+ "creation date": c.creationDate,
+ "ephemeral": c.ephemeral,
+ "last used": c.lastUsedDate,
+ "source container": sourceContainer.Name()}
+
+ shared.LogInfo("Restoring container", ctxMap)
+
// Restore the rootfs
err = c.storage.ContainerRestore(c, sourceContainer)
if err != nil {
- shared.LogError("Restoring the filesystem failed",
- log.Ctx{
- "source": sourceContainer.Name(),
- "destination": c.Name()})
+ shared.LogError("Failed restoring container filesystem", ctxMap)
return err
}
@@ -2003,11 +2010,7 @@ func (c *containerLXC) Restore(sourceContainer container) error {
err = c.Update(args, false)
if err != nil {
- shared.LogError("Restoring the configuration failed",
- log.Ctx{
- "source": sourceContainer.Name(),
- "destination": c.Name()})
-
+ shared.LogError("Failed restoring container configuration", ctxMap)
return err
}
@@ -2022,21 +2025,26 @@ func (c *containerLXC) Restore(sourceContainer container) error {
// this in snapshots.
err2 := os.RemoveAll(c.StatePath())
if err2 != nil {
- shared.LogError("failed to delete snapshot state", log.Ctx{"path": c.StatePath(), "err": err2})
+ shared.LogError("Failed to delete snapshot state", log.Ctx{"path": c.StatePath(), "err": err2})
}
if err != nil {
+ shared.LogInfo("Failed restoring container", ctxMap)
return err
}
+ shared.LogInfo("Restored container", ctxMap)
return nil
}
// Restart the container
if wasRunning {
+ shared.LogInfo("Restored container", ctxMap)
return c.Start(false)
}
+ shared.LogInfo("Restored container", ctxMap)
+
return nil
}
From 2db88de1f5aaa361d1de5d77fbe1b429e80c3df3 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at canonical.com>
Date: Sun, 18 Sep 2016 18:23:44 +0200
Subject: [PATCH 8/9] lxd/container_lxc: improve log on container delete
Signed-off-by: Christian Brauner <christian.brauner at canonical.com>
---
lxd/container_lxc.go | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index b61286b..1e97a7b 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -2065,15 +2065,22 @@ func (c *containerLXC) cleanup() {
}
func (c *containerLXC) Delete() error {
+ ctxMap := log.Ctx{"name": c.name,
+ "creation date": c.creationDate,
+ "ephemeral": c.ephemeral,
+ "last used": c.lastUsedDate}
+
+ shared.LogInfo("Deleting container", ctxMap)
+
if c.IsSnapshot() {
// Remove the snapshot
if err := c.storage.ContainerSnapshotDelete(c); err != nil {
- shared.LogWarn("failed to delete snapshot", log.Ctx{"name": c.Name(), "err": err})
+ shared.LogWarn("Failed to delete snapshot", log.Ctx{"name": c.Name(), "err": err})
}
} else {
// Remove all snapshot
if err := containerDeleteSnapshots(c.daemon, c.Name()); err != nil {
- shared.LogWarn("failed to delete snapshots", log.Ctx{"name": c.Name(), "err": err})
+ shared.LogWarn("Failed to delete snapshots", log.Ctx{"name": c.Name(), "err": err})
}
// Clean things up
@@ -2082,6 +2089,7 @@ func (c *containerLXC) Delete() error {
// Delete the container from disk
if shared.PathExists(c.Path()) {
if err := c.storage.ContainerDelete(c); err != nil {
+ shared.LogError("Failed deleting container", ctxMap)
return err
}
}
@@ -2089,9 +2097,12 @@ func (c *containerLXC) Delete() error {
// Remove the database record
if err := dbContainerRemove(c.daemon.db, c.Name()); err != nil {
+ shared.LogError("Failed deleting container", ctxMap)
return err
}
+ shared.LogInfo("Deleted container", ctxMap)
+
return nil
}
From 8c1613a50d3374eacb4b4715ea8e334c0db6994f Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at canonical.com>
Date: Sun, 18 Sep 2016 18:40:11 +0200
Subject: [PATCH 9/9] lxd/container_lxc: improve log on container rename
Signed-off-by: Christian Brauner <christian.brauner at canonical.com>
---
lxd/container_lxc.go | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 1e97a7b..e62cde9 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -2108,6 +2108,13 @@ func (c *containerLXC) Delete() error {
func (c *containerLXC) Rename(newName string) error {
oldName := c.Name()
+ ctxMap := log.Ctx{"name": c.name,
+ "creation date": c.creationDate,
+ "ephemeral": c.ephemeral,
+ "last used": c.lastUsedDate,
+ "newname": newName}
+
+ shared.LogInfo("Renaming container", ctxMap)
// Sanity checks
if !c.IsSnapshot() && !shared.ValidHostname(newName) {
@@ -2115,7 +2122,7 @@ func (c *containerLXC) Rename(newName string) error {
}
if c.IsRunning() {
- return fmt.Errorf("renaming of running container not allowed")
+ return fmt.Errorf("Renaming of running container not allowed")
}
// Clean things up
@@ -2126,6 +2133,7 @@ func (c *containerLXC) Rename(newName string) error {
if shared.PathExists(c.LogPath()) {
err := os.Rename(c.LogPath(), shared.LogPath(newName))
if err != nil {
+ shared.LogError("Failed renaming container", ctxMap)
return err
}
}
@@ -2133,16 +2141,19 @@ func (c *containerLXC) Rename(newName string) error {
// Rename the storage entry
if c.IsSnapshot() {
if err := c.storage.ContainerSnapshotRename(c, newName); err != nil {
+ shared.LogError("Failed renaming container", ctxMap)
return err
}
} else {
if err := c.storage.ContainerRename(c, newName); err != nil {
+ shared.LogError("Failed renaming container", ctxMap)
return err
}
}
// Rename the database entry
if err := dbContainerRename(c.daemon.db, oldName, newName); err != nil {
+ shared.LogError("Failed renaming container", ctxMap)
return err
}
@@ -2150,6 +2161,7 @@ func (c *containerLXC) Rename(newName string) error {
// Rename all the snapshots
results, err := dbContainerGetSnapshots(c.daemon.db, oldName)
if err != nil {
+ shared.LogError("Failed renaming container", ctxMap)
return err
}
@@ -2158,6 +2170,7 @@ func (c *containerLXC) Rename(newName string) error {
baseSnapName := filepath.Base(sname)
newSnapshotName := newName + shared.SnapshotDelimiter + baseSnapName
if err := dbContainerRename(c.daemon.db, sname, newSnapshotName); err != nil {
+ shared.LogError("Failed renaming container", ctxMap)
return err
}
}
@@ -2169,6 +2182,8 @@ func (c *containerLXC) Rename(newName string) error {
// Invalidate the go-lxc cache
c.c = nil
+ shared.LogInfo("Renamed container", ctxMap)
+
return nil
}
More information about the lxc-devel
mailing list