From f714840da7c1e4e97687725873f3a9aa8f9b9912 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 17 Dec 2020 16:52:47 -0800 Subject: [PATCH] add _MINIO_SERVER_DEBUG env for enabling debug messages (#11128) --- cmd/background-newdisks-heal-ops.go | 5 +++++ cmd/common-main.go | 7 +++++++ cmd/data-crawler.go | 5 +++++ cmd/data-update-tracker.go | 2 +- cmd/erasure-sets.go | 5 +++++ cmd/metacache-bucket.go | 4 ++-- cmd/metacache-set.go | 4 ++-- cmd/metacache.go | 3 --- pkg/console/console.go | 15 +++------------ 9 files changed, 30 insertions(+), 20 deletions(-) diff --git a/cmd/background-newdisks-heal-ops.go b/cmd/background-newdisks-heal-ops.go index 77242ad60..4b2ded917 100644 --- a/cmd/background-newdisks-heal-ops.go +++ b/cmd/background-newdisks-heal-ops.go @@ -25,6 +25,7 @@ import ( "github.com/dustin/go-humanize" "github.com/minio/minio/cmd/logger" + "github.com/minio/minio/pkg/console" ) const ( @@ -140,6 +141,10 @@ wait: } } + if serverDebugLog { + console.Debugf("disk check timer fired, attempting to heal %d drives\n", len(healDisks)) + } + // heal only if new disks found. for _, endpoint := range healDisks { disk, format, err := connectEndpoint(endpoint) diff --git a/cmd/common-main.go b/cmd/common-main.go index 59fda680f..68edba93c 100644 --- a/cmd/common-main.go +++ b/cmd/common-main.go @@ -30,6 +30,7 @@ import ( "strings" "time" + "github.com/fatih/color" dns2 "github.com/miekg/dns" "github.com/minio/cli" "github.com/minio/minio-go/v7/pkg/set" @@ -38,9 +39,13 @@ import ( "github.com/minio/minio/cmd/logger" "github.com/minio/minio/pkg/auth" "github.com/minio/minio/pkg/certs" + "github.com/minio/minio/pkg/console" "github.com/minio/minio/pkg/env" ) +// serverDebugLog will enable debug printing +var serverDebugLog = env.Get("_MINIO_SERVER_DEBUG", config.EnableOff) == config.EnableOn + func init() { logger.Init(GOPATH, GOROOT) logger.RegisterError(config.FmtError) @@ -53,6 +58,8 @@ func init() { globalReplicationState = newReplicationState() globalTransitionState = newTransitionState() + console.SetColor("Debug", color.New()) + gob.Register(StorageErr("")) } diff --git a/cmd/data-crawler.go b/cmd/data-crawler.go index f7cbdaf1f..6c972fbf6 100644 --- a/cmd/data-crawler.go +++ b/cmd/data-crawler.go @@ -35,6 +35,7 @@ import ( "github.com/minio/minio/pkg/bucket/lifecycle" "github.com/minio/minio/pkg/bucket/replication" "github.com/minio/minio/pkg/color" + "github.com/minio/minio/pkg/console" "github.com/minio/minio/pkg/env" "github.com/minio/minio/pkg/event" "github.com/minio/minio/pkg/hash" @@ -110,6 +111,10 @@ func runDataCrawler(ctx context.Context, objAPI ObjectLayer) { // Reset the timer for next cycle. crawlTimer.Reset(dataCrawlStartDelay) + if intDataUpdateTracker.debug { + console.Debugln("starting crawler cycle") + } + // Wait before starting next cycle and wait on startup. results := make(chan DataUsageInfo, 1) go storeDataUsageInBackend(ctx, objAPI, results) diff --git a/cmd/data-update-tracker.go b/cmd/data-update-tracker.go index 15cd1cd32..eaf8ad954 100644 --- a/cmd/data-update-tracker.go +++ b/cmd/data-update-tracker.go @@ -79,7 +79,7 @@ func newDataUpdateTracker() *dataUpdateTracker { Current: dataUpdateFilter{ idx: 1, }, - debug: env.Get(envDataUsageCrawlDebug, config.EnableOff) == config.EnableOn, + debug: env.Get(envDataUsageCrawlDebug, config.EnableOff) == config.EnableOn || serverDebugLog, input: make(chan string, dataUpdateTrackerQueueSize), save: make(chan struct{}, 1), saveExited: make(chan struct{}), diff --git a/cmd/erasure-sets.go b/cmd/erasure-sets.go index cf390a799..7c4ebff00 100644 --- a/cmd/erasure-sets.go +++ b/cmd/erasure-sets.go @@ -34,6 +34,7 @@ import ( "github.com/minio/minio-go/v7/pkg/tags" "github.com/minio/minio/cmd/logger" "github.com/minio/minio/pkg/bpool" + "github.com/minio/minio/pkg/console" "github.com/minio/minio/pkg/dsync" "github.com/minio/minio/pkg/madmin" "github.com/minio/minio/pkg/sync/errgroup" @@ -281,6 +282,10 @@ func (s *erasureSets) monitorAndConnectEndpoints(ctx context.Context, monitorInt // Reset the timer once fired for required interval. monitor.Reset(monitorInterval) + if serverDebugLog { + console.Debugln("running disk monitoring") + } + s.connectDisks() } } diff --git a/cmd/metacache-bucket.go b/cmd/metacache-bucket.go index a68b3a244..9a841a9bd 100644 --- a/cmd/metacache-bucket.go +++ b/cmd/metacache-bucket.go @@ -74,8 +74,8 @@ func newBucketMetacache(bucket string, cleanup bool) *bucketMetacache { } func (b *bucketMetacache) debugf(format string, data ...interface{}) { - if metacacheDebug { - console.Debugf(format, data...) + if serverDebugLog { + console.Debugf(format+"\n", data...) } } diff --git a/cmd/metacache-set.go b/cmd/metacache-set.go index e4c2d11e5..f5e7a74b9 100644 --- a/cmd/metacache-set.go +++ b/cmd/metacache-set.go @@ -125,13 +125,13 @@ func (o listPathOptions) newMetacache() metacache { } func (o *listPathOptions) debugf(format string, data ...interface{}) { - if metacacheDebug { + if serverDebugLog { console.Debugf(format, data...) } } func (o *listPathOptions) debugln(data ...interface{}) { - if metacacheDebug { + if serverDebugLog { console.Debugln(data...) } } diff --git a/cmd/metacache.go b/cmd/metacache.go index 7b0750989..c33b1862a 100644 --- a/cmd/metacache.go +++ b/cmd/metacache.go @@ -46,9 +46,6 @@ const ( // Enabling this will make cache sharing more likely and cause less IO, // but may cause additional latency to some calls. metacacheSharePrefix = false - - // metacacheDebug will enable debug printing - metacacheDebug = false ) //go:generate msgp -file $GOFILE -unexported diff --git a/pkg/console/console.go b/pkg/console/console.go index c2acab1fa..47bff7033 100644 --- a/pkg/console/console.go +++ b/pkg/console/console.go @@ -30,9 +30,6 @@ import ( ) var ( - // DebugPrint enables/disables console debug printing. - DebugPrint = false - // Used by the caller to print multiple lines atomically. Exposed by Lock/Unlock methods. publicMutex sync.Mutex @@ -112,23 +109,17 @@ var ( // Debug prints a debug message without a new line // Debug prints a debug message. Debug = func(data ...interface{}) { - if DebugPrint { - consolePrint("Debug", Theme["Debug"], data...) - } + consolePrint("Debug", Theme["Debug"], data...) } // Debugf prints a debug message with a new line. Debugf = func(format string, data ...interface{}) { - if DebugPrint { - consolePrintf("Debug", Theme["Debug"], format, data...) - } + consolePrintf("Debug", Theme["Debug"], format, data...) } // Debugln prints a debug message with a new line. Debugln = func(data ...interface{}) { - if DebugPrint { - consolePrintln("Debug", Theme["Debug"], data...) - } + consolePrintln("Debug", Theme["Debug"], data...) } // Colorize prints message in a colorized form, dictated by the corresponding tag argument.