Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Generated by Django 4.2.16 on 2025-03-12 17:24

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("pg_telemetry", "0001_initial"),
]

operations = [
migrations.DeleteModel(
name="SimpleMetric",
),
]
59 changes: 1 addition & 58 deletions shared/django_apps/pg_telemetry/models.py
Original file line number Diff line number Diff line change
@@ -1,58 +1 @@
from django.conf import settings
from django.db import models


class BaseModel(models.Model):
"""
Base model for timeseries metrics. It provides a timestamp field which
represents the time that the data sample was captured at and a few metadata
fields that we can filter or group by to investigate issues or identify
trends.

This is the Postgres version. After data flows through both Postgres and
Timescale for a time, we'll pick one.
"""

class Meta:
abstract = True

timestamp = models.DateTimeField(null=False, primary_key=True)

repo_id = models.BigIntegerField(null=True)
owner_id = models.BigIntegerField(null=True)
commit_id = models.BigIntegerField(null=True)

def save(self, *args, **kwargs):
if settings.TELEMETRY_VANILLA_DB:
kwargs["using"] = settings.TELEMETRY_VANILLA_DB
super().save(*args, **kwargs)


class SimpleMetric(BaseModel):
"""
Model for the `telemetry_simple` table which houses many simple metrics.
Rather than create a bespoke model, table, and db migration for each timer
or quantity we want to measure, we put it in `telemetry_simple`.

Examples could include `list_repos_duration_seconds` or `uploads_processed`

This is the Postgres version. After data flows through both Postgres and
Timescale for a time, we'll pick one.
"""

class Meta(BaseModel.Meta):
db_table = "telemetry_simple"
indexes = [
models.Index(
fields=[
"name",
"timestamp",
"repo_id",
"owner_id",
"commit_id",
],
),
]

name = models.TextField(null=False)
value = models.FloatField(null=False)
# TODO: Delete this Django app after deploying the migration to drop its tables
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Generated by Django 4.2.16 on 2025-03-12 17:19

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("rollouts", "0005_featureflag_is_active_featureflag_platform_and_more"),
]

operations = [
migrations.DeleteModel(
name="FeatureExposure",
),
]
41 changes: 0 additions & 41 deletions shared/django_apps/rollouts/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from django.core.exceptions import ValidationError
from django.db import models
from django_better_admin_arrayfield.models.fields import ArrayField

Expand Down Expand Up @@ -118,43 +117,3 @@ class Meta:

def __str__(self):
return self.feature_flag.__str__() + ": " + self.name


class FeatureExposure(models.Model):
"""
Represents a feature variant being exposed to an entity (repo or owner) at
a point in time. Used to keep track of when features and variants have been enabled
and who they affected for experimentation purposes.
"""

exposure_id = models.AutoField(primary_key=True)
feature_flag = models.ForeignKey(
"FeatureFlag", on_delete=models.CASCADE, related_name="exposures"
)
feature_flag_variant = models.ForeignKey(
"FeatureFlagVariant", on_delete=models.CASCADE, related_name="exposures"
)

# Weak foreign keys to Owner and Respository models respectively
owner = models.IntegerField(null=True, blank=True)
repo = models.IntegerField(null=True, blank=True)

timestamp = models.DateTimeField(null=False)

def clean(self):
if not self.owner and not self.repo:
raise ValidationError(
"Exposure must have either a corresponding owner or repo"
)

super(FeatureExposure, self).clean()

def save(self, *args, **kwargs):
self.full_clean()
super(FeatureExposure, self).save(*args, **kwargs)

class Meta:
db_table = "feature_exposures"
# indexes = [ # don't use indexes for now
# models.Index(fields=['feature_flag', 'timestamp'], name='feature_flag_timestamp_idx'),
# ]
35 changes: 0 additions & 35 deletions tests/unit/django_apps/pg_telemetry/test_pg_models.py

This file was deleted.

7 changes: 0 additions & 7 deletions tests/unit/django_apps/test_db_routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from shared.django_apps.codecov_auth.models import Owner
from shared.django_apps.db_routers import MultiDatabaseRouter
from shared.django_apps.pg_telemetry.models import SimpleMetric as PgSimpleMetric


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

router = MultiDatabaseRouter()
assert router.db_for_read(Owner) == "timeseries_read"
assert router.db_for_read(PgSimpleMetric) == "default_read"

@override_settings(
TIMESERIES_DATABASE_READ_REPLICA_ENABLED=False,
Expand All @@ -30,7 +28,6 @@ def test_db_for_read_no_read_replica(self, mocker):

router = MultiDatabaseRouter()
assert router.db_for_read(Owner) == "timeseries"
assert router.db_for_read(PgSimpleMetric) == "default"

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

router = MultiDatabaseRouter()
assert router.db_for_write(Owner) == "timeseries"
assert router.db_for_write(PgSimpleMetric) == "default"

@override_settings(TIMESERIES_ENABLED=True)
def test_allow_migrate_timeseries_enabled(self):
Expand Down Expand Up @@ -72,6 +68,3 @@ def test_allow_relation(self, mocker):

router = MultiDatabaseRouter()
assert router.allow_relation(Owner, Owner) == True
assert router.allow_relation(PgSimpleMetric, Owner) == False
assert router.allow_relation(Owner, PgSimpleMetric) == False
assert router.allow_relation(PgSimpleMetric, PgSimpleMetric) == True