Skip to content

[FSSDK-11132] make entity validation configurable in bucketer #1071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/core/bucketer/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ describe('excluding groups', () => {
experimentIdMap: configObj.experimentIdMap,
groupIdMap: configObj.groupIdMap,
logger: mockLogger,
validateEntity: true,
};

vi.spyOn(bucketValueGenerator, 'generateBucketValue')
Expand Down Expand Up @@ -127,6 +128,7 @@ describe('including groups: random', () => {
groupIdMap: configObj.groupIdMap,
logger: mockLogger,
userId: 'testUser',
validateEntity: true,
};
});

Expand Down Expand Up @@ -228,6 +230,7 @@ describe('including groups: overlapping', () => {
groupIdMap: configObj.groupIdMap,
logger: mockLogger,
userId: 'testUser',
validateEntity: true,
};
});

Expand Down Expand Up @@ -280,6 +283,7 @@ describe('bucket value falls into empty traffic allocation ranges', () => {
experimentIdMap: configObj.experimentIdMap,
groupIdMap: configObj.groupIdMap,
logger: mockLogger,
validateEntity: true,
};
});

Expand Down Expand Up @@ -329,6 +333,7 @@ describe('traffic allocation has invalid variation ids', () => {
experimentIdMap: configObj.experimentIdMap,
groupIdMap: configObj.groupIdMap,
logger: mockLogger,
validateEntity: true,
};
});

Expand Down Expand Up @@ -359,6 +364,7 @@ describe('testBucketWithBucketingId', () => {
variationIdMap: configObj.variationIdMap,
experimentIdMap: configObj.experimentIdMap,
groupIdMap: configObj.groupIdMap,
validateEntity: true,
};
});

Expand Down
7 changes: 7 additions & 0 deletions lib/core/bucketer/index.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ describe('lib/core/bucketer', function () {
experimentIdMap: configObj.experimentIdMap,
groupIdMap: configObj.groupIdMap,
logger: createdLogger,
validateEntity: true,
};
sinon
.stub(bucketValueGenerator, 'generateBucketValue')
Expand Down Expand Up @@ -115,6 +116,7 @@ describe('lib/core/bucketer', function () {
experimentIdMap: configObj.experimentIdMap,
groupIdMap: configObj.groupIdMap,
logger: createdLogger,
validateEntity: true,
};
bucketerStub = sinon.stub(bucketValueGenerator, 'generateBucketValue');
});
Expand All @@ -135,6 +137,7 @@ describe('lib/core/bucketer', function () {
groupIdMap: configObj.groupIdMap,
logger: createdLogger,
userId: 'testUser',
validateEntity: true,
};
});

Expand Down Expand Up @@ -225,6 +228,7 @@ describe('lib/core/bucketer', function () {
groupIdMap: configObj.groupIdMap,
logger: createdLogger,
userId: 'testUser',
validateEntity: true,
};
});

Expand Down Expand Up @@ -269,6 +273,7 @@ describe('lib/core/bucketer', function () {
experimentIdMap: configObj.experimentIdMap,
groupIdMap: configObj.groupIdMap,
logger: createdLogger,
validateEntity: true,
};
});

Expand Down Expand Up @@ -316,6 +321,7 @@ describe('lib/core/bucketer', function () {
experimentIdMap: configObj.experimentIdMap,
groupIdMap: configObj.groupIdMap,
logger: createdLogger,
validateEntity: true,
};
});

Expand Down Expand Up @@ -365,6 +371,7 @@ describe('lib/core/bucketer', function () {
experimentIdMap: configObj.experimentIdMap,
groupIdMap: configObj.groupIdMap,
logger: createdLogger,
validateEntity: true,
};
});

Expand Down
19 changes: 9 additions & 10 deletions lib/core/bucketer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,16 @@ export const bucket = function(bucketerParams: BucketerParams): DecisionResponse
]);

const entityId = _findBucket(bucketValue, bucketerParams.trafficAllocationConfig);
if (entityId !== null) {
if (!bucketerParams.variationIdMap[entityId]) {
if (entityId) {
bucketerParams.logger?.warn(INVALID_VARIATION_ID);
decideReasons.push([INVALID_VARIATION_ID]);
}
return {
result: null,
reasons: decideReasons,
};

if (bucketerParams.validateEntity && entityId !== null && !bucketerParams.variationIdMap[entityId]) {
if (entityId) {
bucketerParams.logger?.warn(INVALID_VARIATION_ID);
decideReasons.push([INVALID_VARIATION_ID]);
}
return {
result: null,
reasons: decideReasons,
};
}

return {
Expand Down
1 change: 1 addition & 0 deletions lib/core/decision_service/index.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ describe('lib/core/decision_service', function() {
experimentIdMap: configObj.experimentIdMap,
experimentKeyMap: configObj.experimentKeyMap,
groupIdMap: configObj.groupIdMap,
validateEntity: true,
};

assert.deepEqual(bucketerParams, expectedParams);
Expand Down
5 changes: 5 additions & 0 deletions lib/core/decision_service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,12 +594,16 @@ export class DecisionService {
bucketingId: string,
userId: string
): BucketerParams {
let validateEntity = true;

let trafficAllocationConfig: TrafficAllocation[] = getTrafficAllocation(configObj, experiment.id);
if (experiment.cmab) {
trafficAllocationConfig = [{
entityId: CMAB_DUMMY_ENTITY_ID,
endOfRange: experiment.cmab.trafficAllocation
}];

validateEntity = false;
}

return {
Expand All @@ -613,6 +617,7 @@ export class DecisionService {
trafficAllocationConfig,
userId,
variationIdMap: configObj.variationIdMap,
validateEntity,
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/shared_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export interface BucketerParams {
variationIdMap: { [id: string]: Variation };
logger?: LoggerFacade;
bucketingId: string;
validateEntity?: boolean;
}

export interface DecisionResponse<T> {
Expand Down
Loading