|
@@ -1,7 +1,5 @@
|
|
|
from unittest import mock
|
|
|
|
|
|
-import pytest
|
|
|
-
|
|
|
from sentry.integrations.base import IntegrationDomain
|
|
|
from sentry.integrations.types import EventLifecycleOutcome
|
|
|
from sentry.integrations.utils.metrics import IntegrationEventLifecycleMetric
|
|
@@ -9,10 +7,6 @@ from sentry.testutils.cases import TestCase
|
|
|
from sentry.testutils.silo import no_silo_test
|
|
|
|
|
|
|
|
|
-class ExampleException(Exception):
|
|
|
- pass
|
|
|
-
|
|
|
-
|
|
|
@no_silo_test
|
|
|
class IntegrationEventLifecycleMetricTest(TestCase):
|
|
|
class TestLifecycleMetric(IntegrationEventLifecycleMetric):
|
|
@@ -77,110 +71,23 @@ class IntegrationEventLifecycleMetricTest(TestCase):
|
|
|
self._check_metrics_call_args(mock_metrics, "halted")
|
|
|
mock_logger.error.assert_not_called()
|
|
|
|
|
|
- @mock.patch("sentry.integrations.utils.metrics.logger")
|
|
|
- @mock.patch("sentry.integrations.utils.metrics.metrics")
|
|
|
- def test_recording_explicit_halt_with_exception(self, mock_metrics, mock_logger):
|
|
|
- metric_obj = self.TestLifecycleMetric()
|
|
|
- with metric_obj.capture() as lifecycle:
|
|
|
- lifecycle.add_extra("extra", "value")
|
|
|
- lifecycle.record_halt(ExampleException(""), extra={"even": "more"})
|
|
|
-
|
|
|
- self._check_metrics_call_args(mock_metrics, "halted")
|
|
|
- mock_logger.warning.assert_called_once_with(
|
|
|
- "integrations.slo.halted",
|
|
|
- extra={
|
|
|
- "extra": "value",
|
|
|
- "even": "more",
|
|
|
- "integration_domain": "messaging",
|
|
|
- "integration_name": "my_integration",
|
|
|
- "interaction_type": "my_interaction",
|
|
|
- },
|
|
|
- exc_info=mock.ANY,
|
|
|
- )
|
|
|
-
|
|
|
- @mock.patch("sentry.integrations.utils.metrics.logger")
|
|
|
- @mock.patch("sentry.integrations.utils.metrics.metrics")
|
|
|
- def test_recording_explicit_halt_with_str(self, mock_metrics, mock_logger):
|
|
|
- metric_obj = self.TestLifecycleMetric()
|
|
|
- with metric_obj.capture() as lifecycle:
|
|
|
- lifecycle.add_extra("extra", "value")
|
|
|
- lifecycle.record_halt("Integration went boom", extra={"even": "more"})
|
|
|
-
|
|
|
- self._check_metrics_call_args(mock_metrics, "halted")
|
|
|
- mock_logger.warning.assert_called_once_with(
|
|
|
- "integrations.slo.halted",
|
|
|
- extra={
|
|
|
- "outcome_reason": "Integration went boom",
|
|
|
- "extra": "value",
|
|
|
- "even": "more",
|
|
|
- "integration_domain": "messaging",
|
|
|
- "integration_name": "my_integration",
|
|
|
- "interaction_type": "my_interaction",
|
|
|
- },
|
|
|
- )
|
|
|
-
|
|
|
@mock.patch("sentry.integrations.utils.metrics.logger")
|
|
|
@mock.patch("sentry.integrations.utils.metrics.metrics")
|
|
|
def test_recording_failure(self, mock_metrics, mock_logger):
|
|
|
- metric_obj = self.TestLifecycleMetric()
|
|
|
- with pytest.raises(ExampleException):
|
|
|
- with metric_obj.capture() as lifecycle:
|
|
|
- lifecycle.add_extra("extra", "value")
|
|
|
- raise ExampleException
|
|
|
-
|
|
|
- self._check_metrics_call_args(mock_metrics, "failure")
|
|
|
- mock_logger.error.assert_called_once_with(
|
|
|
- "integrations.slo.failure",
|
|
|
- extra={
|
|
|
- "extra": "value",
|
|
|
- "integration_domain": "messaging",
|
|
|
- "integration_name": "my_integration",
|
|
|
- "interaction_type": "my_interaction",
|
|
|
- },
|
|
|
- exc_info=mock.ANY,
|
|
|
- )
|
|
|
+ class TestException(Exception):
|
|
|
+ pass
|
|
|
|
|
|
- @mock.patch("sentry.integrations.utils.metrics.logger")
|
|
|
- @mock.patch("sentry.integrations.utils.metrics.metrics")
|
|
|
- def test_recording_explicit_failure_with_exception(self, mock_metrics, mock_logger):
|
|
|
metric_obj = self.TestLifecycleMetric()
|
|
|
- with metric_obj.capture() as lifecycle:
|
|
|
- try:
|
|
|
+ try:
|
|
|
+ with metric_obj.capture() as lifecycle:
|
|
|
lifecycle.add_extra("extra", "value")
|
|
|
- raise ExampleException
|
|
|
- except ExampleException as exc:
|
|
|
- lifecycle.record_failure(exc, extra={"even": "more"})
|
|
|
-
|
|
|
- self._check_metrics_call_args(mock_metrics, "failure")
|
|
|
- mock_logger.error.assert_called_once_with(
|
|
|
- "integrations.slo.failure",
|
|
|
- extra={
|
|
|
- "extra": "value",
|
|
|
- "even": "more",
|
|
|
- "integration_domain": "messaging",
|
|
|
- "integration_name": "my_integration",
|
|
|
- "interaction_type": "my_interaction",
|
|
|
- },
|
|
|
- exc_info=mock.ANY,
|
|
|
- )
|
|
|
-
|
|
|
- @mock.patch("sentry.integrations.utils.metrics.logger")
|
|
|
- @mock.patch("sentry.integrations.utils.metrics.metrics")
|
|
|
- def test_recording_explicit_failure_with_str(self, mock_metrics, mock_logger):
|
|
|
- metric_obj = self.TestLifecycleMetric()
|
|
|
- with metric_obj.capture() as lifecycle:
|
|
|
- lifecycle.add_extra("extra", "value")
|
|
|
- lifecycle.record_failure("Integration went boom", extra={"even": "more"})
|
|
|
+ raise TestException
|
|
|
+ except TestException:
|
|
|
+ pass
|
|
|
+ else:
|
|
|
+ self.fail()
|
|
|
|
|
|
self._check_metrics_call_args(mock_metrics, "failure")
|
|
|
mock_logger.error.assert_called_once_with(
|
|
|
- "integrations.slo.failure",
|
|
|
- extra={
|
|
|
- "outcome_reason": "Integration went boom",
|
|
|
- "extra": "value",
|
|
|
- "even": "more",
|
|
|
- "integration_domain": "messaging",
|
|
|
- "integration_name": "my_integration",
|
|
|
- "interaction_type": "my_interaction",
|
|
|
- },
|
|
|
+ "integrations.slo.failure", extra={"extra": "value"}, exc_info=mock.ANY
|
|
|
)
|