-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bf: ZENKO-1144 add support for Redis sorted sets #567
Conversation
Hello philipyoo,My role is to assist you with the merge of this Status report is not available. |
Waiting for approvalThe following approvals are needed before I can proceed with the merge:
Peer approvals must include at least 1 approval from the following list: |
lib/metrics/RedisClient.js
Outdated
return this._client | ||
.multi([['incrby', key, amount], ['expire', key, expiry]]) | ||
.exec(cb); | ||
set(key, cb) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we not need this, since we aren't using failure keys anymore?
lib/metrics/RedisClient.js
Outdated
/** | ||
* Get range of elements in a sorted set based off score | ||
* @param {string} key - name of key | ||
* @param {integer} min - min score value (inclusive) (can use "-inf") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's update this doc to integer|string
to account for '-inf' values.
lib/metrics/StatsModel.js
Outdated
*/ | ||
addToSortedSet(key, score, value, cb) { | ||
// milliseconds in a day | ||
const msInADay = 24 * 60 * 60 * 1000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: for readability, it seems like this should be within the if block in which it is used.
lib/metrics/StatsModel.js
Outdated
['zadd', key, score, value], | ||
['expire', key, ttl], | ||
]; | ||
return this._redis.batch(cmds, cb); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be useful to check for the batched command errors (i.e. the array of arrays), so that this method returns an error if any of those sub commands fail as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good, on success I'm planning on returning only the zadd
return value to keep both successful returns the same
const key = 'a-test-key'; | ||
const score = 100; | ||
const value = 'a-value'; | ||
// redisClient.ttl(key, (err, res)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra comment.
Changes in this commit: - Add wrapper for Redis sorted set methods: ZADD, ZCARD, ZRANGE, ZRANGEBYSCORE, ZREM, ZSCORE - Add wrapper for Redis methods: EXISTS
0b91835
to
5e2bdd2
Compare
Changes in this commit: - Helper method _normalizeTimestampByHour normalizes date to nearest hour - Helper method _setDateToPreviousHour sets date back 1 hour - method getSortedSetHours returns list of 24 normalized hourly timestamps - method getSortedSetCurrentHour returns normalized hourly timestamp based on epoch passed - method addToSortedSet adds to a sorted set and applies expiry if adding to new sorted set
5e2bdd2
to
0c9c462
Compare
In the queueThe changeset has received all authorizations and has been added to the The changeset will be merged in:
The following branches will NOT be impacted:
There is no action required on your side. You will be notified here once IMPORTANT Please do not attempt to modify this pull request.
If you need this pull request to be removed from the queue, please contact a |
I have successfully merged the changeset of this pull request
The following branches have NOT changed:
Please check the status of the associated issue ZENKO-1144. Goodbye philipyoo. |
* @return {undefined} | ||
*/ | ||
addToSortedSet(key, score, value, cb) { | ||
this._redis.exists(key, (err, resCode) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am assuming that you are only trying to expire when it's set for the first time and it's 24 hours? Your code will be cleaner if you use EXPIREAT
which takes a timestamp. Also EXPIRE
takes value in seconds, the ttl you calculated is in milliseconds. If you use EXPIREAT
, you can set it everytime and don't have to check if the key exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only want to apply the expire if its brand new. We won't know which hour sorted set we are adding to, so I'll keep it as is except for the ms -> sec issue
These changes are to support use of sorted sets in Redis for crr metrics. Plan is to use hourly sorted sets to track failure metrics and keep a epoch sorted list of failure keys.
Changes in this PR:
StatsModel.getSortedSetCurrentHour
returns array of 24 normalized hourly timestampsStatsModel.addToSortedSet
adds to a sorted set and applies expiry if adding to new sorted set