Skip to content

Commit 22b872c

Browse files
Merge branch 'rb_segments_baseline' into rb_segments_splitschanges_updater
2 parents 9cec7a1 + a242745 commit 22b872c

File tree

8 files changed

+16
-14
lines changed

8 files changed

+16
-14
lines changed

src/evaluator/combiners/ifelseif.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function ifElseIfCombinerContext(log: ILogger, predicates: IEvaluator[]):
3535
return undefined;
3636
}
3737

38-
function ifElseIfCombiner(key: SplitIO.SplitKey, seed: number, trafficAllocation?: number, trafficAllocationSeed?: number, attributes?: SplitIO.Attributes, splitEvaluator?: ISplitEvaluator) {
38+
function ifElseIfCombiner(key: SplitIO.SplitKey, seed?: number, trafficAllocation?: number, trafficAllocationSeed?: number, attributes?: SplitIO.Attributes, splitEvaluator?: ISplitEvaluator) {
3939
// In Async environments we are going to have async predicates. There is none way to know
4040
// before hand so we need to evaluate all the predicates, verify for thenables, and finally,
4141
// define how to return the treatment (wrap result into a Promise or not).

src/evaluator/condition/engineUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { bucket } from '../../utils/murmur3/murmur3';
55
/**
66
* Get the treatment name given a key, a seed, and the percentage of each treatment.
77
*/
8-
export function getTreatment(log: ILogger, key: string, seed: number, treatments: { getTreatmentFor: (x: number) => string }) {
8+
export function getTreatment(log: ILogger, key: string, seed: number | undefined, treatments: { getTreatmentFor: (x: number) => string }) {
99
const _bucket = bucket(key, seed);
1010

1111
const treatment = treatments.getTreatmentFor(_bucket);

src/evaluator/condition/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import SplitIO from '../../../types/splitio';
77
import { ILogger } from '../../logger/types';
88

99
// Build Evaluation object if and only if matchingResult is true
10-
function match(log: ILogger, matchingResult: boolean, bucketingKey: string | undefined, seed: number, treatments: { getTreatmentFor: (x: number) => string }, label: string): IEvaluation | undefined {
10+
function match(log: ILogger, matchingResult: boolean, bucketingKey: string | undefined, seed: number | undefined, treatments: { getTreatmentFor: (x: number) => string }, label: string): IEvaluation | undefined {
1111
if (matchingResult) {
1212
const treatment = getTreatment(log, bucketingKey as string, seed, treatments);
1313

@@ -24,7 +24,7 @@ function match(log: ILogger, matchingResult: boolean, bucketingKey: string | und
2424
// Condition factory
2525
export function conditionContext(log: ILogger, matcherEvaluator: (...args: any) => MaybeThenable<boolean>, treatments: { getTreatmentFor: (x: number) => string }, label: string, conditionType: 'ROLLOUT' | 'WHITELIST'): IEvaluator {
2626

27-
return function conditionEvaluator(key: SplitIO.SplitKey, seed: number, trafficAllocation?: number, trafficAllocationSeed?: number, attributes?: SplitIO.Attributes, splitEvaluator?: ISplitEvaluator) {
27+
return function conditionEvaluator(key: SplitIO.SplitKey, seed?: number, trafficAllocation?: number, trafficAllocationSeed?: number, attributes?: SplitIO.Attributes, splitEvaluator?: ISplitEvaluator) {
2828

2929
// Whitelisting has more priority than traffic allocation, so we don't apply this filtering to those conditions.
3030
if (conditionType === 'ROLLOUT' && !shouldApplyRollout(trafficAllocation as number, (key as SplitIO.SplitKeyObject).bucketingKey as string, trafficAllocationSeed as number)) {

src/evaluator/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export function evaluateFeature(
4343
if (thenable(parsedSplit)) {
4444
return parsedSplit.then((split) => getEvaluation(
4545
log,
46-
split,
4746
key,
47+
split,
4848
attributes,
4949
storage,
5050
)).catch(
@@ -56,8 +56,8 @@ export function evaluateFeature(
5656

5757
return getEvaluation(
5858
log,
59-
parsedSplit,
6059
key,
60+
parsedSplit,
6161
attributes,
6262
storage,
6363
);
@@ -80,13 +80,13 @@ export function evaluateFeatures(
8080
}
8181

8282
return thenable(parsedSplits) ?
83-
parsedSplits.then(splits => getEvaluations(log, splitNames, splits, key, attributes, storage))
83+
parsedSplits.then(splits => getEvaluations(log, key, splitNames, splits, attributes, storage))
8484
.catch(() => {
8585
// Exception on async `getSplits` storage. For example, when the storage is redis or
8686
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
8787
return treatmentsException(splitNames);
8888
}) :
89-
getEvaluations(log, splitNames, parsedSplits, key, attributes, storage);
89+
getEvaluations(log, key, splitNames, parsedSplits, attributes, storage);
9090
}
9191

9292
export function evaluateFeaturesByFlagSets(
@@ -136,8 +136,8 @@ export function evaluateFeaturesByFlagSets(
136136

137137
function getEvaluation(
138138
log: ILogger,
139-
splitJSON: ISplit | null,
140139
key: SplitIO.SplitKey,
140+
splitJSON: ISplit | null,
141141
attributes: SplitIO.Attributes | undefined,
142142
storage: IStorageSync | IStorageAsync,
143143
): MaybeThenable<IEvaluationResult> {
@@ -172,9 +172,9 @@ function getEvaluation(
172172

173173
function getEvaluations(
174174
log: ILogger,
175+
key: SplitIO.SplitKey,
175176
splitNames: string[],
176177
splits: Record<string, ISplit | null>,
177-
key: SplitIO.SplitKey,
178178
attributes: SplitIO.Attributes | undefined,
179179
storage: IStorageSync | IStorageAsync,
180180
): MaybeThenable<Record<string, IEvaluationResult>> {
@@ -183,8 +183,8 @@ function getEvaluations(
183183
splitNames.forEach(splitName => {
184184
const evaluation = getEvaluation(
185185
log,
186-
splits[splitName],
187186
key,
187+
splits[splitName],
188188
attributes,
189189
storage
190190
);

src/evaluator/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import SplitIO from '../../types/splitio';
44
import { ILogger } from '../logger/types';
55

66
export interface IDependencyMatcherValue {
7-
key: SplitIO.SplitKey,
7+
key: SplitIO.SplitKeyObject,
88
attributes?: SplitIO.Attributes
99
}
1010

@@ -29,6 +29,6 @@ export type IEvaluationResult = IEvaluation & { treatment: string; impressionsDi
2929

3030
export type ISplitEvaluator = (log: ILogger, key: SplitIO.SplitKey, splitName: string, attributes: SplitIO.Attributes | undefined, storage: IStorageSync | IStorageAsync) => MaybeThenable<IEvaluation>
3131

32-
export type IEvaluator = (key: SplitIO.SplitKey, seed: number, trafficAllocation?: number, trafficAllocationSeed?: number, attributes?: SplitIO.Attributes, splitEvaluator?: ISplitEvaluator) => MaybeThenable<IEvaluation | undefined>
32+
export type IEvaluator = (key: SplitIO.SplitKey, seed?: number, trafficAllocation?: number, trafficAllocationSeed?: number, attributes?: SplitIO.Attributes, splitEvaluator?: ISplitEvaluator) => MaybeThenable<IEvaluation | undefined>
3333

3434
export type IMatcher = (...args: any) => MaybeThenable<boolean>

src/evaluator/value/sanitize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function sanitizeBoolean(val: any): boolean | undefined {
4141
return undefined;
4242
}
4343

44-
function dependencyProcessor(sanitizedValue: string, attributes?: SplitIO.Attributes): IDependencyMatcherValue {
44+
function dependencyProcessor(sanitizedValue: SplitIO.SplitKeyObject, attributes?: SplitIO.Attributes): IDependencyMatcherValue {
4545
return {
4646
key: sanitizedValue,
4747
attributes

src/storages/__tests__/RBSegmentsCacheAsync.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ describe.each([{ cache: cacheInRedis, wrapper: redisClient }, { cache: cachePlug
4949
test('contains should check for segment existence correctly', async () => {
5050
await cache.update([rbSegment, rbSegmentWithInSegmentMatcher], [], 1);
5151

52+
expect(await cache.contains(new Set())).toBe(true);
5253
expect(await cache.contains(new Set([rbSegment.name]))).toBe(true);
5354
expect(await cache.contains(new Set([rbSegment.name, rbSegmentWithInSegmentMatcher.name]))).toBe(true);
5455
expect(await cache.contains(new Set(['nonexistent']))).toBe(false);

src/storages/__tests__/RBSegmentsCacheSync.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ describe.each([cacheInMemory, cacheInLocal])('Rule-based segments cache sync (Me
5151
test('contains should check for segment existence correctly', () => {
5252
cache.update([rbSegment, rbSegmentWithInSegmentMatcher], [], 1);
5353

54+
expect(cache.contains(new Set())).toBe(true);
5455
expect(cache.contains(new Set([rbSegment.name]))).toBe(true);
5556
expect(cache.contains(new Set([rbSegment.name, rbSegmentWithInSegmentMatcher.name]))).toBe(true);
5657
expect(cache.contains(new Set(['nonexistent']))).toBe(false);

0 commit comments

Comments
 (0)