-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat(ACI): Update metric issue occurrence #93368
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(ACI): Update metric issue occurrence #93368
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅ ✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## master #93368 +/- ##
==========================================
+ Coverage 85.77% 85.82% +0.04%
==========================================
Files 10286 10307 +21
Lines 593019 594318 +1299
Branches 23028 23028
==========================================
+ Hits 508677 510045 +1368
+ Misses 83732 83663 -69
Partials 610 610 |
eaa4185
to
68e81cf
Compare
@@ -415,6 +415,7 @@ def _build_detector_evaluation_result( | |||
) | |||
|
|||
# Set the event data with the necessary fields | |||
event_data["environment"] = self.detector.config.get("environment") |
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.
The event schema expects environment
to be set so we may as well set it on the base class
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.
This might be a little tricky since not every detector would have to store the env in the config. is it okay if it's set to None
is some cases? if so, then this seems good 👍
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 hard coded it to none and re-ran my tests so it seems ok! According to the docs it must be set.
tests/sentry/workflow_engine/handlers/detector/test_metric_issue_detector_handler.py
Outdated
Show resolved
Hide resolved
assignee=assignee, | ||
priority=priority, | ||
), | ||
{}, |
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.
In the previous attempt I was setting some event data:
sentry/src/sentry/incidents/grouptype.py
Lines 83 to 87 in 8303446
event_data = { | |
"environment": self.detector.config.get("environment"), | |
"platform": None, | |
"sdk": None, | |
} # XXX: may need to add to this |
it seems that having a "platform" of None was the main problem and the other ones either aren't necessary or are covered by the base class
@with_feature("organizations:workflow-engine-metric-alert-processing") | ||
@with_feature("organizations:workflow-engine-process-metric-issue-workflows") | ||
@patch("sentry.workflow_engine.processors.workflow.process_workflows") | ||
def test_occurrence_post_process(self, mock_process_workflows): |
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.
This test covers the reason the original PR was reverted - it wasn't getting into post processing and processing the workflows as expected. This test makes sure it does!
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.
generally looks good, i think we should move the tests into the incident
module, and the extra credit bits would be to split stuff out into separate files. (might be best to just split the test out to that file, and then do the handler in another pr)
@@ -415,6 +415,7 @@ def _build_detector_evaluation_result( | |||
) | |||
|
|||
# Set the event data with the necessary fields | |||
event_data["environment"] = self.detector.config.get("environment") |
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.
This might be a little tricky since not every detector would have to store the env in the config. is it okay if it's set to None
is some cases? if so, then this seems good 👍
if validated_condition_results: | ||
new_priority = max(new_priority, *validated_condition_results) |
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 add this? it's just checking if there are any items in the list -- which is probably a similar amount of processing power to splat an empty list and max 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.
Yeah this is carried over from the last PR, if there are no results because there was an error or the threshold was not met this causes a problem #92702 (comment)
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, sorry forgot -- thanks for the link!
tests/sentry/workflow_engine/handlers/detector/test_metric_issue_detector_handler.py
Outdated
Show resolved
Hide resolved
@@ -41,6 +43,12 @@ def create_occurrence( | |||
data_packet: DataPacket[QuerySubscriptionUpdate], | |||
priority: DetectorPriorityLevel, | |||
) -> tuple[DetectorOccurrence, EventData]: | |||
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.
🤔 this class is starting to get a bit large, should we pull it out into its own file and then import it here? That might also make it clearer with tests / what's being tested. Thoughts on something like: incidents/metric_detector.py
then incidents/test_metric_detector.py
for the code / tests?
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'm running into circular import issues trying to do this :/
@@ -0,0 +1,262 @@ | |||
from datetime import UTC, datetime, timedelta |
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.
diff got kinda large when I moved this because I copy/pasted the tests into new files rather than moving the whole original file and then copy/pasting the post process tests, but nothing has changed. I tried to put it back in the original file and move it to fix up the diff but it didn't detect any changes at that point 🤷
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.
no worries, thanks for moving these into this module.
if validated_condition_results: | ||
new_priority = max(new_priority, *validated_condition_results) |
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, sorry forgot -- thanks for the link!
@@ -0,0 +1,262 @@ | |||
from datetime import UTC, datetime, timedelta |
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.
no worries, thanks for moving these into this module.
The main change from #92702 with some slight changes I'll call out in comments.
The main change from #92702 with some slight changes I'll call out in comments.
The main change from #92702 with some slight changes I'll call out in comments.