Skip to content
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): create WorkflowFireHistory objects for triggered workflows and update when meeting filters #88775

Merged
merged 3 commits into from
Apr 8, 2025

Conversation

cathteng
Copy link
Member

@cathteng cathteng commented Apr 4, 2025

We've decided that WorkflowFireHistory will track every time a workflow has been triggered. Note that we only fire actions if subsequent workflow filters are met.

Create these objects for triggered workflows in regular processing and delayed processing.

I added a column (has_fired_actions) to track whether a workflow also met its filters and fired actions -- WorkflowFireHistory objects with has_fired_actions=True should be 1:1 with RuleFireHistory today. Update this column if filters are met (there is 1 filter group per Rule/Workflow during the rollout period, this is not guaranteed in the future).

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

codecov bot commented Apr 4, 2025

Codecov Report

Attention: Patch coverage is 98.50746% with 1 line in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/workflow_engine/processors/workflow.py 92.85% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #88775       +/-   ##
===========================================
+ Coverage   42.12%   87.69%   +45.56%     
===========================================
  Files       10062    10093       +31     
  Lines      569227   570890     +1663     
  Branches    22448    22448               
===========================================
+ Hits       239801   500646   +260845     
+ Misses     329018    69836   -259182     
  Partials      408      408               

@cathteng cathteng marked this pull request as ready for review April 4, 2025 15:52
@cathteng cathteng requested a review from a team as a code owner April 4, 2025 15:52
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.

i'd recommend thinking about the code structure here a little more - how can we make these methods not have side effects? I'm a bit concerned about the increased complexity in process_workflows and the side effects in delayed processor.

"payload": job,
"group_id": job.event.group_id,
"event_id": job.event.event_id,
"payload": event_data,
Copy link
Contributor

Choose a reason for hiding this comment

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

next time it'd be a little easier for the review if the event_data rename stuff was split into a separate PR. with this is 1 pr it means i need to try and parse what is just a rename vs the changeset for workflow triggers

workflows = set(Workflow.objects.filter(when_condition_group_id__in=workflow_triggers))
filtered_actions.extend(list(evaluate_workflows_action_filters(workflows, job)))

# create WorkflowFireHistory (updated in evaluate_workflows_action_filters)
create_workflow_fire_histories(workflows, event_data)
Copy link
Contributor

Choose a reason for hiding this comment

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

this feels like a side effect of fire_actions_for_groups is there another place we could do this? The way i'd structure the code is to evaluate the actions, return the list of actions, then have another method trigger them (no queries or anything in that firing method, just taking a list of actions and calling anything that needs to be fired)

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 agree that ideally this would not be here and preferably would be done beforehand...

logically it belongs right after this in get_groups_to_fire

passes, _ = evaluate_data_conditions(conditions_to_evaluate, action_match)

i'm not certain if it's possible to nicely slot it in get_groups_to_fire because:

  1. WorkflowFireHistory requires the event_id from the GroupEvent
  2. we grab the GroupEvents in bulk after exiting from get_groups_to_fire (aka after we figure out which groups we need to fire workflows for)

given this, would it be okay to leave it where it is? i've refactored away other standalone usages save for this one

Copy link
Member

Choose a reason for hiding this comment

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

Oof yeah this is tricky, I looked at it for a bit trying to figure out another way and I can't think of anything super clean. You could store filtered_actions in 2 separate variables (since you tack on the results of evaluate_workflows_action_filters and wouldn't want that) and return both along with the corresponding event ids (or just the event ids ins separate vars?) so you can then call create_workflow_fire_histories in process_delayed_workflows, but idk if that's really much better than you have it now.

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.

lgtm - we may want to refactor the delayed processor stuff in the future to avoid the side-effect style updates, but for now 👍

@cathteng cathteng enabled auto-merge (squash) April 8, 2025 17:23
@cathteng cathteng merged commit 9747525 into master Apr 8, 2025
48 checks passed
@cathteng cathteng deleted the cathy/aci/create-workflow-fire-history branch April 8, 2025 17:43
andrewshie-sentry pushed a commit that referenced this pull request Apr 8, 2025
Christinarlong pushed a commit that referenced this pull request Apr 10, 2025
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.

3 participants