Skip to content

Commit 8cd1bf6

Browse files
mwdd146980claude
andauthored
Catch agnostic HTTPError in sonarqube check() and swap the test (#24249)
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent f1e1514 commit 8cd1bf6

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Catch the backend-agnostic ``HTTPError`` when collecting metadata and metrics so the check keeps working after the httpx migration.

sonarqube/datadog_checks/sonarqube/check.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from requests.exceptions import RequestException
77

88
from datadog_checks.base import AgentCheck, ConfigurationError
9+
from datadog_checks.base.utils.http_exceptions import HTTPError
910

1011
from .constants import CATEGORIES, MAX_PAGES, NUMERIC_TYPES
1112

@@ -31,8 +32,8 @@ def check(self, _):
3132
try:
3233
self.collect_metadata()
3334
self.collect_metrics()
34-
except RequestException as e:
35-
self.log.error('RequestException: %s', e)
35+
except (RequestException, HTTPError) as e:
36+
self.log.error('Error querying the SonarQube API: %s', e)
3637
self.service_check(self.SERVICE_CHECK_CONNECT, self.CRITICAL, tags=self._tags, message=str(e))
3738
else:
3839
self.service_check(self.SERVICE_CHECK_CONNECT, self.OK, tags=self._tags)

sonarqube/tests/test_unit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import os
55

66
import mock
7-
import requests
87

8+
from datadog_checks.base.utils.http_exceptions import HTTPError
99
from datadog_checks.base.utils.http_testing import MockHTTPResponse
1010

1111
from .common import HERE
@@ -14,7 +14,7 @@
1414

1515
def test_service_check_critical(aggregator, dd_run_check, sonarqube_check, web_instance):
1616
with mock.patch('datadog_checks.sonarqube.check.SonarqubeCheck.http') as mock_http:
17-
mock_http.get.side_effect = requests.exceptions.RequestException('Req Exception')
17+
mock_http.get.side_effect = HTTPError('HTTP error')
1818
check = sonarqube_check(web_instance)
1919
global_tags = ['endpoint:{}'.format(web_instance['web_endpoint'])]
2020
global_tags.extend(web_instance['tags'])

0 commit comments

Comments
 (0)