From 70b350c383645cd8d4ea72b8eba704199c12dd54 Mon Sep 17 00:00:00 2001 From: kannappanr <30541348+kannappanr@users.noreply.github.com> Date: Mon, 1 Jul 2019 12:22:01 -0700 Subject: [PATCH] Remove DeploymentID from response headers (#7815) Response headers need not contain deployment ID. --- cmd/admin-handlers.go | 4 ++-- cmd/api-datatypes.go | 2 -- cmd/api-response.go | 8 ++++---- cmd/gateway-main.go | 1 + cmd/generic-handlers.go | 8 ++------ cmd/logger/audit.go | 2 +- cmd/logger/logger.go | 11 ++++++++++- cmd/logger/message/audit/entry.go | 4 ++-- cmd/object-handlers.go | 6 +++--- cmd/routers.go | 2 +- cmd/server-main.go | 1 + cmd/utils.go | 2 +- 12 files changed, 28 insertions(+), 23 deletions(-) diff --git a/cmd/admin-handlers.go b/cmd/admin-handlers.go index db3eeb778..ab3e116e4 100644 --- a/cmd/admin-handlers.go +++ b/cmd/admin-handlers.go @@ -703,14 +703,14 @@ func (a adminAPIHandlers) HealHandler(w http.ResponseWriter, r *http.Request) { if hr.errBody == "" { errorRespJSON = encodeResponseJSON(getAPIErrorResponse(ctx, hr.apiErr, r.URL.Path, w.Header().Get(responseRequestIDKey), - w.Header().Get(responseDeploymentIDKey))) + globalDeploymentID)) } else { errorRespJSON = encodeResponseJSON(APIErrorResponse{ Code: hr.apiErr.Code, Message: hr.errBody, Resource: r.URL.Path, RequestID: w.Header().Get(responseRequestIDKey), - HostID: w.Header().Get(responseDeploymentIDKey), + HostID: globalDeploymentID, }) } if !started { diff --git a/cmd/api-datatypes.go b/cmd/api-datatypes.go index d84cf301f..0ae385838 100644 --- a/cmd/api-datatypes.go +++ b/cmd/api-datatypes.go @@ -23,8 +23,6 @@ import ( const ( // Response request id. responseRequestIDKey = "x-amz-request-id" - // Deployment id. - responseDeploymentIDKey = "x-minio-deployment-id" ) // ObjectIdentifier carries key name for the object to delete. diff --git a/cmd/api-response.go b/cmd/api-response.go index 3daea936e..2e1383b20 100644 --- a/cmd/api-response.go +++ b/cmd/api-response.go @@ -590,7 +590,7 @@ func writeErrorResponse(ctx context.Context, w http.ResponseWriter, err APIError // Generate error response. errorResponse := getAPIErrorResponse(ctx, err, reqURL.Path, - w.Header().Get(responseRequestIDKey), w.Header().Get(responseDeploymentIDKey)) + w.Header().Get(responseRequestIDKey), globalDeploymentID) encodedErrorResponse := encodeResponse(errorResponse) writeResponse(w, err.HTTPStatusCode, encodedErrorResponse, mimeXML) } @@ -603,7 +603,7 @@ func writeErrorResponseHeadersOnly(w http.ResponseWriter, err APIError) { // useful for admin APIs. func writeErrorResponseJSON(ctx context.Context, w http.ResponseWriter, err APIError, reqURL *url.URL) { // Generate error response. - errorResponse := getAPIErrorResponse(ctx, err, reqURL.Path, w.Header().Get(responseRequestIDKey), w.Header().Get(responseDeploymentIDKey)) + errorResponse := getAPIErrorResponse(ctx, err, reqURL.Path, w.Header().Get(responseRequestIDKey), globalDeploymentID) encodedErrorResponse := encodeResponseJSON(errorResponse) writeResponse(w, err.HTTPStatusCode, encodedErrorResponse, mimeJSON) } @@ -622,7 +622,7 @@ func writeCustomErrorResponseJSON(ctx context.Context, w http.ResponseWriter, er BucketName: reqInfo.BucketName, Key: reqInfo.ObjectName, RequestID: w.Header().Get(responseRequestIDKey), - HostID: w.Header().Get(responseDeploymentIDKey), + HostID: globalDeploymentID, } encodedErrorResponse := encodeResponseJSON(errorResponse) writeResponse(w, err.HTTPStatusCode, encodedErrorResponse, mimeJSON) @@ -656,7 +656,7 @@ func writeCustomErrorResponseXML(ctx context.Context, w http.ResponseWriter, err BucketName: reqInfo.BucketName, Key: reqInfo.ObjectName, RequestID: w.Header().Get(responseRequestIDKey), - HostID: w.Header().Get(responseDeploymentIDKey), + HostID: globalDeploymentID, } encodedErrorResponse := encodeResponse(errorResponse) diff --git a/cmd/gateway-main.go b/cmd/gateway-main.go index d6072eff0..3c36ddb4c 100644 --- a/cmd/gateway-main.go +++ b/cmd/gateway-main.go @@ -243,6 +243,7 @@ func StartGateway(ctx *cli.Context, gw Gateway) { // This is only to uniquely identify each gateway deployments. globalDeploymentID = os.Getenv("MINIO_GATEWAY_DEPLOYMENT_ID") + logger.SetDeploymentID(globalDeploymentID) var cacheConfig = globalServerConfig.GetCacheConfig() if len(cacheConfig.Drives) > 0 { diff --git a/cmd/generic-handlers.go b/cmd/generic-handlers.go index 45a309ee7..9139d78d5 100644 --- a/cmd/generic-handlers.go +++ b/cmd/generic-handlers.go @@ -750,7 +750,7 @@ func setBucketForwardingHandler(h http.Handler) http.Handler { return bucketForwardingHandler{fwd, h} } -// customHeaderHandler sets x-amz-request-id, x-minio-deployment-id header. +// customHeaderHandler sets x-amz-request-id header. // Previously, this value was set right before a response was sent to // the client. So, logger and Error response XML were not using this // value. This is set here so that this header can be logged as @@ -764,12 +764,8 @@ func addCustomHeaders(h http.Handler) http.Handler { } func (s customHeaderHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - // Set custom headers such as x-amz-request-id and x-minio-deployment-id - // for each request. + // Set custom headers such as x-amz-request-id for each request. w.Header().Set(responseRequestIDKey, mustGetRequestID(UTCNow())) - if globalDeploymentID != "" { - w.Header().Set(responseDeploymentIDKey, globalDeploymentID) - } s.handler.ServeHTTP(logger.NewResponseWriter(w), r) } diff --git a/cmd/logger/audit.go b/cmd/logger/audit.go index c9fd7b532..e759f4a4c 100644 --- a/cmd/logger/audit.go +++ b/cmd/logger/audit.go @@ -63,6 +63,6 @@ func AuditLog(w http.ResponseWriter, r *http.Request, api string, reqClaims map[ } // Send audit logs only to http targets. for _, t := range AuditTargets { - _ = t.Send(audit.ToEntry(w, r, api, statusCode, reqClaims)) + _ = t.Send(audit.ToEntry(w, r, api, statusCode, reqClaims, globalDeploymentID)) } } diff --git a/cmd/logger/logger.go b/cmd/logger/logger.go index 83b291c3e..8bde67de4 100644 --- a/cmd/logger/logger.go +++ b/cmd/logger/logger.go @@ -55,6 +55,8 @@ const ( var trimStrings []string +var globalDeploymentID string + // TimeFormat - logging time format. const TimeFormat string = "15:04:05 MST 01/02/2006" @@ -154,6 +156,11 @@ 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 @@ -317,7 +324,9 @@ func logIf(ctx context.Context, err error) { // Get the cause for the Error message := err.Error() - + if req.DeploymentID == "" { + req.DeploymentID = globalDeploymentID + } entry := log.Entry{ DeploymentID: req.DeploymentID, Level: ErrorLvl.String(), diff --git a/cmd/logger/message/audit/entry.go b/cmd/logger/message/audit/entry.go index 3d3771f4f..161c5477b 100644 --- a/cmd/logger/message/audit/entry.go +++ b/cmd/logger/message/audit/entry.go @@ -50,7 +50,7 @@ type Entry struct { } // ToEntry - constructs an audit entry object. -func ToEntry(w http.ResponseWriter, r *http.Request, api string, statusCode int, reqClaims map[string]interface{}) Entry { +func ToEntry(w http.ResponseWriter, r *http.Request, api string, statusCode int, reqClaims map[string]interface{}, deploymentID string) Entry { vars := mux.Vars(r) bucket := vars["bucket"] object := vars["object"] @@ -71,7 +71,7 @@ func ToEntry(w http.ResponseWriter, r *http.Request, api string, statusCode int, entry := Entry{ Version: Version, - DeploymentID: w.Header().Get("x-minio-deployment-id"), + DeploymentID: deploymentID, RemoteHost: handlers.GetSourceIP(r), RequestID: w.Header().Get("x-amz-request-id"), UserAgent: r.UserAgent(), diff --git a/cmd/object-handlers.go b/cmd/object-handlers.go index 7785c022b..6f3d0a519 100644 --- a/cmd/object-handlers.go +++ b/cmd/object-handlers.go @@ -166,7 +166,7 @@ func (api objectAPIHandlers) SelectObjectContentHandler(w http.ResponseWriter, r Key: object, Resource: r.URL.Path, RequestID: w.Header().Get(responseRequestIDKey), - HostID: w.Header().Get(responseDeploymentIDKey), + HostID: globalDeploymentID, }) writeResponse(w, serr.HTTPStatusCode(), encodedErrorResponse, mimeXML) } else { @@ -208,7 +208,7 @@ func (api objectAPIHandlers) SelectObjectContentHandler(w http.ResponseWriter, r Key: object, Resource: r.URL.Path, RequestID: w.Header().Get(responseRequestIDKey), - HostID: w.Header().Get(responseDeploymentIDKey), + HostID: globalDeploymentID, }) writeResponse(w, serr.HTTPStatusCode(), encodedErrorResponse, mimeXML) } else { @@ -2272,7 +2272,7 @@ func (api objectAPIHandlers) CompleteMultipartUploadHandler(w http.ResponseWrite // Generate error response. errorResponse := getAPIErrorResponse(ctx, err, reqURL.Path, - w.Header().Get(responseRequestIDKey), w.Header().Get(responseDeploymentIDKey)) + w.Header().Get(responseRequestIDKey), globalDeploymentID) encodedErrorResponse, _ := xml.Marshal(errorResponse) setCommonHeaders(w) w.Header().Set("Content-Type", string(mimeXML)) diff --git a/cmd/routers.go b/cmd/routers.go index 9a1f55ee1..baadd1929 100644 --- a/cmd/routers.go +++ b/cmd/routers.go @@ -48,7 +48,7 @@ func registerDistXLRouters(router *mux.Router, endpoints EndpointList) { // List of some generic handlers which are applied for all incoming requests. var globalHandlers = []HandlerFunc{ - // set x-amz-request-id, x-minio-deployment-id header. + // set x-amz-request-id header. addCustomHeaders, // set HTTP security headers such as Content-Security-Policy. addSecurityHeaders, diff --git a/cmd/server-main.go b/cmd/server-main.go index 8237472f5..1989025da 100644 --- a/cmd/server-main.go +++ b/cmd/server-main.go @@ -314,6 +314,7 @@ func serverMain(ctx *cli.Context) { }() newObject, err := newObjectLayer(globalEndpoints) + logger.SetDeploymentID(globalDeploymentID) if err != nil { // Stop watching for any certificate changes. globalTLSCerts.Stop() diff --git a/cmd/utils.go b/cmd/utils.go index 70eac2546..428af6292 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -425,7 +425,7 @@ func newContext(r *http.Request, w http.ResponseWriter, api string) context.Cont object = prefix } reqInfo := &logger.ReqInfo{ - DeploymentID: w.Header().Get(responseDeploymentIDKey), + DeploymentID: globalDeploymentID, RequestID: w.Header().Get(responseRequestIDKey), RemoteHost: handlers.GetSourceIP(r), UserAgent: r.UserAgent(),