diff --git a/cmd/admin-handlers.go b/cmd/admin-handlers.go index 1e1f46b89..200dfb68b 100644 --- a/cmd/admin-handlers.go +++ b/cmd/admin-handlers.go @@ -53,9 +53,9 @@ import ( xhttp "github.com/minio/minio/internal/http" "github.com/minio/minio/internal/kms" "github.com/minio/minio/internal/logger" - "github.com/minio/minio/internal/logger/message/log" "github.com/minio/mux" iampolicy "github.com/minio/pkg/iam/policy" + "github.com/minio/pkg/logger/message/log" xnet "github.com/minio/pkg/net" "github.com/secure-io/sio-go" ) diff --git a/cmd/consolelogger.go b/cmd/consolelogger.go index ba309b338..f7a25be43 100644 --- a/cmd/consolelogger.go +++ b/cmd/consolelogger.go @@ -25,10 +25,10 @@ import ( "github.com/minio/madmin-go/v2" "github.com/minio/minio/internal/logger" - "github.com/minio/minio/internal/logger/message/log" "github.com/minio/minio/internal/logger/target/console" "github.com/minio/minio/internal/logger/target/types" "github.com/minio/minio/internal/pubsub" + "github.com/minio/pkg/logger/message/log" xnet "github.com/minio/pkg/net" ) diff --git a/cmd/data-update-tracker_test.go b/cmd/data-update-tracker_test.go index 217853d34..19b819ab0 100644 --- a/cmd/data-update-tracker_test.go +++ b/cmd/data-update-tracker_test.go @@ -29,8 +29,8 @@ import ( "testing" "github.com/minio/minio/internal/logger" - "github.com/minio/minio/internal/logger/message/log" "github.com/minio/minio/internal/logger/target/types" + "github.com/minio/pkg/logger/message/log" ) type testLoggerI interface { diff --git a/cmd/peer-rest-client.go b/cmd/peer-rest-client.go index a7935bfcd..be58e91b0 100644 --- a/cmd/peer-rest-client.go +++ b/cmd/peer-rest-client.go @@ -34,8 +34,8 @@ import ( "github.com/minio/minio/internal/event" xhttp "github.com/minio/minio/internal/http" "github.com/minio/minio/internal/logger" - "github.com/minio/minio/internal/logger/message/log" "github.com/minio/minio/internal/rest" + "github.com/minio/pkg/logger/message/log" xnet "github.com/minio/pkg/net" "github.com/tinylib/msgp/msgp" ) diff --git a/cmd/peer-rest-server.go b/cmd/peer-rest-server.go index 3533ed3cf..4fe2e2fdb 100644 --- a/cmd/peer-rest-server.go +++ b/cmd/peer-rest-server.go @@ -34,9 +34,9 @@ import ( b "github.com/minio/minio/internal/bucket/bandwidth" "github.com/minio/minio/internal/event" "github.com/minio/minio/internal/logger" - "github.com/minio/minio/internal/logger/message/log" "github.com/minio/minio/internal/pubsub" "github.com/minio/mux" + "github.com/minio/pkg/logger/message/log" "github.com/tinylib/msgp/msgp" ) diff --git a/cmd/utils.go b/cmd/utils.go index 0c0f21d09..10724a41a 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -62,6 +62,7 @@ import ( "github.com/minio/mux" "github.com/minio/pkg/certs" "github.com/minio/pkg/env" + pkgAudit "github.com/minio/pkg/logger/message/audit" xnet "github.com/minio/pkg/net" "golang.org/x/oauth2" ) @@ -1061,7 +1062,7 @@ func auditLogInternal(ctx context.Context, opts AuditLogOptions) { entry.Error = opts.Error entry.API.Name = opts.APIName entry.API.Bucket = opts.Bucket - entry.API.Objects = []audit.ObjectVersion{{ObjectName: opts.Object, VersionID: opts.VersionID}} + entry.API.Objects = []pkgAudit.ObjectVersion{{ObjectName: opts.Object, VersionID: opts.VersionID}} entry.API.Status = opts.Status entry.Tags = opts.Tags // Merge tag information if found - this is currently needed for tags diff --git a/go.mod b/go.mod index 6a4318657..a9bcd0088 100644 --- a/go.mod +++ b/go.mod @@ -51,7 +51,7 @@ require ( github.com/minio/madmin-go/v2 v2.0.13-0.20230220143547-e6641ef0b8d5 github.com/minio/minio-go/v7 v7.0.48 github.com/minio/mux v1.9.0 - github.com/minio/pkg v1.6.1 + github.com/minio/pkg v1.6.2 github.com/minio/selfupdate v0.6.0 github.com/minio/sha256-simd v1.0.0 github.com/minio/simdjson-go v0.4.2 diff --git a/go.sum b/go.sum index bc671d7e3..876e05343 100644 --- a/go.sum +++ b/go.sum @@ -788,8 +788,8 @@ github.com/minio/minio-go/v7 v7.0.48/go.mod h1:nCrRzjoSUQh8hgKKtu3Y708OLvRLtuASM github.com/minio/mux v1.9.0 h1:dWafQFyEfGhJvK6AwLOt83bIG5bxKxKJnKMCi0XAaoA= github.com/minio/mux v1.9.0/go.mod h1:1pAare17ZRL5GpmNL+9YmqHoWnLmMZF9C/ioUCfy0BQ= github.com/minio/pkg v1.5.4/go.mod h1:2MOaRFdmFKULD+uOLc3qHLGTQTuxCNPKNPfLBTxC8CA= -github.com/minio/pkg v1.6.1 h1:6/ExL3LdNPKbDU/lbHxOUaYKbEOC74IUEExB1VaLUXI= -github.com/minio/pkg v1.6.1/go.mod h1:HisnbndsCEaQHLvEurhBxt6mk6SGAn2LgJqChIfkb+s= +github.com/minio/pkg v1.6.2 h1:BFbBFtmODnQb7YgG/BDPVWeUcbVX7ZRBrX0wf8+sH5o= +github.com/minio/pkg v1.6.2/go.mod h1:HisnbndsCEaQHLvEurhBxt6mk6SGAn2LgJqChIfkb+s= github.com/minio/selfupdate v0.6.0 h1:i76PgT0K5xO9+hjzKcacQtO7+MjJ4JKA8Ak8XQ9DDwU= github.com/minio/selfupdate v0.6.0/go.mod h1:bO02GTIPCMQFTEvE5h4DjYB58bCoZ35XLeBf0buTDdM= github.com/minio/sha256-simd v1.0.0 h1:v1ta+49hkWZyvaKwrQB8elexRqm6Y0aMLjCNsrYxo6g= diff --git a/internal/logger/audit.go b/internal/logger/audit.go index 895d41455..03c7c74d2 100644 --- a/internal/logger/audit.go +++ b/internal/logger/audit.go @@ -24,10 +24,12 @@ import ( "strconv" "time" + internalAudit "github.com/minio/minio/internal/logger/message/audit" + "github.com/minio/pkg/logger/message/audit" + "github.com/klauspost/compress/gzhttp" "github.com/minio/madmin-go/v2" xhttp "github.com/minio/minio/internal/http" - "github.com/minio/minio/internal/logger/message/audit" ) const contextAuditKey = contextKeyType("audit-entry") @@ -49,7 +51,7 @@ func GetAuditEntry(ctx context.Context) *audit.Entry { return r } r = &audit.Entry{ - Version: audit.Version, + Version: internalAudit.Version, DeploymentID: xhttp.GlobalDeploymentID, Time: time.Now().UTC(), } @@ -74,7 +76,7 @@ func AuditLog(ctx context.Context, w http.ResponseWriter, r *http.Request, reqCl reqInfo.RLock() defer reqInfo.RUnlock() - entry = audit.ToEntry(w, r, reqClaims, xhttp.GlobalDeploymentID) + entry = internalAudit.ToEntry(w, r, reqClaims, xhttp.GlobalDeploymentID) // indicates all requests for this API call are inbound entry.Trigger = "incoming" diff --git a/internal/logger/console.go b/internal/logger/console.go index dd2c8b122..5c1aba1c6 100644 --- a/internal/logger/console.go +++ b/internal/logger/console.go @@ -25,8 +25,8 @@ import ( "time" "github.com/minio/minio/internal/color" - "github.com/minio/minio/internal/logger/message/log" c "github.com/minio/pkg/console" + "github.com/minio/pkg/logger/message/log" ) // ConsoleLoggerTgt is a stringified value to represent console logging diff --git a/internal/logger/logger.go b/internal/logger/logger.go index 877e4f4ac..8dbd02030 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -32,7 +32,7 @@ import ( "github.com/minio/madmin-go/v2" "github.com/minio/minio-go/v7/pkg/set" xhttp "github.com/minio/minio/internal/http" - "github.com/minio/minio/internal/logger/message/log" + "github.com/minio/pkg/logger/message/log" ) // HighwayHash key for logging in anonymous mode diff --git a/internal/logger/message/audit/entry.go b/internal/logger/message/audit/entry.go index d9e654386..7e55f5317 100644 --- a/internal/logger/message/audit/entry.go +++ b/internal/logger/message/audit/entry.go @@ -22,6 +22,8 @@ import ( "strings" "time" + "github.com/minio/pkg/logger/message/audit" + "github.com/minio/minio/internal/handlers" xhttp "github.com/minio/minio/internal/http" ) @@ -29,52 +31,9 @@ import ( // Version - represents the current version of audit log structure. const Version = "1" -// ObjectVersion object version key/versionId -type ObjectVersion struct { - ObjectName string `json:"objectName"` - VersionID string `json:"versionId,omitempty"` -} - -// Entry - audit entry logs. -type Entry struct { - Version string `json:"version"` - DeploymentID string `json:"deploymentid,omitempty"` - Time time.Time `json:"time"` - Event string `json:"event"` - // deprecated replaced by 'Event', kept here for some - // time for backward compatibility with k8s Operator. - Trigger string `json:"trigger"` - API struct { - Name string `json:"name,omitempty"` - Bucket string `json:"bucket,omitempty"` - Object string `json:"object,omitempty"` - Objects []ObjectVersion `json:"objects,omitempty"` - Status string `json:"status,omitempty"` - StatusCode int `json:"statusCode,omitempty"` - InputBytes int64 `json:"rx"` - OutputBytes int64 `json:"tx"` - HeaderBytes int64 `json:"txHeaders,omitempty"` - TimeToFirstByte string `json:"timeToFirstByte,omitempty"` - TimeToResponse string `json:"timeToResponse,omitempty"` - } `json:"api"` - RemoteHost string `json:"remotehost,omitempty"` - RequestID string `json:"requestID,omitempty"` - UserAgent string `json:"userAgent,omitempty"` - ReqClaims map[string]interface{} `json:"requestClaims,omitempty"` - ReqQuery map[string]string `json:"requestQuery,omitempty"` - ReqHeader map[string]string `json:"requestHeader,omitempty"` - RespHeader map[string]string `json:"responseHeader,omitempty"` - Tags map[string]interface{} `json:"tags,omitempty"` - - AccessKey string `json:"accessKey,omitempty"` - ParentUser string `json:"parentUser,omitempty"` - - Error string `json:"error,omitempty"` -} - // NewEntry - constructs an audit entry object with some fields filled -func NewEntry(deploymentID string) Entry { - return Entry{ +func NewEntry(deploymentID string) audit.Entry { + return audit.Entry{ Version: Version, DeploymentID: deploymentID, Time: time.Now().UTC(), @@ -82,7 +41,7 @@ func NewEntry(deploymentID string) Entry { } // ToEntry - constructs an audit entry from a http request -func ToEntry(w http.ResponseWriter, r *http.Request, reqClaims map[string]interface{}, deploymentID string) Entry { +func ToEntry(w http.ResponseWriter, r *http.Request, reqClaims map[string]interface{}, deploymentID string) audit.Entry { entry := NewEntry(deploymentID) entry.RemoteHost = handlers.GetSourceIP(r) diff --git a/internal/logger/message/log/entry.go b/internal/logger/message/log/entry.go deleted file mode 100644 index 7f75c0408..000000000 --- a/internal/logger/message/log/entry.go +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (c) 2015-2021 MinIO, Inc. -// -// This file is part of MinIO Object Storage stack -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package log - -import ( - "strings" - "time" - - "github.com/minio/madmin-go/v2" -) - -// ObjectVersion object version key/versionId -type ObjectVersion struct { - ObjectName string `json:"objectName"` - VersionID string `json:"versionId,omitempty"` -} - -// Args - defines the arguments for the API. -type Args struct { - Bucket string `json:"bucket,omitempty"` - Object string `json:"object,omitempty"` - VersionID string `json:"versionId,omitempty"` - Objects []ObjectVersion `json:"objects,omitempty"` - Metadata map[string]string `json:"metadata,omitempty"` -} - -// Trace - defines the trace. -type Trace struct { - Message string `json:"message,omitempty"` - Source []string `json:"source,omitempty"` - Variables map[string]interface{} `json:"variables,omitempty"` -} - -// API - defines the api type and its args. -type API struct { - Name string `json:"name,omitempty"` - Args *Args `json:"args,omitempty"` -} - -// Entry - defines fields and values of each log entry. -type Entry struct { - DeploymentID string `json:"deploymentid,omitempty"` - Level string `json:"level"` - LogKind madmin.LogKind `json:"errKind"` - Time time.Time `json:"time"` - API *API `json:"api,omitempty"` - RemoteHost string `json:"remotehost,omitempty"` - Host string `json:"host,omitempty"` - RequestID string `json:"requestID,omitempty"` - UserAgent string `json:"userAgent,omitempty"` - Message string `json:"message,omitempty"` - Trace *Trace `json:"error,omitempty"` -} - -// Info holds console log messages -type Info struct { - Entry - ConsoleMsg string - NodeName string `json:"node"` - Err error `json:"-"` -} - -// Mask returns the mask based on the error level. -func (l Info) Mask() uint64 { - return l.LogKind.LogMask().Mask() -} - -// SendLog returns true if log pertains to node specified in args. -func (l Info) SendLog(node string, logKind madmin.LogMask) bool { - if logKind.Contains(l.LogKind.LogMask()) { - return node == "" || strings.EqualFold(node, l.NodeName) && !l.Time.IsZero() - } - return false -} diff --git a/internal/logger/target/console/console.go b/internal/logger/target/console/console.go index e91ddfaf0..51e61a05a 100644 --- a/internal/logger/target/console/console.go +++ b/internal/logger/target/console/console.go @@ -25,8 +25,8 @@ import ( "github.com/minio/minio/internal/color" "github.com/minio/minio/internal/logger" - "github.com/minio/minio/internal/logger/message/log" "github.com/minio/pkg/console" + "github.com/minio/pkg/logger/message/log" ) // Target implements loggerTarget to send log diff --git a/internal/logger/target/kafka/kafka.go b/internal/logger/target/kafka/kafka.go index a43e0ace9..15f60f127 100644 --- a/internal/logger/target/kafka/kafka.go +++ b/internal/logger/target/kafka/kafka.go @@ -27,10 +27,11 @@ import ( "sync" "sync/atomic" + "github.com/minio/pkg/logger/message/audit" + "github.com/Shopify/sarama" saramatls "github.com/Shopify/sarama/tools/tls" - "github.com/minio/minio/internal/logger/message/audit" "github.com/minio/minio/internal/logger/target/types" xnet "github.com/minio/pkg/net" )