Skip to content

[FSSDK-11513] limit number of events in the eventStore #1053

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

Merged
merged 2 commits into from
May 15, 2025

Conversation

raju-opti
Copy link
Contributor

Summary

  • saving failed events in the event store indefinitely might cause an app to consume too much storage space. This PR limits the number of events stored in the eventStore.

Test plan

  • added tests

Issues

  • FSSDK-11513

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR limits the number of events stored in the event store to prevent excessive storage use. Key changes include:

  • Adding a new log message (EVENT_STORE_FULL) for cases when the event store reaches capacity.
  • Implementing event count management via eventCountInStore and a dedicated storeEvent method with logic to skip storing events when the maximum is reached.
  • Updating tests to cover scenarios when the event store limit is met and when store saves fail.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
lib/message/log_message.ts Added new log message constant for full event store notification.
lib/event_processor/batch_event_processor.ts Introduced event store capacity logic (eventCountInStore, storeEvent) and replaced dispatchingEventIds with dispatchingEvents.
lib/event_processor/batch_event_processor.spec.ts Added tests covering event store limits and failure conditions.

this.eventStore?.remove(id);
events.forEach((event) => {
this.eventStore?.remove(event.id);
if (!event.notStored && this.eventCountInStore) {
Copy link
Preview

Copilot AI May 15, 2025

Choose a reason for hiding this comment

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

The check 'this.eventCountInStore' may fail when the count is 0 (since 0 is falsy), which could prevent the intended decrement. Consider replacing it with 'this.eventCountInStore !== undefined' to ensure the condition works correctly even when the count is 0.

Suggested change
if (!event.notStored && this.eventCountInStore) {
if (!event.notStored && this.eventCountInStore !== undefined) {

Copilot uses AI. Check for mistakes.

@@ -138,7 +146,8 @@ export class BatchEventProcessor extends BaseService implements EventProcessor {
(currentBatch.length > 0 && !areEventContextsEqual(currentBatch[0].event, event.event))) {
batches.push({
request: buildLogEvent(currentBatch.map((e) => e.event)),
ids: currentBatch.map((e) => e.id),
// ids: currentBatch.map((e) => e.id),
Copy link
Preview

Copilot AI May 15, 2025

Choose a reason for hiding this comment

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

[nitpick] If the 'ids' array is no longer needed after switching to 'events', please consider removing the commented code to improve code clarity.

Suggested change
// ids: currentBatch.map((e) => e.id),

Copilot uses AI. Check for mistakes.

@coveralls
Copy link

coveralls commented May 15, 2025

Coverage Status

coverage: 80.428% (-0.3%) from 80.685%
when pulling 67d0c18 on raju/event_store_limit
into 3c63d79 on master.

Copy link
Contributor

@junaed-optimizely junaed-optimizely left a comment

Choose a reason for hiding this comment

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

LGTM! Its a nice optimization!

@raju-opti raju-opti force-pushed the raju/event_store_limit branch from d3ea562 to 67d0c18 Compare May 15, 2025 17:46
@raju-opti raju-opti merged commit 4d2a4e1 into master May 15, 2025
10 of 16 checks passed
@raju-opti raju-opti deleted the raju/event_store_limit branch May 15, 2025 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants