diff --git a/services/real-time/app.coffee b/services/real-time/app.coffee index 89f0cdfb36..f468ad2d49 100644 --- a/services/real-time/app.coffee +++ b/services/real-time/app.coffee @@ -53,6 +53,11 @@ app.get "/", (req, res, next) -> app.get "/status", (req, res, next) -> res.send "real-time-sharelatex is alive" +app.get "/debug/events", (req, res, next) -> + Settings.debugEvents = parseInt(req.query?.count,10) || 20 + logger.log {count: Settings.debugEvents}, "starting debug mode" + res.send "debug mode will log next #{Settings.debugEvents} events" + rclient = require("redis-sharelatex").createClient(Settings.redis.realtime) app.get "/health_check/redis", (req, res, next) -> rclient.healthCheck (error) -> diff --git a/services/real-time/app/coffee/DocumentUpdaterController.coffee b/services/real-time/app/coffee/DocumentUpdaterController.coffee index 057649aa9c..209af3c0bf 100644 --- a/services/real-time/app/coffee/DocumentUpdaterController.coffee +++ b/services/real-time/app/coffee/DocumentUpdaterController.coffee @@ -15,6 +15,7 @@ module.exports = DocumentUpdaterController = listenForUpdatesFromDocumentUpdater: (io) -> rclient.subscribe "applied-ops" rclient.on "message", (channel, message) -> + EventLogger.debugEvent(channel, message) if settings.debugEvents > 0 DocumentUpdaterController._processMessageFromDocumentUpdater(io, channel, message) _processMessageFromDocumentUpdater: (io, channel, message) -> diff --git a/services/real-time/app/coffee/EventLogger.coffee b/services/real-time/app/coffee/EventLogger.coffee index 3738e4f729..332973659b 100644 --- a/services/real-time/app/coffee/EventLogger.coffee +++ b/services/real-time/app/coffee/EventLogger.coffee @@ -1,5 +1,6 @@ logger = require 'logger-sharelatex' metrics = require 'metrics-sharelatex' +settings = require 'settings-sharelatex' # keep track of message counters to detect duplicate and out of order events # messsage ids have the format "UNIQUEHOSTKEY-COUNTER" @@ -8,10 +9,18 @@ EVENT_LOG_COUNTER = {} EVENT_LOG_TIMESTAMP = {} EVENT_LAST_CLEAN_TIMESTAMP = 0 +# counter for debug logs +COUNTER = 0 + module.exports = EventLogger = MAX_STALE_TIME_IN_MS: 3600 * 1000 + debugEvent: (channel, message) -> + if settings.debugEvents > 0 + logger.log {channel:channel, message:message, counter: COUNTER++}, "logging event" + settings.debugEvents-- + checkEventOrder: (channel, message_id, message) -> return if typeof(message_id) isnt 'string' return if !(result = message_id.match(/^(.*)-(\d+)$/)) diff --git a/services/real-time/app/coffee/WebsocketLoadBalancer.coffee b/services/real-time/app/coffee/WebsocketLoadBalancer.coffee index 3e973fdb4c..8fed080b68 100644 --- a/services/real-time/app/coffee/WebsocketLoadBalancer.coffee +++ b/services/real-time/app/coffee/WebsocketLoadBalancer.coffee @@ -27,6 +27,7 @@ module.exports = WebsocketLoadBalancer = listenForEditorEvents: (io) -> @rclientSub.subscribe "editor-events" @rclientSub.on "message", (channel, message) -> + EventLogger.debugEvent(channel, message) if Settings.debugEvents > 0 WebsocketLoadBalancer._processEditorEvent io, channel, message _processEditorEvent: (io, channel, message) ->