Skip to content
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

feat: introduce ttl index #3172

Merged
merged 6 commits into from
Apr 10, 2023
Merged

Conversation

ainouzgali
Copy link
Contributor

What change does this PR introduce?

We want to introduce TTL to so that certain data is only kept for a certain a mount of time.

Why was this change needed?

Other information (Screenshots)

@linear
Copy link

linear bot commented Apr 10, 2023

NV-1871 Introduce a TTL index to large collections

Why? (Context)

We want to introduce TTL to so that certain data is only kept for a certain a mount of time.

Definition of Done

  • In-App Messages Feed - 6 months
  • All the rest - 30 days
  • Remove 1 year from activity feed page
  • Update docs

…tl-index-to-large

# Conflicts:
#	libs/dal/src/repositories/message/message.schema.ts
Copy link
Contributor

@scopsy scopsy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, added a few notes

@@ -255,6 +258,77 @@ describe(`Trigger event - ${eventTriggerPath} (POST)`, function () {
expect(email.channel).to.equal(ChannelTypeEnum.EMAIL);
});

it('should correctly set expiration date (TTL) for notification and messages', async function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would maybe split this to 3 test cases for each channel type it might be more easier to read. Wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I will add a new test suite for this on Thursday, to also check with overrides and scheduled delay and multiple delayed actions in one workflow @scopsy

},
schemaOptions
);

notificationSchema.index({ expireAt: 1 }, { expires: '48h' });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ainouzgali speaking with @Cliftonz it seems we only need to add the "Expires" path for self hosted right? the online archive with take care for it for us?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect it will not do any harm not to add the check. As the ttl deletion will only run 48 hours after the online archive. If its already deleted, then ttl won't run.
But I would like to make sure when we have the integration with the online archive, and I wouldn't mind adding it @Cliftonz @scopsy

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ainouzgali I do not think we should have both. Both act as a ttl and if the backlog of the archival process gets two log then we could lose data.
I think we should do something like the following:

if Novu_Managed && Enable_TTL 
    enable ttl index
else
    only create index on expireAt for online archive

This way users who want to keep everything can and users who dont can have them deleted after the standard amount of time.
We can make community issues to add configurations for the ttl for each entity we are supporting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we have two things here:

  1. managed should not have 'expire'(ttl) - only by archive
  2. self hosted should have enable_ttl field -> meaning they will have the option to either have our settings for the ttl or to not have it at all

Have I got that right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So basically for Managed Service:

messageSchema.index({ expireAt: 1 });

And for Self hosted:

messageSchema.index({ expireAt: 1 }, { expires: '48h' });

@ainouzgali ainouzgali added this pull request to the merge queue Apr 10, 2023
Merged via the queue into next with commit bfc48c3 Apr 10, 2023
11 checks passed
@ainouzgali ainouzgali deleted the nv-1871-introduce-a-ttl-index-to-large branch April 10, 2023 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants