mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
improve logging for 2 compile backends
This commit is contained in:
parent
b5581c4d40
commit
e60157094b
3 changed files with 46 additions and 32 deletions
|
@ -8,7 +8,7 @@ ProjectEntityHandler = require("../Project/ProjectEntityHandler")
|
||||||
logger = require "logger-sharelatex"
|
logger = require "logger-sharelatex"
|
||||||
Url = require("url")
|
Url = require("url")
|
||||||
ClsiCookieManager = require("./ClsiCookieManager")()
|
ClsiCookieManager = require("./ClsiCookieManager")()
|
||||||
GoogleCloudClsiCookieManager = require("./ClsiCookieManager")("googlecloud")
|
NewBackendCloudClsiCookieManager = require("./ClsiCookieManager")("newBackendcloud")
|
||||||
ClsiStateManager = require("./ClsiStateManager")
|
ClsiStateManager = require("./ClsiStateManager")
|
||||||
_ = require("underscore")
|
_ = require("underscore")
|
||||||
async = require("async")
|
async = require("async")
|
||||||
|
@ -89,42 +89,56 @@ module.exports = ClsiManager =
|
||||||
callback(null, response?.compile?.status, outputFiles, clsiServerId)
|
callback(null, response?.compile?.status, outputFiles, clsiServerId)
|
||||||
|
|
||||||
_makeRequest: (project_id, opts, callback)->
|
_makeRequest: (project_id, opts, callback)->
|
||||||
ClsiManager._makeGoogleCloudRequest project_id, opts, ->
|
startTime = new Date()
|
||||||
ClsiCookieManager.getCookieJar project_id, (err, jar)->
|
async.series {
|
||||||
if err?
|
currentBackend: (cb)->
|
||||||
logger.err err:err, "error getting cookie jar for clsi request"
|
ClsiCookieManager.getCookieJar project_id, (err, jar)->
|
||||||
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)->
|
|
||||||
if err?
|
if err?
|
||||||
logger.warn err:err, project_id:project_id, "error setting server id"
|
logger.err err:err, "error getting cookie jar for clsi request"
|
||||||
return callback err, response, body
|
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()
|
return callback()
|
||||||
opts = _.clone(baseOpts)
|
opts = _.clone(baseOpts)
|
||||||
opts.url = opts.url.replace(Settings.apis.clsi.url, Settings.apis.clsigc?.url)
|
opts.url = opts.url.replace(Settings.apis.clsi.url, Settings.apis.clsi_new?.url)
|
||||||
GoogleCloudClsiCookieManager.getCookieJar project_id, (err, jar)->
|
NewBackendCloudClsiCookieManager.getCookieJar project_id, (err, jar)->
|
||||||
if err?
|
if err?
|
||||||
logger.err err:err, "error getting cookie jar for clsi request"
|
logger.err err:err, "error getting cookie jar for clsi request"
|
||||||
return callback(err)
|
return callback(err)
|
||||||
opts.jar = jar
|
opts.jar = jar
|
||||||
timer = new Metrics.Timer("compile.google")
|
timer = new Metrics.Timer("compile.newBackend")
|
||||||
request opts, (err, response, body)->
|
request opts, (err, response, body)->
|
||||||
timer.done()
|
timer.done()
|
||||||
if err?
|
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)
|
return callback(err)
|
||||||
GoogleCloudClsiCookieManager.setServerId project_id, response, (err)->
|
NewBackendCloudClsiCookieManager.setServerId project_id, response, (err)->
|
||||||
if 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
|
return callback err, response, body
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ Settings = require "settings-sharelatex"
|
||||||
AuthenticationController = require "../Authentication/AuthenticationController"
|
AuthenticationController = require "../Authentication/AuthenticationController"
|
||||||
UserGetter = require "../User/UserGetter"
|
UserGetter = require "../User/UserGetter"
|
||||||
RateLimiter = require("../../infrastructure/RateLimiter")
|
RateLimiter = require("../../infrastructure/RateLimiter")
|
||||||
ClsiCookieManager = require("./ClsiCookieManager")
|
ClsiCookieManager = require("./ClsiCookieManager")()
|
||||||
Path = require("path")
|
Path = require("path")
|
||||||
|
|
||||||
module.exports = CompileController =
|
module.exports = CompileController =
|
||||||
|
|
|
@ -560,22 +560,22 @@ describe "ClsiManager", ->
|
||||||
describe "_makeGoogleCloudRequest", ->
|
describe "_makeGoogleCloudRequest", ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@settings.apis.clsigc =
|
@settings.apis.clsi_new =
|
||||||
url : "https://compiles.googlecloud.test"
|
url : "https://compiles.somewhere.test"
|
||||||
@response = {there:"something"}
|
@response = {there:"something"}
|
||||||
@request.callsArgWith(1, null, @response)
|
@request.callsArgWith(1, null, @response)
|
||||||
@opts =
|
@opts =
|
||||||
url: @ClsiManager._getCompilerUrl(null, @project_id)
|
url: @ClsiManager._getCompilerUrl(null, @project_id)
|
||||||
|
|
||||||
it "should change the domain on the url", (done)->
|
it "should change the domain on the url", (done)->
|
||||||
@ClsiManager._makeGoogleCloudRequest @project_id, @opts, =>
|
@ClsiManager._makeNewBackendRequest @project_id, @opts, =>
|
||||||
args = @request.args[0]
|
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()
|
done()
|
||||||
|
|
||||||
it "should not make a request if there is not clsigc url", (done)->
|
it "should not make a request if there is not clsi_new url", (done)->
|
||||||
@settings.apis.clsigc = undefined
|
@settings.apis.clsi_new = undefined
|
||||||
@ClsiManager._makeGoogleCloudRequest @project_id, @opts, (err)=>
|
@ClsiManager._makeNewBackendRequest @project_id, @opts, (err)=>
|
||||||
expect(err).to.equal undefined
|
expect(err).to.equal undefined
|
||||||
@request.callCount.should.equal 0
|
@request.callCount.should.equal 0
|
||||||
done()
|
done()
|
||||||
|
|
Loading…
Reference in a new issue