Skip to content

Commit 04493d2

Browse files
committed
remove FeatureExposure and SimpleMetric models
1 parent efeee11 commit 04493d2

File tree

6 files changed

+31
-141
lines changed

6 files changed

+31
-141
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Generated by Django 4.2.16 on 2025-03-12 17:24
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("pg_telemetry", "0001_initial"),
9+
]
10+
11+
operations = [
12+
migrations.DeleteModel(
13+
name="SimpleMetric",
14+
),
15+
]
+1-58
Original file line numberDiff line numberDiff line change
@@ -1,58 +1 @@
1-
from django.conf import settings
2-
from django.db import models
3-
4-
5-
class BaseModel(models.Model):
6-
"""
7-
Base model for timeseries metrics. It provides a timestamp field which
8-
represents the time that the data sample was captured at and a few metadata
9-
fields that we can filter or group by to investigate issues or identify
10-
trends.
11-
12-
This is the Postgres version. After data flows through both Postgres and
13-
Timescale for a time, we'll pick one.
14-
"""
15-
16-
class Meta:
17-
abstract = True
18-
19-
timestamp = models.DateTimeField(null=False, primary_key=True)
20-
21-
repo_id = models.BigIntegerField(null=True)
22-
owner_id = models.BigIntegerField(null=True)
23-
commit_id = models.BigIntegerField(null=True)
24-
25-
def save(self, *args, **kwargs):
26-
if settings.TELEMETRY_VANILLA_DB:
27-
kwargs["using"] = settings.TELEMETRY_VANILLA_DB
28-
super().save(*args, **kwargs)
29-
30-
31-
class SimpleMetric(BaseModel):
32-
"""
33-
Model for the `telemetry_simple` table which houses many simple metrics.
34-
Rather than create a bespoke model, table, and db migration for each timer
35-
or quantity we want to measure, we put it in `telemetry_simple`.
36-
37-
Examples could include `list_repos_duration_seconds` or `uploads_processed`
38-
39-
This is the Postgres version. After data flows through both Postgres and
40-
Timescale for a time, we'll pick one.
41-
"""
42-
43-
class Meta(BaseModel.Meta):
44-
db_table = "telemetry_simple"
45-
indexes = [
46-
models.Index(
47-
fields=[
48-
"name",
49-
"timestamp",
50-
"repo_id",
51-
"owner_id",
52-
"commit_id",
53-
],
54-
),
55-
]
56-
57-
name = models.TextField(null=False)
58-
value = models.FloatField(null=False)
1+
# TODO: Delete this Django app after deploying the migration to drop its tables
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Generated by Django 4.2.16 on 2025-03-12 17:19
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("rollouts", "0005_featureflag_is_active_featureflag_platform_and_more"),
9+
]
10+
11+
operations = [
12+
migrations.DeleteModel(
13+
name="FeatureExposure",
14+
),
15+
]

shared/django_apps/rollouts/models.py

-41
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from django.core.exceptions import ValidationError
21
from django.db import models
32
from django_better_admin_arrayfield.models.fields import ArrayField
43

@@ -118,43 +117,3 @@ class Meta:
118117

119118
def __str__(self):
120119
return self.feature_flag.__str__() + ": " + self.name
121-
122-
123-
class FeatureExposure(models.Model):
124-
"""
125-
Represents a feature variant being exposed to an entity (repo or owner) at
126-
a point in time. Used to keep track of when features and variants have been enabled
127-
and who they affected for experimentation purposes.
128-
"""
129-
130-
exposure_id = models.AutoField(primary_key=True)
131-
feature_flag = models.ForeignKey(
132-
"FeatureFlag", on_delete=models.CASCADE, related_name="exposures"
133-
)
134-
feature_flag_variant = models.ForeignKey(
135-
"FeatureFlagVariant", on_delete=models.CASCADE, related_name="exposures"
136-
)
137-
138-
# Weak foreign keys to Owner and Respository models respectively
139-
owner = models.IntegerField(null=True, blank=True)
140-
repo = models.IntegerField(null=True, blank=True)
141-
142-
timestamp = models.DateTimeField(null=False)
143-
144-
def clean(self):
145-
if not self.owner and not self.repo:
146-
raise ValidationError(
147-
"Exposure must have either a corresponding owner or repo"
148-
)
149-
150-
super(FeatureExposure, self).clean()
151-
152-
def save(self, *args, **kwargs):
153-
self.full_clean()
154-
super(FeatureExposure, self).save(*args, **kwargs)
155-
156-
class Meta:
157-
db_table = "feature_exposures"
158-
# indexes = [ # don't use indexes for now
159-
# models.Index(fields=['feature_flag', 'timestamp'], name='feature_flag_timestamp_idx'),
160-
# ]

tests/unit/django_apps/pg_telemetry/test_pg_models.py

-35
This file was deleted.

tests/unit/django_apps/test_db_routers.py

-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from shared.django_apps.codecov_auth.models import Owner
44
from shared.django_apps.db_routers import MultiDatabaseRouter
5-
from shared.django_apps.pg_telemetry.models import SimpleMetric as PgSimpleMetric
65

76

87
class TestMultiDatabaseRouter:
@@ -17,7 +16,6 @@ def test_db_for_read_read_replica(self, mocker):
1716

1817
router = MultiDatabaseRouter()
1918
assert router.db_for_read(Owner) == "timeseries_read"
20-
assert router.db_for_read(PgSimpleMetric) == "default_read"
2119

2220
@override_settings(
2321
TIMESERIES_DATABASE_READ_REPLICA_ENABLED=False,
@@ -30,7 +28,6 @@ def test_db_for_read_no_read_replica(self, mocker):
3028

3129
router = MultiDatabaseRouter()
3230
assert router.db_for_read(Owner) == "timeseries"
33-
assert router.db_for_read(PgSimpleMetric) == "default"
3431

3532
def test_db_for_write(self, mocker):
3633
# At time of writing, the Django timeseries models don't live in this
@@ -39,7 +36,6 @@ def test_db_for_write(self, mocker):
3936

4037
router = MultiDatabaseRouter()
4138
assert router.db_for_write(Owner) == "timeseries"
42-
assert router.db_for_write(PgSimpleMetric) == "default"
4339

4440
@override_settings(TIMESERIES_ENABLED=True)
4541
def test_allow_migrate_timeseries_enabled(self):
@@ -96,6 +92,3 @@ def test_allow_relation(self, mocker):
9692

9793
router = MultiDatabaseRouter()
9894
assert router.allow_relation(Owner, Owner) == True
99-
assert router.allow_relation(PgSimpleMetric, Owner) == False
100-
assert router.allow_relation(Owner, PgSimpleMetric) == False
101-
assert router.allow_relation(PgSimpleMetric, PgSimpleMetric) == True

0 commit comments

Comments
 (0)