add missing request-id from DeleteObject events (#10623)

fixes #10621
master
Harshavardhana 4 years ago committed by GitHub
parent d1ed1da8c6
commit 8e7c00f3d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      cmd/handler-utils.go
  2. 28
      cmd/object-handlers-common.go
  3. 2
      cmd/object-handlers.go
  4. 26
      cmd/web-handlers.go

@ -238,7 +238,9 @@ func extractReqParams(r *http.Request) map[string]string {
// Extract response elements to be sent with event notifiation. // Extract response elements to be sent with event notifiation.
func extractRespElements(w http.ResponseWriter) map[string]string { func extractRespElements(w http.ResponseWriter) map[string]string {
if w == nil {
return map[string]string{}
}
return map[string]string{ return map[string]string{
"requestId": w.Header().Get(xhttp.AmzRequestID), "requestId": w.Header().Get(xhttp.AmzRequestID),
"content-length": w.Header().Get(xhttp.ContentLength), "content-length": w.Header().Get(xhttp.ContentLength),

@ -281,7 +281,7 @@ func setPutObjHeaders(w http.ResponseWriter, objInfo ObjectInfo, delete bool) {
// deleteObject is a convenient wrapper to delete an object, this // deleteObject is a convenient wrapper to delete an object, this
// is a common function to be called from object handlers and // is a common function to be called from object handlers and
// web handlers. // web handlers.
func deleteObject(ctx context.Context, obj ObjectLayer, cache CacheObjectLayer, bucket, object string, r *http.Request, opts ObjectOptions) (objInfo ObjectInfo, err error) { func deleteObject(ctx context.Context, obj ObjectLayer, cache CacheObjectLayer, bucket, object string, w http.ResponseWriter, r *http.Request, opts ObjectOptions) (objInfo ObjectInfo, err error) {
deleteObject := obj.DeleteObject deleteObject := obj.DeleteObject
if cache != nil { if cache != nil {
deleteObject = cache.DeleteObject deleteObject = cache.DeleteObject
@ -293,22 +293,24 @@ func deleteObject(ctx context.Context, obj ObjectLayer, cache CacheObjectLayer,
if objInfo.DeleteMarker { if objInfo.DeleteMarker {
// Notify object deleted marker event. // Notify object deleted marker event.
sendEvent(eventArgs{ sendEvent(eventArgs{
EventName: event.ObjectRemovedDeleteMarkerCreated, EventName: event.ObjectRemovedDeleteMarkerCreated,
BucketName: bucket, BucketName: bucket,
Object: objInfo, Object: objInfo,
ReqParams: extractReqParams(r), ReqParams: extractReqParams(r),
UserAgent: r.UserAgent(), RespElements: extractRespElements(w),
Host: handlers.GetSourceIP(r), UserAgent: r.UserAgent(),
Host: handlers.GetSourceIP(r),
}) })
} else { } else {
// Notify object deleted event. // Notify object deleted event.
sendEvent(eventArgs{ sendEvent(eventArgs{
EventName: event.ObjectRemovedDelete, EventName: event.ObjectRemovedDelete,
BucketName: bucket, BucketName: bucket,
Object: objInfo, Object: objInfo,
ReqParams: extractReqParams(r), ReqParams: extractReqParams(r),
UserAgent: r.UserAgent(), RespElements: extractRespElements(w),
Host: handlers.GetSourceIP(r), UserAgent: r.UserAgent(),
Host: handlers.GetSourceIP(r),
}) })
} }
} }

@ -2726,7 +2726,7 @@ func (api objectAPIHandlers) DeleteObjectHandler(w http.ResponseWriter, r *http.
} }
// http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectDELETE.html // http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectDELETE.html
objInfo, err := deleteObject(ctx, objectAPI, api.CacheAPI(), bucket, object, r, opts) objInfo, err := deleteObject(ctx, objectAPI, api.CacheAPI(), bucket, object, w, r, opts)
if err != nil { if err != nil {
switch err.(type) { switch err.(type) {
case BucketNotFound: case BucketNotFound:

@ -715,7 +715,7 @@ next:
} }
} }
_, err = deleteObject(ctx, objectAPI, web.CacheAPI(), args.BucketName, objectName, r, opts) _, err = deleteObject(ctx, objectAPI, web.CacheAPI(), args.BucketName, objectName, nil, r, opts)
logger.LogIf(ctx, err) logger.LogIf(ctx, err)
continue continue
} }
@ -771,13 +771,35 @@ next:
} }
// Deletes a list of objects. // Deletes a list of objects.
_, errs := deleteObjects(ctx, args.BucketName, objects, opts) deletedObjects, errs := deleteObjects(ctx, args.BucketName, objects, opts)
for _, err := range errs { for _, err := range errs {
if err != nil { if err != nil {
logger.LogIf(ctx, err) logger.LogIf(ctx, err)
break next break next
} }
} }
// Notify deleted event for objects.
for _, dobj := range deletedObjects {
objInfo := ObjectInfo{
Name: dobj.ObjectName,
VersionID: dobj.VersionID,
}
if dobj.DeleteMarker {
objInfo = ObjectInfo{
Name: dobj.ObjectName,
DeleteMarker: dobj.DeleteMarker,
VersionID: dobj.DeleteMarkerVersionID,
}
}
sendEvent(eventArgs{
EventName: event.ObjectRemovedDelete,
BucketName: args.BucketName,
Object: objInfo,
ReqParams: extractReqParams(r),
UserAgent: r.UserAgent(),
Host: handlers.GetSourceIP(r),
})
}
} }
} }

Loading…
Cancel
Save