test_datadog.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from unittest.mock import patch
  2. from datadog.util.hostname import get_hostname
  3. from sentry.metrics.datadog import DatadogMetricsBackend
  4. from sentry.testutils.cases import TestCase
  5. class DatadogMetricsBackendTest(TestCase):
  6. def setUp(self):
  7. self.backend = DatadogMetricsBackend(prefix="sentrytest.")
  8. @patch("datadog.threadstats.base.ThreadStats.increment")
  9. def test_incr(self, mock_incr):
  10. self.backend.incr("foo", instance="bar")
  11. mock_incr.assert_called_once_with(
  12. "sentrytest.foo",
  13. 1,
  14. sample_rate=1,
  15. tags=["instance:bar"],
  16. host=get_hostname(hostname_from_config=True),
  17. )
  18. @patch("datadog.threadstats.base.ThreadStats.timing")
  19. def test_timing(self, mock_timing):
  20. self.backend.timing("foo", 30, instance="bar")
  21. mock_timing.assert_called_once_with(
  22. "sentrytest.foo",
  23. 30,
  24. sample_rate=1,
  25. tags=["instance:bar"],
  26. host=get_hostname(hostname_from_config=True),
  27. )
  28. @patch("datadog.threadstats.base.ThreadStats.gauge")
  29. def test_gauge(self, mock_gauge):
  30. self.backend.gauge("foo", 5, instance="bar")
  31. mock_gauge.assert_called_once_with(
  32. "sentrytest.foo",
  33. 5,
  34. sample_rate=1,
  35. tags=["instance:bar"],
  36. host=get_hostname(hostname_from_config=True),
  37. )