mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #4922 from overleaf/jpa-web-clsi-metrics
[web] add new metrics for tracking initial assign/switch of clsi backend GitOrigin-RevId: 4fb15ee8727cb397d1e44a86efb7d4833626bc6b
This commit is contained in:
parent
46780e5144
commit
1094b0570b
4 changed files with 32 additions and 12 deletions
|
@ -22,6 +22,7 @@ if (Settings.redis.clsi_cookie_secondary != null) {
|
|||
}
|
||||
const Cookie = require('cookie')
|
||||
const logger = require('logger-sharelatex')
|
||||
const Metrics = require('@overleaf/metrics')
|
||||
|
||||
const clsiCookiesEnabled =
|
||||
(Settings.clsiCookie != null ? Settings.clsiCookie.key : undefined) != null &&
|
||||
|
@ -72,15 +73,21 @@ module.exports = function (backendGroup) {
|
|||
})
|
||||
return callback(err)
|
||||
}
|
||||
this.setServerId(project_id, user_id, res, function (err, serverId) {
|
||||
if (err != null) {
|
||||
logger.warn(
|
||||
{ err, project_id },
|
||||
'error setting server id via populate request'
|
||||
)
|
||||
this.setServerId(
|
||||
project_id,
|
||||
user_id,
|
||||
res,
|
||||
null,
|
||||
function (err, serverId) {
|
||||
if (err != null) {
|
||||
logger.warn(
|
||||
{ err, project_id },
|
||||
'error setting server id via populate request'
|
||||
)
|
||||
}
|
||||
return callback(err, serverId)
|
||||
}
|
||||
return callback(err, serverId)
|
||||
})
|
||||
)
|
||||
})
|
||||
},
|
||||
|
||||
|
@ -93,7 +100,7 @@ module.exports = function (backendGroup) {
|
|||
return cookies != null ? cookies[Settings.clsiCookie.key] : undefined
|
||||
},
|
||||
|
||||
setServerId(project_id, user_id, response, callback) {
|
||||
setServerId(project_id, user_id, response, previous, callback) {
|
||||
if (callback == null) {
|
||||
callback = function (err, serverId) {}
|
||||
}
|
||||
|
@ -109,6 +116,12 @@ module.exports = function (backendGroup) {
|
|||
err => callback(err, undefined)
|
||||
)
|
||||
}
|
||||
if (!previous) {
|
||||
// Initial assignment of a user+project or after clearing cache.
|
||||
Metrics.inc('clsi-lb-assign-initial-backend')
|
||||
} else {
|
||||
Metrics.inc('clsi-lb-switch-backend')
|
||||
}
|
||||
if (rclient_secondary != null) {
|
||||
this._setServerIdInRedis(
|
||||
rclient_secondary,
|
||||
|
|
|
@ -328,6 +328,7 @@ const ClsiManager = {
|
|||
projectId,
|
||||
userId,
|
||||
response,
|
||||
clsiServerId,
|
||||
(err, newClsiServerId) => {
|
||||
if (err != null) {
|
||||
callback(
|
||||
|
@ -420,7 +421,7 @@ const ClsiManager = {
|
|||
NewBackendCloudClsiCookieManager.getCookieJar(
|
||||
projectId,
|
||||
userId,
|
||||
(err, jar) => {
|
||||
(err, jar, clsiServerId) => {
|
||||
if (err != null) {
|
||||
return callback(
|
||||
OError.tag(err, 'error getting cookie jar for CLSI request', {
|
||||
|
@ -444,6 +445,7 @@ const ClsiManager = {
|
|||
projectId,
|
||||
userId,
|
||||
response,
|
||||
clsiServerId,
|
||||
err => {
|
||||
if (err != null) {
|
||||
return callback(
|
||||
|
|
|
@ -118,7 +118,7 @@ describe('ClsiCookieManager', function () {
|
|||
this.request.post.callsArgWith(1, null, this.response)
|
||||
return (this.ClsiCookieManager.setServerId = sinon
|
||||
.stub()
|
||||
.callsArgWith(3, null, 'clsi-9'))
|
||||
.yields(null, 'clsi-9'))
|
||||
})
|
||||
|
||||
it('should make a request to the clsi', function (done) {
|
||||
|
@ -160,6 +160,7 @@ describe('ClsiCookieManager', function () {
|
|||
this.project_id,
|
||||
this.user_id,
|
||||
this.response,
|
||||
null,
|
||||
err => {
|
||||
this.redis.setex
|
||||
.calledWith(
|
||||
|
@ -178,6 +179,7 @@ describe('ClsiCookieManager', function () {
|
|||
this.project_id,
|
||||
this.user_id,
|
||||
this.response,
|
||||
null,
|
||||
(err, serverId) => {
|
||||
serverId.should.equal('clsi-8')
|
||||
return done()
|
||||
|
@ -197,6 +199,7 @@ describe('ClsiCookieManager', function () {
|
|||
this.project_id,
|
||||
this.user_id,
|
||||
this.response,
|
||||
null,
|
||||
(err, serverId) => {
|
||||
this.redis.setex.called.should.equal(false)
|
||||
return done()
|
||||
|
@ -212,6 +215,7 @@ describe('ClsiCookieManager', function () {
|
|||
this.project_id,
|
||||
this.user_id,
|
||||
this.response,
|
||||
null,
|
||||
(err, serverId) => {
|
||||
this.redis.setex.called.should.equal(false)
|
||||
return done()
|
||||
|
@ -240,6 +244,7 @@ describe('ClsiCookieManager', function () {
|
|||
this.project_id,
|
||||
this.user_id,
|
||||
this.response,
|
||||
null,
|
||||
(err, serverId) => {
|
||||
this.redis_secondary.setex
|
||||
.calledWith(
|
||||
|
|
|
@ -9,7 +9,7 @@ describe('ClsiManager', function () {
|
|||
this.ClsiCookieManager = {
|
||||
clearServerId: sinon.stub().yields(),
|
||||
getCookieJar: sinon.stub().callsArgWith(2, null, this.jar),
|
||||
setServerId: sinon.stub().callsArgWith(3),
|
||||
setServerId: sinon.stub().yields(null),
|
||||
_getServerId: sinon.stub(),
|
||||
}
|
||||
this.ClsiStateManager = {
|
||||
|
|
Loading…
Reference in a new issue