Skip to content

Commit 30340e8

Browse files
author
NisanthanNanthakumar
authored
feat(escalating-issues): Migration to create GroupForecast table (#45971)
## Objective: New table to hold the forecasts for archived groups. We will check if a group's events has exceeded a forecast to bump it into the `escalating` status.
1 parent 761c507 commit 30340e8

File tree

4 files changed

+87
-1
lines changed

4 files changed

+87
-1
lines changed

migrations_lockfile.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ To resolve this, rebase against latest master and regenerate your migration. Thi
66
will then be regenerated, and you should be able to merge without conflicts.
77

88
nodestore: 0002_nodestore_no_dictfield
9-
sentry: 0392_add_date_uploaded_field_to_bundle
9+
sentry: 0393_create_groupforecast_table
1010
social_auth: 0001_initial
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Generated by Django 2.2.28 on 2023-03-22 16:21
2+
3+
import django.db.models.deletion
4+
import django.utils.timezone
5+
from django.db import migrations, models
6+
7+
import sentry.db.models.fields.array
8+
import sentry.db.models.fields.bounded
9+
import sentry.db.models.fields.foreignkey
10+
from sentry.new_migrations.migrations import CheckedMigration
11+
12+
13+
class Migration(CheckedMigration):
14+
# This flag is used to mark that a migration shouldn't be automatically run in production. For
15+
# the most part, this should only be used for operations where it's safe to run the migration
16+
# after your code has deployed. So this should not be used for most operations that alter the
17+
# schema of a table.
18+
# Here are some things that make sense to mark as dangerous:
19+
# - Large data migrations. Typically we want these to be run manually by ops so that they can
20+
# be monitored and not block the deploy for a long period of time while they run.
21+
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
22+
# have ops run this and not block the deploy. Note that while adding an index is a schema
23+
# change, it's completely safe to run the operation after the code has deployed.
24+
is_dangerous = False
25+
26+
dependencies = [
27+
("sentry", "0392_add_date_uploaded_field_to_bundle"),
28+
]
29+
30+
operations = [
31+
migrations.CreateModel(
32+
name="GroupForecast",
33+
fields=[
34+
(
35+
"id",
36+
sentry.db.models.fields.bounded.BoundedBigAutoField(
37+
primary_key=True, serialize=False
38+
),
39+
),
40+
("forecast", sentry.db.models.fields.array.ArrayField(null=True)),
41+
("date_added", models.DateTimeField(default=django.utils.timezone.now)),
42+
(
43+
"group",
44+
sentry.db.models.fields.foreignkey.FlexibleForeignKey(
45+
on_delete=django.db.models.deletion.CASCADE, to="sentry.Group", unique=True
46+
),
47+
),
48+
],
49+
options={
50+
"db_table": "sentry_groupforecast",
51+
},
52+
),
53+
]

src/sentry/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
from .groupcommitresolution import * # NOQA
4343
from .groupemailthread import * # NOQA
4444
from .groupenvironment import * # NOQA
45+
from .groupforecast import * # NOQA
4546
from .grouphash import * # NOQA
4647
from .grouphistory import * # NOQA
4748
from .groupinbox import * # NOQA

src/sentry/models/groupforecast.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from django.db import models
2+
from django.utils import timezone
3+
4+
from sentry.db.models import (
5+
ArrayField,
6+
BoundedPositiveIntegerField,
7+
FlexibleForeignKey,
8+
Model,
9+
region_silo_only_model,
10+
)
11+
12+
13+
@region_silo_only_model
14+
class GroupForecast(Model):
15+
"""
16+
Stores the forecast of expected counts of events for a Group
17+
18+
``forecast`` will hold an array of integers. The length of the array
19+
is the difference between `date_created` and `valid_until`. Each integer
20+
maps to the days in the range of `date_created` and `valid_until`.
21+
22+
"""
23+
24+
__include_in_export__ = False
25+
26+
group = FlexibleForeignKey("sentry.Group", unique=True)
27+
forecast = ArrayField(of=BoundedPositiveIntegerField, null=True)
28+
date_added = models.DateTimeField(default=timezone.now)
29+
30+
class Meta:
31+
app_label = "sentry"
32+
db_table = "sentry_groupforecast"

0 commit comments

Comments
 (0)