From 36fef4ffc1ad8193c8fd0fe537e3dc7632eb2ac3 Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Fri, 28 Jul 2023 14:02:39 -0700 Subject: [PATCH] feat: Add support for exclude from summaries. (#216) --- .../internal/events/EventSummarizer.test.ts | 14 ++++++++++++++ packages/shared/common/package.json | 2 +- .../common/src/internal/events/EventSummarizer.ts | 2 +- .../common/src/internal/events/InputEvalEvent.ts | 9 ++++++++- .../shared/sdk-server/src/evaluation/data/Flag.ts | 2 ++ .../shared/sdk-server/src/events/EventFactory.ts | 3 ++- 6 files changed, 28 insertions(+), 4 deletions(-) diff --git a/packages/shared/common/__tests__/internal/events/EventSummarizer.test.ts b/packages/shared/common/__tests__/internal/events/EventSummarizer.test.ts index bb4bfa91d..1fd713a9f 100644 --- a/packages/shared/common/__tests__/internal/events/EventSummarizer.test.ts +++ b/packages/shared/common/__tests__/internal/events/EventSummarizer.test.ts @@ -25,6 +25,20 @@ describe('given an event summarizer', () => { expect(beforeSummary).toEqual(afterSummary); }); + it('does nothing for an event with excludeFromSummaries set to true', () => { + const event = { + kind: 'feature', + creationDate: 2000, + key: 'key', + context, + excludeFromSummaries: true, + }; + const beforeSummary = summarizer.getSummary(); + summarizer.summarizeEvent(event as any); + const afterSummary = summarizer.getSummary(); + expect(beforeSummary).toEqual(afterSummary); + }); + it('sets start and end dates for feature events', () => { const event1 = { kind: 'feature', diff --git a/packages/shared/common/package.json b/packages/shared/common/package.json index 9cf60215e..391719034 100644 --- a/packages/shared/common/package.json +++ b/packages/shared/common/package.json @@ -24,7 +24,7 @@ "build": "npx tsc", "clean": "npx tsc --build --clean", "lint": "npx eslint . --ext .ts", - "lint:fix": "yarn run lint -- --fix" + "lint:fix": "yarn run lint --fix" }, "license": "Apache-2.0", "devDependencies": { diff --git a/packages/shared/common/src/internal/events/EventSummarizer.ts b/packages/shared/common/src/internal/events/EventSummarizer.ts index 77ca7ce5e..9b15c7469 100644 --- a/packages/shared/common/src/internal/events/EventSummarizer.ts +++ b/packages/shared/common/src/internal/events/EventSummarizer.ts @@ -52,7 +52,7 @@ export default class EventSummarizer { private contextKinds: Record> = {}; summarizeEvent(event: InputEvent) { - if (isFeature(event)) { + if (isFeature(event) && !event.excludeFromSummaries) { const countKey = counterKey(event); const counter = this.counters[countKey]; let kinds = this.contextKinds[event.key]; diff --git a/packages/shared/common/src/internal/events/InputEvalEvent.ts b/packages/shared/common/src/internal/events/InputEvalEvent.ts index 9d9f19663..9f6ab07e4 100644 --- a/packages/shared/common/src/internal/events/InputEvalEvent.ts +++ b/packages/shared/common/src/internal/events/InputEvalEvent.ts @@ -24,6 +24,8 @@ export default class InputEvalEvent { public readonly version?: number; + public readonly excludeFromSummaries?: boolean; + constructor( withReasons: boolean, context: Context, @@ -35,7 +37,8 @@ export default class InputEvalEvent { trackEvents?: boolean, prereqOf?: string, reason?: LDEvaluationReason, - debugEventsUntilDate?: number + debugEventsUntilDate?: number, + excludeFromSummaries?: boolean ) { this.creationDate = Date.now(); this.context = context; @@ -66,5 +69,9 @@ export default class InputEvalEvent { if (debugEventsUntilDate !== undefined) { this.debugEventsUntilDate = debugEventsUntilDate; } + + if (excludeFromSummaries !== undefined) { + this.excludeFromSummaries = excludeFromSummaries; + } } } diff --git a/packages/shared/sdk-server/src/evaluation/data/Flag.ts b/packages/shared/sdk-server/src/evaluation/data/Flag.ts index 3dacc0dc7..73835c2ae 100644 --- a/packages/shared/sdk-server/src/evaluation/data/Flag.ts +++ b/packages/shared/sdk-server/src/evaluation/data/Flag.ts @@ -25,4 +25,6 @@ export interface Flag extends Versioned { trackEvents?: boolean; trackEventsFallthrough?: boolean; debugEventsUntilDate?: number; + excludeFromSummaries?: boolean; + sampleWeight?: number; } diff --git a/packages/shared/sdk-server/src/events/EventFactory.ts b/packages/shared/sdk-server/src/events/EventFactory.ts index 24d6fb729..e7f952442 100644 --- a/packages/shared/sdk-server/src/events/EventFactory.ts +++ b/packages/shared/sdk-server/src/events/EventFactory.ts @@ -28,7 +28,8 @@ export default class EventFactory { flag.trackEvents || addExperimentData, prereqOfFlag?.key, this.withReasons || addExperimentData ? detail.reason : undefined, - flag.debugEventsUntilDate + flag.debugEventsUntilDate, + flag.excludeFromSummaries ); }