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

ref(releasehealth): Refactor session count calculation before implementing the metrics backend #29078

Merged
merged 2 commits into from
Oct 6, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/sentry/rules/conditions/event_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,15 @@ def query_hook(self, event, start, end, environment_id):
start=end - timedelta(minutes=60),
end=end,
filter_keys=filters,
groupby=["bucketed_started"],
referrer="rules.conditions.event_frequency.EventFrequencyPercentCondition",
)

if result_totals["data"]:
session_count_last_hour = sum(
bucket["sessions"] for bucket in result_totals["data"]
)
else:
session_count_last_hour = False
# Note: (RaduW) Kept sessions_count_last_hour = False (when there are no sessions) to maintain
# compatibility with old the implementation. It doesn't make a lot of sense to me but
# since the value is saved in cache I didn't want to change the original behaviour.
session_count_last_hour = (
result_totals["data"][0]["sessions"] if result_totals["data"] else False
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC, we were storing it as False in order to differentiate between when we got no data back from Snuba, and when we got a count of 0. I think this was more relevant when we weren't making an hour long bucket and dividing it by the interval (this was an optimization done after the original implementation - we used to query per interval but this ends up making a lot more queries and puts a lot more data in the cache). Just looking at the code, it seems like it would be fine if we didn't keep False now...so maybe be okay to change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the background info, I'll change it to 0... I don't think we can get 0 as a legitimate return value from the query (I might be wrong) since a row in sessions would imply at least one session.

)
cache.set(cache_key, session_count_last_hour, 600)

if session_count_last_hour >= MIN_SESSIONS_TO_FIRE:
Expand Down