Merge pull request #2705 from overleaf/jpa-pub-sub-metrics

[misc] track redis pub/sub payload sizes on publish

GitOrigin-RevId: 7ef7ada34f9f6376abdd2b0b6aa10a5aac56a62f
This commit is contained in:
nate stemen 2020-03-30 14:13:23 -04:00 committed by Copybot
parent 3b1a5c458e
commit 797d76f90e
2 changed files with 25 additions and 9 deletions

View file

@ -13,6 +13,7 @@
*/
let EditorRealTimeController
const Settings = require('settings-sharelatex')
const Metrics = require('metrics-sharelatex')
const RedisWrapper = require('../../infrastructure/RedisWrapper')
const rclient = RedisWrapper.client('pubsub')
const os = require('os')
@ -32,15 +33,14 @@ module.exports = EditorRealTimeController = {
} else {
channel = `editor-events:${room_id}`
}
return rclient.publish(
channel,
JSON.stringify({
room_id,
message,
payload,
_id: message_id
})
)
const blob = JSON.stringify({
room_id,
message,
payload,
_id: message_id
})
Metrics.summary('redis.publish.editor-events', blob.length)
return rclient.publish(channel, blob)
},
emitToAll(message, ...payload) {

View file

@ -21,6 +21,7 @@ const modulePath = require('path').join(
describe('EditorRealTimeController', function() {
beforeEach(function() {
this.rclient = { publish: sinon.stub() }
this.Metrics = { summary: sinon.stub() }
this.EditorRealTimeController = SandboxedModule.require(modulePath, {
globals: {
console: console
@ -33,6 +34,7 @@ describe('EditorRealTimeController', function() {
io: (this.io = {})
},
'settings-sharelatex': { redis: {} },
'metrics-sharelatex': this.Metrics,
crypto: (this.crypto = {
randomBytes: sinon
.stub()
@ -71,6 +73,20 @@ describe('EditorRealTimeController', function() {
)
.should.equal(true)
})
it('should track the payload size', function() {
this.Metrics.summary
.calledWith(
'redis.publish.editor-events',
JSON.stringify({
room_id: this.room_id,
message: this.message,
payload: this.payload,
_id: this.message_id
}).length
)
.should.equal(true)
})
})
describe('emitToAll', function() {