Skip to content

ref(alerts): fetch group_to_groupevent once per delayed processing task #91831

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 5 commits into from
May 19, 2025
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
22 changes: 18 additions & 4 deletions src/sentry/rules/processing/delayed_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,15 @@ def fire_rules(
timedelta(seconds=40),
extra={"project_id": project_id},
) as tracker:
groups_to_fire = set().union(*rules_to_fire.values())
group_to_groupevent = get_group_to_groupevent(
parsed_rulegroup_to_event_data, project_id, groups_to_fire
)
group_id_to_group = {group.id: group for group in group_to_groupevent.keys()}
for rule, group_ids in rules_to_fire.items():
with tracker.track(f"rule_{rule.id}"):
frequency = rule.data.get("frequency") or Rule.DEFAULT_FREQUENCY
freq_offset = now - timedelta(minutes=frequency)
group_to_groupevent = get_group_to_groupevent(
log_config, parsed_rulegroup_to_event_data, project.id, group_ids
)
if (
log_config.num_events_issue_debugging
or log_config.workflow_engine_process_workflows
Expand All @@ -521,7 +523,19 @@ def fire_rules(
"rule_id": rule.id,
},
)
for group, groupevent in group_to_groupevent.items():
for group_id in group_ids:
group = group_id_to_group.get(group_id)
if not group:
logger.info(
"delayed_processing.group_not_found",
Copy link
Member

Choose a reason for hiding this comment

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

We should make it easier to understand what this situation means.
group_id_to_group is derived from rules_to_fire, but I think the subset of groups from rulegroup_to_event_data that were in rules_to_fire and we were able to find in the DB.
group_ids is just the raw group ids from rules_to_fire. rules_to_fire groups are themselves a subset of the groups present in rulegroup_to_event_data (i think).
So, my read is that not finding the group suggests something went wrong in fetching, which seems unexpected and probably worth escalating beyond logs.

If that's wrong, I think a comment clarifying what someone who sees this log message should be thinking is worthwhile.

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 can logger.error here, it will throw a sentry error

extra={
"rule_id": rule.id,
"group_id": group_id,
"project_id": project_id,
},
)
continue

rule_statuses = bulk_get_rule_status(alert_rules, group, project)
status = rule_statuses[rule.id]
if status.last_active and status.last_active > freq_offset:
Expand Down
Loading