Explorar el Código

Track metrics of when backends match or disagree

James Allen hace 10 años
padre
commit
dbe03e2757

+ 4 - 1
services/document-updater/app/coffee/RedisBackend.coffee

@@ -2,6 +2,7 @@ Settings = require "settings-sharelatex"
 async = require "async"
 async = require "async"
 _ = require "underscore"
 _ = require "underscore"
 logger = require "logger-sharelatex"
 logger = require "logger-sharelatex"
+Metrics = require "metrics-sharelatex"
 
 
 class Client
 class Client
 	constructor: (@clients) ->
 	constructor: (@clients) ->
@@ -136,7 +137,9 @@ compareResults = (results) ->
 	first = results[0]
 	first = results[0]
 	for result in results.slice(1)
 	for result in results.slice(1)
 		if not _.isEqual(first, result)
 		if not _.isEqual(first, result)
-			logger.warn { results }, "redis return values do not match"
+			Metrics.inc "backend-conflict"
+		else
+			Metrics.inc "backend-match"
 
 
 module.exports =
 module.exports =
 	createClient: () ->
 	createClient: () ->

+ 18 - 16
services/document-updater/test/unit/coffee/RedisBackend/RedisBackendTests.coffee

@@ -53,6 +53,8 @@ describe "RedisBackend", ->
 				activeHealthCheck: sinon.stub()
 				activeHealthCheck: sinon.stub()
 			"ioredis": @ioredis =
 			"ioredis": @ioredis =
 				Cluster: Cluster
 				Cluster: Cluster
+			"metrics-sharelatex":
+				@Metrics = inc: sinon.stub()
 		@client = @RedisBackend.createClient()
 		@client = @RedisBackend.createClient()
 		
 		
 		@doc_id = "mock-doc-id"
 		@doc_id = "mock-doc-id"
@@ -96,6 +98,11 @@ describe "RedisBackend", ->
 				@rclient_ioredis.get
 				@rclient_ioredis.get
 					.calledWith("doclines:{#{@doc_id}}")
 					.calledWith("doclines:{#{@doc_id}}")
 					.should.equal true
 					.should.equal true
+				
+			it "should send a metric", ->
+				@Metrics.inc
+					.calledWith("backend-match")
+					.should.equal true
 
 
 		describe "with different results", ->
 		describe "with different results", ->
 			beforeEach (done) ->
 			beforeEach (done) ->
@@ -110,14 +117,9 @@ describe "RedisBackend", ->
 			it "should return the primary result", ->
 			it "should return the primary result", ->
 				@result.should.equal "primary-result"
 				@result.should.equal "primary-result"
 			
 			
-			it "should log out the difference", ->
-				@logger.warn
-					.calledWith({
-						results: [
-							"primary-result",
-							"secondary-result"
-						]
-					}, "redis return values do not match")
+			it "should send a metric", ->
+				@Metrics.inc
+					.calledWith("backend-conflict")
 					.should.equal true
 					.should.equal true
 
 
 		describe "when the secondary errors", ->
 		describe "when the secondary errors", ->
@@ -233,6 +235,11 @@ describe "RedisBackend", ->
 				@rclient_ioredis.exec
 				@rclient_ioredis.exec
 					.called
 					.called
 					.should.equal true
 					.should.equal true
+				
+			it "should send a metric", ->
+				@Metrics.inc
+					.calledWith("backend-match")
+					.should.equal true
 
 
 		describe "with different results", ->
 		describe "with different results", ->
 			beforeEach (done) ->
 			beforeEach (done) ->
@@ -251,14 +258,9 @@ describe "RedisBackend", ->
 			it "should return the primary result", ->
 			it "should return the primary result", ->
 				@result.should.deep.equal [@doclines, @version]
 				@result.should.deep.equal [@doclines, @version]
 			
 			
-			it "should log out the difference", ->
-				@logger.warn
-					.calledWith({
-						results: [
-							[@doclines, @version],
-							["different-doc-lines", @version]
-						]
-					}, "redis return values do not match")
+			it "should send a metric", ->
+				@Metrics.inc
+					.calledWith("backend-conflict")
 					.should.equal true
 					.should.equal true
 
 
 		describe "when the secondary errors", ->
 		describe "when the secondary errors", ->