-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Conversation
This PR has a migration; here is the generated SQL for --
-- 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"); |
There was a problem hiding this 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!
Codecov ReportAll 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 |
🚨 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 |
Bundle ReportChanges will increase total bundle size by 41.88kB (0.13%) ⬆️. This is within the configured threshold ✅ Detailed changes
|
src/sentry/workflow_engine/migrations/0015_create_rule_lookup_tables.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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.
src/sentry/workflow_engine/migrations/0015_create_rule_lookup_tables.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Mark Story <[email protected]>
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>
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