-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@tus/s3-store: add expiration extension #513
@tus/s3-store: add expiration extension #513
Conversation
a65aa51
to
48dee94
Compare
I've changed slightly the implementation, instead of relying on the Additionally, if we configure an expiration for the upload, we can safely set the expiration for |
1633870
to
96be736
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
I'm not sure this works currently as the store doesn't implement deleteExpired
:
tus-node-server/packages/server/src/server.ts
Lines 232 to 238 in 612ac24
cleanUpExpiredUploads(): Promise<number> { | |
if (!this.datastore.hasExtension('expiration')) { | |
throw ERRORS.UNSUPPORTED_EXPIRATION_EXTENSION | |
} | |
return this.datastore.deleteExpired() | |
} |
Your trick to let S3 do the work is neat but it incompatible with the API currently. Probably fine to do both, although it should be document well that running this particularly for the S3 store is not needed as it works automatically.
96be736
to
5e0c544
Compare
@Murderlon @Acconut Unfortunately the For this reason, I've made quite a few changes as follows:
With the following approach, the user can choose to create a lifecycle policy on S3 and filtering by Let me know how it feels now 👍 |
88421f7
to
dc5da78
Compare
I am 👍 for using S3 lifecycle configurations to support expiration. That is the most efficient way to implement and it scales well for huge buckets, although at the cost of a reduced granularity (expiration can only be configured in days, not hours or minutes). Could you please provide an example for the lifecycle configuration that is intended to be used with your implementation from this PR?
Why is it necessary to delete these manually? We can use the AbortIncompleteMultipartUpload rule (https://docs.aws.amazon.com/AmazonS3/latest/API/API_LifecycleRule.html#AmazonS3-Type-LifecycleRule-AbortIncompleteMultipartUpload) to remove the incomplete multipart uploads and then use "normal" expiration to clean up .info and .part files. |
Hi @Acconut The policy would be the following (pretty simple)
I think it's okay to reduce the granularity and delete assets every 24h from my perspective. |
I agree with you here, but I don't understand why we need the |
@Acconut as mentioned in #513 (review) that's the API we currently have. Not having that method would result in a crash. It's also possible to have a dummy method which does nothing, but why not keep the API consistent across stores for CRON jobs? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for this big effort! Testing locally with minio is pretty cool too.
I tried to add docs but I can't push to this PR. Here is a patch you can use with git apply 0001-Add-docs.path
Yes, I am suggesting to just have a dummy method without doing any manual labor. Then the S3 lifecycles can take care of of this automatically without any cron job needed. Maybe I am confused here. Is the cron implementation an alternative to using S3 lifecycles? Or do I need to run the cron implementation next to lifecycles in order to clean up all expired uploads (complete and incomplete)? |
To clarify, I think that we can say we support both! Even if i don't think it would cause any issue if the user has both lifecycle and cronjob but it doesn't really make sense :) |
Alright, I thought users were expected to use both methods. Thanks for clarifying this. However, the current cron implementation is not able to clean completed uploads, is it? I can imagine that this is also desired by some users. |
I clarified this in the docs git patch I shared above
According the spec:
So might be out of scope? |
The handling of completed uploads is not discussed much in the spec because that is mostly out of the scope of tus. That being said, tus servers often implement features that go beyond the content of the specification because those are needed to properly use and run tus severs, e.g. hooks for integrating with the main application. So deciding what is in scope or not is a blurry line :) I think people will be interested in removing completed uploads as well since this will trim the bucket and keep it from growing indefinitely. Of course, you can decide that this is not something you want to handle in tus-node-server. However, if I were to implement expiration in tusd, I will handle this case as well. |
It is not trivial to add per Object expiration (for successful uploads), the reason is that you have no other way than to iterate the whole bucket keys and compare the LastModified date in S3 with a date you set as the expiration. I believe we can add this functionality in another iteration if needed to not increase the scope of this current PR too much, |
I'm okay with keeping it only for unfinished uploads for now. We can revisit if the need arises. Regarding minio, I thought about it more and I think it's probably better to reuse the existing S3 credentials in CI and actually test against s3. This would make it consistent with the other tests, we avoid the addition of docker in the repository, and we can get rid of the mocking for What do you think? |
Yes agree, I will use S3 credentials |
dc5da78
to
8b50456
Compare
18c45b3
to
04f72d5
Compare
@Murderlon I've switched the tests to use the S3 bucket with the credentials provided as envs, I'm not sure if this was a one off thing or not, could you try to re-run the tests pls, i don't have the power to trigger a re-run. |
4bb22b1
to
c86b1da
Compare
@Murderlon right! I've modified the test slightly to make sure it tests the right thing even if there are unfinished uploads (probably caused by other tests) The test does the following:
|
fe968c5
to
e54178c
Compare
e54178c
to
c57acd5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Thanks!
Co-authored-by: Merlijn Vos <[email protected]>
I think is ready to be merged! 🎉 👍 |
Implements Expiration Extension for the S3 Store.
a new configuration is added on the S3Options to configure how long an upload URL will be valid for: