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(workflow_engine): Split fast and slow condition evaluation #84275

Merged
merged 12 commits into from
Jan 30, 2025

Conversation

saponifi3d
Copy link
Contributor

@saponifi3d saponifi3d commented Jan 29, 2025

Description

This PR splits the fast / slow conditions when we evaluate the condition group. This method will use the condition group logic type to decide when to return slow conditions or if we can short circuit those conditions.

Will Create a follow-up PR for enqueuing the slow conditions to the redis buffer (this was getting large)

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

codecov bot commented Jan 29, 2025

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
23711 1 23710 295
View the top 1 failed tests by shortest run time
tests.sentry.uptime.endpoints.test_organization_uptime_stats.OrganizationUptimeCheckIndexEndpointTest::test_too_many_periods
Stack Traces | 4.49s run time
#x1B[1m#x1B[.../uptime/endpoints/test_organization_uptime_stats.py#x1B[0m:99: in test_too_many_periods
    assert response.status_code == 400
#x1B[1m#x1B[31mE   assert 200 == 400#x1B[0m
#x1B[1m#x1B[31mE    +  where 200 = <Response status_code=200, "application/json">.status_code#x1B[0m

To view more test analytics, go to the Test Analytics Dashboard
📢 Thoughts on this report? Let us know!

Copy link
Member

@cathteng cathteng left a comment

Choose a reason for hiding this comment

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

logic changes lgtm but i'd like to clarify what we're actually enqueueing

if remaining_conditions:
# If there are remaining conditions for the action filter to evaluate,
# then return the list of conditions to enqueue
enqueued_conditions.extend(remaining_conditions)
Copy link
Member

Choose a reason for hiding this comment

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

i had planned to enqueue the DataConditionGroup, i think we can still do that here because the remaining_conditions can only be slow conditions, or am i missing something about why it's better to enqueue the conditions themselves? or is this more generic in case remaining_conditions might not only be slow conditions in the future?

Copy link
Member

Choose a reason for hiding this comment

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

on second thought, probably need to rethink the enqueuing logic since i am planning to have the key be {workflow_id}:{group_id}:{dcg_id,...,dcg_id}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, i ended up changing the enqueue method a bit:

def enqueue_workflow(
workflow: Workflow,
delayed_conditions: list[DataCondition],
event: GroupEvent,
source: WorkflowDataConditionGroupType,
) -> None:
project_id = event.group.project.id
buffer.backend.push_to_sorted_set(key=WORKFLOW_ENGINE_BUFFER_LIST_KEY, value=project_id)
condition_groups = ",".join(
str(condition.condition_group_id) for condition in delayed_conditions
)
value = json.dumps({"event_id": event.event_id, "occurrence_id": event.occurrence_id})
buffer.backend.push_to_hash(
model=Workflow,
filters={"project": project_id},
field=f"{workflow.id}:{event.group.id}:{condition_groups}:{source}",
value=value,
)

Since each condition knows it's condition group, i just made the enqueue method signature a little more ergonomic

Copy link
Member

Choose a reason for hiding this comment

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

yeah this works. will have to refactor my PR using this 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

out of curiosity, why's that? aren't you just reading from the buffer and that's all the format we chatted about this mornin'

Copy link
Member

Choose a reason for hiding this comment

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

oh jk i need to learn to read

Copy link
Member

Choose a reason for hiding this comment

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

i think i was misled that we are passing the conditions be enqueued when we're still actually enqueuing the
DataConditionGroup, do we need to collect all the conditions in that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

eh, probably don't need them all, we could probably move that list coercion up and out of this method and just take a list of ids in the method signature, but can figure that out on the other PR :)

triggered_workflows.add(workflow)
evaluation, remaining_conditions = workflow.evaluate_trigger_conditions(job)
if remaining_conditions:
workflows_to_enqueue.add(workflow)
Copy link
Member

Choose a reason for hiding this comment

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

i think we should enqueue the same thing in the buffer as in evaluate_workflow_action filters, but i assume this is happening in a follow up PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep! rather than us trying to create a data structure here and then enqueue a bunch at the end, i ended up just enqueuing directly in the other PR. that made it so we don't need to have an additional query to match the workflows to the data condition groups when enqueuing them.

@saponifi3d saponifi3d force-pushed the jcallender/aci/delayed-processing branch from 1a1c839 to df05a43 Compare January 30, 2025 19:21
@saponifi3d saponifi3d enabled auto-merge (squash) January 30, 2025 19:22
@saponifi3d saponifi3d merged commit 93ee4ed into master Jan 30, 2025
48 checks passed
@saponifi3d saponifi3d deleted the jcallender/aci/delayed-processing branch January 30, 2025 19:51
andrewshie-sentry pushed a commit that referenced this pull request Feb 5, 2025
## Description
This PR splits the fast / slow conditions when we evaluate the condition
group. This method will use the condition group logic type to decide
when to return slow conditions or if we can short circuit those
conditions.

Will Create a follow-up PR for enqueuing the slow conditions to the
redis buffer (this was getting large)
- Here's the draft of that PR, just need to add tests
#84283
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