Skip to content

perf(alerts): Limit GroupEvent processing to relevant groups #91659

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 1 commit into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 8 additions & 3 deletions src/sentry/rules/processing/delayed_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,17 @@ def get_group_to_groupevent(
groups = Group.objects.filter(id__in=group_ids)
group_id_to_group = {group.id: group for group in groups}

# Filter down to only the event data for the groups we've been asked to process.
relevant_rulegroup_to_event_data = {
key: value for key, value in parsed_rulegroup_to_event_data.items() if key[1] in group_ids
}

# Use a list comprehension for event_ids
event_ids: list[str] = [
event_id
for event_id in (
instance_data.get("event_id")
for instance_data in parsed_rulegroup_to_event_data.values()
for instance_data in relevant_rulegroup_to_event_data.values()
)
if event_id is not None
]
Expand All @@ -312,7 +317,7 @@ def get_group_to_groupevent(
occurrence_id
for occurrence_id in (
instance_data.get("occurrence_id")
for instance_data in parsed_rulegroup_to_event_data.values()
for instance_data in relevant_rulegroup_to_event_data.values()
)
if occurrence_id is not None
]
Expand All @@ -325,7 +330,7 @@ def get_group_to_groupevent(
}

return build_group_to_groupevent(
parsed_rulegroup_to_event_data,
relevant_rulegroup_to_event_data,
bulk_event_id_to_events,
bulk_occurrence_id_to_occurrence,
group_id_to_group,
Expand Down
24 changes: 24 additions & 0 deletions tests/sentry/rules/processing/test_delayed_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,30 @@ def test_invalid_group_ids(self):
result = get_group_to_groupevent(self.parsed_data, self.project.id, {0})
assert len(result) == 0

def test_filtered_group_ids(self):
"""Test that get_group_to_groupevent only requests events for specified group IDs."""
# Track which event IDs are requested
requested_event_ids = set()

original_bulk_fetch_events = bulk_fetch_events

def mock_bulk_fetch_events(event_ids, project_id):
requested_event_ids.update(event_ids)
return original_bulk_fetch_events(event_ids, project_id)

with patch(
"sentry.rules.processing.delayed_processing.bulk_fetch_events",
side_effect=mock_bulk_fetch_events,
):
# Call get_group_to_groupevent with only group1
result = get_group_to_groupevent(self.parsed_data, self.project.id, {self.group1.id})

# Verify only event1 was requested
assert requested_event_ids == {self.event1.event_id}
assert len(result) == 1
assert result[self.group1] == self.event1
assert self.group2 not in result


class GetRulesToFireTest(TestCase):
def setUp(self):
Expand Down
Loading