Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions control_m/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from unittest.mock import Mock

from pytest import MonkeyPatch
from requests.exceptions import HTTPError

from datadog_checks.base.utils.http_exceptions import HTTPStatusError
from datadog_checks.control_m import ControlMCheck

FIXTURE_DIR = Path(__file__).parent / "fixtures"
Expand All @@ -26,7 +26,7 @@ def _respond(data: Any, status_code: int = 200) -> Mock:
resp.raise_for_status = Mock()
else:
resp.text = f"Error {status_code}"
resp.raise_for_status = Mock(side_effect=HTTPError(f"{status_code} Server Error", response=resp))
resp.raise_for_status = Mock(side_effect=HTTPStatusError(f"{status_code} Server Error", response=resp))
return resp


Expand Down
6 changes: 3 additions & 3 deletions control_m/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

import pytest
from pytest import MonkeyPatch
from requests.exceptions import HTTPError

from datadog_checks.base.stubs.aggregator import AggregatorStub
from datadog_checks.base.utils.http_exceptions import HTTPStatusError
from datadog_checks.dev.utils import get_metadata_metrics

from .common import BASE_TAGS, FIXTURE_DIR, _load_job, _make_check, _mock_api, _run_check
Expand Down Expand Up @@ -45,7 +45,7 @@ def test_connect_server_error_emits_critical(
check = _make_check(instance)
_mock_api(check, monkeypatch, server_status=500)

with pytest.raises(HTTPError, match="500"):
with pytest.raises(HTTPStatusError, match="500"):
_run_check(check)

aggregator.assert_metric("control_m.can_connect", value=0, count=1)
Expand All @@ -71,7 +71,7 @@ def test_connect_session_login_failure_emits_critical(
check = _make_check(session_instance)
_mock_api(check, monkeypatch, login_status=401)

with pytest.raises(HTTPError, match="401"):
with pytest.raises(HTTPStatusError, match="401"):
_run_check(check)

aggregator.assert_metric("control_m.can_login", value=0, count=1)
Expand Down
1 change: 1 addition & 0 deletions mesos_master/changelog.d/22676.changed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Catch the backend-agnostic ``HTTPTimeoutError`` on request timeout so the check keeps working after the httpx migration.
3 changes: 2 additions & 1 deletion mesos_master/datadog_checks/mesos_master/mesos_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ def _make_request(self, url):
status = AgentCheck.OK
msg = "Mesos master instance detected at {} ".format(url)
except (requests.exceptions.Timeout, HTTPTimeoutError):
Comment thread
mwdd146980 marked this conversation as resolved.
# If there's a timeout
# On timeout. requests.exceptions.Timeout is a transition shim for the
# httpx2 migration. Drop it once requests is gone.
msg = "{} seconds timeout when hitting {}".format(self.http.options['timeout'], url)
status = AgentCheck.CRITICAL
except Exception as e:
Expand Down
8 changes: 4 additions & 4 deletions mesos_master/tests/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from unittest.mock import MagicMock

import pytest
import requests

from datadog_checks.base import AgentCheck
from datadog_checks.base.errors import CheckException
from datadog_checks.base.utils.http_exceptions import HTTPTimeoutError
from datadog_checks.mesos_master import MesosMaster


Expand Down Expand Up @@ -99,21 +99,21 @@ def test_instance_timeout(check, instance):
),
(
'OK case with failing /state due to Timeout and fallback on /state.json',
[requests.exceptions.Timeout, MagicMock(status_code=200, content='{}')],
[HTTPTimeoutError("timeout"), MagicMock(status_code=200, content='{}')],
AgentCheck.OK,
['my:tag', 'url:http://hello.com/state.json'],
False,
),
(
'OK case with failing /state due to Exception and fallback on /state.json',
[Exception, MagicMock(status_code=200, content='{}')],
[Exception("unexpected error"), MagicMock(status_code=200, content='{}')],
AgentCheck.OK,
['my:tag', 'url:http://hello.com/state.json'],
False,
),
(
'NOK case with failing /state and /state.json due to timeout',
[requests.exceptions.Timeout, requests.exceptions.Timeout],
[HTTPTimeoutError("timeout"), HTTPTimeoutError("timeout")],
AgentCheck.CRITICAL,
['my:tag', 'url:http://hello.com/state.json'],
True,
Expand Down
Loading