test_organization_measurements_meta.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. from sentry.testutils.silo import region_silo_test
  7. pytestmark = pytest.mark.sentry_metrics
  8. @region_silo_test
  9. class OrganizationMeasurementsMetaEndpoint(MetricsEnhancedPerformanceTestCase):
  10. endpoint = "sentry-api-0-organization-measurements-meta"
  11. METRIC_STRINGS = [
  12. "d:transactions/measurements.something_custom@millisecond",
  13. ]
  14. def setUp(self):
  15. super().setUp()
  16. self.login_as(user=self.user)
  17. self.day_ago = before_now(days=1).replace(hour=10, minute=0, second=0, microsecond=0)
  18. self.DEFAULT_METRIC_TIMESTAMP = self.day_ago
  19. self.url = reverse(
  20. self.endpoint, kwargs={"organization_slug": self.project.organization.slug}
  21. )
  22. self.features = {"organizations:performance-use-metrics": True}
  23. def do_request(self, data, url=None, features=None):
  24. if features is None:
  25. features = {"organizations:discover-basic": True}
  26. features.update(self.features)
  27. with self.feature(features):
  28. return self.client.get(self.url if url is None else url, data=data, format="json")
  29. def test_simple(self):
  30. self.store_transaction_metric(
  31. 1,
  32. metric="measurements.something_custom",
  33. internal_metric="d:transactions/measurements.something_custom@millisecond",
  34. entity="metrics_distributions",
  35. timestamp=self.day_ago + timedelta(hours=1, minutes=0),
  36. )
  37. response = self.do_request(
  38. {
  39. "project": self.project.id,
  40. "statsPeriod": "14d",
  41. }
  42. )
  43. assert response.status_code == 200, response.content
  44. assert response.data == {
  45. "measurements.something_custom": {
  46. "functions": [
  47. "apdex",
  48. "avg",
  49. "p50",
  50. "p75",
  51. "p90",
  52. "p95",
  53. "p99",
  54. "p100",
  55. "max",
  56. "min",
  57. "sum",
  58. "percentile",
  59. ],
  60. "unit": "millisecond",
  61. }
  62. }
  63. def test_metric_outside_query_daterange(self):
  64. self.store_transaction_metric(
  65. 1,
  66. metric="measurements.something_custom",
  67. internal_metric="d:transactions/measurements.something_custom@millisecond",
  68. entity="metrics_distributions",
  69. timestamp=self.day_ago - timedelta(days=15, 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 == {}