add metric for queue length

This commit is contained in:
Brian Gough 2019-09-25 17:04:36 +01:00
parent f6b2ac7360
commit 83dd43b809
2 changed files with 7 additions and 3 deletions

View file

@ -35,9 +35,11 @@ module.exports = DeleteQueueManager =
logger.log "hit count limit on flushing old projects" logger.log "hit count limit on flushing old projects"
return callback() return callback()
cutoffTime = now - options.min_delete_age cutoffTime = now - options.min_delete_age
RedisManager.getNextProjectToFlushAndDelete cutoffTime, (err, project_id, flushTimestamp) -> RedisManager.getNextProjectToFlushAndDelete cutoffTime, (err, project_id, flushTimestamp, queueLength) ->
return callback(err) if err? return callback(err) if err?
return callback() if !project_id? return callback() if !project_id?
logger.log {project_id, queueLength: queueLength}, "flushing queued project"
metrics.globalGauge "queued-flush-backlog", queueLength
flushProjectIfNotModified project_id, flushTimestamp, (err, flushed) -> flushProjectIfNotModified project_id, flushTimestamp, (err, flushed) ->
count++ if flushed count++ if flushed
flushNextProject() flushNextProject()

View file

@ -298,18 +298,20 @@ module.exports = RedisManager =
rclient.zadd keys.flushAndDeleteQueue(), Date.now(), project_id, callback rclient.zadd keys.flushAndDeleteQueue(), Date.now(), project_id, callback
getNextProjectToFlushAndDelete: (cutoffTime, callback = (error, key, timestamp)->) -> getNextProjectToFlushAndDelete: (cutoffTime, callback = (error, key, timestamp)->) ->
# find the oldest queued flsus # find the oldest queued flush
rclient.zrangebyscore keys.flushAndDeleteQueue(), 0, cutoffTime, "WITHSCORES", "LIMIT", 0, 1, (err, reply) -> rclient.zrangebyscore keys.flushAndDeleteQueue(), 0, cutoffTime, "WITHSCORES", "LIMIT", 0, 1, (err, reply) ->
return callback(err) if err? return callback(err) if err?
return callback() if !reply?.length return callback() if !reply?.length
multi = rclient.multi() multi = rclient.multi()
multi.zrange keys.flushAndDeleteQueue(), 0, 0, "WITHSCORES" multi.zrange keys.flushAndDeleteQueue(), 0, 0, "WITHSCORES"
multi.zremrangebyrank keys.flushAndDeleteQueue(), 0, 0 multi.zremrangebyrank keys.flushAndDeleteQueue(), 0, 0
multi.zcard keys.flushAndDeleteQueue()
multi.exec (err, reply) -> multi.exec (err, reply) ->
return callback(err) if err? return callback(err) if err?
return callback() if !reply?.length return callback() if !reply?.length
[key, timestamp] = reply[0] [key, timestamp] = reply[0]
callback(null, key, timestamp) queueLength = reply[2]
callback(null, key, timestamp, queueLength)
_serializeRanges: (ranges, callback = (error, serializedRanges) ->) -> _serializeRanges: (ranges, callback = (error, serializedRanges) ->) ->
jsonRanges = JSON.stringify(ranges) jsonRanges = JSON.stringify(ranges)