Skip to content

[mongo] Fall back to configured host when serverStatus hostname resolution fails#23661

Open
pierreln-dd wants to merge 3 commits into
masterfrom
pierreln-dd/SDBM-2618-mongo-hostname-fallback
Open

[mongo] Fall back to configured host when serverStatus hostname resolution fails#23661
pierreln-dd wants to merge 3 commits into
masterfrom
pierreln-dd/SDBM-2618-mongo-hostname-fallback

Conversation

@pierreln-dd
Copy link
Copy Markdown
Contributor

What does this PR do?

When serverStatus() fails (e.g. transient connection error, Atlas Private Link connectivity issue on first check dispatch), the hostname property in MongoInterface silently returns None. This None propagates into _refresh_metadata where set_metadata('resolved_hostname', None) is called without a guard, causing the C extension binding to raise TypeError: argument 3 must be str, not None.

This PR fixes both layers:

  1. api.py: Fall back to self._config.hosts[0] when serverStatus() fails, mirroring how the Postgres integration falls back to the configured DB host when server-side hostname resolution fails. The fallback is not cached in __hostname so serverStatus() is retried on subsequent check runs.

  2. mongo.py: Add a None guard before set_metadata('resolved_hostname', ...) as defence-in-depth for any future code path where hostname resolution yields None.

Motivation

SDBM-2618: Customer's MongoDB integration running as a cluster check (cluster_check: true) against an Atlas Private Link endpoint fails with TypeError: argument 3 must be str, not None on every check run in production. The cluster check runner node cannot reach serverStatus() on initial dispatch, hostname returns None, and the unchecked set_metadata call crashes. Adding reported_database_hostname to the config is the confirmed workaround — this PR makes the integration resilient without requiring that config override.

Root cause is present since Agent 7.56.0 (mongo check 6.7.0) when database_autodiscovery was introduced.

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

…p fails

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@datadog-official
Copy link
Copy Markdown
Contributor

datadog-official Bot commented May 11, 2026

Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 25.00%
Overall Coverage: 91.55%

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

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@pierreln-dd pierreln-dd marked this pull request as ready for review May 11, 2026 13:33
@pierreln-dd pierreln-dd requested review from a team as code owners May 11, 2026 13:33
@dd-octo-sts
Copy link
Copy Markdown
Contributor

dd-octo-sts Bot commented May 11, 2026

Validation Report

All 20 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
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

@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

❌ Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.00%. Comparing base (03b790e) to head (083d1db).
⚠️ Report is 1 commits behind head on master.

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.

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