mirror of
https://github.com/minio/minio.git
synced 2024-12-24 22:25:54 -05:00
Remove DeploymentID from response headers (#7815)
Response headers need not contain deployment ID.
This commit is contained in:
parent
338e9a9be9
commit
70b350c383
@ -703,14 +703,14 @@ func (a adminAPIHandlers) HealHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
if hr.errBody == "" {
|
if hr.errBody == "" {
|
||||||
errorRespJSON = encodeResponseJSON(getAPIErrorResponse(ctx, hr.apiErr,
|
errorRespJSON = encodeResponseJSON(getAPIErrorResponse(ctx, hr.apiErr,
|
||||||
r.URL.Path, w.Header().Get(responseRequestIDKey),
|
r.URL.Path, w.Header().Get(responseRequestIDKey),
|
||||||
w.Header().Get(responseDeploymentIDKey)))
|
globalDeploymentID))
|
||||||
} else {
|
} else {
|
||||||
errorRespJSON = encodeResponseJSON(APIErrorResponse{
|
errorRespJSON = encodeResponseJSON(APIErrorResponse{
|
||||||
Code: hr.apiErr.Code,
|
Code: hr.apiErr.Code,
|
||||||
Message: hr.errBody,
|
Message: hr.errBody,
|
||||||
Resource: r.URL.Path,
|
Resource: r.URL.Path,
|
||||||
RequestID: w.Header().Get(responseRequestIDKey),
|
RequestID: w.Header().Get(responseRequestIDKey),
|
||||||
HostID: w.Header().Get(responseDeploymentIDKey),
|
HostID: globalDeploymentID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if !started {
|
if !started {
|
||||||
|
@ -23,8 +23,6 @@ import (
|
|||||||
const (
|
const (
|
||||||
// Response request id.
|
// Response request id.
|
||||||
responseRequestIDKey = "x-amz-request-id"
|
responseRequestIDKey = "x-amz-request-id"
|
||||||
// Deployment id.
|
|
||||||
responseDeploymentIDKey = "x-minio-deployment-id"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ObjectIdentifier carries key name for the object to delete.
|
// ObjectIdentifier carries key name for the object to delete.
|
||||||
|
@ -590,7 +590,7 @@ func writeErrorResponse(ctx context.Context, w http.ResponseWriter, err APIError
|
|||||||
|
|
||||||
// Generate error response.
|
// Generate error response.
|
||||||
errorResponse := getAPIErrorResponse(ctx, err, reqURL.Path,
|
errorResponse := getAPIErrorResponse(ctx, err, reqURL.Path,
|
||||||
w.Header().Get(responseRequestIDKey), w.Header().Get(responseDeploymentIDKey))
|
w.Header().Get(responseRequestIDKey), globalDeploymentID)
|
||||||
encodedErrorResponse := encodeResponse(errorResponse)
|
encodedErrorResponse := encodeResponse(errorResponse)
|
||||||
writeResponse(w, err.HTTPStatusCode, encodedErrorResponse, mimeXML)
|
writeResponse(w, err.HTTPStatusCode, encodedErrorResponse, mimeXML)
|
||||||
}
|
}
|
||||||
@ -603,7 +603,7 @@ func writeErrorResponseHeadersOnly(w http.ResponseWriter, err APIError) {
|
|||||||
// useful for admin APIs.
|
// useful for admin APIs.
|
||||||
func writeErrorResponseJSON(ctx context.Context, w http.ResponseWriter, err APIError, reqURL *url.URL) {
|
func writeErrorResponseJSON(ctx context.Context, w http.ResponseWriter, err APIError, reqURL *url.URL) {
|
||||||
// Generate error response.
|
// 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)
|
encodedErrorResponse := encodeResponseJSON(errorResponse)
|
||||||
writeResponse(w, err.HTTPStatusCode, encodedErrorResponse, mimeJSON)
|
writeResponse(w, err.HTTPStatusCode, encodedErrorResponse, mimeJSON)
|
||||||
}
|
}
|
||||||
@ -622,7 +622,7 @@ func writeCustomErrorResponseJSON(ctx context.Context, w http.ResponseWriter, er
|
|||||||
BucketName: reqInfo.BucketName,
|
BucketName: reqInfo.BucketName,
|
||||||
Key: reqInfo.ObjectName,
|
Key: reqInfo.ObjectName,
|
||||||
RequestID: w.Header().Get(responseRequestIDKey),
|
RequestID: w.Header().Get(responseRequestIDKey),
|
||||||
HostID: w.Header().Get(responseDeploymentIDKey),
|
HostID: globalDeploymentID,
|
||||||
}
|
}
|
||||||
encodedErrorResponse := encodeResponseJSON(errorResponse)
|
encodedErrorResponse := encodeResponseJSON(errorResponse)
|
||||||
writeResponse(w, err.HTTPStatusCode, encodedErrorResponse, mimeJSON)
|
writeResponse(w, err.HTTPStatusCode, encodedErrorResponse, mimeJSON)
|
||||||
@ -656,7 +656,7 @@ func writeCustomErrorResponseXML(ctx context.Context, w http.ResponseWriter, err
|
|||||||
BucketName: reqInfo.BucketName,
|
BucketName: reqInfo.BucketName,
|
||||||
Key: reqInfo.ObjectName,
|
Key: reqInfo.ObjectName,
|
||||||
RequestID: w.Header().Get(responseRequestIDKey),
|
RequestID: w.Header().Get(responseRequestIDKey),
|
||||||
HostID: w.Header().Get(responseDeploymentIDKey),
|
HostID: globalDeploymentID,
|
||||||
}
|
}
|
||||||
|
|
||||||
encodedErrorResponse := encodeResponse(errorResponse)
|
encodedErrorResponse := encodeResponse(errorResponse)
|
||||||
|
@ -243,6 +243,7 @@ func StartGateway(ctx *cli.Context, gw Gateway) {
|
|||||||
|
|
||||||
// This is only to uniquely identify each gateway deployments.
|
// This is only to uniquely identify each gateway deployments.
|
||||||
globalDeploymentID = os.Getenv("MINIO_GATEWAY_DEPLOYMENT_ID")
|
globalDeploymentID = os.Getenv("MINIO_GATEWAY_DEPLOYMENT_ID")
|
||||||
|
logger.SetDeploymentID(globalDeploymentID)
|
||||||
|
|
||||||
var cacheConfig = globalServerConfig.GetCacheConfig()
|
var cacheConfig = globalServerConfig.GetCacheConfig()
|
||||||
if len(cacheConfig.Drives) > 0 {
|
if len(cacheConfig.Drives) > 0 {
|
||||||
|
@ -750,7 +750,7 @@ func setBucketForwardingHandler(h http.Handler) http.Handler {
|
|||||||
return bucketForwardingHandler{fwd, h}
|
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
|
// Previously, this value was set right before a response was sent to
|
||||||
// the client. So, logger and Error response XML were not using this
|
// 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
|
// 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) {
|
func (s customHeaderHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
// Set custom headers such as x-amz-request-id and x-minio-deployment-id
|
// Set custom headers such as x-amz-request-id for each request.
|
||||||
// for each request.
|
|
||||||
w.Header().Set(responseRequestIDKey, mustGetRequestID(UTCNow()))
|
w.Header().Set(responseRequestIDKey, mustGetRequestID(UTCNow()))
|
||||||
if globalDeploymentID != "" {
|
|
||||||
w.Header().Set(responseDeploymentIDKey, globalDeploymentID)
|
|
||||||
}
|
|
||||||
s.handler.ServeHTTP(logger.NewResponseWriter(w), r)
|
s.handler.ServeHTTP(logger.NewResponseWriter(w), r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +63,6 @@ func AuditLog(w http.ResponseWriter, r *http.Request, api string, reqClaims map[
|
|||||||
}
|
}
|
||||||
// Send audit logs only to http targets.
|
// Send audit logs only to http targets.
|
||||||
for _, t := range AuditTargets {
|
for _, t := range AuditTargets {
|
||||||
_ = t.Send(audit.ToEntry(w, r, api, statusCode, reqClaims))
|
_ = t.Send(audit.ToEntry(w, r, api, statusCode, reqClaims, globalDeploymentID))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,8 @@ const (
|
|||||||
|
|
||||||
var trimStrings []string
|
var trimStrings []string
|
||||||
|
|
||||||
|
var globalDeploymentID string
|
||||||
|
|
||||||
// TimeFormat - logging time format.
|
// TimeFormat - logging time format.
|
||||||
const TimeFormat string = "15:04:05 MST 01/02/2006"
|
const TimeFormat string = "15:04:05 MST 01/02/2006"
|
||||||
|
|
||||||
@ -154,6 +156,11 @@ func uniqueEntries(paths []string) []string {
|
|||||||
return m.ToSlice()
|
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
|
// Init sets the trimStrings to possible GOPATHs
|
||||||
// and GOROOT directories. Also append github.com/minio/minio
|
// and GOROOT directories. Also append github.com/minio/minio
|
||||||
// This is done to clean up the filename, when stack trace is
|
// 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
|
// Get the cause for the Error
|
||||||
message := err.Error()
|
message := err.Error()
|
||||||
|
if req.DeploymentID == "" {
|
||||||
|
req.DeploymentID = globalDeploymentID
|
||||||
|
}
|
||||||
entry := log.Entry{
|
entry := log.Entry{
|
||||||
DeploymentID: req.DeploymentID,
|
DeploymentID: req.DeploymentID,
|
||||||
Level: ErrorLvl.String(),
|
Level: ErrorLvl.String(),
|
||||||
|
@ -50,7 +50,7 @@ type Entry struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ToEntry - constructs an audit entry object.
|
// 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)
|
vars := mux.Vars(r)
|
||||||
bucket := vars["bucket"]
|
bucket := vars["bucket"]
|
||||||
object := vars["object"]
|
object := vars["object"]
|
||||||
@ -71,7 +71,7 @@ func ToEntry(w http.ResponseWriter, r *http.Request, api string, statusCode int,
|
|||||||
|
|
||||||
entry := Entry{
|
entry := Entry{
|
||||||
Version: Version,
|
Version: Version,
|
||||||
DeploymentID: w.Header().Get("x-minio-deployment-id"),
|
DeploymentID: deploymentID,
|
||||||
RemoteHost: handlers.GetSourceIP(r),
|
RemoteHost: handlers.GetSourceIP(r),
|
||||||
RequestID: w.Header().Get("x-amz-request-id"),
|
RequestID: w.Header().Get("x-amz-request-id"),
|
||||||
UserAgent: r.UserAgent(),
|
UserAgent: r.UserAgent(),
|
||||||
|
@ -166,7 +166,7 @@ func (api objectAPIHandlers) SelectObjectContentHandler(w http.ResponseWriter, r
|
|||||||
Key: object,
|
Key: object,
|
||||||
Resource: r.URL.Path,
|
Resource: r.URL.Path,
|
||||||
RequestID: w.Header().Get(responseRequestIDKey),
|
RequestID: w.Header().Get(responseRequestIDKey),
|
||||||
HostID: w.Header().Get(responseDeploymentIDKey),
|
HostID: globalDeploymentID,
|
||||||
})
|
})
|
||||||
writeResponse(w, serr.HTTPStatusCode(), encodedErrorResponse, mimeXML)
|
writeResponse(w, serr.HTTPStatusCode(), encodedErrorResponse, mimeXML)
|
||||||
} else {
|
} else {
|
||||||
@ -208,7 +208,7 @@ func (api objectAPIHandlers) SelectObjectContentHandler(w http.ResponseWriter, r
|
|||||||
Key: object,
|
Key: object,
|
||||||
Resource: r.URL.Path,
|
Resource: r.URL.Path,
|
||||||
RequestID: w.Header().Get(responseRequestIDKey),
|
RequestID: w.Header().Get(responseRequestIDKey),
|
||||||
HostID: w.Header().Get(responseDeploymentIDKey),
|
HostID: globalDeploymentID,
|
||||||
})
|
})
|
||||||
writeResponse(w, serr.HTTPStatusCode(), encodedErrorResponse, mimeXML)
|
writeResponse(w, serr.HTTPStatusCode(), encodedErrorResponse, mimeXML)
|
||||||
} else {
|
} else {
|
||||||
@ -2272,7 +2272,7 @@ func (api objectAPIHandlers) CompleteMultipartUploadHandler(w http.ResponseWrite
|
|||||||
|
|
||||||
// Generate error response.
|
// Generate error response.
|
||||||
errorResponse := getAPIErrorResponse(ctx, err, reqURL.Path,
|
errorResponse := getAPIErrorResponse(ctx, err, reqURL.Path,
|
||||||
w.Header().Get(responseRequestIDKey), w.Header().Get(responseDeploymentIDKey))
|
w.Header().Get(responseRequestIDKey), globalDeploymentID)
|
||||||
encodedErrorResponse, _ := xml.Marshal(errorResponse)
|
encodedErrorResponse, _ := xml.Marshal(errorResponse)
|
||||||
setCommonHeaders(w)
|
setCommonHeaders(w)
|
||||||
w.Header().Set("Content-Type", string(mimeXML))
|
w.Header().Set("Content-Type", string(mimeXML))
|
||||||
|
@ -48,7 +48,7 @@ func registerDistXLRouters(router *mux.Router, endpoints EndpointList) {
|
|||||||
|
|
||||||
// List of some generic handlers which are applied for all incoming requests.
|
// List of some generic handlers which are applied for all incoming requests.
|
||||||
var globalHandlers = []HandlerFunc{
|
var globalHandlers = []HandlerFunc{
|
||||||
// set x-amz-request-id, x-minio-deployment-id header.
|
// set x-amz-request-id header.
|
||||||
addCustomHeaders,
|
addCustomHeaders,
|
||||||
// set HTTP security headers such as Content-Security-Policy.
|
// set HTTP security headers such as Content-Security-Policy.
|
||||||
addSecurityHeaders,
|
addSecurityHeaders,
|
||||||
|
@ -314,6 +314,7 @@ func serverMain(ctx *cli.Context) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
newObject, err := newObjectLayer(globalEndpoints)
|
newObject, err := newObjectLayer(globalEndpoints)
|
||||||
|
logger.SetDeploymentID(globalDeploymentID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Stop watching for any certificate changes.
|
// Stop watching for any certificate changes.
|
||||||
globalTLSCerts.Stop()
|
globalTLSCerts.Stop()
|
||||||
|
@ -425,7 +425,7 @@ func newContext(r *http.Request, w http.ResponseWriter, api string) context.Cont
|
|||||||
object = prefix
|
object = prefix
|
||||||
}
|
}
|
||||||
reqInfo := &logger.ReqInfo{
|
reqInfo := &logger.ReqInfo{
|
||||||
DeploymentID: w.Header().Get(responseDeploymentIDKey),
|
DeploymentID: globalDeploymentID,
|
||||||
RequestID: w.Header().Get(responseRequestIDKey),
|
RequestID: w.Header().Get(responseRequestIDKey),
|
||||||
RemoteHost: handlers.GetSourceIP(r),
|
RemoteHost: handlers.GetSourceIP(r),
|
||||||
UserAgent: r.UserAgent(),
|
UserAgent: r.UserAgent(),
|
||||||
|
Loading…
Reference in New Issue
Block a user