diff --git a/services/web/app/coffee/Features/Compile/ClsiManager.coffee b/services/web/app/coffee/Features/Compile/ClsiManager.coffee index 595d8fe33e..6591c989f9 100755 --- a/services/web/app/coffee/Features/Compile/ClsiManager.coffee +++ b/services/web/app/coffee/Features/Compile/ClsiManager.coffee @@ -8,7 +8,7 @@ ProjectEntityHandler = require("../Project/ProjectEntityHandler") logger = require "logger-sharelatex" Url = require("url") ClsiCookieManager = require("./ClsiCookieManager")() -GoogleCloudClsiCookieManager = require("./ClsiCookieManager")("googlecloud") +NewBackendCloudClsiCookieManager = require("./ClsiCookieManager")("newBackendcloud") ClsiStateManager = require("./ClsiStateManager") _ = require("underscore") async = require("async") @@ -89,42 +89,56 @@ module.exports = ClsiManager = callback(null, response?.compile?.status, outputFiles, clsiServerId) _makeRequest: (project_id, opts, callback)-> - ClsiManager._makeGoogleCloudRequest project_id, opts, -> - ClsiCookieManager.getCookieJar project_id, (err, jar)-> - if err? - logger.err err:err, "error getting cookie jar for clsi request" - return callback(err) - opts.jar = jar - timer = new Metrics.Timer("compile.linode") - request opts, (err, response, body)-> - timer.done() - if err? - logger.err err:err, project_id:project_id, url:opts?.url, "error making request to clsi" - return callback(err) - ClsiCookieManager.setServerId project_id, response, (err)-> + startTime = new Date() + async.series { + currentBackend: (cb)-> + ClsiCookieManager.getCookieJar project_id, (err, jar)-> if err? - logger.warn err:err, project_id:project_id, "error setting server id" - return callback err, response, body + logger.err err:err, "error getting cookie jar for clsi request" + return callback(err) + opts.jar = jar + timer = new Metrics.Timer("compile.currentBackend") + request opts, (err, response, body)-> + timer.done() + if err? + logger.err err:err, project_id:project_id, url:opts?.url, "error making request to clsi" + return callback(err) + ClsiCookieManager.setServerId project_id, response, (err)-> + if err? + logger.warn err:err, project_id:project_id, "error setting server id" + callback err, response, body #return as soon as the standard compile has returned + cb(err, {response:response, body:body, finishTime:new Date() - startTime }) + newBackend: (cb)-> + ClsiManager._makeNewBackendRequest project_id, opts, (err, response, body)-> + cb(err, {response:response, body:body, finishTime:new Date() - startTime}) + }, (err, results)-> + timeDifference = results.newBackend?.finishTime - results.currentBackend?.finishTime + statusCodeSame = results.newBackend?.response?.statusCode == results.currentBackend?.response?.statusCode + currentCompileTime = results.currentBackend?.finishTime + newBackendCompileTime = results.newBackend?.finishTime + logger.log {statusCodeSame, timeDifference, currentCompileTime, newBackendCompileTime}, "both clsi requests returned" - _makeGoogleCloudRequest: (project_id, baseOpts, callback)-> - if !Settings.apis.clsigc?.url? + + + _makeNewBackendRequest: (project_id, baseOpts, callback)-> + if !Settings.apis.clsi_new?.url? return callback() opts = _.clone(baseOpts) - opts.url = opts.url.replace(Settings.apis.clsi.url, Settings.apis.clsigc?.url) - GoogleCloudClsiCookieManager.getCookieJar project_id, (err, jar)-> + opts.url = opts.url.replace(Settings.apis.clsi.url, Settings.apis.clsi_new?.url) + NewBackendCloudClsiCookieManager.getCookieJar project_id, (err, jar)-> if err? logger.err err:err, "error getting cookie jar for clsi request" return callback(err) opts.jar = jar - timer = new Metrics.Timer("compile.google") + timer = new Metrics.Timer("compile.newBackend") request opts, (err, response, body)-> timer.done() if err? - logger.err err:err, project_id:project_id, url:opts?.url, "error making request to clsi" + logger.warn err:err, project_id:project_id, url:opts?.url, "error making request to new clsi" return callback(err) - GoogleCloudClsiCookieManager.setServerId project_id, response, (err)-> + NewBackendCloudClsiCookieManager.setServerId project_id, response, (err)-> if err? - logger.warn err:err, project_id:project_id, "error setting server id" + logger.warn err:err, project_id:project_id, "error setting server id new backend" return callback err, response, body diff --git a/services/web/app/coffee/Features/Compile/CompileController.coffee b/services/web/app/coffee/Features/Compile/CompileController.coffee index ee3e20fdc9..d79eb5d389 100755 --- a/services/web/app/coffee/Features/Compile/CompileController.coffee +++ b/services/web/app/coffee/Features/Compile/CompileController.coffee @@ -9,7 +9,7 @@ Settings = require "settings-sharelatex" AuthenticationController = require "../Authentication/AuthenticationController" UserGetter = require "../User/UserGetter" RateLimiter = require("../../infrastructure/RateLimiter") -ClsiCookieManager = require("./ClsiCookieManager") +ClsiCookieManager = require("./ClsiCookieManager")() Path = require("path") module.exports = CompileController = diff --git a/services/web/test/unit/coffee/Compile/ClsiManagerTests.coffee b/services/web/test/unit/coffee/Compile/ClsiManagerTests.coffee index c4f91d25b4..e7676337e4 100644 --- a/services/web/test/unit/coffee/Compile/ClsiManagerTests.coffee +++ b/services/web/test/unit/coffee/Compile/ClsiManagerTests.coffee @@ -560,22 +560,22 @@ describe "ClsiManager", -> describe "_makeGoogleCloudRequest", -> beforeEach -> - @settings.apis.clsigc = - url : "https://compiles.googlecloud.test" + @settings.apis.clsi_new = + url : "https://compiles.somewhere.test" @response = {there:"something"} @request.callsArgWith(1, null, @response) @opts = url: @ClsiManager._getCompilerUrl(null, @project_id) it "should change the domain on the url", (done)-> - @ClsiManager._makeGoogleCloudRequest @project_id, @opts, => + @ClsiManager._makeNewBackendRequest @project_id, @opts, => args = @request.args[0] - args[0].url.should.equal "https://compiles.googlecloud.test/project/#{@project_id}" + args[0].url.should.equal "https://compiles.somewhere.test/project/#{@project_id}" done() - it "should not make a request if there is not clsigc url", (done)-> - @settings.apis.clsigc = undefined - @ClsiManager._makeGoogleCloudRequest @project_id, @opts, (err)=> + it "should not make a request if there is not clsi_new url", (done)-> + @settings.apis.clsi_new = undefined + @ClsiManager._makeNewBackendRequest @project_id, @opts, (err)=> expect(err).to.equal undefined @request.callCount.should.equal 0 done()