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

migration(crons): Add MonitorIncident table #56435

Merged
merged 9 commits into from
Sep 20, 2023

Conversation

rjo100
Copy link
Contributor

@rjo100 rjo100 commented Sep 18, 2023

Adds MonitorIncidentTable to keep track of open monitor incidents + display them on the timeline view.

If a failure threshold is set, we will open an incident and tag it with the appropriate hash and reference the checkin that caused it to pass the threshold.

If a recovery threshold is set, we will find any incident with the appropriate hash and set it as the closing_checkin.

In the future, if no thresholds are set, we will move to this behavior. But for now, we will keep existing behavior as-is.

The thresholds can be derived from the checkin configs, though we may want to add them as top level fields.

Closes #56402
Rework of #56403

@rjo100 rjo100 requested review from a team as code owners September 18, 2023 22:20
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Sep 18, 2023
@github-actions

This comment was marked as outdated.

@codecov
Copy link

codecov bot commented Sep 18, 2023

Codecov Report

Merging #56435 (cf26dcc) into master (b194ebd) will increase coverage by 1.21%.
The diff coverage is 100.00%.

❗ Current head cf26dcc differs from pull request most recent head d2bb1f9. Consider uploading reports for the commit d2bb1f9 to get more accurate results

@@            Coverage Diff             @@
##           master   #56435      +/-   ##
==========================================
+ Coverage   77.41%   78.62%   +1.21%     
==========================================
  Files        5081     5078       -3     
  Lines      218868   218355     -513     
  Branches    37068    36963     -105     
==========================================
+ Hits       169435   171686    +2251     
+ Misses      43787    41133    -2654     
+ Partials     5646     5536     -110     
Files Changed Coverage
src/sentry/monitors/models.py 100.00%

