From 56628a16c632507bfd5775cfa02f369876ce4658 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Mon, 30 Mar 2020 11:31:44 +0200 Subject: [PATCH] [misc] track redis pub/sub payload sizes on publish --- services/real-time/app.coffee | 5 ++++- services/real-time/app/coffee/ChannelManager.coffee | 1 + .../test/unit/coffee/ChannelManagerTests.coffee | 12 +++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/services/real-time/app.coffee b/services/real-time/app.coffee index 215b3c7cb9..06fd3555f6 100644 --- a/services/real-time/app.coffee +++ b/services/real-time/app.coffee @@ -163,10 +163,13 @@ if Settings.continualPubsubTraffic checker = new HealthCheckManager(channel) logger.debug {channel:channel}, "sending pub to keep connection alive" json = JSON.stringify({health_check:true, key: checker.id, date: new Date().toString()}) + Metrics.summary "redis.publish.#{channel}", json.length pubsubClient.publish channel, json, (err)-> if err? logger.err {err, channel}, "error publishing pubsub traffic to redis" - clusterClient.publish "cluster-continual-traffic", {keep: "alive"}, callback + blob = JSON.stringify({keep: "alive"}) + Metrics.summary "redis.publish.cluster-continual-traffic", blob.length + clusterClient.publish "cluster-continual-traffic", blob, callback runPubSubTraffic = -> diff --git a/services/real-time/app/coffee/ChannelManager.coffee b/services/real-time/app/coffee/ChannelManager.coffee index 3ea5c2e71e..367d2059a2 100644 --- a/services/real-time/app/coffee/ChannelManager.coffee +++ b/services/real-time/app/coffee/ChannelManager.coffee @@ -48,6 +48,7 @@ module.exports = ChannelManager = metrics.inc "unsubscribe.#{baseChannel}" publish: (rclient, baseChannel, id, data) -> + metrics.summary "redis.publish.#{baseChannel}", data.length if id is 'all' or !settings.publishOnIndividualChannels channel = baseChannel else diff --git a/services/real-time/test/unit/coffee/ChannelManagerTests.coffee b/services/real-time/test/unit/coffee/ChannelManagerTests.coffee index e550e963d4..edde3e8170 100644 --- a/services/real-time/test/unit/coffee/ChannelManagerTests.coffee +++ b/services/real-time/test/unit/coffee/ChannelManagerTests.coffee @@ -10,7 +10,7 @@ describe 'ChannelManager', -> @other_rclient = {} @ChannelManager = SandboxedModule.require modulePath, requires: "settings-sharelatex": @settings = {} - "metrics-sharelatex": @metrics = {inc: sinon.stub()} + "metrics-sharelatex": @metrics = {inc: sinon.stub(), summary: sinon.stub()} "logger-sharelatex": @logger = { log: sinon.stub(), warn: sinon.stub(), error: sinon.stub() } describe "subscribe", -> @@ -106,3 +106,13 @@ describe 'ChannelManager', -> @rclient.publish.calledWithExactly("applied-ops:1234567890abcdef", "random-message").should.equal true @rclient.publish.calledOnce.should.equal true + describe "metrics", -> + beforeEach -> + @rclient.publish = sinon.stub() + @ChannelManager.publish @rclient, "applied-ops", "all", "random-message" + + it "should track the payload size", -> + @metrics.summary.calledWithExactly( + "redis.publish.applied-ops", + "random-message".length + ).should.equal true