Skip to content

feat(aci): add WorkflowActionGroupStatus table #91993

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 3 commits into from
May 21, 2025

Conversation

cathteng
Copy link
Member

Rather than adding a non-nullable Workflow FK column to ActionGroupStatus and backfilling it, we can just create a new table and switch over, eventually dropping ActionGroupStatus.

We need the Workflow in order to enforce workflow frequency per action. In the future, actions may be shared between multiple workflows.

Example:
Workflow A: frequency 5 min

  • Action A

Workflow B: frequency 30 min

  • Action A

Workflow A should fire Action A every 5 min for a group. Workflow B should fire Action A every 30 min for that same group. If we don't have Workflow on ActionGroupStatus, then both workflows will "share" the most recent firing (read from the same row) and the interval can get wonky. Workflow B may not fire at 30 minute intervals if Workflow A keeps triggering Action A.

@cathteng cathteng requested review from a team as code owners May 20, 2025 23:13
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label May 20, 2025
Copy link
Contributor

This PR has a migration; here is the generated SQL for src/sentry/workflow_engine/migrations/0066_workflow_action_group_status_table.py

for 0066_workflow_action_group_status_table in workflow_engine

--
-- Create model WorkflowActionGroupStatus
--
CREATE TABLE "workflow_engine_workflowactiongroupstatus" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "date_updated" timestamp with time zone NOT NULL, "date_added" timestamp with time zone NOT NULL, "action_id" bigint NOT NULL, "group_id" bigint NOT NULL, "workflow_id" bigint NOT NULL, CONSTRAINT "workflow_engine_uniq_workflow_action_group" UNIQUE ("workflow_id", "action_id", "group_id"));
ALTER TABLE "workflow_engine_workflowactiongroupstatus" ADD CONSTRAINT "workflow_engine_work_action_id_b4d629d5_fk_workflow_" FOREIGN KEY ("action_id") REFERENCES "workflow_engine_action" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "workflow_engine_workflowactiongroupstatus" VALIDATE CONSTRAINT "workflow_engine_work_action_id_b4d629d5_fk_workflow_";
ALTER TABLE "workflow_engine_workflowactiongroupstatus" ADD CONSTRAINT "workflow_engine_work_group_id_89305015_fk_sentry_gr" FOREIGN KEY ("group_id") REFERENCES "sentry_groupedmessage" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "workflow_engine_workflowactiongroupstatus" VALIDATE CONSTRAINT "workflow_engine_work_group_id_89305015_fk_sentry_gr";
ALTER TABLE "workflow_engine_workflowactiongroupstatus" ADD CONSTRAINT "workflow_engine_work_workflow_id_8110df1d_fk_workflow_" FOREIGN KEY ("workflow_id") REFERENCES "workflow_engine_workflow" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "workflow_engine_workflowactiongroupstatus" VALIDATE CONSTRAINT "workflow_engine_work_workflow_id_8110df1d_fk_workflow_";
CREATE INDEX CONCURRENTLY "workflow_engine_workflowactiongroupstatus_action_id_b4d629d5" ON "workflow_engine_workflowactiongroupstatus" ("action_id");
CREATE INDEX CONCURRENTLY "workflow_engine_workflowactiongroupstatus_group_id_89305015" ON "workflow_engine_workflowactiongroupstatus" ("group_id");
CREATE INDEX CONCURRENTLY "workflow_engine_workflowactiongroupstatus_workflow_id_8110df1d" ON "workflow_engine_workflowactiongroupstatus" ("workflow_id");

Copy link

codecov bot commented May 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

⚠️ Parser warning

The parser emitted a warning. Please review your JUnit XML file:

Warning while parsing testcase attributes: Limit of string is 1000 chars, for name, we got 2083 at 1:156310 in /home/runner/work/sentry/sentry/.artifacts/pytest.junit.xml
Additional details and impacted files
@@           Coverage Diff           @@
##           master   #91993   +/-   ##
=======================================
  Coverage   87.86%   87.86%           
=======================================
  Files       10167    10168    +1     
  Lines      582887   582899   +12     
  Branches    22596    22596           
=======================================
+ Hits       512154   512173   +19     
+ Misses      70312    70305    -7     
  Partials      421      421           

@vgrozdanic
Copy link
Member

What is the plan for the switchover? Are we going to double write data to both tables for some time?

I am not very familiar with workflows, but don't we need historic data in the new table, which would still require us to do a backfill?

Stores when a workflow action last fired for a Group.
"""

__relocation_scope__ = RelocationScope.Excluded
Copy link
Member

Choose a reason for hiding this comment

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

If an account is relocated, do we not want the history of their alert workflows to be preserved?

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm this is the workflow engine equivalent to GroupRuleStatus which is excluded from relocation. i'm not entirely sure why, though

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 is much too much data to relocate, we usually exclude things that are related to groups

@cathteng
Copy link
Member Author

@vgrozdanic I will dual write to both tables and then drop the ActionGroupStatus table. The data in this table is not surfaced anywhere right now and will only be surfaced once we switch over to the new UI for workflow engine, which will not be for some time

@cathteng cathteng requested a review from a team May 21, 2025 16:00
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 from the workflow engine perspective, pls make sure to get a migration +1 as well :)

Copy link
Member

@wedamija wedamija left a comment

Choose a reason for hiding this comment

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

Blocking for now, we're squashing migrations. I'll unblock later today

Copy link
Member

@wedamija wedamija left a comment

Choose a reason for hiding this comment

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

Ok, lgtm now. You'll need to recreate your migration on top of the squash. Probably easiest to just delete and recreate it

@cathteng cathteng enabled auto-merge (squash) May 21, 2025 20:35
@cathteng cathteng merged commit 7f0a4df into master May 21, 2025
59 checks passed
@cathteng cathteng deleted the cathy/aci/workflow-action-group-status branch May 21, 2025 20:50
@cathteng cathteng added Trigger: Revert Add to a merged PR to revert it (skips CI) and removed Scope: Backend Automatically applied to PRs that change backend components labels May 21, 2025
@getsentry-bot
Copy link
Contributor

PR reverted: 3be3c80

getsentry-bot added a commit that referenced this pull request May 21, 2025
This reverts commit 7f0a4df.

Co-authored-by: cathteng <70817427+cathteng@users.noreply.github.com>
andrewshie-sentry pushed a commit that referenced this pull request Jun 2, 2025
This reverts commit 7f0a4df.

Co-authored-by: cathteng <70817427+cathteng@users.noreply.github.com>
@github-actions github-actions bot locked and limited conversation to collaborators Jun 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Trigger: Revert Add to a merged PR to revert it (skips CI)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants