test_performance_span_summary.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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.utils.samples import load_data
  10. FEATURES = {
  11. "organizations:performance-span-histogram-view": True,
  12. "organizations:performance-view": True,
  13. }
  14. class PerformanceSpanSummaryTest(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/spans/{}/?{}".format(
  25. self.org.slug,
  26. "django.middleware:" + "cd" * 8,
  27. urlencode({"project": self.project.id, "transaction": "root transaction"}),
  28. )
  29. self.page = BasePage(self.browser)
  30. self.min_ago = before_now(minutes=1).replace(microsecond=0)
  31. def create_event(self, **kwargs):
  32. if "span_id" not in kwargs:
  33. kwargs["span_id"] = "a" * 16
  34. if "start_timestamp" not in kwargs:
  35. kwargs["start_timestamp"] = self.min_ago
  36. if "timestamp" not in kwargs:
  37. kwargs["timestamp"] = self.min_ago + timedelta(seconds=8)
  38. if "trace_context" not in kwargs:
  39. kwargs["trace_context"] = {
  40. "op": "http.server",
  41. "hash": "ab" * 8,
  42. "exclusive_time": 4.0,
  43. }
  44. if "spans" not in kwargs:
  45. kwargs["spans"] = [
  46. {
  47. "same_process_as_parent": True,
  48. "parent_span_id": "a" * 16,
  49. "span_id": x * 16,
  50. "start_timestamp": iso_format(self.min_ago + timedelta(seconds=1)),
  51. "timestamp": iso_format(self.min_ago + timedelta(seconds=4)),
  52. "op": "django.middleware",
  53. "description": "middleware span",
  54. "hash": "cd" * 8,
  55. "exclusive_time": 3.0,
  56. }
  57. for x in ["b", "c"]
  58. ] + [
  59. {
  60. "same_process_as_parent": True,
  61. "parent_span_id": "a" * 16,
  62. "span_id": x * 16,
  63. "start_timestamp": iso_format(self.min_ago + timedelta(seconds=4)),
  64. "timestamp": iso_format(self.min_ago + timedelta(seconds=5)),
  65. "op": "django.middleware",
  66. "description": "middleware span",
  67. "hash": "cd" * 8,
  68. "exclusive_time": 1.0,
  69. }
  70. for x in ["d", "e", "f"]
  71. ]
  72. data = load_data("transaction", **kwargs)
  73. data["transaction"] = "root transaction"
  74. data["event_id"] = "c" * 32
  75. data["contexts"]["trace"]["trace_id"] = "a" * 32
  76. return self.store_event(data, project_id=self.project.id)
  77. @pytest.mark.skip(reason="Has been flaky lately.")
  78. @patch("django.utils.timezone.now")
  79. def test_with_data(self, mock_now):
  80. mock_now.return_value = before_now().replace(tzinfo=pytz.utc)
  81. self.create_event()
  82. with self.feature(FEATURES):
  83. self.browser.get(self.path)
  84. self.page.wait_until_loaded()
  85. # Wait again for loaders inside the table
  86. self.page.wait_until_loaded()
  87. self.browser.snapshot("performance span summary - with data")