mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
add metric for RoomEvents listeners
This commit is contained in:
parent
277ec71a5b
commit
22d722f3e8
2 changed files with 5 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
||||||
logger = require 'logger-sharelatex'
|
logger = require 'logger-sharelatex'
|
||||||
|
metrics = require "metrics-sharelatex"
|
||||||
{EventEmitter} = require 'events'
|
{EventEmitter} = require 'events'
|
||||||
|
|
||||||
IdMap = new Map() # keep track of whether ids are from projects or docs
|
IdMap = new Map() # keep track of whether ids are from projects or docs
|
||||||
|
@ -55,6 +56,8 @@ module.exports = RoomManager =
|
||||||
callback(err)
|
callback(err)
|
||||||
RoomEvents.emit "#{entity}-active", id
|
RoomEvents.emit "#{entity}-active", id
|
||||||
IdMap.set(id, entity)
|
IdMap.set(id, entity)
|
||||||
|
# keep track of the number of listeners
|
||||||
|
metrics.gauge "room-listeners", RoomEvents.eventNames().length
|
||||||
else
|
else
|
||||||
logger.log {client: client.id, entity, id, beforeCount}, "client joined existing room"
|
logger.log {client: client.id, entity, id, beforeCount}, "client joined existing room"
|
||||||
client.join id
|
client.join id
|
||||||
|
@ -72,6 +75,7 @@ module.exports = RoomManager =
|
||||||
logger.log {entity, id}, "room is now empty"
|
logger.log {entity, id}, "room is now empty"
|
||||||
RoomEvents.emit "#{entity}-empty", id
|
RoomEvents.emit "#{entity}-empty", id
|
||||||
IdMap.delete(id)
|
IdMap.delete(id)
|
||||||
|
metrics.gauge "room-listeners", RoomEvents.eventNames().length
|
||||||
|
|
||||||
# internal functions below, these access socket.io rooms data directly and
|
# internal functions below, these access socket.io rooms data directly and
|
||||||
# will need updating for socket.io v2
|
# will need updating for socket.io v2
|
||||||
|
|
|
@ -13,6 +13,7 @@ describe 'RoomManager', ->
|
||||||
@RoomManager = SandboxedModule.require modulePath, requires:
|
@RoomManager = SandboxedModule.require modulePath, requires:
|
||||||
"settings-sharelatex": @settings = {}
|
"settings-sharelatex": @settings = {}
|
||||||
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
|
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
|
||||||
|
"metrics-sharelatex": @metrics = { gauge: sinon.stub() }
|
||||||
@RoomManager._clientsInRoom = sinon.stub()
|
@RoomManager._clientsInRoom = sinon.stub()
|
||||||
@RoomEvents = @RoomManager.eventSource()
|
@RoomEvents = @RoomManager.eventSource()
|
||||||
sinon.spy(@RoomEvents, 'emit')
|
sinon.spy(@RoomEvents, 'emit')
|
||||||
|
|
Loading…
Reference in a new issue