Add opt-in incremental query metrics collector for MySQL - #24790
Draft
eric-weaver wants to merge 2 commits into
Draft
Add opt-in incremental query metrics collector for MySQL#24790eric-weaver wants to merge 2 commits into
eric-weaver wants to merge 2 commits into
Conversation
Query metrics collection obfuscates every row returned from events_statements_summary_by_digest on every collection, even when a statement has not executed since the last one. Obfuscation is a cgo call and dominates collection cost on instances with large digest tables. This adds an alternative collector behind the hidden, default-off incremental_query_metrics flag. It snapshots the cumulative counters, diffs them against the previous collection to find statements that actually executed, and only resolves and obfuscates the query text for those. Obfuscation results are memoized in a digest-keyed cache sized from performance_schema_digests_size. The emitted payload is unchanged; existing users are unaffected until they opt in. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
Validation Report
Run Passed validations (20)
|
|
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds an alternative query metrics collector for MySQL behind a new hidden, default-off
incremental_query_metricsflag.The existing collector obfuscates every row returned from
events_statements_summary_by_digeston every collection, including statements that have not executed since the previous one. The new collector snapshots the cumulative counters, diffs them against the previous snapshot to determine which statements actually executed, and resolves and obfuscates query text only for those. Obfuscation results are memoized in a digest-keyed cache sized fromperformance_schema_digests_size.Three new modules are added —
delta_detector.py,obfuscation_lookup.py, andstatements_v2.py— mirroring the structure of the equivalent Postgres implementation. Collector selection happens once at check initialization in_initialize_statement_metrics. Aperformance_schema_digests_sizeaccessor is added toGlobalVariables, and the existing integer-coercing property bodies there are folded into a shared_get_int_variablehelper.The emitted payload is unchanged. Existing users are unaffected until they explicitly opt in.
Motivation
Obfuscation is a cgo call and is the dominant cost of query metrics collection on instances with large digest tables, since it is repeated every collection for statements whose counters have not moved.
Benchmarked end to end against a live Agent container with both collectors running side by side over four workload shapes (cold, warm, hot-light, hot-churn), comparing intercepted payloads:
Review checklist (to be filled by reviewers)
qa/requiredif this PR needs QA validation, orqa/skip-qaif it does not. Exactly one of the two is required.backport/<branch-name>label to the PR and it will automatically open a backport PR once this one is mergedMade with Cursor