add doclines set/del metric

This commit is contained in:
Brian Gough 2020-04-01 15:59:25 +01:00
parent 00b11bda96
commit 3a8c362fba
2 changed files with 12 additions and 2 deletions

View file

@ -41,7 +41,7 @@ module.exports = RedisManager =
logger.error {err: error, doc_id: doc_id, docLines: docLines}, error.message logger.error {err: error, doc_id: doc_id, docLines: docLines}, error.message
return callback(error) return callback(error)
docHash = RedisManager._computeHash(docLines) docHash = RedisManager._computeHash(docLines)
metrics.summary "redis.setDoc", docLines.length, {status: "set"} metrics.summary "redis.docLines", docLines.length, {status: "set"}
logger.log {project_id, doc_id, version, docHash, pathname, projectHistoryId}, "putting doc in redis" logger.log {project_id, doc_id, version, docHash, pathname, projectHistoryId}, "putting doc in redis"
RedisManager._serializeRanges ranges, (error, ranges) -> RedisManager._serializeRanges ranges, (error, ranges) ->
if error? if error?
@ -74,6 +74,7 @@ module.exports = RedisManager =
_callback() _callback()
multi = rclient.multi() multi = rclient.multi()
multi.strlen keys.docLines(doc_id:doc_id)
multi.del keys.docLines(doc_id:doc_id) multi.del keys.docLines(doc_id:doc_id)
multi.del keys.projectKey(doc_id:doc_id) multi.del keys.projectKey(doc_id:doc_id)
multi.del keys.docVersion(doc_id:doc_id) multi.del keys.docVersion(doc_id:doc_id)
@ -85,8 +86,11 @@ module.exports = RedisManager =
multi.del keys.unflushedTime(doc_id:doc_id) multi.del keys.unflushedTime(doc_id:doc_id)
multi.del keys.lastUpdatedAt(doc_id: doc_id) multi.del keys.lastUpdatedAt(doc_id: doc_id)
multi.del keys.lastUpdatedBy(doc_id: doc_id) multi.del keys.lastUpdatedBy(doc_id: doc_id)
multi.exec (error) -> multi.exec (error, response) ->
return callback(error) if error? return callback(error) if error?
length = response?[0]
if length > 0
metrics.summary "redis.docLines", length, {status: "del"}
multi = rclient.multi() multi = rclient.multi()
multi.srem keys.docsInProject(project_id:project_id), doc_id multi.srem keys.docsInProject(project_id:project_id), doc_id
multi.del keys.projectState(project_id:project_id) multi.del keys.projectState(project_id:project_id)

View file

@ -671,11 +671,17 @@ describe "RedisManager", ->
describe "removeDocFromMemory", -> describe "removeDocFromMemory", ->
beforeEach (done) -> beforeEach (done) ->
@multi.strlen = sinon.stub()
@multi.del = sinon.stub() @multi.del = sinon.stub()
@multi.srem = sinon.stub() @multi.srem = sinon.stub()
@multi.exec.yields() @multi.exec.yields()
@RedisManager.removeDocFromMemory @project_id, @doc_id, done @RedisManager.removeDocFromMemory @project_id, @doc_id, done
it "should check the length of the current doclines", ->
@multi.strlen
.calledWith("doclines:#{@doc_id}")
.should.equal true
it "should delete the lines", -> it "should delete the lines", ->
@multi.del @multi.del
.calledWith("doclines:#{@doc_id}") .calledWith("doclines:#{@doc_id}")