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

#4205: mark potentially stale features #4217

Merged
merged 10 commits into from
Jul 13, 2023

Conversation

thomasheartman
Copy link
Contributor

@thomasheartman thomasheartman commented Jul 11, 2023

This PR lays most of the groundwork required for emitting events when features are marked as potentially stale by Unleash. It does not emit any events just yet. The summary is:

  • periodically look for features that are potentially stale and mark them (set to run every 10 seconds for now; can be changed)
  • when features are updated, if the update data contains changes to the feature's type or createdAt date, also update the potentially stale status.

It is currently about 220 lines of tests and about 100 lines of application code (primarily db migration and two new methods on the IFeatureToggleStore interface).

The reason I wanted to put this into a single PR (instead of just the db migration, then just the potentially stale marking, then the update logic) is:
If users get the db migration first, but not the rest of the update logic until the events are fired, then they could get a bunch of new events for features that should have been marked as potentially stale several days/weeks/months ago. That seemed undesirable to me, so I decided to bunch those changes together. Of course, I'd be happy to break it into smaller parts.

Rules

A toggle will be marked as potentially stale iff:

  • it is not already stale
  • its createdAt date is older than its feature type's expected lifetime would dictate

Migration

The migration adds a new potentially_stale column to the features
table and sets this to true for any toggles that have exceeded their
expected lifetime and that have not already been marked as stale.

Discussion

The currentTime parameter of markPotentiallyStaleFeatures

The markPotentiallyStaleFetaures method takes an optional currentTime parameter. This was added to make it easier to test (so you can test "into the future"), but it's not used in the application. We can rewrite the tests to instead update feature toggles manually, but that wouldn't test the actual marking method. Happy to discuss.

@vercel
Copy link

vercel bot commented Jul 11, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 13, 2023 8:26am
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 13, 2023 8:26am

The migration adds a new `potentially_stale` column to the features
table and sets this to true for any toggles that have exceeded their
expected lifetime and that have not already been marked as `stale`.
Copy link
Contributor

@sjaanus sjaanus left a comment

Choose a reason for hiding this comment

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

While the update is fine, it will be out of date already tomorrow. We need a scheduler to do it anyways, so question is if there is value of putting this out of date data with migration.

@thomasheartman thomasheartman changed the title #4205: add db migration for potentially stale features #4205: mark potentially stale features Jul 12, 2023
src/lib/services/index.ts Outdated Show resolved Hide resolved
currentTime?: string,
): Promise<string[]> {
const query = this.db(TABLE)
.update('potentially_stale', true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also unmark them if configuration changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That should be handled in the update method, I think. Do you disagree?

Copy link
Contributor

@sjaanus sjaanus left a comment

Choose a reason for hiding this comment

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

LG

@thomasheartman thomasheartman enabled auto-merge (squash) July 13, 2023 11:56
@thomasheartman thomasheartman merged commit 85bd784 into main Jul 13, 2023
15 of 17 checks passed
@thomasheartman thomasheartman deleted the #4205/potentially-stale-events-db-migration branch July 13, 2023 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants