Skip to content

fix(integrations) removing redis watch and changing key to a daily redis hash key #54001

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

Merged
merged 10 commits into from
Aug 2, 2023

Conversation

chloeho7
Copy link
Contributor

@chloeho7 chloeho7 commented Aug 1, 2023

No description provided.

@chloeho7 chloeho7 requested a review from a team as a code owner August 1, 2023 23:21
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Aug 1, 2023

def _get(self):
"""
Returns the list of daily aggregate error counts.
"""
return [
self._convert_obj_to_dict(obj)
self._convert_obj_to_dict(str(obj))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we stringifying the object here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

json.loads() expects a str and redis object uses single quotes instead of double which json expects so I fix the quotes using .replace()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if json.dumps() could help here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is hgetall not returning a python dict for you?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hgetall does return a python dict so I removed this method :)

for i in reversed(range(BUFFER_SIZE)):
with freeze_time(now - timedelta(days=i)):
cur = datetime.now().strftime("%Y-%m-%d")
buffer_key = self.integrationkey + cur
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buffer_key = f"{self.integrationkey}:{cur}"?

finally:
pipe.reset()
pipe.hincrby(buffer_key, count + "_count", 1)
pipe.expire(buffer_key, KEY_EXPIRY)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you can maybe include an NX optional param for the expire command https://redis.io/commands/expire/ and only set the expire once. In practical terms, it probably won't matter since you're only refreshing the ttl for this day and then when the its the next day, the previous day hash won't ever be modified again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like NX also isn't supported

@codecov
Copy link

codecov bot commented Aug 1, 2023

Codecov Report

Merging #54001 (ad8301b) into master (c840864) will increase coverage by 0.00%.
Report is 4 commits behind head on master.
The diff coverage is 100.00%.

❗ Current head ad8301b differs from pull request most recent head a1d6e00. Consider uploading reports for the commit a1d6e00 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #54001   +/-   ##
=======================================
  Coverage   79.53%   79.53%           
=======================================
  Files        4974     4974           
  Lines      210385   210380    -5     
  Branches    35832    35828    -4     
=======================================
- Hits       167337   167334    -3     
+ Misses      37901    37899    -2     
  Partials     5147     5147           
Files Changed Coverage Δ
src/sentry/integrations/request_buffer.py 95.00% <100.00%> (+2.69%) ⬆️

... and 3 files with indirect coverage changes

for i in reversed(range(IS_BROKEN_RANGE)):
cur = (now - timedelta(days=i)).strftime("%Y-%m-%d")
buffer_key = f"{self.integrationkey}:{cur}"
ret.append(self.client.hgetall(buffer_key))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use a pipeline here, and in _get_all_from_buffer, since you already know all the key names in advance.

@barkbarkimashark barkbarkimashark self-requested a review August 2, 2023 18:33
@chloeho7 chloeho7 enabled auto-merge (squash) August 2, 2023 18:37
@chloeho7 chloeho7 merged commit 9ded544 into master Aug 2, 2023
@chloeho7 chloeho7 deleted the fix(integrations)-redis-watch-is-not-implemented branch August 2, 2023 19:03
@github-actions github-actions bot locked and limited conversation to collaborators Aug 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants