Skip to content

Commit d052fa1

Browse files
Refactors to simplify code and make whitelist rule more robust in case of null or undefined field
1 parent 6c85f3d commit d052fa1

File tree

8 files changed

+58
-62
lines changed

8 files changed

+58
-62
lines changed

src/dtos/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface IBetweenStringMatcherData {
2323
}
2424

2525
export interface IWhitelistMatcherData {
26-
whitelist: string[]
26+
whitelist?: string[] | null
2727
}
2828

2929
export interface IInSegmentMatcherData {

src/evaluator/__tests__/evaluate-feature.spec.ts

Lines changed: 24 additions & 23 deletions
Large diffs are not rendered by default.

src/evaluator/__tests__/evaluate-features.spec.ts

Lines changed: 26 additions & 27 deletions
Large diffs are not rendered by default.

src/evaluator/condition/engineUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ export function getTreatment(log: ILogger, key: string, seed: number | undefined
1818
/**
1919
* Evaluates the traffic allocation to see if we should apply rollout conditions or not.
2020
*/
21-
export function shouldApplyRollout(trafficAllocation: number, key: string, trafficAllocationSeed: number) {
21+
export function shouldApplyRollout(trafficAllocation: number, bucketingKey: string, trafficAllocationSeed: number) {
2222
// For rollout, if traffic allocation for splits is 100%, we don't need to filter it because everything should evaluate the rollout.
2323
if (trafficAllocation < 100) {
24-
const _bucket = bucket(key, trafficAllocationSeed);
24+
const _bucket = bucket(bucketingKey, trafficAllocationSeed);
2525

2626
if (_bucket > trafficAllocation) {
2727
return false;

src/evaluator/matchers/whitelist.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export function whitelistMatcherContext(ruleAttr: string[]) {
2-
const whitelistSet = new Set(ruleAttr);
1+
export function whitelistMatcherContext(ruleAttr?: string[] | null) {
2+
const whitelistSet = new Set(ruleAttr || []);
33

44
return function whitelistMatcher(runtimeAttr: string): boolean {
55
const isInWhitelist = whitelistSet.has(runtimeAttr);

src/logger/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export const ENGINE_DEFAULT = 41;
3232

3333
export const CLIENT_READY_FROM_CACHE = 100;
3434
export const CLIENT_READY = 101;
35-
export const IMPRESSION = 102;
3635
export const IMPRESSION_QUEUEING = 103;
3736
export const NEW_SHARED_CLIENT = 104;
3837
export const NEW_FACTORY = 105;

src/logger/messages/info.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ export const codesInfo: [number, string][] = codesWarn.concat([
88
[c.CLIENT_READY_FROM_CACHE, READY_MSG + ' from cache'],
99
[c.CLIENT_READY, READY_MSG],
1010
// SDK
11-
[c.IMPRESSION, c.LOG_PREFIX_IMPRESSIONS_TRACKER +'Feature flag: %s. Key: %s. Evaluation: %s. Label: %s'],
12-
[c.IMPRESSION_QUEUEING, c.LOG_PREFIX_IMPRESSIONS_TRACKER +'Queueing corresponding impression.'],
11+
[c.IMPRESSION_QUEUEING, c.LOG_PREFIX_IMPRESSIONS_TRACKER +'Queueing impression. Feature flag: %s. Key: %s. Evaluation: %s. Label: %s'],
1312
[c.NEW_SHARED_CLIENT, 'New shared client instance created.'],
1413
[c.NEW_FACTORY, 'New Split SDK instance created. %s'],
1514
[c.EVENTS_TRACKER_SUCCESS, c.LOG_PREFIX_EVENTS_TRACKER + 'Successfully queued %s'],

src/sdkClient/client.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { SDK_NOT_READY } from '../utils/labels';
77
import { CONTROL, TREATMENT, TREATMENTS, TREATMENT_WITH_CONFIG, TREATMENTS_WITH_CONFIG, TRACK, TREATMENTS_WITH_CONFIG_BY_FLAGSETS, TREATMENTS_BY_FLAGSETS, TREATMENTS_BY_FLAGSET, TREATMENTS_WITH_CONFIG_BY_FLAGSET, GET_TREATMENTS_WITH_CONFIG, GET_TREATMENTS_BY_FLAG_SETS, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, GET_TREATMENTS_BY_FLAG_SET, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, GET_TREATMENT_WITH_CONFIG, GET_TREATMENT, GET_TREATMENTS, TRACK_FN_LABEL } from '../utils/constants';
88
import { IEvaluationResult } from '../evaluator/types';
99
import SplitIO from '../../types/splitio';
10-
import { IMPRESSION, IMPRESSION_QUEUEING } from '../logger/constants';
10+
import { IMPRESSION_QUEUEING } from '../logger/constants';
1111
import { ISdkFactoryContext } from '../sdkFactory/types';
1212
import { isConsumerMode } from '../utils/settingsValidation/mode';
1313
import { Method } from '../sync/submitters/types';
@@ -153,10 +153,8 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
153153
config = fallbackTreatment.config;
154154
}
155155

156-
log.info(IMPRESSION, [featureFlagName, matchingKey, treatment, label]);
157-
158156
if (validateSplitExistence(log, readinessManager, featureFlagName, label, invokingMethodName)) {
159-
log.info(IMPRESSION_QUEUEING);
157+
log.info(IMPRESSION_QUEUEING, [featureFlagName, matchingKey, treatment, label]);
160158
queue.push({
161159
imp: {
162160
feature: featureFlagName,

0 commit comments

Comments
 (0)