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

Merge pull request #70 from overleaf/bg-metric-for-invalid-hash

add metric for invalid hash and other sharejs errors
Brian Gough 7 лет назад
Родитель
Сommit
e8dd1aae9c
1 измененных файлов с 6 добавлено и 1 удалено
  1. 6 1
      services/document-updater/app/coffee/ShareJsUpdateManager.coffee

+ 6 - 1
services/document-updater/app/coffee/ShareJsUpdateManager.coffee

@@ -48,6 +48,7 @@ module.exports = ShareJsUpdateManager =
 					error = new Errors.DeleteMismatchError("Delete component does not match")
 					error = new Errors.DeleteMismatchError("Delete component does not match")
 					return callback(error)
 					return callback(error)
 				else
 				else
+					metrics.inc "sharejs.other-error"
 					return callback(error)
 					return callback(error)
 			logger.log project_id: project_id, doc_id: doc_id, error: error, "applied update"
 			logger.log project_id: project_id, doc_id: doc_id, error: error, "applied update"
 			model.getSnapshot doc_key, (error, data) =>
 			model.getSnapshot doc_key, (error, data) =>
@@ -55,7 +56,11 @@ module.exports = ShareJsUpdateManager =
 				# only check hash when present and no other updates have been applied 
 				# only check hash when present and no other updates have been applied 
 				if update.hash? and incomingUpdateVersion == version
 				if update.hash? and incomingUpdateVersion == version
 					ourHash = ShareJsUpdateManager._computeHash(data.snapshot)
 					ourHash = ShareJsUpdateManager._computeHash(data.snapshot)
-					return callback(new Error("Invalid hash")) if ourHash != update.hash
+					if ourHash != update.hash
+						metrics.inc "sharejs.hash-fail"
+						return callback(new Error("Invalid hash"))
+					else
+						metrics.inc "sharejs.hash-pass", 0.001
 				docLines = data.snapshot.split(/\r\n|\n|\r/)
 				docLines = data.snapshot.split(/\r\n|\n|\r/)
 				callback(null, docLines, data.v, model.db.appliedOps[doc_key] or [])
 				callback(null, docLines, data.v, model.db.appliedOps[doc_key] or [])