test_group.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. from sentry.issues.grouptype import PerformanceNPlusOneGroupType
  2. from sentry.models import Group
  3. from sentry.testutils import SnubaTestCase, TestCase
  4. from sentry.testutils.helpers.datetime import before_now, iso_format
  5. from sentry.testutils.silo import region_silo_test
  6. from sentry.utils.samples import load_data
  7. @region_silo_test
  8. class GroupTestSnuba(TestCase, SnubaTestCase):
  9. def test_get_oldest_latest_for_environments(self):
  10. project = self.create_project()
  11. min_ago = iso_format(before_now(minutes=1))
  12. self.store_event(
  13. data={
  14. "event_id": "a" * 32,
  15. "environment": "production",
  16. "timestamp": min_ago,
  17. "fingerprint": ["group-1"],
  18. },
  19. project_id=project.id,
  20. )
  21. self.store_event(
  22. data={
  23. "event_id": "b" * 32,
  24. "environment": "production",
  25. "timestamp": min_ago,
  26. "fingerprint": ["group-1"],
  27. },
  28. project_id=project.id,
  29. )
  30. self.store_event(
  31. data={"event_id": "c" * 32, "timestamp": min_ago, "fingerprint": ["group-1"]},
  32. project_id=project.id,
  33. )
  34. group = Group.objects.first()
  35. assert group.get_latest_event_for_environments().event_id == "c" * 32
  36. assert group.get_latest_event_for_environments(["staging"]) is None
  37. assert group.get_latest_event_for_environments(["production"]).event_id == "b" * 32
  38. assert group.get_oldest_event_for_environments().event_id == "a" * 32
  39. assert (
  40. group.get_oldest_event_for_environments(["staging", "production"]).event_id == "a" * 32
  41. )
  42. assert group.get_oldest_event_for_environments(["staging"]) is None
  43. def test_perf_issue(self):
  44. group_fingerprint = f"{PerformanceNPlusOneGroupType.type_id}-group1"
  45. event_data_1 = load_data("transaction", fingerprint=[group_fingerprint])
  46. event_data_1["timestamp"] = iso_format(before_now(seconds=10))
  47. event_data_1["start_timestamp"] = iso_format(before_now(seconds=11))
  48. event_data_1["event_id"] = "d" * 32
  49. event_data_2 = load_data("transaction", fingerprint=[group_fingerprint])
  50. event_data_2["timestamp"] = iso_format(before_now(seconds=20))
  51. event_data_2["start_timestamp"] = iso_format(before_now(seconds=21))
  52. event_data_2["event_id"] = "f" * 32
  53. event_data_3 = load_data("transaction", fingerprint=[group_fingerprint])
  54. event_data_3["timestamp"] = iso_format(before_now(seconds=30))
  55. event_data_3["start_timestamp"] = iso_format(before_now(seconds=31))
  56. event_data_3["event_id"] = "f" * 32
  57. self.transaction_event_1 = self.store_event(data=event_data_1, project_id=self.project.id)
  58. self.transaction_event_2 = self.store_event(data=event_data_2, project_id=self.project.id)
  59. self.transaction_event_3 = self.store_event(data=event_data_3, project_id=self.project.id)
  60. perf_group = self.transaction_event_1.groups[0]
  61. assert perf_group.get_latest_event_for_environments().event_id == "d" * 32
  62. assert perf_group.get_oldest_event_for_environments().event_id == "f" * 32
  63. def test_perf_issue_issue_platform(self):
  64. # Just a duplicate of `test_perf_issue` to verify that perf issues read from
  65. # the issue platform correctly here. Remove once we kill the related flags.
  66. group_fingerprint = f"{PerformanceNPlusOneGroupType.type_id}-group1"
  67. event_data_1 = load_data("transaction", fingerprint=[group_fingerprint])
  68. event_data_1["timestamp"] = iso_format(before_now(seconds=10))
  69. event_data_1["start_timestamp"] = iso_format(before_now(seconds=11))
  70. event_data_1["event_id"] = "d" * 32
  71. event_data_2 = load_data("transaction", fingerprint=[group_fingerprint])
  72. event_data_2["timestamp"] = iso_format(before_now(seconds=20))
  73. event_data_2["start_timestamp"] = iso_format(before_now(seconds=21))
  74. event_data_2["event_id"] = "f" * 32
  75. event_data_3 = load_data("transaction", fingerprint=[group_fingerprint])
  76. event_data_3["timestamp"] = iso_format(before_now(seconds=30))
  77. event_data_3["start_timestamp"] = iso_format(before_now(seconds=31))
  78. event_data_3["event_id"] = "f" * 32
  79. with self.options({"performance.issues.send_to_issues_platform": True}):
  80. self.transaction_event_1 = self.store_event(
  81. data=event_data_1, project_id=self.project.id
  82. )
  83. self.transaction_event_2 = self.store_event(
  84. data=event_data_2, project_id=self.project.id
  85. )
  86. self.transaction_event_3 = self.store_event(
  87. data=event_data_3, project_id=self.project.id
  88. )
  89. perf_group = self.transaction_event_1.groups[0]
  90. with self.feature("organizations:issue-platform-search-perf-issues"):
  91. assert perf_group.get_latest_event_for_environments().event_id == "d" * 32
  92. assert perf_group.get_oldest_event_for_environments().event_id == "f" * 32