test_performance_summary.py 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. from unittest.mock import patch
  2. from urllib.parse import urlencode
  3. import pytz
  4. from fixtures.page_objects.transaction_summary import TransactionSummaryPage
  5. from sentry.models import AssistantActivity
  6. from sentry.testutils import AcceptanceTestCase, SnubaTestCase
  7. from sentry.testutils.helpers.datetime import before_now, iso_format
  8. from sentry.utils.samples import load_data
  9. FEATURES = {"organizations:performance-view": True}
  10. def make_event(event_data):
  11. event_data["event_id"] = "c" * 32
  12. event_data["contexts"]["trace"]["trace_id"] = "a" * 32
  13. return event_data
  14. class PerformanceSummaryTest(AcceptanceTestCase, SnubaTestCase):
  15. def setUp(self):
  16. super().setUp()
  17. self.org = self.create_organization(owner=self.user, name="Rowdy Tiger")
  18. self.team = self.create_team(
  19. organization=self.org, name="Mariachi Band", members=[self.user]
  20. )
  21. self.project = self.create_project(organization=self.org, teams=[self.team], name="Bengal")
  22. self.group = self.create_group(project=self.project)
  23. self.login_as(self.user)
  24. self.path = "/organizations/{}/performance/summary/?{}".format(
  25. self.org.slug,
  26. urlencode({"transaction": "/country_by_code/", "project": self.project.id}),
  27. )
  28. AssistantActivity.objects.create(
  29. user=self.user, guide_id=20, viewed_ts=before_now(minutes=1)
  30. )
  31. self.page = TransactionSummaryPage(self.browser)
  32. @patch("django.utils.timezone.now")
  33. def test_with_data(self, mock_now):
  34. mock_now.return_value = before_now().replace(tzinfo=pytz.utc)
  35. # Create a transaction
  36. event = make_event(load_data("transaction", timestamp=before_now(minutes=3)))
  37. self.store_event(data=event, project_id=self.project.id)
  38. self.store_event(
  39. data={
  40. "transaction": "/country_by_code/",
  41. "message": "This is bad",
  42. "event_id": "b" * 32,
  43. "timestamp": iso_format(before_now(minutes=1)),
  44. },
  45. project_id=self.project.id,
  46. )
  47. with self.feature(FEATURES):
  48. self.browser.get(self.path)
  49. self.page.wait_until_loaded()
  50. # We have to wait for this again because there are loaders inside of the table
  51. self.page.wait_until_loaded()
  52. self.browser.snapshot("performance summary - with data")
  53. @patch("django.utils.timezone.now")
  54. def test_view_details_from_summary(self, mock_now):
  55. mock_now.return_value = before_now().replace(tzinfo=pytz.utc)
  56. event = make_event(
  57. load_data(
  58. "transaction", timestamp=before_now(minutes=3), trace="a" * 32, span_id="ab" * 8
  59. )
  60. )
  61. self.store_event(data=event, project_id=self.project.id)
  62. with self.feature(FEATURES):
  63. self.browser.get(self.path)
  64. self.page.wait_until_loaded()
  65. # View the first event details.
  66. self.browser.element('[data-test-id="view-id"]').click()
  67. self.page.wait_until_loaded()
  68. self.browser.snapshot("performance event details")
  69. @patch("django.utils.timezone.now")
  70. def test_tags_page(self, mock_now):
  71. mock_now.return_value = before_now().replace(tzinfo=pytz.utc)
  72. tags_path = "/organizations/{}/performance/summary/tags/?{}".format(
  73. self.org.slug,
  74. urlencode({"transaction": "/country_by_code/", "project": self.project.id}),
  75. )
  76. # Create a transaction
  77. event_data = load_data("transaction", timestamp=before_now(minutes=3))
  78. event = make_event(event_data)
  79. self.store_event(data=event, project_id=self.project.id)
  80. with self.feature(FEATURES):
  81. self.browser.get(tags_path)
  82. self.page.wait_until_loaded()
  83. self.browser.snapshot("transaction summary tags page")
  84. @patch("django.utils.timezone.now")
  85. def test_transaction_vitals(self, mock_now):
  86. mock_now.return_value = before_now().replace(tzinfo=pytz.utc)
  87. vitals_path = "/organizations/{}/performance/summary/vitals/?{}".format(
  88. self.org.slug,
  89. urlencode({"transaction": "/country_by_code/", "project": self.project.id}),
  90. )
  91. # Create a transaction
  92. event_data = load_data("transaction", timestamp=before_now(minutes=3))
  93. # only frontend pageload transactions can be shown on the vitals tab
  94. event_data["contexts"]["trace"]["op"] = "pageload"
  95. event_data["measurements"]["fp"]["value"] = 5000
  96. event = make_event(event_data)
  97. self.store_event(data=event, project_id=self.project.id)
  98. with self.feature(FEATURES):
  99. self.browser.get(vitals_path)
  100. self.page.wait_until_loaded()
  101. self.browser.snapshot("real user monitoring")
  102. @patch("django.utils.timezone.now")
  103. def test_transaction_vitals_filtering(self, mock_now):
  104. mock_now.return_value = before_now().replace(tzinfo=pytz.utc)
  105. vitals_path = "/organizations/{}/performance/summary/vitals/?{}".format(
  106. self.org.slug,
  107. urlencode(
  108. {
  109. "transaction": "/country_by_code/",
  110. "project": self.project.id,
  111. "dataFilter": "exclude_outliers",
  112. }
  113. ),
  114. )
  115. # Create transactions
  116. for seconds in range(3):
  117. event_data = load_data("transaction", timestamp=before_now(minutes=3))
  118. event_data["contexts"]["trace"]["op"] = "pageload"
  119. event_data["contexts"]["trace"]["id"] = ("c" * 31) + hex(seconds)[2:]
  120. event_data["event_id"] = ("c" * 31) + hex(seconds)[2:]
  121. event_data["measurements"]["fp"]["value"] = seconds * 10
  122. event_data["measurements"]["fcp"]["value"] = seconds * 10
  123. event_data["measurements"]["lcp"]["value"] = seconds * 10
  124. event_data["measurements"]["fid"]["value"] = seconds * 10
  125. event_data["measurements"]["cls"]["value"] = seconds / 10.0
  126. self.store_event(data=event_data, project_id=self.project.id)
  127. # add anchor point
  128. event_data = load_data("transaction", timestamp=before_now(minutes=2))
  129. event_data["contexts"]["trace"]["op"] = "pageload"
  130. event_data["contexts"]["trace"]["id"] = "a" * 32
  131. event_data["event_id"] = "a" * 32
  132. event_data["measurements"]["fp"]["value"] = 3000
  133. event_data["measurements"]["fcp"]["value"] = 3000
  134. event_data["measurements"]["lcp"]["value"] = 3000
  135. event_data["measurements"]["fid"]["value"] = 3000
  136. event_data["measurements"]["cls"]["value"] = 0.3
  137. self.store_event(data=event_data, project_id=self.project.id)
  138. # add outlier
  139. event_data = load_data("transaction", timestamp=before_now(minutes=2))
  140. event_data["contexts"]["trace"]["op"] = "pageload"
  141. event_data["contexts"]["trace"]["id"] = "b" * 32
  142. event_data["event_id"] = "b" * 32
  143. event_data["measurements"]["fp"]["value"] = 3000000000
  144. event_data["measurements"]["fcp"]["value"] = 3000000000
  145. event_data["measurements"]["lcp"]["value"] = 3000000000
  146. event_data["measurements"]["fid"]["value"] = 3000000000
  147. event_data["measurements"]["cls"]["value"] = 3000000000
  148. self.store_event(data=event_data, project_id=self.project.id)
  149. with self.feature(FEATURES):
  150. self.browser.get(vitals_path)
  151. self.page.wait_until_loaded()
  152. self.browser.snapshot("real user monitoring - exclude outliers")
  153. self.browser.element(xpath="//button//span[contains(text(), 'Exclude')]").click()
  154. self.browser.element(xpath="//p[contains(text(), 'Include')]").click()
  155. self.page.wait_until_loaded()
  156. self.browser.snapshot("real user monitoring - view all data")
  157. @patch("django.utils.timezone.now")
  158. def test_transaction_threshold_modal(self, mock_now):
  159. mock_now.return_value = before_now().replace(tzinfo=pytz.utc)
  160. # Create a transaction
  161. event = make_event(load_data("transaction", timestamp=before_now(minutes=3)))
  162. self.store_event(data=event, project_id=self.project.id)
  163. self.store_event(
  164. data={
  165. "transaction": "/country_by_code/",
  166. "message": "This is bad",
  167. "event_id": "b" * 32,
  168. "timestamp": iso_format(before_now(minutes=3)),
  169. },
  170. project_id=self.project.id,
  171. )
  172. with self.feature(FEATURES):
  173. self.browser.get(self.path)
  174. self.page.wait_until_loaded()
  175. self.browser.click('[data-test-id="set-transaction-threshold"]')
  176. self.browser.snapshot("transaction threshold modal")