Skip to content

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

Merged
merged 11 commits into from
Jun 13, 2025

Conversation

ceorourke
Copy link
Member

The main change from #92702 with some slight changes I'll call out in comments.

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jun 11, 2025
Copy link

codecov bot commented Jun 11, 2025

Codecov Report

All 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              

@ceorourke ceorourke force-pushed the ceorourke/update-metric-issue-occurrence-take2 branch from eaa4185 to 68e81cf Compare June 11, 2025 20:52
@@ -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")
Copy link
Member Author

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

Copy link
Contributor

@saponifi3d saponifi3d Jun 13, 2025

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 👍

Copy link
Member Author

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.

@ceorourke ceorourke marked this pull request as ready for review June 12, 2025 22:57
@ceorourke ceorourke requested review from a team as code owners June 12, 2025 22:57
assignee=assignee,
priority=priority,
),
{},
Copy link
Member Author

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:

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):
Copy link
Member Author

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!

Copy link
Contributor

@saponifi3d saponifi3d left a 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")
Copy link
Contributor

@saponifi3d saponifi3d Jun 13, 2025

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 👍

Comment on lines +529 to +530
if validated_condition_results:
new_priority = max(new_priority, *validated_condition_results)
Copy link
Contributor

@saponifi3d saponifi3d Jun 13, 2025

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.

Copy link
Member Author

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)

Copy link
Contributor

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!

@@ -41,6 +43,12 @@ def create_occurrence(
data_packet: DataPacket[QuerySubscriptionUpdate],
priority: DetectorPriorityLevel,
) -> tuple[DetectorOccurrence, EventData]:
try:
Copy link
Contributor

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?

Copy link
Member Author

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
Copy link
Member Author

@ceorourke ceorourke Jun 13, 2025

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 🤷

Copy link
Contributor

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.

Comment on lines +529 to +530
if validated_condition_results:
new_priority = max(new_priority, *validated_condition_results)
Copy link
Contributor

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
Copy link
Contributor

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.

@ceorourke ceorourke merged commit 07c96c0 into master Jun 13, 2025
64 checks passed
@ceorourke ceorourke deleted the ceorourke/update-metric-issue-occurrence-take2 branch June 13, 2025 18:55
billyvg pushed a commit that referenced this pull request Jun 18, 2025
The main change from #92702 with
some slight changes I'll call out in comments.
andrewshie-sentry pushed a commit that referenced this pull request Jun 19, 2025
The main change from #92702 with
some slight changes I'll call out in comments.
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.

2 participants