From 716aa174fb51ff5b99fa4a5187a793b2126e5536 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Mon, 23 May 2022 16:12:55 +0100 Subject: [PATCH] Merge pull request #8070 from overleaf/jpa-web-zonal-traffic-test [web] add split test for rollout of zonal clsi-lb downloads GitOrigin-RevId: 67fb843ffb0c5902419a4e5c7d2ff9d35cf93470 --- .../src/Features/Compile/CompileController.js | 34 ++++++--- .../src/Compile/CompileControllerTests.js | 73 +++++++++++++++++-- 2 files changed, 89 insertions(+), 18 deletions(-) diff --git a/services/web/app/src/Features/Compile/CompileController.js b/services/web/app/src/Features/Compile/CompileController.js index 0e9d814361..7d3916a7a5 100644 --- a/services/web/app/src/Features/Compile/CompileController.js +++ b/services/web/app/src/Features/Compile/CompileController.js @@ -27,6 +27,7 @@ const ClsiCookieManager = require('./ClsiCookieManager')( Settings.apis.clsi != null ? Settings.apis.clsi.backendGroupName : undefined ) const Path = require('path') +const SplitTestHandler = require('../SplitTests/SplitTestHandler') const COMPILE_TIMEOUT_MS = 10 * 60 * 1000 @@ -93,16 +94,29 @@ module.exports = CompileController = { return next(error) } Metrics.inc('compile-status', 1, { status }) - res.json({ - status, - outputFiles, - compileGroup: limits != null ? limits.compileGroup : undefined, - clsiServerId, - validationProblems, - stats, - timings, - pdfDownloadDomain: Settings.pdfDownloadDomain, - }) + SplitTestHandler.getAssignment( + req, + res, + 'zonal-clsi-lb-downloads', + {}, + (_err, assignment) => { + if (assignment?.variant !== 'zonal') { + outputFiles.forEach(file => { + file.url = file.url.replace(/^\/zone\/\w/, '') + }) + } + res.json({ + status, + outputFiles, + compileGroup: limits != null ? limits.compileGroup : undefined, + clsiServerId, + validationProblems, + stats, + timings, + pdfDownloadDomain: Settings.pdfDownloadDomain, + }) + } + ) } ) }, diff --git a/services/web/test/unit/src/Compile/CompileControllerTests.js b/services/web/test/unit/src/Compile/CompileControllerTests.js index 2a30a58666..f69aead526 100644 --- a/services/web/test/unit/src/Compile/CompileControllerTests.js +++ b/services/web/test/unit/src/Compile/CompileControllerTests.js @@ -69,6 +69,11 @@ describe('CompileController', function () { '../Authentication/SessionManager': this.SessionManager, '../../infrastructure/RateLimiter': this.RateLimiter, './ClsiCookieManager': () => this.ClsiCookieManager, + '../SplitTests/SplitTestHandler': { + getAssignment: (this.getAssignment = sinon.stub().yields(null, { + variant: 'default', + })), + }, }, }) this.project_id = 'project-id' @@ -81,14 +86,66 @@ describe('CompileController', function () { beforeEach(function () { this.req.params = { Project_id: this.project_id } this.req.session = {} - return (this.CompileManager.compile = sinon - .stub() - .callsArgWith( - 3, - null, - (this.status = 'success'), - (this.outputFiles = ['mock-output-files']) - )) + return (this.CompileManager.compile = sinon.stub().callsArgWith( + 3, + null, + (this.status = 'success'), + (this.outputFiles = [ + { + path: 'output.pdf', + url: `/zone/b/project/${this.project_id}/user/${this.user_id}/build/id/output.pdf`, + type: 'pdf', + }, + ]) + )) + }) + + describe('zonal downloads', function () { + describe('when in the default split test variant', function () { + beforeEach(function () { + this.getAssignment.yields(null, { variant: 'default' }) + this.CompileController.compile(this.req, this.res, this.next) + }) + + it('should remove the zone prefix', function () { + this.res.statusCode.should.equal(200) + this.res.body.should.equal( + JSON.stringify({ + status: this.status, + outputFiles: [ + { + path: 'output.pdf', + url: `/project/${this.project_id}/user/${this.user_id}/build/id/output.pdf`, + type: 'pdf', + }, + ], + }) + ) + }) + }) + + describe('when in the zonal split test variant', function () { + beforeEach(function () { + this.getAssignment.yields(null, { variant: 'zonal' }) + this.CompileController.compile(this.req, this.res, this.next) + }) + + it('should keep the zone prefix', function () { + this.res.statusCode.should.equal(200) + this.res.body.should.equal( + JSON.stringify({ + status: this.status, + outputFiles: [ + { + path: 'output.pdf', + url: `/zone/b/project/${this.project_id}/user/${this.user_id}/build/id/output.pdf`, + type: 'pdf', + }, + ], + }) + ) + }) + }) }) describe('when not an auto compile', function () {