mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
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:
parent
3b1a5c458e
commit
797d76f90e
2 changed files with 25 additions and 9 deletions
|
@ -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({
|
||||
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) {
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue