test_mri.py 1.3 KB

1234567891011121314151617181920212223242526272829
  1. from typing import cast
  2. import pytest
  3. from sentry.snuba.metrics.naming_layer.mri import format_mri_field, format_mri_field_value
  4. from sentry.testutils.cases import TestCase
  5. pytestmark = pytest.mark.sentry_metrics
  6. class TestMRIUtils(TestCase):
  7. def test_format_mri_field(self):
  8. assert format_mri_field("avg(c:custom/foo@none)") == "avg(foo)"
  9. assert format_mri_field("max(s:spans/user@none)") == "max(user)"
  10. assert format_mri_field("sum(d:spans/exclusive_time@millisecond)") == "sum(exclusive_time)"
  11. assert (
  12. format_mri_field("sum(c:custom/http.client.active_requests@{request})")
  13. == "sum(http.client.active_requests)"
  14. )
  15. assert format_mri_field("sum(c:custom/foo...bar@{request})") == "sum(foo...bar)"
  16. assert format_mri_field("invalid_mri_field") == "invalid_mri_field"
  17. assert format_mri_field(cast(str, None)) is None
  18. def test_format_mri_field_value(self):
  19. assert format_mri_field_value("avg(c:custom/foo@none)", "100.0") == "100.0"
  20. assert format_mri_field_value("count(s:spans/user@none)", "100") == "100"
  21. assert format_mri_field_value("sum(d:spans/exclusive_time@millisecond)", "1000") == "1 s"
  22. assert format_mri_field_value("invalid_mri_field", "100") == "100"
  23. assert format_mri_field_value(cast(str, None), "100") == "100"