Skip to content
Draft
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
2 changes: 1 addition & 1 deletion datadog_checks_base/changelog.d/22676.added
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Add library-agnostic HTTP mocks/proto/exceptions and migrate intg tests.
Add library-agnostic HTTP mocks/proto/exceptions and migrate intg tests. Add ``HTTPXWrapper``, an httpx2-backed HTTP client opt-in via the ``use_httpx`` instance config flag. The default remains the existing requests-based client.
12 changes: 9 additions & 3 deletions datadog_checks_base/datadog_checks/base/checks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,16 @@ def http(self) -> HTTPClientProtocol:
Only new checks or checks on Agent 6.13+ can and should use this for HTTP requests.
"""
if not hasattr(self, '_http'):
# See Performance Optimizations in this package's README.md.
from datadog_checks.base.utils.http import RequestsWrapper
instance = self.instance or {}
if is_affirmative(instance.get('use_httpx', False)):
from datadog_checks.base.utils.http_httpx import HTTPXWrapper

self._http = HTTPXWrapper(instance, self.init_config, self.HTTP_CONFIG_REMAPPER, self.log)
else:
# See Performance Optimizations in this package's README.md.
from datadog_checks.base.utils.http import RequestsWrapper

self._http = RequestsWrapper(self.instance or {}, self.init_config, self.HTTP_CONFIG_REMAPPER, self.log)
self._http = RequestsWrapper(instance, self.init_config, self.HTTP_CONFIG_REMAPPER, self.log)

return self._http

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from datadog_checks.base.constants import ServiceCheck
from datadog_checks.base.errors import ConfigurationError
from datadog_checks.base.utils.functions import no_op, return_true
from datadog_checks.base.utils.http_exceptions import HTTPConnectionError


class OpenMetricsScraper:
Expand Down Expand Up @@ -405,11 +406,11 @@ def stream_connection_lines(self):
self._content_type = connection.headers.get('Content-Type', '')
for line in connection.iter_lines(decode_unicode=True):
yield line
except ConnectionError as e:
except (ConnectionError, HTTPConnectionError) as e:
if self.ignore_connection_errors:
self.log.warning("OpenMetrics endpoint %s is not accessible", self.endpoint)
self.log.warning("OpenMetrics endpoint %s is not accessible: %s", self.endpoint, e)
else:
raise e
raise

def filter_connection_lines(self, line_streamer):
"""
Expand Down
Loading
Loading