log server startup messages to admin console api (#8264)

master
poornas 5 years ago committed by Nitish Tiwari
parent ffded5a930
commit 4925bc3e80
  1. 9
      cmd/common-main.go
  2. 11
      cmd/consolelogger.go
  3. 4
      cmd/disk-cache.go
  4. 2
      cmd/gateway-main.go
  5. 12
      cmd/gateway-startup-msg.go
  6. 4
      cmd/peer-rest-server.go
  7. 39
      cmd/server-startup-msg.go
  8. 5
      pkg/madmin/api-log.go

@ -64,9 +64,9 @@ func checkUpdate(mode string) {
return return
} }
if globalInplaceUpdateDisabled { if globalInplaceUpdateDisabled {
logger.StartupMessage(updateMsg) logStartupMessage(updateMsg)
} else { } 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...)
}

@ -113,9 +113,14 @@ func (sys *HTTPConsoleLoggerSys) Console() *HTTPConsoleLoggerSys {
// Send log message 'e' to console and publish to console // Send log message 'e' to console and publish to console
// log pubsub system // log pubsub system
func (sys *HTTPConsoleLoggerSys) Send(e interface{}) error { func (sys *HTTPConsoleLoggerSys) Send(e interface{}) error {
lg := madmin.LogInfo{} var lg madmin.LogInfo
lg.Entry = e.(log.Entry) switch e := e.(type) {
lg.NodeName = sys.nodeName 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) sys.pubsub.Publish(lg)
// add log to ring buffer // add log to ring buffer
sys.logBuf.Value = lg sys.logBuf.Value = lg

@ -446,7 +446,7 @@ func checkAtimeSupport(dir string) (err error) {
return return
} }
func (c *cacheObjects) migrateCacheFromV1toV2(ctx context.Context) { func (c *cacheObjects) migrateCacheFromV1toV2(ctx context.Context) {
logger.StartupMessage(colorBlue("Cache migration initiated ....")) logStartupMessage(colorBlue("Cache migration initiated ...."))
var wg sync.WaitGroup var wg sync.WaitGroup
errs := make([]error, len(c.cache)) errs := make([]error, len(c.cache))
@ -482,7 +482,7 @@ func (c *cacheObjects) migrateCacheFromV1toV2(ctx context.Context) {
c.migMutex.Lock() c.migMutex.Lock()
defer c.migMutex.Unlock() defer c.migMutex.Unlock()
c.migrating = false 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 // PutObject - caches the uploaded object for single Put operations

@ -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. // Print a warning message if gateway is not ready for production before the startup banner.
if !gw.Production() { if !gw.Production() {
logger.StartupMessage(colorYellow(" *** Warning: Not Ready for Production ***")) logStartupMessage(colorYellow(" *** Warning: Not Ready for Production ***"))
} }
// Print gateway startup message. // Print gateway startup message.

@ -20,8 +20,6 @@ import (
"context" "context"
"fmt" "fmt"
"strings" "strings"
"github.com/minio/minio/cmd/logger"
) )
// Prints the formatted startup message. // Prints the formatted startup message.
@ -57,15 +55,15 @@ func printGatewayCommonMsg(apiEndpoints []string) {
apiEndpointStr := strings.Join(apiEndpoints, " ") apiEndpointStr := strings.Join(apiEndpoints, " ")
// Colorize the message and print. // 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 { if isTerminal() && !globalCLIContext.Anonymous {
logger.StartupMessage(colorBlue("AccessKey: ") + colorBold(fmt.Sprintf("%s ", cred.AccessKey))) logStartupMessage(colorBlue("AccessKey: ") + colorBold(fmt.Sprintf("%s ", cred.AccessKey)))
logger.StartupMessage(colorBlue("SecretKey: ") + colorBold(fmt.Sprintf("%s ", cred.SecretKey))) logStartupMessage(colorBlue("SecretKey: ") + colorBold(fmt.Sprintf("%s ", cred.SecretKey)))
} }
printEventNotifiers() printEventNotifiers()
if globalIsBrowserEnabled { if globalIsBrowserEnabled {
logger.StartupMessage(colorBlue("\nBrowser Access:")) logStartupMessage(colorBlue("\nBrowser Access:"))
logger.StartupMessage(fmt.Sprintf(getFormatStr(len(apiEndpointStr), 3), apiEndpointStr)) logStartupMessage(fmt.Sprintf(getFormatStr(len(apiEndpointStr), 3), apiEndpointStr))
} }
} }

@ -32,7 +32,6 @@ import (
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/pkg/event" "github.com/minio/minio/pkg/event"
"github.com/minio/minio/pkg/lifecycle" "github.com/minio/minio/pkg/lifecycle"
"github.com/minio/minio/pkg/madmin"
xnet "github.com/minio/minio/pkg/net" xnet "github.com/minio/minio/pkg/net"
"github.com/minio/minio/pkg/policy" "github.com/minio/minio/pkg/policy"
trace "github.com/minio/minio/pkg/trace" trace "github.com/minio/minio/pkg/trace"
@ -940,8 +939,7 @@ func (s *peerRESTServer) ConsoleLogHandler(w http.ResponseWriter, r *http.Reques
for { for {
select { select {
case entry := <-ch: case entry := <-ch:
log := entry.(madmin.LogInfo) if err := enc.Encode(entry); err != nil {
if err := enc.Encode(log); err != nil {
return return
} }
w.(http.Flusher).Flush() w.(http.Flusher).Flush()

@ -25,7 +25,6 @@ import (
"strings" "strings"
humanize "github.com/dustin/go-humanize" humanize "github.com/dustin/go-humanize"
"github.com/minio/minio/cmd/logger"
xnet "github.com/minio/minio/pkg/net" xnet "github.com/minio/minio/pkg/net"
) )
@ -122,19 +121,19 @@ func printServerCommonMsg(apiEndpoints []string) {
apiEndpointStr := strings.Join(apiEndpoints, " ") apiEndpointStr := strings.Join(apiEndpoints, " ")
// Colorize the message and print. // 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 { if isTerminal() && !globalCLIContext.Anonymous {
logger.StartupMessage(colorBlue("AccessKey: ") + colorBold(fmt.Sprintf("%s ", cred.AccessKey))) logStartupMessage(colorBlue("AccessKey: ") + colorBold(fmt.Sprintf("%s ", cred.AccessKey)))
logger.StartupMessage(colorBlue("SecretKey: ") + colorBold(fmt.Sprintf("%s ", cred.SecretKey))) logStartupMessage(colorBlue("SecretKey: ") + colorBold(fmt.Sprintf("%s ", cred.SecretKey)))
if region != "" { 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() printEventNotifiers()
if globalIsBrowserEnabled { if globalIsBrowserEnabled {
logger.StartupMessage(colorBlue("\nBrowser Access:")) logStartupMessage(colorBlue("\nBrowser Access:"))
logger.StartupMessage(fmt.Sprintf(getFormatStr(len(apiEndpointStr), 3), apiEndpointStr)) logStartupMessage(fmt.Sprintf(getFormatStr(len(apiEndpointStr), 3), apiEndpointStr))
} }
} }
@ -150,7 +149,7 @@ func printEventNotifiers() {
arnMsg += colorBold(fmt.Sprintf(getFormatStr(len(arn), 1), arn)) 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 // 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. // Configure 'mc', following block prints platform specific information for minio client.
if isTerminal() { if isTerminal() {
logger.StartupMessage(colorBlue("\nCommand-line Access: ") + mcQuickStartGuide) logStartupMessage(colorBlue("\nCommand-line Access: ") + mcQuickStartGuide)
if runtime.GOOS == globalWindowsOSName { if runtime.GOOS == globalWindowsOSName {
mcMessage := fmt.Sprintf("$ mc.exe config host add %s %s %s %s", alias, endPoint, cred.AccessKey, cred.SecretKey) 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 { } else {
mcMessage := fmt.Sprintf("$ mc config host add %s %s %s %s", alias, endPoint, cred.AccessKey, cred.SecretKey) 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. // Prints startup message for Object API acces, prints link to our SDK documentation.
func printObjectAPIMsg() { func printObjectAPIMsg() {
logger.StartupMessage(colorBlue("\nObject API (Amazon S3 compatible):")) logStartupMessage(colorBlue("\nObject API (Amazon S3 compatible):"))
logger.StartupMessage(colorBlue(" Go: ") + fmt.Sprintf(getFormatStr(len(goQuickStartGuide), 8), goQuickStartGuide)) logStartupMessage(colorBlue(" Go: ") + fmt.Sprintf(getFormatStr(len(goQuickStartGuide), 8), goQuickStartGuide))
logger.StartupMessage(colorBlue(" Java: ") + fmt.Sprintf(getFormatStr(len(javaQuickStartGuide), 6), javaQuickStartGuide)) logStartupMessage(colorBlue(" Java: ") + fmt.Sprintf(getFormatStr(len(javaQuickStartGuide), 6), javaQuickStartGuide))
logger.StartupMessage(colorBlue(" Python: ") + fmt.Sprintf(getFormatStr(len(pyQuickStartGuide), 4), pyQuickStartGuide)) logStartupMessage(colorBlue(" Python: ") + fmt.Sprintf(getFormatStr(len(pyQuickStartGuide), 4), pyQuickStartGuide))
logger.StartupMessage(colorBlue(" JavaScript: ") + jsQuickStartGuide) logStartupMessage(colorBlue(" JavaScript: ") + jsQuickStartGuide)
logger.StartupMessage(colorBlue(" .NET: ") + fmt.Sprintf(getFormatStr(len(dotnetQuickStartGuide), 6), dotnetQuickStartGuide)) logStartupMessage(colorBlue(" .NET: ") + fmt.Sprintf(getFormatStr(len(dotnetQuickStartGuide), 6), dotnetQuickStartGuide))
} }
// Get formatted disk/storage info message. // Get formatted disk/storage info message.
@ -195,7 +194,7 @@ func getStorageInfoMsg(storageInfo StorageInfo) string {
// Prints startup message of storage capacity and erasure information. // Prints startup message of storage capacity and erasure information.
func printStorageInfo(storageInfo StorageInfo) { func printStorageInfo(storageInfo StorageInfo) {
if msg := getStorageInfoMsg(storageInfo); msg != "" { 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:"), msg := fmt.Sprintf("%s %s Free, %s Total", colorBlue("Cache Capacity:"),
humanize.IBytes(uint64(storageInfo.Free)), humanize.IBytes(uint64(storageInfo.Free)),
humanize.IBytes(uint64(storageInfo.Total))) humanize.IBytes(uint64(storageInfo.Total)))
logger.StartupMessage(msg) logStartupMessage(msg)
} }
// Prints certificate expiry date warning // Prints certificate expiry date warning
@ -226,5 +225,5 @@ func getCertificateChainMsg(certs []*x509.Certificate) string {
// Prints the certificate expiry message. // Prints the certificate expiry message.
func printCertificateMsg(certs []*x509.Certificate) { func printCertificateMsg(certs []*x509.Certificate) {
logger.StartupMessage(getCertificateChainMsg(certs)) logStartupMessage(getCertificateChainMsg(certs))
} }

@ -29,8 +29,9 @@ import (
// LogInfo holds console log messages // LogInfo holds console log messages
type LogInfo struct { type LogInfo struct {
log.Entry log.Entry
NodeName string `json:"node"` ConsoleMsg string
Err error `json:"-"` NodeName string `json:"node"`
Err error `json:"-"`
} }
// SendLog returns true if log pertains to node specified in args. // SendLog returns true if log pertains to node specified in args.

Loading…
Cancel
Save