test_organization_measurements_meta.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. from datetime import timedelta
  2. import pytest
  3. from django.urls import reverse
  4. from sentry.testutils.cases import MetricsEnhancedPerformanceTestCase
  5. from sentry.testutils.helpers.datetime import before_now
  6. pytestmark = pytest.mark.sentry_metrics
  7. class OrganizationMeasurementsMetaEndpoint(MetricsEnhancedPerformanceTestCase):
  8. endpoint = "sentry-api-0-organization-measurements-meta"
  9. METRIC_STRINGS = [
  10. "d:transactions/measurements.something_custom@millisecond",
  11. ]
  12. def setUp(self):
  13. super().setUp()
  14. self.login_as(user=self.user)
  15. self.day_ago = before_now(days=1).replace(hour=10, minute=0, second=0, microsecond=0)
  16. self.DEFAULT_METRIC_TIMESTAMP = self.day_ago
  17. self.url = reverse(
  18. self.endpoint, kwargs={"organization_slug": self.project.organization.slug}
  19. )
  20. self.features = {"organizations:performance-use-metrics": True}
  21. def do_request(self, data, url=None, features=None):
  22. if features is None:
  23. features = {"organizations:discover-basic": True}
  24. features.update(self.features)
  25. with self.feature(features):
  26. return self.client.get(self.url if url is None else url, data=data, format="json")
  27. def test_simple(self):
  28. self.store_transaction_metric(
  29. 1,
  30. metric="measurements.something_custom",
  31. internal_metric="d:transactions/measurements.something_custom@millisecond",
  32. entity="metrics_distributions",
  33. timestamp=self.day_ago + timedelta(hours=1, minutes=0),
  34. )
  35. response = self.do_request(
  36. {
  37. "project": self.project.id,
  38. "statsPeriod": "14d",
  39. }
  40. )
  41. assert response.status_code == 200, response.content
  42. assert response.data == {
  43. "measurements.something_custom": {
  44. "functions": [
  45. "apdex",
  46. "avg",
  47. "p50",
  48. "p75",
  49. "p90",
  50. "p95",
  51. "p99",
  52. "p100",
  53. "max",
  54. "min",
  55. "sum",
  56. "percentile",
  57. "http_error_count",
  58. "http_error_rate",
  59. ],
  60. "unit": "millisecond",
  61. }
  62. }
  63. def test_measurements_with_numbers_in_name(self):
  64. self.store_transaction_metric(
  65. 1,
  66. metric="measurements.something_custom",
  67. internal_metric="d:transactions/measurements.1234567890.abcdef@millisecond",
  68. entity="metrics_distributions",
  69. timestamp=self.day_ago + timedelta(hours=1, minutes=0),
  70. )
  71. response = self.do_request(
  72. {
  73. "project": self.project.id,
  74. "statsPeriod": "14d",
  75. }
  76. )
  77. assert response.status_code == 200, response.content
  78. assert response.data == {
  79. "measurements.1234567890.abcdef": {
  80. "functions": [
  81. "apdex",
  82. "avg",
  83. "p50",
  84. "p75",
  85. "p90",
  86. "p95",
  87. "p99",
  88. "p100",
  89. "max",
  90. "min",
  91. "sum",
  92. "percentile",
  93. "http_error_count",
  94. "http_error_rate",
  95. ],
  96. "unit": "millisecond",
  97. }
  98. }
  99. def test_measurements_with_lots_of_periods(self):
  100. self.store_transaction_metric(
  101. 1,
  102. metric="measurements.something_custom",
  103. internal_metric="d:transactions/measurements.a.b.c.d.e.f.g@millisecond",
  104. entity="metrics_distributions",
  105. timestamp=self.day_ago + timedelta(hours=1, minutes=0),
  106. )
  107. response = self.do_request(
  108. {
  109. "project": self.project.id,
  110. "statsPeriod": "14d",
  111. }
  112. )
  113. assert response.status_code == 200, response.content
  114. assert response.data == {
  115. "measurements.a.b.c.d.e.f.g": {
  116. "functions": [
  117. "apdex",
  118. "avg",
  119. "p50",
  120. "p75",
  121. "p90",
  122. "p95",
  123. "p99",
  124. "p100",
  125. "max",
  126. "min",
  127. "sum",
  128. "percentile",
  129. "http_error_count",
  130. "http_error_rate",
  131. ],
  132. "unit": "millisecond",
  133. }
  134. }
  135. def test_metric_outside_query_daterange(self):
  136. self.store_transaction_metric(
  137. 1,
  138. metric="measurements.something_custom",
  139. internal_metric="d:transactions/measurements.something_custom@millisecond",
  140. entity="metrics_distributions",
  141. timestamp=self.day_ago - timedelta(days=15, minutes=0),
  142. )
  143. response = self.do_request(
  144. {
  145. "project": self.project.id,
  146. "statsPeriod": "14d",
  147. }
  148. )
  149. assert response.status_code == 200, response.content
  150. assert response.data == {}