Skip to content

Restrict SQL Server instance-level database metrics to autodiscovered databases - #24952

Open
jasonmp85 wants to merge 6 commits into
masterfrom
jmp/sqlserver-3a-autodiscovery-bound
Open

Restrict SQL Server instance-level database metrics to autodiscovered databases#24952
jasonmp85 wants to merge 6 commits into
masterfrom
jmp/sqlserver-3a-autodiscovery-bound

Conversation

@jasonmp85

@jasonmp85 jasonmp85 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Restricts instance-level database metric collectors to the databases selected by autodiscovery. A shared _database_filter helper adds an IN (...) predicate to the queries behind file stats, database stats, and database backup metrics when a database list is configured, and leaves the query unchanged when it is not.

Measured effect

Bench instance with 3,945 databases on the server and autodiscovery_include naming five of them. Per-collector attribution, same configuration on both sides:

collector before this PR before this PR
file stats 78,971 100 630.9 ms 68.3 ms
database stats 19,726 25 173.1 ms 9.8 ms
database backup 3,946 5 69.4 ms 9.2 ms

Total check time 918.8 ms → 132.3 ms (6.9x), and roughly 102,600 samples for unmonitored databases are no longer emitted. File stats alone accounted for 65% of the cost.

The sample counts on the right are what the configuration actually asked for: five monitored databases and their files.

Motivation

autodiscovery_include currently bounds the database-level collectors but not the instance-level ones, so naming a handful of databases does not stop the check from reporting on every database on the server. A user monitoring five databases on a shared instance pays for all 3,945 and receives metrics for databases they did not ask about.

Note for reviewers: this changes what the check emits. Users who currently rely on instance-level metrics for databases outside their autodiscovery filter would stop receiving them. I have filed the changelog entry as changed on that basis, but would appreciate a maintainer's read on whether fixed is the better call, since the current behavior contradicts the documented meaning of the option.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Add qa/required if this PR needs QA validation, or qa/skip-qa if it does not. Exactly one of the two is required.
  • 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

@datadog-prod-us1-3

datadog-prod-us1-3 Bot commented Aug 21, 2026

Copy link
Copy Markdown

Tests  Code Coverage

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 97.92%
Overall Coverage: 90.90% (+2.23%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: b3d69c9 | Docs | View more details | Give us feedback!

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Major version bump
The changelog type changed or removed was used in this Pull Request, so the next release will bump major version. Please make sure this is a breaking change, or use the fixed or added type instead.

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 21, 2026

Copy link
Copy Markdown

evalya-impact-summary

evalya impact analysis
Impact analysis: 0 selected, 0 skipped (of 0 test tasks)
Publish tasks:   1 (always emitted)
Diff (8 files):
  sqlserver/changelog.d/24952.fixed
  sqlserver/datadog_checks/sqlserver/database_metrics/base.py
  sqlserver/datadog_checks/sqlserver/database_metrics/database_backup_metrics.py
  sqlserver/datadog_checks/sqlserver/database_metrics/database_stats_metrics.py
  sqlserver/datadog_checks/sqlserver/database_metrics/file_stats_metrics.py
  sqlserver/datadog_checks/sqlserver/sqlserver.py
  sqlserver/tests/test_database_metrics.py
  sqlserver/tests/test_unit.py

Debug a specific task: evalya plan impact --path <path> --task <task>

Learn more about CI impact filtering

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 09461d1c41

ℹ️ 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".

Comment thread sqlserver/datadog_checks/sqlserver/database_metrics/base.py Outdated
@jasonmp85

Copy link
Copy Markdown
Contributor Author

OK, so there was this autodiscovery_include thing before. Using it would keep certain databases out of per-database queries.

Unfortunately, queries which implicitly include all databases would not honor this at all (queries that aren't per-DB, but make one call and get all-DB information).

So customers who set this before wouldn't be getting certain metrics for non-matching DBs, but would be getting others.

With this fix, the include is fully honored and they'll stop receiving all metrics for things outside their list.

A customer might be implicitly depending upon the broken behavior. But we're "fixing" the stated behavior.

So is this a bug fix or a breaking change (in the CHANGELOG)?

@jasonmp85
jasonmp85 force-pushed the jmp/sqlserver-3a-autodiscovery-bound branch from e301762 to 72ddef1 Compare August 21, 2026 22:10
@jasonmp85
jasonmp85 force-pushed the jmp/sqlserver-3a-autodiscovery-bound branch from ffa03e4 to ceb5e70 Compare August 24, 2026 18:36
Comment thread sqlserver/datadog_checks/sqlserver/database_metrics/base.py
sethsamuel
sethsamuel previously approved these changes Aug 24, 2026
@temporal-github-worker-1
temporal-github-worker-1 Bot dismissed sethsamuel’s stale review August 24, 2026 19:37

Review from sethsamuel is dismissed. Related teams and files:

  • database-monitoring-agent
    • sqlserver/changelog.d/24952.fixed
    • sqlserver/datadog_checks/sqlserver/database_metrics/base.py
@dd-octo-sts

dd-octo-sts Bot commented Aug 24, 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 code coverage 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

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.

2 participants