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

chore(aci): add WorkflowFireHistory model #88472

Merged
merged 5 commits into from
Apr 2, 2025

Conversation

cathteng
Copy link
Member

@cathteng cathteng commented Apr 1, 2025

We need a WorkflowFireHistory model to support the workflow engine equivalent of the fire history graph and table that currently exists for issue alerts

Screenshot 2025-04-01 at 11 51 30

@cathteng cathteng requested review from a team as code owners April 1, 2025 18:52
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 1, 2025
Copy link
Contributor

github-actions bot commented Apr 1, 2025

This PR has a migration; here is the generated SQL for src/sentry/workflow_engine/migrations/0039_workflow_fire_history_table.py ()

--
-- Create model WorkflowFireHistory
--
CREATE TABLE "workflow_engine_workflowfirehistory" ("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, "event_id" text NOT NULL, "notification_uuid" uuid NOT NULL UNIQUE, "group_id" bigint NOT NULL, "workflow_id" bigint NOT NULL);
ALTER TABLE "workflow_engine_workflowfirehistory" ADD CONSTRAINT "workflow_engine_work_group_id_d0001482_fk_sentry_gr" FOREIGN KEY ("group_id") REFERENCES "sentry_groupedmessage" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "workflow_engine_workflowfirehistory" VALIDATE CONSTRAINT "workflow_engine_work_group_id_d0001482_fk_sentry_gr";
ALTER TABLE "workflow_engine_workflowfirehistory" ADD CONSTRAINT "workflow_engine_work_workflow_id_7c271053_fk_workflow_" FOREIGN KEY ("workflow_id") REFERENCES "workflow_engine_workflow" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "workflow_engine_workflowfirehistory" VALIDATE CONSTRAINT "workflow_engine_work_workflow_id_7c271053_fk_workflow_";
CREATE INDEX CONCURRENTLY "workflow_engine_workflowfirehistory_group_id_d0001482" ON "workflow_engine_workflowfirehistory" ("group_id");
CREATE INDEX CONCURRENTLY "workflow_engine_workflowfirehistory_workflow_id_7c271053" ON "workflow_engine_workflowfirehistory" ("workflow_id");

Comment on lines 12 to 13
workflow = FlexibleForeignKey("workflow_engine.Workflow", db_constraint=False)
group = FlexibleForeignKey("sentry.Group", db_constraint=False)
Copy link
Member

Choose a reason for hiding this comment

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

Why db_constraint=False here?

Copy link
Member Author

Choose a reason for hiding this comment

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

idk i copied what you did here, i should probably at least add the constraint back to workflow

project = FlexibleForeignKey("sentry.Project", db_constraint=False)
rule = FlexibleForeignKey("sentry.Rule")
group = FlexibleForeignKey("sentry.Group", db_constraint=False)

Copy link
Member Author

Choose a reason for hiding this comment

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

seems like DB constraint is false in case the group is deleted, we still want to have a record of when the rule fired?

Copy link
Member

Choose a reason for hiding this comment

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

At the time it was risky to add relations to busy tables like Project and Group, since we didn't have our migration safety framework in place. It's not a problem anymore, so you're better off putting these constraints in.

Setting db_constraint=False doesn't prevent cascade deletions, all it does it remove the db level fk.

Copy link
Member Author

Choose a reason for hiding this comment

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

added it back in, i think cascade deletions is fine



@region_silo_model
class WorkflowFireHistory(DefaultFieldsModel):
Copy link
Member

Choose a reason for hiding this comment

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

Do we need notification_uuid like in the previous table?

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'm not sure what it's used for, need to check

Copy link
Member Author

Choose a reason for hiding this comment

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

added it back in

@cathteng cathteng requested a review from wedamija April 2, 2025 15:38
workflow = FlexibleForeignKey("workflow_engine.Workflow")
group = FlexibleForeignKey("sentry.Group")
event_id = CharField(max_length=32)
notification_uuid = UUIDField(auto_add=True, unique=True)
Copy link
Member

Choose a reason for hiding this comment

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

I don't really know how this col is used, but I just want to check that it's valid to always have a notification uuid here?

Copy link
Member Author

Choose a reason for hiding this comment

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

currently no rows in RuleFireHistory have a null notification_uuid so it's ok to require

@cathteng cathteng merged commit 9727880 into master Apr 2, 2025
48 checks passed
@cathteng cathteng deleted the cathy/aci/workflow-fire-history-model branch April 2, 2025 17:50
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