prometheus/openmetrics: request wrapper mock for httpx migration#22615
Closed
mwdd146980 wants to merge 7 commits into
Closed
prometheus/openmetrics: request wrapper mock for httpx migration#22615mwdd146980 wants to merge 7 commits into
mwdd146980 wants to merge 7 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files🚀 New features to boost your workflow:
|
Contributor
|
Replace requests.Session.get patches with get_http_handler + RequestWrapperMock/HTTPResponseMock so tests are implementation-agnostic and do not depend on requests. Add ignore_tls_warning to RequestWrapperMock so scraper code that checks handler.ignore_tls_warning works when the handler is the mock.
- prometheus: remove local MockResponse, use HTTPResponseMock from datadog_checks.dev.http everywhere so tests rely on a single mock type - openmetrics: consolidate imports (HTTPResponseMock, MockResponse, RequestWrapperMock from datadog_checks.dev.http) - test_http_mock: fix import order (http_protocol before dev.http) Easier to maintain and reduces effort for future HTTP-client migrations.
- mock_http_response(patch_target, *args, **kwargs): first argument is the dotted path to the callable to patch (e.g. RequestsWrapper.get); remaining args/kwargs build the response via HTTPResponseMock. No check-specific logic in the fixture. - Add OPENMETRICS_SCRAPER_HTTP_TARGET and LEGACY_OPENMETRICS_HTTP_TARGET in openmetrics test utils; update all openmetrics and kubelet_base tests to pass the appropriate target. - Legacy test_openmetrics: use HTTPResponseMock + RequestWrapperMock and patch get_http_handler where the fixture does not apply. - Update datadog_checks.dev.http and plugin pytest docstrings; document testing pattern in docs/developer/base/http.md.
…o RequestWrapperMock - OpenMetrics and Prometheus mixins/base_check now use SharedHTTPError and SharedSSLError from http_exceptions and built-in ConnectionError instead of requests exceptions. - OpenMetrics v2 base_scraper uses built-in ConnectionError. - Prometheus and OpenMetrics tests use HTTPResponseMock and RequestWrapperMock from datadog_checks.dev.http instead of base.utils.http_mock. - Changelog: 22615.changed
2693247 to
e691a5d
Compare
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?
This PR migrates Prometheus and OpenMetrics tests to RequestWrapperMock by replacing
requests.Session.getpatches withget_http_handler+RequestWrapperMock/HTTPResponseMockso tests are implementation-agnostic and do not depend on requests.It also adds
ignore_tls_warningtoRequestWrapperMockso scraper code that checkshandler.ignore_tls_warningworks when the handler is the mock.Motivation
RFC
Review checklist (to be filled by reviewers)
qa/skip-qalabel if the PR doesn't need to be tested during QA.backport/<branch-name>label to the PR and it will automatically open a backport PR once this one is merged