Skip to content

Commit 8bc8abc

Browse files
committed
feedback from PR
1 parent 74bcc0f commit 8bc8abc

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

src/cache/abstract-assignment-cache.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,28 @@ import { getMD5Hash } from '../obfuscation';
22

33
import { LRUCache } from './lru-cache';
44

5-
type FlagAssignmentCacheValue = {
6-
allocationKey: string;
7-
variationKey: string;
8-
};
9-
10-
type BanditAssignmentCacheValue = {
11-
banditKey: string;
12-
actionKey: string;
13-
};
14-
15-
export type AssignmentCacheValue = FlagAssignmentCacheValue | BanditAssignmentCacheValue;
16-
5+
/**
6+
* Assignment cache keys are only on the subject and flag level, while the entire value is used
7+
* for uniqueness checking. This way that if an assigned variation or bandit action changes for a
8+
* flag, it evicts the old one. Then, if an older assignment is later reassigned, it will be treated
9+
* as new.
10+
*/
1711
export type AssignmentCacheKey = {
1812
subjectKey: string;
1913
flagKey: string;
2014
};
2115

16+
export type AssignmentCacheValue = Record<string, string>;
17+
2218
export type AssignmentCacheEntry = AssignmentCacheKey & AssignmentCacheValue;
2319

2420
/** Converts an {@link AssignmentCacheKey} to a string. */
2521
export function assignmentCacheKeyToString({ subjectKey, flagKey }: AssignmentCacheKey): string {
2622
return getMD5Hash([subjectKey, flagKey].join(';'));
2723
}
2824

29-
export function assignmentCacheValueToString(cacheValue: Record<string, string>): string {
25+
/** Converts an {@link AssignmentCacheValue} to a string. */
26+
export function assignmentCacheValueToString(cacheValue: AssignmentCacheValue): string {
3027
return getMD5Hash(Object.values(cacheValue).join(';'));
3128
}
3229

src/client/eppo-client.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -652,16 +652,12 @@ export default class EppoClient {
652652
}
653653

654654
private logBanditAction(banditEvent: IBanditEvent): void {
655+
// First we check if this bandit action has been logged before
655656
const subjectKey = banditEvent.subject;
656657
const flagKey = banditEvent.featureFlag;
657658
const banditKey = banditEvent.bandit;
658659
const actionKey = banditEvent.action ?? '__eppo_no_action';
659660

660-
// What our bandit assignment cache cares about for avoiding logging duplicate bandit assignments,
661-
// if one is active. Like the flag assignment cache, entries are only stored for a given flag
662-
// and subject. However, Bandit and action keys are also used for determining assignment uniqueness.
663-
// This means that if a flag's bandit assigns one action, and then later a new action, the first
664-
// one will be evicted from the cache. If later assigned again, it will be treated as new.
665661
const banditAssignmentCacheProperties = {
666662
flagKey,
667663
subjectKey,
@@ -674,13 +670,15 @@ export default class EppoClient {
674670
return;
675671
}
676672

673+
// If no logger defined, queue up the events (up to a max) to flush if a logger is later defined
677674
if (!this.banditLogger) {
678675
// No bandit logger set; enqueue the event in case a logger is later set
679676
if (this.queuedBanditEvents.length < MAX_EVENT_QUEUE_SIZE) {
680677
this.queuedBanditEvents.push(banditEvent);
681678
}
682679
return;
683680
}
681+
684682
// If here, we have a logger and a new assignment to be logged
685683
try {
686684
this.banditLogger.logBanditAction(banditEvent);

0 commit comments

Comments
 (0)