Merge pull request #130 from overleaf/jpa-pub-sub-metrics

[misc] track redis pub/sub payload sizes on publish
This commit is contained in:
Jakob Ackermann 2020-03-30 12:26:28 +02:00 committed by GitHub
commit 5dabba11c6
2 changed files with 9 additions and 2 deletions

View file

@ -39,9 +39,13 @@ module.exports = RealTimeRedisManager =
# create a unique message id using a counter # create a unique message id using a counter
message_id = "doc:#{HOST}:#{RND}-#{COUNT++}" message_id = "doc:#{HOST}:#{RND}-#{COUNT++}"
data?._id = message_id data?._id = message_id
blob = JSON.stringify(data)
metrics.summary "redis.publish.applied-ops", blob.length
# publish on separate channels for individual projects and docs when # publish on separate channels for individual projects and docs when
# configured (needs realtime to be configured for this too). # configured (needs realtime to be configured for this too).
if Settings.publishOnIndividualChannels if Settings.publishOnIndividualChannels
pubsubClient.publish "applied-ops:#{data.doc_id}", JSON.stringify(data) pubsubClient.publish "applied-ops:#{data.doc_id}", blob
else else
pubsubClient.publish "applied-ops", JSON.stringify(data) pubsubClient.publish "applied-ops", blob

View file

@ -90,3 +90,6 @@ describe "RealTimeRedisManager", ->
it "should send the op with a message id", -> it "should send the op with a message id", ->
@pubsubClient.publish.calledWith("applied-ops", JSON.stringify({op:"thisop",_id:@message_id})).should.equal true @pubsubClient.publish.calledWith("applied-ops", JSON.stringify({op:"thisop",_id:@message_id})).should.equal true
it "should track the payload size", ->
@metrics.summary.calledWith("redis.publish.applied-ops", JSON.stringify({op:"thisop",_id:@message_id}).length).should.equal true