From 22d722f3e8afca3ebdf773d9d57a1ef83f1ac706 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Wed, 24 Jul 2019 16:25:45 +0100 Subject: [PATCH] add metric for RoomEvents listeners --- services/real-time/app/coffee/RoomManager.coffee | 4 ++++ services/real-time/test/unit/coffee/RoomManagerTests.coffee | 1 + 2 files changed, 5 insertions(+) diff --git a/services/real-time/app/coffee/RoomManager.coffee b/services/real-time/app/coffee/RoomManager.coffee index 9f42083198..adf472e26c 100644 --- a/services/real-time/app/coffee/RoomManager.coffee +++ b/services/real-time/app/coffee/RoomManager.coffee @@ -1,4 +1,5 @@ logger = require 'logger-sharelatex' +metrics = require "metrics-sharelatex" {EventEmitter} = require 'events' IdMap = new Map() # keep track of whether ids are from projects or docs @@ -55,6 +56,8 @@ module.exports = RoomManager = callback(err) RoomEvents.emit "#{entity}-active", id IdMap.set(id, entity) + # keep track of the number of listeners + metrics.gauge "room-listeners", RoomEvents.eventNames().length else logger.log {client: client.id, entity, id, beforeCount}, "client joined existing room" client.join id @@ -72,6 +75,7 @@ module.exports = RoomManager = logger.log {entity, id}, "room is now empty" RoomEvents.emit "#{entity}-empty", id IdMap.delete(id) + metrics.gauge "room-listeners", RoomEvents.eventNames().length # internal functions below, these access socket.io rooms data directly and # will need updating for socket.io v2 diff --git a/services/real-time/test/unit/coffee/RoomManagerTests.coffee b/services/real-time/test/unit/coffee/RoomManagerTests.coffee index 294365dd61..ee46a3ef04 100644 --- a/services/real-time/test/unit/coffee/RoomManagerTests.coffee +++ b/services/real-time/test/unit/coffee/RoomManagerTests.coffee @@ -13,6 +13,7 @@ describe 'RoomManager', -> @RoomManager = SandboxedModule.require modulePath, requires: "settings-sharelatex": @settings = {} "logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() } + "metrics-sharelatex": @metrics = { gauge: sinon.stub() } @RoomManager._clientsInRoom = sinon.stub() @RoomEvents = @RoomManager.eventSource() sinon.spy(@RoomEvents, 'emit')