fix: admin console logger changes to log.Info

master
Harshavardhana 5 years ago
parent ae654831aa
commit b4bfdc92cc
  1. 5
      cmd/admin-handlers.go
  2. 14
      cmd/consolelogger.go
  3. 11
      cmd/logger/message/log/entry.go
  4. 8
      pkg/madmin/api-log.go

@ -42,6 +42,7 @@ import (
"github.com/minio/minio/cmd/crypto" "github.com/minio/minio/cmd/crypto"
xhttp "github.com/minio/minio/cmd/http" xhttp "github.com/minio/minio/cmd/http"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/cmd/logger/message/log"
"github.com/minio/minio/pkg/auth" "github.com/minio/minio/pkg/auth"
"github.com/minio/minio/pkg/cpu" "github.com/minio/minio/pkg/cpu"
"github.com/minio/minio/pkg/event/target" "github.com/minio/minio/pkg/event/target"
@ -1227,8 +1228,8 @@ func (a adminAPIHandlers) ConsoleLogHandler(w http.ResponseWriter, r *http.Reque
for { for {
select { select {
case entry := <-logCh: case entry := <-logCh:
log := entry.(madmin.LogInfo) log, ok := entry.(log.Info)
if log.SendLog(node, logKind) { if ok && log.SendLog(node, logKind) {
if err := enc.Encode(log); err != nil { if err := enc.Encode(log); err != nil {
return return
} }

@ -24,7 +24,6 @@ import (
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/cmd/logger/message/log" "github.com/minio/minio/cmd/logger/message/log"
"github.com/minio/minio/cmd/logger/target/console" "github.com/minio/minio/cmd/logger/target/console"
"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/pubsub" "github.com/minio/minio/pkg/pubsub"
) )
@ -84,25 +83,28 @@ func (sys *HTTPConsoleLoggerSys) Subscribe(subCh chan interface{}, doneCh chan s
cnt := 0 cnt := 0
// by default send all console logs in the ring buffer unless node or limit query parameters // by default send all console logs in the ring buffer unless node or limit query parameters
// are set. // are set.
var lastN []madmin.LogInfo var lastN []log.Info
if last > defaultLogBufferCount || last <= 0 { if last > defaultLogBufferCount || last <= 0 {
last = defaultLogBufferCount last = defaultLogBufferCount
} }
lastN = make([]madmin.LogInfo, last) lastN = make([]log.Info, last)
sys.RLock() sys.RLock()
sys.logBuf.Do(func(p interface{}) { sys.logBuf.Do(func(p interface{}) {
if p != nil && (p.(madmin.LogInfo)).SendLog(node, logKind) { if p != nil {
lastN[cnt%last] = p.(madmin.LogInfo) lg, ok := p.(log.Info)
if ok && lg.SendLog(node, logKind) {
lastN[cnt%last] = lg
cnt++ cnt++
} }
}
}) })
sys.RUnlock() sys.RUnlock()
// send last n console log messages in order filtered by node // send last n console log messages in order filtered by node
if cnt > 0 { if cnt > 0 {
for i := 0; i < last; i++ { for i := 0; i < last; i++ {
entry := lastN[(cnt+i)%last] entry := lastN[(cnt+i)%last]
if (entry == madmin.LogInfo{}) { if (entry == log.Info{}) {
continue continue
} }
select { select {

@ -1,5 +1,5 @@
/* /*
* MinIO Cloud Storage, (C) 2018 MinIO, Inc. * MinIO Cloud Storage, (C) 2018, 2020 MinIO, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,6 +16,8 @@
package log package log
import "strings"
// Args - defines the arguments for the API. // Args - defines the arguments for the API.
type Args struct { type Args struct {
Bucket string `json:"bucket,omitempty"` Bucket string `json:"bucket,omitempty"`
@ -58,3 +60,10 @@ type Info struct {
NodeName string `json:"node"` NodeName string `json:"node"`
Err error `json:"-"` Err error `json:"-"`
} }
// SendLog returns true if log pertains to node specified in args.
func (l Info) SendLog(node, logKind string) bool {
nodeFltr := (node == "" || strings.EqualFold(node, l.NodeName))
typeFltr := strings.EqualFold(logKind, "all") || strings.EqualFold(l.LogKind, logKind)
return nodeFltr && typeFltr
}

@ -22,7 +22,6 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"strconv" "strconv"
"strings"
) )
// LogInfo holds console log messages // LogInfo holds console log messages
@ -33,13 +32,6 @@ type LogInfo struct {
Err error `json:"-"` Err error `json:"-"`
} }
// SendLog returns true if log pertains to node specified in args.
func (l LogInfo) SendLog(node, logKind string) bool {
nodeFltr := (node == "" || strings.EqualFold(node, l.NodeName))
typeFltr := strings.EqualFold(logKind, "all") || strings.EqualFold(l.LogKind, logKind)
return nodeFltr && typeFltr
}
// GetLogs - listen on console log messages. // GetLogs - listen on console log messages.
func (adm AdminClient) GetLogs(ctx context.Context, node string, lineCnt int, logKind string) <-chan LogInfo { func (adm AdminClient) GetLogs(ctx context.Context, node string, lineCnt int, logKind string) <-chan LogInfo {
logCh := make(chan LogInfo, 1) logCh := make(chan LogInfo, 1)

Loading…
Cancel
Save