partitioning.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from dateutil.relativedelta import relativedelta
  2. from django.conf import settings
  3. from apps.issue_events.models import IssueEvent, IssueTag
  4. from apps.performance.models import TransactionEvent
  5. from apps.projects.models import (
  6. IssueEventProjectHourlyStatistic,
  7. TransactionEventProjectHourlyStatistic,
  8. )
  9. from apps.uptime.models import MonitorCheck
  10. from psqlextra.partitioning import (
  11. PostgresCurrentTimePartitioningStrategy,
  12. PostgresPartitioningManager,
  13. PostgresTimePartitionSize,
  14. )
  15. from psqlextra.partitioning.config import PostgresPartitioningConfig
  16. issue_strategy = PostgresCurrentTimePartitioningStrategy(
  17. size=PostgresTimePartitionSize(days=1),
  18. count=7,
  19. max_age=relativedelta(days=settings.GLITCHTIP_MAX_EVENT_LIFE_DAYS),
  20. )
  21. transaction_strategy = PostgresCurrentTimePartitioningStrategy(
  22. size=PostgresTimePartitionSize(days=1),
  23. count=7,
  24. max_age=relativedelta(days=settings.GLITCHTIP_MAX_TRANSACTION_EVENT_LIFE_DAYS),
  25. )
  26. project_stat_strategy = PostgresCurrentTimePartitioningStrategy(
  27. size=PostgresTimePartitionSize(weeks=1),
  28. count=4,
  29. max_age=relativedelta(days=settings.GLITCHTIP_MAX_EVENT_LIFE_DAYS * 4),
  30. )
  31. uptime_strategy = PostgresCurrentTimePartitioningStrategy(
  32. size=PostgresTimePartitionSize(days=1),
  33. count=4,
  34. max_age=relativedelta(days=settings.GLITCHTIP_MAX_UPTIME_CHECK_LIFE_DAYS),
  35. )
  36. manager = PostgresPartitioningManager(
  37. [
  38. PostgresPartitioningConfig(model=IssueEvent, strategy=issue_strategy),
  39. PostgresPartitioningConfig(model=IssueTag, strategy=issue_strategy),
  40. PostgresPartitioningConfig(
  41. model=TransactionEvent, strategy=transaction_strategy
  42. ),
  43. PostgresPartitioningConfig(
  44. model=IssueEventProjectHourlyStatistic, strategy=project_stat_strategy
  45. ),
  46. PostgresPartitioningConfig(
  47. model=TransactionEventProjectHourlyStatistic, strategy=project_stat_strategy
  48. ),
  49. PostgresPartitioningConfig(model=MonitorCheck, strategy=uptime_strategy),
  50. ]
  51. )