Skip to content

Migrate kube_apiserver_metrics, kube_dns, kube_metrics_server, kube_proxy tests to mock_openmetrics_http#23781

Merged
mwdd146980 merged 5 commits into
mwdd146980/httpx-migration-basefrom
mwdd146980/step6-kube-small-batch
May 28, 2026
Merged

Migrate kube_apiserver_metrics, kube_dns, kube_metrics_server, kube_proxy tests to mock_openmetrics_http#23781
mwdd146980 merged 5 commits into
mwdd146980/httpx-migration-basefrom
mwdd146980/step6-kube-small-batch

Conversation

@mwdd146980

@mwdd146980 mwdd146980 commented May 20, 2026

Copy link
Copy Markdown
Contributor

Motivation

Migrates the kube_apiserver_metrics, kube_dns, kube_metrics_server, and kube_proxy test suites off mock.patch('requests.Session.get', ...) to mock_openmetrics_http. Removing requests-library-level patches is a precondition for the upcoming httpx swap. Test-only, no production changes.

Approach

  • Shared make_mock_metrics helper in each integration's tests/common.py.
  • Opt-in mock_healthcheck_wrapper fixture in kube_dns, kube_metrics_server, and kube_proxy conftests. These three checks build a separate RequestsWrapper inside _healthcheck_http_handler, outside self.http, so mock_openmetrics_http does not cover the healthcheck path. The fixture patches the integration-local RequestsWrapper symbol. kube_apiserver_metrics has no healthcheck path and does not need it.
  • test_service_check raises requests.HTTPError directly to exercise the live except requests.exceptions.RequestException branch.
  • kube_proxy gains an empty tests/__init__.py so the new tests/common.py is importable.

Verification

ddev test -fs clean and ddev --no-interactive test green for all four integrations (32 tests pass).

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

Migrate kube_apiserver_metrics, kube_dns, kube_metrics_server, and
kube_proxy off requests.Session.get patches to mock_openmetrics_http
+ MockHTTPResponse. Test-only changes, no production code touched.

Adds shared make_mock_metrics helpers in each integration's
tests/common.py and opt-in mock_healthcheck_wrapper fixtures in
kube_dns, kube_metrics_server, kube_proxy conftests to neutralize
_healthcheck_http_handler's separate RequestsWrapper instances.

Replaces test_service_check_ok in three integrations with a
parametrized test_service_check that exercises both the OK branch
and the requests.HTTPError branch against the production
except requests.exceptions.RequestException handler.
@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented May 20, 2026

Copy link
Copy Markdown

Pipelines  Tests

Fix all issues with BitsAI

⚠️ Warnings

🚦 5 Pipeline jobs failed

PR | test / test-minimum-base-package (linux, ubuntu-22.04, kube_apiserver_metrics, Kubernetes API server met... / minimum-base-package-Kubernetes API server metrics (py3.13)-py3.13   View in Datadog   GitHub Actions

🔧 Fix in code (Fix with Cursor). ImportError: No module named 'datadog_checks.base.utils.http_testing' during test collection in tests/test_kube_apiserver_metrics.py and others.

PR | test / test-minimum-base-package (linux, ubuntu-22.04, kube_metrics_server, Kube metrics server (py3.13)... / minimum-base-package-Kube metrics server (py3.13)-py3.13   View in Datadog   GitHub Actions

🔧 Fix in code (Fix with Cursor). ImportError: No module named 'datadog_checks.base.utils.http_testing' in tests/test_kube_metrics_server.py

PR | test / test-minimum-base-package (linux, ubuntu-22.04, kube_dns, Kube DNS (py3.13), py3.13) / minimum-base-package-Kube DNS (py3.13)-py3.13   View in Datadog   GitHub Actions

🛟 This job is unlikely to succeed on retry. Please review your pipeline configuration. ImportError: ModuleNotFoundError: No module named 'datadog_checks.base.utils.http_testing' in tests/test_kube_dns.py.

View all 5 failed jobs.

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 96.90% (+9.44%)

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 89f7b97 | Docs | Datadog PR Page | Give us feedback!

@codecov

codecov Bot commented May 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.99%. Comparing base (f1788f2) to head (89f7b97).
⚠️ Report is 1 commits behind head on mwdd146980/httpx-migration-base.

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.

@mwdd146980 mwdd146980 self-assigned this May 20, 2026
@mwdd146980

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@mwdd146980
mwdd146980 marked this pull request as ready for review May 21, 2026 15:46
@mwdd146980
mwdd146980 requested review from a team as code owners May 21, 2026 15:46
@dd-octo-sts

dd-octo-sts Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Validation Report

All 21 validations passed.

Show details
Validation Description Status
agent-reqs Verify check versions match the Agent requirements file
ci Validate CI configuration and Codecov settings
codeowners Validate every integration has a CODEOWNERS entry
config Validate default configuration files against spec.yaml
dep Verify dependency pins are consistent and Agent-compatible
http Validate integrations use the HTTP wrapper correctly
imports Validate check imports do not use deprecated modules
integration-style Validate check code style conventions
jmx-metrics Validate JMX metrics definition files and config
labeler Validate PR labeler config matches integration directories
legacy-signature Validate no integration uses the legacy Agent check signature
license-headers Validate Python files have proper license headers
licenses Validate third-party license attribution list
metadata Validate metadata.csv metric definitions
models Validate configuration data models match spec.yaml
openmetrics Validate OpenMetrics integrations disable the metric limit
package Validate Python package metadata and naming
qa-label Validate the pull request declares whether it needs QA for the next Agent release
readmes Validate README files have required sections
saved-views Validate saved view JSON file structure and fields
version Validate version consistency between package and changelog

View full run

@mwdd146980
mwdd146980 merged commit f14a5ce into mwdd146980/httpx-migration-base May 28, 2026
40 of 48 checks passed
@mwdd146980
mwdd146980 deleted the mwdd146980/step6-kube-small-batch branch May 28, 2026 15:57
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.

3 participants