[lxc-devel] [lxd/master] Make LXD less verbose and drop use of "pkg/errors"

stgraber on Github lxc-bot at linuxcontainers.org
Mon Aug 28 19:46:40 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170828/6b5190fb/attachment.bin>
-------------- next part --------------
From 608a80195eeb4358bc2bbaf0685fdb3ac377fac7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Sun, 27 Aug 2017 22:07:06 -0400
Subject: [PATCH 1/2] client: Reduce request logging to Debug
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 client/connection.go | 8 ++++----
 client/lxd.go        | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/client/connection.go b/client/connection.go
index 759ac3d25..a9474a18a 100644
--- a/client/connection.go
+++ b/client/connection.go
@@ -42,7 +42,7 @@ type ConnectionArgs struct {
 //
 // Unless the remote server is trusted by the system CA, the remote certificate must be provided (TLSServerCert).
 func ConnectLXD(url string, args *ConnectionArgs) (ContainerServer, error) {
-	logger.Infof("Connecting to a remote LXD over HTTPs")
+	logger.Debugf("Connecting to a remote LXD over HTTPs")
 
 	return httpsLXD(url, args)
 }
@@ -52,7 +52,7 @@ func ConnectLXD(url string, args *ConnectionArgs) (ContainerServer, error) {
 // If the path argument is empty, then $LXD_DIR/unix.socket will be used.
 // If that one isn't set either, then the path will default to /var/lib/lxd/unix.socket.
 func ConnectLXDUnix(path string, args *ConnectionArgs) (ContainerServer, error) {
-	logger.Infof("Connecting to a local LXD over a Unix socket")
+	logger.Debugf("Connecting to a local LXD over a Unix socket")
 
 	// Use empty args if not specified
 	if args == nil {
@@ -99,7 +99,7 @@ func ConnectLXDUnix(path string, args *ConnectionArgs) (ContainerServer, error)
 //
 // Unless the remote server is trusted by the system CA, the remote certificate must be provided (TLSServerCert).
 func ConnectPublicLXD(url string, args *ConnectionArgs) (ImageServer, error) {
-	logger.Infof("Connecting to a remote public LXD over HTTPs")
+	logger.Debugf("Connecting to a remote public LXD over HTTPs")
 
 	return httpsLXD(url, args)
 }
@@ -108,7 +108,7 @@ func ConnectPublicLXD(url string, args *ConnectionArgs) (ImageServer, error) {
 //
 // Unless the remote server is trusted by the system CA, the remote certificate must be provided (TLSServerCert).
 func ConnectSimpleStreams(url string, args *ConnectionArgs) (ImageServer, error) {
-	logger.Infof("Connecting to a remote simplestreams server")
+	logger.Debugf("Connecting to a remote simplestreams server")
 
 	// Use empty args if not specified
 	if args == nil {
diff --git a/client/lxd.go b/client/lxd.go
index 12ccdee88..f1c171ae3 100644
--- a/client/lxd.go
+++ b/client/lxd.go
@@ -111,7 +111,7 @@ func (r *ProtocolLXD) rawQuery(method string, url string, data interface{}, ETag
 	var err error
 
 	// Log the request
-	logger.Info("Sending request to LXD",
+	logger.Debug("Sending request to LXD",
 		"method", method,
 		"url", url,
 		"etag", ETag,

From 3dc56e77878bb25c023aab9a64f90239d831122d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 28 Aug 2017 15:42:29 -0400
Subject: [PATCH 2/2] db: Revert the use of the "pkg/errors" package
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/db/query/transaction.go |  8 ++------
 lxd/db/schema/schema.go     | 26 ++++++++------------------
 2 files changed, 10 insertions(+), 24 deletions(-)

diff --git a/lxd/db/query/transaction.go b/lxd/db/query/transaction.go
index 845b25a9a..122c3af2a 100644
--- a/lxd/db/query/transaction.go
+++ b/lxd/db/query/transaction.go
@@ -3,15 +3,13 @@ package query
 import (
 	"database/sql"
 	"fmt"
-
-	"github.com/pkg/errors"
 )
 
 // Transaction executes the given function within a database transaction.
 func Transaction(db *sql.DB, f func(*sql.Tx) error) error {
 	tx, err := db.Begin()
 	if err != nil {
-		return errors.Wrap(err, "failed to begin transaction")
+		return fmt.Errorf("failed to begin transaction: %v", err)
 	}
 
 	err = f(tx)
@@ -28,9 +26,7 @@ func Transaction(db *sql.DB, f func(*sql.Tx) error) error {
 func rollback(tx *sql.Tx, reason error) error {
 	err := tx.Rollback()
 	if err != nil {
-		return errors.Wrap(
-			reason,
-			fmt.Sprintf("failed to rollback transaction after error (%v)", reason))
+		return fmt.Errorf("failed to rollback transaction after error (%v)", reason)
 	}
 
 	return reason
diff --git a/lxd/db/schema/schema.go b/lxd/db/schema/schema.go
index d0d83ae28..b21592706 100644
--- a/lxd/db/schema/schema.go
+++ b/lxd/db/schema/schema.go
@@ -6,8 +6,6 @@ import (
 	"sort"
 	"strings"
 
-	"github.com/pkg/errors"
-
 	"github.com/lxc/lxd/lxd/db/query"
 )
 
@@ -148,12 +146,12 @@ INSERT INTO schema (version, updated_at) VALUES (%d, strftime("%%s"))
 func ensureSchemaTableExists(tx *sql.Tx) error {
 	exists, err := doesSchemaTableExist(tx)
 	if err != nil {
-		return errors.Wrap(err, "failed to check if schema table is there")
+		return fmt.Errorf("failed to check if schema table is there: %v", err)
 	}
 	if !exists {
 		err := createSchemaTable(tx)
 		if err != nil {
-			return errors.Wrap(err, "failed to create schema table")
+			return fmt.Errorf("failed to create schema table: %v", err)
 		}
 	}
 	return nil
@@ -165,7 +163,7 @@ func ensureUpdatesAreApplied(tx *sql.Tx, updates []Update, hook Hook) error {
 
 	versions, err := selectSchemaVersions(tx)
 	if err != nil {
-		return errors.Wrap(err, "failed to fetch update versions")
+		return fmt.Errorf("failed to fetch update versions: %v", err)
 	}
 	if len(versions) > 1 {
 		return fmt.Errorf(
@@ -179,9 +177,7 @@ func ensureUpdatesAreApplied(tx *sql.Tx, updates []Update, hook Hook) error {
 	if len(versions) == 0 {
 		err := insertSchemaVersion(tx, len(updates))
 		if err != nil {
-			return errors.Wrap(
-				err,
-				fmt.Sprintf("failed to insert version %d", len(updates)))
+			return fmt.Errorf("failed to insert version %d: %v", len(updates), err)
 		}
 	} else {
 		current = versions[0]
@@ -192,9 +188,7 @@ func ensureUpdatesAreApplied(tx *sql.Tx, updates []Update, hook Hook) error {
 		}
 		err := updateSchemaVersion(tx, current, len(updates))
 		if err != nil {
-			return errors.Wrap(
-				err,
-				fmt.Sprintf("failed to update version %d", current))
+			return fmt.Errorf("failed to update version %d: %v", current, err)
 		}
 	}
 
@@ -208,16 +202,12 @@ func ensureUpdatesAreApplied(tx *sql.Tx, updates []Update, hook Hook) error {
 		if hook != nil {
 			err := hook(current, tx)
 			if err != nil {
-				return errors.Wrap(
-					err,
-					fmt.Sprintf("failed to execute hook (version %d)", current))
+				return fmt.Errorf("failed to execute hook (version %d): %v", current, err)
 			}
 		}
 		err := update(tx)
 		if err != nil {
-			return errors.Wrap(
-				err,
-				fmt.Sprintf("failed to apply update %d", current))
+			return fmt.Errorf("failed to apply update %d: %v", current, err)
 		}
 		current++
 	}
@@ -229,7 +219,7 @@ func ensureUpdatesAreApplied(tx *sql.Tx, updates []Update, hook Hook) error {
 func checkAllUpdatesAreApplied(tx *sql.Tx, updates []Update) error {
 	versions, err := selectSchemaVersions(tx)
 	if err != nil {
-		return errors.Wrap(err, "failed to fetch update versions")
+		return fmt.Errorf("failed to fetch update versions: %v", err)
 	}
 	if len(versions) != 1 {
 		return fmt.Errorf("schema table contains %d rows, expected 1", len(versions))


More information about the lxc-devel mailing list