add /debug/events endpoint

This commit is contained in:
Brian Gough 2019-04-11 15:00:25 +01:00
parent 2a31139254
commit c6225d614e
4 changed files with 16 additions and 0 deletions

View file

@ -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) ->

View file

@ -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) ->

View file

@ -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+)$/))

View file

@ -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) ->