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

fix(processing): Separate second query of percentage comparison #73099

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

schew2381
Copy link
Member

@schew2381 schew2381 commented Jun 21, 2024

Fixes ALRT-101

@schew2381 schew2381 self-assigned this Jun 21, 2024
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jun 21, 2024
Copy link

codecov bot commented Jun 21, 2024

Codecov Report

Attention: Patch coverage is 82.69231% with 9 lines in your changes missing coverage. Please review.

Project coverage is 78.00%. Comparing base (486a589) to head (b4fc09e).
Report is 66 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #73099      +/-   ##
==========================================
- Coverage   78.01%   78.00%   -0.01%     
==========================================
  Files        6630     6632       +2     
  Lines      295916   296082     +166     
  Branches    50971    50989      +18     
==========================================
+ Hits       230848   230967     +119     
- Misses      58732    58778      +46     
- Partials     6336     6337       +1     
Files Coverage Δ
src/sentry/rules/conditions/event_frequency.py 89.65% <100.00%> (ø)
src/sentry/rules/processing/delayed_processing.py 86.83% <79.54%> (+0.73%) ⬆️

... and 86 files with indirect coverage changes

Copy link
Member

@wedamija wedamija left a comment

Choose a reason for hiding this comment

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

This makes sense to me, I'll give it a second review once you've finished tests

if len(query_values) == 2:
calculated_value = percent_increase(calculated_value, query_values[1])

target_value = float(condition_data["value"])
Copy link
Member

Choose a reason for hiding this comment

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

Previously we converted this to a string then float, not sure if that's important though

Copy link
Member Author

@schew2381 schew2381 Jun 25, 2024

Choose a reason for hiding this comment

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

@ceorourke do you remember why we originally did that here?

Copy link
Member

Choose a reason for hiding this comment

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

I think it was just to match this https://github.com/getsentry/sentry/blob/master/src/sentry/rules/conditions/event_frequency.py - what's the data type initially? A float?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a string but I think we can just convert that directly, like here

Copy link
Member

@nhsiehgit nhsiehgit left a comment

Choose a reason for hiding this comment

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

some pre-lim comments

haven't looked over the tests yet, lookin gnow

src/sentry/rules/conditions/event_frequency.py Outdated Show resolved Hide resolved
src/sentry/rules/conditions/event_frequency.py Outdated Show resolved Hide resolved
"""
end = timezone.now() - interval
if comparison_interval:
end = end - comparison_interval
Copy link
Member

Choose a reason for hiding this comment

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

If we're already passing in the end - why do we pass in the offset?
Can we just calculate the new end when invoking this helper?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could but I liked having this function handle all the time calculations instead of doing it in get_rate_bulk and get_rate

src/sentry/rules/conditions/event_frequency.py Outdated Show resolved Hide resolved
with self.disable_consistent_snuba_mode(duration):
result = self.query(event, start, end, environment_id=environment_id)
if comparison_type == ComparisonType.PERCENT:
# TODO: Figure out if there's a way we can do this less frequently. All queries are
# automatically cached for 10s. We could consider trying to cache this and the main
# query for 20s to reduce the load.
start, end = self.get_comparison_start_end(comparison_interval, duration)
start, end = self.get_comparison_start_end(
Copy link
Member

Choose a reason for hiding this comment

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

RE: comments above

1 - lets make this kwargs
2 - lets pre-calucate the end here

src/sentry/rules/conditions/event_frequency.py Outdated Show resolved Hide resolved
Copy link
Member

@nhsiehgit nhsiehgit left a comment

Choose a reason for hiding this comment

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

some more comments on the tests

query, but the second percent query is separate.
"""

def ordered_callthrough(descending=False):
Copy link
Member

Choose a reason for hiding this comment

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

🤔 can we call this mock_get_condition_group? or toss side_effect/callback somewhere in teh name of this?

Copy link
Member

Choose a reason for hiding this comment

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

Also - does this need to be a separate helper?

Why are we modifying the args being passed into this method? This means we aren't properly capturing how the implementation would behave.

This feels smelly 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

We're modifying the order of the list of rules being passed into the function. We need to do this to test the behavior when count and percent conditions can share a query, so that ordering doesn't matter.

Originally they come in a random order, so we test for both orderings (count first then percent and vice versa)

@schew2381 schew2381 force-pushed the seiji/fix/separate-percent-comparison-queries branch from 4a5c976 to edbfdf9 Compare June 25, 2024 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants