Add HTTP-agnostic protocol, shared exceptions, and mock fixtures to base#24544
Closed
mwdd146980 wants to merge 2 commits into
Closed
Add HTTP-agnostic protocol, shared exceptions, and mock fixtures to base#24544mwdd146980 wants to merge 2 commits into
mwdd146980 wants to merge 2 commits into
Conversation
Introduce the backend-neutral HTTP foundation so checks and tests can depend on an HTTP-agnostic surface instead of requests-specific APIs: - HTTPClientProtocol / HTTPResponseProtocol (http_protocol.py) - A shared, backend-neutral exception hierarchy (http_exceptions.py) - A MockHTTPResponse test double (http_testing.py) plus the mock_http, mock_openmetrics_http, and mock_prometheus_http dev fixtures - trust_env, close, get_cookie, get_header, set_header on RequestsWrapper - A create_http_client factory seam on AgentCheck Purely additive. self.http still raises requests exceptions, and the existing mock_response fixtures are unchanged, so there is no behavior change and no integration catch sites need updating.
Contributor
Validation ReportAll 21 validations passed. Show details
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Lands the backend-neutral HTTP foundation on master, decoupled from the feature branch, so integrations and tests can build against an HTTP-agnostic surface. It adds:
HTTPClientProtocolandHTTPResponseProtocol(http_protocol.py).http_exceptions.py).MockHTTPResponsetest double (http_testing.py) plus newmock_http,mock_openmetrics_http, andmock_prometheus_httpdev fixtures.RequestsWrapper:trust_env,close,get_cookie,get_header,set_header.create_http_clientfactory seam onAgentCheckso the backing HTTP client is overridable.The change is purely additive.
self.httpstill raisesrequestsexceptions, the existingmock_responsefixtures are unchanged, and no integration catch sites are touched, so there is no behavior change.Motivation
We want to migrate the shipped Agent off
requestsbehind an HTTP-agnostic surface. This PR moves the non-breaking foundation (proto, shared exception types, mock fixtures, wrapper capabilities, and the factory seam) to master first, so we can adopt the surface incrementally.Verification
http.pydiff vs master is additive only: 46 insertions, 0 removals, and zero references to the exception-translation machinery (_translate_*,http_exceptions,requests_exceptions). The verbs,raise_for_status, andResponseWrapperare byte-identical to master, soself.httpbehavior is unchanged.test_capabilities.pyandtest_http_testing.py, the appendedget_header/set_headertests, and thecreate_http_clientfactory tests. The remaining errors/failures are pre-existing environmental gaps (jwt,requests_kerberos, socks proxy) that fail identically on master.ddev test --lint datadog_checks_base datadog_checks_dev(ruff formatandruff check: all checks passed).Review checklist (to be filled by reviewers)
qa/requiredif this PR needs QA validation, orqa/skip-qaif it does not. Exactly one of the two is required. (qa/skip-qa: additive surface, no shipped check uses it yet,self.httpbehavior unchanged.)backport/<branch-name>label to the PR and it will automatically open a backport PR once this one is merged