test_performance_span_summary.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. from datetime import timedelta
  2. from unittest.mock import patch
  3. from urllib.parse import urlencode
  4. import pytest
  5. import pytz
  6. from fixtures.page_objects.base import BasePage
  7. from sentry.testutils.cases import AcceptanceTestCase, SnubaTestCase
  8. from sentry.testutils.helpers.datetime import before_now, iso_format
  9. from sentry.testutils.silo import no_silo_test
  10. from sentry.utils.samples import load_data
  11. FEATURES = {
  12. "organizations:performance-span-histogram-view": True,
  13. "organizations:performance-view": True,
  14. }
  15. @no_silo_test(stable=True)
  16. class PerformanceSpanSummaryTest(AcceptanceTestCase, SnubaTestCase):
  17. def setUp(self):
  18. super().setUp()
  19. self.org = self.create_organization(owner=self.user, name="Rowdy Tiger")
  20. self.team = self.create_team(
  21. organization=self.org, name="Mariachi Band", members=[self.user]
  22. )
  23. self.project = self.create_project(organization=self.org, teams=[self.team], name="Bengal")
  24. self.group = self.create_group(project=self.project)
  25. self.login_as(self.user)
  26. self.path = "/organizations/{}/performance/summary/spans/{}/?{}".format(
  27. self.org.slug,
  28. "django.middleware:" + "cd" * 8,
  29. urlencode({"project": self.project.id, "transaction": "root transaction"}),
  30. )
  31. self.page = BasePage(self.browser)
  32. self.min_ago = before_now(minutes=1).replace(microsecond=0)
  33. def create_event(self, **kwargs):
  34. if "span_id" not in kwargs:
  35. kwargs["span_id"] = "a" * 16
  36. if "start_timestamp" not in kwargs:
  37. kwargs["start_timestamp"] = self.min_ago
  38. if "timestamp" not in kwargs:
  39. kwargs["timestamp"] = self.min_ago + timedelta(seconds=8)
  40. if "trace_context" not in kwargs:
  41. kwargs["trace_context"] = {
  42. "op": "http.server",
  43. "hash": "ab" * 8,
  44. "exclusive_time": 4.0,
  45. }
  46. if "spans" not in kwargs:
  47. kwargs["spans"] = [
  48. {
  49. "same_process_as_parent": True,
  50. "parent_span_id": "a" * 16,
  51. "span_id": x * 16,
  52. "start_timestamp": iso_format(self.min_ago + timedelta(seconds=1)),
  53. "timestamp": iso_format(self.min_ago + timedelta(seconds=4)),
  54. "op": "django.middleware",
  55. "description": "middleware span",
  56. "hash": "cd" * 8,
  57. "exclusive_time": 3.0,
  58. }
  59. for x in ["b", "c"]
  60. ] + [
  61. {
  62. "same_process_as_parent": True,
  63. "parent_span_id": "a" * 16,
  64. "span_id": x * 16,
  65. "start_timestamp": iso_format(self.min_ago + timedelta(seconds=4)),
  66. "timestamp": iso_format(self.min_ago + timedelta(seconds=5)),
  67. "op": "django.middleware",
  68. "description": "middleware span",
  69. "hash": "cd" * 8,
  70. "exclusive_time": 1.0,
  71. }
  72. for x in ["d", "e", "f"]
  73. ]
  74. data = load_data("transaction", **kwargs)
  75. data["transaction"] = "root transaction"
  76. data["event_id"] = "c" * 32
  77. data["contexts"]["trace"]["trace_id"] = "a" * 32
  78. return self.store_event(data, project_id=self.project.id)
  79. @pytest.mark.skip(reason="Has been flaky lately.")
  80. @patch("django.utils.timezone.now")
  81. def test_with_data(self, mock_now):
  82. mock_now.return_value = before_now().replace(tzinfo=pytz.utc)
  83. self.create_event()
  84. with self.feature(FEATURES):
  85. self.browser.get(self.path)
  86. self.page.wait_until_loaded()
  87. # Wait again for loaders inside the table
  88. self.page.wait_until_loaded()
  89. self.browser.snapshot("performance span summary - with data")