From 4925bc3e802b4bb5f404b0959f7a585e9592ce88 Mon Sep 17 00:00:00 2001 From: poornas Date: Sun, 22 Sep 2019 01:24:32 -0700 Subject: [PATCH] log server startup messages to admin console api (#8264) --- cmd/common-main.go | 9 +++++++-- cmd/consolelogger.go | 11 ++++++++--- cmd/disk-cache.go | 4 ++-- cmd/gateway-main.go | 2 +- cmd/gateway-startup-msg.go | 12 +++++------- cmd/peer-rest-server.go | 4 +--- cmd/server-startup-msg.go | 39 +++++++++++++++++++------------------- pkg/madmin/api-log.go | 5 +++-- 8 files changed, 46 insertions(+), 40 deletions(-) diff --git a/cmd/common-main.go b/cmd/common-main.go index 207e07b3c..50fafbece 100644 --- a/cmd/common-main.go +++ b/cmd/common-main.go @@ -64,9 +64,9 @@ func checkUpdate(mode string) { return } if globalInplaceUpdateDisabled { - logger.StartupMessage(updateMsg) + logStartupMessage(updateMsg) } else { - logger.StartupMessage(prepareUpdateMessage("Run `mc admin update`", latestReleaseTime.Sub(currentReleaseTime))) + logStartupMessage(prepareUpdateMessage("Run `mc admin update`", latestReleaseTime.Sub(currentReleaseTime))) } } } @@ -438,3 +438,8 @@ func handleCommonEnvVars() { } } } + +func logStartupMessage(msg string, data ...interface{}) { + globalConsoleSys.Send(msg) + logger.StartupMessage(msg, data...) +} diff --git a/cmd/consolelogger.go b/cmd/consolelogger.go index 9d300c0b1..8e8d42b81 100644 --- a/cmd/consolelogger.go +++ b/cmd/consolelogger.go @@ -113,9 +113,14 @@ func (sys *HTTPConsoleLoggerSys) Console() *HTTPConsoleLoggerSys { // Send log message 'e' to console and publish to console // log pubsub system func (sys *HTTPConsoleLoggerSys) Send(e interface{}) error { - lg := madmin.LogInfo{} - lg.Entry = e.(log.Entry) - lg.NodeName = sys.nodeName + var lg madmin.LogInfo + switch e := e.(type) { + case log.Entry: + lg = madmin.LogInfo{Entry: e, NodeName: sys.nodeName} + case string: + lg = madmin.LogInfo{ConsoleMsg: e, NodeName: sys.nodeName} + } + sys.pubsub.Publish(lg) // add log to ring buffer sys.logBuf.Value = lg diff --git a/cmd/disk-cache.go b/cmd/disk-cache.go index 7e67cebb2..b63782e45 100644 --- a/cmd/disk-cache.go +++ b/cmd/disk-cache.go @@ -446,7 +446,7 @@ func checkAtimeSupport(dir string) (err error) { return } func (c *cacheObjects) migrateCacheFromV1toV2(ctx context.Context) { - logger.StartupMessage(colorBlue("Cache migration initiated ....")) + logStartupMessage(colorBlue("Cache migration initiated ....")) var wg sync.WaitGroup errs := make([]error, len(c.cache)) @@ -482,7 +482,7 @@ func (c *cacheObjects) migrateCacheFromV1toV2(ctx context.Context) { c.migMutex.Lock() defer c.migMutex.Unlock() c.migrating = false - logger.StartupMessage(colorBlue("Cache migration completed successfully.")) + logStartupMessage(colorBlue("Cache migration completed successfully.")) } // PutObject - caches the uploaded object for single Put operations diff --git a/cmd/gateway-main.go b/cmd/gateway-main.go index 786c32a6d..7fc0c8ca6 100644 --- a/cmd/gateway-main.go +++ b/cmd/gateway-main.go @@ -304,7 +304,7 @@ func StartGateway(ctx *cli.Context, gw Gateway) { // Print a warning message if gateway is not ready for production before the startup banner. if !gw.Production() { - logger.StartupMessage(colorYellow(" *** Warning: Not Ready for Production ***")) + logStartupMessage(colorYellow(" *** Warning: Not Ready for Production ***")) } // Print gateway startup message. diff --git a/cmd/gateway-startup-msg.go b/cmd/gateway-startup-msg.go index f5a8bdbaf..324da7942 100644 --- a/cmd/gateway-startup-msg.go +++ b/cmd/gateway-startup-msg.go @@ -20,8 +20,6 @@ import ( "context" "fmt" "strings" - - "github.com/minio/minio/cmd/logger" ) // Prints the formatted startup message. @@ -57,15 +55,15 @@ func printGatewayCommonMsg(apiEndpoints []string) { apiEndpointStr := strings.Join(apiEndpoints, " ") // Colorize the message and print. - logger.StartupMessage(colorBlue("Endpoint: ") + colorBold(fmt.Sprintf(getFormatStr(len(apiEndpointStr), 1), apiEndpointStr))) + logStartupMessage(colorBlue("Endpoint: ") + colorBold(fmt.Sprintf(getFormatStr(len(apiEndpointStr), 1), apiEndpointStr))) if isTerminal() && !globalCLIContext.Anonymous { - logger.StartupMessage(colorBlue("AccessKey: ") + colorBold(fmt.Sprintf("%s ", cred.AccessKey))) - logger.StartupMessage(colorBlue("SecretKey: ") + colorBold(fmt.Sprintf("%s ", cred.SecretKey))) + logStartupMessage(colorBlue("AccessKey: ") + colorBold(fmt.Sprintf("%s ", cred.AccessKey))) + logStartupMessage(colorBlue("SecretKey: ") + colorBold(fmt.Sprintf("%s ", cred.SecretKey))) } printEventNotifiers() if globalIsBrowserEnabled { - logger.StartupMessage(colorBlue("\nBrowser Access:")) - logger.StartupMessage(fmt.Sprintf(getFormatStr(len(apiEndpointStr), 3), apiEndpointStr)) + logStartupMessage(colorBlue("\nBrowser Access:")) + logStartupMessage(fmt.Sprintf(getFormatStr(len(apiEndpointStr), 3), apiEndpointStr)) } } diff --git a/cmd/peer-rest-server.go b/cmd/peer-rest-server.go index 2ad5365db..d8f28d6ac 100644 --- a/cmd/peer-rest-server.go +++ b/cmd/peer-rest-server.go @@ -32,7 +32,6 @@ import ( "github.com/minio/minio/cmd/logger" "github.com/minio/minio/pkg/event" "github.com/minio/minio/pkg/lifecycle" - "github.com/minio/minio/pkg/madmin" xnet "github.com/minio/minio/pkg/net" "github.com/minio/minio/pkg/policy" trace "github.com/minio/minio/pkg/trace" @@ -940,8 +939,7 @@ func (s *peerRESTServer) ConsoleLogHandler(w http.ResponseWriter, r *http.Reques for { select { case entry := <-ch: - log := entry.(madmin.LogInfo) - if err := enc.Encode(log); err != nil { + if err := enc.Encode(entry); err != nil { return } w.(http.Flusher).Flush() diff --git a/cmd/server-startup-msg.go b/cmd/server-startup-msg.go index 2c2bf3fa4..02b0e7856 100644 --- a/cmd/server-startup-msg.go +++ b/cmd/server-startup-msg.go @@ -25,7 +25,6 @@ import ( "strings" humanize "github.com/dustin/go-humanize" - "github.com/minio/minio/cmd/logger" xnet "github.com/minio/minio/pkg/net" ) @@ -122,19 +121,19 @@ func printServerCommonMsg(apiEndpoints []string) { apiEndpointStr := strings.Join(apiEndpoints, " ") // Colorize the message and print. - logger.StartupMessage(colorBlue("Endpoint: ") + colorBold(fmt.Sprintf(getFormatStr(len(apiEndpointStr), 1), apiEndpointStr))) + logStartupMessage(colorBlue("Endpoint: ") + colorBold(fmt.Sprintf(getFormatStr(len(apiEndpointStr), 1), apiEndpointStr))) if isTerminal() && !globalCLIContext.Anonymous { - logger.StartupMessage(colorBlue("AccessKey: ") + colorBold(fmt.Sprintf("%s ", cred.AccessKey))) - logger.StartupMessage(colorBlue("SecretKey: ") + colorBold(fmt.Sprintf("%s ", cred.SecretKey))) + logStartupMessage(colorBlue("AccessKey: ") + colorBold(fmt.Sprintf("%s ", cred.AccessKey))) + logStartupMessage(colorBlue("SecretKey: ") + colorBold(fmt.Sprintf("%s ", cred.SecretKey))) if region != "" { - logger.StartupMessage(colorBlue("Region: ") + colorBold(fmt.Sprintf(getFormatStr(len(region), 3), region))) + logStartupMessage(colorBlue("Region: ") + colorBold(fmt.Sprintf(getFormatStr(len(region), 3), region))) } } printEventNotifiers() if globalIsBrowserEnabled { - logger.StartupMessage(colorBlue("\nBrowser Access:")) - logger.StartupMessage(fmt.Sprintf(getFormatStr(len(apiEndpointStr), 3), apiEndpointStr)) + logStartupMessage(colorBlue("\nBrowser Access:")) + logStartupMessage(fmt.Sprintf(getFormatStr(len(apiEndpointStr), 3), apiEndpointStr)) } } @@ -150,7 +149,7 @@ func printEventNotifiers() { arnMsg += colorBold(fmt.Sprintf(getFormatStr(len(arn), 1), arn)) } - logger.StartupMessage(arnMsg) + logStartupMessage(arnMsg) } // Prints startup message for command line access. Prints link to our documentation @@ -161,25 +160,25 @@ func printCLIAccessMsg(endPoint string, alias string) { // Configure 'mc', following block prints platform specific information for minio client. if isTerminal() { - logger.StartupMessage(colorBlue("\nCommand-line Access: ") + mcQuickStartGuide) + logStartupMessage(colorBlue("\nCommand-line Access: ") + mcQuickStartGuide) if runtime.GOOS == globalWindowsOSName { mcMessage := fmt.Sprintf("$ mc.exe config host add %s %s %s %s", alias, endPoint, cred.AccessKey, cred.SecretKey) - logger.StartupMessage(fmt.Sprintf(getFormatStr(len(mcMessage), 3), mcMessage)) + logStartupMessage(fmt.Sprintf(getFormatStr(len(mcMessage), 3), mcMessage)) } else { mcMessage := fmt.Sprintf("$ mc config host add %s %s %s %s", alias, endPoint, cred.AccessKey, cred.SecretKey) - logger.StartupMessage(fmt.Sprintf(getFormatStr(len(mcMessage), 3), mcMessage)) + logStartupMessage(fmt.Sprintf(getFormatStr(len(mcMessage), 3), mcMessage)) } } } // Prints startup message for Object API acces, prints link to our SDK documentation. func printObjectAPIMsg() { - logger.StartupMessage(colorBlue("\nObject API (Amazon S3 compatible):")) - logger.StartupMessage(colorBlue(" Go: ") + fmt.Sprintf(getFormatStr(len(goQuickStartGuide), 8), goQuickStartGuide)) - logger.StartupMessage(colorBlue(" Java: ") + fmt.Sprintf(getFormatStr(len(javaQuickStartGuide), 6), javaQuickStartGuide)) - logger.StartupMessage(colorBlue(" Python: ") + fmt.Sprintf(getFormatStr(len(pyQuickStartGuide), 4), pyQuickStartGuide)) - logger.StartupMessage(colorBlue(" JavaScript: ") + jsQuickStartGuide) - logger.StartupMessage(colorBlue(" .NET: ") + fmt.Sprintf(getFormatStr(len(dotnetQuickStartGuide), 6), dotnetQuickStartGuide)) + logStartupMessage(colorBlue("\nObject API (Amazon S3 compatible):")) + logStartupMessage(colorBlue(" Go: ") + fmt.Sprintf(getFormatStr(len(goQuickStartGuide), 8), goQuickStartGuide)) + logStartupMessage(colorBlue(" Java: ") + fmt.Sprintf(getFormatStr(len(javaQuickStartGuide), 6), javaQuickStartGuide)) + logStartupMessage(colorBlue(" Python: ") + fmt.Sprintf(getFormatStr(len(pyQuickStartGuide), 4), pyQuickStartGuide)) + logStartupMessage(colorBlue(" JavaScript: ") + jsQuickStartGuide) + logStartupMessage(colorBlue(" .NET: ") + fmt.Sprintf(getFormatStr(len(dotnetQuickStartGuide), 6), dotnetQuickStartGuide)) } // Get formatted disk/storage info message. @@ -195,7 +194,7 @@ func getStorageInfoMsg(storageInfo StorageInfo) string { // Prints startup message of storage capacity and erasure information. func printStorageInfo(storageInfo StorageInfo) { if msg := getStorageInfoMsg(storageInfo); msg != "" { - logger.StartupMessage(msg) + logStartupMessage(msg) } } @@ -203,7 +202,7 @@ func printCacheStorageInfo(storageInfo CacheStorageInfo) { msg := fmt.Sprintf("%s %s Free, %s Total", colorBlue("Cache Capacity:"), humanize.IBytes(uint64(storageInfo.Free)), humanize.IBytes(uint64(storageInfo.Total))) - logger.StartupMessage(msg) + logStartupMessage(msg) } // Prints certificate expiry date warning @@ -226,5 +225,5 @@ func getCertificateChainMsg(certs []*x509.Certificate) string { // Prints the certificate expiry message. func printCertificateMsg(certs []*x509.Certificate) { - logger.StartupMessage(getCertificateChainMsg(certs)) + logStartupMessage(getCertificateChainMsg(certs)) } diff --git a/pkg/madmin/api-log.go b/pkg/madmin/api-log.go index 07bac1e43..6448d7e15 100644 --- a/pkg/madmin/api-log.go +++ b/pkg/madmin/api-log.go @@ -29,8 +29,9 @@ import ( // LogInfo holds console log messages type LogInfo struct { log.Entry - NodeName string `json:"node"` - Err error `json:"-"` + ConsoleMsg string + NodeName string `json:"node"` + Err error `json:"-"` } // SendLog returns true if log pertains to node specified in args.