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

add partitioning to pg_telemetry SimpleMetric model #241

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
4 changes: 1 addition & 3 deletions shared/django_apps/db_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@
POSTGRES_EXTRA_DB_BACKEND_BASE: "django_prometheus.db.backends.postgresql" # type: ignore

# Allows to use the pgpartition command
PSQLEXTRA_PARTITIONING_MANAGER = (
"shared.django_apps.user_measurements.partitioning.manager"
)
PSQLEXTRA_PARTITIONING_MANAGER = "shared.django_apps.partitioning.manager"

DATABASE_ROUTERS = [
"shared.django_apps.db_routers.MultiDatabaseRouter",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
)
from psqlextra.partitioning.config import PostgresPartitioningConfig

from shared.django_apps.pg_telemetry.models import SimpleMetric
from shared.django_apps.user_measurements.models import UserMeasurement

# Overlapping partitions will cause errors - https://www.postgresql.org/docs/current/ddl-partitioning.html#DDL-PARTITIONING-DECLARATIVE -> "create partitions"
Expand All @@ -23,5 +24,13 @@
max_age=relativedelta(months=12),
),
),
PostgresPartitioningConfig(
model=SimpleMetric,
strategy=PostgresCurrentTimePartitioningStrategy(
size=PostgresTimePartitionSize(months=1),
count=3,
max_age=relativedelta(months=6),
),
),
]
)
8 changes: 7 additions & 1 deletion shared/django_apps/pg_telemetry/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from django.conf import settings
from django.db import models
from psqlextra.models import PostgresPartitionedModel
from psqlextra.types import PostgresPartitioningMethod


class BaseModel(models.Model):
class BaseModel(PostgresPartitionedModel):
"""
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
Expand All @@ -13,6 +15,10 @@ class BaseModel(models.Model):
Timescale for a time, we'll pick one.
"""

class PartitioningMeta:
method = PostgresPartitioningMethod.RANGE
key = ["timestamp"]

class Meta:
abstract = True

Expand Down
Loading