Просмотр исходного кода

add missing argument to metrics.inc

also track retries rather than attempts (which is always 1 for a successful request)
Brian Gough 6 лет назад
Родитель
Сommit
7036803acf

+ 5 - 5
services/document-updater/app/coffee/PersistenceManager.coffee

@@ -21,11 +21,11 @@ updateMetric = (method, error, response) ->
 			error.code
 		else if response?
 			response.statusCode
-	Metrics.inc method, {status: status}
-	if error?.attempts > 0
-		Metrics.inc "#{method}-attempts", {status: 'error'}
-	if response?.attempts > 0
-		Metrics.inc "#{method}-attempts", {status: 'success'}
+	Metrics.inc method, 1, {status: status}
+	if error?.attempts > 1
+		Metrics.inc "#{method}-retries", 1, {status: 'error'}
+	if response?.attempts > 1
+		Metrics.inc "#{method}-retries", 1, {status: 'success'}
 
 module.exports = PersistenceManager =
 	getDoc: (project_id, doc_id, _callback = (error, lines, version, ranges, pathname, projectHistoryId, projectHistoryType) ->) ->

+ 8 - 8
services/document-updater/test/unit/coffee/PersistenceManager/PersistenceManagerTests.coffee

@@ -73,7 +73,7 @@ describe "PersistenceManager", ->
 				@Metrics.Timer::done.called.should.equal true
 
 			it "should increment the metric", ->
-				@Metrics.inc.calledWith("getDoc", {status: 200}).should.equal true
+				@Metrics.inc.calledWith("getDoc", 1, {status: 200}).should.equal true
 
 		describe "when request returns an error", ->
 			beforeEach ->
@@ -89,7 +89,7 @@ describe "PersistenceManager", ->
 				@Metrics.Timer::done.called.should.equal true
 
 			it "should increment the metric", ->
-				@Metrics.inc.calledWith("getDoc", {status: "EOOPS"}).should.equal true
+				@Metrics.inc.calledWith("getDoc", 1, {status: "EOOPS"}).should.equal true
 
 		describe "when the request returns 404", ->
 			beforeEach ->
@@ -103,7 +103,7 @@ describe "PersistenceManager", ->
 				@Metrics.Timer::done.called.should.equal true
 
 			it "should increment the metric", ->
-				@Metrics.inc.calledWith("getDoc", {status: 404}).should.equal true
+				@Metrics.inc.calledWith("getDoc", 1, {status: 404}).should.equal true
 
 		describe "when the request returns an error status code", ->
 			beforeEach ->
@@ -117,7 +117,7 @@ describe "PersistenceManager", ->
 				@Metrics.Timer::done.called.should.equal true
 
 			it "should increment the metric", ->
-				@Metrics.inc.calledWith("getDoc", {status: 500}).should.equal true
+				@Metrics.inc.calledWith("getDoc", 1, {status: 500}).should.equal true
 
 		describe "when request returns an doc without lines", ->
 			beforeEach ->
@@ -179,7 +179,7 @@ describe "PersistenceManager", ->
 				@Metrics.Timer::done.called.should.equal true
 
 			it "should increment the metric", ->
-				@Metrics.inc.calledWith("setDoc", {status: 200}).should.equal true
+				@Metrics.inc.calledWith("setDoc", 1, {status: 200}).should.equal true
 
 		describe "when request returns an error", ->
 			beforeEach ->
@@ -195,7 +195,7 @@ describe "PersistenceManager", ->
 				@Metrics.Timer::done.called.should.equal true
 
 			it "should increment the metric", ->
-				@Metrics.inc.calledWith("setDoc", {status: "EOOPS"}).should.equal true
+				@Metrics.inc.calledWith("setDoc", 1, {status: "EOOPS"}).should.equal true
 
 		describe "when the request returns 404", ->
 			beforeEach ->
@@ -209,7 +209,7 @@ describe "PersistenceManager", ->
 				@Metrics.Timer::done.called.should.equal true
 
 			it "should increment the metric", ->
-				@Metrics.inc.calledWith("setDoc", {status: 404}).should.equal true
+				@Metrics.inc.calledWith("setDoc", 1, {status: 404}).should.equal true
 
 		describe "when the request returns an error status code", ->
 			beforeEach ->
@@ -223,4 +223,4 @@ describe "PersistenceManager", ->
 				@Metrics.Timer::done.called.should.equal true
 
 			it "should increment the metric", ->
-				@Metrics.inc.calledWith("setDoc", {status: 500}).should.equal true
+				@Metrics.inc.calledWith("setDoc", 1, {status: 500}).should.equal true