Skip to content

prometheus/openmetrics: request wrapper mock for httpx migration#22615

Closed
mwdd146980 wants to merge 7 commits into
mwdd146980/ai-6576from
mwdd146980/prom-openmetrics-request-wrapper-mock
Closed

prometheus/openmetrics: request wrapper mock for httpx migration#22615
mwdd146980 wants to merge 7 commits into
mwdd146980/ai-6576from
mwdd146980/prom-openmetrics-request-wrapper-mock

Conversation

@mwdd146980

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR migrates Prometheus and OpenMetrics tests to RequestWrapperMock by replacing requests.Session.get patches with get_http_handler + RequestWrapperMock / HTTPResponseMock so tests are implementation-agnostic and do not depend on requests.

It also adds ignore_tls_warning to RequestWrapperMock so scraper code that checks handler.ignore_tls_warning works when the handler is the mock.

Motivation

RFC

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Add the qa/skip-qa label if the PR doesn't need to be tested during QA.
  • If you need to backport this PR to another branch, you can add the backport/<branch-name> label to the PR and it will automatically open a backport PR once this one is merged

@codecov

codecov Bot commented Feb 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (mwdd146980/ai-6576@91ca7dc). Learn more about missing BASE report.

Additional details and impacted files
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

⚠️ Tests

Fix all issues with Cursor

⚠️ Warnings

🧪 137 Tests failed

test_check from test_unit.py (Datadog) (Fix with Cursor)
mock_http_response.<locals>._mock() missing 1 required positional argument: 'patch_target'
test_collect_metadata from test_unit.py (Datadog) (Fix with Cursor)
mock_http_response.<locals>._mock() missing 1 required positional argument: 'patch_target'
test_connection_limit_metrics from test_unit.py (Datadog) (Fix with Cursor)
mock_http_response.<locals>._mock() missing 1 required positional argument: 'patch_target'
View all

ℹ️ Info

❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 46329b3 | Docs | Datadog PR Page | Was this helpful? Give us feedback!

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
@mwdd146980 mwdd146980 force-pushed the mwdd146980/prom-openmetrics-request-wrapper-mock branch from 2693247 to e691a5d Compare February 12, 2026 20:27
@mwdd146980 mwdd146980 closed this Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant