Skip to content

Commit

Permalink
feat: Add support for exclude from summaries. (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
kinyoklion authored Jul 28, 2023
1 parent 72c0f53 commit 36fef4f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class EventSummarizer {
private contextKinds: Record<string, Set<string>> = {};

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];
Expand Down
9 changes: 8 additions & 1 deletion packages/shared/common/src/internal/events/InputEvalEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default class InputEvalEvent {

public readonly version?: number;

public readonly excludeFromSummaries?: boolean;

constructor(
withReasons: boolean,
context: Context,
Expand All @@ -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;
Expand Down Expand Up @@ -66,5 +69,9 @@ export default class InputEvalEvent {
if (debugEventsUntilDate !== undefined) {
this.debugEventsUntilDate = debugEventsUntilDate;
}

if (excludeFromSummaries !== undefined) {
this.excludeFromSummaries = excludeFromSummaries;
}
}
}
2 changes: 2 additions & 0 deletions packages/shared/sdk-server/src/evaluation/data/Flag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ export interface Flag extends Versioned {
trackEvents?: boolean;
trackEventsFallthrough?: boolean;
debugEventsUntilDate?: number;
excludeFromSummaries?: boolean;
sampleWeight?: number;
}
3 changes: 2 additions & 1 deletion packages/shared/sdk-server/src/events/EventFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down

0 comments on commit 36fef4f

Please sign in to comment.