mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
85bd7845b0
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. |
||
---|---|---|
.. | ||
__snapshots__ | ||
addons | ||
db | ||
domain/project-health | ||
error | ||
features | ||
middleware | ||
openapi | ||
proxy | ||
routes | ||
schema | ||
segments | ||
services | ||
types | ||
util | ||
app.test.ts | ||
app.ts | ||
create-config.test.ts | ||
create-config.ts | ||
default-custom-auth-deny-all.ts | ||
internals.ts | ||
logger.test.ts | ||
logger.ts | ||
metric-events.ts | ||
metrics.test.ts | ||
metrics.ts | ||
server-impl.test.ts | ||
server-impl.ts |