Collect Tier 1 workload telemetry - #6
Merged
Conversation
Adds three best-effort statistics sources: per-table activity from pg_stat_user_tables, per-index scan counts and size from pg_stat_user_indexes, and the top statements from pg_stat_statements. Each source degrades independently. A role that can read the catalog but not a statistics view gets a bundle with that section omitted and a warning beside it, because the operator running the profile is often not the person who can grant the missing privilege. Four warning codes distinguish "not installed" from "installed but unreadable": only the second is worth retrying with more access. Statements are ranked in SQL with two window functions -- slowest and most frequent are different questions -- capped at 400 rows, scoped to the profiled database, and deduplicated by queryid in Python. The forbidden-token check now matches ANALYZE on word boundaries. pg_stat_user_tables exposes last_analyze, analyze_count, autoanalyze_count and n_mod_since_analyze, and a substring match rejected all four. Those columns are how a reader knows whether the source statistics are stale enough to make the rest of the profile untrustworthy, so dropping them would have traded real signal for the appearance of rigour. ANALYZE as a statement is still rejected; there are guard tests in both directions. pg_database and pg_extension join the relation allowlist alongside the collectors that read them. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
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.
Task 6 of the MVP plan.
Three best-effort statistics sources: per-table activity (
pg_stat_user_tables), per-index scan counts and size (pg_stat_user_indexes), and top statements (pg_stat_statements).Each source degrades independently. A role that can read the catalog but not a statistics view gets a bundle with that section omitted and a warning beside it — the operator running the profile is often not the person who can grant the missing privilege. Four warning codes distinguish not installed from installed but unreadable; only the second is worth retrying with more access.
pg_stat_statements_infofailing costs the reset timestamp, not the counters.Top-N is ranked in SQL with two window functions in one pass — slowest and most frequent are different questions, and a migration plan needs both. Capped at 400 rows, scoped to the profiled database (
pg_stat_statementsis cluster-wide; without the filter the profile would describe a workload that never touched the target), deduplicated byqueryidin Python keeping the most expensive occurrence.The forbidden-token check now matches
ANALYZEon word boundaries.pg_stat_user_tablesexposeslast_analyze,analyze_count,autoanalyze_countandn_mod_since_analyze, and a substring match rejected all four. Those columns are how a reader knows whether the source statistics are stale enough to make the rest of the profile untrustworthy — dropping them would trade real signal for the appearance of rigour.ANALYZE public.usersandVACUUM ANALYZEare still rejected;\bCOUNT\(still catchespg_catalog.count(*)and now correctly ignores the tail ofautovacuum_count. Six guard tests, both directions.pg_databaseandpg_extensionjoin the relation allowlist alongside the collectors that read them. The extension probe runs first, so a database withoutpg_stat_statementscosts one query rather than two failures.Query text is collected raw into a record that is never serialized; tokenization lands in task 7 where the HMAC key handling lives.
Verification: 185 tests pass,
--check-safetyclean over 14 SQL constants,ruff checkclean, 3.9 grammar verified.