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

View file

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

View file

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

View file

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

View file

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