test_organization_measurements_meta.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. from datetime import timedelta
  2. import pytest
  3. from django.urls import reverse
  4. from sentry.testutils 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. ],
  58. }
  59. }
  60. def test_metric_outside_query_daterange(self):
  61. self.store_transaction_metric(
  62. 1,
  63. metric="measurements.something_custom",
  64. internal_metric="d:transactions/measurements.something_custom@millisecond",
  65. entity="metrics_distributions",
  66. timestamp=self.day_ago - timedelta(days=15, minutes=0),
  67. )
  68. response = self.do_request(
  69. {
  70. "project": self.project.id,
  71. "statsPeriod": "14d",
  72. }
  73. )
  74. assert response.status_code == 200, response.content
  75. assert response.data == {}