Add node address information to logs (#7941)

master
Krishnan Parthasarathi 5 years ago committed by Harshavardhana
parent be9baa1464
commit fbfc9a61ec
  1. 14
      cmd/admin-handlers.go
  2. 13
      cmd/handler-utils.go
  3. 1
      cmd/logger/logger.go
  4. 1
      cmd/logger/message/log/entry.go
  5. 1
      cmd/logger/reqinfo.go
  6. 9
      cmd/logger/target/console/console.go
  7. 1
      cmd/utils.go
  8. 1
      cmd/web-handler-context.go

@ -241,17 +241,12 @@ func (a adminAPIHandlers) ServerInfoHandler(w http.ResponseWriter, r *http.Reque
if objectAPI == nil { if objectAPI == nil {
return return
} }
hostName, err := getHostName(r)
if err != nil {
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
return
}
serverInfo := globalNotificationSys.ServerInfo(ctx) serverInfo := globalNotificationSys.ServerInfo(ctx)
// Once we have received all the ServerInfo from peers // Once we have received all the ServerInfo from peers
// add the local peer server info as well. // add the local peer server info as well.
serverInfo = append(serverInfo, ServerInfo{ serverInfo = append(serverInfo, ServerInfo{
Addr: hostName, Addr: getHostName(r),
Data: &ServerInfoData{ Data: &ServerInfoData{
StorageInfo: objectAPI.StorageInfo(ctx), StorageInfo: objectAPI.StorageInfo(ctx),
ConnStats: globalConnStats.toServerConnStats(), ConnStats: globalConnStats.toServerConnStats(),
@ -442,18 +437,13 @@ func (a adminAPIHandlers) TopLocksHandler(w http.ResponseWriter, r *http.Request
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrMethodNotAllowed), r.URL) writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrMethodNotAllowed), r.URL)
return return
} }
hostName, err := getHostName(r)
if err != nil {
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
return
}
peerLocks := globalNotificationSys.GetLocks(ctx) peerLocks := globalNotificationSys.GetLocks(ctx)
// Once we have received all the locks currently used from peers // Once we have received all the locks currently used from peers
// add the local peer locks list as well. // add the local peer locks list as well.
localLocks := globalLockServer.ll.DupLockMap() localLocks := globalLockServer.ll.DupLockMap()
peerLocks = append(peerLocks, &PeerLocks{ peerLocks = append(peerLocks, &PeerLocks{
Addr: hostName, Addr: getHostName(r),
Locks: localLocks, Locks: localLocks,
}) })

@ -31,7 +31,6 @@ import (
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/pkg/auth" "github.com/minio/minio/pkg/auth"
"github.com/minio/minio/pkg/handlers" "github.com/minio/minio/pkg/handlers"
xnet "github.com/minio/minio/pkg/net"
) )
// Parses location constraint from the incoming reader. // Parses location constraint from the incoming reader.
@ -387,15 +386,11 @@ func notFoundHandler(w http.ResponseWriter, r *http.Request) {
} }
// gets host name for current node // gets host name for current node
func getHostName(r *http.Request) (hostName string, err error) { func getHostName(r *http.Request) (hostName string) {
var thisAddr *xnet.Host
hostName = r.Host
if globalIsDistXL { if globalIsDistXL {
thisAddr, err = xnet.ParseHost(GetLocalPeer(globalEndpoints)) hostName = GetLocalPeer(globalEndpoints)
if err != nil { } else {
return hostName = r.Host
}
hostName = thisAddr.String()
} }
return return
} }

@ -331,6 +331,7 @@ func logIf(ctx context.Context, err error) {
DeploymentID: req.DeploymentID, DeploymentID: req.DeploymentID,
Level: ErrorLvl.String(), Level: ErrorLvl.String(),
RemoteHost: req.RemoteHost, RemoteHost: req.RemoteHost,
Host: req.Host,
RequestID: req.RequestID, RequestID: req.RequestID,
UserAgent: req.UserAgent, UserAgent: req.UserAgent,
Time: time.Now().UTC().Format(time.RFC3339Nano), Time: time.Now().UTC().Format(time.RFC3339Nano),

@ -43,6 +43,7 @@ type Entry struct {
Time string `json:"time"` Time string `json:"time"`
API *API `json:"api,omitempty"` API *API `json:"api,omitempty"`
RemoteHost string `json:"remotehost,omitempty"` RemoteHost string `json:"remotehost,omitempty"`
Host string `json:"host,omitempty"`
RequestID string `json:"requestID,omitempty"` RequestID string `json:"requestID,omitempty"`
UserAgent string `json:"userAgent,omitempty"` UserAgent string `json:"userAgent,omitempty"`
Message string `json:"message,omitempty"` Message string `json:"message,omitempty"`

@ -36,6 +36,7 @@ type KeyVal struct {
// ReqInfo stores the request info. // ReqInfo stores the request info.
type ReqInfo struct { type ReqInfo struct {
RemoteHost string // Client Host/IP RemoteHost string // Client Host/IP
Host string // Node Host/IP
UserAgent string // User Agent UserAgent string // User Agent
DeploymentID string // x-minio-deployment-id DeploymentID string // x-minio-deployment-id
RequestID string // x-amz-request-id RequestID string // x-amz-request-id

@ -89,6 +89,11 @@ func (c *Target) Send(e interface{}) error {
remoteHost = "\nRemoteHost: " + entry.RemoteHost remoteHost = "\nRemoteHost: " + entry.RemoteHost
} }
var host string
if entry.Host != "" {
host = "\nHost: " + entry.Host
}
var userAgent string var userAgent string
if entry.UserAgent != "" { if entry.UserAgent != "" {
userAgent = "\nUserAgent: " + entry.UserAgent userAgent = "\nUserAgent: " + entry.UserAgent
@ -99,8 +104,8 @@ func (c *Target) Send(e interface{}) error {
} }
var msg = logger.ColorFgRed(logger.ColorBold(entry.Trace.Message)) var msg = logger.ColorFgRed(logger.ColorBold(entry.Trace.Message))
var output = fmt.Sprintf("\n%s\n%s%s%s%s%s\nError: %s%s\n%s", var output = fmt.Sprintf("\n%s\n%s%s%s%s%s%s\nError: %s%s\n%s",
apiString, timeString, deploymentID, requestID, remoteHost, userAgent, apiString, timeString, deploymentID, requestID, remoteHost, host, userAgent,
msg, tagString, strings.Join(trace, "\n")) msg, tagString, strings.Join(trace, "\n"))
fmt.Println(output) fmt.Println(output)

@ -429,6 +429,7 @@ func newContext(r *http.Request, w http.ResponseWriter, api string) context.Cont
DeploymentID: globalDeploymentID, DeploymentID: globalDeploymentID,
RequestID: w.Header().Get(xhttp.AmzRequestID), RequestID: w.Header().Get(xhttp.AmzRequestID),
RemoteHost: handlers.GetSourceIP(r), RemoteHost: handlers.GetSourceIP(r),
Host: getHostName(r),
UserAgent: r.UserAgent(), UserAgent: r.UserAgent(),
API: api, API: api,
BucketName: bucket, BucketName: bucket,

@ -235,6 +235,7 @@ func newWebContext(r *http.Request, args ToKeyValuer, api string) context.Contex
reqInfo := &logger.ReqInfo{ reqInfo := &logger.ReqInfo{
DeploymentID: globalDeploymentID, DeploymentID: globalDeploymentID,
RemoteHost: handlers.GetSourceIP(r), RemoteHost: handlers.GetSourceIP(r),
Host: getHostName(r),
UserAgent: r.UserAgent(), UserAgent: r.UserAgent(),
API: api, API: api,
BucketName: bucket, BucketName: bucket,

Loading…
Cancel
Save