Skip to content

✨ feat: add workflow_id to WorkflowEventData#90959

Closed
iamrajjoshi wants to merge 4 commits into
masterfrom
raj/aci/add-workflow-id-to-workflow-event-data
Closed

✨ feat: add workflow_id to WorkflowEventData#90959
iamrajjoshi wants to merge 4 commits into
masterfrom
raj/aci/add-workflow-id-to-workflow-event-data

Conversation

@iamrajjoshi

@iamrajjoshi iamrajjoshi commented May 5, 2025

Copy link
Copy Markdown
Collaborator

This PR adds the corresponding workflow_id to the WorkflowEventData dataclass.

This allows us to use that workflow_id in our notifications

The main change is rather than returning a set of Action, we return a set of tuple[Action, int], where the int is the workflow_id

@iamrajjoshi iamrajjoshi self-assigned this May 5, 2025
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label May 5, 2025
@codecov

codecov Bot commented May 5, 2025

Copy link
Copy Markdown

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
25434 1 25433 333
View the top 1 failed test(s) by shortest run time
tests.sentry.workflow_engine.processors.test_delayed_workflow.TestFireActionsForGroups::test_fire_actions_for_groups__fire_actions
Stack Traces | 24.3s run time
#x1B[1m#x1B[.../workflow_engine/processors/test_delayed_workflow.py#x1B[0m:774: in test_fire_actions_for_groups__fire_actions
    assert mock_trigger.call_args_list[0][0] == (
#x1B[1m#x1B[31mE   assert (WorkflowEven...01e50: id=48>) == (WorkflowEven...02bd0: id=48>)#x1B[0m
#x1B[1m#x1B[31mE     #x1B[0m
#x1B[1m#x1B[31mE     At index 0 diff: WorkflowEventData(event=<sentry.eventstore.models.GroupEvent object at 0x7f342f5d1270>, group_state=None, has_reappeared=None, has_escalated=None, workflow_id=45, workflow_env=None) != WorkflowEventData(event=<sentry.eventstore.models.GroupEvent object at 0x7f342f5d1590>, group_state=None, has_reappeared=None, has_escalated=None, workflow_id=None, workflow_env=None)#x1B[0m
#x1B[1m#x1B[31mE     #x1B[0m
#x1B[1m#x1B[31mE     Full diff:#x1B[0m
#x1B[1m#x1B[31mE       (#x1B[0m
#x1B[1m#x1B[31mE           WorkflowEventData(#x1B[0m
#x1B[1m#x1B[31mE     -         event=<sentry.eventstore.models.GroupEvent object at 0x7f342f5d1590>,#x1B[0m
#x1B[1m#x1B[31mE     ?                                                                         ^^#x1B[0m
#x1B[1m#x1B[31mE     +         event=<sentry.eventstore.models.GroupEvent object at 0x7f342f5d1270>,#x1B[0m
#x1B[1m#x1B[31mE     ?                                                                         ^^#x1B[0m
#x1B[1m#x1B[31mE               group_state=None,#x1B[0m
#x1B[1m#x1B[31mE               has_reappeared=None,#x1B[0m
#x1B[1m#x1B[31mE               has_escalated=None,#x1B[0m
#x1B[1m#x1B[31mE     -         workflow_id=None,#x1B[0m
#x1B[1m#x1B[31mE     ?                     ^^^^#x1B[0m
#x1B[1m#x1B[31mE     +         workflow_id=45,#x1B[0m
#x1B[1m#x1B[31mE     ?                     ^^#x1B[0m
#x1B[1m#x1B[31mE               workflow_env=None,#x1B[0m
#x1B[1m#x1B[31mE           ),#x1B[0m
#x1B[1m#x1B[31mE     -     <Detector at 0x7f341e602bd0: id=48>,#x1B[0m
#x1B[1m#x1B[31mE     ?                            ^^^#x1B[0m
#x1B[1m#x1B[31mE     +     <Detector at 0x7f341e601e50: id=48>,#x1B[0m
#x1B[1m#x1B[31mE     ?                            ^^^#x1B[0m
#x1B[1m#x1B[31mE       )#x1B[0m

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

Comment on lines +133 to +138
else:
logger.error(
"Action %s has no associated DataConditionGroupAction",
action.id,
extra={"action_id": action.id},
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So this seems like an invariant we'd want to potentially uphold. Does it make sense to continue executing the rest of this function when this occurs, or should we raise an exception and bail due to the data inconsistency this likely signifies?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

hmm, thinking about this. i know this is a hot path so whatever we end up selecting needs to be resilient

Comment thread src/sentry/workflow_engine/processors/action.py Outdated
Comment thread src/sentry/workflow_engine/processors/workflow.py
@iamrajjoshi iamrajjoshi marked this pull request as ready for review May 5, 2025 22:50
@iamrajjoshi iamrajjoshi requested a review from a team as a code owner May 5, 2025 22:50

@saponifi3d saponifi3d left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I feel like this is probably not happing in quite the right spot of the workflow engine processing, and that's where the complexity in this method is coming from.

i think it'd be a bit cleaner if we handled this when we trigger the action in process workflows or have the action.trigger do the lookup so it's better encapsulated whenever any action is triggered.


result_list: set[tuple[Action, int]] = set()
for action in filtered_actions:
dcg_action = action.dataconditiongroupaction_set.first()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we shouldn't make an assumption about there only being 1 dcga per action, can we just handle this in a loop instead?

if dcg_action:
workflow_id = filtered_action_groups[dcg_action.condition_group]
result_list.add((action, workflow_id))
else:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this possible given the filter on dcga on at the beginning of the method?

filtered_action_groups: set[DataConditionGroup], event_data: WorkflowEventData
) -> BaseQuerySet[Action]:
filtered_action_groups: dict[DataConditionGroup, int], event_data: WorkflowEventData
) -> set[tuple[Action, int]]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤔 not sure i agree with this method signature change - it seems like we're just grabbing the workflow id that we probably already have when we're invoking this method (we would need the workflow to get the list of dcgs to filter on).

Is there somewhere else we should be adding the workflow id instead? could we keep it super simple and get the id from process workflows when we're triggering actions? (or handle this in action.trigger to find the corresponding workflow so it's more generic)

@iamrajjoshi iamrajjoshi closed this May 6, 2025
@iamrajjoshi

Copy link
Copy Markdown
Collaborator Author

closed in favor of https://github.com/getsentry/sentry/pull/91031/files

@github-actions github-actions Bot locked and limited conversation to collaborators May 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants