From 25144fedd52441ebcfc218ba85e6262e3ea5bcb4 Mon Sep 17 00:00:00 2001 From: Shireesh Anjal <355479+anjalshireesh@users.noreply.github.com> Date: Thu, 24 Feb 2022 03:06:01 +0530 Subject: [PATCH] Send deployment id and minio version in http header (#14378) --- cmd/gateway-main.go | 2 +- cmd/server-main.go | 3 ++- internal/http/headers.go | 6 ++++++ internal/http/server.go | 18 ++++++++++++++++++ internal/logger/audit.go | 5 +++-- internal/logger/logger.go | 10 ++-------- internal/logger/target/http/http.go | 2 ++ 7 files changed, 34 insertions(+), 12 deletions(-) diff --git a/cmd/gateway-main.go b/cmd/gateway-main.go index a1b5b31e2..6b10a02ba 100644 --- a/cmd/gateway-main.go +++ b/cmd/gateway-main.go @@ -161,7 +161,7 @@ func StartGateway(ctx *cli.Context, gw Gateway) { signal.Notify(globalOSSignalCh, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT) // This is only to uniquely identify each gateway deployments. globalDeploymentID = env.Get("MINIO_GATEWAY_DEPLOYMENT_ID", mustGetUUID()) - logger.SetDeploymentID(globalDeploymentID) + xhttp.SetDeploymentID(globalDeploymentID) if gw == nil { logger.FatalIf(errUnexpected, "Gateway implementation not initialized") diff --git a/cmd/server-main.go b/cmd/server-main.go index 00a09109c..9ecd102d5 100644 --- a/cmd/server-main.go +++ b/cmd/server-main.go @@ -493,7 +493,8 @@ func serverMain(ctx *cli.Context) { logFatalErrs(err, Endpoint{}, true) } - logger.SetDeploymentID(globalDeploymentID) + xhttp.SetDeploymentID(globalDeploymentID) + xhttp.SetMinIOVersion(Version) // Enable background operations for erasure coding if globalIsErasure { diff --git a/internal/http/headers.go b/internal/http/headers.go index 6bec1e7f6..5b06f4cae 100644 --- a/internal/http/headers.go +++ b/internal/http/headers.go @@ -191,3 +191,9 @@ const ( UploadID = "uploadId" ) + +// http headers sent to webhook targets +const ( + // Reports the version of MinIO server + MinIOVersion = "x-minio-version" +) diff --git a/internal/http/server.go b/internal/http/server.go index 81b0f8350..078f330ee 100644 --- a/internal/http/server.go +++ b/internal/http/server.go @@ -33,6 +33,14 @@ import ( humanize "github.com/dustin/go-humanize" ) +var ( + // GlobalMinIOVersion - is sent in the header to all http targets + GlobalMinIOVersion string + + // GlobalDeploymentID - is sent in the header to all http targets + GlobalDeploymentID string +) + const ( serverShutdownPoll = 500 * time.Millisecond @@ -196,3 +204,13 @@ func NewServer(addrs []string) *Server { httpServer.MaxHeaderBytes = DefaultMaxHeaderBytes return httpServer } + +// SetMinIOVersion -- MinIO version from the main package is set here +func SetMinIOVersion(minioVer string) { + GlobalMinIOVersion = minioVer +} + +// SetDeploymentID -- Deployment Id from the main package is set here +func SetDeploymentID(deploymentID string) { + GlobalDeploymentID = deploymentID +} diff --git a/internal/logger/audit.go b/internal/logger/audit.go index 36c44f68e..898014317 100644 --- a/internal/logger/audit.go +++ b/internal/logger/audit.go @@ -28,6 +28,7 @@ import ( "time" "github.com/klauspost/compress/gzhttp" + xhttp "github.com/minio/minio/internal/http" "github.com/minio/minio/internal/logger/message/audit" ) @@ -146,7 +147,7 @@ func GetAuditEntry(ctx context.Context) *audit.Entry { } r = &audit.Entry{ Version: audit.Version, - DeploymentID: globalDeploymentID, + DeploymentID: xhttp.GlobalDeploymentID, Time: time.Now().UTC(), } SetAuditEntry(ctx, r) @@ -170,7 +171,7 @@ func AuditLog(ctx context.Context, w http.ResponseWriter, r *http.Request, reqCl return } - entry = audit.ToEntry(w, r, reqClaims, globalDeploymentID) + entry = audit.ToEntry(w, r, reqClaims, xhttp.GlobalDeploymentID) // indicates all requests for this API call are inbound entry.Trigger = "incoming" diff --git a/internal/logger/logger.go b/internal/logger/logger.go index 89f685851..9388a10b9 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -32,6 +32,7 @@ import ( "github.com/minio/highwayhash" "github.com/minio/minio-go/v7/pkg/set" + xhttp "github.com/minio/minio/internal/http" "github.com/minio/minio/internal/logger/message/log" ) @@ -53,8 +54,6 @@ const ( var trimStrings []string -var globalDeploymentID string - // TimeFormat - logging time format. const TimeFormat string = "15:04:05 MST 01/02/2006" @@ -130,11 +129,6 @@ func uniqueEntries(paths []string) []string { return m.ToSlice() } -// SetDeploymentID -- Deployment Id from the main package is set here -func SetDeploymentID(deploymentID string) { - globalDeploymentID = deploymentID -} - // Init sets the trimStrings to possible GOPATHs // and GOROOT directories. Also append github.com/minio/minio // This is done to clean up the filename, when stack trace is @@ -319,7 +313,7 @@ func logIf(ctx context.Context, err error, errKind ...interface{}) { // Get the cause for the Error message := fmt.Sprintf("%v (%T)", err, err) if req.DeploymentID == "" { - req.DeploymentID = globalDeploymentID + req.DeploymentID = xhttp.GlobalDeploymentID } objects := make([]log.ObjectVersion, 0, len(req.Objects)) diff --git a/internal/logger/target/http/http.go b/internal/logger/target/http/http.go index ab00a6f8b..38ed9ebb2 100644 --- a/internal/logger/target/http/http.go +++ b/internal/logger/target/http/http.go @@ -144,6 +144,8 @@ func (h *Target) logEntry(entry interface{}) { return } req.Header.Set(xhttp.ContentType, "application/json") + req.Header.Set(xhttp.MinIOVersion, xhttp.GlobalMinIOVersion) + req.Header.Set(xhttp.MinioDeploymentID, xhttp.GlobalDeploymentID) // Set user-agent to indicate MinIO release // version to the configured log endpoint