starting_checkin = FlexibleForeignKey(
"sentry.MonitorCheckIn", null=True, related_name="created_incidents"
)
starting_timestamp = models.DateTimeField(null=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

might not want to allow this to be null

Copy link
Member

Choose a reason for hiding this comment

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

Would you ever have a MonitorIncident that lacks a starting checkin and time?

@github-actions
Copy link
Contributor

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

--
-- Create model MonitorIncident
--
CREATE TABLE "sentry_monitorincident" ("id" bigserial NOT NULL PRIMARY KEY, "starting_timestamp" timestamp with time zone NULL, "resolving_timestamp" timestamp with time zone NULL, "grouphash" varchar(32) NOT NULL, "date_added" timestamp with time zone NOT NULL, "monitor_id" bigint NOT NULL, "monitor_environment_id" bigint NOT NULL, "resolving_checkin_id" bigint NULL, "starting_checkin_id" bigint NULL);
ALTER TABLE "sentry_monitorincident" ADD CONSTRAINT "sentry_monitorincident_monitor_id_0a9c5983_fk_sentry_monitor_id" FOREIGN KEY ("monitor_id") REFERENCES "sentry_monitor" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_monitorincident" VALIDATE CONSTRAINT "sentry_monitorincident_monitor_id_0a9c5983_fk_sentry_monitor_id";
ALTER TABLE "sentry_monitorincident" ADD CONSTRAINT "sentry_monitorincide_monitor_environment__30d108cb_fk_sentry_mo" FOREIGN KEY ("monitor_environment_id") REFERENCES "sentry_monitorenvironment" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_monitorincident" VALIDATE CONSTRAINT "sentry_monitorincide_monitor_environment__30d108cb_fk_sentry_mo";
ALTER TABLE "sentry_monitorincident" ADD CONSTRAINT "sentry_monitorincide_resolving_checkin_id_9b2daf6a_fk_sentry_mo" FOREIGN KEY ("resolving_checkin_id") REFERENCES "sentry_monitorcheckin" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_monitorincident" VALIDATE CONSTRAINT "sentry_monitorincide_resolving_checkin_id_9b2daf6a_fk_sentry_mo";
ALTER TABLE "sentry_monitorincident" ADD CONSTRAINT "sentry_monitorincide_starting_checkin_id_fc465c34_fk_sentry_mo" FOREIGN KEY ("starting_checkin_id") REFERENCES "sentry_monitorcheckin" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_monitorincident" VALIDATE CONSTRAINT "sentry_monitorincide_starting_checkin_id_fc465c34_fk_sentry_mo";
CREATE INDEX CONCURRENTLY "sentry_monitorincident_monitor_id_0a9c5983" ON "sentry_monitorincident" ("monitor_id");
CREATE INDEX CONCURRENTLY "sentry_monitorincident_monitor_environment_id_30d108cb" ON "sentry_monitorincident" ("monitor_environment_id");
CREATE INDEX CONCURRENTLY "sentry_monitorincident_resolving_checkin_id_9b2daf6a" ON "sentry_monitorincident" ("resolving_checkin_id");
CREATE INDEX CONCURRENTLY "sentry_monitorincident_starting_checkin_id_fc465c34" ON "sentry_monitorincident" ("starting_checkin_id");

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 looks good to me.

@github-actions
Copy link
Contributor

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

--
-- Create model MonitorIncident
--
CREATE TABLE "sentry_monitorincident" ("id" bigserial NOT NULL PRIMARY KEY, "starting_timestamp" timestamp with time zone NULL, "resolving_timestamp" timestamp with time zone NULL, "grouphash" varchar(32) NOT NULL, "date_added" timestamp with time zone NOT NULL, "monitor_id" bigint NOT NULL, "monitor_environment_id" bigint NOT NULL, "resolving_checkin_id" bigint NULL, "starting_checkin_id" bigint NULL);
ALTER TABLE "sentry_monitorincident" ADD CONSTRAINT "sentry_monitorincident_monitor_id_0a9c5983_fk_sentry_monitor_id" FOREIGN KEY ("monitor_id") REFERENCES "sentry_monitor" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_monitorincident" VALIDATE CONSTRAINT "sentry_monitorincident_monitor_id_0a9c5983_fk_sentry_monitor_id";
ALTER TABLE "sentry_monitorincident" ADD CONSTRAINT "sentry_monitorincide_monitor_environment__30d108cb_fk_sentry_mo" FOREIGN KEY ("monitor_environment_id") REFERENCES "sentry_monitorenvironment" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_monitorincident" VALIDATE CONSTRAINT "sentry_monitorincide_monitor_environment__30d108cb_fk_sentry_mo";
ALTER TABLE "sentry_monitorincident" ADD CONSTRAINT "sentry_monitorincide_resolving_checkin_id_9b2daf6a_fk_sentry_mo" FOREIGN KEY ("resolving_checkin_id") REFERENCES "sentry_monitorcheckin" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_monitorincident" VALIDATE CONSTRAINT "sentry_monitorincide_resolving_checkin_id_9b2daf6a_fk_sentry_mo";
ALTER TABLE "sentry_monitorincident" ADD CONSTRAINT "sentry_monitorincide_starting_checkin_id_fc465c34_fk_sentry_mo" FOREIGN KEY ("starting_checkin_id") REFERENCES "sentry_monitorcheckin" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_monitorincident" VALIDATE CONSTRAINT "sentry_monitorincide_starting_checkin_id_fc465c34_fk_sentry_mo";
CREATE INDEX CONCURRENTLY "sentry_monitorincident_monitor_id_0a9c5983" ON "sentry_monitorincident" ("monitor_id");
CREATE INDEX CONCURRENTLY "sentry_monitorincident_monitor_environment_id_30d108cb" ON "sentry_monitorincident" ("monitor_environment_id");
CREATE INDEX CONCURRENTLY "sentry_monitorincident_resolving_checkin_id_9b2daf6a" ON "sentry_monitorincident" ("resolving_checkin_id");
CREATE INDEX CONCURRENTLY "sentry_monitorincident_starting_checkin_id_fc465c34" ON "sentry_monitorincident" ("starting_checkin_id");

@rjo100 rjo100 merged commit 49faf7c into master Sep 20, 2023
48 of 49 checks passed
@rjo100 rjo100 deleted the rjo100/initial-monitorincident-table branch September 20, 2023 17:00
@github-actions github-actions bot locked and limited conversation to collaborators Oct 6, 2023
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create Table migration
3 participants