From e63b90d288fb4e5ce7f0aee078cd91f30bb3d565 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Thu, 2 Feb 2023 11:58:41 +0000 Subject: [PATCH] Merge pull request #11624 from overleaf/jpa-hybrid-download-params [web] add split tests for tweaking user content domain access check GitOrigin-RevId: a5e6959098c10ea230634492b465c2b9dcdd909f --- .../src/Features/Project/ProjectController.js | 22 +++++++++++++++++++ .../user-content-domain-access-check/index.ts | 15 ++++++++++--- services/web/frontend/js/ide.js | 1 - .../frontend/js/utils/isSplitTestEnabled.ts | 5 ----- .../web/frontend/js/utils/splitTestUtils.ts | 14 ++++++++++++ 5 files changed, 48 insertions(+), 9 deletions(-) delete mode 100644 services/web/frontend/js/utils/isSplitTestEnabled.ts create mode 100644 services/web/frontend/js/utils/splitTestUtils.ts diff --git a/services/web/app/src/Features/Project/ProjectController.js b/services/web/app/src/Features/Project/ProjectController.js index 2dbac215d1..380f2782f9 100644 --- a/services/web/app/src/Features/Project/ProjectController.js +++ b/services/web/app/src/Features/Project/ProjectController.js @@ -1081,6 +1081,28 @@ const ProjectController = { } ) }, + userContentDomainAccessCheckDelayAssigment(cb) { + SplitTestHandler.getAssignment( + req, + res, + 'user-content-domain-access-check-delay', + () => { + // We'll pick up the assignment from the res.locals assignment. + cb() + } + ) + }, + userContentDomainAccessCheckMaxChecksAssigment(cb) { + SplitTestHandler.getAssignment( + req, + res, + 'user-content-domain-access-check-max-checks', + () => { + // We'll pick up the assignment from the res.locals assignment. + cb() + } + ) + }, reportUserContentDomainAccessCheckErrorAssigment(cb) { SplitTestHandler.getAssignment( req, diff --git a/services/web/frontend/js/features/user-content-domain-access-check/index.ts b/services/web/frontend/js/features/user-content-domain-access-check/index.ts index d6fa5dd10c..c38920401d 100644 --- a/services/web/frontend/js/features/user-content-domain-access-check/index.ts +++ b/services/web/frontend/js/features/user-content-domain-access-check/index.ts @@ -8,10 +8,19 @@ import getMeta from '../../utils/meta' import OError from '@overleaf/o-error' import { captureException } from '../../infrastructure/error-reporter' import { postJSON } from '../../infrastructure/fetch-json' -import isSplitTestEnabled from '../../utils/isSplitTestEnabled' +import { + isSplitTestEnabled, + parseIntFromSplitTest, +} from '../../utils/splitTestUtils' -const MAX_CHECKS_PER_PAGE_LOAD = 3 -const INITIAL_DELAY_MS = 30_000 +const MAX_CHECKS_PER_PAGE_LOAD = parseIntFromSplitTest( + 'user-content-domain-access-check-max-checks', + 3 +) +const INITIAL_DELAY_MS = parseIntFromSplitTest( + 'user-content-domain-access-check-delay', + 30_000 +) const DELAY_BETWEEN_PROBES_MS = 1_000 const TIMEOUT_MS = 30_000 const FULL_SIZE = 739 diff --git a/services/web/frontend/js/ide.js b/services/web/frontend/js/ide.js index e8da4fe218..7dc9a4f798 100644 --- a/services/web/frontend/js/ide.js +++ b/services/web/frontend/js/ide.js @@ -70,7 +70,6 @@ import { cleanupServiceWorker } from './utils/service-worker-cleanup' import { reportCM6Perf } from './infrastructure/cm6-performance' import { reportAcePerf } from './ide/editor/ace-performance' import { scheduleUserContentDomainAccessCheck } from './features/user-content-domain-access-check' -import isSplitTestEnabled from './utils/isSplitTestEnabled' App.controller( 'IdeController', diff --git a/services/web/frontend/js/utils/isSplitTestEnabled.ts b/services/web/frontend/js/utils/isSplitTestEnabled.ts deleted file mode 100644 index 3776345db2..0000000000 --- a/services/web/frontend/js/utils/isSplitTestEnabled.ts +++ /dev/null @@ -1,5 +0,0 @@ -import getMeta from './meta' - -export default function isSplitTestEnabled(name: string) { - return getMeta('ol-splitTestVariants')?.[name] === 'enabled' -} diff --git a/services/web/frontend/js/utils/splitTestUtils.ts b/services/web/frontend/js/utils/splitTestUtils.ts new file mode 100644 index 0000000000..a31ac9db79 --- /dev/null +++ b/services/web/frontend/js/utils/splitTestUtils.ts @@ -0,0 +1,14 @@ +import getMeta from './meta' + +export function isSplitTestEnabled(name: string) { + return getMeta('ol-splitTestVariants')?.[name] === 'enabled' +} + +export function parseIntFromSplitTest(name: string, defaultValue: number) { + const v = getMeta('ol-splitTestVariants')?.[name] + const n = parseInt(v, 10) + if (v === 'default' || Number.isNaN(n)) { + return defaultValue + } + return n +}