123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- from sentry.issues.grouptype import PerformanceNPlusOneGroupType
- from sentry.models import Group
- from sentry.testutils import SnubaTestCase, TestCase
- from sentry.testutils.helpers.datetime import before_now, iso_format
- from sentry.testutils.silo import region_silo_test
- from sentry.utils.samples import load_data
- @region_silo_test
- class GroupTestSnuba(TestCase, SnubaTestCase):
- def test_get_oldest_latest_for_environments(self):
- project = self.create_project()
- min_ago = iso_format(before_now(minutes=1))
- self.store_event(
- data={
- "event_id": "a" * 32,
- "environment": "production",
- "timestamp": min_ago,
- "fingerprint": ["group-1"],
- },
- project_id=project.id,
- )
- self.store_event(
- data={
- "event_id": "b" * 32,
- "environment": "production",
- "timestamp": min_ago,
- "fingerprint": ["group-1"],
- },
- project_id=project.id,
- )
- self.store_event(
- data={"event_id": "c" * 32, "timestamp": min_ago, "fingerprint": ["group-1"]},
- project_id=project.id,
- )
- group = Group.objects.first()
- assert group.get_latest_event_for_environments().event_id == "c" * 32
- assert group.get_latest_event_for_environments(["staging"]) is None
- assert group.get_latest_event_for_environments(["production"]).event_id == "b" * 32
- assert group.get_oldest_event_for_environments().event_id == "a" * 32
- assert (
- group.get_oldest_event_for_environments(["staging", "production"]).event_id == "a" * 32
- )
- assert group.get_oldest_event_for_environments(["staging"]) is None
- def test_perf_issue(self):
- group_fingerprint = f"{PerformanceNPlusOneGroupType.type_id}-group1"
- event_data_1 = load_data("transaction", fingerprint=[group_fingerprint])
- event_data_1["timestamp"] = iso_format(before_now(seconds=10))
- event_data_1["start_timestamp"] = iso_format(before_now(seconds=11))
- event_data_1["event_id"] = "d" * 32
- event_data_2 = load_data("transaction", fingerprint=[group_fingerprint])
- event_data_2["timestamp"] = iso_format(before_now(seconds=20))
- event_data_2["start_timestamp"] = iso_format(before_now(seconds=21))
- event_data_2["event_id"] = "f" * 32
- event_data_3 = load_data("transaction", fingerprint=[group_fingerprint])
- event_data_3["timestamp"] = iso_format(before_now(seconds=30))
- event_data_3["start_timestamp"] = iso_format(before_now(seconds=31))
- event_data_3["event_id"] = "f" * 32
- self.transaction_event_1 = self.store_event(data=event_data_1, project_id=self.project.id)
- self.transaction_event_2 = self.store_event(data=event_data_2, project_id=self.project.id)
- self.transaction_event_3 = self.store_event(data=event_data_3, project_id=self.project.id)
- perf_group = self.transaction_event_1.groups[0]
- assert perf_group.get_latest_event_for_environments().event_id == "d" * 32
- assert perf_group.get_oldest_event_for_environments().event_id == "f" * 32
- def test_perf_issue_issue_platform(self):
- # Just a duplicate of `test_perf_issue` to verify that perf issues read from
- # the issue platform correctly here. Remove once we kill the related flags.
- group_fingerprint = f"{PerformanceNPlusOneGroupType.type_id}-group1"
- event_data_1 = load_data("transaction", fingerprint=[group_fingerprint])
- event_data_1["timestamp"] = iso_format(before_now(seconds=10))
- event_data_1["start_timestamp"] = iso_format(before_now(seconds=11))
- event_data_1["event_id"] = "d" * 32
- event_data_2 = load_data("transaction", fingerprint=[group_fingerprint])
- event_data_2["timestamp"] = iso_format(before_now(seconds=20))
- event_data_2["start_timestamp"] = iso_format(before_now(seconds=21))
- event_data_2["event_id"] = "f" * 32
- event_data_3 = load_data("transaction", fingerprint=[group_fingerprint])
- event_data_3["timestamp"] = iso_format(before_now(seconds=30))
- event_data_3["start_timestamp"] = iso_format(before_now(seconds=31))
- event_data_3["event_id"] = "f" * 32
- with self.options({"performance.issues.send_to_issues_platform": True}):
- self.transaction_event_1 = self.store_event(
- data=event_data_1, project_id=self.project.id
- )
- self.transaction_event_2 = self.store_event(
- data=event_data_2, project_id=self.project.id
- )
- self.transaction_event_3 = self.store_event(
- data=event_data_3, project_id=self.project.id
- )
- perf_group = self.transaction_event_1.groups[0]
- with self.feature("organizations:issue-platform-search-perf-issues"):
- assert perf_group.get_latest_event_for_environments().event_id == "d" * 32
- assert perf_group.get_oldest_event_for_environments().event_id == "f" * 32
|