Skip to content

[mysql] Name REFERENCES in the schema collection privileges warning - #24739

Open
azhou-datadog wants to merge 1 commit into
masterfrom
allen.zhou/mysql-schema-collection-improvements
Open

[mysql] Name REFERENCES in the schema collection privileges warning#24739
azhou-datadog wants to merge 1 commit into
masterfrom
allen.zhou/mysql-schema-collection-improvements

Conversation

@azhou-datadog

Copy link
Copy Markdown
Contributor

Supersedes #24737, which could not be reopened after its branch was rewritten to drop the unrelated commits it had picked up.

What does this PR do?

Points the schema-collection insufficient-privileges warning at the REFERENCES privilege instead of SELECT.

MySQL exposes a table in INFORMATION_SCHEMA only to users that hold some privilege on it — that is why schema collection currently asks customers to GRANT SELECT ON *.*, and why the setup docs have to explain in prose that the Agent doesn't actually read their data. REFERENCES satisfies the same visibility check and grants no ability to read (or write) anything.

No query changes: the collected payload is identical under either privilege.

Motivation

Requiring SELECT on customer tables is the main setup hurdle for MySQL schema collection and blocks enabling it by default. A spike verified that REFERENCES produces a byte-identical schema payload while leaving the Agent unable to read table data:

  • All six schema queries diff clean against a full-SELECT baseline on MySQL 5.6.51, 5.7.44, 8.0.45, 8.4.3, 9.7.2, Percona 8.4.10 and MariaDB 10.11.18, 11.4.12.
  • End to end, the mysql_databases payload the Agent puts on the wire is unchanged after swapping the grant (18 tables / 97 columns / 41 indexes / 4 FKs / 5 partitions, empty diff), while SELECT * FROM <table> as the Agent user returns ERROR 1142.
  • REFERENCES alone cannot create a foreign key: that needs CREATE/ALTER on the referencing table, which the datadog user does not have.
  • Grantable on RDS/Aurora (rds_superuser_role includes it WITH GRANT OPTION), Cloud SQL, and Azure MySQL.

Worth noting: tests/conftest.py:606 already grants REFERENCES to the test user, with the comment "needed to query INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS in mariadb 10.5 and above". That requirement was worked around in the fixture but never surfaced to customers, so MariaDB users following the docs today collect foreign keys without their ON UPDATE/ON DELETE actions.

One behavioural consequence for the docs rather than the code: with REFERENCES instead of SELECT, the STATEMENT explain strategy (a direct EXPLAIN as the datadog user) no longer works, so explain plans depend on the explain_statement definer procedures that setup already prescribes. Verified both halves in a sandbox.

Additional Notes

Docs counterpart: DataDog/documentation#38606.

Deliberately not in this PR, to be handled separately: SQL_FOREIGN_KEYS aggregates referenced_column_names with group_concat and no ORDER BY, unlike the column_names aggregate beside it, so composite foreign keys report their referenced columns in a non-deterministic order (reproduced as a,b vs b,a on the same constraint across MySQL 5.6 and MariaDB). test_collect_schemas currently sorts that field before comparing, which hides it.

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

@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.

@datadog-official

datadog-official Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Tests  Code Coverage

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 90.66% (+2.28%)

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

@azhou-datadog
azhou-datadog force-pushed the allen.zhou/mysql-schema-collection-improvements branch from efa6afe to 6210174 Compare July 30, 2026 19:57
@azhou-datadog azhou-datadog added the qa/skip-qa Automatically skip this PR for the next QA label Jul 30, 2026
@azhou-datadog
azhou-datadog marked this pull request as ready for review July 30, 2026 20:02
@azhou-datadog
azhou-datadog requested review from a team as code owners July 30, 2026 20:02

@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: 62101740f2

ℹ️ 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 on lines +296 to +297
"to view table metadata. The datadog user needs REFERENCES (or SELECT) privileges on the "
"tables.".format(len(db_infos))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Update shipped schema-collection guidance

This warning now tells users to grant REFERENCES, but the in-repo generated sample config still says schema collection only collects tables with SELECT privileges (mysql/datadog_checks/mysql/data/conf.yaml.example:337, generated from mysql/assets/configuration/spec.yaml:475). Users configuring from the shipped sample will continue granting broader read access and get guidance that contradicts this new Agent warning, so the config spec/sample should be updated along with the warning.

Useful? React with 👍 / 👎.

@azhou-datadog
azhou-datadog force-pushed the allen.zhou/mysql-schema-collection-improvements branch from 6210174 to 8a0f8c0 Compare July 30, 2026 20:15
MySQL only exposes a table in INFORMATION_SCHEMA to users holding a privilege on
it, which is why schema collection currently asks customers for SELECT on their
tables. The REFERENCES privilege satisfies that same visibility check without
granting any ability to read table data, so the insufficient-privileges warning
now points at it instead of SELECT.

The config spec carried the same SELECT-only guidance in five places - the
collect_schemas description, its deprecated schemas_collection twin, and the
three size-metric options - so update those too and regenerate the sample.
Otherwise anyone configuring from the shipped conf.yaml.example would keep
granting broader read access than the Agent needs, and would get advice that
contradicts the new warning.

Verified that the size-metric queries return identical results under REFERENCES
and SELECT on Percona 8.4.10, MariaDB 11.4.12 and MySQL 5.6.51, so the wording
change is accurate for those options too.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@azhou-datadog
azhou-datadog force-pushed the allen.zhou/mysql-schema-collection-improvements branch from 8a0f8c0 to 2f6abc9 Compare July 30, 2026 20:21
@dd-octo-sts

dd-octo-sts Bot commented Jul 30, 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.

1 participant