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

feat(dlq): Extend Count policy to save to/load from Redis #2537

Merged
merged 8 commits into from
Mar 28, 2022

Conversation

rahul-kumar-saini
Copy link
Contributor

@rahul-kumar-saini rahul-kumar-saini commented Mar 21, 2022

Added a new DLQ Policy which extends the Count policy and adds functionality to save the hits in Redis and to be able to load the state upon instantiation.

@codecov-commenter
Copy link

codecov-commenter commented Mar 21, 2022

Codecov Report

Merging #2537 (c091516) into master (3462be1) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2537      +/-   ##
==========================================
+ Coverage   92.68%   92.70%   +0.01%     
==========================================
  Files         609      611       +2     
  Lines       28123    28200      +77     
==========================================
+ Hits        26065    26142      +77     
  Misses       2058     2058              
Impacted Files Coverage Δ
snuba/state/stateful_count.py 100.00% <100.00%> (ø)
tests/state/test_stateful_count_policy.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3462be1...c091516. Read the comment docs.

Copy link
Contributor Author

@rahul-kumar-saini rahul-kumar-saini left a comment

Choose a reason for hiding this comment

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

Using a Redis Hash instead of a Sorted Set since the values (# of hits in time bucket) will not be unique. There is a better way of doing this using the new Redis TimeSeries type but that is only available in Redis >= 4.0.0.

I'm not sure what directory the policy should live in, left it in /snuba/state for now but open to suggestions.

snuba/state/stateful_count.py Outdated Show resolved Hide resolved
@rahul-kumar-saini rahul-kumar-saini marked this pull request as ready for review March 21, 2022 23:25
@rahul-kumar-saini rahul-kumar-saini requested a review from a team as a code owner March 21, 2022 23:25
"""

def __init__(self, redis_hash_name: str, limit: int, seconds: int = 60) -> None:
self.__name = redis_hash_name
Copy link
Member

Choose a reason for hiding this comment

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

just curious is the redis_hash_name going to be set by the consumer? like will different consumers have different hash names?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah each consumer would have its own DLQ, which means a policy would be instantiated per consumer. The name of the hash storing the counts would be set wherever the consumer is instantiated with a DLQ.

snuba/state/stateful_count.py Outdated Show resolved Hide resolved
snuba/state/stateful_count.py Outdated Show resolved Hide resolved
snuba/state/stateful_count.py Outdated Show resolved Hide resolved
snuba/state/stateful_count.py Show resolved Hide resolved
Copy link
Member

@nikhars nikhars left a comment

Choose a reason for hiding this comment

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

What's the reason for putting StatefulCountInvalidMessagePolicy in Snuba and not arroyo? I see a valid use case for this in arroyo. Sentry can now start using arroyo. The Sentry consumers like indexer and subscriptions would be more resilient if they also had DLQ for them. Having it in arroyo would make it possible for those consumers to use it in the future.

rahul-kumar-saini and others added 2 commits March 22, 2022 11:37
Co-authored-by: Lyn Nagara <lyn.nagara@gmail.com>
@rahul-kumar-saini
Copy link
Contributor Author

rahul-kumar-saini commented Mar 22, 2022

What's the reason for putting StatefulCountInvalidMessagePolicy in Snuba and not arroyo?

Redis is only accessible in Snuba and not Arroyo, the base class does this counting anyway but doesn't add anything to Redis like this policy does. Sentry could simply use that policy as is or extend it like this one if the state of hits should be saved/loaded.

@rahul-kumar-saini rahul-kumar-saini enabled auto-merge (squash) March 28, 2022 19:58
@rahul-kumar-saini rahul-kumar-saini merged commit 2c861e3 into master Mar 28, 2022
@rahul-kumar-saini rahul-kumar-saini deleted the feat/redis-hit-counter branch March 28, 2022 20:14
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.

6 participants