From 934bed47faef699b125a95355581d4a20939ee61 Mon Sep 17 00:00:00 2001 From: Poorna Krishnamoorthy Date: Mon, 7 Dec 2020 13:53:28 -0800 Subject: [PATCH] Add transition event notification (#11047) This is a MinIO specific extension to allow monitoring of transition events. --- cmd/bucket-lifecycle.go | 18 +++++++++++++++--- docs/bucket/lifecycle/README.md | 5 +++++ pkg/event/name.go | 21 ++++++++++++++++++++- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/cmd/bucket-lifecycle.go b/cmd/bucket-lifecycle.go index d67dc2d71..3bdceee05 100644 --- a/cmd/bucket-lifecycle.go +++ b/cmd/bucket-lifecycle.go @@ -356,11 +356,23 @@ func transitionObject(ctx context.Context, objectAPI ObjectLayer, objInfo Object opts.Versioned = globalBucketVersioningSys.Enabled(oi.Bucket) opts.VersionID = oi.VersionID opts.TransitionStatus = lifecycle.TransitionComplete + eventName := event.ObjectTransitionComplete - if _, err = objectAPI.DeleteObject(ctx, oi.Bucket, oi.Name, opts); err != nil { - return err + _, err = objectAPI.DeleteObject(ctx, oi.Bucket, oi.Name, opts) + if err != nil { + eventName = event.ObjectTransitionFailed } - return nil + // Notify object deleted event. + sendEvent(eventArgs{ + EventName: eventName, + BucketName: oi.Bucket, + Object: ObjectInfo{ + Name: oi.Name, + VersionID: opts.VersionID, + }, + Host: "Internal: [ILM-Transition]", + }) + return err } // getLifecycleTransitionTargetArn returns transition ARN for storage class specified in the config. diff --git a/docs/bucket/lifecycle/README.md b/docs/bucket/lifecycle/README.md index 8e1894837..a92314996 100644 --- a/docs/bucket/lifecycle/README.md +++ b/docs/bucket/lifecycle/README.md @@ -127,6 +127,11 @@ aws s3api restore-object --bucket srcbucket \ --restore-request Days=3 ``` +### 4.1 Monitoring transition events +`s3:ObjectTransition:Complete` and `s3:ObjectTransition:Failed` events can be used to monitor transition events between the source cluster and transition tier. To watch lifecycle events, you can enable bucket notification on the source bucket with `mc event add` and specify `--event ilm` flag. + +Note that transition event notification is a MinIO extension. + ## Explore Further - [MinIO | Golang Client API Reference](https://docs.min.io/docs/golang-client-api-reference.html#SetBucketLifecycle) - [Object Lifecycle Management](https://docs.aws.amazon.com/AmazonS3/latest/dev/object-lifecycle-mgmt.html) diff --git a/pkg/event/name.go b/pkg/event/name.go index 6f5a108f7..5ec7afc76 100644 --- a/pkg/event/name.go +++ b/pkg/event/name.go @@ -55,6 +55,9 @@ const ( ObjectRestorePostInitiated ObjectRestorePostCompleted ObjectRestorePostAll + ObjectTransitionAll + ObjectTransitionFailed + ObjectTransitionComplete ) // Expand - returns expanded values of abbreviated event type. @@ -94,6 +97,11 @@ func (name Name) Expand() []Name { ObjectRestorePostInitiated, ObjectRestorePostCompleted, } + case ObjectTransitionAll: + return []Name{ + ObjectTransitionFailed, + ObjectTransitionComplete, + } default: return []Name{name} } @@ -152,6 +160,12 @@ func (name Name) String() string { return "s3:ObjectRestore:Post" case ObjectRestorePostCompleted: return "s3:ObjectRestore:Completed" + case ObjectTransitionAll: + return "s3:ObjectTransition:*" + case ObjectTransitionFailed: + return "s3:ObjectTransition:Failed" + case ObjectTransitionComplete: + return "s3:ObjectTransition:Complete" } return "" @@ -254,7 +268,12 @@ func ParseName(s string) (Name, error) { return ObjectRestorePostInitiated, nil case "s3:ObjectRestore:Completed": return ObjectRestorePostCompleted, nil - + case "s3:ObjectTransition:Failed": + return ObjectTransitionFailed, nil + case "s3:ObjectTransition:Complete": + return ObjectTransitionComplete, nil + case "s3:ObjectTransition:*": + return ObjectTransitionAll, nil default: return 0, &ErrInvalidEventName{s} }