Skip to content
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

Merged
merged 2 commits into from
Sep 14, 2018

Conversation

philipyoo
Copy link
Contributor

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:

  • Add wrapper for Redis sorted set methods: ZADD, ZCARD, ZRANGE, ZRANGEBYSCORE, ZREM, ZSCORE
  • Add wrapper for Redis methods: SET, EXISTS, TTL
  • StatsModel.getSortedSetCurrentHour returns array of 24 normalized hourly timestamps
  • StatsModel.addToSortedSet adds to a sorted set and applies expiry if adding to new sorted set

@bert-e
Copy link
Contributor

bert-e commented Sep 14, 2018

Hello philipyoo,

My role is to assist you with the merge of this
pull request. Please type @bert-e help to get
information on this process.

Status report is not available.

@bert-e
Copy link
Contributor

bert-e commented Sep 14, 2018

Waiting for approval

The following approvals are needed before I can proceed with the merge:

  • 2 peers

Peer approvals must include at least 1 approval from the following list:

return this._client
.multi([['incrby', key, amount], ['expire', key, expiry]])
.exec(cb);
set(key, cb) {

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?

/**
* 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")

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.

*/
addToSortedSet(key, score, value, cb) {
// milliseconds in a day
const msInADay = 24 * 60 * 60 * 1000;

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.

['zadd', key, score, value],
['expire', key, ttl],
];
return this._redis.batch(cmds, cb);
Copy link

@bennettbuchanan bennettbuchanan Sep 14, 2018

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.

Copy link
Contributor Author

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))

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
@philipyoo philipyoo force-pushed the bugfix/ZENKO-1144-addRedisSortedSets branch 3 times, most recently from 0b91835 to 5e2bdd2 Compare September 14, 2018 14:36
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
@bert-e
Copy link
Contributor

bert-e commented Sep 14, 2018

In the queue

The changeset has received all authorizations and has been added to the
relevant queue(s). The queue(s) will be merged in the target development
branch(es) as soon as builds have passed.

The changeset will be merged in:

  • ✔️ development/8.0

The following branches will NOT be impacted:

  • development/6.4
  • development/7.4

There is no action required on your side. You will be notified here once
the changeset has been merged. In the unlikely event that the changeset
fails permanently on the queue, a member of Release Engineering will
contact you to help resolve the matter.

IMPORTANT

Please do not attempt to modify this pull request.

  • Any commit you add on the source branch will trigger a new cycle after the
    current queue is merged.
  • Any commit you add on one of the integration branches will be lost.

If you need this pull request to be removed from the queue, please contact a
member of Release Engineering now.

@bert-e
Copy link
Contributor

bert-e commented Sep 14, 2018

I have successfully merged the changeset of this pull request
into targetted development branches:

  • ✔️ development/8.0

The following branches have NOT changed:

  • development/6.4
  • development/7.4

Please check the status of the associated issue ZENKO-1144.

Goodbye philipyoo.

@bert-e bert-e merged commit 0c9c462 into development/8.0 Sep 14, 2018
* @return {undefined}
*/
addToSortedSet(key, score, value, cb) {
this._redis.exists(key, (err, resCode) => {
Copy link
Collaborator

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.

Copy link
Contributor Author

@philipyoo philipyoo Sep 14, 2018

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

@jonathan-gramain jonathan-gramain deleted the bugfix/ZENKO-1144-addRedisSortedSets branch September 14, 2018 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants