Merge pull request #11940 from overleaf/jpa-fix-assignment-of-initial-clsi-vm

[web] fix assignment of initial compile server

GitOrigin-RevId: 84aea918946a106a5826d7cf39cc0bf47047cb35
This commit is contained in:
Jakob Ackermann 2023-03-06 10:21:38 +00:00 committed by Copybot
parent 38973fb971
commit e0c84f08fb
5 changed files with 112 additions and 14 deletions

View file

@ -39,7 +39,13 @@ module.exports = function (backendGroup) {
}
},
_getServerId(project_id, user_id, compileGroup, callback) {
_getServerId(
project_id,
user_id,
compileGroup,
compileBackendClass,
callback
) {
if (callback == null) {
callback = function () {}
}
@ -54,6 +60,7 @@ module.exports = function (backendGroup) {
project_id,
user_id,
compileGroup,
compileBackendClass,
callback
)
} else {
@ -63,14 +70,23 @@ module.exports = function (backendGroup) {
)
},
_populateServerIdViaRequest(project_id, user_id, compileGroup, callback) {
_populateServerIdViaRequest(
project_id,
user_id,
compileGroup,
compileBackendClass,
callback
) {
if (callback == null) {
callback = function () {}
}
const u = new URL(
`${Settings.apis.clsi.url}/project/${project_id}/status`
)
u.search = new URLSearchParams({ compileGroup }).toString()
u.search = new URLSearchParams({
compileGroup,
compileBackendClass,
}).toString()
request.post(u.href, (err, res, body) => {
if (err != null) {
OError.tag(err, 'error getting initial server id for project', {
@ -82,6 +98,7 @@ module.exports = function (backendGroup) {
project_id,
user_id,
compileGroup,
compileBackendClass,
res,
null,
function (err, serverId) {
@ -106,11 +123,11 @@ module.exports = function (backendGroup) {
return cookies != null ? cookies[Settings.clsiCookie.key] : undefined
},
checkIsLoadSheddingEvent(clsiserverid, compileGroup) {
checkIsLoadSheddingEvent(clsiserverid, compileGroup, compileBackendClass) {
request.get(
{
url: `${Settings.apis.clsi.url}/instance-state`,
qs: { clsiserverid, compileGroup },
qs: { clsiserverid, compileGroup, compileBackendClass },
},
(err, res, body) => {
if (err) {
@ -139,6 +156,7 @@ module.exports = function (backendGroup) {
project_id,
user_id,
compileGroup,
compileBackendClass,
response,
previous,
callback
@ -162,7 +180,11 @@ module.exports = function (backendGroup) {
// Initial assignment of a user+project or after clearing cache.
Metrics.inc('clsi-lb-assign-initial-backend')
} else {
this.checkIsLoadSheddingEvent(previous, compileGroup)
this.checkIsLoadSheddingEvent(
previous,
compileGroup,
compileBackendClass
)
}
if (rclient_secondary != null) {
this._setServerIdInRedis(
@ -200,7 +222,13 @@ module.exports = function (backendGroup) {
return rclient.del(this.buildKey(project_id, user_id), callback)
},
getCookieJar(project_id, user_id, compileGroup, callback) {
getCookieJar(
project_id,
user_id,
compileGroup,
compileBackendClass,
callback
) {
if (callback == null) {
callback = function () {}
}
@ -211,6 +239,7 @@ module.exports = function (backendGroup) {
project_id,
user_id,
compileGroup,
compileBackendClass,
(err, serverId) => {
if (err != null) {
OError.tag(err, 'error getting server id', {

View file

@ -134,7 +134,14 @@ const ClsiManager = {
url: compilerUrl,
method: 'POST',
}
ClsiManager._makeRequest(projectId, userId, compileGroup, opts, callback)
ClsiManager._makeRequest(
projectId,
userId,
compileGroup,
compileBackendClass,
opts,
callback
)
},
deleteAuxFiles(projectId, userId, options, clsiserverid, callback) {
@ -156,6 +163,7 @@ const ClsiManager = {
projectId,
userId,
compileGroup,
compileBackendClass,
opts,
clsiserverid,
clsiErr => {
@ -283,13 +291,17 @@ const ClsiManager = {
projectId,
userId,
compileGroup,
compileBackendClass,
opts,
clsiserverid,
callback
) {
if (clsiserverid) {
// ignore cookies and newBackend, go straight to the clsi node
opts.qs = Object.assign({ compileGroup, clsiserverid }, opts.qs)
opts.qs = Object.assign(
{ compileGroup, compileBackendClass, clsiserverid },
opts.qs
)
request(opts, (err, response, body) => {
if (err) {
return callback(
@ -299,11 +311,25 @@ const ClsiManager = {
callback(null, response, body)
})
} else {
ClsiManager._makeRequest(projectId, userId, compileGroup, opts, callback)
ClsiManager._makeRequest(
projectId,
userId,
compileGroup,
compileBackendClass,
opts,
callback
)
}
},
_makeRequest(projectId, userId, compileGroup, opts, callback) {
_makeRequest(
projectId,
userId,
compileGroup,
compileBackendClass,
opts,
callback
) {
async.series(
{
currentBackend(cb) {
@ -312,6 +338,7 @@ const ClsiManager = {
projectId,
userId,
compileGroup,
compileBackendClass,
(err, jar, clsiServerId) => {
if (err != null) {
return callback(
@ -338,6 +365,7 @@ const ClsiManager = {
projectId,
userId,
compileGroup,
compileBackendClass,
response,
clsiServerId,
(err, newClsiServerId) => {
@ -373,6 +401,7 @@ const ClsiManager = {
projectId,
userId,
compileGroup,
compileBackendClass,
opts,
(err, response, body) => {
if (err != null) {
@ -419,7 +448,14 @@ const ClsiManager = {
)
},
_makeNewBackendRequest(projectId, userId, compileGroup, baseOpts, callback) {
_makeNewBackendRequest(
projectId,
userId,
compileGroup,
compileBackendClass,
baseOpts,
callback
) {
if (Settings.apis.clsi_new == null || Settings.apis.clsi_new.url == null) {
return callback()
}
@ -434,6 +470,7 @@ const ClsiManager = {
projectId,
userId,
compileGroup,
compileBackendClass,
(err, jar, clsiServerId) => {
if (err != null) {
return callback(
@ -458,6 +495,7 @@ const ClsiManager = {
projectId,
userId,
compileGroup,
compileBackendClass,
response,
clsiServerId,
err => {
@ -521,6 +559,7 @@ const ClsiManager = {
projectId,
userId,
compileGroup,
compileBackendClass,
opts,
(err, response, body, clsiServerId) => {
if (err != null) {
@ -938,6 +977,7 @@ const ClsiManager = {
projectId,
userId,
compileGroup,
compileBackendClass,
opts,
clsiserverid,
(err, response, body) => {

View file

@ -644,6 +644,7 @@ function _getPersistenceOptions(
projectId,
userId,
compileGroup,
compileBackendClass,
(err, jar) => {
callback(err, { jar, qs: { compileGroup, compileBackendClass } })
}

View file

@ -69,6 +69,7 @@ describe('ClsiCookieManager', function () {
this.project_id,
this.user_id,
'',
'e2',
(err, serverId) => {
this.redis.get
.calledWith(`clsiserver:${this.project_id}:${this.user_id}`)
@ -106,6 +107,7 @@ describe('ClsiCookieManager', function () {
this.project_id,
this.user_id,
'',
'e2',
(err, serverId) => {
this.ClsiCookieManager._populateServerIdViaRequest
.calledWith(this.project_id, this.user_id)
@ -130,12 +132,14 @@ describe('ClsiCookieManager', function () {
this.project_id,
this.user_id,
'standard',
'e2',
(err, serverId) => {
const args = this.ClsiCookieManager.setServerId.args[0]
args[0].should.equal(this.project_id)
args[1].should.equal(this.user_id)
args[2].should.equal('standard')
args[3].should.deep.equal(this.response)
args[3].should.equal('e2')
args[4].should.deep.equal(this.response)
return done()
}
)
@ -146,6 +150,7 @@ describe('ClsiCookieManager', function () {
this.project_id,
this.user_id,
'',
'e2',
(err, serverId) => {
serverId.should.equal('clsi-9')
return done()
@ -167,6 +172,7 @@ describe('ClsiCookieManager', function () {
this.project_id,
this.user_id,
'standard',
'e2',
this.response,
null,
err => {
@ -190,6 +196,7 @@ describe('ClsiCookieManager', function () {
this.project_id,
this.user_id,
'standard',
'e2',
this.response,
null,
err => {
@ -208,6 +215,7 @@ describe('ClsiCookieManager', function () {
this.project_id,
this.user_id,
'standard',
'e2',
this.response,
null,
(err, serverId) => {
@ -229,6 +237,7 @@ describe('ClsiCookieManager', function () {
this.project_id,
this.user_id,
'standard',
'e2',
this.response,
null,
(err, serverId) => {
@ -246,6 +255,7 @@ describe('ClsiCookieManager', function () {
this.project_id,
this.user_id,
'standard',
'e2',
this.response,
null,
(err, serverId) => {
@ -276,6 +286,7 @@ describe('ClsiCookieManager', function () {
this.project_id,
this.user_id,
'standard',
'e2',
this.response,
null,
(err, serverId) => {
@ -304,6 +315,7 @@ describe('ClsiCookieManager', function () {
this.project_id,
this.user_id,
'',
'e2',
(err, jar) => {
jar._jar.store.idx['clsi.example.com']['/'][
this.settings.clsiCookie.key
@ -328,6 +340,7 @@ describe('ClsiCookieManager', function () {
this.project_id,
this.user_id,
'',
'e2',
(err, jar) => {
assert.deepEqual(jar, realRequst.jar())
return done()

View file

@ -514,6 +514,7 @@ describe('ClsiManager', function () {
this.project_id,
this.user_id,
'standard',
'e2',
{
method: 'DELETE',
url: `${this.settings.apis.clsi.url}/project/${this.project_id}/user/${this.user_id}?compileBackendClass=e2&compileGroup=standard`,
@ -965,7 +966,7 @@ describe('ClsiManager', function () {
it('should send the request to the CLSI', function () {
const url = `${this.settings.apis.clsi.url}/project/${this.project_id}/user/${this.user_id}/compile?compileBackendClass=e2&compileGroup=standard`
this.ClsiManager._makeRequest
.calledWith(this.project_id, this.user_id, 'standard', {
.calledWith(this.project_id, this.user_id, 'standard', 'e2', {
method: 'POST',
url,
json: this.req,
@ -1030,6 +1031,7 @@ describe('ClsiManager', function () {
this.project_id,
this.user_id,
'standard',
'e2',
{
method: 'GET',
url: `http://clsi.example.com/project/${this.project_id}/user/${this.user_id}/wordcount?compileBackendClass=e2&compileGroup=standard`,
@ -1067,6 +1069,7 @@ describe('ClsiManager', function () {
this.project_id,
this.user_id,
'standard',
'e2',
{
method: 'GET',
url: `http://clsi.example.com/project/${this.project_id}/user/${this.user_id}/wordcount?compileBackendClass=e2&compileGroup=standard`,
@ -1099,6 +1102,7 @@ describe('ClsiManager', function () {
this.project_id,
this.user_id,
'standard',
'e2',
{
method: 'GET',
url: `http://clsi.example.com/project/${this.project_id}/user/${this.user_id}/wordcount?compileBackendClass=e2&compileGroup=standard`,
@ -1127,6 +1131,7 @@ describe('ClsiManager', function () {
this.project_id,
this.user_id,
'standard',
'e2',
this.opts,
() => {
const args = this.request.args[0]
@ -1143,6 +1148,7 @@ describe('ClsiManager', function () {
this.project_id,
this.user_id,
'standard',
'e2',
this.opts,
() => {
this.ClsiCookieManager.setServerId
@ -1150,6 +1156,7 @@ describe('ClsiManager', function () {
this.project_id,
this.user_id,
'standard',
'e2',
this.response
)
.should.equal(true)
@ -1175,6 +1182,7 @@ describe('ClsiManager', function () {
this.project_id,
this.user_id,
'standard',
'e2',
this.opts,
undefined,
err => {
@ -1194,6 +1202,7 @@ describe('ClsiManager', function () {
this.project_id,
this.user_id,
'standard',
'e2',
this.opts,
undefined,
err => {
@ -1203,6 +1212,7 @@ describe('ClsiManager', function () {
this.project_id,
this.user_id,
'standard',
'e2',
this.response
)
.should.equal(true)
@ -1218,6 +1228,7 @@ describe('ClsiManager', function () {
this.project_id,
this.user_id,
'standard',
'e2',
this.opts,
'node-1',
err => {
@ -1229,6 +1240,7 @@ describe('ClsiManager', function () {
expect(requestOpts.qs).to.deep.equal({
clsiserverid: 'node-1',
compileGroup: 'standard',
compileBackendClass: 'e2',
})
done()
}
@ -1240,6 +1252,7 @@ describe('ClsiManager', function () {
this.project_id,
this.user_id,
'standard',
'e2',
this.opts,
'node-1',
err => {
@ -1271,6 +1284,7 @@ describe('ClsiManager', function () {
this.project_id,
this.user_id,
'standard',
'e2',
this.opts,
() => {
const args = this.request.args[0]
@ -1288,6 +1302,7 @@ describe('ClsiManager', function () {
this.project_id,
this.user_id,
'standard',
'e2',
this.opts,
err => {
expect(err).to.equal(undefined)