Skip to content
Draft
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
25 changes: 24 additions & 1 deletion ab-testing/config/abTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ const ABTests: ABTest[] = [
groups: ["a", "b"],
shouldForceMetricsCollection: false,
},

{
name: "commercial-prebid-failsafe-timeout",
description:
Expand All @@ -223,6 +222,30 @@ const ABTests: ABTest[] = [
groups: ["control", "variant"],
shouldForceMetricsCollection: true,
},
{
name: "webx-test-test",
description: "Test for webx test",
owners: ["dotcom.platform@theguardian.com"],
status: "ON",
expirationDate: "2026-08-31",
type: "client",
audienceSize: 10 / 100,
audienceSpace: "D",
groups: ["control", "variant"],
shouldForceMetricsCollection: false,
},
{
name: "webx-test-test-2",
description: "Test for webx test",
owners: ["dotcom.platform@theguardian.com"],
status: "ON",
expirationDate: "2026-08-31",
type: "client",
audienceSize: 50 / 100,
audienceSpace: "E",
groups: ["control", "variant"],
shouldForceMetricsCollection: false,
},
];

const activeABtests = ABTests.filter((test) => test.status === "ON");
Expand Down
4 changes: 2 additions & 2 deletions ab-testing/config/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type FastlyTestParams = { name: string; type: string; exp: number };
type AudienceSpace = Map<string, FastlyTestParams>;

type AllSpace = Map<string, FastlyTestParams[]>;
type AllSpaces = Map<string, FastlyTestParams[]>;

export type { FastlyTestParams, AudienceSpace, AllSpace };
export type { FastlyTestParams, AudienceSpace, AllSpaces as AllSpace };
19 changes: 14 additions & 5 deletions ab-testing/config/scripts/build/calculate-mvt-updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const calculateAllSpaceUpdates = (
mvtGroups: AllSpace,
tests: ABTest[],
): AllSpace => {
const updatedTestSpace: AudienceSpace[] = AudienceSpaces.map((space, i) => {
const updatedTestSpaces: AudienceSpace[] = AudienceSpaces.map((space) => {
console.log(`Calculating updates for space: ${space}`);
const spaceTests = tests.filter(
(test) => (test.audienceSpace ?? "A") === space, // 'A' is the default space
Expand All @@ -116,15 +116,24 @@ const calculateAllSpaceUpdates = (
}

const spaceMVTGroups = new Map(
mvtGroups
.entries()
.map(([key, value]) => [key, value[i] as FastlyTestParams]),
Array.from(mvtGroups.entries())
.map(([mvtId, tests]) => [
mvtId,
spaceTests.find((test) =>
tests.find(
(t) => t.name === test.name && t.type === test.type,
),
),
])
.filter(([, test]) => test !== undefined) as Array<
[string, FastlyTestParams]
>,
);

return calculateSpaceUpdates(spaceMVTGroups, spaceTests);
});

return updatedTestSpace.reduce((acc, curr) => {
return updatedTestSpaces.reduce((acc, curr) => {
curr.forEach((value, key) => {
if (!acc.has(key)) {
acc.set(key, []);
Expand Down
21 changes: 12 additions & 9 deletions ab-testing/config/scripts/build/test-group-mvt-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ class TestGroupMVTManager {
Array.from(this.testGroups.values()).flat(),
);

/**
* collect all available MVTs that are not currently occupied in a random order
* so that new test mvts are assigned randomly.
*/
this.availableMVTs = Array.from({ length: MVT_COUNT }, (_, i) => i)
.filter((i) => !this.occupiedMVTs.has(i))
.sort((a, b) => a - b);
.sort(() => Math.random() - 0.5);

console.log(
`Initialized TestGroupMVTs with ${this.availableMVTs.length} available MVTs`,
Expand Down Expand Up @@ -109,11 +113,14 @@ class TestGroupMVTManager {
throw new Error(`Not enough available MVTs for test ${name}`);
}
for (let i = 0; i < additionalMVTsNeeded; i++) {
const mvtIndex = this.availableMVTs.shift();
if (mvtIndex !== undefined) {
currentMVTs.push(mvtIndex);
this.occupiedMVTs.add(mvtIndex);
const mvtId = this.availableMVTs.shift();
if (mvtId === undefined) {
throw new Error(
`No available MVTs left to expand test ${name}`,
);
}
currentMVTs.push(mvtId);
this.occupiedMVTs.add(mvtId);
}
} else if (newSize < currentSize) {
const removedMVTs = currentMVTs.slice(newSize);
Expand All @@ -122,8 +129,6 @@ class TestGroupMVTManager {
this.availableMVTs.push(mvt);
});
currentMVTs.length = newSize;
// Keep available MVTs sorted in ascending order
this.availableMVTs.sort((a, b) => a - b);
}
this.testGroups.set(name, currentMVTs);
}
Expand All @@ -140,8 +145,6 @@ class TestGroupMVTManager {
this.availableMVTs.push(mvt);
});
this.testGroups.delete(name);
// Keep available MVTs sorted in ascending order
this.availableMVTs.sort((a, b) => a - b);
}
}
}
Expand Down
Loading