-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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(anomaly detection): warn users if less than one week of historical data is available (backend) #75214
Conversation
ef6f4b2
to
051a28f
Compare
ack accidentally branched off of a branch ;_; |
051a28f
to
b1686bf
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #75214 +/- ##
=======================================
Coverage 78.18% 78.18%
=======================================
Files 6808 6808
Lines 302899 302924 +25
Branches 52128 52134 +6
=======================================
+ Hits 236818 236850 +32
+ Misses 59692 59685 -7
Partials 6389 6389
|
tests/sentry/incidents/endpoints/test_organization_alert_rule_index.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few comments
src/sentry/incidents/endpoints/organization_alert_rule_index.py
Outdated
Show resolved
Hide resolved
src/sentry/incidents/endpoints/organization_alert_rule_index.py
Outdated
Show resolved
Hide resolved
src/sentry/incidents/endpoints/organization_alert_rule_index.py
Outdated
Show resolved
Hide resolved
tests/sentry/incidents/endpoints/test_organization_alert_rule_index.py
Outdated
Show resolved
Hide resolved
src/sentry/incidents/endpoints/organization_alert_rule_index.py
Outdated
Show resolved
Hide resolved
if not indices_with_results: | ||
return start, end | ||
else: | ||
start = indices_with_results[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh grab the first and the last because the data is already ordered is that right?
Maybe we should add some quick validations in here for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we're looping through the data in order, so start is guaranteed to be <= end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't be able to test the validation—should I still add it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a quick assertion here so that it would raise an exception 🤷
could just be a quick assert start < end
This way it will raise in case this is ever false
MIN_DAYS = 7 | ||
data_start_index, data_end_index = get_start_and_end(historical_data) | ||
if data_start_index == -1: | ||
resp.status = 202 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok - RE: comments above, lets just throw an exception if there's not enough data.
This should be a loud failure, rather than a seeming success
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we do create the alert rule—it just won't detect any anomalies until Seer has at least a week of data. Should we still have an exception in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^^ Yes this is just a warning to the user that it can't fire for some period of time until we've collected the data. We still want to create it and then we'll be periodically sending updated data to Seer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, that makes sense!
Commented above - rather than modifying the response and returning the response,
Thoughts on simply returning a boolean for successful backfill or not?
we're not utilizing the rest of the response, and modifying the response is unexpected (for ex. mocking seer response w/ 200, but expecting a 202?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can do that
346e50c
to
43d0fbd
Compare
maybeeee? backend stuff smol change logic fixed (tests are gonna fail don't come for me) buggies fix stuff and add test cleanup test fixed (?) fix failing test and address some comments another test fix up more tests
777553f
to
9e2ebcf
Compare
8a79a46
to
3c33428
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few comments!
@@ -106,6 +106,7 @@ def create_metric_alert(self, request, organization, project=None): | |||
}, | |||
data=data, | |||
) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷
@@ -652,7 +652,10 @@ def create_alert_rule( | |||
) | |||
|
|||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
So we've covered create_alert_rule
,
Lets also be sure to capture update_alert_rule
as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll work in that in the next PR after Colleen's changes to update_alert_rule
land
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we leave a TODO in the update method so we don't forget it?
if not indices_with_results: | ||
return start, end | ||
else: | ||
start = indices_with_results[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a quick assertion here so that it would raise an exception 🤷
could just be a quick assert start < end
This way it will raise in case this is ever false
MIN_DAYS = 7 | ||
data_start_index, data_end_index = get_start_and_end(historical_data) | ||
if data_start_index == -1: | ||
resp.status = 202 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, that makes sense!
Commented above - rather than modifying the response and returning the response,
Thoughts on simply returning a boolean for successful backfill or not?
we're not utilizing the rest of the response, and modifying the response is unexpected (for ex. mocking seer response w/ 200, but expecting a 202?)
self.alert_rule.save() | ||
else: | ||
# we don't need to check if the alert should fire if the alert can't fire yet | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to continue iterating through this - like would there be a situation in which the next potential_anomaly
would change the result of self.has_enough_data()
? If not, we can just break here (which I realize is also a little silly since we expect one anomaly, but 🤷♀️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, but I also don't know, which is why I did continue instead of break. If only one anomaly is returned, like how it's spec'd in Seer, then they accomplish the same thing. I think continue is just a little safer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔
Would Seer ever actually return any potential anomalies if we don't have enough data?
This check may actually be unnecessary? (but safe to have anyways)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hell yea!
a few nit comments, but this is looking sharp!
@@ -652,7 +652,10 @@ def create_alert_rule( | |||
) | |||
|
|||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we leave a TODO in the update method so we don't forget it?
self.alert_rule.save() | ||
else: | ||
# we don't need to check if the alert should fire if the alert can't fire yet | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔
Would Seer ever actually return any potential anomalies if we don't have enough data?
This check may actually be unnecessary? (but safe to have anyways)
Suspect IssuesThis pull request was deployed and Sentry observed the following issues:
Did you find this useful? React with a 👍 or 👎 |
If snuba returns fewer than 7 days worth of historical data, then surface a warning.