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): Add lookup tables for rules #81704

Merged
merged 15 commits into from
Dec 9, 2024

Conversation

ceorourke
Copy link
Member

Add some new lookup tables for rules to be able to relate to the new models during the migration phase. I modeled the constraints off of what we did for the RuleSnooze table since it also has to be either an issue or a metric rule but not both.

Closes https://getsentry.atlassian.net/browse/ACI-20

@ceorourke ceorourke requested a review from a team as a code owner December 4, 2024 23:15
@ceorourke ceorourke requested a review from a team December 4, 2024 23:15
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Dec 4, 2024
Copy link
Contributor

github-actions bot commented Dec 4, 2024

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

--
-- Create model AlertRuleTriggerDataCondition
--
CREATE TABLE "workflow_engine_alertruletriggerdatacondition" ("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, "alert_rule_trigger_id" bigint NOT NULL, "data_condition_id" bigint NOT NULL);
--
-- Create model AlertRuleDetector
--
CREATE TABLE "workflow_engine_alertruledetector" ("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, "alert_rule_id" bigint NULL, "detector_id" bigint NOT NULL, "rule_id" bigint NULL, CONSTRAINT "rule_or_alert_rule_detector" CHECK ((("alert_rule_id" IS NULL AND "rule_id" IS NOT NULL) OR ("alert_rule_id" IS NOT NULL AND "rule_id" IS NULL))));
--
-- Create model AlertRuleWorkflow
--
CREATE TABLE "workflow_engine_alertruleworkflow" ("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, "alert_rule_id" bigint NULL, "rule_id" bigint NULL, "workflow_id" bigint NOT NULL, CONSTRAINT "rule_or_alert_rule_workflow" CHECK ((("alert_rule_id" IS NULL AND "rule_id" IS NOT NULL) OR ("alert_rule_id" IS NOT NULL AND "rule_id" IS NULL))));
ALTER TABLE "workflow_engine_alertruletriggerdatacondition" ADD CONSTRAINT "workflow_engine_aler_alert_rule_trigger_i_319dccbe_fk_sentry_al" FOREIGN KEY ("alert_rule_trigger_id") REFERENCES "sentry_alertruletrigger" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "workflow_engine_alertruletriggerdatacondition" VALIDATE CONSTRAINT "workflow_engine_aler_alert_rule_trigger_i_319dccbe_fk_sentry_al";
ALTER TABLE "workflow_engine_alertruletriggerdatacondition" ADD CONSTRAINT "workflow_engine_aler_data_condition_id_763c5b10_fk_workflow_" FOREIGN KEY ("data_condition_id") REFERENCES "workflow_engine_datacondition" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "workflow_engine_alertruletriggerdatacondition" VALIDATE CONSTRAINT "workflow_engine_aler_data_condition_id_763c5b10_fk_workflow_";
CREATE INDEX CONCURRENTLY "workflow_engine_alertrulet_alert_rule_trigger_id_319dccbe" ON "workflow_engine_alertruletriggerdatacondition" ("alert_rule_trigger_id");
CREATE INDEX CONCURRENTLY "workflow_engine_alertrulet_data_condition_id_763c5b10" ON "workflow_engine_alertruletriggerdatacondition" ("data_condition_id");
CREATE UNIQUE INDEX CONCURRENTLY "workflow_engine_alertrul_detector_id_alert_rule_i_d864d4e5_uniq" ON "workflow_engine_alertruledetector" ("detector_id", "alert_rule_id");
ALTER TABLE "workflow_engine_alertruledetector" ADD CONSTRAINT "workflow_engine_alertrul_detector_id_alert_rule_i_d864d4e5_uniq" UNIQUE USING INDEX "workflow_engine_alertrul_detector_id_alert_rule_i_d864d4e5_uniq";
CREATE UNIQUE INDEX CONCURRENTLY "workflow_engine_alertrul_detector_id_rule_id_72b66958_uniq" ON "workflow_engine_alertruledetector" ("detector_id", "rule_id");
ALTER TABLE "workflow_engine_alertruledetector" ADD CONSTRAINT "workflow_engine_alertrul_detector_id_rule_id_72b66958_uniq" UNIQUE USING INDEX "workflow_engine_alertrul_detector_id_rule_id_72b66958_uniq";
ALTER TABLE "workflow_engine_alertruledetector" ADD CONSTRAINT "workflow_engine_aler_alert_rule_id_c81b0f4b_fk_sentry_al" FOREIGN KEY ("alert_rule_id") REFERENCES "sentry_alertrule" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "workflow_engine_alertruledetector" VALIDATE CONSTRAINT "workflow_engine_aler_alert_rule_id_c81b0f4b_fk_sentry_al";
ALTER TABLE "workflow_engine_alertruledetector" ADD CONSTRAINT "workflow_engine_aler_detector_id_cca73564_fk_workflow_" FOREIGN KEY ("detector_id") REFERENCES "workflow_engine_detector" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "workflow_engine_alertruledetector" VALIDATE CONSTRAINT "workflow_engine_aler_detector_id_cca73564_fk_workflow_";
ALTER TABLE "workflow_engine_alertruledetector" ADD CONSTRAINT "workflow_engine_aler_rule_id_26bc9c69_fk_sentry_ru" FOREIGN KEY ("rule_id") REFERENCES "sentry_rule" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "workflow_engine_alertruledetector" VALIDATE CONSTRAINT "workflow_engine_aler_rule_id_26bc9c69_fk_sentry_ru";
CREATE INDEX CONCURRENTLY "workflow_engine_alertruledetector_alert_rule_id_c81b0f4b" ON "workflow_engine_alertruledetector" ("alert_rule_id");
CREATE INDEX CONCURRENTLY "workflow_engine_alertruledetector_detector_id_cca73564" ON "workflow_engine_alertruledetector" ("detector_id");
CREATE INDEX CONCURRENTLY "workflow_engine_alertruledetector_rule_id_26bc9c69" ON "workflow_engine_alertruledetector" ("rule_id");
CREATE UNIQUE INDEX CONCURRENTLY "workflow_engine_alertrul_workflow_id_alert_rule_i_b4f9c011_uniq" ON "workflow_engine_alertruleworkflow" ("workflow_id", "alert_rule_id");
ALTER TABLE "workflow_engine_alertruleworkflow" ADD CONSTRAINT "workflow_engine_alertrul_workflow_id_alert_rule_i_b4f9c011_uniq" UNIQUE USING INDEX "workflow_engine_alertrul_workflow_id_alert_rule_i_b4f9c011_uniq";
CREATE UNIQUE INDEX CONCURRENTLY "workflow_engine_alertrul_workflow_id_rule_id_d65a1fbe_uniq" ON "workflow_engine_alertruleworkflow" ("workflow_id", "rule_id");
ALTER TABLE "workflow_engine_alertruleworkflow" ADD CONSTRAINT "workflow_engine_alertrul_workflow_id_rule_id_d65a1fbe_uniq" UNIQUE USING INDEX "workflow_engine_alertrul_workflow_id_rule_id_d65a1fbe_uniq";
ALTER TABLE "workflow_engine_alertruleworkflow" ADD CONSTRAINT "workflow_engine_aler_alert_rule_id_952ceb2c_fk_sentry_al" FOREIGN KEY ("alert_rule_id") REFERENCES "sentry_alertrule" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "workflow_engine_alertruleworkflow" VALIDATE CONSTRAINT "workflow_engine_aler_alert_rule_id_952ceb2c_fk_sentry_al";
ALTER TABLE "workflow_engine_alertruleworkflow" ADD CONSTRAINT "workflow_engine_aler_rule_id_c93d1444_fk_sentry_ru" FOREIGN KEY ("rule_id") REFERENCES "sentry_rule" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "workflow_engine_alertruleworkflow" VALIDATE CONSTRAINT "workflow_engine_aler_rule_id_c93d1444_fk_sentry_ru";
ALTER TABLE "workflow_engine_alertruleworkflow" ADD CONSTRAINT "workflow_engine_aler_workflow_id_88b357e4_fk_workflow_" FOREIGN KEY ("workflow_id") REFERENCES "workflow_engine_workflow" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "workflow_engine_alertruleworkflow" VALIDATE CONSTRAINT "workflow_engine_aler_workflow_id_88b357e4_fk_workflow_";
CREATE INDEX CONCURRENTLY "workflow_engine_alertruleworkflow_alert_rule_id_952ceb2c" ON "workflow_engine_alertruleworkflow" ("alert_rule_id");
CREATE INDEX CONCURRENTLY "workflow_engine_alertruleworkflow_rule_id_c93d1444" ON "workflow_engine_alertruleworkflow" ("rule_id");
CREATE INDEX CONCURRENTLY "workflow_engine_alertruleworkflow_workflow_id_88b357e4" ON "workflow_engine_alertruleworkflow" ("workflow_id");

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 - wasn't 100% sure about the dcg vs data condition for alert rule triggers, just want to double check.

let's also get a db reviewer to take a look if possible!

Copy link

codecov bot commented Dec 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #81704      +/-   ##
==========================================
+ Coverage   80.44%   80.65%   +0.20%     
==========================================
  Files        7245     7257      +12     
  Lines      321923   326311    +4388     
  Branches    20822    20822              
==========================================
+ Hits       258987   263184    +4197     
- Misses      62539    62730     +191     
  Partials      397      397              

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Dec 5, 2024
Copy link
Contributor

github-actions bot commented Dec 5, 2024

🚨 Warning: This pull request contains Frontend and Backend changes!

It's discouraged to make changes to Sentry's Frontend and Backend in a single pull request. The Frontend and Backend are not atomically deployed. If the changes are interdependent of each other, they must be separated into two pull requests and be made forward or backwards compatible, such that the Backend or Frontend can be safely deployed independently.

Have questions? Please ask in the #discuss-dev-infra channel.

Copy link

codecov bot commented Dec 5, 2024

Bundle Report

Changes will increase total bundle size by 41.88kB (0.13%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
app-webpack-bundle-array-push 32.0MB 41.88kB (0.13%) ⬆️

Copy link
Member

@markstory markstory left a comment

Choose a reason for hiding this comment

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

Schema changes look good to me. You should consider adding these models to relocations so that alert rules retain their detector workflows on export.

@ceorourke ceorourke merged commit ec1594f into master Dec 9, 2024
50 checks passed
@ceorourke ceorourke deleted the ceorourke/create_aci_lookup_tables branch December 9, 2024 18:10
mifu67 pushed a commit that referenced this pull request Dec 10, 2024
Add some new lookup tables for rules to be able to relate to the new
models during the migration phase. I modeled the constraints off of
[what we did for the `RuleSnooze`
table](https://github.com/getsentry/sentry/blob/master/src/sentry/models/rulesnooze.py#L44)
since it also has to be either an issue or a metric rule but not both.

Closes https://getsentry.atlassian.net/browse/ACI-20

---------

Co-authored-by: Mark Story <[email protected]>
Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
@github-actions github-actions bot locked and limited conversation to collaborators Dec 25, 2024
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 Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants