improve logging for 2 compile backends

This commit is contained in:
Henry Oswald 2018-06-20 11:07:34 +01:00
parent b5581c4d40
commit e60157094b
3 changed files with 46 additions and 32 deletions

View file

@ -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,13 +89,15 @@ module.exports = ClsiManager =
callback(null, response?.compile?.status, outputFiles, clsiServerId)
_makeRequest: (project_id, opts, callback)->
ClsiManager._makeGoogleCloudRequest project_id, opts, ->
startTime = new Date()
async.series {
currentBackend: (cb)->
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")
timer = new Metrics.Timer("compile.currentBackend")
request opts, (err, response, body)->
timer.done()
if err?
@ -104,27 +106,39 @@ module.exports = ClsiManager =
ClsiCookieManager.setServerId project_id, response, (err)->
if err?
logger.warn err:err, project_id:project_id, "error setting server id"
return callback err, response, body
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

View file

@ -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 =

View file

@ -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()